diff options
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Modules/zutil.c | 761 | ||||
-rw-r--r-- | Src/Modules/zutil.mdd | 3 | ||||
-rw-r--r-- | Src/Zle/computil.c | 429 | ||||
-rw-r--r-- | Src/Zle/computil.mdd | 2 | ||||
-rw-r--r-- | Src/xmods.conf | 1 |
5 files changed, 766 insertions, 430 deletions
diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c new file mode 100644 index 000000000..590678f98 --- /dev/null +++ b/Src/Modules/zutil.c @@ -0,0 +1,761 @@ +/* + * zutil.c - misc utilities + * + * This file is part of zsh, the Z shell. + * + * Copyright (c) 1999 Sven Wischnowsky + * All rights reserved. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and to distribute modified versions of this software for any + * purpose, provided that the above copyright notice and the following + * two paragraphs appear in all copies of this software. + * + * In no event shall Sven Wischnowsky or the Zsh Development Group be liable + * to any party for direct, indirect, special, incidental, or consequential + * damages arising out of the use of this software and its documentation, + * even if Sven Wischnowsky and the Zsh Development Group have been advised of + * the possibility of such damage. + * + * Sven Wischnowsky and the Zsh Development Group specifically disclaim any + * warranties, including, but not limited to, the implied warranties of + * merchantability and fitness for a particular purpose. The software + * provided hereunder is on an "as is" basis, and Sven Wischnowsky and the + * Zsh Development Group have no obligation to provide maintenance, + * support, updates, enhancements, or modifications. + * + */ + +#include "zutil.mdh" +#include "zutil.pro" + +/* Style stuff. */ + +typedef struct stypat *Stypat; +typedef struct style *Style; + +/* A pattern and the styles for it. */ + +struct stypat { + Stypat next; + char *pat; /* pattern string */ + Patprog prog; /* compiled pattern */ + int weight; /* how specific is the pattern? */ + Style styles, lstyles; /* first/last style */ +}; + +struct style { + Style next; + char *name; + char **vals; +}; + +/* List of styles. */ + +static Stypat zstyles, lzstyles; + +/* Memory stuff. */ + +static void +freestyle(Style s) +{ + Style n; + + while (s) { + n = s->next; + + zsfree(s->name); + if (s->vals) + freearray(s->vals); + zfree(s, sizeof(*s)); + + s = n; + } +} + +static void +freestypat(Stypat p) +{ + Stypat n; + + while (p) { + n = p->next; + + zsfree(p->pat); + freepatprog(p->prog); + zfree(p, sizeof(*p)); + + p = n; + } +} + +/* Get the struct for a pattern, if any. */ + +static Stypat +getstypat(char *pat) +{ + Stypat p; + + for (p = zstyles; p; p = p->next) + if (!strcmp(pat, p->pat)) + return p; + + return NULL; +} + +/* Get the style stuff for a name. */ + +static Style +getstyle(Stypat p, char *name) +{ + Style s; + + for (s = p->styles; s; s= s->next) + if (!strcmp(name, s->name)) + return s; + + return NULL; +} + +/* Store a value for a style. */ + +static void +setstyle(Stypat p, char *name, char **vals) +{ + Style s; + + for (s = p->styles; s; s = s->next) + if (!strcmp(name, s->name)) { + + /* Exists -> replace. */ + + if (s->vals) + freearray(s->vals); + PERMALLOC { + s->vals = arrdup(vals); + } LASTALLOC; + + return; + } + + /* New style. */ + + s = (Style) zalloc(sizeof(*s)); + + s->name = ztrdup(name); + PERMALLOC { + s->vals = arrdup(vals); + } LASTALLOC; + s->next = NULL; + + if (p->lstyles) + p->lstyles->next = s; + else + p->styles = s; + p->lstyles = s; +} + +/* Add a new pattern. */ + +static Stypat +addstypat(char *pat, Patprog prog) +{ + Stypat p, q, qq; + int weight, tmp, first; + char *s; + + /* Calculate the weight. */ + + for (weight = 0, tmp = 2, first = 1, s = pat; *s; s++) { + if (first && *s == '*' && (!s[1] || s[1] == ':')) { + /* Only `*' in this component. */ + tmp = 0; + continue; + } + first = 0; + + if (*s == '(' || *s == '|' || *s == '*' || *s == '[' || *s == '<' || + *s == '?' || *s == '#' || *s == '^') + /* Is pattern. */ + tmp = 1; + + if (*s == ':') { + /* Yet another component. */ + + first = 1; + weight += tmp; + tmp = 2; + } + } + weight += tmp; + + p = (Stypat) zalloc(sizeof(*p)); + + p->pat = ztrdup(pat); + p->weight = weight; + p->prog = prog; + p->styles = p->lstyles = NULL; + + for (qq = NULL, q = zstyles; q && q->weight >= weight; + qq = q, q = q->next); + + p->next = q; + if (qq) + qq->next = p; + else + zstyles = p; + if (!q) + lzstyles = p; + + return p; +} + +/* Delete a style. */ + +static void +deletestyle(Stypat p, char *name) +{ + Style ps, s; + + for (ps = NULL, s = p->styles; s; ps = s, s = s->next) + if (!strcmp(name, s->name)) { + if (ps) + ps->next = s->next; + else + p->styles = s->next; + if (s == p->lstyles) + p->lstyles = ps; + + s->next = NULL; + freestyle(s); + + return; + } +} + +/* Delete a whole pattern with all its styles. */ + +static void +deletestypat(Stypat pat) +{ + Stypat pp, p; + + for (pp = NULL, p = zstyles; p; pp = p, p = p->next) + if (p == pat) { + if (pp) + pp->next = p->next; + else + zstyles = p->next; + if (p == lzstyles) + lzstyles = pp; + + p->next = NULL; + zsfree(p->pat); + freepatprog(p->prog); + freestyle(p->styles); + zfree(p, sizeof(*p)); + + return; + } +} + +/* Look up a style for a context pattern. This does the matching. */ + +static Style +lookupstyle(char *ctxt, char *style) +{ + Stypat p; + Style s; + + for (p = zstyles; p; p = p->next) + if (pattry(p->prog, ctxt)) + for (s = p->styles; s; s = s->next) + if (!strcmp(style, s->name)) + return s; + + return NULL; +} + +static int +bin_zstyle(char *nam, char **args, char *ops, int func) +{ + int min, max, n, add = 0, list = 0; + + if (!args[0]) + list = 1; + else if (args[0][0] == '-') { + char oc; + + if ((oc = args[0][1]) && oc != '-') { + if (args[0][2]) { + zerrnam(nam, "invalid argument: %s", args[0], 0); + return 1; + } + if (oc == 'L') + list = 2; + } else { + add = 1; + args++; + } + } else + add = 1; + + if (add) { + Stypat p; + + if (arrlen(args) < 2) { + zerrnam(nam, "not enough arguments", NULL, 0); + return 1; + } + if (!(p = getstypat(args[0]))) { + Patprog prog; + char *pat = dupstring(args[0]); + + tokenize(pat); + + if (!(prog = patcompile(pat, PAT_ZDUP, NULL))) { + zerrnam(nam, "invalid pattern: %s", args[0], 0); + return 1; + } + p = addstypat(args[0], prog); + } + setstyle(p, args[1], args + 2); + + return 0; + } + if (list) { + Stypat p; + Style s; + char **v; + + for (p = zstyles; p; p = p->next) { + if (list == 1) { + quotedzputs(p->pat, stdout); + putchar('\n'); + } + for (s = p->styles; s; s = s->next) { + if (list == 1) + printf(" %s", s->name); + else { + printf("zstyle "); + quotedzputs(p->pat, stdout); + printf(" %s", s->name); + } + for (v = s->vals; *v; v++) { + putchar(' '); + quotedzputs(*v, stdout); + } + putchar('\n'); + } + } + return 0; + } + switch (args[0][1]) { + case 'd': min = 0; max = -1; break; + case 's': min = 3; max = 4; break; + case 'b': min = 3; max = 3; break; + case 'a': min = 3; max = 3; break; + case 'h': min = 3; max = 3; break; + case 't': min = 2; max = -1; break; + case 'm': min = 3; max = 3; break; + case 'g': min = 1; max = 3; break; + default: + zerrnam(nam, "invalid option: %s", args[0], 0); + return 1; + } + n = arrlen(args) - 1; + if (n < min) { + zerrnam(nam, "not enough arguments", NULL, 0); + return 1; + } else if (max >= 0 && n > max) { + zerrnam(nam, "too many arguments", NULL, 0); + return 1; + } + switch (args[0][1]) { + case 'd': + { + Stypat p; + + if (args[1]) { + if ((p = getstypat(args[1]))) { + if (args[2]) { + char **ap = args + 2; + + while (*ap) + deletestyle(p, *ap++); + + if (!p->styles) + deletestypat(p); + } else + deletestypat(p); + } + } else { + freestypat(zstyles); + zstyles = lzstyles = NULL; + } + } + break; + case 's': + { + Style s; + char *ret; + int val; + + if ((s = lookupstyle(args[1], args[2])) && s->vals[0]) { + PERMALLOC { + ret = sepjoin(s->vals, (args[4] ? args[4] : " ")); + } LASTALLOC; + val = 0; + } else { + ret = ztrdup(""); + val = 1; + } + setsparam(args[3], ret); + + return val; + } + break; + case 'b': + { + Style s; + char *ret; + int val; + + if ((s = lookupstyle(args[1], args[2])) && + s->vals[0] && !s->vals[1] && + (!strcmp(s->vals[0], "yes") || + !strcmp(s->vals[0], "true") || + !strcmp(s->vals[0], "on") || + !strcmp(s->vals[0], "1"))) { + ret = "yes"; + val = 0; + } else { + ret = "no"; + val = 1; + } + setsparam(args[3], ztrdup(ret)); + + return val; + } + break; + case 'a': + case 'h': + { + Style s; + char **ret; + int val; + + if ((s = lookupstyle(args[1], args[2]))) { + PERMALLOC { + ret = arrdup(s->vals); + } LASTALLOC; + val = 0; + } else { + char *dummy = NULL; + + PERMALLOC { + ret = arrdup(&dummy); + } LASTALLOC; + val = 1; + } + if (args[0][1] == 'a') + setaparam(args[3], ret); + else + sethparam(args[3], ret); + + return val; + } + break; + case 't': + { + Style s; + + if ((s = lookupstyle(args[1], args[2])) && s->vals[0]) { + if (args[3]) { + char **ap = args + 3, **p; + + while (*ap) { + p = s->vals; + while (*p) + if (!strcmp(*ap, *p++)) + return 0; + ap++; + } + return 1; + } else + return !(!strcmp(s->vals[0], "true") || + !strcmp(s->vals[0], "yes") || + !strcmp(s->vals[0], "on") || + !strcmp(s->vals[0], "1")); + } + return 1; + } + break; + case 'm': + { + Style s; + Patprog prog; + + tokenize(args[3]); + + if ((s = lookupstyle(args[1], args[2])) && + (prog = patcompile(args[3], PAT_STATIC, NULL))) { + char **p = s->vals; + + while (*p) + if (pattry(prog, *p++)) + return 0; + } + return 1; + } + break; + case 'g': + { + LinkList l = newlinklist(); + int ret = 1; + Stypat p; + + if (args[2]) { + if ((p = getstypat(args[2]))) { + Style s; + + if (args[3]) { + if ((s = getstyle(p, args[3]))) { + char **v = s->vals; + + while (*v) + addlinknode(l, *v++); + + ret = 0; + } + } else { + for (s = p->styles; s; s = s->next) + addlinknode(l, s->name); + + ret = 0; + } + } + } else { + for (p = zstyles; p; p = p->next) + addlinknode(l, p->pat); + + ret = 0; + } + set_list_array(args[1], l); + + return ret; + } + } + return 0; +} + +/* Format stuff. */ + +static int +bin_zformat(char *nam, char **args, char *ops, int func) +{ + char opt; + + if (args[0][0] != '-' || !(opt = args[0][1]) || args[0][2]) { + zerrnam(nam, "invalid argument: %s", args[0], 0); + return 1; + } + args++; + + switch (opt) { + case 'f': + { + char **ap, *specs[256], *out, *s; + int olen, oused = 0; + + memset(specs, 0, 256 * sizeof(char *)); + + for (ap = args + 2; *ap; ap++) { + if (!ap[0][0] || ap[0][0] == '-' || ap[0][0] == '.' || + (ap[0][0] >= '0' && ap[0][0] <= '9') || + ap[0][1] != ':') { + zerrnam(nam, "invalid argument: %s", *ap, 0); + return 1; + } + specs[STOUC(ap[0][0])] = ap[0] + 2; + } + out = (char *) zhalloc(olen = 128); + + for (s = args[1]; *s; s++) { + if (*s == '%') { + int right, min = -1, max = -1, outl; + char *spec, *start = s; + + if ((right = (*++s == '-'))) + s++; + + if (*s >= '0' && *s <= '9') { + for (min = 0; *s >= '0' && *s <= '9'; s++) + min = (min * 10) + (int) STOUC(*s) - '0'; + } + if (*s == '.' && s[1] >= '0' && s[1] <= '9') { + for (max = 0, s++; *s >= '0' && *s <= '9'; s++) + max = (max * 10) + (int) STOUC(*s) - '0'; + } + if ((spec = specs[STOUC(*s)])) { + int len; + + if ((len = strlen(spec)) > max && max >= 0) + len = max; + outl = (min >= 0 ? (min > len ? min : len) : len); + + if (oused + outl >= olen) { + int nlen = olen + outl + 128; + char *tmp = (char *) zhalloc(nlen); + + memcpy(tmp, out, olen); + olen = nlen; + out = tmp; + } + if (len >= outl) { + memcpy(out + oused, spec, outl); + oused += outl; + } else { + int diff = outl - len; + + if (right) { + while (diff--) + out[oused++] = ' '; + memcpy(out + oused, spec, len); + oused += len; + } else { + memcpy(out + oused, spec, len); + oused += len; + while (diff--) + out[oused++] = ' '; + } + } + } else { + int len = s - start + 1; + + if (oused + len >= olen) { + int nlen = olen + len + 128; + char *tmp = (char *) zhalloc(nlen); + + memcpy(tmp, out, olen); + olen = nlen; + out = tmp; + } + memcpy(out + oused, start, len); + oused += len; + } + } else { + if (oused + 1 >= olen) { + char *tmp = (char *) zhalloc(olen << 1); + + memcpy(tmp, out, olen); + olen <<= 1; + out = tmp; + } + out[oused++] = *s; + } + } + out[oused] = '\0'; + + setsparam(args[0], ztrdup(out)); + return 0; + } + break; + case 'a': + { + char **ap, *cp; + int nbc = 0, colon = 0, pre = 0, suf = 0; + + for (ap = args + 2; *ap; ap++) { + for (nbc = 0, cp = *ap; *cp && *cp != ':'; cp++) + if (*cp == '\\' && cp[1]) + cp++, nbc++; + if (*cp == ':' && cp[1]) { + int d; + + colon++; + if ((d = cp - *ap - nbc) > pre) + pre = d; + if ((d = strlen(cp + 1)) > suf) + suf = d; + } + } + { + int sl = strlen(args[1]); + VARARR(char, buf, pre + suf + sl + 1); + char **ret, **rp, *copy, *cpp, oldc; + + ret = (char **) zalloc((arrlen(args + 2) + 1) * + sizeof(char *)); + + memcpy(buf + pre, args[1], sl); + suf = pre + sl; + + for (rp = ret, ap = args + 2; *ap; ap++) { + copy = dupstring(*ap); + for (cp = cpp = copy; *cp && *cp != ':'; cp++) { + if (*cp == '\\' && cp[1]) + cp++; + *cpp++ = *cp; + } + oldc = *cpp; + *cpp = '\0'; + if (((cpp == cp && oldc == ':') || *cp == ':') && cp[1]) { + memset(buf, ' ', pre); + memcpy(buf, copy, (cpp - copy)); + strcpy(buf + suf, cp + 1); + *rp++ = ztrdup(buf); + } else + *rp++ = ztrdup(copy); + } + *rp = NULL; + + setaparam(args[0], ret); + return 0; + } + } + break; + } + zerrnam(nam, "invalid option: -%c", 0, opt); + return 1; +} + +static struct builtin bintab[] = { + BUILTIN("zstyle", 0, bin_zstyle, 0, -1, 0, NULL, NULL), + BUILTIN("zformat", 0, bin_zformat, 3, -1, 0, NULL, NULL), +}; + + +/**/ +int +setup_zutil(Module m) +{ + zstyles = NULL; + + return 0; +} + +/**/ +int +boot_zutil(Module m) +{ + return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); +} + +/**/ +int +cleanup_zutil(Module m) +{ + deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); + return 0; +} + +/**/ +int +finish_zutil(Module m) +{ + freestypat(zstyles); + + return 0; +} diff --git a/Src/Modules/zutil.mdd b/Src/Modules/zutil.mdd new file mode 100644 index 000000000..edc1f0d32 --- /dev/null +++ b/Src/Modules/zutil.mdd @@ -0,0 +1,3 @@ +objects="zutil.o" + +autobins="zformat zstyle" diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index ae7dba5a8..bb69e5bf8 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -102,24 +102,6 @@ cdisp_build(Cdisp disp, char *sep, char **args) return ret; } -/**/ -static int -bin_compdisplay(char *nam, char **args, char *ops, int func) -{ - struct cdisp disp; - - if (incompfunc != 1) { - zerrnam(nam, "can only be called from completion function", NULL, 0); - return 1; - } - disp.pre = disp.suf = disp.colon = 0; - - cdisp_calc(&disp, args + 2); - setaparam(args[0], cdisp_build(&disp, args[1], args + 2)); - - return !disp.colon; -} - /* Help fuer `_describe'. */ typedef struct cdset *Cdset; @@ -2179,411 +2161,6 @@ bin_compquote(char *nam, char **args, char *ops, int func) return 0; } -/* Style stuff. */ - -typedef struct cspat *Cspat; -typedef struct cstyle *Cstyle; - -/* A pattern and the styles for it. */ - -struct cspat { - Cspat next; - char *pat; /* pattern string */ - Patprog prog; /* compiled pattern */ - int weight; /* how specific is the pattern? */ - Cstyle styles, lstyles; /* first/last style */ -}; - -struct cstyle { - Cstyle next; - char *name; - char **vals; -}; - -/* List of styles. */ - -static Cspat compstyles, lcompstyles; - -/* Memory stuff. */ - -static void -freecstyle(Cstyle s) -{ - Cstyle n; - - while (s) { - n = s->next; - - zsfree(s->name); - if (s->vals) - freearray(s->vals); - zfree(s, sizeof(*s)); - - s = n; - } -} - -static void -freecspat(Cspat p) -{ - Cspat n; - - while (p) { - n = p->next; - - zsfree(p->pat); - freepatprog(p->prog); - zfree(p, sizeof(*p)); - - p = n; - } -} - -/* Get the struct for a pattern, if any. */ - -static Cspat -getcspat(char *pat) -{ - Cspat p; - - for (p = compstyles; p; p = p->next) - if (!strcmp(pat, p->pat)) - return p; - - return NULL; -} - -/* Get the style stuff for a name. */ - -static Cstyle -getcstyle(Cspat p, char *name) -{ - Cstyle s; - - for (s = p->styles; s; s= s->next) - if (!strcmp(name, s->name)) - return s; - - return NULL; -} - -/* Store a value for a style. */ - -static void -setcstyle(Cspat p, char *name, char **vals) -{ - Cstyle s; - - for (s = p->styles; s; s = s->next) - if (!strcmp(name, s->name)) { - - /* Exists -> replace. */ - - if (s->vals) - freearray(s->vals); - PERMALLOC { - s->vals = arrdup(vals); - } LASTALLOC; - - return; - } - - /* New style. */ - - s = (Cstyle) zalloc(sizeof(*s)); - - s->name = ztrdup(name); - PERMALLOC { - s->vals = arrdup(vals); - } LASTALLOC; - s->next = NULL; - - if (p->lstyles) - p->lstyles->next = s; - else - p->styles = s; - p->lstyles = s; -} - -/* Add a new pattern. */ - -static Cspat -addcspat(char *pat, Patprog prog) -{ - Cspat p, q, qq; - int weight, tmp, first; - char *s; - - /* Calculate the weight. */ - - for (weight = 0, tmp = 2, first = 1, s = pat; *s; s++) { - if (first && *s == '*' && (!s[1] || s[1] == ':')) { - /* Only `*' in this component. */ - tmp = 0; - continue; - } - first = 0; - - if (*s == '(' || *s == '|' || *s == '*' || *s == '[' || *s == '<' || - *s == '?' || *s == '#' || *s == '^') - /* Is pattern. */ - tmp = 1; - - if (*s == ':') { - /* Yet another component. */ - - first = 1; - weight += tmp; - tmp = 2; - } - } - weight += tmp; - - p = (Cspat) zalloc(sizeof(*p)); - - p->pat = ztrdup(pat); - p->weight = weight; - p->prog = prog; - p->styles = p->lstyles = NULL; - - for (qq = NULL, q = compstyles; q && q->weight >= weight; - qq = q, q = q->next); - - p->next = q; - if (qq) - qq->next = p; - else - compstyles = p; - if (!q) - lcompstyles = p; - - return p; -} - -/* Delete a style. */ - -static void -deletecstyle(Cspat p, char *name) -{ - Cstyle ps, s; - - for (ps = NULL, s = p->styles; s; ps = s, s = s->next) - if (!strcmp(name, s->name)) { - if (ps) - ps->next = s->next; - else - p->styles = s->next; - if (s == p->lstyles) - p->lstyles = ps; - - s->next = NULL; - freecstyle(s); - - return; - } -} - -/* Delete a whole pattern with all its styles. */ - -static void -deletecspat(Cspat pat) -{ - Cspat pp, p; - - for (pp = NULL, p = compstyles; p; pp = p, p = p->next) - if (p == pat) { - if (pp) - pp->next = p->next; - else - compstyles = p->next; - if (p == lcompstyles) - lcompstyles = pp; - - p->next = NULL; - zsfree(p->pat); - freepatprog(p->prog); - freecstyle(p->styles); - zfree(p, sizeof(*p)); - - return; - } -} - -/* Look up a style for a context pattern. This does the matching. */ - -static Cstyle -lookupcstyle(char *ctxt, char *style) -{ - Cspat p; - Cstyle s; - - for (p = compstyles; p; p = p->next) - if (pattry(p->prog, ctxt)) - for (s = p->styles; s; s = s->next) - if (!strcmp(style, s->name)) - return s; - - return NULL; -} - -static int -bin_compstyles(char *nam, char **args, char *ops, int func) -{ - int min, max, n; - - if (args[0][0] != '-' || !args[0][1] || args[0][2]) { - zerrnam(nam, "invalid argument: %s", args[0], 0); - return 1; - } - switch (args[0][1]) { - case 'a': min = 2; max = -1; break; - case 'd': min = 0; max = 2; break; - case 'S': min = 3; max = 3; break; - case 'A': min = 3; max = 3; break; - case 'H': min = 3; max = 3; break; - case 'T': min = 2; max = 2; break; - case 'G': min = 1; max = 3; break; - default: - zerrnam(nam, "invalid option: %s", args[0], 0); - return 1; - } - n = arrlen(args) - 1; - if (n < min) { - zerrnam(nam, "not enough arguments", NULL, 0); - return 1; - } else if (max >= 0 && n > max) { - zerrnam(nam, "too many arguments", NULL, 0); - return 1; - } - switch (args[0][1]) { - case 'a': - { - Cspat p; - - if (!(p = getcspat(args[1]))) { - Patprog prog; - char *pat = dupstring(args[1]); - - tokenize(pat); - - if (!(prog = patcompile(pat, PAT_ZDUP, NULL))) { - zerrnam(nam, "invalid pattern: %s", args[1], 0); - return 1; - } - p = addcspat(args[1], prog); - } - setcstyle(p, args[2], args + 3); - } - break; - case 'd': - { - Cspat p; - - if (args[1]) { - if ((p = getcspat(args[1]))) { - if (args[2]) { - deletecstyle(p, args[2]); - if (!p->styles) - deletecspat(p); - } else - deletecspat(p); - } - } else { - freecspat(compstyles); - compstyles = lcompstyles = NULL; - } - } - break; - case 'S': - { - Cstyle s; - char *ret; - int val; - - if ((s = lookupcstyle(args[1], args[2])) && s->vals[0]) { - PERMALLOC { - ret = sepjoin(s->vals, NULL); - } LASTALLOC; - val = 0; - } else { - ret = ztrdup(""); - val = 1; - } - setsparam(args[3], ret); - - return val; - } - break; - case 'A': - case 'H': - { - Cstyle s; - char **ret; - int val; - - if ((s = lookupcstyle(args[1], args[2]))) { - PERMALLOC { - ret = arrdup(s->vals); - } LASTALLOC; - val = 0; - } else { - char *dummy = NULL; - - PERMALLOC { - ret = arrdup(&dummy); - } LASTALLOC; - val = 1; - } - if (args[0][1] == 'A') - setaparam(args[3], ret); - else - sethparam(args[3], ret); - - return val; - } - break; - case 'T': - return !lookupcstyle(args[1], args[2]); - case 'G': - { - LinkList l = newlinklist(); - int ret = 1; - Cspat p; - - if (args[2]) { - if ((p = getcspat(args[2]))) { - Cstyle s; - - if (args[3]) { - if ((s = getcstyle(p, args[3]))) { - char **v = s->vals; - - while (*v) - addlinknode(l, *v++); - - ret = 0; - } - } else { - for (s = p->styles; s; s = s->next) - addlinknode(l, s->name); - - ret = 0; - } - } - } else { - for (p = compstyles; p; p = p->next) - addlinknode(l, p->pat); - - ret = 0; - } - set_list_array(args[1], l); - - return ret; - } - } - return 0; -} - /* Tags stuff. */ typedef struct ctags *Ctags; @@ -2855,12 +2432,10 @@ bin_compfmt(char *nam, char **args, char *ops, int func) } static struct builtin bintab[] = { - BUILTIN("compdisplay", 0, bin_compdisplay, 2, -1, 0, NULL, NULL), BUILTIN("compdescribe", 0, bin_compdescribe, 3, -1, 0, NULL, NULL), BUILTIN("comparguments", 0, bin_comparguments, 1, -1, 0, NULL, NULL), BUILTIN("compvalues", 0, bin_compvalues, 1, -1, 0, NULL, NULL), BUILTIN("compquote", 0, bin_compquote, 1, -1, 0, NULL, NULL), - BUILTIN("compstyles", 0, bin_compstyles, 1, -1, 0, NULL, NULL), BUILTIN("comptags", 0, bin_comptags, 1, -1, 0, NULL, NULL), BUILTIN("comptry", 0, bin_comptry, 0, -1, 0, NULL, NULL), BUILTIN("compfmt", 0, bin_compfmt, 2, -1, 0, NULL, NULL), @@ -2874,8 +2449,6 @@ setup_computil(Module m) memset(cadef_cache, 0, sizeof(cadef_cache)); memset(cvdef_cache, 0, sizeof(cvdef_cache)); - compstyles = NULL; - memset(comptags, 0, sizeof(comptags)); lasttaglevel = 0; @@ -2909,8 +2482,6 @@ finish_computil(Module m) for (i = 0; i < MAX_CVCACHE; i++) freecvdef(cvdef_cache[i]); - freecspat(compstyles); - for (i = 0; i < MAX_TAGS; i++) freectags(comptags[i]); diff --git a/Src/Zle/computil.mdd b/Src/Zle/computil.mdd index 0246f24b3..cf2a13b60 100644 --- a/Src/Zle/computil.mdd +++ b/Src/Zle/computil.mdd @@ -2,4 +2,4 @@ moddeps="complete zle" objects="computil.o" -autobins="compdisplay compdescribe comparguments compvalues compquote compstyles comptags comptry" +autobins="compdescribe comparguments compvalues compquote comptags comptry" diff --git a/Src/xmods.conf b/Src/xmods.conf index db72b4933..ed7769dbc 100644 --- a/Src/xmods.conf +++ b/Src/xmods.conf @@ -4,6 +4,7 @@ complete compctl sched complist +zutil computil parameter zleparameter |