aboutsummaryrefslogtreecommitdiff
path: root/shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell.c')
-rw-r--r--shell.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/shell.c b/shell.c
index e4f41b7..dbdb698 100644
--- a/shell.c
+++ b/shell.c
@@ -23,7 +23,6 @@
23#define FLAG_MOVES "-moves" 23#define FLAG_MOVES "-moves"
24#define FLAG_TRANS "-trans" 24#define FLAG_TRANS "-trans"
25#define FLAG_SOLVER "-solver" 25#define FLAG_SOLVER "-solver"
26#define FLAG_OPTIONS "-options"
27#define FLAG_NISSTYPE "-nisstype" 26#define FLAG_NISSTYPE "-nisstype"
28#define FLAG_MINMOVES "-m" 27#define FLAG_MINMOVES "-m"
29#define FLAG_MAXMOVES "-M" 28#define FLAG_MAXMOVES "-M"
@@ -50,7 +49,6 @@ typedef struct {
50 char *str_moves; 49 char *str_moves;
51 char *str_trans; 50 char *str_trans;
52 char *str_solver; 51 char *str_solver;
53 char *str_options; /* TODO: remove, use only solver */
54 char *str_nisstype; /* TODO: remove, use flags */ 52 char *str_nisstype; /* TODO: remove, use flags */
55 int8_t minmoves; 53 int8_t minmoves;
56 int8_t maxmoves; 54 int8_t maxmoves;
@@ -87,7 +85,6 @@ static bool set_str_format_out(int, char **, args_t *);
87static bool set_str_moves(int, char **, args_t *); 85static bool set_str_moves(int, char **, args_t *);
88static bool set_str_trans(int, char **, args_t *); 86static bool set_str_trans(int, char **, args_t *);
89static bool set_str_solver(int, char **, args_t *); 87static bool set_str_solver(int, char **, args_t *);
90static bool set_str_options(int, char **, args_t *);
91static bool set_str_nisstype(int, char **, args_t *); 88static bool set_str_nisstype(int, char **, args_t *);
92static bool set_minmoves(int, char **, args_t *); 89static bool set_minmoves(int, char **, args_t *);
93static bool set_maxmoves(int, char **, args_t *); 90static bool set_maxmoves(int, char **, args_t *);
@@ -113,7 +110,6 @@ struct {
113 OPTION(FLAG_MOVES, 1, set_str_moves), 110 OPTION(FLAG_MOVES, 1, set_str_moves),
114 OPTION(FLAG_TRANS, 1, set_str_trans), 111 OPTION(FLAG_TRANS, 1, set_str_trans),
115 OPTION(FLAG_SOLVER, 1, set_str_solver), 112 OPTION(FLAG_SOLVER, 1, set_str_solver),
116 OPTION(FLAG_OPTIONS, 1, set_str_options), /* TODO: remove, use only solver */
117 OPTION(FLAG_NISSTYPE, 1, set_str_nisstype), /* TODO: remove, use flags */ 113 OPTION(FLAG_NISSTYPE, 1, set_str_nisstype), /* TODO: remove, use flags */
118 OPTION(FLAG_MINMOVES, 1, set_minmoves), 114 OPTION(FLAG_MINMOVES, 1, set_minmoves),
119 OPTION(FLAG_MAXMOVES, 1, set_maxmoves), 115 OPTION(FLAG_MAXMOVES, 1, set_maxmoves),
@@ -183,21 +179,21 @@ struct {
183 ), 179 ),
184 COMMAND( 180 COMMAND(
185 "datasize", 181 "datasize",
186 "datasize " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS", 182 "datasize " FLAG_SOLVER " SOLVER",
187 "Return the size in bytes of the data table used by " 183 "Return the size in bytes of the data table used by "
188 "SOLVER when called with the given OPTIONS.", 184 "SOLVER when called with the given OPTIONS.",
189 datasize_exec 185 datasize_exec
190 ), 186 ),
191 COMMAND( 187 COMMAND(
192 "gendata", 188 "gendata",
193 "gendata " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS", 189 "gendata " FLAG_SOLVER " SOLVER",
194 "Generate the data table used by " 190 "Generate the data table used by "
195 "SOLVER when called with the given OPTIONS.", 191 "SOLVER when called with the given OPTIONS.",
196 gendata_exec 192 gendata_exec
197 ), 193 ),
198 COMMAND( 194 COMMAND(
199 "solve", 195 "solve",
200 "solve " FLAG_SOLVER " SOLVER " FLAG_OPTIONS " OPTIONS " 196 "solve " FLAG_SOLVER " SOLVER"
201 "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " 197 "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] "
202 FLAG_CUBE " CUBE", 198 FLAG_CUBE " CUBE",
203 "Solve the given CUBE using SOLVER with the given OPTIONS, " 199 "Solve the given CUBE using SOLVER with the given OPTIONS, "
@@ -357,7 +353,7 @@ datasize_exec(args_t *args)
357{ 353{
358 int64_t ret; 354 int64_t ret;
359 355
360 ret = nissy_datasize(args->str_solver, args->str_options); 356 ret = nissy_datasize(args->str_solver);
361 if (ret < 0) 357 if (ret < 0)
362 fprintf(stderr, "Unknown error (make sure solver is valid)\n"); 358 fprintf(stderr, "Unknown error (make sure solver is valid)\n");
363 printf("%" PRId64 "\n", ret); 359 printf("%" PRId64 "\n", ret);
@@ -389,7 +385,7 @@ gendata_exec(args_t *args)
389 return -2; 385 return -2;
390 } 386 }
391 387
392 size = nissy_datasize(args->str_solver, args->str_options); 388 size = nissy_datasize(args->str_solver);
393 389
394 if (size < 0) { 390 if (size < 0) {
395 fprintf(stderr, 391 fprintf(stderr,
@@ -401,7 +397,7 @@ gendata_exec(args_t *args)
401 397
402 buf = malloc(size); 398 buf = malloc(size);
403 399
404 ret = nissy_gendata(args->str_solver, args->str_options, buf); 400 ret = nissy_gendata(args->str_solver, buf);
405 if (ret < 0) { 401 if (ret < 0) {
406 fprintf(stderr, "Unknown error in generating data\n"); 402 fprintf(stderr, "Unknown error in generating data\n");
407 fclose(file); 403 fclose(file);
@@ -476,7 +472,7 @@ solve_exec(args_t *args)
476 return -1; 472 return -1;
477 } 473 }
478 474
479 size = nissy_datasize(args->str_solver, args->str_options); 475 size = nissy_datasize(args->str_solver);
480 buf = malloc(size); 476 buf = malloc(size);
481 read = fread(buf, size, 1, file); 477 read = fread(buf, size, 1, file);
482 fclose(file); 478 fclose(file);
@@ -488,9 +484,8 @@ solve_exec(args_t *args)
488 } 484 }
489 485
490 ret = nissy_solve( 486 ret = nissy_solve(
491 args->cube, args->str_solver, args->str_options, args->str_nisstype, 487 args->cube, args->str_solver, args->str_nisstype, args->minmoves,
492 args->minmoves, args->maxmoves, args->maxsolutions, args->optimal, 488 args->maxmoves, args->maxsolutions, args->optimal, buf, solutions);
493 buf, solutions);
494 489
495 free(buf); 490 free(buf);
496 491
@@ -545,7 +540,6 @@ parse_args(int argc, char **argv, args_t *args)
545 .str_moves = "", 540 .str_moves = "",
546 .str_trans = "", 541 .str_trans = "",
547 .str_solver = "", 542 .str_solver = "",
548 .str_options = "",
549 .str_nisstype = "", 543 .str_nisstype = "",
550 .minmoves = 0, 544 .minmoves = 0,
551 .maxmoves = 20, 545 .maxmoves = 20,
@@ -703,14 +697,6 @@ set_str_solver(int argc, char **argv, args_t *args)
703} 697}
704 698
705static bool 699static bool
706set_str_options(int argc, char **argv, args_t *args)
707{
708 args->str_options = argv[0];
709
710 return true;
711}
712
713static bool
714set_str_nisstype(int argc, char **argv, args_t *args) 700set_str_nisstype(int argc, char **argv, args_t *args)
715{ 701{
716 args->str_nisstype = argv[0]; 702 args->str_nisstype = argv[0];

Generated with cgit - Back to sebastiano.tronto.net