]> git.wh0rd.org Git - nano.git/commitdiff
General - Added separate regex variable (color_regex and colormatches) so that color...
authorChris Allegretta <chrisa@asty.org>
Sun, 24 Mar 2002 23:19:32 +0000 (23:19 +0000)
committerChris Allegretta <chrisa@asty.org>
Sun, 24 Mar 2002 23:19:32 +0000 (23:19 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1140 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
global.c
proto.h
winio.c

index 252845a2905deff99ed3bcea2f64c1a6d52a57c1..10295efa7bae7d9ac00b8ec359e26ef3d9bfd39b 100644 (file)
--- 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).
index ccf5e6a070761d99863c19b492d505aa35380fbd..ca9f84bb76c5611c84773f3dd9cb0b8ce2671cfd 100644 (file)
--- 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 1d91998f90ae0c77badbd84ef73bf2fe9bb03ce5..8a158be7cea195bfb699aa00a82ae79f3ce7bc91 100644 (file)
--- 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 81f686e2359b351cbf79c1b0e01d3baff514db00..e4fdca9cd1fa7cdabb87ebb441e2312a4df4c187 100644 (file)
--- 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;
                            }