diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/alg.c | 13 | ||||
| -rw-r--r-- | src/commands.c | 13 |
2 files changed, 12 insertions, 14 deletions
| @@ -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; |
