Blob Blame History Raw
From ea296ebe2f027e40457d116c40e687f1724fab90 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Thu, 3 Mar 2011 12:02:51 +0100
Subject: [PATCH] nano-2.3.0 likes to tell me it matched

From: Mike Frysinger <vapier <at> gentoo.org>
Newsgroups: gmane.editors.nano.devel
Date: 2011-03-03 09:44:20 GMT (1 hour and 16 minutes ago)

when i save the attached file, nano writes to stdout (not via ncurses)
the string "We matched!"
-mike

--
http://thread.gmane.org/gmane.editors.nano.devel/2911
---
 src/color.c |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/color.c b/src/color.c
index 269cd21..8dfcf23 100644
--- a/src/color.c
+++ b/src/color.c
@@ -31,6 +31,12 @@
 #include <magic.h>
 #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 @@ void color_init(void)
 
 	    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 @@ void color_update(void)
 #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 @@ void color_update(void)
 #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 @@ void color_update(void)
 			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 @@ void color_update(void)
 
 	/* 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 @@ void color_update(void)
 
 		    /* 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;
-- 
1.7.4