commit 71c0188306377940ae172dceb58f2bd5f4fcdb4f
parent e986713657bc5f9880e91ed49dd9b0d0227f048d
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Thu, 20 Jun 2024 14:07:51 +0200
Changed logger from va_args to ...
Diffstat:
10 files changed, 60 insertions(+), 64 deletions(-)
diff --git a/src/cube.c b/src/cube.c
@@ -3,27 +3,16 @@
#include <stdbool.h>
#include <string.h>
-void (*nissy_log)(const char *, va_list);
+void (*nissy_log)(const char *, ...);
-void
-_log(const char *str, ...) /* TODO: rename */
-{
- va_list args;
-
- if (nissy_log != NULL) {
- va_start(args, str);
- nissy_log(str, args);
- va_end(args);
- }
-}
+#define LOG(...) if (nissy_log != NULL) nissy_log(__VA_ARGS__);
#ifdef DEBUG
#define _static
#define _static_inline
-#define DBG_WARN(condition, ...) if (!(condition)) _log(__VA_ARGS__);
+#define DBG_WARN(condition, ...) if (!(condition)) LOG(__VA_ARGS__);
#define DBG_ASSERT(condition, retval, ...) \
- if (!(condition)) { _log(__VA_ARGS__); return retval; }
-
+ if (!(condition)) { LOG(__VA_ARGS__); return retval; }
#else
#define _static static
#define _static_inline static inline
diff --git a/src/cube.h b/src/cube.h
@@ -84,4 +84,4 @@ int64_t nissy_solve(
char *solutions
);
-void nissy_setlogger(void (*logger_function)(const char *, va_list));
+void nissy_setlogger(void (*logger_function)(const char *, ...));
diff --git a/src/cube_generic.h b/src/cube_generic.h
@@ -65,16 +65,16 @@ isconsistent(cube_t cube)
return true;
inconsistent_ep:
- _log("Inconsistent EP\n");
+ LOG("Inconsistent EP\n");
return false;
inconsistent_cp:
- _log("Inconsistent CP\n");
+ LOG("Inconsistent CP\n");
return false;
inconsistent_eo:
- _log("Inconsistent EO\n");
+ LOG("Inconsistent EO\n");
return false;
inconsistent_co:
- _log("Inconsistent CO\n");
+ LOG("Inconsistent CO\n");
return false;
}
@@ -114,13 +114,13 @@ issolvable(cube_t cube)
return true;
issolvable_parity:
- _log("EP and CP parities are different\n");
+ LOG("EP and CP parities are different\n");
return false;
issolvable_eo:
- _log("Odd number of flipped edges\n");
+ LOG("Odd number of flipped edges\n");
return false;
issolvable_co:
- _log("Sum of corner orientation is not multiple of 3\n");
+ LOG("Sum of corner orientation is not multiple of 3\n");
return false;
}
@@ -161,7 +161,7 @@ applymoves_finish:
return cube;
applymoves_error:
- _log("applymoves error\n");
+ LOG("applymoves error\n");
return zero;
}
@@ -238,7 +238,7 @@ move(cube_t c, uint8_t m)
case _move_B3:
return _move(B3, c);
default:
- _log("move error, unknown move\n");
+ LOG("move error, unknown move\n");
return zero;
}
}
diff --git a/src/cube_public.h b/src/cube_public.h
@@ -168,7 +168,7 @@ nissy_solve(
}
void
-nissy_setlogger(void (*log)(const char *, va_list))
+nissy_setlogger(void (*log)(const char *, ...))
{
nissy_log = log;
}
diff --git a/src/cube_transform_with_switch.h b/src/cube_transform_with_switch.h
@@ -118,7 +118,7 @@ transform_edges(cube_t c, uint8_t t)
case _trans_BLm:
return _trans_edges_mirrored(BLm, c);
default:
- _log("transform error, unknown transformation\n");
+ LOG("transform error, unknown transformation\n");
return zero;
}
}
@@ -224,7 +224,7 @@ transform_corners(cube_t c, uint8_t t)
case _trans_BLm:
return _trans_corners_mirrored(BLm, c);
default:
- _log("transform error, unknown transformation\n");
+ LOG("transform error, unknown transformation\n");
return zero;
}
}
@@ -330,7 +330,7 @@ transform(cube_t c, uint8_t t)
case _trans_BLm:
return _trans_mirrored(BLm, c);
default:
- _log("transform error, unknown transformation\n");
+ LOG("transform error, unknown transformation\n");
return zero;
}
}
diff --git a/src/io_cube.h b/src/io_cube.h
@@ -49,7 +49,7 @@ readcube(const char *format, const char *buf)
if (!strcmp(format, ioformat[i].name))
return ioformat[i].read(buf);
- _log("Cannot read cube in the given format\n");
+ LOG("Cannot read cube in the given format\n");
return zero;
}
@@ -76,7 +76,7 @@ writecube(const char *format, cube_t cube, char *buf)
errormsg = "ERROR: format";
writecube_error:
- _log("writecube error, see stdout for details\n");
+ LOG("writecube error, see stdout for details\n");
len = strlen(errormsg);
memcpy(buf, errormsg, len);
buf[len] = '\n';
@@ -93,7 +93,7 @@ readco(const char *str)
if (*str == '2')
return _ctwist_ccw;
- _log("Error reading CO\n");
+ LOG("Error reading CO\n");
return _error;
}
@@ -107,7 +107,7 @@ readcp(const char *str)
!strncmp(str, cornerstralt[c], 3))
return c;
- _log("Error reading CP\n");
+ LOG("Error reading CP\n");
return _error;
}
@@ -119,7 +119,7 @@ readeo(const char *str)
if (*str == '1')
return _eflip;
- _log("Error reading EO\n");
+ LOG("Error reading EO\n");
return _error;
}
@@ -132,7 +132,7 @@ readep(const char *str)
if (!strncmp(str, edgestr[e], 2))
return e;
- _log("Error reading EP\n");
+ LOG("Error reading EP\n");
return _error;
}
diff --git a/src/io_move_trans.h b/src/io_move_trans.h
@@ -49,7 +49,7 @@ readtrans(const char *buf)
if (!strncmp(buf, transstr[t], 11))
return t;
- _log("readtrans error\n");
+ LOG("readtrans error\n");
return _error;
}
diff --git a/src/solve_generic.h b/src/solve_generic.h
@@ -49,11 +49,11 @@ solve(
solutions
);
} else {
- _log("solve: unknown solver '%s'\n", solver);
+ LOG("solve: unknown solver '%s'\n", solver);
return -1;
}
- _log("solve: error\n");
+ LOG("solve: error\n");
return -1;
}
@@ -63,7 +63,7 @@ solve_generic_appendsolution(dfsarg_generic_t *arg)
int strl;
strl = writemoves(arg->moves, arg->depth, *arg->nextsol);
- _log("Solution found: %s\n", *arg->nextsol);
+ LOG("Solution found: %s\n", *arg->nextsol);
*arg->nextsol += strl;
**arg->nextsol = '\n';
(*arg->nextsol)++;
@@ -126,12 +126,12 @@ solve_generic(
int64_t ret, tmp, first;
if (!issolvable(cube)) {
- _log("solve: cube is not solvable\n");
+ LOG("solve: cube is not solvable\n");
return -1;
}
if (issolved(cube)) {
- _log("solve: cube is already solved\n");
+ LOG("solve: cube is already solved\n");
sols[0] = '\n';
sols[1] = 0;
return 1;
@@ -141,32 +141,32 @@ solve_generic(
"solve: NISS not implemented yet, 'nisstype' ignored\n");
if (minmoves < 0) {
- _log("solve: 'minmoves' is negative, setting to 0\n");
+ LOG("solve: 'minmoves' is negative, setting to 0\n");
minmoves = 0;
}
if (maxmoves < 0) {
- _log("solve: invalid 'maxmoves', setting to 20\n");
+ LOG("solve: invalid 'maxmoves', setting to 20\n");
maxmoves = 20;
}
if (maxsols < 0) {
- _log("solve: 'maxsols' is negative\n");
+ LOG("solve: 'maxsols' is negative\n");
return -1;
}
if (maxsols == 0) {
- _log("solve: 'maxsols' is 0\n");
+ LOG("solve: 'maxsols' is 0\n");
return 0;
}
if (sols == NULL) {
- _log("solve: return parameter 'sols' is NULL\n");
+ LOG("solve: return parameter 'sols' is NULL\n");
return -1;
}
if (estimate == NULL) {
- _log("solve: 'estimate' is NULL\n");
+ LOG("solve: 'estimate' is NULL\n");
return -1;
}
@@ -187,7 +187,7 @@ solve_generic(
if (tmp != 0)
first = arg.depth;
- _log("Found %" PRId64 " solution%s at depth %" PRIu8 "\n",
+ LOG("Found %" PRId64 " solution%s at depth %" PRIu8 "\n",
tmp, tmp == 1 ? "" : "s", arg.depth);
if (ret >= maxsols)
@@ -248,7 +248,7 @@ gendata(const char *solver, const char *options, void *data)
maxdepth = atoi(&options[i+1]);
ret = gendata_h48(data, h, maxdepth);
} else {
- _log("gendata: implemented only for H48 solver\n");
+ LOG("gendata: implemented only for H48 solver\n");
ret = -1;
}
diff --git a/src/solve_h48.h b/src/solve_h48.h
@@ -146,13 +146,13 @@ gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep)
.rep = rep
};
for (i = 0, n = 0, cc = 0; i < 10; i++) {
- _log("cocsep: generating depth %" PRIu8 "\n", i);
+ LOG("cocsep: generating depth %" PRIu8 "\n", i);
memset(visited, 0, COCSEP_VISITEDSIZE);
arg.depth = 0;
arg.maxdepth = i;
cc = gendata_cocsep_dfs(&arg);
info[i+2] = cc;
- _log("found %" PRIu32 "\n", cc);
+ LOG("found %" PRIu32 "\n", cc);
}
info[0] = (uint32_t)n;
@@ -161,12 +161,12 @@ gendata_cocsep(void *buf, uint64_t *selfsim, cube_t *rep)
"cocsep: computed %" PRIu16 " symmetry classes, "
"expected %zu\n", n, COCSEP_CLASSES);
- _log("cocsep data computed\n");
- _log("Symmetry classes: %" PRIu32 "\n", info[0]);
- _log("Maximum pruning value: %" PRIu32 "\n", info[1]);
- _log("Pruning value distribution:\n");
+ LOG("cocsep data computed\n");
+ LOG("Symmetry classes: %" PRIu32 "\n", info[0]);
+ LOG("Maximum pruning value: %" PRIu32 "\n", info[1]);
+ LOG("Pruning value distribution:\n");
for (j = 0; j < 10; j++)
- _log("%" PRIu8 ":\t%" PRIu32 "\n", j, info[j+2]);
+ LOG("%" PRIu8 ":\t%" PRIu32 "\n", j, info[j+2]);
gendata_cocsep_return_size:
return COCSEP_FULLSIZE;
@@ -264,21 +264,21 @@ gendata_h48(void *buf, uint8_t h, uint8_t maxdepth)
tot < esep_max && arg.depth <= maxdepth;
arg.depth++
) {
- _log("esep: generating depth %" PRIu8 "\n", arg.depth);
+ LOG("esep: generating depth %" PRIu8 "\n", arg.depth);
cc = gendata_esep_bfs(&arg);
tot += cc;
info[arg.depth+1] = cc;
- _log("found %" PRIu64 "\n", cc);
+ LOG("found %" PRIu64 "\n", cc);
}
info[0] = arg.depth-1;
infosize = 4 * (size_t)(info[0] + 2);
- _log("h48 pruning table computed\n");
- _log("Maximum pruning value: %" PRIu32 "\n", info[0]);
- _log("Pruning value distribution:\n");
+ LOG("h48 pruning table computed\n");
+ LOG("Maximum pruning value: %" PRIu32 "\n", info[0]);
+ LOG("Pruning value distribution:\n");
for (j = 0; j <= info[0]; j++)
- _log("%" PRIu8 ":\t%" PRIu32 "\n", j, info[j+1]);
+ LOG("%" PRIu8 ":\t%" PRIu32 "\n", j, info[j+1]);
gendata_h48_return_size:
return cocsepsize + ESEP_TABLESIZE(h, k) + infosize;
diff --git a/test/test.h b/test/test.h
@@ -25,12 +25,19 @@ bool issolvable(cube_t);
bool issolved(cube_t);
cube_t readcube(char *, char *);
void writecube(char *, cube_t, char *);
-void nissy_setlogger(void (*logger_function)(const char *, va_list));
+void nissy_setlogger(void (*logger_function)(const char *, ...));
/* Test function to be implemented by all tests */
void run(void);
-void log_stderr(const char *str, va_list vl) { vfprintf(stderr, str, vl); }
+void log_stderr(const char *str, ...)
+{
+ va_list args;
+
+ va_start(args, str);
+ vfprintf(stderr, str, args);
+ va_end(args);
+}
int main(void) {
nissy_setlogger(log_stderr);