diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-08 15:30:22 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-08 15:30:22 +0200 |
| commit | ff7cee6df128cbf6b05c57585fd9b8ca8f3665f4 (patch) | |
| tree | 6d6279e1974414e90f739454001abf359e586797 | |
| parent | 5e7c8b2f3684d8de1c2722515f693c2e54323208 (diff) | |
| download | nissy-core-ff7cee6df128cbf6b05c57585fd9b8ca8f3665f4.tar.gz nissy-core-ff7cee6df128cbf6b05c57585fd9b8ca8f3665f4.zip | |
Fixed shell; reorganized nissy.h
Diffstat (limited to '')
| -rw-r--r-- | shell/shell.c | 14 | ||||
| -rw-r--r-- | src/nissy.h | 186 |
2 files changed, 98 insertions, 102 deletions
diff --git a/shell/shell.c b/shell/shell.c index 4b354c6..6b349e5 100644 --- a/shell/shell.c +++ b/shell/shell.c | |||
| @@ -344,7 +344,7 @@ static int64_t | |||
| 344 | solverinfo_exec(args_t *args) | 344 | solverinfo_exec(args_t *args) |
| 345 | { | 345 | { |
| 346 | int64_t ret; | 346 | int64_t ret; |
| 347 | char buf[NISSY_DATAID_SIZE]; | 347 | char buf[NISSY_SIZE_DATAID]; |
| 348 | 348 | ||
| 349 | ret = nissy_solverinfo(args->str_solver, buf); | 349 | ret = nissy_solverinfo(args->str_solver, buf); |
| 350 | if (ret < 0) | 350 | if (ret < 0) |
| @@ -359,7 +359,7 @@ gendata_exec(args_t *args) | |||
| 359 | { | 359 | { |
| 360 | int i; | 360 | int i; |
| 361 | FILE *file; | 361 | FILE *file; |
| 362 | char *buf, path[MAX_PATH_LENGTH], dataid[NISSY_DATAID_SIZE]; | 362 | char *buf, path[MAX_PATH_LENGTH], dataid[NISSY_SIZE_DATAID]; |
| 363 | int64_t ret, size; | 363 | int64_t ret, size; |
| 364 | size_t written; | 364 | size_t written; |
| 365 | 365 | ||
| @@ -427,7 +427,7 @@ solve_exec(args_t *args) | |||
| 427 | uint8_t nissflag; | 427 | uint8_t nissflag; |
| 428 | FILE *file; | 428 | FILE *file; |
| 429 | char *buf, solutions[SOLUTIONS_BUFFER_SIZE], path[MAX_PATH_LENGTH]; | 429 | char *buf, solutions[SOLUTIONS_BUFFER_SIZE], path[MAX_PATH_LENGTH]; |
| 430 | char dataid[NISSY_DATAID_SIZE]; | 430 | char dataid[NISSY_SIZE_DATAID]; |
| 431 | long long stats[NISSY_SIZE_SOLVE_STATS]; | 431 | long long stats[NISSY_SIZE_SOLVE_STATS]; |
| 432 | int64_t ret, gendata_ret, size; | 432 | int64_t ret, gendata_ret, size; |
| 433 | size_t read; | 433 | size_t read; |
| @@ -780,13 +780,9 @@ set_threads(int argc, char **argv, args_t *args) | |||
| 780 | } | 780 | } |
| 781 | 781 | ||
| 782 | void | 782 | void |
| 783 | log_stderr(const char *str, ...) | 783 | log_stderr(const char *str) |
| 784 | { | 784 | { |
| 785 | va_list args; | 785 | fprintf(stderr, "%s", str); |
| 786 | |||
| 787 | va_start(args, str); | ||
| 788 | vfprintf(stderr, str, args); | ||
| 789 | va_end(args); | ||
| 790 | } | 786 | } |
| 791 | 787 | ||
| 792 | int | 788 | int |
diff --git a/src/nissy.h b/src/nissy.h index 42429d3..a6a0ac1 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -40,6 +40,99 @@ for example 'rotation UF' or 'mirrored BL'. | |||
| 40 | #define NISSY_SOLVED_CUBE "ABCDEFGH=ABCDEFGHIJKL" | 40 | #define NISSY_SOLVED_CUBE "ABCDEFGH=ABCDEFGHIJKL" |
| 41 | 41 | ||
| 42 | 42 | ||
| 43 | /* Error codes ***************************************************************/ | ||
| 44 | |||
| 45 | /* | ||
| 46 | The value NISSY_OK denotes a success. If returned by solve, it means | ||
| 47 | that no solution has been found. | ||
| 48 | */ | ||
| 49 | #define NISSY_OK 0LL | ||
| 50 | |||
| 51 | /* | ||
| 52 | The value NISSY_WARNING_UNSOLVABLE is a warning. It means that the | ||
| 53 | operation was completed succesfully, but the resulting cube is in an | ||
| 54 | unsolvable state. This could be intended, for example if the user has | ||
| 55 | provided an unsolvable cube as input. | ||
| 56 | */ | ||
| 57 | #define NISSY_WARNING_UNSOLVABLE -1LL | ||
| 58 | |||
| 59 | /* | ||
| 60 | The value NISSY_ERROR_INVALID_CUBE means that the provided cube is | ||
| 61 | invalid. It could be written in an unknown format, or in a format | ||
| 62 | different from what specified, or simply ill-formed. | ||
| 63 | */ | ||
| 64 | #define NISSY_ERROR_INVALID_CUBE -10LL | ||
| 65 | |||
| 66 | /* | ||
| 67 | The value NISSY_ERROR_UNSOLVABLE_CUBE means that the provided cube is in | ||
| 68 | an unsolvable state for the given solver. This could mean either that the | ||
| 69 | cube is not solvable at all (for example in case it has a single twisted | ||
| 70 | corner), or that it is not ready for the given step (for example if the | ||
| 71 | caller wants to solve a DR finish without the cube being in DR state). | ||
| 72 | */ | ||
| 73 | #define NISSY_ERROR_UNSOLVABLE_CUBE -11LL | ||
| 74 | |||
| 75 | /* | ||
| 76 | The value NISSY_ERROR_INVALID_MOVES means that the given moves are | ||
| 77 | invalid. | ||
| 78 | */ | ||
| 79 | #define NISSY_ERROR_INVALID_MOVES -20LL | ||
| 80 | |||
| 81 | /* | ||
| 82 | The value NISSY_ERROR_INVALID_TRANS means that the given transformation | ||
| 83 | is invalid. | ||
| 84 | */ | ||
| 85 | #define NISSY_ERROR_INVALID_TRANS -30LL | ||
| 86 | |||
| 87 | /* | ||
| 88 | The value NISSY_ERROR_INVALID_FORMAT means that the given format is | ||
| 89 | not known. | ||
| 90 | */ | ||
| 91 | #define NISSY_ERROR_INVALID_FORMAT -40LL | ||
| 92 | |||
| 93 | /* | ||
| 94 | The value NISSY_ERROR_INVALID_SOLVER means that the given solver is | ||
| 95 | not known. | ||
| 96 | */ | ||
| 97 | #define NISSY_ERROR_INVALID_SOLVER -50LL | ||
| 98 | |||
| 99 | /* | ||
| 100 | The value NISSY_ERROR_NULL_POINTER means that one of the provided pointer | ||
| 101 | arguments is NULL. For example, it may be returned by solve when called | ||
| 102 | with a solver that requires some pre-computed data, but the provided | ||
| 103 | data is NULL. | ||
| 104 | */ | ||
| 105 | #define NISSY_ERROR_NULL_POINTER -60LL | ||
| 106 | |||
| 107 | /* | ||
| 108 | The value NISSY_ERROR_BUFFER_SIZE means that one of the buffers provided | ||
| 109 | is too small. For example, it could be too small to hold the result or | ||
| 110 | too small to hold the data generated by gendata. | ||
| 111 | */ | ||
| 112 | #define NISSY_ERROR_BUFFER_SIZE -61LL | ||
| 113 | |||
| 114 | /* | ||
| 115 | The value NISSY_ERROR_DATA means that the provided data is invalid. For | ||
| 116 | example, it may be returned by solve when called with incompatible solver | ||
| 117 | and data arguments. | ||
| 118 | */ | ||
| 119 | #define NISSY_ERROR_DATA -70LL | ||
| 120 | |||
| 121 | /* | ||
| 122 | The value NISSY_ERROR_OPTIONS means that one or more of the given options | ||
| 123 | are invalid. For example, it may be returned by solve when called with | ||
| 124 | a negative maximum number of solutions. | ||
| 125 | */ | ||
| 126 | #define NISSY_ERROR_OPTIONS -80LL | ||
| 127 | |||
| 128 | /* | ||
| 129 | The value NISSY_ERROR_UNKNOWN denotes an unexpected error. It probably | ||
| 130 | means that there some bug in this library. If you can, report any error | ||
| 131 | of this kind to sebastiano@tronto.net. Thanks! | ||
| 132 | */ | ||
| 133 | #define NISSY_ERROR_UNKNOWN -999LL | ||
| 134 | |||
| 135 | |||
| 43 | /* Library functions *********************************************************/ | 136 | /* Library functions *********************************************************/ |
| 44 | 137 | ||
| 45 | /* | 138 | /* |
| @@ -338,96 +431,3 @@ long long | |||
| 338 | nissy_setlogger( | 431 | nissy_setlogger( |
| 339 | void (*logger_function)(const char *) | 432 | void (*logger_function)(const char *) |
| 340 | ); | 433 | ); |
| 341 | |||
| 342 | |||
| 343 | /* Error codes ***************************************************************/ | ||
| 344 | |||
| 345 | /* | ||
| 346 | The value NISSY_OK denotes a success. If returned by solve, it means | ||
| 347 | that no solution has been found. | ||
| 348 | */ | ||
| 349 | #define NISSY_OK 0LL | ||
| 350 | |||
| 351 | /* | ||
| 352 | The value NISSY_WARNING_UNSOLVABLE is a warning. It means that the | ||
| 353 | operation was completed succesfully, but the resulting cube is in an | ||
| 354 | unsolvable state. This could be intended, for example if the user has | ||
| 355 | provided an unsolvable cube as input. | ||
| 356 | */ | ||
| 357 | #define NISSY_WARNING_UNSOLVABLE -1LL | ||
| 358 | |||
| 359 | /* | ||
| 360 | The value NISSY_ERROR_INVALID_CUBE means that the provided cube is | ||
| 361 | invalid. It could be written in an unknown format, or in a format | ||
| 362 | different from what specified, or simply ill-formed. | ||
| 363 | */ | ||
| 364 | #define NISSY_ERROR_INVALID_CUBE -10LL | ||
| 365 | |||
| 366 | /* | ||
| 367 | The value NISSY_ERROR_UNSOLVABLE_CUBE means that the provided cube is in | ||
| 368 | an unsolvable state for the given solver. This could mean either that the | ||
| 369 | cube is not solvable at all (for example in case it has a single twisted | ||
| 370 | corner), or that it is not ready for the given step (for example if the | ||
| 371 | caller wants to solve a DR finish without the cube being in DR state). | ||
| 372 | */ | ||
| 373 | #define NISSY_ERROR_UNSOLVABLE_CUBE -11LL | ||
| 374 | |||
| 375 | /* | ||
| 376 | The value NISSY_ERROR_INVALID_MOVES means that the given moves are | ||
| 377 | invalid. | ||
| 378 | */ | ||
| 379 | #define NISSY_ERROR_INVALID_MOVES -20LL | ||
| 380 | |||
| 381 | /* | ||
| 382 | The value NISSY_ERROR_INVALID_TRANS means that the given transformation | ||
| 383 | is invalid. | ||
| 384 | */ | ||
| 385 | #define NISSY_ERROR_INVALID_TRANS -30LL | ||
| 386 | |||
| 387 | /* | ||
| 388 | The value NISSY_ERROR_INVALID_FORMAT means that the given format is | ||
| 389 | not known. | ||
| 390 | */ | ||
| 391 | #define NISSY_ERROR_INVALID_FORMAT -40LL | ||
| 392 | |||
| 393 | /* | ||
| 394 | The value NISSY_ERROR_INVALID_SOLVER means that the given solver is | ||
| 395 | not known. | ||
| 396 | */ | ||
| 397 | #define NISSY_ERROR_INVALID_SOLVER -50LL | ||
| 398 | |||
| 399 | /* | ||
| 400 | The value NISSY_ERROR_NULL_POINTER means that one of the provided pointer | ||
| 401 | arguments is NULL. For example, it may be returned by solve when called | ||
| 402 | with a solver that requires some pre-computed data, but the provided | ||
| 403 | data is NULL. | ||
| 404 | */ | ||
| 405 | #define NISSY_ERROR_NULL_POINTER -60LL | ||
| 406 | |||
| 407 | /* | ||
| 408 | The value NISSY_ERROR_BUFFER_SIZE means that one of the buffers provided | ||
| 409 | is too small. For example, it could be too small to hold the result or | ||
| 410 | too small to hold the data generated by gendata. | ||
| 411 | */ | ||
| 412 | #define NISSY_ERROR_BUFFER_SIZE -61LL | ||
| 413 | |||
| 414 | /* | ||
| 415 | The value NISSY_ERROR_DATA means that the provided data is invalid. For | ||
| 416 | example, it may be returned by solve when called with incompatible solver | ||
| 417 | and data arguments. | ||
| 418 | */ | ||
| 419 | #define NISSY_ERROR_DATA -70LL | ||
| 420 | |||
| 421 | /* | ||
| 422 | The value NISSY_ERROR_OPTIONS means that one or more of the given options | ||
| 423 | are invalid. For example, it may be returned by solve when called with | ||
| 424 | a negative maximum number of solutions. | ||
| 425 | */ | ||
| 426 | #define NISSY_ERROR_OPTIONS -80LL | ||
| 427 | |||
| 428 | /* | ||
| 429 | The value NISSY_ERROR_UNKNOWN denotes an unexpected error. It probably | ||
| 430 | means that there some bug in this library. If you can, report any error | ||
| 431 | of this kind to sebastiano@tronto.net. Thanks! | ||
| 432 | */ | ||
| 433 | #define NISSY_ERROR_UNKNOWN -999LL | ||
