summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2016-05-05 14:59:28 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2016-05-05 14:59:28 +0200
commit3405b0c1635843cbb81f042364bfcf238d7dc930 (patch)
tree39501fec9ec72863c929a45dbc297412bbf90688 /src/io/error.h
parentc28bb6d31a122ec983e1e0a0dd1a8bd198098c58 (diff)
Adds the current code.
It's been running for close to a month on one of the IRC channels I frequent and seems to be working fine. One should be aware that, among other missing features, this version does not store permanently what the bot learns. Indeed, I am currently using a file with 431848 lines as its initial knowledge bank, making this particular feature not a high priority one. Also consider the fact that Zero of One converts text to underscore before reading it but will not change its own aliases. This could potentially be a cause for surprises when using uppercase letters in the latter.
Diffstat (limited to 'src/io/error.h')
-rw-r--r--src/io/error.h146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/io/error.h b/src/io/error.h
new file mode 100644
index 0000000..e4267a0
--- /dev/null
+++ b/src/io/error.h
@@ -0,0 +1,146 @@
+#ifndef _ZoO_IO_ERROR_H_
+#define _ZoO_IO_ERROR_H_
+
+#include <stdio.h>
+
+#include "../pervasive.h"
+
+#define ZoO_DEBUG_ALL 1
+
+#ifndef ZoO_DEBUG_ALL
+ #define ZoO_DEBUG_ALL 0
+#endif
+
+#ifndef ZoO_DEBUG_PROGRAM_FLOW
+ #define ZoO_DEBUG_PROGRAM_FLOW (0 || ZoO_DEBUG_ALL)
+#endif
+
+#ifndef ZoO_DEBUG_CONFIG
+ #define ZoO_DEBUG_CONFIG (0 || ZoO_DEBUG_ALL)
+#endif
+
+#ifndef ZoO_DEBUG_LEARNING
+ #define ZoO_DEBUG_LEARNING (0 || ZoO_DEBUG_ALL)
+#endif
+
+#ifndef ZoO_DEBUG_NETWORK
+ #define ZoO_DEBUG_NETWORK (0 || ZoO_DEBUG_ALL)
+#endif
+
+#define ZoO_ENABLE_WARNINGS_OUTPUT 1
+#define ZoO_ENABLE_RUNTIME_ERRORS_OUTPUT 1
+#define ZoO_ENABLE_PROGRAMMING_ERRORS_OUTPUT 1
+#define ZoO_ENABLE_FATAL_ERROR_OUTPUT 1
+
+#ifdef ZoO_ENABLE_ERROR_LOCATION
+ #define ZoO_LOCATION "[" __FILE__ "][" ZoO_TO_STRING(__LINE__) "]"
+#else
+ #define ZoO_LOCATION ""
+#endif
+
+#define ZoO_PRINT_STDERR(symbol, str, ...)\
+ fprintf(stderr, "[" symbol "]" ZoO_LOCATION " " str "\n", __VA_ARGS__);
+
+/*
+ * Given that we use preprocessor contants as flags, we can expect the compilers
+ * to remove the test condition for disabled flags. No need to be shy about
+ * allowing many debug options.
+ */
+
+#define ZoO_DEBUG(flag, str, ...)\
+ ZoO_ISOLATE\
+ (\
+ if (flag)\
+ {\
+ ZoO_PRINT_STDERR("D", str, __VA_ARGS__);\
+ }\
+ )
+
+
+#define ZoO_WARNING(str, ...)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_WARNINGS_OUTPUT)\
+ {\
+ ZoO_PRINT_STDERR("W", str, __VA_ARGS__);\
+ }\
+ )
+
+#define ZoO_ERROR(str, ...)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_RUNTIME_ERRORS_OUTPUT)\
+ {\
+ ZoO_PRINT_STDERR("E", str, __VA_ARGS__);\
+ }\
+ )
+
+#define ZoO_PROG_ERROR(str, ...)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\
+ {\
+ ZoO_PRINT_STDERR("P", str, __VA_ARGS__);\
+ }\
+ )
+
+#define ZoO_FATAL(str, ...)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_FATAL_ERROR_OUTPUT)\
+ {\
+ ZoO_PRINT_STDERR("F", str, __VA_ARGS__);\
+ }\
+ )
+
+/* For outputs without dynamic content (static). ******************************/
+
+#define ZoO_PRINT_S_STDERR(symbol, str)\
+ fprintf(stderr, "[" symbol "]" ZoO_LOCATION " " str "\n");
+
+#define ZoO_S_DEBUG(flag, str)\
+ ZoO_ISOLATE\
+ (\
+ if (flag)\
+ {\
+ ZoO_PRINT_S_STDERR("D", str);\
+ }\
+ )
+
+#define ZoO_S_WARNING(str)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_WARNINGS_OUTPUT)\
+ {\
+ ZoO_PRINT_S_STDERR("W", str);\
+ }\
+ )
+
+#define ZoO_S_ERROR(str)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_RUNTIME_ERRORS_OUTPUT)\
+ {\
+ ZoO_PRINT_S_STDERR("E", str);\
+ }\
+ )
+
+#define ZoO_S_PROG_ERROR(str)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_PROGRAMMING_ERRORS_OUTPUT)\
+ {\
+ ZoO_PRINT_S_STDERR("P", str);\
+ }\
+ )
+
+#define ZoO_S_FATAL(str)\
+ ZoO_ISOLATE\
+ (\
+ if (ZoO_ENABLE_FATAL_ERROR_OUTPUT)\
+ {\
+ ZoO_PRINT_S_STDERR("F", str);\
+ }\
+ )
+
+#endif