From 9634760d5eae4e8618e4b9ed9752d7305b3695a9 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 27 Aug 2002 21:10:30 +0000 Subject: 17582: Improved option argument handling. unposted: Updated version to 4.1.0-dev-6 because of interface change. --- Src/Zle/compctl.c | 34 +++++++++++++++++----------------- Src/Zle/complete.c | 4 ++-- Src/Zle/computil.c | 21 +++++++++++---------- Src/Zle/zle_keymap.c | 51 ++++++++++++++++++++++++++------------------------- Src/Zle/zle_main.c | 14 +++++++------- Src/Zle/zle_thingy.c | 42 +++++++++++++++++++++--------------------- 6 files changed, 84 insertions(+), 82 deletions(-) (limited to 'Src/Zle') diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index a84f604cc..69f742731 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -187,7 +187,7 @@ freecompcond(void *a) /**/ int -compctlread(char *name, char **args, char *ops, char *reply) +compctlread(char *name, char **args, Options ops, char *reply) { char *buf, *bptr; @@ -198,15 +198,15 @@ compctlread(char *name, char **args, char *ops, char *reply) return 1; } - if (ops['l']) { + if (OPT_ISSET(ops,'l')) { /* -ln gives the index of the word the cursor is currently on, which is available in cs (but remember that Zsh counts from one, not zero!) */ - if (ops['n']) { + if (OPT_ISSET(ops,'n')) { char nbuf[14]; - if (ops['e'] || ops['E']) + if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) printf("%d\n", cs + 1); - if (!ops['e']) { + if (!OPT_ISSET(ops,'e')) { sprintf(nbuf, "%d", cs + 1); setsparam(reply, ztrdup(nbuf)); } @@ -214,11 +214,11 @@ compctlread(char *name, char **args, char *ops, char *reply) } /* without -n, the current line is assigned to the given parameter as a scalar */ - if (ops['e'] || ops['E']) { + if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) { zputs((char *) line, stdout); putchar('\n'); } - if (!ops['e']) + if (!OPT_ISSET(ops,'e')) setsparam(reply, ztrdup((char *) line)); } else { int i; @@ -226,12 +226,12 @@ compctlread(char *name, char **args, char *ops, char *reply) /* -cn gives the current cursor position within the current word, which is available in clwpos (but remember that Zsh counts from one, not zero!) */ - if (ops['n']) { + if (OPT_ISSET(ops,'n')) { char nbuf[14]; - if (ops['e'] || ops['E']) + if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) printf("%d\n", clwpos + 1); - if (!ops['e']) { + if (!OPT_ISSET(ops,'e')) { sprintf(nbuf, "%d", clwpos + 1); setsparam(reply, ztrdup(nbuf)); } @@ -239,7 +239,7 @@ compctlread(char *name, char **args, char *ops, char *reply) } /* without -n, the words of the current line are assigned to the given parameters separately */ - if (ops['A'] && !ops['e']) { + if (OPT_ISSET(ops,'A') && !OPT_ISSET(ops,'e')) { /* the -A option means that one array is specified, instead of many parameters */ char **p, **b = (char **)zcalloc((clwnum + 1) * sizeof(char *)); @@ -250,13 +250,13 @@ compctlread(char *name, char **args, char *ops, char *reply) setaparam(reply, b); return 0; } - if (ops['e'] || ops['E']) { + if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) { for (i = 0; i < clwnum; i++) { zputs(clwords[i], stdout); putchar('\n'); } - if (ops['e']) + if (OPT_ISSET(ops,'e')) return 0; } @@ -1572,7 +1572,7 @@ printcompctlp(HashNode hn, int printflags) /**/ static int -bin_compctl(char *name, char **argv, char *ops, int func) +bin_compctl(char *name, char **argv, Options ops, int func) { Compctl cc = NULL; int ret = 0; @@ -1678,14 +1678,14 @@ bin_compctl(char *name, char **argv, char *ops, int func) #define CFN_DEFAULT 2 static int -bin_compcall(char *name, char **argv, char *ops, int func) +bin_compcall(char *name, char **argv, Options ops, int func) { if (incompfunc != 1) { zwarnnam(name, "can only be called from completion function", NULL, 0); return 1; } - return makecomplistctl((ops['T'] ? 0 : CFN_FIRST) | - (ops['D'] ? 0 : CFN_DEFAULT)); + return makecomplistctl((OPT_ISSET(ops,'T') ? 0 : CFN_FIRST) | + (OPT_ISSET(ops,'D') ? 0 : CFN_DEFAULT)); } /* diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index ef029ddcb..713ce7f9e 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -421,7 +421,7 @@ parse_class(Cpattern p, unsigned char *s, unsigned char e) /**/ static int -bin_compadd(char *name, char **argv, char *ops, int func) +bin_compadd(char *name, char **argv, Options ops, int func) { struct cadata dat; char *p, **sp, *e, *m = NULL, *mstr = NULL; @@ -866,7 +866,7 @@ do_comp_vars(int test, int na, char *sa, int nb, char *sb, int mod) /**/ static int -bin_compset(char *name, char **argv, char *ops, int func) +bin_compset(char *name, char **argv, Options ops, int func) { int test = 0, na = 0, nb = 0; char *sa = NULL, *sb = NULL; diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index 412347ec9..7fa4364df 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -717,7 +717,7 @@ cd_get(char **params) /**/ static int -bin_compdescribe(char *nam, char **args, char *ops, int func) +bin_compdescribe(char *nam, char **args, Options ops, int func) { int n = arrlen(args); @@ -2259,7 +2259,7 @@ ca_set_data(LinkList descr, LinkList act, LinkList subc, } static int -bin_comparguments(char *nam, char **args, char *ops, int func) +bin_comparguments(char *nam, char **args, Options ops, int func) { int min, max, n; Castate lstate = &ca_laststate; @@ -3136,7 +3136,7 @@ cv_parse_word(Cvdef d) } static int -bin_compvalues(char *nam, char **args, char *ops, int func) +bin_compvalues(char *nam, char **args, Options ops, int func) { int min, max, n; @@ -3349,7 +3349,7 @@ comp_quote(char *str, int prefix) } static int -bin_compquote(char *nam, char **args, char *ops, int func) +bin_compquote(char *nam, char **args, Options ops, int func) { char *name; struct value vbuf; @@ -3372,7 +3372,8 @@ bin_compquote(char *nam, char **args, char *ops, int func) if ((v = getvalue(&vbuf, &name, 0))) { switch (PM_TYPE(v->pm->flags)) { case PM_SCALAR: - setstrvalue(v, ztrdup(comp_quote(getstrvalue(v), ops['p']))); + setstrvalue(v, ztrdup(comp_quote(getstrvalue(v), + OPT_ISSET(ops,'p')))); break; case PM_ARRAY: { @@ -3382,7 +3383,7 @@ bin_compquote(char *nam, char **args, char *ops, int func) char **p = new; for (; *val; val++, p++) - *p = ztrdup(comp_quote(*val, ops['p'])); + *p = ztrdup(comp_quote(*val, OPT_ISSET(ops,'p'))); *p = NULL; setarrvalue(v, new); @@ -3499,7 +3500,7 @@ arrcontains(char **a, char *s, int colon) } static int -bin_comptags(char *nam, char **args, char *ops, int func) +bin_comptags(char *nam, char **args, Options ops, int func) { int min, max, n, level; @@ -3629,7 +3630,7 @@ bin_comptags(char *nam, char **args, char *ops, int func) } static int -bin_comptry(char *nam, char **args, char *ops, int func) +bin_comptry(char *nam, char **args, Options ops, int func) { if (incompfunc != 1) { zwarnnam(nam, "can only be called from completion function", NULL, 0); @@ -4321,7 +4322,7 @@ cf_remove_other(char **names, char *pre, int *amb) } static int -bin_compfiles(char *nam, char **args, char *ops, int func) +bin_compfiles(char *nam, char **args, Options ops, int func) { if (incompfunc != 1) { zwarnnam(nam, "can only be called from completion function", NULL, 0); @@ -4423,7 +4424,7 @@ bin_compfiles(char *nam, char **args, char *ops, int func) } static int -bin_compgroups(char *nam, char **args, char *ops, int func) +bin_compgroups(char *nam, char **args, Options ops, int func) { Heap oldheap; char *n; diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c index 9fd5a9197..c36657697 100644 --- a/Src/Zle/zle_keymap.c +++ b/Src/Zle/zle_keymap.c @@ -604,12 +604,12 @@ keyisprefix(Keymap km, char *seq) /**/ int -bin_bindkey(char *name, char **argv, char *ops, int func) +bin_bindkey(char *name, char **argv, Options ops, int func) { static struct opn { char o; char selp; - int (*func) _((char *, char *, Keymap, char **, char *, char)); + int (*func) _((char *, char *, Keymap, char **, Options, char)); int min, max; } const opns[] = { { 'l', 0, bin_bindkey_lsmaps, 0, 0 }, @@ -628,15 +628,16 @@ bin_bindkey(char *name, char **argv, char *ops, int func) int n; /* select operation and ensure no clashing arguments */ - for(op = opns; op->o && !ops[STOUC(op->o)]; op++) ; + for(op = opns; op->o && !OPT_ISSET(ops,STOUC(op->o)); op++) ; if(op->o) for(opp = op; (++opp)->o; ) - if(ops[STOUC(opp->o)]) { + if(OPT_ISSET(ops,STOUC(opp->o))) { zwarnnam(name, "incompatible operation selection options", NULL, 0); return 1; } - n = ops['e'] + ops['v'] + ops['a'] + ops['M']; + n = OPT_ISSET(ops,'e') + OPT_ISSET(ops,'v') + + OPT_ISSET(ops,'a') + OPT_ISSET(ops,'M'); if(!op->selp && n) { zwarnnam(name, "keymap cannot be selected with -%c", NULL, op->o); return 1; @@ -648,13 +649,13 @@ bin_bindkey(char *name, char **argv, char *ops, int func) /* keymap selection */ if(op->selp) { - if(ops['e']) + if(OPT_ISSET(ops,'e')) kmname = "emacs"; - else if(ops['v']) + else if(OPT_ISSET(ops,'v')) kmname = "viins"; - else if(ops['a']) + else if(OPT_ISSET(ops,'a')) kmname = "vicmd"; - else if(ops['M']) { + else if(OPT_ISSET(ops,'M')) { kmname = *argv++; if(!kmname) { zwarnnam(name, "-M option requires a keymap argument", NULL, 0); @@ -667,7 +668,7 @@ bin_bindkey(char *name, char **argv, char *ops, int func) zwarnnam(name, "no such keymap `%s'", kmname, 0); return 1; } - if(ops['e'] || ops['v']) + if(OPT_ISSET(ops,'e') || OPT_ISSET(ops,'v')) linkkeymap(km, "main", 0); } else { kmname = NULL; @@ -676,7 +677,7 @@ bin_bindkey(char *name, char **argv, char *ops, int func) /* listing is a special case */ if(!op->o && (!argv[0] || !argv[1])) { - if(ops['e'] || ops['v']) + if(OPT_ISSET(ops,'e') || OPT_ISSET(ops,'v')) return 0; return bin_bindkey_list(name, kmname, km, argv, ops, op->o); } @@ -699,9 +700,9 @@ bin_bindkey(char *name, char **argv, char *ops, int func) /**/ static int -bin_bindkey_lsmaps(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_lsmaps(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { - scanhashtable(keymapnamtab, 1, 0, 0, scanlistmaps, ops['L']); + scanhashtable(keymapnamtab, 1, 0, 0, scanlistmaps, OPT_ISSET(ops,'L')); return 0; } @@ -725,7 +726,7 @@ scanlistmaps(HashNode hn, int list) /**/ static int -bin_bindkey_delall(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_delall(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { keymapnamtab->emptytable(keymapnamtab); default_bindings(); @@ -736,7 +737,7 @@ bin_bindkey_delall(char *name, char *kmname, Keymap km, char **argv, char *ops, /**/ static int -bin_bindkey_del(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_del(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { int ret = 0; @@ -755,7 +756,7 @@ bin_bindkey_del(char *name, char *kmname, Keymap km, char **argv, char *ops, cha /**/ static int -bin_bindkey_link(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_link(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { km = openkeymap(argv[0]); if(!km) { @@ -772,7 +773,7 @@ bin_bindkey_link(char *name, char *kmname, Keymap km, char **argv, char *ops, ch /**/ static int -bin_bindkey_new(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_new(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { KeymapName kmn = (KeymapName) keymapnamtab->getnode(keymapnamtab, argv[0]); @@ -800,7 +801,7 @@ bin_bindkey_new(char *name, char *kmname, Keymap km, char **argv, char *ops, cha /**/ static int -bin_bindkey_meta(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_meta(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { char m[3], *str; int i; @@ -830,7 +831,7 @@ bin_bindkey_meta(char *name, char *kmname, Keymap km, char **argv, char *ops, ch /**/ static int -bin_bindkey_bind(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_bind(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { int ret = 0; @@ -847,7 +848,7 @@ bin_bindkey_bind(char *name, char *kmname, Keymap km, char **argv, char *ops, ch zwarnnam(name, "keymap `%s' is protected", kmname, 0); return 1; } - if (func == 'r' && ops['p']) { + if (func == 'r' && OPT_ISSET(ops,'p')) { char *useq, *bseq; int len; struct remprefstate rps; @@ -878,7 +879,7 @@ bin_bindkey_bind(char *name, char *kmname, Keymap km, char **argv, char *ops, ch } bseq = getkeystring(useq, &len, 2, NULL); seq = metafy(bseq, len, META_USEHEAP); - if(ops['R']) { + if(OPT_ISSET(ops,'R')) { int first, last; char m[3]; @@ -924,13 +925,13 @@ scanremoveprefix(char *seq, Thingy bind, char *str, void *magic) /**/ static int -bin_bindkey_list(char *name, char *kmname, Keymap km, char **argv, char *ops, char func) +bin_bindkey_list(char *name, char *kmname, Keymap km, char **argv, Options ops, char func) { struct bindstate bs; - bs.flags = ops['L'] ? BS_LIST : 0; + bs.flags = OPT_ISSET(ops,'L') ? BS_LIST : 0; bs.kmname = kmname; - if(argv[0] && !ops['p']) { + if(argv[0] && !OPT_ISSET(ops,'p')) { int len; char *seq; @@ -944,7 +945,7 @@ bin_bindkey_list(char *name, char *kmname, Keymap km, char **argv, char *ops, ch bindlistout(&bs); } else { /* empty prefix is equivalent to no prefix */ - if (ops['p'] && (!argv[0] || argv[0][0])) { + if (OPT_ISSET(ops,'p') && (!argv[0] || argv[0][0])) { if (!argv[0]) { zwarnnam(name, "option -p requires a prefix string", NULL, 0); return 1; diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c index e1429a0d0..1c45d120c 100644 --- a/Src/Zle/zle_main.c +++ b/Src/Zle/zle_main.c @@ -951,7 +951,7 @@ mod_export char *varedarg; /**/ static int -bin_vared(char *name, char **args, char *ops, int func) +bin_vared(char *name, char **args, Options ops, int func) { char *s, *t, *ova = varedarg; struct value vbuf; @@ -1012,11 +1012,11 @@ bin_vared(char *name, char **args, char *ops, int func) break; case 'h': /* -h option -- enable history */ - ops['h'] = 1; + ops->ind['h'] = 1; break; case 'e': /* -e option -- enable EOF */ - ops['e'] = 1; + ops->ind['e'] = 1; break; default: /* unrecognised option character */ @@ -1113,14 +1113,14 @@ bin_vared(char *name, char **args, char *ops, int func) varedarg = *args; ifl = isfirstln; - if (ops['h']) + if (OPT_ISSET(ops,'h')) hbegin(2); - isfirstln = ops['e']; + isfirstln = OPT_ISSET(ops,'e'); ieof = opts[IGNOREEOF]; opts[IGNOREEOF] = 0; - t = (char *) zleread(p1, p2, ops['h'] ? ZLRF_HISTORY : 0); + t = (char *) zleread(p1, p2, OPT_ISSET(ops,'h') ? ZLRF_HISTORY : 0); opts[IGNOREEOF] = ieof; - if (ops['h']) + if (OPT_ISSET(ops,'h')) hend(NULL); isfirstln = ifl; varedarg = ova; diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c index 7d6c5103e..503060d7b 100644 --- a/Src/Zle/zle_thingy.c +++ b/Src/Zle/zle_thingy.c @@ -324,11 +324,11 @@ deletezlefunction(Widget w) /**/ int -bin_zle(char *name, char **args, char *ops, int func) +bin_zle(char *name, char **args, Options ops, int func) { static struct opn { char o; - int (*func) _((char *, char **, char *, char)); + int (*func) _((char *, char **, Options, char)); int min, max; } const opns[] = { { 'l', bin_zle_list, 0, -1 }, @@ -348,10 +348,10 @@ bin_zle(char *name, char **args, char *ops, int func) int n; /* select operation and ensure no clashing arguments */ - for(op = opns; op->o && !ops[STOUC(op->o)]; op++) ; + for(op = opns; op->o && !OPT_ISSET(ops,STOUC(op->o)); op++) ; if(op->o) for(opp = op; (++opp)->o; ) - if(ops[STOUC(opp->o)]) { + if(OPT_ISSET(ops,STOUC(opp->o))) { zwarnnam(name, "incompatible operation selection options", NULL, 0); return 1; @@ -373,11 +373,11 @@ bin_zle(char *name, char **args, char *ops, int func) /**/ static int -bin_zle_list(char *name, char **args, char *ops, char func) +bin_zle_list(char *name, char **args, Options ops, char func) { if (!*args) { scanhashtable(thingytab, 1, 0, DISABLED, scanlistwidgets, - (ops['a'] ? -1 : ops['L'])); + (OPT_ISSET(ops,'a') ? -1 : OPT_ISSET(ops,'L'))); return 0; } else { int ret = 0; @@ -385,7 +385,7 @@ bin_zle_list(char *name, char **args, char *ops, char func) for (; *args && !ret; args++) { if (!(t = (Thingy) thingytab->getnode2(thingytab, *args)) || - (!ops['a'] && (t->widget->flags & WIDGET_INT))) + (!OPT_ISSET(ops,'a') && (t->widget->flags & WIDGET_INT))) ret = 1; } return ret; @@ -394,7 +394,7 @@ bin_zle_list(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_refresh(char *name, char **args, char *ops, char func) +bin_zle_refresh(char *name, char **args, Options ops, char func) { char *s = statusline; int sl = statusll, ocl = clearlist; @@ -421,11 +421,11 @@ bin_zle_refresh(char *name, char **args, char *ops, char func) lastlistlen++; showinglist = clearlist = 0; zmult = zmultsav; - } else if (ops['c']) { + } else if (OPT_ISSET(ops,'c')) { clearlist = 1; lastlistlen = 0; } - } else if (ops['c']) { + } else if (OPT_ISSET(ops,'c')) { clearlist = listshown = 1; lastlistlen = 0; } @@ -439,7 +439,7 @@ bin_zle_refresh(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_mesg(char *name, char **args, char *ops, char func) +bin_zle_mesg(char *name, char **args, Options ops, char func) { if (!zleactive) { zwarnnam(name, "can only be called from widget function", NULL, 0); @@ -453,7 +453,7 @@ bin_zle_mesg(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_unget(char *name, char **args, char *ops, char func) +bin_zle_unget(char *name, char **args, Options ops, char func) { char *b = *args, *p = b + strlen(b); @@ -468,7 +468,7 @@ bin_zle_unget(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_keymap(char *name, char **args, char *ops, char func) +bin_zle_keymap(char *name, char **args, Options ops, char func) { if (!zleactive) { zwarnnam(name, "can only be called from widget function", NULL, 0); @@ -522,7 +522,7 @@ scanlistwidgets(HashNode hn, int list) /**/ static int -bin_zle_del(char *name, char **args, char *ops, char func) +bin_zle_del(char *name, char **args, Options ops, char func) { int ret = 0; @@ -541,7 +541,7 @@ bin_zle_del(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_link(char *name, char **args, char *ops, char func) +bin_zle_link(char *name, char **args, Options ops, char func) { Thingy t = (Thingy) thingytab->getnode(thingytab, args[0]); @@ -558,7 +558,7 @@ bin_zle_link(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_new(char *name, char **args, char *ops, char func) +bin_zle_new(char *name, char **args, Options ops, char func) { Widget w = zalloc(sizeof(*w)); @@ -574,7 +574,7 @@ bin_zle_new(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_complete(char *name, char **args, char *ops, char func) +bin_zle_complete(char *name, char **args, Options ops, char func) { Thingy t; Widget w, cw; @@ -608,7 +608,7 @@ bin_zle_complete(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_call(char *name, char **args, char *ops, char func) +bin_zle_call(char *name, char **args, Options ops, char func) { Thingy t; struct modifier modsave; @@ -672,7 +672,7 @@ bin_zle_call(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_invalidate(char *name, char **args, char *ops, char func) +bin_zle_invalidate(char *name, char **args, Options ops, char func) { if (zleactive) { if (!trashedzle) @@ -684,7 +684,7 @@ bin_zle_invalidate(char *name, char **args, char *ops, char func) /**/ static int -bin_zle_fd(char *name, char **args, char *ops, char func) +bin_zle_fd(char *name, char **args, Options ops, char func) { int fd = 0, i, found = 0; char *endptr; @@ -698,7 +698,7 @@ bin_zle_fd(char *name, char **args, char *ops, char func) } } - if (ops['L'] || !*args) { + if (OPT_ISSET(ops,'L') || !*args) { /* Listing handlers. */ if (*args && args[1]) { zwarnnam(name, "too many arguments for -FL", NULL, 0); -- cgit 1.4.1