diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/cube.h | 4 | ||||
| -rw-r--r-- | src/core/io_moves.h | 9 | ||||
| -rw-r--r-- | src/core/moves.h | 7 |
3 files changed, 7 insertions, 13 deletions
diff --git a/src/core/cube.h b/src/core/cube.h index a3c3e14..49d868c 100644 --- a/src/core/cube.h +++ b/src/core/cube.h | |||
| @@ -4,7 +4,7 @@ STATIC bool isconsistent(cube_t); | |||
| 4 | STATIC bool issolvable(cube_t); | 4 | STATIC bool issolvable(cube_t); |
| 5 | STATIC bool issolved(cube_t); | 5 | STATIC bool issolved(cube_t); |
| 6 | STATIC bool iserror(cube_t); | 6 | STATIC bool iserror(cube_t); |
| 7 | STATIC void getcube_fix(int64_t *, int64_t *, int64_t *, int64_t *); | 7 | STATIC void getcube_fix(long long *, long long *, long long *, long long *); |
| 8 | STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); | 8 | STATIC cube_t getcube(int64_t, int64_t, int64_t, int64_t); |
| 9 | 9 | ||
| 10 | /* This is used only in tests, use SOLVED_CUBE directly everywhere else */ | 10 | /* This is used only in tests, use SOLVED_CUBE directly everywhere else */ |
| @@ -128,7 +128,7 @@ iserror(cube_t cube) | |||
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | STATIC void | 130 | STATIC void |
| 131 | getcube_fix(int64_t *ep, int64_t *eo, int64_t *cp, int64_t *co) | 131 | getcube_fix(long long *ep, long long *eo, long long *cp, long long *co) |
| 132 | { | 132 | { |
| 133 | uint8_t e[12], c[8], coarr[8]; | 133 | uint8_t e[12], c[8], coarr[8]; |
| 134 | 134 | ||
diff --git a/src/core/io_moves.h b/src/core/io_moves.h index be43568..806887b 100644 --- a/src/core/io_moves.h +++ b/src/core/io_moves.h | |||
| @@ -43,6 +43,7 @@ writemoves(uint8_t *m, int n, uint64_t buf_size, char *buf) | |||
| 43 | { | 43 | { |
| 44 | int i; | 44 | int i; |
| 45 | uint64_t len; | 45 | uint64_t len; |
| 46 | int64_t written; | ||
| 46 | const char *s; | 47 | const char *s; |
| 47 | char *b; | 48 | char *b; |
| 48 | 49 | ||
| @@ -51,16 +52,16 @@ writemoves(uint8_t *m, int n, uint64_t buf_size, char *buf) | |||
| 51 | return NISSY_ERROR_BUFFER_SIZE; | 52 | return NISSY_ERROR_BUFFER_SIZE; |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | for (i = 0, b = buf; i < n; i++, b++, buf_size--) { | 55 | for (i = 0, b = buf, written = 0; i < n; i++, b++, written++) { |
| 55 | s = movestr[m[i]]; | 56 | s = movestr[m[i]]; |
| 56 | len = strlen(s); | 57 | len = strlen(s); |
| 57 | if (len >= buf_size) { | 58 | if (len + written >= buf_size) { |
| 58 | LOG("Error: the given buffer is too small for " | 59 | LOG("Error: the given buffer is too small for " |
| 59 | "writing the given moves.\n"); | 60 | "writing the given moves.\n"); |
| 60 | goto writemoves_error; | 61 | goto writemoves_error; |
| 61 | } | 62 | } |
| 62 | memcpy(b, s, len); | 63 | memcpy(b, s, len); |
| 63 | buf_size -= len; | 64 | written += len; |
| 64 | b += len; | 65 | b += len; |
| 65 | *b = ' '; | 66 | *b = ' '; |
| 66 | } | 67 | } |
| @@ -69,7 +70,7 @@ writemoves(uint8_t *m, int n, uint64_t buf_size, char *buf) | |||
| 69 | b--; /* Remove last space */ | 70 | b--; /* Remove last space */ |
| 70 | *b = '\0'; | 71 | *b = '\0'; |
| 71 | 72 | ||
| 72 | return buf_size; | 73 | return written; |
| 73 | 74 | ||
| 74 | writemoves_error: | 75 | writemoves_error: |
| 75 | *buf = '\0'; | 76 | *buf = '\0'; |
diff --git a/src/core/moves.h b/src/core/moves.h index 28abc7f..d07bc19 100644 --- a/src/core/moves.h +++ b/src/core/moves.h | |||
| @@ -15,7 +15,6 @@ STATIC void invertmoves(uint8_t *, uint8_t, uint8_t *); | |||
| 15 | 15 | ||
| 16 | STATIC int readmoves(const char *, int, uint8_t *); | 16 | STATIC int readmoves(const char *, int, uint8_t *); |
| 17 | STATIC cube_t applymoves(cube_t, const char *); | 17 | STATIC cube_t applymoves(cube_t, const char *); |
| 18 | STATIC cube_t frommoves(const char *); | ||
| 19 | 18 | ||
| 20 | #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ | 19 | #define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ |
| 21 | RET_ERROR, ARG_ACTION) \ | 20 | RET_ERROR, ARG_ACTION) \ |
| @@ -246,9 +245,3 @@ applymoves(cube_t cube, const char *buf) | |||
| 246 | 245 | ||
| 247 | return cube; | 246 | return cube; |
| 248 | } | 247 | } |
| 249 | |||
| 250 | STATIC cube_t | ||
| 251 | frommoves(const char *buf) | ||
| 252 | { | ||
| 253 | return applymoves(SOLVED_CUBE, buf); | ||
| 254 | } | ||
