diff options
| author | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-27 12:43:14 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano.tronto@gmail.com> | 2021-12-27 12:43:14 +0100 |
| commit | 2332679ad64e3e0318ca812421190156edec9186 (patch) | |
| tree | 35a0d1fee1f9e57c973640c599d1e2896e44fd45 /src/commands.c | |
| parent | 8cec37cb3e490b06639f2e05df8b947a9333d5d2 (diff) | |
| download | nissy-2332679ad64e3e0318ca812421190156edec9186.tar.gz nissy-2332679ad64e3e0318ca812421190156edec9186.zip | |
Added option -i to accept scramble(s) from stdin, very useful for batch mode
Diffstat (limited to '')
| -rw-r--r-- | src/commands.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/commands.c b/src/commands.c index fc63e7c..9ecc9c7 100644 --- a/src/commands.c +++ b/src/commands.c | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | CommandArgs * gen_parse_args(int c, char **v); | 5 | CommandArgs * gen_parse_args(int c, char **v); |
| 6 | CommandArgs * help_parse_args(int c, char **v); | 6 | CommandArgs * help_parse_args(int c, char **v); |
| 7 | CommandArgs * print_parse_args(int c, char **v); | ||
| 8 | CommandArgs * parse_only_scramble(int c, char **v); | 7 | CommandArgs * parse_only_scramble(int c, char **v); |
| 9 | CommandArgs * parse_no_arg(int c, char **v); | 8 | CommandArgs * parse_no_arg(int c, char **v); |
| 10 | CommandArgs * solve_parse_args(int c, char **v); | 9 | CommandArgs * solve_parse_args(int c, char **v); |
| @@ -92,7 +91,7 @@ print_cmd = { | |||
| 92 | .name = "print", | 91 | .name = "print", |
| 93 | .usage = "print SCRAMBLE", | 92 | .usage = "print SCRAMBLE", |
| 94 | .description = "Print written description of the cube", | 93 | .description = "Print written description of the cube", |
| 95 | .parse_args = print_parse_args, | 94 | .parse_args = parse_only_scramble, |
| 96 | .exec = print_exec, | 95 | .exec = print_exec, |
| 97 | }; | 96 | }; |
| 98 | 97 | ||
| @@ -235,6 +234,8 @@ solve_parse_args(int c, char **v) | |||
| 235 | infinitesols = true; | 234 | infinitesols = true; |
| 236 | } else if (!strcmp(v[i], "-N")) { | 235 | } else if (!strcmp(v[i], "-N")) { |
| 237 | a->opts->can_niss = true; | 236 | a->opts->can_niss = true; |
| 237 | } else if (!strcmp(v[i], "-i")) { | ||
| 238 | a->scrstdin = true; | ||
| 238 | } else if (!strcmp(v[i], "-v")) { | 239 | } else if (!strcmp(v[i], "-v")) { |
| 239 | a->opts->verbose = true; | 240 | a->opts->verbose = true; |
| 240 | } else if (!strcmp(v[i], "-a")) { | 241 | } else if (!strcmp(v[i], "-a")) { |
| @@ -251,7 +252,7 @@ solve_parse_args(int c, char **v) | |||
| 251 | if (infinitesols && !fixedmsols) | 252 | if (infinitesols && !fixedmsols) |
| 252 | a->opts->max_solutions = 1000000; /* 1M = +infty */ | 253 | a->opts->max_solutions = 1000000; /* 1M = +infty */ |
| 253 | 254 | ||
| 254 | a->success = read_scramble(c-i, &v[i], a); | 255 | a->success = (a->scrstdin && i == c) || read_scramble(c-i, &v[i], a); |
| 255 | return a; | 256 | return a; |
| 256 | } | 257 | } |
| 257 | 258 | ||
| @@ -338,7 +339,12 @@ parse_only_scramble(int c, char **v) | |||
| 338 | { | 339 | { |
| 339 | CommandArgs *a = new_args(); | 340 | CommandArgs *a = new_args(); |
| 340 | 341 | ||
| 341 | a->success = read_scramble(c, v, a); | 342 | if (!strcmp(v[0], "-i")) { |
| 343 | a->scrstdin = true; | ||
| 344 | a->success = c == 1; | ||
| 345 | } else { | ||
| 346 | a->success = read_scramble(c, v, a); | ||
| 347 | } | ||
| 342 | 348 | ||
| 343 | return a; | 349 | return a; |
| 344 | } | 350 | } |
| @@ -353,16 +359,6 @@ parse_no_arg(int c, char **v) | |||
| 353 | return a; | 359 | return a; |
| 354 | } | 360 | } |
| 355 | 361 | ||
| 356 | CommandArgs * | ||
| 357 | print_parse_args(int c, char **v) | ||
| 358 | { | ||
| 359 | CommandArgs *a = new_args(); | ||
| 360 | |||
| 361 | a->success = read_scramble(c, v, a); | ||
| 362 | |||
| 363 | return a; | ||
| 364 | } | ||
| 365 | |||
| 366 | /* Exec functions implementation *********************************************/ | 362 | /* Exec functions implementation *********************************************/ |
| 367 | 363 | ||
| 368 | static void | 364 | static void |
| @@ -611,6 +607,7 @@ new_args() | |||
| 611 | CommandArgs *args = malloc(sizeof(CommandArgs)); | 607 | CommandArgs *args = malloc(sizeof(CommandArgs)); |
| 612 | 608 | ||
| 613 | args->success = false; | 609 | args->success = false; |
| 610 | args->scrstdin = false; | ||
| 614 | args->scramble = NULL; /* initialized in read_scramble */ | 611 | args->scramble = NULL; /* initialized in read_scramble */ |
| 615 | args->opts = malloc(sizeof(SolveOptions)); | 612 | args->opts = malloc(sizeof(SolveOptions)); |
| 616 | 613 | ||
