]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - error.c
cache filenames as such instead of using code_cachedstring
[xonotic/gmqcc.git] / error.c
diff --git a/error.c b/error.c
index c220d72e57edd71c6af6465d1cf3c757e7da5b2e..e6a1c7da2f5f499f483d03b2de47c462e0756803 100644 (file)
--- a/error.c
+++ b/error.c
@@ -1,6 +1,7 @@
 /*
- * Copyright (C) 2012 
- *     Dale Weiler
+ * Copyright (C) 2012
+ *     Dale Weiler
+ *     Wolfgang Bumiller
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  * this software and associated documentation files (the "Software"), to deal in
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
-#include <stdarg.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
+#include "gmqcc.h"
 
 /*
  * Compiler error system, this handles the error printing, and managing
  * such as after so many errors just stop the compilation, and other
  * intereting like colors for the console.
  */
+
 #ifndef WIN32
-#      define CON_BLACK   30
-#      define CON_RED     31
-#      define CON_GREEN   32
-#      define CON_BROWN   33
-#      define CON_BLUE    34
-#      define CON_MAGENTA 35
-#      define CON_CYAN    36
-#      define CON_WHITE   37
-static const int error_color[] = {
-       CON_RED,
-       CON_CYAN,
-       CON_MAGENTA
+int levelcolor[] = {
+    CON_WHITE,
+    CON_CYAN,
+    CON_RED
 };
 #endif
-int error_total = 0;
-int error_max   = 10;
-
-static const char *const error_list[] = {
-       "Parsing Error:",
-       "Lexing Error:",
-       "Internal Error:"
-};
 
-int error(int status, const char *msg, ...) {
-       char      bu[1024*4]; /* enough? */
-       char      fu[1024*4]; /* enough? */
-       va_list   va;
-       
-       if (error_total + 1 > error_max) {
-               fprintf(stderr, "%d errors and more following, bailing\n", error_total);
-               exit (-1);
-       }
-       error_total ++;
-/* color */
-#      ifndef WIN32
-       sprintf  (bu, "\033[0;%dm%s \033[0;%dm", error_color[status-SHRT_MAX], error_list[status-SHRT_MAX], error_color[(status-1)-SHRT_MAX]);
+void vprintmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, va_list ap)
+{
+#ifndef WIN32
+    fprintf (stderr, "\033[0;%dm%s:%d: \033[0;%dm%s: \033[0m", CON_CYAN, name, (int)line, levelcolor[level], msgtype);
 #else
-       sprintf  (bu, "%s ", error_list[status-SHRT_MAX]);
+    fprintf (stderr, "%s:%d: %s: ", name, line, msgtype);
 #endif
-       va_start (va, msg);
-       vsprintf (fu, msg, va);
-       va_end   (va);
-       fputs    (bu, stderr);
-       fputs    (fu, stderr);
+    vfprintf(stderr, msg, ap);
+    fprintf (stderr, "\n");
+}
+
+void printmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, ...)
+{
+    va_list   va;
+    va_start(va, msg);
+    vprintmsg(level, name, line, msgtype, msg, va);
+    va_end  (va);
+}
+
+void cvprintmsg(lex_ctx ctx, int lvl, const char *msgtype, const char *msg, va_list ap)
+{
+    vprintmsg(lvl, ctx.file, ctx.line, msgtype, msg, ap);
+}
 
-/* color */
-#      ifndef WIN32
-       fputs    ("\033[0m", stderr);
-#      endif
-       
-       fflush   (stderr);
-       
-       return status;
+void cprintmsg (lex_ctx ctx, int lvl, const char *msgtype, const char *msg, ...)
+{
+    va_list   va;
+    va_start(va, msg);
+    cvprintmsg(ctx, lvl, msgtype, msg, va);
+    va_end  (va);
 }