diff options
Diffstat (limited to 'Src/Modules')
-rw-r--r-- | Src/Modules/datetime.c | 2 | ||||
-rw-r--r-- | Src/Modules/parameter.c | 30 | ||||
-rw-r--r-- | Src/Modules/pcre.c | 11 | ||||
-rw-r--r-- | Src/Modules/stat.c | 2 | ||||
-rw-r--r-- | Src/Modules/zutil.c | 159 |
5 files changed, 124 insertions, 80 deletions
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c index a4e7eca86..00ebd2b49 100644 --- a/Src/Modules/datetime.c +++ b/Src/Modules/datetime.c @@ -130,7 +130,7 @@ bin_strftime(char *nam, char **argv, Options ops, UNUSED(int func)) buffer = zalloc(bufsize); for (x=0; x < 4; x++) { - if (ztrftime(buffer, bufsize, argv[0], t) >= 0) + if (ztrftime(buffer, bufsize, argv[0], t, 0L) >= 0) break; buffer = zrealloc(buffer, bufsize *= 2); } diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 22148f991..0385a709e 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -106,7 +106,7 @@ getpmparameter(UNUSED(HashTable ht), const char *name) pm->u.str = paramtypestr(rpm); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -224,7 +224,7 @@ getpmcommand(UNUSED(HashTable ht), const char *name) } } else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -410,7 +410,7 @@ getfunction(UNUSED(HashTable ht), const char *name, int dis) } } else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -661,7 +661,7 @@ getbuiltin(UNUSED(HashTable ht), const char *name, int dis) pm->u.str = dupstring(t); } else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -876,7 +876,7 @@ getpmoption(UNUSED(HashTable ht), const char *name) } else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -934,7 +934,7 @@ getpmmodule(UNUSED(HashTable ht), const char *name) pm->u.str = dupstring(type); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1048,7 +1048,7 @@ getpmhistory(UNUSED(HashTable ht), const char *name) pm->u.str = dupstring(he->node.nam); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1158,7 +1158,7 @@ getpmjobtext(UNUSED(HashTable ht), const char *name) pm->u.str = pmjobtext(job); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1259,7 +1259,7 @@ getpmjobstate(UNUSED(HashTable ht), const char *name) pm->u.str = pmjobstate(job); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1325,7 +1325,7 @@ getpmjobdir(UNUSED(HashTable ht), const char *name) pm->u.str = pmjobdir(job); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1451,7 +1451,7 @@ getpmnameddir(UNUSED(HashTable ht), const char *name) pm->u.str = dupstring(nd->dir); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1502,7 +1502,7 @@ getpmuserdir(UNUSED(HashTable ht), const char *name) pm->u.str = dupstring(nd->dir); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1754,7 +1754,7 @@ getalias(HashTable alht, UNUSED(HashTable ht), const char *name, int flags) pm->u.str = dupstring(al->text); else { pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); } return &pm->node; } @@ -1950,7 +1950,7 @@ getpmusergroups(UNUSED(HashTable ht), const char *name) if (!gs) { zerr("failed to retrieve groups for user: %e", errno); pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); return &pm->node; } @@ -1965,7 +1965,7 @@ getpmusergroups(UNUSED(HashTable ht), const char *name) } pm->u.str = dupstring(""); - pm->node.flags |= PM_UNSET; + pm->node.flags |= (PM_UNSET|PM_SPECIAL); return &pm->node; } diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c index cb9f8ef57..040a33f8e 100644 --- a/Src/Modules/pcre.c +++ b/Src/Modules/pcre.c @@ -289,14 +289,11 @@ bin_pcre_match(char *nam, char **args, Options ops, UNUSED(int func)) matched_portion = OPT_ARG(ops,c); } if(OPT_HASARG(ops,c='n')) { /* The offset position to start the search, in bytes. */ - offset_start = getposint(OPT_ARG(ops,c), nam); + if ((offset_start = getposint(OPT_ARG(ops,c), nam) < 0)) + return 1; } /* For the entire match, 'Return' the offset byte positions instead of the matched string */ if(OPT_ISSET(ops,'b')) want_offset_pair = 1; - - if(!*args) { - zwarnnam(nam, "not enough arguments"); - } if ((ret = pcre_fullinfo(pcre_pattern, pcre_hints, PCRE_INFO_CAPTURECOUNT, &capcount))) { @@ -311,7 +308,7 @@ bin_pcre_match(char *nam, char **args, Options ops, UNUSED(int func)) unmetafy(plaintext, NULL); subject_len = (int)strlen(plaintext); - if (offset_start < 0 || offset_start >= subject_len) + if (offset_start > 0 && offset_start >= subject_len) ret = PCRE_ERROR_NOMATCH; else ret = pcre_exec(pcre_pattern, pcre_hints, plaintext, subject_len, offset_start, 0, ovec, ovecsize); @@ -345,6 +342,8 @@ cond_pcre_match(char **a, int id) if (zpcre_utf8_enabled()) pcre_opts |= PCRE_UTF8; + if (isset(REMATCHPCRE) && !isset(CASEMATCH)) + pcre_opts |= PCRE_CASELESS; lhstr = cond_str(a,0,0); rhre = cond_str(a,1,0); diff --git a/Src/Modules/stat.c b/Src/Modules/stat.c index edae0841e..6fc53894c 100644 --- a/Src/Modules/stat.c +++ b/Src/Modules/stat.c @@ -198,7 +198,7 @@ stattimeprint(time_t tim, char *outbuf, int flags) if (flags & STF_STRING) { char *oend = outbuf + strlen(outbuf); ztrftime(oend, 40, timefmt, (flags & STF_GMT) ? gmtime(&tim) : - localtime(&tim)); + localtime(&tim), 0L); if (flags & STF_RAW) strcat(oend, ")"); } diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 399c45f46..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; @@ -1543,6 +1549,45 @@ add_opt_val(Zoptdesc d, char *arg) } } +/* + * For "zparseopts -K -A assoc ..." this function copies the keys and + * values from the default and allocates the extra space for any parsed + * values having the same keys. If there are no new values, creates an + * empty array. Returns a pointer to the NULL element marking the end. + * + * aval = pointer to the newly allocated array + * assoc = name of the default hash param to copy + * keep = whether we need to make the copy at all + * num = count of new values to add space for + */ +static char ** +zalloc_default_array(char ***aval, char *assoc, int keep, int num) +{ + char **ap = 0; + + *aval = 0; + if (keep && num) { + struct value vbuf; + Value v = fetchvalue(&vbuf, &assoc, 0, + SCANPM_WANTKEYS|SCANPM_WANTVALS|SCANPM_MATCHMANY); + if (v && v->isarr) { + char **dp, **dval = getarrvalue(v); + int dnum = (dval ? arrlen(dval) : 0) + 1; + *aval = (char **) zalloc(((num * 2) + dnum) * sizeof(char *)); + for (ap = *aval, dp = dval; dp && *dp; dp++) { + *ap = (char *) zalloc(strlen(*dp) + 1); + strcpy(*ap++, *dp); + } + *ap = NULL; + } + } + if (!ap) { + ap = *aval = (char **) zalloc(((num * 2) + 1) * sizeof(char *)); + *ap = NULL; + } + return ap; +} + static int bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) { @@ -1825,8 +1870,8 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) num++; if (!keep || num) { - aval = (char **) zalloc(((num * 2) + 1) * sizeof(char *)); - for (ap = aval, d = opt_descs; d; d = d->next) { + ap = zalloc_default_array(&aval, assoc, keep, num); + for (d = opt_descs; d; d = d->next) { if (d->vals) { *ap++ = n = (char *) zalloc(strlen(d->name) + 2); *n = '-'; |