X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=error.c;h=e6a1c7da2f5f499f483d03b2de47c462e0756803;hb=ac01e3b5d36630e07363889618ab88e203244d49;hp=592416a8154d1f3ffd5478faf77623c2647da038;hpb=05966ee00986535f426c5d2229397eab4b15412e;p=xonotic%2Fgmqcc.git diff --git a/error.c b/error.c index 592416a..e6a1c7d 100644 --- a/error.c +++ b/error.c @@ -1,6 +1,7 @@ /* * 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 @@ -20,7 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include #include "gmqcc.h" /* @@ -28,63 +28,43 @@ * 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, +int levelcolor[] = { + CON_WHITE, CON_CYAN, - CON_MAGENTA, - CON_BLUE, - CON_BROWN, - CON_WHITE + CON_RED }; #endif -int error_total = 0; -int error_max = 10; - -static const char *const error_list[] = { - "Parsing Error:", - "Lexing Error:", - "Internal Error:", - "Compilation Error:", - "Preprocessor Error:" -}; -int error(lex_file *file, 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 %s:%d ", error_color[status-SHRT_MAX], error_list[status-SHRT_MAX], error_color[(status-1)-SHRT_MAX], file->name, file->line); +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"); +} -/* color */ -# ifndef WIN32 - fputs ("\033[0m", stderr); -# endif +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); +} - fflush (stderr); +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); +} - 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); }