diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/cube.h | 14 | ||||
| -rw-r--r-- | src/core/io_cube.h | 62 | ||||
| -rw-r--r-- | src/core/io_trans.h | 1 | ||||
| -rw-r--r-- | src/core/moves.h | 24 | ||||
| -rw-r--r-- | src/core/transform.h | 6 |
5 files changed, 64 insertions, 43 deletions
diff --git a/src/core/cube.h b/src/core/cube.h index 2252a85..a3c3e14 100644 --- a/src/core/cube.h +++ b/src/core/cube.h | |||
| @@ -66,16 +66,10 @@ isconsistent(cube_t cube) | |||
| 66 | return true; | 66 | return true; |
| 67 | 67 | ||
| 68 | inconsistent_ep: | 68 | inconsistent_ep: |
| 69 | LOG("Inconsistent EP\n"); | ||
| 70 | return false; | ||
| 71 | inconsistent_cp: | 69 | inconsistent_cp: |
| 72 | LOG("Inconsistent CP\n"); | ||
| 73 | return false; | ||
| 74 | inconsistent_eo: | 70 | inconsistent_eo: |
| 75 | LOG("Inconsistent EO\n"); | ||
| 76 | return false; | ||
| 77 | inconsistent_co: | 71 | inconsistent_co: |
| 78 | LOG("Inconsistent CO\n"); | 72 | /* We used to do more logging here, hence the 4 different labels */ |
| 79 | return false; | 73 | return false; |
| 80 | } | 74 | } |
| 81 | 75 | ||
| @@ -115,13 +109,9 @@ issolvable(cube_t cube) | |||
| 115 | return true; | 109 | return true; |
| 116 | 110 | ||
| 117 | issolvable_parity: | 111 | issolvable_parity: |
| 118 | LOG("EP and CP parities are different\n"); | ||
| 119 | return false; | ||
| 120 | issolvable_eo: | 112 | issolvable_eo: |
| 121 | LOG("Odd number of flipped edges\n"); | ||
| 122 | return false; | ||
| 123 | issolvable_co: | 113 | issolvable_co: |
| 124 | LOG("Sum of corner orientation is not multiple of 3\n"); | 114 | /* We used to do more logging here, hence the 3 different labels */ |
| 125 | return false; | 115 | return false; |
| 126 | } | 116 | } |
| 127 | 117 | ||
diff --git a/src/core/io_cube.h b/src/core/io_cube.h index 9ae82d7..1ac8ec7 100644 --- a/src/core/io_cube.h +++ b/src/core/io_cube.h | |||
| @@ -1,3 +1,6 @@ | |||
| 1 | STATIC cube_t readcube(const char *, const char *); | ||
| 2 | STATIC int writecube(const char *, cube_t, char *); | ||
| 3 | STATIC void log_available_formats(void); | ||
| 1 | STATIC uint8_t readco(const char *); | 4 | STATIC uint8_t readco(const char *); |
| 2 | STATIC uint8_t readcp(const char *); | 5 | STATIC uint8_t readcp(const char *); |
| 3 | STATIC uint8_t readeo(const char *); | 6 | STATIC uint8_t readeo(const char *); |
| @@ -29,7 +32,7 @@ STATIC struct { | |||
| 29 | { .name = "NONE", .read = NULL, .write = NULL }, | 32 | { .name = "NONE", .read = NULL, .write = NULL }, |
| 30 | }; | 33 | }; |
| 31 | 34 | ||
| 32 | cube_t | 35 | STATIC cube_t |
| 33 | readcube(const char *format, const char *buf) | 36 | readcube(const char *format, const char *buf) |
| 34 | { | 37 | { |
| 35 | int i; | 38 | int i; |
| @@ -38,11 +41,12 @@ readcube(const char *format, const char *buf) | |||
| 38 | if (!strcmp(format, ioformat[i].name)) | 41 | if (!strcmp(format, ioformat[i].name)) |
| 39 | return ioformat[i].read(buf); | 42 | return ioformat[i].read(buf); |
| 40 | 43 | ||
| 41 | LOG("Cannot read cube in the given format\n"); | 44 | LOG("Cannot read cube: unknown format '%s'\n", format); |
| 45 | log_available_formats(); | ||
| 42 | return ZERO_CUBE; | 46 | return ZERO_CUBE; |
| 43 | } | 47 | } |
| 44 | 48 | ||
| 45 | void | 49 | STATIC int |
| 46 | writecube(const char *format, cube_t cube, char *buf) | 50 | writecube(const char *format, cube_t cube, char *buf) |
| 47 | { | 51 | { |
| 48 | char *errormsg; | 52 | char *errormsg; |
| @@ -58,18 +62,30 @@ writecube(const char *format, cube_t cube, char *buf) | |||
| 58 | for (i = 0; ioformat[i].write != NULL; i++) { | 62 | for (i = 0; ioformat[i].write != NULL; i++) { |
| 59 | if (!strcmp(format, ioformat[i].name)) { | 63 | if (!strcmp(format, ioformat[i].name)) { |
| 60 | ioformat[i].write(cube, buf); | 64 | ioformat[i].write(cube, buf); |
| 61 | return; | 65 | return 0; |
| 62 | } | 66 | } |
| 63 | } | 67 | } |
| 64 | 68 | ||
| 69 | LOG("Cannot write cube: unknown format '%s'\n", format); | ||
| 70 | log_available_formats(); | ||
| 65 | errormsg = "ERROR: format"; | 71 | errormsg = "ERROR: format"; |
| 66 | 72 | ||
| 67 | writecube_error: | 73 | writecube_error: |
| 68 | LOG("writecube error, see stdout for details\n"); | ||
| 69 | len = strlen(errormsg); | 74 | len = strlen(errormsg); |
| 70 | memcpy(buf, errormsg, len); | 75 | memcpy(buf, errormsg, len); |
| 71 | buf[len] = '\n'; | 76 | buf[len] = '\0'; |
| 72 | buf[len+1] = '\0'; | 77 | return 1; |
| 78 | } | ||
| 79 | |||
| 80 | STATIC void | ||
| 81 | log_available_formats(void) | ||
| 82 | { | ||
| 83 | int i; | ||
| 84 | |||
| 85 | LOG("Available formats: "); | ||
| 86 | for (i = 0; ioformat[i].read != NULL; i++) | ||
| 87 | LOG("'%s' ", ioformat[i].name); | ||
| 88 | LOG("\n"); | ||
| 73 | } | 89 | } |
| 74 | 90 | ||
| 75 | STATIC uint8_t | 91 | STATIC uint8_t |
| @@ -133,14 +149,34 @@ readcube_B32(const char *buf) | |||
| 133 | 149 | ||
| 134 | for (i = 0; i < 8; i++) { | 150 | for (i = 0; i < 8; i++) { |
| 135 | c[i] = b32tocorner(buf[i]); | 151 | c[i] = b32tocorner(buf[i]); |
| 136 | DBG_ASSERT(c[i] < 255, ZERO_CUBE, | 152 | if (c[i] == UINT8_ERROR) { |
| 137 | "Error reading B32 corner %d (char %d)\n", i, i); | 153 | LOG("Error reading B32 corner %d ", i); |
| 154 | if (buf[i] == 0) { | ||
| 155 | LOG("(string terminated early)\n"); | ||
| 156 | } else { | ||
| 157 | LOG("(char '%c')\n", buf[i]); | ||
| 158 | } | ||
| 159 | return ZERO_CUBE; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | |||
| 163 | if (buf[8] != '=') { | ||
| 164 | LOG("Error reading B32 separator: a single '=' " | ||
| 165 | "must be used to separate edges and corners\n"); | ||
| 166 | return ZERO_CUBE; | ||
| 138 | } | 167 | } |
| 139 | 168 | ||
| 140 | for (i = 0; i < 12; i++) { | 169 | for (i = 0; i < 12; i++) { |
| 141 | e[i] = b32toedge(buf[i+9]); | 170 | e[i] = b32toedge(buf[i+9]); |
| 142 | DBG_ASSERT(e[i] < 255, ZERO_CUBE, | 171 | if (e[i] == UINT8_ERROR) { |
| 143 | "Error reading B32 edge %d (char %d)\n", i, i+9); | 172 | LOG("Error reading B32 edge %d ", i); |
| 173 | if (buf[i+9] == 0) { | ||
| 174 | LOG("(string terminated early)\n"); | ||
| 175 | } else { | ||
| 176 | LOG("(char '%c')\n", buf[i+9]); | ||
| 177 | } | ||
| 178 | return ZERO_CUBE; | ||
| 179 | } | ||
| 144 | } | 180 | } |
| 145 | 181 | ||
| 146 | return cubefromarray(c, e); | 182 | return cubefromarray(c, e); |
| @@ -314,7 +350,7 @@ STATIC uint8_t | |||
| 314 | b32toedge(char c) | 350 | b32toedge(char c) |
| 315 | { | 351 | { |
| 316 | if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) | 352 | if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) |
| 317 | return 255; | 353 | return UINT8_ERROR; |
| 318 | 354 | ||
| 319 | return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; | 355 | return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; |
| 320 | } | 356 | } |
| @@ -324,7 +360,7 @@ b32tocorner(char c) { | |||
| 324 | uint8_t val; | 360 | uint8_t val; |
| 325 | 361 | ||
| 326 | if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) | 362 | if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) |
| 327 | return 255; | 363 | return UINT8_ERROR; |
| 328 | 364 | ||
| 329 | val = c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; | 365 | val = c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; |
| 330 | 366 | ||
diff --git a/src/core/io_trans.h b/src/core/io_trans.h index d91e9a2..f4e8ace 100644 --- a/src/core/io_trans.h +++ b/src/core/io_trans.h | |||
| @@ -10,7 +10,6 @@ readtrans(const char *buf) | |||
| 10 | if (!strncmp(buf, transstr[t], 11)) | 10 | if (!strncmp(buf, transstr[t], 11)) |
| 11 | return t; | 11 | return t; |
| 12 | 12 | ||
| 13 | LOG("readtrans error\n"); | ||
| 14 | return UINT8_ERROR; | 13 | return UINT8_ERROR; |
| 15 | } | 14 | } |
| 16 | 15 | ||
diff --git a/src/core/moves.h b/src/core/moves.h index f0d7646..28abc7f 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -18,7 +18,7 @@ STATIC cube_t applymoves(cube_t, const char *); | |||
| 18 | STATIC cube_t frommoves(const char *); | 18 | STATIC cube_t frommoves(const char *); |
| 19 | 19 | ||
| 20 | #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ | 20 | #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ |
| 21 | LABEL_ERROR, ARG_ACTION) \ | 21 | RET_ERROR, ARG_ACTION) \ |
| 22 | const char *VAR_B; \ | 22 | const char *VAR_B; \ |
| 23 | uint8_t VAR_MOVE_NOMOD, VAR_MOD; \ | 23 | uint8_t VAR_MOVE_NOMOD, VAR_MOD; \ |
| 24 | for (VAR_B = ARG_BUF, ARG_C = 0; *VAR_B != '\0'; VAR_B++, ARG_C++) { \ | 24 | for (VAR_B = ARG_BUF, ARG_C = 0; *VAR_B != '\0'; VAR_B++, ARG_C++) { \ |
| @@ -26,8 +26,10 @@ STATIC cube_t frommoves(const char *); | |||
| 26 | VAR_B++; \ | 26 | VAR_B++; \ |
| 27 | if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ | 27 | if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ |
| 28 | break; \ | 28 | break; \ |
| 29 | if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) \ | 29 | if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ |
| 30 | goto LABEL_ERROR; \ | 30 | LOG("Error: unknown move '%c'\n", *VAR_B); \ |
| 31 | return RET_ERROR; \ | ||
| 32 | } \ | ||
| 31 | if ((VAR_MOD = readmodifier(*(VAR_B+1))) != 0) \ | 33 | if ((VAR_MOD = readmodifier(*(VAR_B+1))) != 0) \ |
| 32 | VAR_B++; \ | 34 | VAR_B++; \ |
| 33 | ARG_MOVE = VAR_MOVE_NOMOD + VAR_MOD; \ | 35 | ARG_MOVE = VAR_MOVE_NOMOD + VAR_MOD; \ |
| @@ -124,7 +126,7 @@ move(cube_t c, uint8_t m) | |||
| 124 | case MOVE_B3: | 126 | case MOVE_B3: |
| 125 | return MOVE(B3, c); | 127 | return MOVE(B3, c); |
| 126 | default: | 128 | default: |
| 127 | LOG("move error, unknown move\n"); | 129 | LOG("move error: unknown move %" PRIu8 "\n", m); |
| 128 | return ZERO_CUBE; | 130 | return ZERO_CUBE; |
| 129 | } | 131 | } |
| 130 | } | 132 | } |
| @@ -171,7 +173,7 @@ premove(cube_t c, uint8_t m) | |||
| 171 | case MOVE_B3: | 173 | case MOVE_B3: |
| 172 | return PREMOVE(B, c); | 174 | return PREMOVE(B, c); |
| 173 | default: | 175 | default: |
| 174 | LOG("move error, unknown move\n"); | 176 | LOG("premove error: unknown move %" PRIu8 "\n", m); |
| 175 | return ZERO_CUBE; | 177 | return ZERO_CUBE; |
| 176 | } | 178 | } |
| 177 | } | 179 | } |
| @@ -222,15 +224,11 @@ readmoves(const char *buf, int max, uint8_t *ret) | |||
| 222 | uint8_t m; | 224 | uint8_t m; |
| 223 | int c; | 225 | int c; |
| 224 | 226 | ||
| 225 | FOREACH_READMOVE(buf, m, c, max, readmoves_error, | 227 | FOREACH_READMOVE(buf, m, c, max, -1, |
| 226 | ret[c] = m; | 228 | ret[c] = m; |
| 227 | ) | 229 | ) |
| 228 | 230 | ||
| 229 | return c; | 231 | return c; |
| 230 | |||
| 231 | readmoves_error: | ||
| 232 | LOG("readmoves error\n"); | ||
| 233 | return -1; | ||
| 234 | } | 232 | } |
| 235 | 233 | ||
| 236 | STATIC cube_t | 234 | STATIC cube_t |
| @@ -242,15 +240,11 @@ applymoves(cube_t cube, const char *buf) | |||
| 242 | DBG_ASSERT(isconsistent(cube), ZERO_CUBE, | 240 | DBG_ASSERT(isconsistent(cube), ZERO_CUBE, |
| 243 | "move error: inconsistent cube\n"); | 241 | "move error: inconsistent cube\n"); |
| 244 | 242 | ||
| 245 | FOREACH_READMOVE(buf, m, c, -1, applymoves_error, | 243 | FOREACH_READMOVE(buf, m, c, -1, ZERO_CUBE, |
| 246 | cube = move(cube, m); | 244 | cube = move(cube, m); |
| 247 | ) | 245 | ) |
| 248 | 246 | ||
| 249 | return cube; | 247 | return cube; |
| 250 | |||
| 251 | applymoves_error: | ||
| 252 | LOG("applymoves error\n"); | ||
| 253 | return ZERO_CUBE; | ||
| 254 | } | 248 | } |
| 255 | 249 | ||
| 256 | STATIC cube_t | 250 | STATIC cube_t |
diff --git a/src/core/transform.h b/src/core/transform.h index 83204d5..73636fe 100644 --- a/src/core/transform.h +++ b/src/core/transform.h | |||
| @@ -229,7 +229,7 @@ transform_corners(cube_t c, uint8_t t) | |||
| 229 | case TRANS_BLm: | 229 | case TRANS_BLm: |
| 230 | return TRANS_CORNERS_MIRRORED(BLm, c); | 230 | return TRANS_CORNERS_MIRRORED(BLm, c); |
| 231 | default: | 231 | default: |
| 232 | LOG("transform error, unknown transformation %" PRIu8 "\n", t); | 232 | LOG("transform error: unknown transformation %" PRIu8 "\n", t); |
| 233 | return ZERO_CUBE; | 233 | return ZERO_CUBE; |
| 234 | } | 234 | } |
| 235 | } | 235 | } |
| @@ -335,7 +335,6 @@ transform(cube_t c, uint8_t t) | |||
| 335 | case TRANS_BLm: | 335 | case TRANS_BLm: |
| 336 | return TRANS_MIRRORED(BLm, c); | 336 | return TRANS_MIRRORED(BLm, c); |
| 337 | default: | 337 | default: |
| 338 | LOG("transform error, unknown transformation %" PRIu8 "\n", t); | ||
| 339 | return ZERO_CUBE; | 338 | return ZERO_CUBE; |
| 340 | } | 339 | } |
| 341 | } | 340 | } |
| @@ -350,5 +349,8 @@ applytrans(cube_t cube, const char *buf) | |||
| 350 | 349 | ||
| 351 | t = readtrans(buf); | 350 | t = readtrans(buf); |
| 352 | 351 | ||
| 352 | if (t == UINT8_ERROR) | ||
| 353 | LOG("Unknown transformation '%s'\n", buf); | ||
| 354 | |||
| 353 | return transform(cube, t); | 355 | return transform(cube, t); |
| 354 | } | 356 | } |
