diff options
Diffstat (limited to '')
| -rw-r--r-- | shell/shell.c | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/shell/shell.c b/shell/shell.c index 2a1a8cd..0387856 100644 --- a/shell/shell.c +++ b/shell/shell.c | |||
| @@ -65,7 +65,7 @@ static int64_t applytrans_exec(args_t *); | |||
| 65 | static int64_t frommoves_exec(args_t *); | 65 | static int64_t frommoves_exec(args_t *); |
| 66 | static int64_t convert_exec(args_t *); | 66 | static int64_t convert_exec(args_t *); |
| 67 | static int64_t randomcube_exec(args_t *); | 67 | static int64_t randomcube_exec(args_t *); |
| 68 | static int64_t datasize_exec(args_t *); | 68 | static int64_t solverinfo_exec(args_t *); |
| 69 | static int64_t gendata_exec(args_t *); | 69 | static int64_t gendata_exec(args_t *); |
| 70 | static int64_t solve_exec(args_t *); | 70 | static int64_t solve_exec(args_t *); |
| 71 | static int64_t solve_scramble_exec(args_t *); | 71 | static int64_t solve_scramble_exec(args_t *); |
| @@ -180,11 +180,11 @@ struct { | |||
| 180 | randomcube_exec | 180 | randomcube_exec |
| 181 | ), | 181 | ), |
| 182 | COMMAND( | 182 | COMMAND( |
| 183 | "datasize", | 183 | "solverinfo", |
| 184 | "datasize " FLAG_SOLVER " SOLVER", | 184 | "solverinfo " FLAG_SOLVER " SOLVER", |
| 185 | "Return the size in bytes of the data table used by " | 185 | "Return the size in bytes and the id of the data table " |
| 186 | "SOLVER when called with the given OPTIONS.", | 186 | "used by SOLVER when called with the given OPTIONS.", |
| 187 | datasize_exec | 187 | solverinfo_exec |
| 188 | ), | 188 | ), |
| 189 | COMMAND( | 189 | COMMAND( |
| 190 | "gendata", | 190 | "gendata", |
| @@ -340,14 +340,15 @@ randomcube_exec(args_t *args) | |||
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | static int64_t | 342 | static int64_t |
| 343 | datasize_exec(args_t *args) | 343 | solverinfo_exec(args_t *args) |
| 344 | { | 344 | { |
| 345 | int64_t ret; | 345 | int64_t ret; |
| 346 | char buf[NISSY_DATAID_SIZE]; | ||
| 346 | 347 | ||
| 347 | ret = nissy_datasize(args->str_solver); | 348 | ret = nissy_solverinfo(args->str_solver, buf); |
| 348 | if (ret < 0) | 349 | if (ret < 0) |
| 349 | fprintf(stderr, "Unknown error (make sure solver is valid)\n"); | 350 | fprintf(stderr, "Unknown error (make sure solver is valid)\n"); |
| 350 | printf("%" PRId64 "\n", ret); | 351 | printf("%" PRId64 "\n%s\n", ret, buf); |
| 351 | 352 | ||
| 352 | return ret; | 353 | return ret; |
| 353 | } | 354 | } |
| @@ -357,14 +358,22 @@ gendata_exec(args_t *args) | |||
| 357 | { | 358 | { |
| 358 | int i; | 359 | int i; |
| 359 | FILE *file; | 360 | FILE *file; |
| 360 | char *buf, path[MAX_PATH_LENGTH]; | 361 | char *buf, path[MAX_PATH_LENGTH], dataid[NISSY_DATAID_SIZE]; |
| 361 | int64_t ret, size; | 362 | int64_t ret, size; |
| 362 | size_t written; | 363 | size_t written; |
| 363 | 364 | ||
| 365 | size = nissy_solverinfo(args->str_solver, dataid); | ||
| 366 | |||
| 367 | if (size < 0) { | ||
| 368 | fprintf(stderr, "gendata: unknown solver %s\n", | ||
| 369 | args->str_solver); | ||
| 370 | return -3; | ||
| 371 | } | ||
| 372 | |||
| 364 | /* TODO: should give warning if overwriting existing file */ | 373 | /* TODO: should give warning if overwriting existing file */ |
| 365 | for (i = 0; tablepaths[i] != NULL; i++) { | 374 | for (i = 0; tablepaths[i] != NULL; i++) { |
| 366 | strcpy(path, tablepaths[i]); | 375 | strcpy(path, tablepaths[i]); |
| 367 | strcat(path, args->str_solver); | 376 | strcat(path, dataid); |
| 368 | file = fopen(path, "wb"); | 377 | file = fopen(path, "wb"); |
| 369 | if (file != NULL) | 378 | if (file != NULL) |
| 370 | break; | 379 | break; |
| @@ -376,16 +385,6 @@ gendata_exec(args_t *args) | |||
| 376 | return -2; | 385 | return -2; |
| 377 | } | 386 | } |
| 378 | 387 | ||
| 379 | size = nissy_datasize(args->str_solver); | ||
| 380 | |||
| 381 | if (size < 0) { | ||
| 382 | fprintf(stderr, | ||
| 383 | "Unknown error in retrieving data size" | ||
| 384 | "(make sure solver is valid)\n"); | ||
| 385 | fclose(file); | ||
| 386 | return -3; | ||
| 387 | } | ||
| 388 | |||
| 389 | buf = malloc(size); | 388 | buf = malloc(size); |
| 390 | 389 | ||
| 391 | ret = nissy_gendata(args->str_solver, size, buf); | 390 | ret = nissy_gendata(args->str_solver, size, buf); |
| @@ -427,15 +426,24 @@ solve_exec(args_t *args) | |||
| 427 | uint8_t nissflag; | 426 | uint8_t nissflag; |
| 428 | FILE *file; | 427 | FILE *file; |
| 429 | char *buf, solutions[SOLUTIONS_BUFFER_SIZE], path[MAX_PATH_LENGTH]; | 428 | char *buf, solutions[SOLUTIONS_BUFFER_SIZE], path[MAX_PATH_LENGTH]; |
| 429 | char dataid[NISSY_DATAID_SIZE]; | ||
| 430 | long long stats[NISSY_SIZE_SOLVE_STATS]; | 430 | long long stats[NISSY_SIZE_SOLVE_STATS]; |
| 431 | int64_t ret, gendata_ret, size; | 431 | int64_t ret, gendata_ret, size; |
| 432 | size_t read; | 432 | size_t read; |
| 433 | 433 | ||
| 434 | nissflag = NISSY_NISSFLAG_NORMAL; /* TODO: parse str_nisstype */ | 434 | nissflag = NISSY_NISSFLAG_NORMAL; /* TODO: parse str_nisstype */ |
| 435 | 435 | ||
| 436 | size = nissy_solverinfo(args->str_solver, dataid); | ||
| 437 | |||
| 438 | if (size < 0) { | ||
| 439 | fprintf(stderr, "solve: unknown solver %s\n", | ||
| 440 | args->str_solver); | ||
| 441 | return size; | ||
| 442 | } | ||
| 443 | |||
| 436 | for (i = 0; tablepaths[i] != NULL; i++) { | 444 | for (i = 0; tablepaths[i] != NULL; i++) { |
| 437 | strcpy(path, tablepaths[i]); | 445 | strcpy(path, tablepaths[i]); |
| 438 | strcat(path, args->str_solver); | 446 | strcat(path, dataid); |
| 439 | file = fopen(path, "rb"); | 447 | file = fopen(path, "rb"); |
| 440 | if (file != NULL) | 448 | if (file != NULL) |
| 441 | break; | 449 | break; |
| @@ -454,7 +462,7 @@ solve_exec(args_t *args) | |||
| 454 | if (file == NULL) { | 462 | if (file == NULL) { |
| 455 | for (i = 0; tablepaths[i] != NULL; i++) { | 463 | for (i = 0; tablepaths[i] != NULL; i++) { |
| 456 | strcpy(path, tablepaths[i]); | 464 | strcpy(path, tablepaths[i]); |
| 457 | strcat(path, args->str_solver); | 465 | strcat(path, dataid); |
| 458 | file = fopen(path, "rb"); | 466 | file = fopen(path, "rb"); |
| 459 | if (file != NULL) | 467 | if (file != NULL) |
| 460 | break; | 468 | break; |
| @@ -467,7 +475,6 @@ solve_exec(args_t *args) | |||
| 467 | return -1; | 475 | return -1; |
| 468 | } | 476 | } |
| 469 | 477 | ||
| 470 | size = nissy_datasize(args->str_solver); | ||
| 471 | buf = malloc(size); | 478 | buf = malloc(size); |
| 472 | read = fread(buf, size, 1, file); | 479 | read = fread(buf, size, 1, file); |
| 473 | fclose(file); | 480 | fclose(file); |
