diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Src/Modules/zutil.c | 116 |
2 files changed, 67 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog index 839e5af69..5aeacd26b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ +2014-03-09 Barton E. Schaefer <schaefer@zsh.org> + + * 32468: Src/Modules/zutil.c: save/restore match/mbegin/mend + when doing pattern lookups against zstyle contexts + 2014-03-03 Barton E. Schaefer <schaefer@zsh.org> * users/18550: Doc/Zsh/compsys.yo: matcher-list clarifications + 2014-03-03 Simon Ruderich <simon@ruderich.org> * 32289: Doc: Add zsh version to footer in HTML documentation. diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 46b29f237..1cca0c4b8 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -30,6 +30,55 @@ #include "zutil.mdh" #include "zutil.pro" +typedef struct { + char **match; + char **mbegin; + char **mend; +} MatchData; + +static void +savematch(MatchData *m) +{ + char **a; + + queue_signals(); + a = getaparam("match"); + m->match = a ? zarrdup(a) : NULL; + a = getaparam("mbegin"); + m->mbegin = a ? zarrdup(a) : NULL; + a = getaparam("mend"); + m->mend = a ? zarrdup(a) : NULL; + unqueue_signals(); +} + +static void +restorematch(MatchData *m) +{ + if (m->match) + setaparam("match", m->match); + else + unsetparam("match"); + if (m->mbegin) + setaparam("mbegin", m->mbegin); + else + unsetparam("mbegin"); + if (m->mend) + setaparam("mend", m->mend); + else + unsetparam("mend"); +} + +static void +freematch(MatchData *m) +{ + if (m->match) + freearray(m->match); + if (m->mbegin) + freearray(m->mbegin); + if (m->mend) + freearray(m->mend); +} + /* Style stuff. */ typedef struct stypat *Stypat; @@ -370,15 +419,21 @@ lookupstyle(char *ctxt, char *style) { Style s; Stypat p; + char **found = NULL; s = (Style)zstyletab->getnode2(zstyletab, style); - if (!s) - return NULL; - for (p = s->pats; p; p = p->next) - if (pattry(p->prog, ctxt)) - return (p->eval ? evalstyle(p) : p->vals); + if (s) { + MatchData match; + savematch(&match); + for (p = s->pats; p; p = p->next) + if (pattry(p->prog, ctxt)) { + found = (p->eval ? evalstyle(p) : p->vals); + break; + } + restorematch(&match); + } - return NULL; + return found; } static int @@ -915,55 +970,6 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) /* Zregexparse stuff. */ typedef struct { - char **match; - char **mbegin; - char **mend; -} MatchData; - -static void -savematch(MatchData *m) -{ - char **a; - - queue_signals(); - a = getaparam("match"); - m->match = a ? zarrdup(a) : NULL; - a = getaparam("mbegin"); - m->mbegin = a ? zarrdup(a) : NULL; - a = getaparam("mend"); - m->mend = a ? zarrdup(a) : NULL; - unqueue_signals(); -} - -static void -restorematch(MatchData *m) -{ - if (m->match) - setaparam("match", m->match); - else - unsetparam("match"); - if (m->mbegin) - setaparam("mbegin", m->mbegin); - else - unsetparam("mbegin"); - if (m->mend) - setaparam("mend", m->mend); - else - unsetparam("mend"); -} - -static void -freematch(MatchData *m) -{ - if (m->match) - freearray(m->match); - if (m->mbegin) - freearray(m->mbegin); - if (m->mend) - freearray(m->mend); -} - -typedef struct { int cutoff; char *pattern; Patprog patprog; |