aboutsummaryrefslogtreecommitdiff
path: root/shell/shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/shell.c')
-rw-r--r--shell/shell.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/shell/shell.c b/shell/shell.c
index 0387856..1b66f19 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -73,7 +73,8 @@ static int64_t countmoves_exec(args_t *);
73static int64_t help_exec(args_t *); 73static int64_t help_exec(args_t *);
74 74
75static int parse_args(int, char **, args_t *); 75static int parse_args(int, char **, args_t *);
76static bool parse_uint(char *, unsigned *); 76static bool parse_uint(const char *, unsigned *);
77static uint8_t parse_nisstype(const char *);
77 78
78static bool set_cube(int, char **, args_t *); 79static bool set_cube(int, char **, args_t *);
79static bool set_cube_perm(int, char **, args_t *); 80static bool set_cube_perm(int, char **, args_t *);
@@ -111,7 +112,7 @@ struct {
111 OPTION(FLAG_MOVES, 1, set_str_moves), 112 OPTION(FLAG_MOVES, 1, set_str_moves),
112 OPTION(FLAG_TRANS, 1, set_str_trans), 113 OPTION(FLAG_TRANS, 1, set_str_trans),
113 OPTION(FLAG_SOLVER, 1, set_str_solver), 114 OPTION(FLAG_SOLVER, 1, set_str_solver),
114 OPTION(FLAG_NISSTYPE, 1, set_str_nisstype), /* TODO: more args ? */ 115 OPTION(FLAG_NISSTYPE, 1, set_str_nisstype),
115 OPTION(FLAG_MINMOVES, 1, set_minmoves), 116 OPTION(FLAG_MINMOVES, 1, set_minmoves),
116 OPTION(FLAG_MAXMOVES, 1, set_maxmoves), 117 OPTION(FLAG_MAXMOVES, 1, set_maxmoves),
117 OPTION(FLAG_OPTIMAL, 1, set_optimal), 118 OPTION(FLAG_OPTIMAL, 1, set_optimal),
@@ -431,12 +432,18 @@ solve_exec(args_t *args)
431 int64_t ret, gendata_ret, size; 432 int64_t ret, gendata_ret, size;
432 size_t read; 433 size_t read;
433 434
434 nissflag = NISSY_NISSFLAG_NORMAL; /* TODO: parse str_nisstype */ 435 nissflag = parse_nisstype(args->str_nisstype);
436 if (nissflag == UINT8_MAX) {
437 fprintf(stderr, "solve: unknown niss type '%s', use one "
438 "of the following:\nnormal\ninverse\nlinear\nmixed\nall",
439 args->str_nisstype);
440 return -1;
441 }
435 442
436 size = nissy_solverinfo(args->str_solver, dataid); 443 size = nissy_solverinfo(args->str_solver, dataid);
437 444
438 if (size < 0) { 445 if (size < 0) {
439 fprintf(stderr, "solve: unknown solver %s\n", 446 fprintf(stderr, "solve: unknown solver '%s'\n",
440 args->str_solver); 447 args->str_solver);
441 return size; 448 return size;
442 } 449 }
@@ -622,8 +629,8 @@ parse_args(int argc, char **argv, args_t *args)
622 return 0; 629 return 0;
623} 630}
624 631
625bool 632static bool
626parse_uint(char *argv, unsigned *result) 633parse_uint(const char *argv, unsigned *result)
627{ 634{
628 *result = strtol(argv, NULL, 10); 635 *result = strtol(argv, NULL, 10);
629 636
@@ -631,6 +638,27 @@ parse_uint(char *argv, unsigned *result)
631 return true; 638 return true;
632} 639}
633 640
641static uint8_t
642parse_nisstype(const char *arg)
643{
644 if (!strcmp("normal", arg))
645 return NISSY_NISSFLAG_NORMAL;
646
647 if (!strcmp("inverse", arg))
648 return NISSY_NISSFLAG_INVERSE;
649
650 if (!strcmp("linear", arg))
651 return NISSY_NISSFLAG_LINEAR;
652
653 if (!strcmp("mixed", arg))
654 return NISSY_NISSFLAG_MIXED;
655
656 if (!strcmp("all", arg))
657 return NISSY_NISSFLAG_ALL;
658
659 return UINT8_MAX;
660}
661
634static bool 662static bool
635set_cube(int argc, char **argv, args_t *args) 663set_cube(int argc, char **argv, args_t *args)
636{ 664{

Generated with cgit - Back to sebastiano.tronto.net