diff options
Diffstat (limited to 'src/alg.c')
| -rw-r--r-- | src/alg.c | 13 |
1 files changed, 11 insertions, 2 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 | ||
