]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - con.c
Remove trailing whitespace for Blub.
[xonotic/gmqcc.git] / con.c
diff --git a/con.c b/con.c
index 8073a5723d71286568e5d0c164d3e34059af924f..2bd8e397de579096f017b421ce5ba783ff4cecf2 100644 (file)
--- a/con.c
+++ b/con.c
 #include <unistd.h>
 #endif
 
-#define GMQCC_IS_STDOUT(X) ((X) == stdout)
-#define GMQCC_IS_STDERR(X) ((X) == stderr)
+#define GMQCC_IS_STDOUT(X) ((FILE*)((void*)X) == stdout)
+#define GMQCC_IS_STDERR(X) ((FILE*)((void*)X) == stderr)
 #define GMQCC_IS_DEFINE(X) (GMQCC_IS_STDERR(X) || GMQCC_IS_STDOUT(X))
 
 typedef struct {
     FILE *handle_err;
     FILE *handle_out;
-    
+
     int   color_err;
     int   color_out;
 } con_t;
@@ -64,7 +64,7 @@ typedef struct {
  * with yay, another macro :P
  */
 #define isatty _isatty
+
 enum {
     RESET = 0,
     BOLD  = 1,
@@ -107,15 +107,15 @@ static void win_fputs(char *str, FILE *f) {
     int acolor;
     int wcolor;
     int icolor;
-    
+
     int state;
     int place;
-    
+
     /* attributes */
     int intense  =  -1;
     int colors[] = {-1, -1 };
     int colorpos = 1;
-    
+
     CONSOLE_SCREEN_BUFFER_INFO cinfo;
     GetConsoleScreenBufferInfo(
         (GMQCC_IS_STDOUT(h)) ?
@@ -123,7 +123,7 @@ static void win_fputs(char *str, FILE *f) {
             GetStdHandle(STD_ERROR_HANDLE), &cinfo
     );
     icolor = cinfo.wAttributes;
-    
+
     while (*str) {
         if (*str == '\e')
             state = '\e';
@@ -140,7 +140,7 @@ static void win_fputs(char *str, FILE *f) {
                     acolor += (colors[find] - 48) * mult;
                     mult   *= 10;
                 }
-                
+
                 /* convert to windows color */
                 if (acolor == BOLD)
                     intense = WINTENSE;
@@ -155,12 +155,12 @@ static void win_fputs(char *str, FILE *f) {
                     wcolor  = WWHITE;
                     intense = WBLACK;
                 }
-                
+
                 SetConsoleTextattribute(
                     (h == stdout) ?
                     GetStdHandle(STD_OUTPUT_HANDLE) :
                     GetStdHandle(STD_ERROR_HANDLE),
-                    
+
                     wcolor | intense | (icolor & 0xF0)
                 );
                 colorpos =  1;
@@ -190,7 +190,7 @@ static con_t console;
  * Enables color on output if supported.
  * NOTE: The support for checking colors is NULL.  On windows this will
  * always work, on *nix it depends if the term has colors.
- * 
+ *
  * NOTE: This prevents colored output to piped stdout/err via isatty
  * checks.
  */
@@ -270,21 +270,21 @@ void con_reset() {
  */
 int con_change(const char *out, const char *err) {
     con_close();
-    
-    if (GMQCC_IS_DEFINE((FILE*)out)) {
-        console.handle_out = (((FILE*)out) == stdout) ? stdout : stderr;
+
+    if (GMQCC_IS_DEFINE(out)) {
+        console.handle_out = GMQCC_IS_STDOUT(out) ? stdout : stderr;
         con_enablecolor();
     } else if (!(console.handle_out = fopen(out, "w"))) return 0;
-    
-    if (GMQCC_IS_DEFINE((FILE*)err)) {
-        console.handle_err = (((FILE*)err) == stdout) ? stdout : stderr;
+
+    if (GMQCC_IS_DEFINE(err)) {
+        console.handle_err = GMQCC_IS_STDOUT(err) ? stdout : stderr;
         con_enablecolor();
     } else if (!(console.handle_err = fopen(err, "w"))) return 0;
-    
-    // no buffering
+
+    /* no buffering */
     setvbuf(console.handle_out, NULL, _IONBF, 0);
     setvbuf(console.handle_err, NULL, _IONBF, 0);
-    
+
     return 1;
 }
 
@@ -328,18 +328,19 @@ void con_vprintmsg(int level, const char *name, size_t line, const char *msgtype
         CON_CYAN,
         CON_RED
     };
-    
-    int  err                        = !!(level == LVL_ERROR);
-    int  color                      = (err) ? console.color_err : console.color_out;
-    int (*print)(const char *, ...) = (err) ? &con_err          : &con_out;
-    
+
+    int  err                         = !!(level == LVL_ERROR);
+    int  color                       = (err) ? console.color_err : console.color_out;
+    int (*print)(const char *, ...)  = (err) ? &con_err          : &con_out;
+    int (*vprint)(const char *, va_list) = (err) ? &con_verr : &con_vout;
+
     if (color)
         print("\033[0;%dm%s:%d: \033[0;%dm%s: \033[0m", CON_CYAN, name, (int)line, sel[level], msgtype);
     else
         print("%s:%d: %s: ", name, (int)line, msgtype);
-        
-    con_verr(msg, ap);
-    fprintf (stderr, "\n");
+
+    vprint(msg, ap);
+    print("\n");
 }
 
 void con_printmsg(int level, const char *name, size_t line, const char *msgtype, const char *msg, ...) {