diff options
Diffstat (limited to 'src/commands.c')
| -rw-r--r-- | src/commands.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/commands.c b/src/commands.c index 78d7583..f01edfd 100644 --- a/src/commands.c +++ b/src/commands.c | |||
| @@ -6,6 +6,7 @@ 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 * parse_only_scramble(int c, char **v); | 7 | CommandArgs * parse_only_scramble(int c, char **v); |
| 8 | CommandArgs * parse_no_arg(int c, char **v); | 8 | CommandArgs * parse_no_arg(int c, char **v); |
| 9 | CommandArgs * ptable_parse_args(int c, char **v); | ||
| 9 | CommandArgs * solve_parse_args(int c, char **v); | 10 | CommandArgs * solve_parse_args(int c, char **v); |
| 10 | CommandArgs * scramble_parse_args(int c, char **v); | 11 | CommandArgs * scramble_parse_args(int c, char **v); |
| 11 | 12 | ||
| @@ -20,6 +21,7 @@ static void steps_exec(CommandArgs *args); | |||
| 20 | static void commands_exec(CommandArgs *args); | 21 | static void commands_exec(CommandArgs *args); |
| 21 | static void freemem_exec(CommandArgs *args); | 22 | static void freemem_exec(CommandArgs *args); |
| 22 | static void print_exec(CommandArgs *args); | 23 | static void print_exec(CommandArgs *args); |
| 24 | static void ptable_exec(CommandArgs *args); | ||
| 23 | static void twophase_exec(CommandArgs *args); | 25 | static void twophase_exec(CommandArgs *args); |
| 24 | static void help_exec(CommandArgs *args); | 26 | static void help_exec(CommandArgs *args); |
| 25 | static void quit_exec(CommandArgs *args); | 27 | static void quit_exec(CommandArgs *args); |
| @@ -107,6 +109,15 @@ print_cmd = { | |||
| 107 | }; | 109 | }; |
| 108 | 110 | ||
| 109 | Command | 111 | Command |
| 112 | ptable_cmd = { | ||
| 113 | .name = "ptable", | ||
| 114 | .usage = "ptable [TABLE]", | ||
| 115 | .description = "Print information on pruning tables", | ||
| 116 | .parse_args = ptable_parse_args, | ||
| 117 | .exec = ptable_exec, | ||
| 118 | }; | ||
| 119 | |||
| 120 | Command | ||
| 110 | help_cmd = { | 121 | help_cmd = { |
| 111 | .name = "help", | 122 | .name = "help", |
| 112 | .usage = "help [COMMAND]", | 123 | .usage = "help [COMMAND]", |
| @@ -167,6 +178,7 @@ Command *commands[] = { | |||
| 167 | &help_cmd, | 178 | &help_cmd, |
| 168 | &invert_cmd, | 179 | &invert_cmd, |
| 169 | &print_cmd, | 180 | &print_cmd, |
| 181 | &ptable_cmd, | ||
| 170 | &quit_cmd, | 182 | &quit_cmd, |
| 171 | &solve_cmd, | 183 | &solve_cmd, |
| 172 | &scramble_cmd, | 184 | &scramble_cmd, |
| @@ -384,6 +396,24 @@ parse_no_arg(int c, char **v) | |||
| 384 | return a; | 396 | return a; |
| 385 | } | 397 | } |
| 386 | 398 | ||
| 399 | CommandArgs * | ||
| 400 | ptable_parse_args(int c, char **v) | ||
| 401 | { | ||
| 402 | int i; | ||
| 403 | CommandArgs *a = new_args(); | ||
| 404 | |||
| 405 | if (c == 1) { | ||
| 406 | for (i = 0; all_pd[i] != NULL; i++) | ||
| 407 | if (!strcmp(v[0], all_pd[i]->filename)) | ||
| 408 | a->pd = all_pd[i]; | ||
| 409 | if (a->pd == NULL) | ||
| 410 | fprintf(stderr, "%s: pruning table not found\n", v[0]); | ||
| 411 | } | ||
| 412 | |||
| 413 | a->success = c == 0 || (c == 1 && a->pd != NULL); | ||
| 414 | return a; | ||
| 415 | } | ||
| 416 | |||
| 387 | /* Exec functions implementation *********************************************/ | 417 | /* Exec functions implementation *********************************************/ |
| 388 | 418 | ||
| 389 | static void | 419 | static void |
| @@ -584,6 +614,23 @@ print_exec(CommandArgs *args) | |||
| 584 | } | 614 | } |
| 585 | 615 | ||
| 586 | static void | 616 | static void |
| 617 | ptable_exec(CommandArgs *args) | ||
| 618 | { | ||
| 619 | int i = 0; | ||
| 620 | if (args->pd == NULL) { | ||
| 621 | printf("Available pruning tables:\n"); | ||
| 622 | for (i = 0; all_pd[i] != NULL; i++) | ||
| 623 | printf("\t%s\n", all_pd[i]->filename); | ||
| 624 | printf("Use ptable [TABLE] to see the table distribution" | ||
| 625 | " and other information\n"); | ||
| 626 | } else { | ||
| 627 | genptable(args->pd, args->opts->nthreads); | ||
| 628 | print_ptable(args->pd); | ||
| 629 | } | ||
| 630 | } | ||
| 631 | |||
| 632 | |||
| 633 | static void | ||
| 587 | twophase_exec(CommandArgs *args) | 634 | twophase_exec(CommandArgs *args) |
| 588 | { | 635 | { |
| 589 | Cube c; | 636 | Cube c; |
| @@ -750,6 +797,7 @@ new_args(void) | |||
| 750 | /* step and command are static */ | 797 | /* step and command are static */ |
| 751 | args->step = steps[0]; /* default: first step in list */ | 798 | args->step = steps[0]; /* default: first step in list */ |
| 752 | args->command = NULL; | 799 | args->command = NULL; |
| 800 | args->pd = NULL; | ||
| 753 | 801 | ||
| 754 | return args; | 802 | return args; |
| 755 | } | 803 | } |
