diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-15 15:51:40 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-15 15:51:40 +0200 |
| commit | b25a939e2d8b045c083caf3264c4e5aac1cf88fb (patch) | |
| tree | 37b862c82389ceddcf4624b5e26536390d6b8265 /src/nissy.c | |
| parent | b02c083a3545b6e6b36ab62680128edec619a804 (diff) | |
| download | nissy-core-b25a939e2d8b045c083caf3264c4e5aac1cf88fb.tar.gz nissy-core-b25a939e2d8b045c083caf3264c4e5aac1cf88fb.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | src/nissy.c | 21 |
1 files changed, 10 insertions, 11 deletions
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( | |||
| 366 | long long | 366 | long long |
| 367 | nissy_datainfo( | 367 | nissy_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 | ||
| 625 | long long | 622 | long long |
| 626 | nissy_setlogger( | 623 | nissy_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 | } |
