From 3533a348fcfe934f1aa492495dee20faa83066ec Mon Sep 17 00:00:00 2001
From: Chris Allegretta <chrisa@asty.org>
Date: Sun, 24 Mar 2002 23:19:32 +0000
Subject: [PATCH] General - Added separate regex variable (color_regex and
 colormatches) so that color syntax and regex search/replace can coexist

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1140 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog |  2 ++
 global.c  |  5 +++++
 proto.h   |  5 +++++
 winio.c   | 48 ++++++++++++++++++++++++------------------------
 4 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 252845a2..10295efa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@ CVS code -
 	- New "External Command" code, originally by Dwayne Rightler.
 	  New function files.c:open_pipe(), changes to do_insertfile(),
 	  new list extcmd_list, cmd is ^X after ^R by default.
+	- Added separate regex variable (color_regex and colormatches)
+	  so that color syntax and regex search/replace can coexist.
 - files.c:
   check_writable_directory()
 	- Stat full_path, not path (Steven Kneizys).
diff --git a/global.c b/global.c
index ccf5e6a0..ca9f84bb 100644
--- a/global.c
+++ b/global.c
@@ -123,6 +123,11 @@ toggle *toggles = NULL;
 regex_t search_regexp;		/* Global to store compiled search regexp */
 regmatch_t regmatches[10];	/* Match positions for parenthetical
 				   subexpressions, max of 10 */
+#ifdef ENABLE_COLOR
+regex_t color_regexp;		/* Global to store compiled search regexp */
+regmatch_t colormatches;	/* Match positions for parenthetical */
+#endif /* ENABLE_COLOR */
+
 #endif
 
 int length_of_list(shortcut *s) 
diff --git a/proto.h b/proto.h
index 1d91998f..8a158be7 100644
--- a/proto.h
+++ b/proto.h
@@ -83,6 +83,11 @@ extern shortcut *currshortcut;
 extern int use_regexp, regexp_compiled;
 extern regex_t search_regexp;
 extern regmatch_t regmatches[10];  
+
+#ifdef ENABLE_COLOR
+extern regex_t color_regexp;
+extern regmatch_t colormatches[1];  
+#endif /* HJAVE_COLOR */
 #endif
 
 extern toggle *toggles;
diff --git a/winio.c b/winio.c
index 81f686e2..e4fdca9c 100644
--- a/winio.c
+++ b/winio.c
@@ -798,32 +798,32 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 
 		/* First, highlight all single-line regexes */
 		k = start;
-		regcomp(&search_regexp, tmpcolor->start, 0);
-		while (!regexec(&search_regexp, &fileptr->data[k], 1,
-				regmatches, 0)) {
+		regcomp(&color_regexp, tmpcolor->start, 0);
+		while (!regexec(&color_regexp, &fileptr->data[k], 1,
+				colormatches, 0)) {
 
-		    if (regmatches[0].rm_eo - regmatches[0].rm_so < 1) {
+		    if (colormatches[0].rm_eo - colormatches[0].rm_so < 1) {
 			statusbar("Refusing 0 length regex match");
 			break;
 		    }
 #ifdef DEBUG
 		    fprintf(stderr, "Match! (%d chars) \"%s\"\n",
-			    regmatches[0].rm_eo - regmatches[0].rm_so,
-			    &fileptr->data[k + regmatches[0].rm_so]);
+			    colormatches[0].rm_eo - colormatches[0].rm_so,
+			    &fileptr->data[k + colormatches[0].rm_so]);
 #endif
-		    if (regmatches[0].rm_so < COLS - 1) {
+		    if (colormatches[0].rm_so < COLS - 1) {
 			if (tmpcolor->bright)
 			    wattron(edit, A_BOLD);
 			wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
 
-			if (regmatches[0].rm_eo + k <= COLS)
+			if (colormatches[0].rm_eo + k <= COLS)
 			    paintlen =
-				regmatches[0].rm_eo - regmatches[0].rm_so;
+				colormatches[0].rm_eo - colormatches[0].rm_so;
 			else
-			    paintlen = COLS - k - regmatches[0].rm_so - 1;
+			    paintlen = COLS - k - colormatches[0].rm_so - 1;
 
-			mvwaddnstr(edit, yval, regmatches[0].rm_so + k,
-				   &fileptr->data[k + regmatches[0].rm_so],
+			mvwaddnstr(edit, yval, colormatches[0].rm_so + k,
+				   &fileptr->data[k + colormatches[0].rm_so],
 				   paintlen);
 
 		    }
@@ -832,7 +832,7 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 			wattroff(edit, A_BOLD);
 		    wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
 
-		    k += regmatches[0].rm_eo;
+		    k += colormatches[0].rm_eo;
 
 		}
 	    }
@@ -845,22 +845,22 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 
 		s = fileptr;
 		while (s != NULL) {
-		    regcomp(&search_regexp, tmpcolor->start, 0);
+		    regcomp(&color_regexp, tmpcolor->start, 0);
 		    if (!regexec
-			(&search_regexp, s->data, 1, regmatches, 0))
+			(&color_regexp, s->data, 1, colormatches, 0))
 			break;
 		    s = s->prev;
 		}
 
 		if (s != NULL) {
 		    /* We found a start, mark it */
-		    smatch = regmatches[0].rm_so;
+		    smatch = colormatches[0].rm_so;
 
 		    e = s;
 		    while (e != NULL && e != fileptr) {
-			regcomp(&search_regexp, tmpcolor->end, 0);
+			regcomp(&color_regexp, tmpcolor->end, 0);
 			if (!regexec
-			    (&search_regexp, e->data, 1, regmatches, 0))
+			    (&color_regexp, e->data, 1, colormatches, 0))
 			    break;
 			e = e->next;
 		    }
@@ -869,9 +869,9 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 			continue;	/* There's an end before us */
 		    else {	/* Keep looking for an end */
 			while (e != NULL) {
-			    regcomp(&search_regexp, tmpcolor->end, 0);
+			    regcomp(&color_regexp, tmpcolor->end, 0);
 			    if (!regexec
-				(&search_regexp, e->data, 1, regmatches,
+				(&color_regexp, e->data, 1, colormatches,
 				 0))
 				break;
 			    e = e->next;
@@ -880,13 +880,13 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
 			if (e == NULL)
 			    continue;	/* There's no start before the end :) */
 			else {	/* Okay, we found an end, mark it! */
-			    ematch = regmatches[0].rm_eo;
+			    ematch = colormatches[0].rm_eo;
 
 			    while (e != NULL) {
-				regcomp(&search_regexp, tmpcolor->end, 0);
+				regcomp(&color_regexp, tmpcolor->end, 0);
 				if (!regexec
-				    (&search_regexp, e->data, 1,
-				     regmatches, 0))
+				    (&color_regexp, e->data, 1,
+				     colormatches, 0))
 				    break;
 				e = e->next;
 			    }
-- 
GitLab