[hackers] [scc] Add DBG() macro || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 13 Aug 2015 20:02:11 +0200 (CEST)

commit 7a2a1f936d8ca77484fa4ddb3b1244ecd350a8b5
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Aug 13 12:58:34 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Aug 13 12:58:34 2015 +0200

    Add DBG() macro
    
    This macro removes all the debug output when NDEBUG is defined

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 13e587a..e554b47 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -207,12 +207,12 @@ expand(char *begin, Symbol *sym)
         if (!parsepars(arguments, arglist, atoi(s)))
                 return 0;
         for (n = 0; n < atoi(s); ++n)
- fprintf(stderr, "MACRO par%d:%s\n", n, arglist[n]);
+ DBG(stderr, "MACRO par%d:%s\n", n, arglist[n]);
 
         elen = copymacro(buffer, s+3, INPUTSIZ-1, arglist);
 
 substitute:
- fprintf(stderr, "MACRO '%s' expanded to :'%s'\n", macroname, buffer);
+ DBG(stderr, "MACRO '%s' expanded to :'%s'\n", macroname, buffer);
         rlen = strlen(input->p); /* rigth length */
         llen = begin - input->line; /* left length */
         ilen = input->p - begin; /* invocation length */
_AT_@ -334,7 +334,7 @@ define(void)
         if (!getdefs(args, n, buff+3, LINESIZ-3))
                 goto delete;
         sym->u.s = xstrdup(buff);
- fprintf(stderr, "MACRO '%s' defined as '%s'\n", sym->name, buff);
+ DBG(stderr, "MACRO '%s' defined as '%s'\n", sym->name, buff);
         return;
 
 delete:
diff --git a/cc1/lex.c b/cc1/lex.c
index 04f1aa4..2220592 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -537,7 +537,7 @@ next(void)
                 yytoken = operator();
 
 exit:
- fprintf(stderr, "TOKEN %s\n", yytext);
+ DBG(stderr, "TOKEN %s\n", yytext);
         lex_ns = NS_IDEN;
         return yytoken;
 }
diff --git a/inc/cc.h b/inc/cc.h
index 6519957..990822d 100644
--- a/inc/cc.h
+++ b/inc/cc.h
_AT_@ -7,6 +7,12 @@ typedef unsigned bool;
 #endif
 #endif
 
+#ifndef NDEBUG
+#define DBG(...) fprintf(__VA_ARGS__)
+#else
+#define DBG(...)
+#endif
+
 #define TINT long
 #define TUINT unsigned long
 #define TFLOAT double
Received on Thu Aug 13 2015 - 20:02:11 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 13 2015 - 20:12:20 CEST