src/lib/error.h
branchnew-lib-errors
changeset 217 7728d6ec3abf
parent 216 a10ba529ae39
child 218 5229a5d098b2
--- a/src/lib/error.h	Wed May 27 23:07:00 2009 +0300
+++ b/src/lib/error.h	Wed May 27 23:57:48 2009 +0300
@@ -11,6 +11,7 @@
  * tree has it's own set of error codes, and then error info contexts contain a stack of these error codes, which can
  * then be used to trace the error down.
  */
+#include <stdbool.h>
 
 /**
  * The type used to represent a scalar error code, there are only unique per level.
@@ -133,7 +134,7 @@
     } stack[ERROR_DEPTH_MAX];
 
     /** Current top of stack for accumulating errors, NULL means empty stack */
-    struct error_info_level *cur;
+    struct error_item *cur;
 
     /** Type info for external error info */
     const struct error_extra_type *extra_type;
@@ -154,9 +155,9 @@
 const struct error_type* error_lookup (const error_t *err);
 
 /**
- * Return the error name for the lowest level error in the given state's stack.
+ * Return the error name for the given code.
  */
-const char* error_name (const error_t *err);
+const char* error_name (const struct error_list *list, err_t code);
 
 /**
  * Maximum length of messages returned by error_msg
@@ -175,17 +176,16 @@
 
 
 /**
- * Reset the given error state to an empty state
+ * Reset the given error state to an empty state.
+ *
+ * This is just the same as memset() with zero.
  */
-static inline void error_reset (error_t *err)
-{
-    memset(err, 0, sizeof(*err));
-}
+void error_reset (error_t *err);
 
 /**
  * Evaluates to the current top of the error stack, 
  */
-static struct error_item* error_top (const error_t *err)
+static struct error_item* error_top (error_t *err)
 {
     return err->cur ? err->cur : err->stack;
 }
@@ -275,4 +275,18 @@
  */
 #define NOT_REACHED(val) error_abort("%s = %#x", #val, (int) (val));
 
+/**
+ * General-purpose errors that may be useful and don't belong in any more specific namespace.
+ */
+enum general_error_code {
+    ERR_GENERAL_NONE,
+    ERR_MEM,                ///< memory allocation error
+    ERR_NOT_IMPLEMENTED,    ///< function not implmented: <func>
+    ERR_MISC,               ///< miscellaneous error: <error>
+    ERR_CMD_OPT,            ///< invalid command line option: <error> - XXX: replace with something getopt
+    ERR_UNKNOWN,            ///< unknown error
+};
+
+const struct error_list general_errors;
+
 #endif /* LIBQMSK_ERROR_H */