Index: src/color.c =================================================================== --- src/color.c (revision 4538) +++ src/color.c (working copy) @@ -31,6 +31,12 @@ #include #endif +#ifdef DEBUG +# define debug_printf(...) fprintf(stderr, __VA_ARGS__) +#else +# define debug_printf(...) +#endif + #ifdef ENABLE_COLOR /* For each syntax list entry, go through the list of colors and assign @@ -100,9 +106,7 @@ init_pair(tmpcolor->pairnum, foreground, background); -#ifdef DEBUG - fprintf(stderr, "init_pair(): fg = %hd, bg = %hd\n", tmpcolor->fg, tmpcolor->bg); -#endif + debug_printf("init_pair(): fg = %hd, bg = %hd\n", tmpcolor->fg, tmpcolor->bg); } } } @@ -167,16 +171,14 @@ #endif /* DEBUG */ MAGIC_ERROR); if (m == NULL || magic_load(m, NULL) < 0) - fprintf(stderr, "something went wrong: %s [%s]\n", strerror(errno), openfile->filename); + debug_printf("something went wrong: %s [%s]\n", strerror(errno), openfile->filename); else { magicstring = magic_file(m,openfile->filename); if (magicstring == NULL) { magicerr = magic_error(m); - fprintf(stderr, "something went wrong: %s [%s]\n", magicerr, openfile->filename); + debug_printf("something went wrong: %s [%s]\n", magicerr, openfile->filename); } -#ifdef DEBUG - fprintf(stderr, "magic string returned: %s\n", magicstring); -#endif /* DEBUG */ + debug_printf("magic string returned: %s\n", magicstring); } } #endif /* HAVE_LIBMAGIC */ @@ -227,9 +229,7 @@ #ifdef HAVE_LIBMAGIC if (openfile->colorstrings == NULL) { -#ifdef DEBUG - fprintf(stderr, "No match using extension, trying libmagic...\n"); -#endif /* DEBUG */ + debug_printf("No match using extension, trying libmagic...\n"); for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { @@ -239,12 +239,10 @@ e->ext = (regex_t *)nmalloc(sizeof(regex_t)); regcomp(e->ext, fixbounds(e->ext_regex), REG_EXTENDED); } -#ifdef DEBUG - fprintf(stderr,"Matching regex \"%s\" against \"%s\"\n",e->ext_regex, magicstring); -#endif /* DEBUG */ + debug_printf("Matching regex \"%s\" against \"%s\"\n",e->ext_regex, magicstring); if (magicstring && regexec(e->ext, magicstring, 0, NULL, 0) == 0) { - fprintf(stderr,"We matched!\n"); + debug_printf("We matched!\n"); openfile->syntax = tmpsyntax; openfile->colorstrings = tmpsyntax->color; break; @@ -259,9 +257,7 @@ /* If we haven't matched anything yet, try the headers */ if (openfile->colorstrings == NULL) { -#ifdef DEBUG - fprintf(stderr, "No match for file extensions, looking at headers...\n"); -#endif + debug_printf("No match for file extensions, looking at headers...\n"); for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { @@ -278,9 +274,7 @@ /* Set colorstrings if we matched the extension * regex. */ -#ifdef DEBUG - fprintf(stderr, "Comparing header regex \"%s\" to fileage \"%s\"...\n", e->ext_regex, openfile->fileage->data); -#endif + debug_printf("Comparing header regex \"%s\" to fileage \"%s\"...\n", e->ext_regex, openfile->fileage->data); if (regexec(e->ext, openfile->fileage->data, 0, NULL, 0) == 0) { openfile->syntax = tmpsyntax; openfile->colorstrings = tmpsyntax->color;