From b25a939e2d8b045c083caf3264c4e5aac1cf88fb Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 15 Apr 2025 15:51:40 +0200 Subject: Better logging function Now it is possible to provide some data together with the logging function. This is useful for example in C++, where I can now provide an arbitrary callable object as data, and a simple wrapper function that call the callable object as logging function. --- tools/000_gendata/gendata.c | 4 ++-- tools/001_derive_h48/derive_h48.c | 2 +- tools/100_checkdata/checkdata.c | 2 +- tools/300_solve_small/solve_small.c | 2 +- tools/301_solve_file/solve_file.c | 2 +- tools/302_solve_multisol/solve_multisol.c | 2 +- tools/400_solvetest/solve_test.c | 2 +- tools/nissy_extra.h | 2 +- tools/tool.h | 15 ++++----------- 9 files changed, 13 insertions(+), 20 deletions(-) (limited to 'tools') diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c index f2ac1a0..3123bf5 100644 --- a/tools/000_gendata/gendata.c +++ b/tools/000_gendata/gendata.c @@ -17,7 +17,7 @@ run(void) { case -2: goto gendata_run_finish; default: - nissy_datainfo(size, buf, write_stdout); + nissy_datainfo(size, buf); consistent = nissy_checkdata(size, buf) == 0; expected = check_distribution(solver, size, buf); if (consistent && expected) { @@ -51,7 +51,7 @@ int main(int argc, char **argv) { parse_h48_solver(solver, &h, &k); expected = expected_h48[h][k]; - nissy_setlogger(log_stderr); + nissy_setlogger(log_stdout, NULL); timerun(run); diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c index c964882..e471f9b 100644 --- a/tools/001_derive_h48/derive_h48.c +++ b/tools/001_derive_h48/derive_h48.c @@ -32,7 +32,7 @@ int main(int argc, char **argv) { filename_large = argv[3]; filename_small = argv[4]; - nissy_setlogger(log_stderr); + nissy_setlogger(log_stdout, NULL); timerun(run); diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c index 5b3db2c..00875fa 100644 --- a/tools/100_checkdata/checkdata.c +++ b/tools/100_checkdata/checkdata.c @@ -41,7 +41,7 @@ int main(int argc, char **argv) { solver = argv[1]; filename = argv[2]; - nissy_setlogger(log_stderr); + nissy_setlogger(log_stdout, NULL); timerun(run); diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c index bec8add..c6dd661 100644 --- a/tools/300_solve_small/solve_small.c +++ b/tools/300_solve_small/solve_small.c @@ -56,7 +56,7 @@ int main(int argc, char **argv) { solver = argv[1]; srand(time(NULL)); - nissy_setlogger(log_stderr); + nissy_setlogger(log_stdout, NULL); sprintf(filename, "tables/%s", solver); diff --git a/tools/301_solve_file/solve_file.c b/tools/301_solve_file/solve_file.c index a772e95..06b8198 100644 --- a/tools/301_solve_file/solve_file.c +++ b/tools/301_solve_file/solve_file.c @@ -46,7 +46,7 @@ int main(int argc, char **argv) { scrfilename = argv[2]; srand(time(NULL)); - nissy_setlogger(log_stderr); + nissy_setlogger(log_stdout, NULL); sprintf(filename, "tables/%s", solver); if (getdata(solver, &buf, filename) != 0) diff --git a/tools/302_solve_multisol/solve_multisol.c b/tools/302_solve_multisol/solve_multisol.c index e933a94..ec36711 100644 --- a/tools/302_solve_multisol/solve_multisol.c +++ b/tools/302_solve_multisol/solve_multisol.c @@ -50,7 +50,7 @@ int main(int argc, char **argv) { solver = argv[1]; nsol = atoi(argv[2]); srand(time(NULL)); - nissy_setlogger(log_stderr); + nissy_setlogger(log_stdout, NULL); sprintf(filename, "tables/%s", solver); diff --git a/tools/400_solvetest/solve_test.c b/tools/400_solvetest/solve_test.c index e881030..6e7b2a5 100644 --- a/tools/400_solvetest/solve_test.c +++ b/tools/400_solvetest/solve_test.c @@ -104,7 +104,7 @@ int main(int argc, char **argv) { solver = argv[1]; srand(time(NULL)); - nissy_setlogger(log_stderr); + nissy_setlogger(log_stdout, NULL); sprintf(filename, "tables/%s", solver); if (getdata(solver, &buf, filename) != 0) diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h index 3e9c9ab..505f53a 100644 --- a/tools/nissy_extra.h +++ b/tools/nissy_extra.h @@ -11,5 +11,5 @@ for testing purposes only. size_t gendata_h48_derive(uint8_t, const void *, void *); int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); -long long int nissy_datainfo(uint64_t, const char *, void (*)(const char *)); +long long int nissy_datainfo(uint64_t, const char *); long long int nissy_derivedata(const char *, const void *, void *); diff --git a/tools/tool.h b/tools/tool.h index 51301c6..ee6c8eb 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -9,8 +9,7 @@ #include "../src/nissy.h" #include "nissy_extra.h" -static void log_stderr(const char *); -static void log_stdout(const char *); +static void log_stdout(const char *, void *); static double timerun(void (*)(void)); static void writetable(const char *, int64_t, const char *); static long long int generatetable(const char *, char **, @@ -23,13 +22,7 @@ static void derivedata_run( const char *, const char *, const char *, const char *); static void -log_stderr(const char *str) -{ - fprintf(stderr, "%s", str); -} - -static void -write_stdout(const char *str) +log_stdout(const char *str, void *unused) { fprintf(stdout, "%s", str); } @@ -211,7 +204,7 @@ gendata_run( case -2: goto gendata_run_finish; default: - nissy_datainfo(size, buf, write_stdout); + nissy_datainfo(size, buf); printf("\n"); printf("Succesfully generated %lld bytes. " "See above for details on the tables.\n", size); @@ -244,7 +237,7 @@ derivedata_run( case -2: goto derivedata_run_finish; default: - nissy_datainfo(size, buf, write_stdout); + nissy_datainfo(size, buf); printf("\n"); printf("Succesfully generated %lld bytes. " "See above for details on the tables.\n", size); -- cgit v1.3