diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-08 15:16:21 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-08 15:16:21 +0200 |
| commit | e4f356b9592599ad91aac34bf2265c9bcdfbb81f (patch) | |
| tree | 5a95908f9cb9cf5ad7d7802661e1d0c3bc2a0e3a /tools/tool.h | |
| parent | c5a6ff0443fc9e5e890fe72cb13ea78d4fe2bbcb (diff) | |
| download | nissy-core-e4f356b9592599ad91aac34bf2265c9bcdfbb81f.tar.gz nissy-core-e4f356b9592599ad91aac34bf2265c9bcdfbb81f.zip | |
Some minor changes to the interface.
- Simplified logger to accept only a string, not a variadic list
of args like printf(). This can still use some improvement,
but now it is easier to use from other languages.
- Fixed some misuses of the logger (wrong types etc)
- Renamed some constants
- Fixed some typos in comments.
Diffstat (limited to 'tools/tool.h')
| -rw-r--r-- | tools/tool.h | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/tools/tool.h b/tools/tool.h index b65f33a..51301c6 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -9,12 +9,12 @@ | |||
| 9 | #include "../src/nissy.h" | 9 | #include "../src/nissy.h" |
| 10 | #include "nissy_extra.h" | 10 | #include "nissy_extra.h" |
| 11 | 11 | ||
| 12 | static void log_stderr(const char *, ...); | 12 | static void log_stderr(const char *); |
| 13 | static void log_stdout(const char *, ...); | 13 | static void log_stdout(const char *); |
| 14 | static double timerun(void (*)(void)); | 14 | static double timerun(void (*)(void)); |
| 15 | static void writetable(const char *, int64_t, const char *); | 15 | static void writetable(const char *, int64_t, const char *); |
| 16 | static long long int generatetable(const char *, char **, | 16 | static long long int generatetable(const char *, char **, |
| 17 | char [static NISSY_DATAID_SIZE]); | 17 | char [static NISSY_SIZE_DATAID]); |
| 18 | static long long int derivetable( | 18 | static long long int derivetable( |
| 19 | const char *, const char *, const char *, char **); | 19 | const char *, const char *, const char *, char **); |
| 20 | static int getdata(const char *, char **, const char *); | 20 | static int getdata(const char *, char **, const char *); |
| @@ -23,23 +23,15 @@ static void derivedata_run( | |||
| 23 | const char *, const char *, const char *, const char *); | 23 | const char *, const char *, const char *, const char *); |
| 24 | 24 | ||
| 25 | static void | 25 | static void |
| 26 | log_stderr(const char *str, ...) | 26 | log_stderr(const char *str) |
| 27 | { | 27 | { |
| 28 | va_list args; | 28 | fprintf(stderr, "%s", str); |
| 29 | |||
| 30 | va_start(args, str); | ||
| 31 | vfprintf(stderr, str, args); | ||
| 32 | va_end(args); | ||
| 33 | } | 29 | } |
| 34 | 30 | ||
| 35 | static void | 31 | static void |
| 36 | write_stdout(const char *str, ...) | 32 | write_stdout(const char *str) |
| 37 | { | 33 | { |
| 38 | va_list args; | 34 | fprintf(stdout, "%s", str); |
| 39 | |||
| 40 | va_start(args, str); | ||
| 41 | vfprintf(stdout, str, args); | ||
| 42 | va_end(args); | ||
| 43 | } | 35 | } |
| 44 | 36 | ||
| 45 | static double | 37 | static double |
| @@ -90,7 +82,7 @@ static long long int | |||
| 90 | generatetable( | 82 | generatetable( |
| 91 | const char *solver, | 83 | const char *solver, |
| 92 | char **buf, | 84 | char **buf, |
| 93 | char dataid[static NISSY_DATAID_SIZE] | 85 | char dataid[static NISSY_SIZE_DATAID] |
| 94 | ) | 86 | ) |
| 95 | { | 87 | { |
| 96 | long long int size, gensize; | 88 | long long int size, gensize; |
| @@ -125,7 +117,7 @@ derivetable( | |||
| 125 | { | 117 | { |
| 126 | uint8_t h, k; | 118 | uint8_t h, k; |
| 127 | long long int size, gensize; | 119 | long long int size, gensize; |
| 128 | char *fulltable, dataid[NISSY_DATAID_SIZE]; | 120 | char *fulltable, dataid[NISSY_SIZE_DATAID]; |
| 129 | 121 | ||
| 130 | if (getdata(solver_large, &fulltable, filename_large) != 0) { | 122 | if (getdata(solver_large, &fulltable, filename_large) != 0) { |
| 131 | printf("Error reading full table.\n"); | 123 | printf("Error reading full table.\n"); |
| @@ -169,7 +161,7 @@ getdata( | |||
| 169 | ) { | 161 | ) { |
| 170 | long long int size, sizeread; | 162 | long long int size, sizeread; |
| 171 | FILE *f; | 163 | FILE *f; |
| 172 | char dataid[NISSY_DATAID_SIZE]; | 164 | char dataid[NISSY_SIZE_DATAID]; |
| 173 | 165 | ||
| 174 | if ((f = fopen(filename, "rb")) == NULL) { | 166 | if ((f = fopen(filename, "rb")) == NULL) { |
| 175 | printf("Table file not found, generating it.\n"); | 167 | printf("Table file not found, generating it.\n"); |
| @@ -209,7 +201,7 @@ gendata_run( | |||
| 209 | uint64_t expected[static 21] | 201 | uint64_t expected[static 21] |
| 210 | ) { | 202 | ) { |
| 211 | long long int size; | 203 | long long int size; |
| 212 | char *buf, filename[1024], dataid[NISSY_DATAID_SIZE]; | 204 | char *buf, filename[1024], dataid[NISSY_SIZE_DATAID]; |
| 213 | 205 | ||
| 214 | size = generatetable(solver, &buf, dataid); | 206 | size = generatetable(solver, &buf, dataid); |
| 215 | sprintf(filename, "tables/%s", dataid); | 207 | sprintf(filename, "tables/%s", dataid); |
