diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-13 12:12:42 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-13 12:12:42 +0100 |
| commit | 97c9dba402d6d4097cbdc4c44c00222c53122033 (patch) | |
| tree | f604aa049737b5e486924c88f86d91106428ec24 | |
| parent | ac458f4de9a1d5fa203bed7b57de05ea65451788 (diff) | |
| download | nissy-97c9dba402d6d4097cbdc4c44c00222c53122033.tar.gz nissy-97c9dba402d6d4097cbdc4c44c00222c53122033.zip | |
Fixed bug in reading scrambles with unmatched parentheses
| -rw-r--r-- | TODO.md | 3 | ||||
| -rwxr-xr-x | nissy | bin | 322488 -> 322488 bytes | |||
| -rw-r--r-- | nissy-2.0.tar.gz | bin | 65160 -> 0 bytes | |||
| -rw-r--r-- | src/alg.c | 13 | ||||
| -rw-r--r-- | src/commands.c | 13 |
5 files changed, 15 insertions, 14 deletions
| @@ -4,6 +4,9 @@ This is a list of things that I would like to add or change at some point. | |||
| 4 | It's more of a personal reminder than anything else. | 4 | It's more of a personal reminder than anything else. |
| 5 | 5 | ||
| 6 | ## For version 2.1 | 6 | ## For version 2.1 |
| 7 | ### Bugs | ||
| 8 | * when reading scramble, unmatched ( does not produce any error, unmatched ) | ||
| 9 | produces TWO errors but it goes on anyway | ||
| 7 | ### Scrambles | 10 | ### Scrambles |
| 8 | * Better two-phase solver, make sure to not have cancelling moves | 11 | * Better two-phase solver, make sure to not have cancelling moves |
| 9 | (possibly use cleanup function) | 12 | (possibly use cleanup function) |
| Binary files differ | |||
diff --git a/nissy-2.0.tar.gz b/nissy-2.0.tar.gz deleted file mode 100644 index 29172d0..0000000 --- a/nissy-2.0.tar.gz +++ /dev/null | |||
| Binary files differ | |||
| @@ -268,27 +268,31 @@ move_string(Move m) | |||
| 268 | Alg * | 268 | Alg * |
| 269 | new_alg(char *str) | 269 | new_alg(char *str) |
| 270 | { | 270 | { |
| 271 | Alg *alg = malloc(sizeof(Alg)); | 271 | Alg *alg; |
| 272 | int i; | 272 | int i; |
| 273 | bool niss = false, move_read; | 273 | bool niss, move_read; |
| 274 | Move j, m; | 274 | Move j, m; |
| 275 | 275 | ||
| 276 | alg = malloc(sizeof(Alg)); | ||
| 276 | alg->move = malloc(30 * sizeof(Move)); | 277 | alg->move = malloc(30 * sizeof(Move)); |
| 277 | alg->inv = malloc(30 * sizeof(bool)); | 278 | alg->inv = malloc(30 * sizeof(bool)); |
| 278 | alg->allocated = 30; | 279 | alg->allocated = 30; |
| 279 | alg->len = 0; | 280 | alg->len = 0; |
| 280 | 281 | ||
| 282 | niss = false; | ||
| 281 | for (i = 0; str[i]; i++) { | 283 | for (i = 0; str[i]; i++) { |
| 282 | if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n') | 284 | if (str[i] == ' ' || str[i] == '\t' || str[i] == '\n') |
| 283 | continue; | 285 | continue; |
| 284 | 286 | ||
| 285 | if (str[i] == '(' && niss) { | 287 | if (str[i] == '(' && niss) { |
| 286 | fprintf(stderr, "Error reading moves: nested ( )\n"); | 288 | fprintf(stderr, "Error reading moves: nested ( )\n"); |
| 289 | alg->len = 0; | ||
| 287 | return alg; | 290 | return alg; |
| 288 | } | 291 | } |
| 289 | 292 | ||
| 290 | if (str[i] == ')' && !niss) { | 293 | if (str[i] == ')' && !niss) { |
| 291 | fprintf(stderr, "Error reading moves: unmatched )\n"); | 294 | fprintf(stderr, "Error reading moves: unmatched )\n"); |
| 295 | alg->len = 0; | ||
| 292 | return alg; | 296 | return alg; |
| 293 | } | 297 | } |
| 294 | 298 | ||
| @@ -353,6 +357,11 @@ new_alg(char *str) | |||
| 353 | } | 357 | } |
| 354 | } | 358 | } |
| 355 | 359 | ||
| 360 | if (niss) { | ||
| 361 | fprintf(stderr, "Error reading moves: unmatched (\n"); | ||
| 362 | alg->len = 0; | ||
| 363 | } | ||
| 364 | |||
| 356 | return alg; | 365 | return alg; |
| 357 | } | 366 | } |
| 358 | 367 | ||
diff --git a/src/commands.c b/src/commands.c index 740736c..d9d6b50 100644 --- a/src/commands.c +++ b/src/commands.c | |||
| @@ -519,25 +519,14 @@ read_scramble(int c, char **v, CommandArgs *args) | |||
| 519 | int i, k, n; | 519 | int i, k, n; |
| 520 | unsigned int j; | 520 | unsigned int j; |
| 521 | char *algstr; | 521 | char *algstr; |
| 522 | Alg *aux; | ||
| 523 | 522 | ||
| 524 | if (c < 1) { | 523 | if (c < 1) { |
| 525 | fprintf(stderr, "Error: no scramble given?\n"); | 524 | fprintf(stderr, "Error: no scramble given?\n"); |
| 526 | return false; | 525 | return false; |
| 527 | } | 526 | } |
| 528 | 527 | ||
| 529 | n = 0; | 528 | for(n = 0, i = 0; i < c; i++) |
| 530 | for(i = 0; i < c; i++) { | ||
| 531 | aux = new_alg(v[i]); | ||
| 532 | if (aux->len == 0) { | ||
| 533 | fprintf(stderr, "Error: %s or its argument" | ||
| 534 | "unrecognized\n", v[i]); | ||
| 535 | free(aux); | ||
| 536 | return false; | ||
| 537 | } | ||
| 538 | free(aux); | ||
| 539 | n += strlen(v[i]); | 529 | n += strlen(v[i]); |
| 540 | } | ||
| 541 | 530 | ||
| 542 | algstr = malloc((n + 1) * sizeof(char)); | 531 | algstr = malloc((n + 1) * sizeof(char)); |
| 543 | k = 0; | 532 | k = 0; |
