aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nissy.c144
-rw-r--r--src/nissy.h142
2 files changed, 89 insertions, 197 deletions
diff --git a/src/nissy.c b/src/nissy.c
index d5d0270..6b083e0 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -571,149 +571,5 @@ nissy_setlogger(
571) 571)
572{ 572{
573 nissy_log = log; 573 nissy_log = log;
574
575 if (log == NULL)
576 return NISSY_WARNING_NULL_CALLBACK;
577
578 return NISSY_OK; 574 return NISSY_OK;
579} 575}
580
581int64_t
582nissy_explainerror(
583 int64_t error_code,
584 void (*write)(const char *, ...)
585)
586{
587 if (write == NULL)
588 return NISSY_WARNING_NULL_CALLBACK;
589
590 switch (error_code) {
591 case NISSY_OK:
592 write(
593 "The value %" PRId64 " denotes a success.\n"
594 "If returned by solve, it means that no solutions has "
595 "been found.\n", NISSY_OK
596 );
597 return NISSY_OK;
598 case NISSY_WARNING_UNSOLVABLE:
599 write(
600 "The value %" PRId64 " is a warning. It means that the "
601 "operation was completed succesfully, but the resulting "
602 "cube is in an unsolvable state. This could be intended, "
603 "for example if the user has provided an unsolvable cube "
604 "as input.\n", NISSY_WARNING_UNSOLVABLE
605 );
606 return NISSY_OK;
607 case NISSY_WARNING_NULL_CALLBACK:
608 write(
609 "The value %" PRId64 " is a warning. It means that the "
610 "provided pointer to a writer function is NULL.\n"
611 "If returned by nissy_setlogger, it means that any future "
612 "log messages will not be printed.\n",
613 NISSY_WARNING_NULL_CALLBACK
614 );
615 return NISSY_OK;
616 case NISSY_ERROR_INVALID_CUBE:
617 write(
618 "The value %" PRId64 " means that the provided cube is "
619 "invalid. It could be written in an unknown format, or "
620 "in a format different from what specified, or simply "
621 "ill-formed.\n", NISSY_ERROR_INVALID_CUBE
622 );
623 return NISSY_OK;
624 case NISSY_ERROR_UNSOLVABLE_CUBE:
625 write(
626 "The value %" PRId64 " means that the provided cube is "
627 "in an unsolvable state.\n", NISSY_ERROR_INVALID_CUBE
628 );
629 return NISSY_OK;
630 case NISSY_ERROR_INVALID_MOVES:
631 write(
632 "The value %" PRId64 " means that the given moves are "
633 "invalid.\n", NISSY_ERROR_INVALID_MOVES
634 );
635 return NISSY_OK;
636 case NISSY_ERROR_INVALID_TRANS:
637 write(
638 "The value %" PRId64 " means that the given transformation "
639 "is invalid.\n", NISSY_ERROR_INVALID_TRANS
640 );
641 return NISSY_OK;
642 case NISSY_ERROR_INVALID_FORMAT:
643 write(
644 "The value %" PRId64 " means that the given format is not "
645 "known.\n", NISSY_ERROR_INVALID_FORMAT
646 );
647 return NISSY_OK;
648 case NISSY_ERROR_INVALID_SOLVER:
649 write(
650 "The value %" PRId64 " means that the given solver is not "
651 "known.\n", NISSY_ERROR_INVALID_SOLVER
652 );
653 return NISSY_OK;
654 case NISSY_ERROR_NULL_POINTER:
655 write(
656 "The value %" PRId64 " means that one of the provided "
657 "pointer arguments is NULL. For example, it may be "
658 "returned by solve when called with a solver that "
659 "requires some pre-computed data, but the provided data "
660 "is NULL.\n", NISSY_ERROR_NULL_POINTER
661 );
662 return NISSY_OK;
663 case NISSY_ERROR_BUFFER_SIZE:
664 write(
665 "The value %" PRId64 " means that one of the buffers "
666 "provided is too small. For example, it could be too "
667 "small to hold the result or too small to hold the data "
668 "generated by gendata.\n", NISSY_ERROR_BUFFER_SIZE
669 );
670 return NISSY_OK;
671 case NISSY_ERROR_DATA:
672 write(
673 "The value %" PRId64 " means that the provided data is "
674 "invalid. For example, it may be returned by solve when "
675 "called with incompatible solver and data arguments.\n",
676 NISSY_ERROR_DATA
677 );
678 return NISSY_OK;
679 case NISSY_ERROR_OPTIONS:
680 write(
681 "The value %" PRId64 " means that one or more of the "
682 "given options are invalid. For example, it may be "
683 "returned by solve when called with a negative maximum "
684 "number of solutions.\n", NISSY_ERROR_OPTIONS
685 );
686 return NISSY_OK;
687 case NISSY_ERROR_INVALID_CODE:
688 write(
689 "The value %" PRId64 " means that the given error code "
690 "is not known. It may be returned by explainerror.\n",
691 NISSY_ERROR_INVALID_CODE
692 );
693 return NISSY_OK;
694 case NISSY_ERROR_UNKNOWN:
695 write(
696 "The value %" PRId64 " denotes an unexpected error. It "
697 "probably means that there some bug in this library.\n"
698 "If you can, report any error of this kind to "
699 "sebastiano@tronto.net. Thanks!\n", NISSY_ERROR_UNKNOWN
700 );
701 return NISSY_OK;
702 default:
703 break;
704 }
705
706 if (error_code > 0) {
707 write(
708 "A positive return values does not denote an error\n"
709 "If returned by gendata or datasize, it denotes the size "
710 "of the data, in bytes\n"
711 "If returned by solve, it denotes the number of solutions "
712 "found.\n"
713 );
714 return NISSY_OK;
715 } else {
716 write("Unknown error code %" PRId64 "\n", error_code);
717 return NISSY_ERROR_INVALID_CODE;
718 }
719}
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
11All the functions return 0 or a positive integer in case of success and 11All the functions return 0 or a positive integer in case of success and
12a negative integer in case of error, unless otherwise specified. 12a negative integer in case of error, unless otherwise specified. See at
13You can see the list of error codes below, or use nissy_explainerror(). 13the bottom of this file for the list of error codes and their meaning.
14 14
15All cube arguments are in B32 formats, unless otherwise specified. 15All cube arguments are in B32 formats, unless otherwise specified.
16Other available formats are H48 and SRC. See README.md for more info on 16Other 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
24for example 'rotation UF' or 'mirrored BL'. 24for 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/*
260Print information on a data table via the provided callback writer.
261
262Parameters:
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
267Return values:
268 NISSY_OK - The data is correct.
269 NISSY_ERROR_DATA - The data contains errors.
270*/
271int64_t nissy_datainfo(
272 uint64_t data_size,
273 const char data[data_size],
274 void (*write)(const char *, ...)
275);
276
277/*
278Check that the data is a valid data table for a solver. 243Check that the data is a valid data table for a solver.
279 244
280Parameters: 245Parameters:
@@ -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
342Return values: 307Return 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*/
346int64_t nissy_setlogger( 311int64_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/*
351Print an explanation of the given error code via the provided callback writer. 319The value NISSY_OK denotes a success. If returned by solve, it means
320that no solution has been found.
321*/
322#define NISSY_OK INT64_C(0)
352 323
353Parameters: 324/*
354 error_code - The error code to be explained. It can be any value returned 325The value NISSY_WARNING_UNSOLVABLE is a warning. It means that the
355 by a function in this library, not necessarily an error. 326operation was completed succesfully, but the resulting cube is in an
356 write - A callback writer with the same signature as printf(3). 327unsolvable state. This could be intended, for example if the user has
357 Must be non-NULL. 328provided an unsolvable cube as input.
329*/
330#define NISSY_WARNING_UNSOLVABLE INT64_C(-1)
358 331
359Return values: 332/*
360 NISSY_OK - The error code is known. 333The value NISSY_ERROR_INVALID_CUBE means that the provided cube is
361 NISSY_WARNING_NULL_CALLBACK - The provided callback writer is NULL. 334invalid. It could be written in an unknown format, or in a format
362 NISSY_ERROR_INVALID_CODE - The error code is unknown. 335different from what specified, or simply ill-formed.
363*/ 336*/
364int64_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); 340The value NISSY_ERROR_UNSOLVABLE_CUBE means that the provided cube is
341in an unsolvable state.
342*/
343#define NISSY_ERROR_UNSOLVABLE_CUBE INT64_C(-11)
344
345/*
346The value NISSY_ERROR_INVALID_MOVES means that the given moves are
347invalid.
348*/
349#define NISSY_ERROR_INVALID_MOVES INT64_C(-20)
350
351/*
352The value NISSY_ERROR_INVALID_TRANS means that the given transformation
353is invalid.
354*/
355#define NISSY_ERROR_INVALID_TRANS INT64_C(-30)
356
357/*
358The value NISSY_ERROR_INVALID_FORMAT means that the given format is
359not known.
360*/
361#define NISSY_ERROR_INVALID_FORMAT INT64_C(-40)
362
363/*
364The value NISSY_ERROR_INVALID_SOLVER means that the given solver is
365not known.
366*/
367#define NISSY_ERROR_INVALID_SOLVER INT64_C(-50)
368
369/*
370The value NISSY_ERROR_NULL_POINTER means that one of the provided pointer
371arguments is NULL. For example, it may be returned by solve when called
372with a solver that requires some pre-computed data, but the provided
373data is NULL.
374*/
375#define NISSY_ERROR_NULL_POINTER INT64_C(-60)
376
377/*
378The value NISSY_ERROR_BUFFER_SIZE means that one of the buffers provided
379is too small. For example, it could be too small to hold the result or
380too small to hold the data generated by gendata.
381*/
382#define NISSY_ERROR_BUFFER_SIZE INT64_C(-61)
383
384/*
385The value NISSY_ERROR_DATA means that the provided data is invalid. For
386example, it may be returned by solve when called with incompatible solver
387and data arguments.
388*/
389#define NISSY_ERROR_DATA INT64_C(-70)
390
391/*
392The value NISSY_ERROR_OPTIONS means that one or more of the given options
393are invalid. For example, it may be returned by solve when called with
394a negative maximum number of solutions.
395*/
396#define NISSY_ERROR_OPTIONS INT64_C(-80)
397
398/*
399The value NISSY_ERROR_UNKNOWN denotes an unexpected error. It probably
400means that there some bug in this library. If you can, report any error
401of this kind to sebastiano@tronto.net. Thanks!
402*/
403#define NISSY_ERROR_UNKNOWN INT64_C(-999)

Generated with cgit - Back to sebastiano.tronto.net