diff options
Diffstat (limited to 'src/nissy.h')
| -rw-r--r-- | src/nissy.h | 142 |
1 files changed, 89 insertions, 53 deletions
diff --git a/src/nissy.h b/src/nissy.h index d365a32..6d78778 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -9,8 +9,8 @@ If you include this file, you should also use the following includes: | |||
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | 10 | ||
| 11 | All the functions return 0 or a positive integer in case of success and | 11 | All the functions return 0 or a positive integer in case of success and |
| 12 | a negative integer in case of error, unless otherwise specified. | 12 | a negative integer in case of error, unless otherwise specified. See at |
| 13 | You can see the list of error codes below, or use nissy_explainerror(). | 13 | the bottom of this file for the list of error codes and their meaning. |
| 14 | 14 | ||
| 15 | All cube arguments are in B32 formats, unless otherwise specified. | 15 | All cube arguments are in B32 formats, unless otherwise specified. |
| 16 | Other available formats are H48 and SRC. See README.md for more info on | 16 | Other available formats are H48 and SRC. See README.md for more info on |
| @@ -24,23 +24,6 @@ A transformation must be given in the format | |||
| 24 | for example 'rotation UF' or 'mirrored BL'. | 24 | for example 'rotation UF' or 'mirrored BL'. |
| 25 | */ | 25 | */ |
| 26 | 26 | ||
| 27 | /* Error codes */ | ||
| 28 | #define NISSY_OK INT64_C(0) | ||
| 29 | #define NISSY_WARNING_UNSOLVABLE INT64_C(-1) | ||
| 30 | #define NISSY_WARNING_NULL_CALLBACK INT64_C(-2) | ||
| 31 | #define NISSY_ERROR_INVALID_CUBE INT64_C(-10) | ||
| 32 | #define NISSY_ERROR_UNSOLVABLE_CUBE INT64_C(-11) | ||
| 33 | #define NISSY_ERROR_INVALID_MOVES INT64_C(-20) | ||
| 34 | #define NISSY_ERROR_INVALID_TRANS INT64_C(-30) | ||
| 35 | #define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) | ||
| 36 | #define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) | ||
| 37 | #define NISSY_ERROR_NULL_POINTER INT64_C(-60) | ||
| 38 | #define NISSY_ERROR_BUFFER_SIZE INT64_C(-61) | ||
| 39 | #define NISSY_ERROR_DATA INT64_C(-70) | ||
| 40 | #define NISSY_ERROR_OPTIONS INT64_C(-80) | ||
| 41 | #define NISSY_ERROR_INVALID_CODE INT64_C(-90) | ||
| 42 | #define NISSY_ERROR_UNKNOWN INT64_C(-999) | ||
| 43 | |||
| 44 | /* Some constants for size for I/O buffers */ | 27 | /* Some constants for size for I/O buffers */ |
| 45 | #define NISSY_SIZE_B32 UINT64_C(22) | 28 | #define NISSY_SIZE_B32 UINT64_C(22) |
| 46 | #define NISSY_SIZE_H48 UINT64_C(88) | 29 | #define NISSY_SIZE_H48 UINT64_C(88) |
| @@ -257,24 +240,6 @@ int64_t nissy_gendata( | |||
| 257 | ); | 240 | ); |
| 258 | 241 | ||
| 259 | /* | 242 | /* |
| 260 | Print information on a data table via the provided callback writer. | ||
| 261 | |||
| 262 | Parameters: | ||
| 263 | data_size - The size of the data buffer. | ||
| 264 | data - The data to be read. | ||
| 265 | write - A callback writer with the same signature as printf(3). | ||
| 266 | |||
| 267 | Return values: | ||
| 268 | NISSY_OK - The data is correct. | ||
| 269 | NISSY_ERROR_DATA - The data contains errors. | ||
| 270 | */ | ||
| 271 | int64_t nissy_datainfo( | ||
| 272 | uint64_t data_size, | ||
| 273 | const char data[data_size], | ||
| 274 | void (*write)(const char *, ...) | ||
| 275 | ); | ||
| 276 | |||
| 277 | /* | ||
| 278 | Check that the data is a valid data table for a solver. | 243 | Check that the data is a valid data table for a solver. |
| 279 | 244 | ||
| 280 | Parameters: | 245 | Parameters: |
| @@ -340,28 +305,99 @@ Parameters: | |||
| 340 | write - A callback writer with the same signature as printf(3). | 305 | write - A callback writer with the same signature as printf(3). |
| 341 | 306 | ||
| 342 | Return values: | 307 | Return values: |
| 343 | NISSY_OK - Logger set succesfully. | 308 | NISSY_OK - Logger set succesfully. No warning or error is goind to be given |
| 344 | NISSY_WARNING_NULL_CALLBACK - The provided callback writer is NULL. | 309 | if the logger is NULL or invalid. |
| 345 | */ | 310 | */ |
| 346 | int64_t nissy_setlogger( | 311 | int64_t nissy_setlogger( |
| 347 | void (*logger_function)(const char *, ...) | 312 | void (*logger_function)(const char *, ...) |
| 348 | ); | 313 | ); |
| 349 | 314 | ||
| 315 | |||
| 316 | /* Error codes */ | ||
| 317 | |||
| 350 | /* | 318 | /* |
| 351 | Print an explanation of the given error code via the provided callback writer. | 319 | The value NISSY_OK denotes a success. If returned by solve, it means |
| 320 | that no solution has been found. | ||
| 321 | */ | ||
| 322 | #define NISSY_OK INT64_C(0) | ||
| 352 | 323 | ||
| 353 | Parameters: | 324 | /* |
| 354 | error_code - The error code to be explained. It can be any value returned | 325 | The value NISSY_WARNING_UNSOLVABLE is a warning. It means that the |
| 355 | by a function in this library, not necessarily an error. | 326 | operation was completed succesfully, but the resulting cube is in an |
| 356 | write - A callback writer with the same signature as printf(3). | 327 | unsolvable state. This could be intended, for example if the user has |
| 357 | Must be non-NULL. | 328 | provided an unsolvable cube as input. |
| 329 | */ | ||
| 330 | #define NISSY_WARNING_UNSOLVABLE INT64_C(-1) | ||
| 358 | 331 | ||
| 359 | Return values: | 332 | /* |
| 360 | NISSY_OK - The error code is known. | 333 | The value NISSY_ERROR_INVALID_CUBE means that the provided cube is |
| 361 | NISSY_WARNING_NULL_CALLBACK - The provided callback writer is NULL. | 334 | invalid. It could be written in an unknown format, or in a format |
| 362 | NISSY_ERROR_INVALID_CODE - The error code is unknown. | 335 | different from what specified, or simply ill-formed. |
| 363 | */ | 336 | */ |
| 364 | int64_t nissy_explainerror( | 337 | #define NISSY_ERROR_INVALID_CUBE INT64_C(-10) |
| 365 | int64_t error_code, | 338 | |
| 366 | void (*write)(const char *, ...) | 339 | /* |
| 367 | ); | 340 | The value NISSY_ERROR_UNSOLVABLE_CUBE means that the provided cube is |
| 341 | in an unsolvable state. | ||
| 342 | */ | ||
| 343 | #define NISSY_ERROR_UNSOLVABLE_CUBE INT64_C(-11) | ||
| 344 | |||
| 345 | /* | ||
| 346 | The value NISSY_ERROR_INVALID_MOVES means that the given moves are | ||
| 347 | invalid. | ||
| 348 | */ | ||
| 349 | #define NISSY_ERROR_INVALID_MOVES INT64_C(-20) | ||
| 350 | |||
| 351 | /* | ||
| 352 | The value NISSY_ERROR_INVALID_TRANS means that the given transformation | ||
| 353 | is invalid. | ||
| 354 | */ | ||
| 355 | #define NISSY_ERROR_INVALID_TRANS INT64_C(-30) | ||
| 356 | |||
| 357 | /* | ||
| 358 | The value NISSY_ERROR_INVALID_FORMAT means that the given format is | ||
| 359 | not known. | ||
| 360 | */ | ||
| 361 | #define NISSY_ERROR_INVALID_FORMAT INT64_C(-40) | ||
| 362 | |||
| 363 | /* | ||
| 364 | The value NISSY_ERROR_INVALID_SOLVER means that the given solver is | ||
| 365 | not known. | ||
| 366 | */ | ||
| 367 | #define NISSY_ERROR_INVALID_SOLVER INT64_C(-50) | ||
| 368 | |||
| 369 | /* | ||
| 370 | The value NISSY_ERROR_NULL_POINTER means that one of the provided pointer | ||
| 371 | arguments is NULL. For example, it may be returned by solve when called | ||
| 372 | with a solver that requires some pre-computed data, but the provided | ||
| 373 | data is NULL. | ||
| 374 | */ | ||
| 375 | #define NISSY_ERROR_NULL_POINTER INT64_C(-60) | ||
| 376 | |||
| 377 | /* | ||
| 378 | The value NISSY_ERROR_BUFFER_SIZE means that one of the buffers provided | ||
| 379 | is too small. For example, it could be too small to hold the result or | ||
| 380 | too small to hold the data generated by gendata. | ||
| 381 | */ | ||
| 382 | #define NISSY_ERROR_BUFFER_SIZE INT64_C(-61) | ||
| 383 | |||
| 384 | /* | ||
| 385 | The value NISSY_ERROR_DATA means that the provided data is invalid. For | ||
| 386 | example, it may be returned by solve when called with incompatible solver | ||
| 387 | and data arguments. | ||
| 388 | */ | ||
| 389 | #define NISSY_ERROR_DATA INT64_C(-70) | ||
| 390 | |||
| 391 | /* | ||
| 392 | The value NISSY_ERROR_OPTIONS means that one or more of the given options | ||
| 393 | are invalid. For example, it may be returned by solve when called with | ||
| 394 | a negative maximum number of solutions. | ||
| 395 | */ | ||
| 396 | #define NISSY_ERROR_OPTIONS INT64_C(-80) | ||
| 397 | |||
| 398 | /* | ||
| 399 | The value NISSY_ERROR_UNKNOWN denotes an unexpected error. It probably | ||
| 400 | means that there some bug in this library. If you can, report any error | ||
| 401 | of this kind to sebastiano@tronto.net. Thanks! | ||
| 402 | */ | ||
| 403 | #define NISSY_ERROR_UNKNOWN INT64_C(-999) | ||
