X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=error.c;h=b9cf740b6b5ddae8383ff718b87a76598dc6a25e;hb=fec07921a4eef78453a5705d3cac502e7cfb6665;hp=3f7cfb5f5b6d2a60e39b7201bbc4f886e359d801;hpb=36378e341ef1b2ce4ffc32a90460b6e5712346de;p=xonotic%2Fgmqcc.git diff --git a/error.c b/error.c index 3f7cfb5..b9cf740 100644 --- a/error.c +++ b/error.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 2012 - * Dale Weiler + * Copyright (C) 2012 + * Dale Weiler * * 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 @@ -21,9 +21,6 @@ * SOFTWARE. */ #include -#include -#include -#include #include "gmqcc.h" /* @@ -32,62 +29,64 @@ * 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 +enum { + CON_BLACK = 30, + CON_RED, + CON_GREEN, + CON_BROWN, + CON_BLUE, + CON_MAGENTA, + CON_CYAN , + CON_WHITE +}; static const int error_color[] = { - CON_RED, - CON_CYAN, - CON_MAGENTA, - CON_BLUE, - CON_BROWN, - CON_WHITE + CON_RED, + CON_CYAN, + CON_MAGENTA, + CON_BLUE, + CON_BROWN, + CON_WHITE }; #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:" + "Parsing Error:", + "Lexing Error:", + "Internal Error:", + "Compilation Error:", + "Preprocessor Error:" }; -int error(struct 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 ++; +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); +# 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); #else - sprintf (bu, "%s ", error_list[status-SHRT_MAX]); + sprintf (bu, "%s ", error_list[status-SHRT_MAX]); #endif - va_start (va, msg); - vsprintf (fu, msg, va); - va_end (va); - fputs (bu, stderr); - fputs (fu, stderr); + va_start (va, msg); + vsprintf (fu, msg, va); + va_end (va); + fputs (bu, stderr); + fputs (fu, stderr); /* color */ -# ifndef WIN32 - fputs ("\033[0m", stderr); -# endif - - fflush (stderr); - - return status; +# ifndef WIN32 + fputs ("\033[0m", stderr); +# endif + + fflush (stderr); + + return status; }