aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cpp/examples/solve_h48h3k2.cpp2
-rw-r--r--cpp/nissy.cpp7
-rw-r--r--cpp/nissy.h2
-rw-r--r--python/nissy_module.c4
-rw-r--r--shell/shell.c4
-rw-r--r--src/nissy.c21
-rw-r--r--src/nissy.h9
-rw-r--r--src/utils/dbg_log.h9
-rw-r--r--test/test.h4
-rw-r--r--tools/000_gendata/gendata.c4
-rw-r--r--tools/001_derive_h48/derive_h48.c2
-rw-r--r--tools/100_checkdata/checkdata.c2
-rw-r--r--tools/300_solve_small/solve_small.c2
-rw-r--r--tools/301_solve_file/solve_file.c2
-rw-r--r--tools/302_solve_multisol/solve_multisol.c2
-rw-r--r--tools/400_solvetest/solve_test.c2
-rw-r--r--tools/nissy_extra.h2
-rw-r--r--tools/tool.h15
18 files changed, 48 insertions, 47 deletions
diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp
index 454d6dc..7f06376 100644
--- a/cpp/examples/solve_h48h3k2.cpp
+++ b/cpp/examples/solve_h48h3k2.cpp
@@ -8,7 +8,7 @@
8 8
9int main() { 9int main() {
10 // Get verbose output 10 // Get verbose output
11 nissy::set_logger([](const char* s) { std::cout << s; }); 11 nissy::set_logger([](const char* s, void *u) { std::cout << s; }, NULL);
12 12
13 // Get the scramble from the user 13 // Get the scramble from the user
14 std::cout << "Enter scramble: "; 14 std::cout << "Enter scramble: ";
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp
index 2a52ab1..944944b 100644
--- a/cpp/nissy.cpp
+++ b/cpp/nissy.cpp
@@ -24,7 +24,7 @@ extern "C" {
24 unsigned, unsigned, int, int, unsigned long long, const char *, 24 unsigned, unsigned, int, int, unsigned long long, const char *,
25 unsigned, char *, long long *); 25 unsigned, char *, long long *);
26 long long nissy_countmoves(const char *); 26 long long nissy_countmoves(const char *);
27 long long nissy_setlogger(void (*)(const char *)); 27 long long nissy_setlogger(void (*)(const char *, void *), void *);
28} 28}
29 29
30namespace nissy { 30namespace nissy {
@@ -227,5 +227,8 @@ namespace nissy {
227 return error{err}; 227 return error{err};
228 } 228 }
229 229
230 void set_logger(void (*log)(const char *)) { nissy_setlogger(log); } 230 void set_logger(void (*log)(const char *, void *), void *data)
231 {
232 nissy_setlogger(log, data);
233 }
231} 234}
diff --git a/cpp/nissy.h b/cpp/nissy.h
index ff74f12..db8ba5f 100644
--- a/cpp/nissy.h
+++ b/cpp/nissy.h
@@ -100,7 +100,7 @@ namespace nissy {
100 }; 100 };
101 101
102 error count_moves(const std::string&); 102 error count_moves(const std::string&);
103 void set_logger(void (*)(const char*)); 103 void set_logger(void (*)(const char *, void *), void *);
104} 104}
105 105
106#endif 106#endif
diff --git a/python/nissy_module.c b/python/nissy_module.c
index da0b1c5..e92cfd9 100644
--- a/python/nissy_module.c
+++ b/python/nissy_module.c
@@ -421,7 +421,7 @@ static struct PyModuleDef nissy_python_module = {
421}; 421};
422 422
423static void 423static void
424log_stdout(const char *str) 424log_stdout(const char *str, void *unused)
425{ 425{
426 fprintf(stderr, "%s", str); 426 fprintf(stderr, "%s", str);
427} 427}
@@ -429,7 +429,7 @@ log_stdout(const char *str)
429PyMODINIT_FUNC PyInit_nissy_python_module(void) { 429PyMODINIT_FUNC PyInit_nissy_python_module(void) {
430 PyObject *module; 430 PyObject *module;
431 431
432 nissy_setlogger(log_stdout); 432 nissy_setlogger(log_stdout, NULL);
433 module = PyModule_Create(&nissy_python_module); 433 module = PyModule_Create(&nissy_python_module);
434 434
435 PyModule_AddStringConstant(module, "solved_cube", NISSY_SOLVED_CUBE); 435 PyModule_AddStringConstant(module, "solved_cube", NISSY_SOLVED_CUBE);
diff --git a/shell/shell.c b/shell/shell.c
index 6b349e5..1ef1a39 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -780,7 +780,7 @@ set_threads(int argc, char **argv, args_t *args)
780} 780}
781 781
782void 782void
783log_stderr(const char *str) 783log_stderr(const char *str, void *unused)
784{ 784{
785 fprintf(stderr, "%s", str); 785 fprintf(stderr, "%s", str);
786} 786}
@@ -792,7 +792,7 @@ main(int argc, char **argv)
792 args_t args; 792 args_t args;
793 793
794 srand(time(NULL)); 794 srand(time(NULL));
795 nissy_setlogger(log_stderr); 795 nissy_setlogger(log_stderr, NULL);
796 796
797 parse_error = parse_args(argc-1, argv+1, &args); 797 parse_error = parse_args(argc-1, argv+1, &args);
798 if (parse_error) 798 if (parse_error)
diff --git a/src/nissy.c b/src/nissy.c
index 92fc01b..a7f8432 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -366,8 +366,7 @@ nissy_getcube(
366long long 366long long
367nissy_datainfo( 367nissy_datainfo(
368 uint64_t data_size, 368 uint64_t data_size,
369 const char data[data_size], 369 const char data[data_size]
370 void (*write)(const char *)
371) 370)
372{ 371{
373 uint8_t i; 372 uint8_t i;
@@ -383,8 +382,7 @@ nissy_datainfo(
383 if (ret != 0) 382 if (ret != 0)
384 return ret; 383 return ret;
385 384
386 write_wrapper(write, 385 LOG("\n---------\n\n"
387 "\n---------\n\n"
388 "Table information for '%s'\n\n" 386 "Table information for '%s'\n\n"
389 "Size: %" PRIu64 " bytes\n" 387 "Size: %" PRIu64 " bytes\n"
390 "Entries: %" PRIu64 " (%" PRIu8 " bits per entry)\n", 388 "Entries: %" PRIu64 " (%" PRIu8 " bits per entry)\n",
@@ -392,15 +390,14 @@ nissy_datainfo(
392 390
393 switch (info.type) { 391 switch (info.type) {
394 case TABLETYPE_PRUNING: 392 case TABLETYPE_PRUNING:
395 write_wrapper(write, "\nTable distribution:\n" 393 LOG("\nTable distribution:\nValue\tPositions\n");
396 "Value\tPositions\n");
397 for (i = 0; i <= info.maxvalue; i++) { 394 for (i = 0; i <= info.maxvalue; i++) {
398 write_wrapper(write, "%" PRIu8 "\t%" PRIu64 "\n", 395 LOG("%" PRIu8 "\t%" PRIu64 "\n",
399 i + info.base, info.distribution[i]); 396 i + info.base, info.distribution[i]);
400 } 397 }
401 break; 398 break;
402 case TABLETYPE_SPECIAL: 399 case TABLETYPE_SPECIAL:
403 write_wrapper(write, "This is an ad-hoc table\n"); 400 LOG("This is an ad-hoc table\n");
404 break; 401 break;
405 default: 402 default:
406 LOG("datainfo: unknown table type\n"); 403 LOG("datainfo: unknown table type\n");
@@ -409,9 +406,9 @@ nissy_datainfo(
409 406
410 if (info.next != 0) 407 if (info.next != 0)
411 return nissy_datainfo( 408 return nissy_datainfo(
412 data_size - info.next, (char *)data + info.next, write); 409 data_size - info.next, (char *)data + info.next);
413 410
414 write_wrapper(write, "\n---------\n"); 411 LOG("\n---------\n");
415 412
416 return NISSY_OK; 413 return NISSY_OK;
417} 414}
@@ -624,9 +621,11 @@ nissy_countmoves(
624 621
625long long 622long long
626nissy_setlogger( 623nissy_setlogger(
627 void (*log)(const char *) 624 void (*log)(const char *, void *),
625 void *user_data
628) 626)
629{ 627{
630 nissy_log = log; 628 nissy_log = log;
629 nissy_log_data = user_data;
631 return NISSY_OK; 630 return NISSY_OK;
632} 631}
diff --git a/src/nissy.h b/src/nissy.h
index 816e03a..b13f417 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -421,7 +421,11 @@ Set a global logger function used by this library. Setting the logger to NULL
421disables logging. 421disables logging.
422 422
423Parameters: 423Parameters:
424 write - A callback writer with the same signature as printf(3). 424 logger_function - A pointer to a function that takes two parameters:
425 * A C string, the string to be printed.
426 * Any other data via a void pointer.
427 user_data - Any data that will be provided by the logger when
428 calling logger_function.
425 429
426Return values: 430Return values:
427 NISSY_OK - Logger set succesfully. No warning or error is going to be given 431 NISSY_OK - Logger set succesfully. No warning or error is going to be given
@@ -429,5 +433,6 @@ Return values:
429*/ 433*/
430long long 434long long
431nissy_setlogger( 435nissy_setlogger(
432 void (*logger_function)(const char *) 436 void (*logger_function)(const char *, void *),
437 void *user_data
433); 438);
diff --git a/src/utils/dbg_log.h b/src/utils/dbg_log.h
index 2467983..e5b3e24 100644
--- a/src/utils/dbg_log.h
+++ b/src/utils/dbg_log.h
@@ -1,10 +1,11 @@
1#include <stdio.h> 1#include <stdio.h>
2 2
3void (*nissy_log)(const char *); 3void (*nissy_log)(const char *, void *);
4void write_wrapper(void (*)(const char *), const char *, ...); 4void *nissy_log_data;
5void write_wrapper(void (*)(const char *, void *), const char *, ...);
5 6
6void 7void
7write_wrapper(void (*write)(const char *), const char *str, ...) 8write_wrapper(void (*write)(const char *, void *), const char *str, ...)
8{ 9{
9 static const size_t len = 1000; 10 static const size_t len = 1000;
10 char message[len]; 11 char message[len];
@@ -14,7 +15,7 @@ write_wrapper(void (*write)(const char *), const char *str, ...)
14 vsprintf(message, str, args); 15 vsprintf(message, str, args);
15 va_end(args); 16 va_end(args);
16 17
17 write(message); 18 write(message, nissy_log_data);
18} 19}
19 20
20#define LOG(...) if (nissy_log != NULL) write_wrapper(nissy_log, __VA_ARGS__); 21#define LOG(...) if (nissy_log != NULL) write_wrapper(nissy_log, __VA_ARGS__);
diff --git a/test/test.h b/test/test.h
index 0b12fb7..97f229b 100644
--- a/test/test.h
+++ b/test/test.h
@@ -31,13 +31,13 @@ int64_t writecube(const char *, cube_t, size_t n, char [n]);
31/* Test function to be implemented by all tests */ 31/* Test function to be implemented by all tests */
32void run(void); 32void run(void);
33 33
34void log_stderr(const char *str) 34void log_stderr(const char *str, void *unused)
35{ 35{
36 fprintf(stderr, "%s", str); 36 fprintf(stderr, "%s", str);
37} 37}
38 38
39int main(void) { 39int main(void) {
40 nissy_setlogger(log_stderr); 40 nissy_setlogger(log_stderr, NULL);
41 run(); 41 run();
42 return 0; 42 return 0;
43} 43}
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) {
17 case -2: 17 case -2:
18 goto gendata_run_finish; 18 goto gendata_run_finish;
19 default: 19 default:
20 nissy_datainfo(size, buf, write_stdout); 20 nissy_datainfo(size, buf);
21 consistent = nissy_checkdata(size, buf) == 0; 21 consistent = nissy_checkdata(size, buf) == 0;
22 expected = check_distribution(solver, size, buf); 22 expected = check_distribution(solver, size, buf);
23 if (consistent && expected) { 23 if (consistent && expected) {
@@ -51,7 +51,7 @@ int main(int argc, char **argv) {
51 parse_h48_solver(solver, &h, &k); 51 parse_h48_solver(solver, &h, &k);
52 expected = expected_h48[h][k]; 52 expected = expected_h48[h][k];
53 53
54 nissy_setlogger(log_stderr); 54 nissy_setlogger(log_stdout, NULL);
55 55
56 timerun(run); 56 timerun(run);
57 57
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) {
32 filename_large = argv[3]; 32 filename_large = argv[3];
33 filename_small = argv[4]; 33 filename_small = argv[4];
34 34
35 nissy_setlogger(log_stderr); 35 nissy_setlogger(log_stdout, NULL);
36 36
37 timerun(run); 37 timerun(run);
38 38
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) {
41 41
42 solver = argv[1]; 42 solver = argv[1];
43 filename = argv[2]; 43 filename = argv[2];
44 nissy_setlogger(log_stderr); 44 nissy_setlogger(log_stdout, NULL);
45 45
46 timerun(run); 46 timerun(run);
47 47
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) {
56 56
57 solver = argv[1]; 57 solver = argv[1];
58 srand(time(NULL)); 58 srand(time(NULL));
59 nissy_setlogger(log_stderr); 59 nissy_setlogger(log_stdout, NULL);
60 60
61 61
62 sprintf(filename, "tables/%s", solver); 62 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) {
46 scrfilename = argv[2]; 46 scrfilename = argv[2];
47 47
48 srand(time(NULL)); 48 srand(time(NULL));
49 nissy_setlogger(log_stderr); 49 nissy_setlogger(log_stdout, NULL);
50 50
51 sprintf(filename, "tables/%s", solver); 51 sprintf(filename, "tables/%s", solver);
52 if (getdata(solver, &buf, filename) != 0) 52 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) {
50 solver = argv[1]; 50 solver = argv[1];
51 nsol = atoi(argv[2]); 51 nsol = atoi(argv[2]);
52 srand(time(NULL)); 52 srand(time(NULL));
53 nissy_setlogger(log_stderr); 53 nissy_setlogger(log_stdout, NULL);
54 54
55 55
56 sprintf(filename, "tables/%s", solver); 56 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) {
104 104
105 solver = argv[1]; 105 solver = argv[1];
106 srand(time(NULL)); 106 srand(time(NULL));
107 nissy_setlogger(log_stderr); 107 nissy_setlogger(log_stdout, NULL);
108 108
109 sprintf(filename, "tables/%s", solver); 109 sprintf(filename, "tables/%s", solver);
110 if (getdata(solver, &buf, filename) != 0) 110 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.
11 11
12size_t gendata_h48_derive(uint8_t, const void *, void *); 12size_t gendata_h48_derive(uint8_t, const void *, void *);
13int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); 13int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]);
14long long int nissy_datainfo(uint64_t, const char *, void (*)(const char *)); 14long long int nissy_datainfo(uint64_t, const char *);
15long long int nissy_derivedata(const char *, const void *, void *); 15long 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 @@
9#include "../src/nissy.h" 9#include "../src/nissy.h"
10#include "nissy_extra.h" 10#include "nissy_extra.h"
11 11
12static void log_stderr(const char *); 12static void log_stdout(const char *, void *);
13static void log_stdout(const char *);
14static double timerun(void (*)(void)); 13static double timerun(void (*)(void));
15static void writetable(const char *, int64_t, const char *); 14static void writetable(const char *, int64_t, const char *);
16static long long int generatetable(const char *, char **, 15static long long int generatetable(const char *, char **,
@@ -23,13 +22,7 @@ static void derivedata_run(
23 const char *, const char *, const char *, const char *); 22 const char *, const char *, const char *, const char *);
24 23
25static void 24static void
26log_stderr(const char *str) 25log_stdout(const char *str, void *unused)
27{
28 fprintf(stderr, "%s", str);
29}
30
31static void
32write_stdout(const char *str)
33{ 26{
34 fprintf(stdout, "%s", str); 27 fprintf(stdout, "%s", str);
35} 28}
@@ -211,7 +204,7 @@ gendata_run(
211 case -2: 204 case -2:
212 goto gendata_run_finish; 205 goto gendata_run_finish;
213 default: 206 default:
214 nissy_datainfo(size, buf, write_stdout); 207 nissy_datainfo(size, buf);
215 printf("\n"); 208 printf("\n");
216 printf("Succesfully generated %lld bytes. " 209 printf("Succesfully generated %lld bytes. "
217 "See above for details on the tables.\n", size); 210 "See above for details on the tables.\n", size);
@@ -244,7 +237,7 @@ derivedata_run(
244 case -2: 237 case -2:
245 goto derivedata_run_finish; 238 goto derivedata_run_finish;
246 default: 239 default:
247 nissy_datainfo(size, buf, write_stdout); 240 nissy_datainfo(size, buf);
248 printf("\n"); 241 printf("\n");
249 printf("Succesfully generated %lld bytes. " 242 printf("Succesfully generated %lld bytes. "
250 "See above for details on the tables.\n", size); 243 "See above for details on the tables.\n", size);

Generated with cgit - Back to sebastiano.tronto.net