diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/io_cube.h | 103 | ||||
| -rw-r--r-- | src/nissy.c | 73 | ||||
| -rw-r--r-- | src/nissy.h | 33 | ||||
| -rw-r--r-- | test/020_io_H48_read_write/io_H48_tests.c | 2 | ||||
| -rw-r--r-- | test/021_io_B32_write/io_B32_read_tests.c | 2 | ||||
| -rw-r--r-- | test/022_io_B32_read/io_B32_read_tests.c | 2 | ||||
| -rw-r--r-- | test/023_io_LST_write/io_LST_write_tests.c | 2 | ||||
| -rw-r--r-- | test/024_io_LST_read/io_LST_read_tests.c | 2 | ||||
| -rw-r--r-- | test/030_move/move_tests.c | 2 | ||||
| -rw-r--r-- | test/031_premove/premove_tests.c | 2 | ||||
| -rw-r--r-- | test/040_inverse_cube/inverse_tests.c | 2 | ||||
| -rw-r--r-- | test/050_compose/compose_tests.c | 2 | ||||
| -rw-r--r-- | test/060_transform/transform_tests.c | 2 | ||||
| -rw-r--r-- | test/075_set_eo/set_eo_tests.c | 2 | ||||
| -rw-r--r-- | test/076_copy_corners/copy_corners_tests.c | 2 | ||||
| -rw-r--r-- | test/077_copy_edges/copy_edges_tests.c | 2 | ||||
| -rw-r--r-- | test/081_getcube/getcube_tests.c | 2 | ||||
| -rw-r--r-- | test/test.h | 4 |
18 files changed, 130 insertions, 111 deletions
diff --git a/src/core/io_cube.h b/src/core/io_cube.h index 1ac8ec7..0c18f34 100644 --- a/src/core/io_cube.h +++ b/src/core/io_cube.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | STATIC cube_t readcube(const char *, const char *); | 1 | STATIC cube_t readcube(const char *, const char *); |
| 2 | STATIC int writecube(const char *, cube_t, char *); | 2 | STATIC int64_t writecube(const char *, cube_t, uint64_t, char *); |
| 3 | STATIC void log_available_formats(void); | 3 | STATIC void log_available_formats(void); |
| 4 | STATIC uint8_t readco(const char *); | 4 | STATIC uint8_t readco(const char *); |
| 5 | STATIC uint8_t readcp(const char *); | 5 | STATIC uint8_t readcp(const char *); |
| @@ -10,10 +10,10 @@ STATIC cube_t readcube_H48(const char *); | |||
| 10 | STATIC uint8_t readpiece_LST(const char **); | 10 | STATIC uint8_t readpiece_LST(const char **); |
| 11 | STATIC cube_t readcube_LST(const char *); | 11 | STATIC cube_t readcube_LST(const char *); |
| 12 | 12 | ||
| 13 | STATIC int writepiece_LST(uint8_t, char *); | 13 | STATIC int64_t writepiece_LST(uint8_t, uint64_t, char *); |
| 14 | STATIC void writecube_B32(cube_t, char *); | 14 | STATIC int64_t writecube_B32(cube_t, uint64_t, char *); |
| 15 | STATIC void writecube_H48(cube_t, char *); | 15 | STATIC int64_t writecube_H48(cube_t, uint64_t, char *); |
| 16 | STATIC void writecube_LST(cube_t, char *); | 16 | STATIC int64_t writecube_LST(cube_t, uint64_t, char *); |
| 17 | 17 | ||
| 18 | STATIC uint8_t b32toedge(char); | 18 | STATIC uint8_t b32toedge(char); |
| 19 | STATIC uint8_t b32tocorner(char); | 19 | STATIC uint8_t b32tocorner(char); |
| @@ -23,7 +23,7 @@ STATIC char cornertob32(uint8_t); | |||
| 23 | STATIC struct { | 23 | STATIC struct { |
| 24 | const char *name; | 24 | const char *name; |
| 25 | cube_t (*read)(const char *); | 25 | cube_t (*read)(const char *); |
| 26 | void (*write)(cube_t, char *); | 26 | int64_t (*write)(cube_t, uint64_t, char *); |
| 27 | } ioformat[] = | 27 | } ioformat[] = |
| 28 | { | 28 | { |
| 29 | { .name = "B32", .read = readcube_B32, .write = writecube_B32 }, | 29 | { .name = "B32", .read = readcube_B32, .write = writecube_B32 }, |
| @@ -46,35 +46,18 @@ readcube(const char *format, const char *buf) | |||
| 46 | return ZERO_CUBE; | 46 | return ZERO_CUBE; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | STATIC int | 49 | STATIC int64_t |
| 50 | writecube(const char *format, cube_t cube, char *buf) | 50 | writecube(const char *format, cube_t cube, uint64_t buf_size, char *buf) |
| 51 | { | 51 | { |
| 52 | char *errormsg; | ||
| 53 | size_t len; | ||
| 54 | |||
| 55 | if (!isconsistent(cube)) { | ||
| 56 | errormsg = "ERROR: inconsistent"; | ||
| 57 | goto writecube_error; | ||
| 58 | } | ||
| 59 | |||
| 60 | int i; | 52 | int i; |
| 61 | 53 | ||
| 62 | for (i = 0; ioformat[i].write != NULL; i++) { | 54 | for (i = 0; ioformat[i].write != NULL; i++) |
| 63 | if (!strcmp(format, ioformat[i].name)) { | 55 | if (!strcmp(format, ioformat[i].name)) |
| 64 | ioformat[i].write(cube, buf); | 56 | return ioformat[i].write(cube, buf_size, buf); |
| 65 | return 0; | ||
| 66 | } | ||
| 67 | } | ||
| 68 | 57 | ||
| 69 | LOG("Cannot write cube: unknown format '%s'\n", format); | 58 | LOG("Cannot write cube: unknown format '%s'\n", format); |
| 70 | log_available_formats(); | 59 | log_available_formats(); |
| 71 | errormsg = "ERROR: format"; | 60 | return NISSY_ERROR_INVALID_FORMAT; |
| 72 | |||
| 73 | writecube_error: | ||
| 74 | len = strlen(errormsg); | ||
| 75 | memcpy(buf, errormsg, len); | ||
| 76 | buf[len] = '\0'; | ||
| 77 | return 1; | ||
| 78 | } | 61 | } |
| 79 | 62 | ||
| 80 | STATIC void | 63 | STATIC void |
| @@ -249,11 +232,14 @@ readcube_LST(const char *buf) | |||
| 249 | return cubefromarray(c, e); | 232 | return cubefromarray(c, e); |
| 250 | } | 233 | } |
| 251 | 234 | ||
| 252 | STATIC int | 235 | STATIC int64_t |
| 253 | writepiece_LST(uint8_t piece, char *buf) | 236 | writepiece_LST(uint8_t piece, uint64_t buf_size, char *buf) |
| 254 | { | 237 | { |
| 255 | char digits[3]; | 238 | char digits[3]; |
| 256 | int i, len; | 239 | uint64_t i, len; |
| 240 | |||
| 241 | if (piece > 99 || buf_size < 3) | ||
| 242 | return 0; | ||
| 257 | 243 | ||
| 258 | len = 0; | 244 | len = 0; |
| 259 | while (piece != 0) { | 245 | while (piece != 0) { |
| @@ -261,6 +247,9 @@ writepiece_LST(uint8_t piece, char *buf) | |||
| 261 | piece /= 10; | 247 | piece /= 10; |
| 262 | } | 248 | } |
| 263 | 249 | ||
| 250 | if (buf_size < len+2) | ||
| 251 | return 0; | ||
| 252 | |||
| 264 | if (len == 0) | 253 | if (len == 0) |
| 265 | digits[len++] = '0'; | 254 | digits[len++] = '0'; |
| 266 | 255 | ||
| @@ -273,12 +262,19 @@ writepiece_LST(uint8_t piece, char *buf) | |||
| 273 | return len+2; | 262 | return len+2; |
| 274 | } | 263 | } |
| 275 | 264 | ||
| 276 | STATIC void | 265 | STATIC int64_t |
| 277 | writecube_B32(cube_t cube, char *buf) | 266 | writecube_B32(cube_t cube, uint64_t buf_size, char *buf) |
| 278 | { | 267 | { |
| 279 | int i; | 268 | int i; |
| 280 | uint8_t corner[8], edge[12]; | 269 | uint8_t corner[8], edge[12]; |
| 281 | 270 | ||
| 271 | if (buf_size < NISSY_SIZE_B32) { | ||
| 272 | LOG("Cannot write cube in B32 format: buffer size must be " | ||
| 273 | "at least %" PRIu64 " bytes, but the provided one is %" | ||
| 274 | PRIu64 " bytes.\n", NISSY_SIZE_B32, buf_size); | ||
| 275 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 276 | } | ||
| 277 | |||
| 282 | pieces(&cube, corner, edge); | 278 | pieces(&cube, corner, edge); |
| 283 | 279 | ||
| 284 | for (i = 0; i < 8; i++) | 280 | for (i = 0; i < 8; i++) |
| @@ -290,14 +286,23 @@ writecube_B32(cube_t cube, char *buf) | |||
| 290 | buf[i+9] = edgetob32(edge[i]); | 286 | buf[i+9] = edgetob32(edge[i]); |
| 291 | 287 | ||
| 292 | buf[21] = '\0'; | 288 | buf[21] = '\0'; |
| 289 | |||
| 290 | return NISSY_OK; | ||
| 293 | } | 291 | } |
| 294 | 292 | ||
| 295 | STATIC void | 293 | STATIC int64_t |
| 296 | writecube_H48(cube_t cube, char *buf) | 294 | writecube_H48(cube_t cube, uint64_t buf_size, char *buf) |
| 297 | { | 295 | { |
| 298 | uint8_t piece, perm, orient, corner[8], edge[12]; | 296 | uint8_t piece, perm, orient, corner[8], edge[12]; |
| 299 | int i; | 297 | int i; |
| 300 | 298 | ||
| 299 | if (buf_size < NISSY_SIZE_H48) { | ||
| 300 | LOG("Cannot write cube in H48 format: buffer size must be " | ||
| 301 | "at least %" PRIu64 " bytes, but the provided one is %" | ||
| 302 | PRIu64 " bytes.\n", NISSY_SIZE_H48, buf_size); | ||
| 303 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 304 | } | ||
| 305 | |||
| 301 | pieces(&cube, corner, edge); | 306 | pieces(&cube, corner, edge); |
| 302 | 307 | ||
| 303 | for (i = 0; i < 12; i++) { | 308 | for (i = 0; i < 12; i++) { |
| @@ -321,13 +326,15 @@ writecube_H48(cube_t cube, char *buf) | |||
| 321 | } | 326 | } |
| 322 | 327 | ||
| 323 | buf[48+39] = '\0'; | 328 | buf[48+39] = '\0'; |
| 329 | |||
| 330 | return NISSY_OK; | ||
| 324 | } | 331 | } |
| 325 | 332 | ||
| 326 | STATIC void | 333 | STATIC int64_t |
| 327 | writecube_LST(cube_t cube, char *buf) | 334 | writecube_LST(cube_t cube, uint64_t buf_size, char *buf) |
| 328 | { | 335 | { |
| 329 | int i; | 336 | int i; |
| 330 | size_t ptr; | 337 | uint64_t ptr; |
| 331 | uint8_t piece, corner[8], edge[12]; | 338 | uint8_t piece, corner[8], edge[12]; |
| 332 | 339 | ||
| 333 | ptr = 0; | 340 | ptr = 0; |
| @@ -335,15 +342,27 @@ writecube_LST(cube_t cube, char *buf) | |||
| 335 | 342 | ||
| 336 | for (i = 0; i < 8; i++) { | 343 | for (i = 0; i < 8; i++) { |
| 337 | piece = corner[i]; | 344 | piece = corner[i]; |
| 338 | ptr += writepiece_LST(piece, buf + ptr); | 345 | ptr += writepiece_LST(piece, buf_size - ptr, buf + ptr); |
| 346 | if (ptr == 0) | ||
| 347 | goto writecube_LST_error; | ||
| 339 | } | 348 | } |
| 340 | 349 | ||
| 341 | for (i = 0; i < 12; i++) { | 350 | for (i = 0; i < 12; i++) { |
| 342 | piece = edge[i]; | 351 | piece = edge[i]; |
| 343 | ptr += writepiece_LST(piece, buf + ptr); | 352 | ptr += writepiece_LST(piece, buf_size - ptr, buf + ptr); |
| 353 | if (ptr == 0) | ||
| 354 | goto writecube_LST_error; | ||
| 344 | } | 355 | } |
| 345 | 356 | ||
| 346 | *(buf+ptr-2) = 0; | 357 | *(buf+ptr-2) = '\0'; |
| 358 | |||
| 359 | return NISSY_OK; | ||
| 360 | |||
| 361 | writecube_LST_error: | ||
| 362 | LOG("Cannot write cube in LST: buffer is too small (%" PRIu64 | ||
| 363 | " bytes given). The LST format has a variable size, try a " | ||
| 364 | "larger buffer.\n", buf_size); | ||
| 365 | return NISSY_ERROR_BUFFER_SIZE; | ||
| 347 | } | 366 | } |
| 348 | 367 | ||
| 349 | STATIC uint8_t | 368 | STATIC uint8_t |
diff --git a/src/nissy.c b/src/nissy.c index bc608de..d725599 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -5,15 +5,14 @@ | |||
| 5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
| 6 | #include <string.h> | 6 | #include <string.h> |
| 7 | 7 | ||
| 8 | #include "nissy.h" | ||
| 8 | #include "utils/utils.h" | 9 | #include "utils/utils.h" |
| 9 | #include "arch/arch.h" | 10 | #include "arch/arch.h" |
| 10 | #include "core/core.h" | 11 | #include "core/core.h" |
| 11 | #include "solvers/solvers.h" | 12 | #include "solvers/solvers.h" |
| 12 | 13 | ||
| 13 | #include "nissy.h" | ||
| 14 | |||
| 15 | int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); | 14 | int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); |
| 16 | STATIC int64_t write_result(cube_t, char [static 22]); | 15 | STATIC int64_t write_result(cube_t, char [static NISSY_SIZE_B32]); |
| 17 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], | 16 | STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], |
| 18 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); | 17 | const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); |
| 19 | STATIC bool checkdata(const char *, const tableinfo_t *); | 18 | STATIC bool checkdata(const char *, const tableinfo_t *); |
| @@ -107,9 +106,9 @@ distribution_equal( | |||
| 107 | } | 106 | } |
| 108 | 107 | ||
| 109 | STATIC int64_t | 108 | STATIC int64_t |
| 110 | write_result(cube_t cube, char result[static 22]) | 109 | write_result(cube_t cube, char result[static NISSY_SIZE_B32]) |
| 111 | { | 110 | { |
| 112 | writecube("B32", cube, result); | 111 | writecube("B32", cube, NISSY_SIZE_B32, result); |
| 113 | 112 | ||
| 114 | if (!issolvable(cube)) { | 113 | if (!issolvable(cube)) { |
| 115 | LOG("Warning: resulting cube is not solvable\n"); | 114 | LOG("Warning: resulting cube is not solvable\n"); |
| @@ -121,9 +120,9 @@ write_result(cube_t cube, char result[static 22]) | |||
| 121 | 120 | ||
| 122 | int64_t | 121 | int64_t |
| 123 | nissy_compose( | 122 | nissy_compose( |
| 124 | const char cube[static 22], | 123 | const char cube[static NISSY_SIZE_B32], |
| 125 | const char permutation[static 22], | 124 | const char permutation[static NISSY_SIZE_B32], |
| 126 | char result[static 22] | 125 | char result[static NISSY_SIZE_B32] |
| 127 | ) | 126 | ) |
| 128 | { | 127 | { |
| 129 | cube_t c, p, res; | 128 | cube_t c, p, res; |
| @@ -156,14 +155,14 @@ nissy_compose( | |||
| 156 | return write_result(res, result); | 155 | return write_result(res, result); |
| 157 | 156 | ||
| 158 | nissy_compose_error: | 157 | nissy_compose_error: |
| 159 | writecube("B32", ZERO_CUBE, result); | 158 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); |
| 160 | return err; | 159 | return err; |
| 161 | } | 160 | } |
| 162 | 161 | ||
| 163 | int64_t | 162 | int64_t |
| 164 | nissy_inverse( | 163 | nissy_inverse( |
| 165 | const char cube[static 22], | 164 | const char cube[static NISSY_SIZE_B32], |
| 166 | char result[static 22] | 165 | char result[static NISSY_SIZE_B32] |
| 167 | ) | 166 | ) |
| 168 | { | 167 | { |
| 169 | cube_t c, res; | 168 | cube_t c, res; |
| @@ -188,15 +187,15 @@ nissy_inverse( | |||
| 188 | return write_result(res, result); | 187 | return write_result(res, result); |
| 189 | 188 | ||
| 190 | nissy_inverse_error: | 189 | nissy_inverse_error: |
| 191 | writecube("B32", ZERO_CUBE, result); | 190 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); |
| 192 | return err; | 191 | return err; |
| 193 | } | 192 | } |
| 194 | 193 | ||
| 195 | int64_t | 194 | int64_t |
| 196 | nissy_applymoves( | 195 | nissy_applymoves( |
| 197 | const char cube[static 22], | 196 | const char cube[static NISSY_SIZE_B32], |
| 198 | const char *moves, | 197 | const char *moves, |
| 199 | char result[static 22] | 198 | char result[static NISSY_SIZE_B32] |
| 200 | ) | 199 | ) |
| 201 | { | 200 | { |
| 202 | cube_t c, res; | 201 | cube_t c, res; |
| @@ -227,15 +226,15 @@ nissy_applymoves( | |||
| 227 | return write_result(res, result); | 226 | return write_result(res, result); |
| 228 | 227 | ||
| 229 | nissy_applymoves_error: | 228 | nissy_applymoves_error: |
| 230 | writecube("B32", ZERO_CUBE, result); | 229 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); |
| 231 | return err; | 230 | return err; |
| 232 | } | 231 | } |
| 233 | 232 | ||
| 234 | int64_t | 233 | int64_t |
| 235 | nissy_applytrans( | 234 | nissy_applytrans( |
| 236 | const char cube[static 22], | 235 | const char cube[static NISSY_SIZE_B32], |
| 237 | const char transformation[static 12], | 236 | const char transformation[static NISSY_SIZE_TRANSFORMATION], |
| 238 | char result[static 22] | 237 | char result[static NISSY_SIZE_B32] |
| 239 | ) | 238 | ) |
| 240 | { | 239 | { |
| 241 | cube_t c, res; | 240 | cube_t c, res; |
| @@ -260,14 +259,14 @@ nissy_applytrans( | |||
| 260 | return write_result(res, result); | 259 | return write_result(res, result); |
| 261 | 260 | ||
| 262 | nissy_applytrans_error: | 261 | nissy_applytrans_error: |
| 263 | writecube("B32", ZERO_CUBE, result); | 262 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); |
| 264 | return err; | 263 | return err; |
| 265 | } | 264 | } |
| 266 | 265 | ||
| 267 | int64_t | 266 | int64_t |
| 268 | nissy_frommoves( | 267 | nissy_frommoves( |
| 269 | const char *moves, | 268 | const char *moves, |
| 270 | char result[static 22] | 269 | char result[static NISSY_SIZE_B32] |
| 271 | ) | 270 | ) |
| 272 | { | 271 | { |
| 273 | cube_t res; | 272 | cube_t res; |
| @@ -290,7 +289,7 @@ nissy_frommoves( | |||
| 290 | return write_result(res, result); | 289 | return write_result(res, result); |
| 291 | 290 | ||
| 292 | nissy_frommoves_error: | 291 | nissy_frommoves_error: |
| 293 | writecube("B32", ZERO_CUBE, result); | 292 | writecube("B32", ZERO_CUBE, NISSY_SIZE_B32, result); |
| 294 | return err; | 293 | return err; |
| 295 | } | 294 | } |
| 296 | 295 | ||
| @@ -304,7 +303,6 @@ nissy_convert( | |||
| 304 | ) | 303 | ) |
| 305 | { | 304 | { |
| 306 | cube_t c; | 305 | cube_t c; |
| 307 | int ret; | ||
| 308 | int64_t err; | 306 | int64_t err; |
| 309 | 307 | ||
| 310 | if (format_in == NULL) { | 308 | if (format_in == NULL) { |
| @@ -327,28 +325,15 @@ nissy_convert( | |||
| 327 | 325 | ||
| 328 | c = readcube(format_in, cube_string); | 326 | c = readcube(format_in, cube_string); |
| 329 | 327 | ||
| 330 | if (iserror(c)) { | ||
| 331 | err = NISSY_ERROR_INVALID_CUBE; | ||
| 332 | goto nissy_convert_error; | ||
| 333 | } | ||
| 334 | |||
| 335 | ret = writecube(format_out, c, result); | ||
| 336 | |||
| 337 | if (ret != 0) { | ||
| 338 | /* Assume the format was invalid */ | ||
| 339 | err = NISSY_ERROR_INVALID_FORMAT; | ||
| 340 | goto nissy_convert_error; | ||
| 341 | } | ||
| 342 | |||
| 343 | if (!isconsistent(c)) { | 328 | if (!isconsistent(c)) { |
| 344 | err = NISSY_ERROR_UNKNOWN; | 329 | err = NISSY_ERROR_INVALID_CUBE; |
| 345 | goto nissy_convert_error; | 330 | goto nissy_convert_error; |
| 346 | } | 331 | } |
| 347 | 332 | ||
| 348 | return NISSY_OK; | 333 | return writecube(format_out, c, result_size, result); |
| 349 | 334 | ||
| 350 | nissy_convert_error: | 335 | nissy_convert_error: |
| 351 | /* We don't write anything to result, we don't know the format */ | 336 | result[0] = '\0'; |
| 352 | return err; | 337 | return err; |
| 353 | } | 338 | } |
| 354 | 339 | ||
| @@ -359,7 +344,7 @@ nissy_getcube( | |||
| 359 | int64_t cp, | 344 | int64_t cp, |
| 360 | int64_t co, | 345 | int64_t co, |
| 361 | const char *options, | 346 | const char *options, |
| 362 | char result[static 22] | 347 | char result[static NISSY_SIZE_B32] |
| 363 | ) | 348 | ) |
| 364 | { | 349 | { |
| 365 | int i; | 350 | int i; |
| @@ -498,7 +483,7 @@ nissy_checkdata( | |||
| 498 | 483 | ||
| 499 | int64_t | 484 | int64_t |
| 500 | nissy_solve( | 485 | nissy_solve( |
| 501 | const char cube[static 22], | 486 | const char cube[static NISSY_SIZE_B32], |
| 502 | const char *solver, | 487 | const char *solver, |
| 503 | uint8_t nissflag, | 488 | uint8_t nissflag, |
| 504 | int8_t minmoves, | 489 | int8_t minmoves, |
| @@ -671,6 +656,14 @@ nissy_explainerror( | |||
| 671 | "is NULL.\n", NISSY_ERROR_NULL_POINTER | 656 | "is NULL.\n", NISSY_ERROR_NULL_POINTER |
| 672 | ); | 657 | ); |
| 673 | return NISSY_OK; | 658 | return NISSY_OK; |
| 659 | case NISSY_ERROR_BUFFER_SIZE: | ||
| 660 | write( | ||
| 661 | "The value %" PRId64 " means that one of the buffers " | ||
| 662 | "provided is too small. For example, it could be too " | ||
| 663 | "small to hold the result or too small to hold the data " | ||
| 664 | "generated by gendata.\n", NISSY_ERROR_BUFFER_SIZE | ||
| 665 | ); | ||
| 666 | return NISSY_OK; | ||
| 674 | case NISSY_ERROR_DATA: | 667 | case NISSY_ERROR_DATA: |
| 675 | write( | 668 | write( |
| 676 | "The value %" PRId64 " means that the provided data is " | 669 | "The value %" PRId64 " means that the provided data is " |
diff --git a/src/nissy.h b/src/nissy.h index d4c2760..f91ee63 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -35,11 +35,17 @@ for example 'rotation UF' or 'mirrored BL'. | |||
| 35 | #define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) | 35 | #define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) |
| 36 | #define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) | 36 | #define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) |
| 37 | #define NISSY_ERROR_NULL_POINTER INT64_C(-60) | 37 | #define NISSY_ERROR_NULL_POINTER INT64_C(-60) |
| 38 | #define NISSY_ERROR_BUFFER_SIZE INT64_C(-61) | ||
| 38 | #define NISSY_ERROR_DATA INT64_C(-70) | 39 | #define NISSY_ERROR_DATA INT64_C(-70) |
| 39 | #define NISSY_ERROR_OPTIONS INT64_C(-80) | 40 | #define NISSY_ERROR_OPTIONS INT64_C(-80) |
| 40 | #define NISSY_ERROR_INVALID_CODE INT64_C(-90) | 41 | #define NISSY_ERROR_INVALID_CODE INT64_C(-90) |
| 41 | #define NISSY_ERROR_UNKNOWN INT64_C(-999) | 42 | #define NISSY_ERROR_UNKNOWN INT64_C(-999) |
| 42 | 43 | ||
| 44 | /* Some constants for size for I/O buffers */ | ||
| 45 | #define NISSY_SIZE_B32 UINT64_C(22) | ||
| 46 | #define NISSY_SIZE_H48 UINT64_C(88) | ||
| 47 | #define NISSY_SIZE_TRANSFORMATION UINT64_C(12) | ||
| 48 | |||
| 43 | /* Flags for NISS options */ | 49 | /* Flags for NISS options */ |
| 44 | #define NISSY_NISSFLAG_NORMAL UINT8_C(1) | 50 | #define NISSY_NISSFLAG_NORMAL UINT8_C(1) |
| 45 | #define NISSY_NISSFLAG_INVERSE UINT8_C(2) | 51 | #define NISSY_NISSFLAG_INVERSE UINT8_C(2) |
| @@ -68,9 +74,9 @@ Return values: | |||
| 68 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 74 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| 69 | */ | 75 | */ |
| 70 | int64_t nissy_compose( | 76 | int64_t nissy_compose( |
| 71 | const char cube[static 22], | 77 | const char cube[static NISSY_SIZE_B32], |
| 72 | const char permutation[static 22], | 78 | const char permutation[static NISSY_SIZE_B32], |
| 73 | char result[static 22] | 79 | char result[static NISSY_SIZE_B32] |
| 74 | ); | 80 | ); |
| 75 | 81 | ||
| 76 | /* | 82 | /* |
| @@ -89,8 +95,8 @@ Return values: | |||
| 89 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 95 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| 90 | */ | 96 | */ |
| 91 | int64_t nissy_inverse( | 97 | int64_t nissy_inverse( |
| 92 | const char cube[static 22], | 98 | const char cube[static NISSY_SIZE_B32], |
| 93 | char result[static 22] | 99 | char result[static NISSY_SIZE_B32] |
| 94 | ); | 100 | ); |
| 95 | 101 | ||
| 96 | /* | 102 | /* |
| @@ -111,9 +117,9 @@ Return values: | |||
| 111 | NISSY_ERROR_NULL_POINTER - The 'moves' argument is NULL. | 117 | NISSY_ERROR_NULL_POINTER - The 'moves' argument is NULL. |
| 112 | */ | 118 | */ |
| 113 | int64_t nissy_applymoves( | 119 | int64_t nissy_applymoves( |
| 114 | const char cube[static 22], | 120 | const char cube[static NISSY_SIZE_B32], |
| 115 | const char *moves, | 121 | const char *moves, |
| 116 | char result[static 22] | 122 | char result[static NISSY_SIZE_B32] |
| 117 | ); | 123 | ); |
| 118 | 124 | ||
| 119 | /* | 125 | /* |
| @@ -132,9 +138,9 @@ Return values: | |||
| 132 | NISSY_ERROR_INVALID_TRANS - The given transformation is invalid. | 138 | NISSY_ERROR_INVALID_TRANS - The given transformation is invalid. |
| 133 | */ | 139 | */ |
| 134 | int64_t nissy_applytrans( | 140 | int64_t nissy_applytrans( |
| 135 | const char cube[static 22], | 141 | const char cube[static NISSY_SIZE_B32], |
| 136 | const char transformation[static 12], | 142 | const char transformation[static NISSY_SIZE_TRANSFORMATION], |
| 137 | char result[static 22] | 143 | char result[static NISSY_SIZE_B32] |
| 138 | ); | 144 | ); |
| 139 | 145 | ||
| 140 | /* | 146 | /* |
| @@ -154,7 +160,7 @@ Return values: | |||
| 154 | */ | 160 | */ |
| 155 | int64_t nissy_frommoves( | 161 | int64_t nissy_frommoves( |
| 156 | const char *moves, | 162 | const char *moves, |
| 157 | char result[static 22] | 163 | char result[static NISSY_SIZE_B32] |
| 158 | ); | 164 | ); |
| 159 | 165 | ||
| 160 | /* | 166 | /* |
| @@ -169,6 +175,7 @@ Parameters: | |||
| 169 | 175 | ||
| 170 | Return values: | 176 | Return values: |
| 171 | NISSY_OK - The conversion was performed succesfully. | 177 | NISSY_OK - The conversion was performed succesfully. |
| 178 | NISSY_ERROR_BUFFER_SIZE - The given buffer is too small for the result. | ||
| 172 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. | 179 | NISSY_ERROR_INVALID_CUBE - The given cube is invalid. |
| 173 | NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid. | 180 | NISSY_ERROR_INVALID_FORMAT - At least one of the given formats is invalid. |
| 174 | NISSY_ERROR_UNKNOWN - An unknown error occurred. | 181 | NISSY_ERROR_UNKNOWN - An unknown error occurred. |
| @@ -208,7 +215,7 @@ int64_t nissy_getcube( | |||
| 208 | int64_t cp, | 215 | int64_t cp, |
| 209 | int64_t co, | 216 | int64_t co, |
| 210 | const char *options, | 217 | const char *options, |
| 211 | char result[static 22] | 218 | char result[static NISSY_SIZE_B32] |
| 212 | ); | 219 | ); |
| 213 | 220 | ||
| 214 | /* | 221 | /* |
| @@ -313,7 +320,7 @@ Return values: | |||
| 313 | Any value >= 0 - The number of solutions found. | 320 | Any value >= 0 - The number of solutions found. |
| 314 | */ | 321 | */ |
| 315 | int64_t nissy_solve( | 322 | int64_t nissy_solve( |
| 316 | const char cube[static 22], | 323 | const char cube[static NISSY_SIZE_B32], |
| 317 | const char *solver, | 324 | const char *solver, |
| 318 | uint8_t nissflag, | 325 | uint8_t nissflag, |
| 319 | int8_t minmoves, | 326 | int8_t minmoves, |
diff --git a/test/020_io_H48_read_write/io_H48_tests.c b/test/020_io_H48_read_write/io_H48_tests.c index 3d4b7e3..7809c87 100644 --- a/test/020_io_H48_read_write/io_H48_tests.c +++ b/test/020_io_H48_read_write/io_H48_tests.c | |||
| @@ -16,7 +16,7 @@ void run(void) { | |||
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!issolvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("H48", cube, str); | 19 | writecube("H48", cube, NISSY_SIZE_H48, str); |
| 20 | printf("%s\n", str); | 20 | printf("%s\n", str); |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
diff --git a/test/021_io_B32_write/io_B32_read_tests.c b/test/021_io_B32_write/io_B32_read_tests.c index 1d2d334..50e07d4 100644 --- a/test/021_io_B32_write/io_B32_read_tests.c +++ b/test/021_io_B32_write/io_B32_read_tests.c | |||
| @@ -16,7 +16,7 @@ void run(void) { | |||
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!issolvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("B32", cube, str); | 19 | writecube("B32", cube, NISSY_SIZE_B32, str); |
| 20 | printf("%s\n", str); | 20 | printf("%s\n", str); |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
diff --git a/test/022_io_B32_read/io_B32_read_tests.c b/test/022_io_B32_read/io_B32_read_tests.c index 5fa9daf..e11b017 100644 --- a/test/022_io_B32_read/io_B32_read_tests.c +++ b/test/022_io_B32_read/io_B32_read_tests.c | |||
| @@ -16,7 +16,7 @@ void run(void) { | |||
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!issolvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("H48", cube, str); | 19 | writecube("H48", cube, NISSY_SIZE_H48, str); |
| 20 | printf("%s\n", str); | 20 | printf("%s\n", str); |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
diff --git a/test/023_io_LST_write/io_LST_write_tests.c b/test/023_io_LST_write/io_LST_write_tests.c index f041864..363bc6d 100644 --- a/test/023_io_LST_write/io_LST_write_tests.c +++ b/test/023_io_LST_write/io_LST_write_tests.c | |||
| @@ -16,7 +16,7 @@ void run(void) { | |||
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!issolvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("LST", cube, str); | 19 | writecube("LST", cube, STRLENMAX, str); |
| 20 | printf("%s\n", str); | 20 | printf("%s\n", str); |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
diff --git a/test/024_io_LST_read/io_LST_read_tests.c b/test/024_io_LST_read/io_LST_read_tests.c index fa80131..1a0f087 100644 --- a/test/024_io_LST_read/io_LST_read_tests.c +++ b/test/024_io_LST_read/io_LST_read_tests.c | |||
| @@ -16,7 +16,7 @@ void run(void) { | |||
| 16 | } else if (!issolvable(cube)) { | 16 | } else if (!issolvable(cube)) { |
| 17 | printf("Cube is not solvable\n"); | 17 | printf("Cube is not solvable\n"); |
| 18 | } else { | 18 | } else { |
| 19 | writecube("H48", cube, str); | 19 | writecube("H48", cube, NISSY_SIZE_H48, str); |
| 20 | printf("%s\n", str); | 20 | printf("%s\n", str); |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
diff --git a/test/030_move/move_tests.c b/test/030_move/move_tests.c index d4a109b..2f0ecfb 100644 --- a/test/030_move/move_tests.c +++ b/test/030_move/move_tests.c | |||
| @@ -17,7 +17,7 @@ void run(void) { | |||
| 17 | } else if (!issolvable(cube)) { | 17 | } else if (!issolvable(cube)) { |
| 18 | printf("Moved cube is not solvable\n"); | 18 | printf("Moved cube is not solvable\n"); |
| 19 | } else { | 19 | } else { |
| 20 | writecube("H48", cube, cubestr); | 20 | writecube("H48", cube, NISSY_SIZE_H48, cubestr); |
| 21 | printf("%s\n", cubestr); | 21 | printf("%s\n", cubestr); |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
diff --git a/test/031_premove/premove_tests.c b/test/031_premove/premove_tests.c index fa3707e..07631c1 100644 --- a/test/031_premove/premove_tests.c +++ b/test/031_premove/premove_tests.c | |||
| @@ -21,7 +21,7 @@ void run(void) { | |||
| 21 | } else if (!issolvable(cube)) { | 21 | } else if (!issolvable(cube)) { |
| 22 | printf("Moved cube is not solvable\n"); | 22 | printf("Moved cube is not solvable\n"); |
| 23 | } else { | 23 | } else { |
| 24 | writecube("H48", cube, cubestr); | 24 | writecube("H48", cube, NISSY_SIZE_H48, cubestr); |
| 25 | printf("%s\n", cubestr); | 25 | printf("%s\n", cubestr); |
| 26 | } | 26 | } |
| 27 | } | 27 | } |
diff --git a/test/040_inverse_cube/inverse_tests.c b/test/040_inverse_cube/inverse_tests.c index 4cb7ad1..c1045ab 100644 --- a/test/040_inverse_cube/inverse_tests.c +++ b/test/040_inverse_cube/inverse_tests.c | |||
| @@ -15,7 +15,7 @@ void run(void) { | |||
| 15 | } else if (!issolvable(inv)) { | 15 | } else if (!issolvable(inv)) { |
| 16 | printf("Inverted cube is not solvable\n"); | 16 | printf("Inverted cube is not solvable\n"); |
| 17 | } else { | 17 | } else { |
| 18 | writecube("H48", inv, str); | 18 | writecube("H48", inv, NISSY_SIZE_H48, str); |
| 19 | printf("%s\n", str); | 19 | printf("%s\n", str); |
| 20 | } | 20 | } |
| 21 | } | 21 | } |
diff --git a/test/050_compose/compose_tests.c b/test/050_compose/compose_tests.c index e0e65b2..c778838 100644 --- a/test/050_compose/compose_tests.c +++ b/test/050_compose/compose_tests.c | |||
| @@ -18,7 +18,7 @@ void run(void) { | |||
| 18 | } else if (!issolvable(c3)) { | 18 | } else if (!issolvable(c3)) { |
| 19 | printf("Composed cube is not solvable\n"); | 19 | printf("Composed cube is not solvable\n"); |
| 20 | } else { | 20 | } else { |
| 21 | writecube("H48", c3, str); | 21 | writecube("H48", c3, NISSY_SIZE_H48, str); |
| 22 | printf("%s\n", str); | 22 | printf("%s\n", str); |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
diff --git a/test/060_transform/transform_tests.c b/test/060_transform/transform_tests.c index bdb4dc5..80a2031 100644 --- a/test/060_transform/transform_tests.c +++ b/test/060_transform/transform_tests.c | |||
| @@ -17,7 +17,7 @@ void run(void) { | |||
| 17 | } else if (!issolvable(cube)) { | 17 | } else if (!issolvable(cube)) { |
| 18 | printf("Transformed cube is not solvable\n"); | 18 | printf("Transformed cube is not solvable\n"); |
| 19 | } else { | 19 | } else { |
| 20 | writecube("H48", cube, cubestr); | 20 | writecube("H48", cube, NISSY_SIZE_H48, cubestr); |
| 21 | printf("%s\n", cubestr); | 21 | printf("%s\n", cubestr); |
| 22 | } | 22 | } |
| 23 | } | 23 | } |
diff --git a/test/075_set_eo/set_eo_tests.c b/test/075_set_eo/set_eo_tests.c index fb2c23e..0c67e87 100644 --- a/test/075_set_eo/set_eo_tests.c +++ b/test/075_set_eo/set_eo_tests.c | |||
| @@ -30,7 +30,7 @@ void run(void) { | |||
| 30 | fprintf(stderr, "\n"); | 30 | fprintf(stderr, "\n"); |
| 31 | printf("Setting EO resulted in inconsistent cube\n"); | 31 | printf("Setting EO resulted in inconsistent cube\n"); |
| 32 | } else { | 32 | } else { |
| 33 | writecube("H48", cube, str); | 33 | writecube("H48", cube, NISSY_SIZE_H48, str); |
| 34 | printf("%s\n", str); | 34 | printf("%s\n", str); |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
diff --git a/test/076_copy_corners/copy_corners_tests.c b/test/076_copy_corners/copy_corners_tests.c index 7464ecc..d1674fc 100644 --- a/test/076_copy_corners/copy_corners_tests.c +++ b/test/076_copy_corners/copy_corners_tests.c | |||
| @@ -19,7 +19,7 @@ void run(void) { | |||
| 19 | } else if (!isconsistent(c1)) { | 19 | } else if (!isconsistent(c1)) { |
| 20 | printf("Setting EO resulted in inconsistent cube\n"); | 20 | printf("Setting EO resulted in inconsistent cube\n"); |
| 21 | } else { | 21 | } else { |
| 22 | writecube("H48", c1, str); | 22 | writecube("H48", c1, NISSY_SIZE_H48, str); |
| 23 | printf("%s\n", str); | 23 | printf("%s\n", str); |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
diff --git a/test/077_copy_edges/copy_edges_tests.c b/test/077_copy_edges/copy_edges_tests.c index 5077861..48c5c53 100644 --- a/test/077_copy_edges/copy_edges_tests.c +++ b/test/077_copy_edges/copy_edges_tests.c | |||
| @@ -19,7 +19,7 @@ void run(void) { | |||
| 19 | } else if (!isconsistent(c1)) { | 19 | } else if (!isconsistent(c1)) { |
| 20 | printf("Setting EO resulted in inconsistent cube\n"); | 20 | printf("Setting EO resulted in inconsistent cube\n"); |
| 21 | } else { | 21 | } else { |
| 22 | writecube("H48", c1, str); | 22 | writecube("H48", c1, NISSY_SIZE_H48, str); |
| 23 | printf("%s\n", str); | 23 | printf("%s\n", str); |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
diff --git a/test/081_getcube/getcube_tests.c b/test/081_getcube/getcube_tests.c index 7eb59dc..46c324b 100644 --- a/test/081_getcube/getcube_tests.c +++ b/test/081_getcube/getcube_tests.c | |||
| @@ -23,7 +23,7 @@ void run(void) { | |||
| 23 | } else if (!isconsistent(cube)) { | 23 | } else if (!isconsistent(cube)) { |
| 24 | printf("Inconsistent cube\n"); | 24 | printf("Inconsistent cube\n"); |
| 25 | } else { | 25 | } else { |
| 26 | writecube("H48", cube, str); | 26 | writecube("H48", cube, NISSY_SIZE_H48, str); |
| 27 | printf("%s\n", str); | 27 | printf("%s\n", str); |
| 28 | } | 28 | } |
| 29 | } | 29 | } |
diff --git a/test/test.h b/test/test.h index b90a399..fe362c7 100644 --- a/test/test.h +++ b/test/test.h | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | 10 | ||
| 11 | #include "../src/nissy.h" | ||
| 11 | #include "../src/arch/arch.h" | 12 | #include "../src/arch/arch.h" |
| 12 | #include "../src/solvers/tables_types_macros.h" | 13 | #include "../src/solvers/tables_types_macros.h" |
| 13 | #include "../src/solvers/h48/coordinate_macros.h" | 14 | #include "../src/solvers/h48/coordinate_macros.h" |
| @@ -23,8 +24,7 @@ bool isconsistent(cube_t); | |||
| 23 | bool issolvable(cube_t); | 24 | bool issolvable(cube_t); |
| 24 | bool issolved(cube_t); | 25 | bool issolved(cube_t); |
| 25 | cube_t readcube(char *, char *); | 26 | cube_t readcube(char *, char *); |
| 26 | void writecube(char *, cube_t, char *); | 27 | int64_t writecube(char *, cube_t, uint64_t, char *); |
| 27 | void nissy_setlogger(void (*logger_function)(const char *, ...)); | ||
| 28 | 28 | ||
| 29 | /* Test function to be implemented by all tests */ | 29 | /* Test function to be implemented by all tests */ |
| 30 | void run(void); | 30 | void run(void); |
