Permalink
Browse files

unified error-telling system

  • Loading branch information...
1 parent d206411 commit 994a3965c218b238b87fda36b665572ce4a58d21 @niksaak committed Feb 20, 2013
Showing with 30 additions and 4 deletions.
  1. +21 −0 src/engine/util.c
  2. +9 −4 src/engine/util.h
View
@@ -43,6 +43,26 @@ bool nullp(const void* ptr)
return false;
}
+void promulgate(const char* funname, bool crushing, const char* warning, ...)
+{
+ static char crushstr[] = "CRUSHING ERROR @ %s: ";
+ static char warnstr[] = "WARNING @ %s: ";
+ char* errstr = warnstr;
+ va_list varargs;
+
+ if(crushing)
+ errstr = crushstr;
+
+ va_start(varargs, warning);
+ fprintf(stderr, errstr, funname);
+ vfprintf(stderr, warning, varargs);
+ fputc('\n', stderr);
+ va_end(varargs);
+
+ if(crushing)
+ exit(EXIT_FAILURE);
+}
+
void warn(const char* funname, const char* warning)
{
fprintf(stderr, "%s: WARNING: %s\n", funname, warning);
@@ -62,6 +82,7 @@ int ran_domo(Uint32 min, Uint32 max)
if(domo == RAND_MAX)
return ran_domo(min, max);
+
int range = max - min;
int rem = RAND_MAX % range;
int bucket = RAND_MAX / range;
View
@@ -10,13 +10,15 @@
#include <stdio.h>
#define DEBUG(...) \
fprintf(stderr, __VA_ARGS__);
+#else
+#define DEBUG(...)
#endif
-#define WARN(w) \
- warn(__func__, w);
+#define WARN(...) \
+ promulgate(__func__, false, __VA_ARGS__);
-#define CRASH(r) \
- crash(__func__, r);
+#define CRASH(...) \
+ promulgate(__func__, true, __VA_ARGS__);
typedef struct SDL_point {
int x;
@@ -31,6 +33,9 @@ extern cpVect SDLcpv(SDL_Point point, const SDL_Surface* target, cpVect offset);
extern bool nullp(const void*);
+extern void
+promulgate(const char* funname, bool crushing, const char* warning, ...);
+
extern void warn(const char*, const char*);
extern void crash(const char*, const char*);

0 comments on commit 994a396

Please sign in to comment.