17582: Improved option argument handling.

unposted: Updated version to 4.1.0-dev-6 because of interface change.
This commit is contained in:
Peter Stephenson 2002-08-27 21:10:30 +00:00
parent 043c302261
commit 9634760d5e
38 changed files with 1023 additions and 662 deletions

View file

@ -1,3 +1,21 @@
2002-08-27 Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
* unposted: Config/version.mk: Update version to 4.1.0-dev-6.
* 17582: Doc/Zsh/builtins.yo, Src/builtin.c, Src/hashtable.c,
Src/hashtable.h, Src/init.c, Src/jobs.c, Src/mem.c, Src/module.c,
Src/options.c, Src/parse.c, Src/watch.c, Src/zsh.h,
Src/Builtins/rlimits.c, Src/Builtins/sched.c, Src/Modules/cap.c,
Src/Modules/clone.c, Src/Modules/datetime.c,
Src/Modules/example.c, Src/Modules/files.c, Src/Modules/pcre.c,
Src/Modules/socket.c, Src/Modules/stat.c, Src/Modules/tcp.c,
Src/Modules/termcap.c, Src/Modules/terminfo.c, Src/Modules/zftp.c,
Src/Modules/zprof.c, Src/Modules/zpty.c, Src/Modules/zselect.c,
Src/Modules/zutil.c, Src/Zle/compctl.c, Src/Zle/complete.c,
Src/Zle/computil.c, Src/Zle/zle_keymap.c, Src/Zle/zle_main.c,
Src/Zle/zle_thingy.c: Improve handling of arguments to options
of builtins by replacing character array with `struct options'.
2002-08-24 Oliver Kiddle <opk@zsh.org> 2002-08-24 Oliver Kiddle <opk@zsh.org>
* 17577: Completion/Unix/Command/_ant, Completion/Unix/Command/_zip, * 17577: Completion/Unix/Command/_ant, Completion/Unix/Command/_zip,

View file

@ -27,5 +27,5 @@
# This must also serve as a shell script, so do not add spaces around the # This must also serve as a shell script, so do not add spaces around the
# `=' signs. # `=' signs.
VERSION=4.1.0-dev-5 VERSION=4.1.0-dev-6
VERSION_DATE='June 17, 2002' VERSION_DATE='August 26, 2002'

View file

@ -846,9 +846,6 @@ Read only one (or var(num)) characters. All are assigned to the first
var(name), without word splitting. This flag is ignored when tt(-q) is var(name), without word splitting. This flag is ignored when tt(-q) is
present. Input is read from the terminal unless one of tt(-u) or tt(-p) present. Input is read from the terminal unless one of tt(-u) or tt(-p)
is present. This option may also be used within zle widgets. is present. This option may also be used within zle widgets.
Note that var(num) must be in the argument word that follows tt(-k), not
in the same word. See tt(-u).
) )
item(tt(-z))( item(tt(-z))(
Read one entry from the editor buffer stack and assign it to the first Read one entry from the editor buffer stack and assign it to the first
@ -884,8 +881,7 @@ and that when the cursor is at the end of the line, its character
index is the length of the line plus one. index is the length of the line plus one.
) )
item(tt(-u)var(n))( item(tt(-u)var(n))(
Input is read from file descriptor var(n), where var(n) is a single Input is read from file descriptor var(n).
digit and must em(not) be separated from tt(-u) by any whitespace.
) )
item(tt(-p))( item(tt(-p))(
Input is read from the coprocess. Input is read from the coprocess.

View file

@ -283,15 +283,15 @@ printulimit(int lim, int hard, int head)
/**/ /**/
static int static int
bin_limit(char *nam, char **argv, char *ops, int func) bin_limit(char *nam, char **argv, Options ops, int func)
{ {
char *s; char *s;
int hard, limnum, lim; int hard, limnum, lim;
rlim_t val; rlim_t val;
int ret = 0; int ret = 0;
hard = ops['h']; hard = OPT_ISSET(ops,'h');
if (ops['s'] && !*argv) if (OPT_ISSET(ops,'s') && !*argv)
return setlimits(NULL); return setlimits(NULL);
/* without arguments, display limits */ /* without arguments, display limits */
if (!*argv) { if (!*argv) {
@ -380,7 +380,7 @@ bin_limit(char *nam, char **argv, char *ops, int func)
return 1; return 1;
} else } else
limits[lim].rlim_cur = val; limits[lim].rlim_cur = val;
if (ops['s'] && zsetlimit(lim, "limit")) if (OPT_ISSET(ops,'s') && zsetlimit(lim, "limit"))
ret++; ret++;
} }
return ret; return ret;
@ -391,13 +391,13 @@ bin_limit(char *nam, char **argv, char *ops, int func)
/**/ /**/
static int static int
bin_unlimit(char *nam, char **argv, char *ops, int func) bin_unlimit(char *nam, char **argv, Options ops, int func)
{ {
int hard, limnum, lim; int hard, limnum, lim;
int ret = 0; int ret = 0;
uid_t euid = geteuid(); uid_t euid = geteuid();
hard = ops['h']; hard = OPT_ISSET(ops,'h');
/* Without arguments, remove all limits. */ /* Without arguments, remove all limits. */
if (!*argv) { if (!*argv) {
for (limnum = 0; limnum != RLIM_NLIMITS; limnum++) { for (limnum = 0; limnum != RLIM_NLIMITS; limnum++) {
@ -409,7 +409,7 @@ bin_unlimit(char *nam, char **argv, char *ops, int func)
} else } else
limits[limnum].rlim_cur = limits[limnum].rlim_max; limits[limnum].rlim_cur = limits[limnum].rlim_max;
} }
if (ops['s']) if (OPT_ISSET(ops,'s'))
ret += setlimits(nam); ret += setlimits(nam);
if (ret) if (ret)
zwarnnam(nam, "can't remove hard limits", NULL, 0); zwarnnam(nam, "can't remove hard limits", NULL, 0);
@ -443,7 +443,7 @@ bin_unlimit(char *nam, char **argv, char *ops, int func)
limits[lim].rlim_max = RLIM_INFINITY; limits[lim].rlim_max = RLIM_INFINITY;
} else } else
limits[lim].rlim_cur = limits[lim].rlim_max; limits[lim].rlim_cur = limits[lim].rlim_max;
if (ops['s'] && zsetlimit(lim, nam)) if (OPT_ISSET(ops,'s') && zsetlimit(lim, nam))
ret++; ret++;
} }
} }
@ -454,7 +454,7 @@ bin_unlimit(char *nam, char **argv, char *ops, int func)
/**/ /**/
static int static int
bin_ulimit(char *name, char **argv, char *ops, int func) bin_ulimit(char *name, char **argv, Options ops, int func)
{ {
int res, resmask = 0, hard = 0, soft = 0, nres = 0; int res, resmask = 0, hard = 0, soft = 0, nres = 0;
char *options; char *options;

View file

@ -46,7 +46,7 @@ static struct schedcmd *schedcmds;
/**/ /**/
static int static int
bin_sched(char *nam, char **argv, char *ops, int func) bin_sched(char *nam, char **argv, Options ops, int func)
{ {
char *s = *argv++; char *s = *argv++;
time_t t; time_t t;
@ -143,9 +143,7 @@ bin_sched(char *nam, char **argv, char *ops, int func)
of scheduled commands. */ of scheduled commands. */
sch = (struct schedcmd *) zcalloc(sizeof *sch); sch = (struct schedcmd *) zcalloc(sizeof *sch);
sch->time = t; sch->time = t;
PERMALLOC { sch->cmd = zjoin(argv, ' ', 0);
sch->cmd = zjoin(argv, ' ');
} LASTALLOC;
sch->next = NULL; sch->next = NULL;
for (sch2 = (struct schedcmd *)&schedcmds; sch2->next; sch2 = sch2->next); for (sch2 = (struct schedcmd *)&schedcmds; sch2->next; sch2 = sch2->next);
sch2->next = sch; sch2->next = sch;
@ -185,7 +183,14 @@ static struct builtin bintab[] = {
/**/ /**/
int int
boot_sched(Module m) setup_(Module m)
{
return 0;
}
/**/
int
boot_(Module m)
{ {
if(!addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab))) if(!addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)))
return 1; return 1;
@ -193,11 +198,9 @@ boot_sched(Module m)
return 0; return 0;
} }
#ifdef MODULE
/**/ /**/
int int
cleanup_sched(Module m) cleanup_(Module m)
{ {
struct schedcmd *sch, *schn; struct schedcmd *sch, *schn;
@ -211,4 +214,9 @@ cleanup_sched(Module m)
return 0; return 0;
} }
#endif /**/
int
finish_(Module m)
{
return 0;
}

View file

@ -33,7 +33,7 @@
#ifdef HAVE_CAP_GET_PROC #ifdef HAVE_CAP_GET_PROC
static int static int
bin_cap(char *nam, char **argv, char *ops, int func) bin_cap(char *nam, char **argv, Options ops, int func)
{ {
int ret = 0; int ret = 0;
cap_t caps; cap_t caps;
@ -48,7 +48,7 @@ bin_cap(char *nam, char **argv, char *ops, int func)
ret = 1; ret = 1;
} }
} else { } else {
char *result; char *result = NULL;
ssize_t length; ssize_t length;
caps = cap_get_proc(); caps = cap_get_proc();
if(caps) if(caps)
@ -59,17 +59,17 @@ bin_cap(char *nam, char **argv, char *ops, int func)
} else } else
puts(result); puts(result);
} }
cap_free(&caps); cap_free(caps);
return ret; return ret;
} }
static int static int
bin_getcap(char *nam, char **argv, char *ops, int func) bin_getcap(char *nam, char **argv, Options ops, int func)
{ {
int ret = 0; int ret = 0;
do { do {
char *result; char *result = NULL;
ssize_t length; ssize_t length;
cap_t caps = cap_get_file(*argv); cap_t caps = cap_get_file(*argv);
if(caps) if(caps)
@ -79,13 +79,13 @@ bin_getcap(char *nam, char **argv, char *ops, int func)
ret = 1; ret = 1;
} else } else
printf("%s %s\n", *argv, result); printf("%s %s\n", *argv, result);
cap_free(&caps); cap_free(caps);
} while(*++argv); } while(*++argv);
return ret; return ret;
} }
static int static int
bin_setcap(char *nam, char **argv, char *ops, int func) bin_setcap(char *nam, char **argv, Options ops, int func)
{ {
cap_t caps; cap_t caps;
int ret = 0; int ret = 0;
@ -102,7 +102,7 @@ bin_setcap(char *nam, char **argv, char *ops, int func)
ret = 1; ret = 1;
} }
} while(*++argv); } while(*++argv);
cap_free(&caps); cap_free(caps);
return ret; return ret;
} }
@ -124,18 +124,29 @@ static struct builtin bintab[] = {
/**/ /**/
int int
boot_cap(Module m) setup_(Module m)
{
return 0;
}
/**/
int
boot_(Module m)
{ {
return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
} }
#ifdef MODULE
/**/ /**/
int int
cleanup_cap(Module m) cleanup_(Module m)
{ {
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
return 0; return 0;
} }
#endif
/**/
int
finish_(Module m)
{
return 0;
}

View file

@ -41,7 +41,7 @@
/**/ /**/
static int static int
bin_clone(char *nam, char **args, char *ops, int func) bin_clone(char *nam, char **args, Options ops, int func)
{ {
int ttyfd, pid; int ttyfd, pid;

View file

@ -32,7 +32,7 @@
#include <time.h> #include <time.h>
static int static int
bin_strftime(char *nam, char **argv, char *ops, int func) bin_strftime(char *nam, char **argv, Options ops, int func)
{ {
int bufsize, x; int bufsize, x;
char *endptr = NULL, *buffer = NULL; char *endptr = NULL, *buffer = NULL;

View file

@ -30,47 +30,203 @@
#include "example.mdh" #include "example.mdh"
#include "example.pro" #include "example.pro"
/* parameters */
static zlong intparam;
static char *strparam;
static char **arrparam;
/**/ /**/
static int static int
bin_example(char *nam, char **args, char *ops, int func) bin_example(char *nam, char **args, Options ops, int func)
{ {
unsigned char c; unsigned char c;
char **oargs = args, **p = arrparam;
long i = 0;
printf("Options: "); printf("Options: ");
for (c = 32; ++c < 128;) for (c = 32; ++c < 128;)
if (ops[c]) if (OPT_ISSET(ops,c))
putchar(c); putchar(c);
printf("\nArguments:"); printf("\nArguments:");
for (; *args; args++) { for (; *args; i++, args++) {
putchar(' '); putchar(' ');
fputs(*args, stdout); fputs(*args, stdout);
} }
printf("\nName: %s\n", nam); printf("\nName: %s\n", nam);
#ifdef ZSH_64_BIT_TYPE
printf("\nInteger Parameter: %s\n", output64(intparam));
#else
printf("\nInteger Parameter: %ld\n", intparam);
#endif
printf("String Parameter: %s\n", strparam ? strparam : "");
printf("Array Parameter:");
if (p)
while (*p) printf(" %s", *p++);
printf("\n");
intparam = i;
zsfree(strparam);
strparam = ztrdup(*oargs ? *oargs : "");
freearray(arrparam);
arrparam = zarrdup(oargs);
return 0; return 0;
} }
/**/
static int
cond_p_len(char **a, int id)
{
char *s1 = cond_str(a, 0, 0);
if (a[1]) {
zlong v = cond_val(a, 1);
return strlen(s1) == v;
} else {
return !s1[0];
}
}
/**/
static int
cond_i_ex(char **a, int id)
{
char *s1 = cond_str(a, 0, 0), *s2 = cond_str(a, 1, 0);
return !strcmp("example", dyncat(s1, s2));
}
/**/
static mnumber
math_sum(char *name, int argc, mnumber *argv, int id)
{
mnumber ret;
int f = 0;
ret.u.l = 0;
while (argc--) {
if (argv->type == MN_INTEGER) {
if (f)
ret.u.d += (double) argv->u.l;
else
ret.u.l += argv->u.l;
} else {
if (f)
ret.u.d += argv->u.d;
else {
ret.u.d = ((double) ret.u.l) + ((double) argv->u.d);
f = 1;
}
}
argv++;
}
ret.type = (f ? MN_FLOAT : MN_INTEGER);
return ret;
}
/**/
static mnumber
math_length(char *name, char *arg, int id)
{
mnumber ret;
ret.type = MN_INTEGER;
ret.u.l = strlen(arg);
return ret;
}
/**/
static int
ex_wrapper(Eprog prog, FuncWrap w, char *name)
{
if (strncmp(name, "example", 7))
return 1;
else {
int ogd = opts[GLOBDOTS];
opts[GLOBDOTS] = 1;
runshfunc(prog, w, name);
opts[GLOBDOTS] = ogd;
return 0;
}
}
/* /*
* boot_example is executed when the module is loaded. * boot_ is executed when the module is loaded.
*/ */
static struct builtin bintab[] = { static struct builtin bintab[] = {
BUILTIN("example", 0, bin_example, 0, -1, 0, "flags", NULL), BUILTIN("example", 0, bin_example, 0, -1, 0, "flags", NULL),
}; };
/**/ static struct conddef cotab[] = {
int CONDDEF("len", 0, cond_p_len, 1, 2, 0),
boot_example(Module m) CONDDEF("ex", CONDF_INFIX, cond_i_ex, 0, 0, 0),
{ };
return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
}
#ifdef MODULE static struct paramdef patab[] = {
INTPARAMDEF("exint", &intparam),
STRPARAMDEF("exstr", &strparam),
ARRPARAMDEF("exarr", &arrparam),
};
static struct mathfunc mftab[] = {
NUMMATHFUNC("sum", math_sum, 1, -1, 0),
STRMATHFUNC("length", math_length, 0),
};
static struct funcwrap wrapper[] = {
WRAPDEF(ex_wrapper),
};
/**/ /**/
int int
cleanup_example(Module m) setup_(Module m)
{ {
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); printf("The example module has now been set up.\n");
fflush(stdout);
return 0;
}
/**/
int
boot_(Module m)
{
intparam = 42;
strparam = ztrdup("example");
arrparam = (char **) zalloc(3 * sizeof(char *));
arrparam[0] = ztrdup("example");
arrparam[1] = ztrdup("array");
arrparam[2] = NULL;
return !(addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)) |
addconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab)) |
addparamdefs(m->nam, patab, sizeof(patab)/sizeof(*patab)) |
addmathfuncs(m->nam, mftab, sizeof(mftab)/sizeof(*mftab)) |
!addwrapper(m, wrapper));
}
/**/
int
cleanup_(Module m)
{
deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
deleteconddefs(m->nam, cotab, sizeof(cotab)/sizeof(*cotab));
deleteparamdefs(m->nam, patab, sizeof(patab)/sizeof(*patab));
deletemathfuncs(m->nam, mftab, sizeof(mftab)/sizeof(*mftab));
deletewrapper(m, wrapper);
return 0;
}
/**/
int
finish_(Module m)
{
printf("Thank you for using the example module. Have a nice day.\n");
fflush(stdout);
return 0; return 0;
} }
#endif

View file

@ -56,7 +56,7 @@ ask(void)
/**/ /**/
static int static int
bin_sync(char *nam, char **args, char *ops, int func) bin_sync(char *nam, char **args, Options ops, int func)
{ {
sync(); sync();
return 0; return 0;
@ -66,14 +66,14 @@ bin_sync(char *nam, char **args, char *ops, int func)
/**/ /**/
static int static int
bin_mkdir(char *nam, char **args, char *ops, int func) bin_mkdir(char *nam, char **args, Options ops, int func)
{ {
mode_t oumask = umask(0); mode_t oumask = umask(0);
mode_t mode = 0777 & ~oumask; mode_t mode = 0777 & ~oumask;
int err = 0; int err = 0;
umask(oumask); umask(oumask);
if(ops['m']) { if(OPT_ISSET(ops,'m')) {
char *str = *args++, *ptr; char *str = *args++, *ptr;
if(!*args) { if(!*args) {
@ -91,7 +91,7 @@ bin_mkdir(char *nam, char **args, char *ops, int func)
while(ptr > *args + (**args == '/') && *--ptr == '/') while(ptr > *args + (**args == '/') && *--ptr == '/')
*ptr = 0; *ptr = 0;
if(ops['p']) { if(OPT_ISSET(ops,'p')) {
char *ptr = *args; char *ptr = *args;
for(;;) { for(;;) {
@ -147,7 +147,7 @@ domkdir(char *nam, char *path, mode_t mode, int p)
/**/ /**/
static int static int
bin_rmdir(char *nam, char **args, char *ops, int func) bin_rmdir(char *nam, char **args, Options ops, int func)
{ {
int err = 0; int err = 0;
@ -183,7 +183,7 @@ bin_rmdir(char *nam, char **args, char *ops, int func)
/**/ /**/
static int static int
bin_ln(char *nam, char **args, char *ops, int func) bin_ln(char *nam, char **args, Options ops, int func)
{ {
MoveFunc move; MoveFunc move;
int flags, err = 0; int flags, err = 0;
@ -194,22 +194,22 @@ bin_ln(char *nam, char **args, char *ops, int func)
if(func == BIN_MV) { if(func == BIN_MV) {
move = (MoveFunc) rename; move = (MoveFunc) rename;
flags = ops['f'] ? 0 : MV_ASKNW; flags = OPT_ISSET(ops,'f') ? 0 : MV_ASKNW;
flags |= MV_ATOMIC; flags |= MV_ATOMIC;
} else { } else {
flags = ops['f'] ? MV_FORCE : 0; flags = OPT_ISSET(ops,'f') ? MV_FORCE : 0;
#ifdef HAVE_LSTAT #ifdef HAVE_LSTAT
if(ops['s']) if(OPT_ISSET(ops,'s'))
move = (MoveFunc) symlink; move = (MoveFunc) symlink;
else else
#endif #endif
{ {
move = (MoveFunc) link; move = (MoveFunc) link;
if(!ops['d']) if(!OPT_ISSET(ops,'d'))
flags |= MV_NODIRS; flags |= MV_NODIRS;
} }
} }
if(ops['i'] && !ops['f']) if(OPT_ISSET(ops,'i') && !OPT_ISSET(ops,'f'))
flags |= MV_INTER; flags |= MV_INTER;
for(a = args; a[1]; a++) ; for(a = args; a[1]; a++) ;
if(a != args) { if(a != args) {
@ -567,18 +567,20 @@ rm_dirpost(char *arg, char *rp, struct stat const *sp, void *magic)
/**/ /**/
static int static int
bin_rm(char *nam, char **args, char *ops, int func) bin_rm(char *nam, char **args, Options ops, int func)
{ {
struct rmmagic rmm; struct rmmagic rmm;
int err; int err;
rmm.nam = nam; rmm.nam = nam;
rmm.opt_force = ops['f']; rmm.opt_force = OPT_ISSET(ops,'f');
rmm.opt_interact = ops['i'] && !ops['f']; rmm.opt_interact = OPT_ISSET(ops,'i') && !OPT_ISSET(ops,'f');
rmm.opt_unlinkdir = ops['d']; rmm.opt_unlinkdir = OPT_ISSET(ops,'d');
err = recursivecmd(nam, ops['f'], ops['r'] && !ops['d'], ops['s'], err = recursivecmd(nam, OPT_ISSET(ops,'f'),
OPT_ISSET(ops,'r') && !OPT_ISSET(ops,'d'),
OPT_ISSET(ops,'s'),
args, recurse_donothing, rm_dirpost, rm_leaf, &rmm); args, recurse_donothing, rm_dirpost, rm_leaf, &rmm);
return ops['f'] ? 0 : err; return OPT_ISSET(ops,'f') ? 0 : err;
} }
/* chown builtin */ /* chown builtin */
@ -620,7 +622,7 @@ enum { BIN_CHOWN, BIN_CHGRP };
/**/ /**/
static int static int
bin_chown(char *nam, char **args, char *ops, int func) bin_chown(char *nam, char **args, Options ops, int func)
{ {
struct chownmagic chm; struct chownmagic chm;
char *uspec = ztrdup(*args), *p = uspec; char *uspec = ztrdup(*args), *p = uspec;
@ -685,7 +687,7 @@ bin_chown(char *nam, char **args, char *ops, int func)
chm.gid = -1; chm.gid = -1;
} }
free(uspec); free(uspec);
return recursivecmd(nam, 0, ops['R'], ops['s'], return recursivecmd(nam, 0, OPT_ISSET(ops,'R'), OPT_ISSET(ops,'s'),
args + 1, chown_dochown, recurse_donothing, chown_dochown, &chm); args + 1, chown_dochown, recurse_donothing, chown_dochown, &chm);
} }

View file

@ -40,15 +40,15 @@ static pcre_extra *pcre_hints;
/**/ /**/
static int static int
bin_pcre_compile(char *nam, char **args, char *ops, int func) bin_pcre_compile(char *nam, char **args, Options ops, int func)
{ {
int pcre_opts = 0, pcre_errptr; int pcre_opts = 0, pcre_errptr;
const char *pcre_error; const char *pcre_error;
if(ops['a']) pcre_opts |= PCRE_ANCHORED; if(OPT_ISSET(ops,'a')) pcre_opts |= PCRE_ANCHORED;
if(ops['i']) pcre_opts |= PCRE_CASELESS; if(OPT_ISSET(ops,'i')) pcre_opts |= PCRE_CASELESS;
if(ops['m']) pcre_opts |= PCRE_MULTILINE; if(OPT_ISSET(ops,'m')) pcre_opts |= PCRE_MULTILINE;
if(ops['x']) pcre_opts |= PCRE_EXTENDED; if(OPT_ISSET(ops,'x')) pcre_opts |= PCRE_EXTENDED;
pcre_hints = NULL; /* Is this necessary? */ pcre_hints = NULL; /* Is this necessary? */
@ -68,7 +68,7 @@ bin_pcre_compile(char *nam, char **args, char *ops, int func)
/**/ /**/
static int static int
bin_pcre_study(char *nam, char **args, char *ops, int func) bin_pcre_study(char *nam, char **args, Options ops, int func)
{ {
const char *pcre_error; const char *pcre_error;
@ -92,12 +92,12 @@ bin_pcre_study(char *nam, char **args, char *ops, int func)
/**/ /**/
static int static int
bin_pcre_match(char *nam, char **args, char *ops, int func) bin_pcre_match(char *nam, char **args, Options ops, int func)
{ {
int ret, capcount, *ovec, ovecsize; int ret, capcount, *ovec, ovecsize;
char **captures, **matches, *receptacle = NULL; char **captures, **matches, *receptacle = NULL;
if(ops['a']) { if(OPT_ISSET(ops,'a')) {
receptacle = *args++; receptacle = *args++;
if(!*args) { if(!*args) {
zwarnnam(nam, "not enough arguments", NULL, 0); zwarnnam(nam, "not enough arguments", NULL, 0);

View file

@ -58,7 +58,7 @@
#endif #endif
static int static int
bin_zsocket(char *nam, char **args, char *ops, int func) bin_zsocket(char *nam, char **args, Options ops, int func)
{ {
int err=1, verbose=0, test=0, targetfd=0; int err=1, verbose=0, test=0, targetfd=0;
SOCKLEN_T len; SOCKLEN_T len;
@ -66,13 +66,13 @@ bin_zsocket(char *nam, char **args, char *ops, int func)
struct sockaddr_un soun; struct sockaddr_un soun;
int sfd; int sfd;
if (ops['v']) if (OPT_ISSET(ops,'v'))
verbose = 1; verbose = 1;
if (ops['t']) if (OPT_ISSET(ops,'t'))
test = 1; test = 1;
if (ops['d']) { if (OPT_ISSET(ops,'d')) {
targetfd = atoi(args[0]); targetfd = atoi(args[0]);
dargs = args + 1; dargs = args + 1;
if (!targetfd) { if (!targetfd) {
@ -84,7 +84,7 @@ bin_zsocket(char *nam, char **args, char *ops, int func)
dargs = args; dargs = args;
if (ops['l']) { if (OPT_ISSET(ops,'l')) {
char *localfn; char *localfn;
if (!dargs[0]) { if (!dargs[0]) {
@ -135,7 +135,7 @@ bin_zsocket(char *nam, char **args, char *ops, int func)
return 0; return 0;
} }
else if (ops['a']) else if (OPT_ISSET(ops,'a'))
{ {
int lfd, rfd; int lfd, rfd;

View file

@ -341,7 +341,7 @@ statprint(struct stat *sbuf, char *outbuf, char *fname, int iwhich, int flags)
*/ */
/**/ /**/
static int static int
bin_stat(char *name, char **args, char *ops, int func) bin_stat(char *name, char **args, Options ops, int func)
{ {
char **aptr, *arrnam = NULL, **array = NULL, **arrptr = NULL; char **aptr, *arrnam = NULL, **array = NULL, **arrptr = NULL;
char *hashnam = NULL, **hash = NULL, **hashptr = NULL; char *hashnam = NULL, **hash = NULL, **hashptr = NULL;
@ -376,12 +376,12 @@ bin_stat(char *name, char **args, char *ops, int func)
} }
/* if name of link requested, turn on lstat */ /* if name of link requested, turn on lstat */
if (iwhich == ST_READLINK) if (iwhich == ST_READLINK)
ops['L'] = 1; ops->ind['L'] = 1;
flags |= STF_PICK; flags |= STF_PICK;
} else { } else {
for (; *arg; arg++) { for (; *arg; arg++) {
if (strchr("glLnNorstT", *arg)) if (strchr("glLnNorstT", *arg))
ops[STOUC(*arg)] = 1; ops->ind[STOUC(*arg)] = 1;
else if (*arg == 'A') { else if (*arg == 'A') {
if (arg[1]) { if (arg[1]) {
arrnam = arg+1; arrnam = arg+1;
@ -404,7 +404,7 @@ bin_stat(char *name, char **args, char *ops, int func)
break; break;
} else if (*arg == 'f') { } else if (*arg == 'f') {
char *sfd; char *sfd;
ops['f'] = 1; ops->ind['f'] = 1;
if (arg[1]) { if (arg[1]) {
sfd = arg+1; sfd = arg+1;
} else if (!(sfd = *++args)) { } else if (!(sfd = *++args)) {
@ -425,7 +425,7 @@ bin_stat(char *name, char **args, char *ops, int func)
return 1; return 1;
} }
/* force string format in order to use time format */ /* force string format in order to use time format */
ops['s'] = 1; ops->ind['s'] = 1;
break; break;
} else { } else {
zwarnnam(name, "bad option: -%c", NULL, *arg); zwarnnam(name, "bad option: -%c", NULL, *arg);
@ -444,7 +444,7 @@ bin_stat(char *name, char **args, char *ops, int func)
* be similar to stat -A foo -A bar filename */ * be similar to stat -A foo -A bar filename */
} }
if (ops['l']) { if (OPT_ISSET(ops,'l')) {
/* list types and return: can also list to array */ /* list types and return: can also list to array */
if (arrnam) { if (arrnam) {
arrptr = array = (char **)zalloc((ST_COUNT+1)*sizeof(char *)); arrptr = array = (char **)zalloc((ST_COUNT+1)*sizeof(char *));
@ -468,34 +468,34 @@ bin_stat(char *name, char **args, char *ops, int func)
return 0; return 0;
} }
if (!*args && !ops['f']) { if (!*args && !OPT_ISSET(ops,'f')) {
zwarnnam(name, "no files given", NULL, 0); zwarnnam(name, "no files given", NULL, 0);
return 1; return 1;
} else if (*args && ops['f']) { } else if (*args && OPT_ISSET(ops,'f')) {
zwarnnam(name, "no files allowed with -f", NULL, 0); zwarnnam(name, "no files allowed with -f", NULL, 0);
return 1; return 1;
} }
nargs = 0; nargs = 0;
if (ops['f']) if (OPT_ISSET(ops,'f'))
nargs = 1; nargs = 1;
else else
for (aptr = args; *aptr; aptr++) for (aptr = args; *aptr; aptr++)
nargs++; nargs++;
if (ops['g']) { if (OPT_ISSET(ops,'g')) {
flags |= STF_GMT; flags |= STF_GMT;
ops['s'] = 1; ops->ind['s'] = 1;
} }
if (ops['s'] || ops['r']) if (OPT_ISSET(ops,'s') || OPT_ISSET(ops,'r'))
flags |= STF_STRING; flags |= STF_STRING;
if (ops['r'] || !ops['s']) if (OPT_ISSET(ops,'r') || !OPT_ISSET(ops,'s'))
flags |= STF_RAW; flags |= STF_RAW;
if (ops['n']) if (OPT_ISSET(ops,'n'))
flags |= STF_FILE; flags |= STF_FILE;
if (ops['o']) if (OPT_ISSET(ops,'o'))
flags |= STF_OCTAL; flags |= STF_OCTAL;
if (ops['t']) if (OPT_ISSET(ops,'t'))
flags |= STF_NAME; flags |= STF_NAME;
if (!(arrnam || hashnam)) { if (!(arrnam || hashnam)) {
@ -505,9 +505,9 @@ bin_stat(char *name, char **args, char *ops, int func)
flags |= STF_NAME; flags |= STF_NAME;
} }
if (ops['N'] || ops['f']) if (OPT_ISSET(ops,'N') || OPT_ISSET(ops,'f'))
flags &= ~STF_FILE; flags &= ~STF_FILE;
if (ops['T'] || ops['H']) if (OPT_ISSET(ops,'T') || OPT_ISSET(ops,'H'))
flags &= ~STF_NAME; flags &= ~STF_NAME;
if (hashnam) { if (hashnam) {
@ -529,16 +529,18 @@ bin_stat(char *name, char **args, char *ops, int func)
arrptr = array = (char **)zcalloc((arrsize+1)*sizeof(char *)); arrptr = array = (char **)zcalloc((arrsize+1)*sizeof(char *));
} }
for (; ops['f'] || *args; args++) { for (; OPT_ISSET(ops,'f') || *args; args++) {
char outbuf[PATH_MAX + 9]; /* "link " + link name + NULL */ char outbuf[PATH_MAX + 9]; /* "link " + link name + NULL */
int rval = ops['f'] ? fstat(fd, &statbuf) : int rval = OPT_ISSET(ops,'f') ? fstat(fd, &statbuf) :
ops['L'] ? lstat(*args, &statbuf) : stat(*args, &statbuf); OPT_ISSET(ops,'L') ? lstat(*args, &statbuf) :
stat(*args, &statbuf);
if (rval) { if (rval) {
if (ops['f']) if (OPT_ISSET(ops,'f'))
sprintf(outbuf, "%d", fd); sprintf(outbuf, "%d", fd);
zwarnnam(name, "%s: %e", ops['f'] ? outbuf : *args, errno); zwarnnam(name, "%s: %e", OPT_ISSET(ops,'f') ? outbuf : *args,
errno);
ret = 1; ret = 1;
if (ops['f'] || arrnam) if (OPT_ISSET(ops,'f') || arrnam)
break; break;
else else
continue; continue;
@ -558,7 +560,7 @@ bin_stat(char *name, char **args, char *ops, int func)
if (arrnam) if (arrnam)
*arrptr++ = ztrdup(outbuf); *arrptr++ = ztrdup(outbuf);
else if (hashnam) { else if (hashnam) {
/* STF_NAME explicitly turned off for ops['H'] above */ /* STF_NAME explicitly turned off for ops.ind['H'] above */
*hashptr++ = ztrdup(statelts[iwhich]); *hashptr++ = ztrdup(statelts[iwhich]);
*hashptr++ = ztrdup(outbuf); *hashptr++ = ztrdup(outbuf);
} else } else
@ -570,14 +572,14 @@ bin_stat(char *name, char **args, char *ops, int func)
if (arrnam) if (arrnam)
*arrptr++= ztrdup(outbuf); *arrptr++= ztrdup(outbuf);
else if (hashnam) { else if (hashnam) {
/* STF_NAME explicitly turned off for ops['H'] above */ /* STF_NAME explicitly turned off for ops.ind['H'] above */
*hashptr++ = ztrdup(statelts[i]); *hashptr++ = ztrdup(statelts[i]);
*hashptr++ = ztrdup(outbuf); *hashptr++ = ztrdup(outbuf);
} else } else
printf("%s\n", outbuf); printf("%s\n", outbuf);
} }
} }
if (ops['f']) if (OPT_ISSET(ops,'f'))
break; break;
if (!arrnam && !hashnam && args[1] && !(flags & STF_PICK)) if (!arrnam && !hashnam && args[1] && !(flags & STF_PICK))

View file

@ -336,7 +336,7 @@ tcp_connect(Tcp_session sess, char *addrp, struct hostent *zhost, int d_port)
} }
static int static int
bin_ztcp(char *nam, char **args, char *ops, int func) bin_ztcp(char *nam, char **args, Options ops, int func)
{ {
int herrno, err=1, destport, force=0, verbose=0, test=0, targetfd=0; int herrno, err=1, destport, force=0, verbose=0, test=0, targetfd=0;
SOCKLEN_T len; SOCKLEN_T len;
@ -345,16 +345,16 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
struct servent *srv; struct servent *srv;
Tcp_session sess = NULL; Tcp_session sess = NULL;
if (ops['f']) if (OPT_ISSET(ops,'f'))
force = 1; force = 1;
if (ops['v']) if (OPT_ISSET(ops,'v'))
verbose = 1; verbose = 1;
if (ops['t']) if (OPT_ISSET(ops,'t'))
test = 1; test = 1;
if (ops['d']) { if (OPT_ISSET(ops,'d')) {
targetfd = atoi(args[0]); targetfd = atoi(args[0]);
dargs = args + 1; dargs = args + 1;
if (!targetfd) { if (!targetfd) {
@ -366,7 +366,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
dargs = args; dargs = args;
if (ops['c']) { if (OPT_ISSET(ops,'c')) {
if (!dargs[0]) { if (!dargs[0]) {
tcp_cleanup(); tcp_cleanup();
} }
@ -395,7 +395,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
} }
} }
} }
else if (ops['l']) { else if (OPT_ISSET(ops,'l')) {
int lport = 0; int lport = 0;
if (!dargs[0]) { if (!dargs[0]) {
@ -462,7 +462,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
return 0; return 0;
} }
else if (ops['a']) else if (OPT_ISSET(ops,'a'))
{ {
int lfd, rfd; int lfd, rfd;
@ -571,7 +571,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
remotename = ztpeer->h_name; remotename = ztpeer->h_name;
else else
remotename = ztrdup(inet_ntoa(sess->peer.in.sin_addr)); remotename = ztrdup(inet_ntoa(sess->peer.in.sin_addr));
if (ops['L']) { if (OPT_ISSET(ops,'L')) {
int schar; int schar;
if (sess->flags & ZTCP_ZFTP) if (sess->flags & ZTCP_ZFTP)
schar = 'Z'; schar = 'Z';

View file

@ -103,7 +103,7 @@ ztgetflag(char *s)
/**/ /**/
static int static int
bin_echotc(char *name, char **argv, char *ops, int func) bin_echotc(char *name, char **argv, Options ops, int func)
{ {
char *s, buf[2048], *t, *u; char *s, buf[2048], *t, *u;
int num, argct; int num, argct;

View file

@ -57,7 +57,7 @@ static Param terminfo_pm;
/**/ /**/
static int static int
bin_echoti(char *name, char **argv, char *ops, int func) bin_echoti(char *name, char **argv, Options ops, int func)
{ {
char *s, *t; char *s, *t;
int num; int num;

View file

@ -2951,7 +2951,7 @@ zftp_rmsession(char *name, char **args, int flags)
/**/ /**/
static int static int
bin_zftp(char *name, char **args, char *ops, int func) bin_zftp(char *name, char **args, Options ops, int func)
{ {
char fullname[20] = "zftp "; char fullname[20] = "zftp ";
char *cnam = *args++, *prefs, *ptr; char *cnam = *args++, *prefs, *ptr;

View file

@ -136,9 +136,9 @@ cmpparcs(Parc *a, Parc *b)
} }
static int static int
bin_zprof(char *nam, char **args, char *ops, int func) bin_zprof(char *nam, char **args, Options ops, int func)
{ {
if (ops['c']) { if (OPT_ISSET(ops,'c')) {
freepfuncs(calls); freepfuncs(calls);
calls = NULL; calls = NULL;
ncalls = 0; ncalls = 0;

View file

@ -603,20 +603,23 @@ ptywrite(Ptycmd cmd, char **args, int nonl)
/**/ /**/
static int static int
bin_zpty(char *nam, char **args, char *ops, int func) bin_zpty(char *nam, char **args, Options ops, int func)
{ {
if ((ops['r'] && ops['w']) || if ((OPT_ISSET(ops,'r') && OPT_ISSET(ops,'w')) ||
((ops['r'] || ops['w']) && (ops['d'] || ops['e'] || ((OPT_ISSET(ops,'r') || OPT_ISSET(ops,'w')) &&
ops['b'] || ops['L'])) || (OPT_ISSET(ops,'d') || OPT_ISSET(ops,'e') ||
(ops['w'] && ops['t']) || OPT_ISSET(ops,'b') || OPT_ISSET(ops,'L'))) ||
(ops['n'] && (ops['b'] || ops['e'] || ops['r'] || ops['t'] || (OPT_ISSET(ops,'w') && OPT_ISSET(ops,'t')) ||
ops['d'] || ops['L'])) || (OPT_ISSET(ops,'n') && (OPT_ISSET(ops,'b') || OPT_ISSET(ops,'e') ||
(ops['d'] && (ops['b'] || ops['e'] || ops['L'] || ops['t'])) || OPT_ISSET(ops,'r') || OPT_ISSET(ops,'t') ||
(ops['L'] && (ops['b'] || ops['e']))) { OPT_ISSET(ops,'d') || OPT_ISSET(ops,'L'))) ||
(OPT_ISSET(ops,'d') && (OPT_ISSET(ops,'b') || OPT_ISSET(ops,'e') ||
OPT_ISSET(ops,'L') || OPT_ISSET(ops,'t'))) ||
(OPT_ISSET(ops,'L') && (OPT_ISSET(ops,'b') || OPT_ISSET(ops,'e')))) {
zwarnnam(nam, "illegal option combination", NULL, 0); zwarnnam(nam, "illegal option combination", NULL, 0);
return 1; return 1;
} }
if (ops['r'] || ops['w']) { if (OPT_ISSET(ops,'r') || OPT_ISSET(ops,'w')) {
Ptycmd p; Ptycmd p;
if (!*args) { if (!*args) {
@ -628,13 +631,14 @@ bin_zpty(char *nam, char **args, char *ops, int func)
} }
if (p->fin) if (p->fin)
return 2; return 2;
if (ops['t'] && p->read == -1 && !read_poll(p->fd, &p->read, 0)) if (OPT_ISSET(ops,'t') && p->read == -1 &&
!read_poll(p->fd, &p->read, 0))
return 1; return 1;
return (ops['r'] ? return (OPT_ISSET(ops,'r') ?
ptyread(nam, p, args + 1) : ptyread(nam, p, args + 1) :
ptywrite(p, args + 1, ops['n'])); ptywrite(p, args + 1, OPT_ISSET(ops,'n')));
} else if (ops['d']) { } else if (OPT_ISSET(ops,'d')) {
Ptycmd p; Ptycmd p;
int ret = 0; int ret = 0;
@ -650,7 +654,7 @@ bin_zpty(char *nam, char **args, char *ops, int func)
deleteallptycmds(); deleteallptycmds();
return ret; return ret;
} else if (ops['t']) { } else if (OPT_ISSET(ops,'t')) {
Ptycmd p; Ptycmd p;
if (!*args) { if (!*args) {
@ -671,14 +675,15 @@ bin_zpty(char *nam, char **args, char *ops, int func)
zwarnnam(nam, "pty command name already used: %s", *args, 0); zwarnnam(nam, "pty command name already used: %s", *args, 0);
return 1; return 1;
} }
return newptycmd(nam, *args, args + 1, ops['e'], ops['b']); return newptycmd(nam, *args, args + 1, OPT_ISSET(ops,'e'),
OPT_ISSET(ops,'b'));
} else { } else {
Ptycmd p; Ptycmd p;
char **a; char **a;
for (p = ptycmds; p; p = p->next) { for (p = ptycmds; p; p = p->next) {
checkptycmd(p); checkptycmd(p);
if (ops['L']) if (OPT_ISSET(ops,'L'))
printf("%s %s%s%s ", nam, (p->echo ? "-e " : ""), printf("%s %s%s%s ", nam, (p->echo ? "-e " : ""),
(p->nblock ? "-b " : ""), p->name); (p->nblock ? "-b " : ""), p->name);
else if (p->fin) else if (p->fin)

View file

@ -62,7 +62,7 @@ handle_digits(char *nam, char *argptr, fd_set *fdset, int *fdmax)
/**/ /**/
static int static int
bin_zselect(char *nam, char **args, char *ops, int func) bin_zselect(char *nam, char **args, Options ops, int func)
{ {
#ifdef HAVE_SELECT #ifdef HAVE_SELECT
int i, fd, fdsetind = 0, fdmax = 0, fdcount; int i, fd, fdsetind = 0, fdmax = 0, fdcount;

View file

@ -254,7 +254,7 @@ lookupstyle(char *ctxt, char *style)
} }
static int static int
bin_zstyle(char *nam, char **args, char *ops, int func) bin_zstyle(char *nam, char **args, Options ops, int func)
{ {
int min, max, n, add = 0, list = 0, eval = 0; int min, max, n, add = 0, list = 0, eval = 0;
@ -550,7 +550,7 @@ bin_zstyle(char *nam, char **args, char *ops, int func)
/* Format stuff. */ /* Format stuff. */
static int static int
bin_zformat(char *nam, char **args, char *ops, int func) bin_zformat(char *nam, char **args, Options ops, int func)
{ {
char opt; char opt;
@ -1161,7 +1161,7 @@ rmatch(RParseResult *sm, char *subj, char *var1, char *var2, int comp)
*/ */
static int static int
bin_zregexparse(char *nam, char **args, char *ops, int func) bin_zregexparse(char *nam, char **args, Options ops, int func)
{ {
int oldextendedglob = opts[EXTENDEDGLOB]; int oldextendedglob = opts[EXTENDEDGLOB];
char *var1 = args[0]; char *var1 = args[0];
@ -1187,7 +1187,7 @@ bin_zregexparse(char *nam, char **args, char *ops, int func)
ret = 0; ret = 0;
if (!ret) if (!ret)
ret = rmatch(&result, subj, var1, var2, ops['c']); ret = rmatch(&result, subj, var1, var2, OPT_ISSET(ops,'c'));
popheap(); popheap();
opts[EXTENDEDGLOB] = oldextendedglob; opts[EXTENDEDGLOB] = oldextendedglob;
@ -1315,7 +1315,7 @@ add_opt_val(Zoptdesc d, char *arg)
} }
static int static int
bin_zparseopts(char *nam, char **args, char *ops, int func) bin_zparseopts(char *nam, char **args, Options ops, int func)
{ {
char *o, *p, *n, **pp, **aval, **ap, *assoc = NULL, **cp, **np; char *o, *p, *n, **pp, **aval, **ap, *assoc = NULL, **cp, **np;
int del = 0, f, extract = 0, keep = 0; int del = 0, f, extract = 0, keep = 0;

View file

@ -187,7 +187,7 @@ freecompcond(void *a)
/**/ /**/
int int
compctlread(char *name, char **args, char *ops, char *reply) compctlread(char *name, char **args, Options ops, char *reply)
{ {
char *buf, *bptr; char *buf, *bptr;
@ -198,15 +198,15 @@ compctlread(char *name, char **args, char *ops, char *reply)
return 1; return 1;
} }
if (ops['l']) { if (OPT_ISSET(ops,'l')) {
/* -ln gives the index of the word the cursor is currently on, which is /* -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!) */ available in cs (but remember that Zsh counts from one, not zero!) */
if (ops['n']) { if (OPT_ISSET(ops,'n')) {
char nbuf[14]; char nbuf[14];
if (ops['e'] || ops['E']) if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E'))
printf("%d\n", cs + 1); printf("%d\n", cs + 1);
if (!ops['e']) { if (!OPT_ISSET(ops,'e')) {
sprintf(nbuf, "%d", cs + 1); sprintf(nbuf, "%d", cs + 1);
setsparam(reply, ztrdup(nbuf)); 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 /* without -n, the current line is assigned to the given parameter as a
scalar */ scalar */
if (ops['e'] || ops['E']) { if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) {
zputs((char *) line, stdout); zputs((char *) line, stdout);
putchar('\n'); putchar('\n');
} }
if (!ops['e']) if (!OPT_ISSET(ops,'e'))
setsparam(reply, ztrdup((char *) line)); setsparam(reply, ztrdup((char *) line));
} else { } else {
int i; 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 /* -cn gives the current cursor position within the current word, which
is available in clwpos (but remember that Zsh counts from one, not is available in clwpos (but remember that Zsh counts from one, not
zero!) */ zero!) */
if (ops['n']) { if (OPT_ISSET(ops,'n')) {
char nbuf[14]; char nbuf[14];
if (ops['e'] || ops['E']) if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E'))
printf("%d\n", clwpos + 1); printf("%d\n", clwpos + 1);
if (!ops['e']) { if (!OPT_ISSET(ops,'e')) {
sprintf(nbuf, "%d", clwpos + 1); sprintf(nbuf, "%d", clwpos + 1);
setsparam(reply, ztrdup(nbuf)); 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 /* without -n, the words of the current line are assigned to the given
parameters separately */ 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 /* the -A option means that one array is specified, instead of
many parameters */ many parameters */
char **p, **b = (char **)zcalloc((clwnum + 1) * sizeof(char *)); 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); setaparam(reply, b);
return 0; return 0;
} }
if (ops['e'] || ops['E']) { if (OPT_ISSET(ops,'e') || OPT_ISSET(ops,'E')) {
for (i = 0; i < clwnum; i++) { for (i = 0; i < clwnum; i++) {
zputs(clwords[i], stdout); zputs(clwords[i], stdout);
putchar('\n'); putchar('\n');
} }
if (ops['e']) if (OPT_ISSET(ops,'e'))
return 0; return 0;
} }
@ -1572,7 +1572,7 @@ printcompctlp(HashNode hn, int printflags)
/**/ /**/
static int 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; Compctl cc = NULL;
int ret = 0; int ret = 0;
@ -1678,14 +1678,14 @@ bin_compctl(char *name, char **argv, char *ops, int func)
#define CFN_DEFAULT 2 #define CFN_DEFAULT 2
static int 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) { if (incompfunc != 1) {
zwarnnam(name, "can only be called from completion function", NULL, 0); zwarnnam(name, "can only be called from completion function", NULL, 0);
return 1; return 1;
} }
return makecomplistctl((ops['T'] ? 0 : CFN_FIRST) | return makecomplistctl((OPT_ISSET(ops,'T') ? 0 : CFN_FIRST) |
(ops['D'] ? 0 : CFN_DEFAULT)); (OPT_ISSET(ops,'D') ? 0 : CFN_DEFAULT));
} }
/* /*

View file

@ -421,7 +421,7 @@ parse_class(Cpattern p, unsigned char *s, unsigned char e)
/**/ /**/
static int 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; struct cadata dat;
char *p, **sp, *e, *m = NULL, *mstr = NULL; 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 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; int test = 0, na = 0, nb = 0;
char *sa = NULL, *sb = NULL; char *sa = NULL, *sb = NULL;

View file

@ -717,7 +717,7 @@ cd_get(char **params)
/**/ /**/
static int 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); int n = arrlen(args);
@ -2259,7 +2259,7 @@ ca_set_data(LinkList descr, LinkList act, LinkList subc,
} }
static int 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; int min, max, n;
Castate lstate = &ca_laststate; Castate lstate = &ca_laststate;
@ -3136,7 +3136,7 @@ cv_parse_word(Cvdef d)
} }
static int 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; int min, max, n;
@ -3349,7 +3349,7 @@ comp_quote(char *str, int prefix)
} }
static int static int
bin_compquote(char *nam, char **args, char *ops, int func) bin_compquote(char *nam, char **args, Options ops, int func)
{ {
char *name; char *name;
struct value vbuf; struct value vbuf;
@ -3372,7 +3372,8 @@ bin_compquote(char *nam, char **args, char *ops, int func)
if ((v = getvalue(&vbuf, &name, 0))) { if ((v = getvalue(&vbuf, &name, 0))) {
switch (PM_TYPE(v->pm->flags)) { switch (PM_TYPE(v->pm->flags)) {
case PM_SCALAR: case PM_SCALAR:
setstrvalue(v, ztrdup(comp_quote(getstrvalue(v), ops['p']))); setstrvalue(v, ztrdup(comp_quote(getstrvalue(v),
OPT_ISSET(ops,'p'))));
break; break;
case PM_ARRAY: case PM_ARRAY:
{ {
@ -3382,7 +3383,7 @@ bin_compquote(char *nam, char **args, char *ops, int func)
char **p = new; char **p = new;
for (; *val; val++, p++) for (; *val; val++, p++)
*p = ztrdup(comp_quote(*val, ops['p'])); *p = ztrdup(comp_quote(*val, OPT_ISSET(ops,'p')));
*p = NULL; *p = NULL;
setarrvalue(v, new); setarrvalue(v, new);
@ -3499,7 +3500,7 @@ arrcontains(char **a, char *s, int colon)
} }
static int 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; int min, max, n, level;
@ -3629,7 +3630,7 @@ bin_comptags(char *nam, char **args, char *ops, int func)
} }
static int 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) { if (incompfunc != 1) {
zwarnnam(nam, "can only be called from completion function", NULL, 0); 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 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) { if (incompfunc != 1) {
zwarnnam(nam, "can only be called from completion function", NULL, 0); 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 static int
bin_compgroups(char *nam, char **args, char *ops, int func) bin_compgroups(char *nam, char **args, Options ops, int func)
{ {
Heap oldheap; Heap oldheap;
char *n; char *n;

View file

@ -604,12 +604,12 @@ keyisprefix(Keymap km, char *seq)
/**/ /**/
int int
bin_bindkey(char *name, char **argv, char *ops, int func) bin_bindkey(char *name, char **argv, Options ops, int func)
{ {
static struct opn { static struct opn {
char o; char o;
char selp; char selp;
int (*func) _((char *, char *, Keymap, char **, char *, char)); int (*func) _((char *, char *, Keymap, char **, Options, char));
int min, max; int min, max;
} const opns[] = { } const opns[] = {
{ 'l', 0, bin_bindkey_lsmaps, 0, 0 }, { 'l', 0, bin_bindkey_lsmaps, 0, 0 },
@ -628,15 +628,16 @@ bin_bindkey(char *name, char **argv, char *ops, int func)
int n; int n;
/* select operation and ensure no clashing arguments */ /* 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) if(op->o)
for(opp = op; (++opp)->o; ) for(opp = op; (++opp)->o; )
if(ops[STOUC(opp->o)]) { if(OPT_ISSET(ops,STOUC(opp->o))) {
zwarnnam(name, "incompatible operation selection options", zwarnnam(name, "incompatible operation selection options",
NULL, 0); NULL, 0);
return 1; 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) { if(!op->selp && n) {
zwarnnam(name, "keymap cannot be selected with -%c", NULL, op->o); zwarnnam(name, "keymap cannot be selected with -%c", NULL, op->o);
return 1; return 1;
@ -648,13 +649,13 @@ bin_bindkey(char *name, char **argv, char *ops, int func)
/* keymap selection */ /* keymap selection */
if(op->selp) { if(op->selp) {
if(ops['e']) if(OPT_ISSET(ops,'e'))
kmname = "emacs"; kmname = "emacs";
else if(ops['v']) else if(OPT_ISSET(ops,'v'))
kmname = "viins"; kmname = "viins";
else if(ops['a']) else if(OPT_ISSET(ops,'a'))
kmname = "vicmd"; kmname = "vicmd";
else if(ops['M']) { else if(OPT_ISSET(ops,'M')) {
kmname = *argv++; kmname = *argv++;
if(!kmname) { if(!kmname) {
zwarnnam(name, "-M option requires a keymap argument", NULL, 0); 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); zwarnnam(name, "no such keymap `%s'", kmname, 0);
return 1; return 1;
} }
if(ops['e'] || ops['v']) if(OPT_ISSET(ops,'e') || OPT_ISSET(ops,'v'))
linkkeymap(km, "main", 0); linkkeymap(km, "main", 0);
} else { } else {
kmname = NULL; kmname = NULL;
@ -676,7 +677,7 @@ bin_bindkey(char *name, char **argv, char *ops, int func)
/* listing is a special case */ /* listing is a special case */
if(!op->o && (!argv[0] || !argv[1])) { if(!op->o && (!argv[0] || !argv[1])) {
if(ops['e'] || ops['v']) if(OPT_ISSET(ops,'e') || OPT_ISSET(ops,'v'))
return 0; return 0;
return bin_bindkey_list(name, kmname, km, argv, ops, op->o); 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 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; return 0;
} }
@ -725,7 +726,7 @@ scanlistmaps(HashNode hn, int list)
/**/ /**/
static int 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); keymapnamtab->emptytable(keymapnamtab);
default_bindings(); default_bindings();
@ -736,7 +737,7 @@ bin_bindkey_delall(char *name, char *kmname, Keymap km, char **argv, char *ops,
/**/ /**/
static int 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; int ret = 0;
@ -755,7 +756,7 @@ bin_bindkey_del(char *name, char *kmname, Keymap km, char **argv, char *ops, cha
/**/ /**/
static int 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]); km = openkeymap(argv[0]);
if(!km) { if(!km) {
@ -772,7 +773,7 @@ bin_bindkey_link(char *name, char *kmname, Keymap km, char **argv, char *ops, ch
/**/ /**/
static int 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]); 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 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; char m[3], *str;
int i; int i;
@ -830,7 +831,7 @@ bin_bindkey_meta(char *name, char *kmname, Keymap km, char **argv, char *ops, ch
/**/ /**/
static int 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; 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); zwarnnam(name, "keymap `%s' is protected", kmname, 0);
return 1; return 1;
} }
if (func == 'r' && ops['p']) { if (func == 'r' && OPT_ISSET(ops,'p')) {
char *useq, *bseq; char *useq, *bseq;
int len; int len;
struct remprefstate rps; 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); bseq = getkeystring(useq, &len, 2, NULL);
seq = metafy(bseq, len, META_USEHEAP); seq = metafy(bseq, len, META_USEHEAP);
if(ops['R']) { if(OPT_ISSET(ops,'R')) {
int first, last; int first, last;
char m[3]; char m[3];
@ -924,13 +925,13 @@ scanremoveprefix(char *seq, Thingy bind, char *str, void *magic)
/**/ /**/
static int 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; struct bindstate bs;
bs.flags = ops['L'] ? BS_LIST : 0; bs.flags = OPT_ISSET(ops,'L') ? BS_LIST : 0;
bs.kmname = kmname; bs.kmname = kmname;
if(argv[0] && !ops['p']) { if(argv[0] && !OPT_ISSET(ops,'p')) {
int len; int len;
char *seq; char *seq;
@ -944,7 +945,7 @@ bin_bindkey_list(char *name, char *kmname, Keymap km, char **argv, char *ops, ch
bindlistout(&bs); bindlistout(&bs);
} else { } else {
/* empty prefix is equivalent to no prefix */ /* 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]) { if (!argv[0]) {
zwarnnam(name, "option -p requires a prefix string", NULL, 0); zwarnnam(name, "option -p requires a prefix string", NULL, 0);
return 1; return 1;

View file

@ -951,7 +951,7 @@ mod_export char *varedarg;
/**/ /**/
static int 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; char *s, *t, *ova = varedarg;
struct value vbuf; struct value vbuf;
@ -1012,11 +1012,11 @@ bin_vared(char *name, char **args, char *ops, int func)
break; break;
case 'h': case 'h':
/* -h option -- enable history */ /* -h option -- enable history */
ops['h'] = 1; ops->ind['h'] = 1;
break; break;
case 'e': case 'e':
/* -e option -- enable EOF */ /* -e option -- enable EOF */
ops['e'] = 1; ops->ind['e'] = 1;
break; break;
default: default:
/* unrecognised option character */ /* unrecognised option character */
@ -1113,14 +1113,14 @@ bin_vared(char *name, char **args, char *ops, int func)
varedarg = *args; varedarg = *args;
ifl = isfirstln; ifl = isfirstln;
if (ops['h']) if (OPT_ISSET(ops,'h'))
hbegin(2); hbegin(2);
isfirstln = ops['e']; isfirstln = OPT_ISSET(ops,'e');
ieof = opts[IGNOREEOF]; ieof = opts[IGNOREEOF];
opts[IGNOREEOF] = 0; 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; opts[IGNOREEOF] = ieof;
if (ops['h']) if (OPT_ISSET(ops,'h'))
hend(NULL); hend(NULL);
isfirstln = ifl; isfirstln = ifl;
varedarg = ova; varedarg = ova;

View file

@ -324,11 +324,11 @@ deletezlefunction(Widget w)
/**/ /**/
int int
bin_zle(char *name, char **args, char *ops, int func) bin_zle(char *name, char **args, Options ops, int func)
{ {
static struct opn { static struct opn {
char o; char o;
int (*func) _((char *, char **, char *, char)); int (*func) _((char *, char **, Options, char));
int min, max; int min, max;
} const opns[] = { } const opns[] = {
{ 'l', bin_zle_list, 0, -1 }, { 'l', bin_zle_list, 0, -1 },
@ -348,10 +348,10 @@ bin_zle(char *name, char **args, char *ops, int func)
int n; int n;
/* select operation and ensure no clashing arguments */ /* 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) if(op->o)
for(opp = op; (++opp)->o; ) for(opp = op; (++opp)->o; )
if(ops[STOUC(opp->o)]) { if(OPT_ISSET(ops,STOUC(opp->o))) {
zwarnnam(name, "incompatible operation selection options", zwarnnam(name, "incompatible operation selection options",
NULL, 0); NULL, 0);
return 1; return 1;
@ -373,11 +373,11 @@ bin_zle(char *name, char **args, char *ops, int func)
/**/ /**/
static int 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) { if (!*args) {
scanhashtable(thingytab, 1, 0, DISABLED, scanlistwidgets, scanhashtable(thingytab, 1, 0, DISABLED, scanlistwidgets,
(ops['a'] ? -1 : ops['L'])); (OPT_ISSET(ops,'a') ? -1 : OPT_ISSET(ops,'L')));
return 0; return 0;
} else { } else {
int ret = 0; int ret = 0;
@ -385,7 +385,7 @@ bin_zle_list(char *name, char **args, char *ops, char func)
for (; *args && !ret; args++) { for (; *args && !ret; args++) {
if (!(t = (Thingy) thingytab->getnode2(thingytab, *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; ret = 1;
} }
return ret; return ret;
@ -394,7 +394,7 @@ bin_zle_list(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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; char *s = statusline;
int sl = statusll, ocl = clearlist; int sl = statusll, ocl = clearlist;
@ -421,11 +421,11 @@ bin_zle_refresh(char *name, char **args, char *ops, char func)
lastlistlen++; lastlistlen++;
showinglist = clearlist = 0; showinglist = clearlist = 0;
zmult = zmultsav; zmult = zmultsav;
} else if (ops['c']) { } else if (OPT_ISSET(ops,'c')) {
clearlist = 1; clearlist = 1;
lastlistlen = 0; lastlistlen = 0;
} }
} else if (ops['c']) { } else if (OPT_ISSET(ops,'c')) {
clearlist = listshown = 1; clearlist = listshown = 1;
lastlistlen = 0; lastlistlen = 0;
} }
@ -439,7 +439,7 @@ bin_zle_refresh(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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) { if (!zleactive) {
zwarnnam(name, "can only be called from widget function", NULL, 0); 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 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); char *b = *args, *p = b + strlen(b);
@ -468,7 +468,7 @@ bin_zle_unget(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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) { if (!zleactive) {
zwarnnam(name, "can only be called from widget function", NULL, 0); zwarnnam(name, "can only be called from widget function", NULL, 0);
@ -522,7 +522,7 @@ scanlistwidgets(HashNode hn, int list)
/**/ /**/
static int 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; int ret = 0;
@ -541,7 +541,7 @@ bin_zle_del(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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]); 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 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)); Widget w = zalloc(sizeof(*w));
@ -574,7 +574,7 @@ bin_zle_new(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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; Thingy t;
Widget w, cw; Widget w, cw;
@ -608,7 +608,7 @@ bin_zle_complete(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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; Thingy t;
struct modifier modsave; struct modifier modsave;
@ -672,7 +672,7 @@ bin_zle_call(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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 (zleactive) {
if (!trashedzle) if (!trashedzle)
@ -684,7 +684,7 @@ bin_zle_invalidate(char *name, char **args, char *ops, char func)
/**/ /**/
static int 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; int fd = 0, i, found = 0;
char *endptr; 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. */ /* Listing handlers. */
if (*args && args[1]) { if (*args && args[1]) {
zwarnnam(name, "too many arguments for -FL", NULL, 0); zwarnnam(name, "too many arguments for -FL", NULL, 0);

File diff suppressed because it is too large Load diff

View file

@ -557,7 +557,7 @@ printhashtabinfo(HashTable ht)
/**/ /**/
int int
bin_hashinfo(char *nam, char **args, char *ops, int func) bin_hashinfo(char *nam, char **args, Options ops, int func)
{ {
HashTable ht; HashTable ht;

View file

@ -48,15 +48,16 @@
#define BIN_EVAL 14 #define BIN_EVAL 14
#define BIN_SCHED 15 #define BIN_SCHED 15
#define BIN_FC 16 #define BIN_FC 16
#define BIN_PUSHLINE 17 #define BIN_R 17
#define BIN_LOGOUT 18 #define BIN_PUSHLINE 18
#define BIN_TEST 19 #define BIN_LOGOUT 19
#define BIN_BRACKET 20 #define BIN_TEST 20
#define BIN_EXPORT 21 #define BIN_BRACKET 21
#define BIN_ECHO 22 #define BIN_EXPORT 22
#define BIN_DISABLE 23 #define BIN_ECHO 23
#define BIN_ENABLE 24 #define BIN_DISABLE 24
#define BIN_PRINTF 25 #define BIN_ENABLE 25
#define BIN_PRINTF 26
/* These currently depend on being 0 and 1. */ /* These currently depend on being 0 and 1. */
#define BIN_SETOPT 0 #define BIN_SETOPT 0

View file

@ -1175,7 +1175,7 @@ mod_export CompctlReadFn compctlreadptr = fallback_compctlread;
/**/ /**/
mod_export int mod_export int
fallback_compctlread(char *name, char **args, char *ops, char *reply) fallback_compctlread(char *name, char **args, Options ops, char *reply)
{ {
zwarnnam(name, "option valid only in functions called from completion", zwarnnam(name, "option valid only in functions called from completion",
NULL, 0); NULL, 0);

View file

@ -1252,11 +1252,11 @@ init_hackzero(char **argv, char **envp)
/**/ /**/
int int
bin_fg(char *name, char **argv, char *ops, int func) bin_fg(char *name, char **argv, Options ops, int func)
{ {
int job, lng, firstjob = -1, retval = 0, ofunc = func; int job, lng, firstjob = -1, retval = 0, ofunc = func;
if (ops['Z']) { if (OPT_ISSET(ops,'Z')) {
int len; int len;
if(isset(RESTRICTED)) { if(isset(RESTRICTED)) {
@ -1277,8 +1277,8 @@ bin_fg(char *name, char **argv, char *ops, int func)
return 0; return 0;
} }
lng = (ops['l']) ? 1 : (ops['p']) ? 2 : 0; lng = (OPT_ISSET(ops,'l')) ? 1 : (OPT_ISSET(ops,'p')) ? 2 : 0;
if (ops['d']) if (OPT_ISSET(ops,'d'))
lng |= 4; lng |= 4;
if ((func == BIN_FG || func == BIN_BG) && !jobbing) { if ((func == BIN_FG || func == BIN_BG) && !jobbing) {
@ -1327,10 +1327,11 @@ bin_fg(char *name, char **argv, char *ops, int func)
} }
for (job = 0; job != maxjob; job++, jobptr++) for (job = 0; job != maxjob; job++, jobptr++)
if (job != ignorejob && jobptr->stat) { if (job != ignorejob && jobptr->stat) {
if ((!ops['r'] && !ops['s']) || if ((!OPT_ISSET(ops,'r') && !OPT_ISSET(ops,'s')) ||
(ops['r'] && ops['s']) || (OPT_ISSET(ops,'r') && OPT_ISSET(ops,'s')) ||
(ops['r'] && !(jobptr->stat & STAT_STOPPED)) || (OPT_ISSET(ops,'r') &&
(ops['s'] && jobptr->stat & STAT_STOPPED)) !(jobptr->stat & STAT_STOPPED)) ||
(OPT_ISSET(ops,'s') && jobptr->stat & STAT_STOPPED))
printjob(jobptr, lng, 2); printjob(jobptr, lng, 2);
} }
unqueue_signals(); unqueue_signals();
@ -1498,7 +1499,7 @@ bin_fg(char *name, char **argv, char *ops, int func)
/**/ /**/
int int
bin_kill(char *nam, char **argv, char *ops, int func) bin_kill(char *nam, char **argv, Options ops, int func)
{ {
int sig = SIGTERM; int sig = SIGTERM;
int returnval = 0; int returnval = 0;
@ -1642,10 +1643,10 @@ bin_kill(char *nam, char **argv, char *ops, int func)
/**/ /**/
int int
bin_suspend(char *name, char **argv, char *ops, int func) bin_suspend(char *name, char **argv, Options ops, int func)
{ {
/* won't suspend a login shell, unless forced */ /* won't suspend a login shell, unless forced */
if (islogin && !ops['f']) { if (islogin && !OPT_ISSET(ops,'f')) {
zwarnnam(name, "can't suspend login shell", NULL, 0); zwarnnam(name, "can't suspend login shell", NULL, 0);
return 1; return 1;
} }

View file

@ -1238,7 +1238,7 @@ calloc(MALLOC_ARG_T n, MALLOC_ARG_T size)
/**/ /**/
int int
bin_mem(char *name, char **argv, char *ops, int func) bin_mem(char *name, char **argv, Options ops, int func)
{ {
int i, ii, fi, ui, j; int i, ii, fi, ui, j;
struct m_hdr *m, *mf, *ms; struct m_hdr *m, *mf, *ms;
@ -1246,21 +1246,21 @@ bin_mem(char *name, char **argv, char *ops, int func)
long u = 0, f = 0, to, cu; long u = 0, f = 0, to, cu;
queue_signals(); queue_signals();
if (ops['v']) { if (OPT_ISSET(ops,'v')) {
printf("The lower and the upper addresses of the heap. Diff gives\n"); printf("The lower and the upper addresses of the heap. Diff gives\n");
printf("the difference between them, i.e. the size of the heap.\n\n"); printf("the difference between them, i.e. the size of the heap.\n\n");
} }
printf("low mem %ld\t high mem %ld\t diff %ld\n", printf("low mem %ld\t high mem %ld\t diff %ld\n",
(long)m_l, (long)m_high, (long)(m_high - ((char *)m_l))); (long)m_l, (long)m_high, (long)(m_high - ((char *)m_l)));
if (ops['v']) { if (OPT_ISSET(ops,'v')) {
printf("\nThe number of bytes that were allocated using sbrk() and\n"); printf("\nThe number of bytes that were allocated using sbrk() and\n");
printf("the number of bytes that were given back to the system\n"); printf("the number of bytes that were given back to the system\n");
printf("via brk().\n"); printf("via brk().\n");
} }
printf("\nsbrk %d\tbrk %d\n", m_s, m_b); printf("\nsbrk %d\tbrk %d\n", m_s, m_b);
if (ops['v']) { if (OPT_ISSET(ops,'v')) {
printf("\nInformation about the sizes that were allocated or freed.\n"); printf("\nInformation about the sizes that were allocated or freed.\n");
printf("For each size that were used the number of mallocs and\n"); printf("For each size that were used the number of mallocs and\n");
printf("frees is shown. Diff gives the difference between these\n"); printf("frees is shown. Diff gives the difference between these\n");
@ -1282,7 +1282,7 @@ bin_mem(char *name, char **argv, char *ops, int func)
if (m_m[i] || m_f[i]) if (m_m[i] || m_f[i])
printf("big\t%d\t%d\t%d\n", m_m[i], m_f[i], m_m[i] - m_f[i]); printf("big\t%d\t%d\t%d\n", m_m[i], m_f[i], m_m[i] - m_f[i]);
if (ops['v']) { if (OPT_ISSET(ops,'v')) {
printf("\nThe list of memory blocks. For each block the following\n"); printf("\nThe list of memory blocks. For each block the following\n");
printf("information is shown:\n\n"); printf("information is shown:\n\n");
printf("num\tthe number of this block\n"); printf("num\tthe number of this block\n");
@ -1334,7 +1334,7 @@ bin_mem(char *name, char **argv, char *ops, int func)
mf = mf->next; mf = mf->next;
} }
if (ops['v']) { if (OPT_ISSET(ops,'v')) {
printf("\nHere is some information about the small blocks used.\n"); printf("\nHere is some information about the small blocks used.\n");
printf("For each size the arrays with the number of free and the\n"); printf("For each size the arrays with the number of free and the\n");
printf("number of used blocks are shown.\n"); printf("number of used blocks are shown.\n");
@ -1353,7 +1353,7 @@ bin_mem(char *name, char **argv, char *ops, int func)
} }
putchar('\n'); putchar('\n');
} }
if (ops['v']) { if (OPT_ISSET(ops,'v')) {
printf("\n\nBelow is some information about the allocation\n"); printf("\n\nBelow is some information about the allocation\n");
printf("behaviour of the zsh heaps. First the number of times\n"); printf("behaviour of the zsh heaps. First the number of times\n");
printf("pushheap(), popheap(), and freeheap() were called.\n"); printf("pushheap(), popheap(), and freeheap() were called.\n");
@ -1362,7 +1362,7 @@ bin_mem(char *name, char **argv, char *ops, int func)
printf("push %d\tpop %d\tfree %d\n\n", h_push, h_pop, h_free); printf("push %d\tpop %d\tfree %d\n\n", h_push, h_pop, h_free);
if (ops['v']) { if (OPT_ISSET(ops,'v')) {
printf("\nThe next list shows for several sizes the number of times\n"); printf("\nThe next list shows for several sizes the number of times\n");
printf("memory of this size were taken from heaps.\n\n"); printf("memory of this size were taken from heaps.\n\n");
} }

View file

@ -92,9 +92,9 @@ register_module(char *n, Module_func setup, Module_func boot,
/**/ /**/
static void static void
printmodalias(Module m, char *ops) printmodalias(Module m, Options ops)
{ {
if (ops['L']) { if (OPT_ISSET(ops,'L')) {
printf("zmodload -A "); printf("zmodload -A ");
if (m->nam[0] == '-') if (m->nam[0] == '-')
fputs("-- ", stdout); fputs("-- ", stdout);
@ -956,10 +956,11 @@ autoloadscan(HashNode hn, int printflags)
/**/ /**/
int int
bin_zmodload(char *nam, char **args, char *ops, int func) bin_zmodload(char *nam, char **args, Options ops, int func)
{ {
int ops_bcpf = ops['b'] || ops['c'] || ops['p'] || ops['f']; int ops_bcpf = OPT_ISSET(ops,'b') || OPT_ISSET(ops,'c') ||
int ops_au = ops['a'] || ops['u']; OPT_ISSET(ops,'p') || OPT_ISSET(ops,'f');
int ops_au = OPT_ISSET(ops,'a') || OPT_ISSET(ops,'u');
int ret = 1; int ret = 1;
if (ops_bcpf && !ops_au) { if (ops_bcpf && !ops_au) {
@ -967,41 +968,45 @@ bin_zmodload(char *nam, char **args, char *ops, int func)
NULL, 0); NULL, 0);
return 1; return 1;
} }
if (ops['A'] || ops['R']) { if (OPT_ISSET(ops,'A') || OPT_ISSET(ops,'R')) {
if (ops_bcpf || ops_au || ops['d'] || (ops['R'] && ops['e'])) { if (ops_bcpf || ops_au || OPT_ISSET(ops,'d') ||
(OPT_ISSET(ops,'R') && OPT_ISSET(ops,'e'))) {
zwarnnam(nam, "illegal flags combined with -A or -R", NULL, 0); zwarnnam(nam, "illegal flags combined with -A or -R", NULL, 0);
return 1; return 1;
} }
if (!ops['e']) if (!OPT_ISSET(ops,'e'))
return bin_zmodload_alias(nam, args, ops); return bin_zmodload_alias(nam, args, ops);
} }
if (ops['d'] && ops['a']) { if (OPT_ISSET(ops,'d') && OPT_ISSET(ops,'a')) {
zwarnnam(nam, "-d cannot be combined with -a", NULL, 0); zwarnnam(nam, "-d cannot be combined with -a", NULL, 0);
return 1; return 1;
} }
if (ops['u'] && !*args) { if (OPT_ISSET(ops,'u') && !*args) {
zwarnnam(nam, "what do you want to unload?", NULL, 0); zwarnnam(nam, "what do you want to unload?", NULL, 0);
return 1; return 1;
} }
if (ops['e'] && (ops['I'] || ops['L'] || ops['a'] || ops['d'] || if (OPT_ISSET(ops,'e') && (OPT_ISSET(ops,'I') || OPT_ISSET(ops,'L') ||
ops['i'] || ops['u'])) { OPT_ISSET(ops,'a') || OPT_ISSET(ops,'d') ||
OPT_ISSET(ops,'i') || OPT_ISSET(ops,'u'))) {
zwarnnam(nam, "-e cannot be combined with other options", NULL, 0); zwarnnam(nam, "-e cannot be combined with other options", NULL, 0);
return 1; return 1;
} }
queue_signals(); queue_signals();
if (ops['e']) if (OPT_ISSET(ops,'e'))
ret = bin_zmodload_exist(nam, args, ops); ret = bin_zmodload_exist(nam, args, ops);
else if (ops['d']) else if (OPT_ISSET(ops,'d'))
ret = bin_zmodload_dep(nam, args, ops); ret = bin_zmodload_dep(nam, args, ops);
else if ((ops['a'] || ops['b']) && !(ops['c'] || ops['p'] || ops['f'])) else if ((OPT_ISSET(ops,'a') || OPT_ISSET(ops,'b')) &&
!(OPT_ISSET(ops,'c') || OPT_ISSET(ops,'p') || OPT_ISSET(ops,'f')))
ret = bin_zmodload_auto(nam, args, ops); ret = bin_zmodload_auto(nam, args, ops);
else if (ops['c'] && !(ops['b'] || ops['p'])) else if (OPT_ISSET(ops,'c') && !(OPT_ISSET(ops,'b') || OPT_ISSET(ops,'p')))
ret = bin_zmodload_cond(nam, args, ops); ret = bin_zmodload_cond(nam, args, ops);
else if (ops['f'] && !(ops['b'] || ops['p'])) else if (OPT_ISSET(ops,'f') && !(OPT_ISSET(ops,'b') || OPT_ISSET(ops,'p')))
ret = bin_zmodload_math(nam, args, ops); ret = bin_zmodload_math(nam, args, ops);
else if (ops['p'] && !(ops['b'] || ops['c'])) else if (OPT_ISSET(ops,'p') && !(OPT_ISSET(ops,'b') || OPT_ISSET(ops,'c')))
ret = bin_zmodload_param(nam, args, ops); ret = bin_zmodload_param(nam, args, ops);
else if (!(ops['a'] || ops['b'] || ops['c'] || ops['p'])) else if (!(OPT_ISSET(ops,'a') || OPT_ISSET(ops,'b') ||
OPT_ISSET(ops,'c') || OPT_ISSET(ops,'p')))
ret = bin_zmodload_load(nam, args, ops); ret = bin_zmodload_load(nam, args, ops);
else else
zwarnnam(nam, "use only one of -b, -c, or -p", NULL, 0); zwarnnam(nam, "use only one of -b, -c, or -p", NULL, 0);
@ -1012,7 +1017,7 @@ bin_zmodload(char *nam, char **args, char *ops, int func)
/**/ /**/
static int static int
bin_zmodload_alias(char *nam, char **args, char *ops) bin_zmodload_alias(char *nam, char **args, Options ops)
{ {
/* /*
* TODO: while it would be too nasty to have aliases, as opposed * TODO: while it would be too nasty to have aliases, as opposed
@ -1032,7 +1037,7 @@ bin_zmodload_alias(char *nam, char **args, char *ops)
int ret = 0; int ret = 0;
if (!*args) { if (!*args) {
if (ops['R']) { if (OPT_ISSET(ops,'R')) {
zwarnnam(nam, "no module alias to remove", NULL, 0); zwarnnam(nam, "no module alias to remove", NULL, 0);
return 1; return 1;
} }
@ -1053,7 +1058,7 @@ bin_zmodload_alias(char *nam, char **args, char *ops)
zwarnnam(nam, "invalid module name `%s'", *args, 0); zwarnnam(nam, "invalid module name `%s'", *args, 0);
return 1; return 1;
} }
if (ops['R']) { if (OPT_ISSET(ops,'R')) {
if (aliasname) { if (aliasname) {
zwarnnam(nam, "bad syntax for removing module alias: %s", zwarnnam(nam, "bad syntax for removing module alias: %s",
*args, 0); *args, 0);
@ -1123,7 +1128,7 @@ bin_zmodload_alias(char *nam, char **args, char *ops)
/**/ /**/
static int static int
bin_zmodload_exist(char *nam, char **args, char *ops) bin_zmodload_exist(char *nam, char **args, Options ops)
{ {
LinkNode node; LinkNode node;
Module m; Module m;
@ -1135,7 +1140,8 @@ bin_zmodload_exist(char *nam, char **args, char *ops)
modname = m->nam; modname = m->nam;
if (m->flags & MOD_ALIAS) { if (m->flags & MOD_ALIAS) {
LinkNode node2; LinkNode node2;
if (ops['A'] && (node2 = find_module(m->u.alias, 1, NULL))) if (OPT_ISSET(ops,'A') &&
(node2 = find_module(m->u.alias, 1, NULL)))
m = (Module) getdata(node2); m = (Module) getdata(node2);
else else
continue; continue;
@ -1161,11 +1167,11 @@ bin_zmodload_exist(char *nam, char **args, char *ops)
/**/ /**/
static int static int
bin_zmodload_dep(char *nam, char **args, char *ops) bin_zmodload_dep(char *nam, char **args, Options ops)
{ {
LinkNode node; LinkNode node;
Module m; Module m;
if (ops['u']) { if (OPT_ISSET(ops,'u')) {
/* remove dependencies, which can't pertain to aliases */ /* remove dependencies, which can't pertain to aliases */
const char *tnam = *args++; const char *tnam = *args++;
node = find_module(tnam, 1, &tnam); node = find_module(tnam, 1, &tnam);
@ -1201,7 +1207,7 @@ bin_zmodload_dep(char *nam, char **args, char *ops)
m = (Module) getdata(node); m = (Module) getdata(node);
if (m->deps && (!args[0] || !strcmp(args[0], m->nam))) { if (m->deps && (!args[0] || !strcmp(args[0], m->nam))) {
LinkNode n; LinkNode n;
if (ops['L']) { if (OPT_ISSET(ops,'L')) {
printf("zmodload -d "); printf("zmodload -d ");
if(m->nam[0] == '-') if(m->nam[0] == '-')
fputs("-- ", stdout); fputs("-- ", stdout);
@ -1212,7 +1218,7 @@ bin_zmodload_dep(char *nam, char **args, char *ops)
} }
for (n = firstnode(m->deps); n; incnode(n)) { for (n = firstnode(m->deps); n; incnode(n)) {
putchar(' '); putchar(' ');
if(ops['L']) if(OPT_ISSET(ops,'L'))
quotedzputs((char *) getdata(n), stdout); quotedzputs((char *) getdata(n), stdout);
else else
nicezputs((char *) getdata(n), stdout); nicezputs((char *) getdata(n), stdout);
@ -1234,15 +1240,15 @@ bin_zmodload_dep(char *nam, char **args, char *ops)
/**/ /**/
static int static int
bin_zmodload_auto(char *nam, char **args, char *ops) bin_zmodload_auto(char *nam, char **args, Options ops)
{ {
int ret = 0; int ret = 0;
if(ops['u']) { if(OPT_ISSET(ops,'u')) {
/* remove autoloaded builtins */ /* remove autoloaded builtins */
for (; *args; args++) { for (; *args; args++) {
Builtin bn = (Builtin) builtintab->getnode2(builtintab, *args); Builtin bn = (Builtin) builtintab->getnode2(builtintab, *args);
if (!bn) { if (!bn) {
if(!ops['i']) { if(!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such builtin", *args, 0); zwarnnam(nam, "%s: no such builtin", *args, 0);
ret = 1; ret = 1;
} }
@ -1256,7 +1262,7 @@ bin_zmodload_auto(char *nam, char **args, char *ops)
} else if(!*args) { } else if(!*args) {
/* list autoloaded builtins */ /* list autoloaded builtins */
scanhashtable(builtintab, 0, 0, 0, scanhashtable(builtintab, 0, 0, 0,
autoloadscan, ops['L'] ? PRINT_LIST : 0); autoloadscan, OPT_ISSET(ops,'L') ? PRINT_LIST : 0);
return 0; return 0;
} else { } else {
/* add autoloaded builtins */ /* add autoloaded builtins */
@ -1267,7 +1273,7 @@ bin_zmodload_auto(char *nam, char **args, char *ops)
if (strchr(bnam, '/')) { if (strchr(bnam, '/')) {
zwarnnam(nam, "%s: `/' is illegal in a builtin", bnam, 0); zwarnnam(nam, "%s: `/' is illegal in a builtin", bnam, 0);
ret = 1; ret = 1;
} else if (add_autobin(bnam, modnam) && !ops['i']) { } else if (add_autobin(bnam, modnam) && !OPT_ISSET(ops,'i')) {
zwarnnam(nam, "failed to add builtin %s", bnam, 0); zwarnnam(nam, "failed to add builtin %s", bnam, 0);
ret = 1; ret = 1;
} }
@ -1278,17 +1284,17 @@ bin_zmodload_auto(char *nam, char **args, char *ops)
/**/ /**/
static int static int
bin_zmodload_cond(char *nam, char **args, char *ops) bin_zmodload_cond(char *nam, char **args, Options ops)
{ {
int ret = 0; int ret = 0;
if (ops['u']) { if (OPT_ISSET(ops,'u')) {
/* remove autoloaded conditions */ /* remove autoloaded conditions */
for (; *args; args++) { for (; *args; args++) {
Conddef cd = getconddef(ops['I'], *args, 0); Conddef cd = getconddef(OPT_ISSET(ops,'I'), *args, 0);
if (!cd) { if (!cd) {
if (!ops['i']) { if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such condition", *args, 0); zwarnnam(nam, "%s: no such condition", *args, 0);
ret = 1; ret = 1;
} }
@ -1305,7 +1311,7 @@ bin_zmodload_cond(char *nam, char **args, char *ops)
for (p = condtab; p; p = p->next) { for (p = condtab; p; p = p->next) {
if (p->module) { if (p->module) {
if (ops['L']) { if (OPT_ISSET(ops,'L')) {
fputs("zmodload -ac", stdout); fputs("zmodload -ac", stdout);
if (p->flags & CONDF_INFIX) if (p->flags & CONDF_INFIX)
putchar('I'); putchar('I');
@ -1330,7 +1336,8 @@ bin_zmodload_cond(char *nam, char **args, char *ops)
if (strchr(cnam, '/')) { if (strchr(cnam, '/')) {
zwarnnam(nam, "%s: `/' is illegal in a condition", cnam, 0); zwarnnam(nam, "%s: `/' is illegal in a condition", cnam, 0);
ret = 1; ret = 1;
} else if (add_autocond(cnam, ops['I'], modnam) && !ops['i']) { } else if (add_autocond(cnam, OPT_ISSET(ops,'I'), modnam) &&
!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "failed to add condition `%s'", cnam, 0); zwarnnam(nam, "failed to add condition `%s'", cnam, 0);
ret = 1; ret = 1;
} }
@ -1341,17 +1348,17 @@ bin_zmodload_cond(char *nam, char **args, char *ops)
/**/ /**/
static int static int
bin_zmodload_math(char *nam, char **args, char *ops) bin_zmodload_math(char *nam, char **args, Options ops)
{ {
int ret = 0; int ret = 0;
if (ops['u']) { if (OPT_ISSET(ops,'u')) {
/* remove autoloaded math functions */ /* remove autoloaded math functions */
for (; *args; args++) { for (; *args; args++) {
MathFunc f = getmathfunc(*args, 0); MathFunc f = getmathfunc(*args, 0);
if (!f) { if (!f) {
if (!ops['i']) { if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such math function", *args, 0); zwarnnam(nam, "%s: no such math function", *args, 0);
ret = 1; ret = 1;
} }
@ -1368,7 +1375,7 @@ bin_zmodload_math(char *nam, char **args, char *ops)
for (p = mathfuncs; p; p = p->next) { for (p = mathfuncs; p; p = p->next) {
if (p->module) { if (p->module) {
if (ops['L']) { if (OPT_ISSET(ops,'L')) {
fputs("zmodload -af", stdout); fputs("zmodload -af", stdout);
printf(" %s %s\n", p->module, p->name); printf(" %s %s\n", p->module, p->name);
} else } else
@ -1387,7 +1394,7 @@ bin_zmodload_math(char *nam, char **args, char *ops)
zwarnnam(nam, "%s: `/' is illegal in a math function", zwarnnam(nam, "%s: `/' is illegal in a math function",
fnam, 0); fnam, 0);
ret = 1; ret = 1;
} else if (add_automathfunc(fnam, modnam) && !ops['i']) { } else if (add_automathfunc(fnam, modnam) && !OPT_ISSET(ops,'i')) {
zwarnnam(nam, "failed to add math function `%s'", fnam, 0); zwarnnam(nam, "failed to add math function `%s'", fnam, 0);
ret = 1; ret = 1;
} }
@ -1411,17 +1418,17 @@ printautoparams(HashNode hn, int lon)
/**/ /**/
static int static int
bin_zmodload_param(char *nam, char **args, char *ops) bin_zmodload_param(char *nam, char **args, Options ops)
{ {
int ret = 0; int ret = 0;
if (ops['u']) { if (OPT_ISSET(ops,'u')) {
/* remove autoloaded parameters */ /* remove autoloaded parameters */
for (; *args; args++) { for (; *args; args++) {
Param pm = (Param) gethashnode2(paramtab, *args); Param pm = (Param) gethashnode2(paramtab, *args);
if (!pm) { if (!pm) {
if (!ops['i']) { if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such parameter", *args, 0); zwarnnam(nam, "%s: no such parameter", *args, 0);
ret = 1; ret = 1;
} }
@ -1433,7 +1440,7 @@ bin_zmodload_param(char *nam, char **args, char *ops)
} }
return ret; return ret;
} else if (!*args) { } else if (!*args) {
scanhashtable(paramtab, 1, 0, 0, printautoparams, ops['L']); scanhashtable(paramtab, 1, 0, 0, printautoparams, OPT_ISSET(ops,'L'));
return 0; return 0;
} else { } else {
/* add autoloaded parameters */ /* add autoloaded parameters */
@ -1544,12 +1551,12 @@ unload_module(Module m, LinkNode node)
/**/ /**/
static int static int
bin_zmodload_load(char *nam, char **args, char *ops) bin_zmodload_load(char *nam, char **args, Options ops)
{ {
LinkNode node; LinkNode node;
Module m; Module m;
int ret = 0; int ret = 0;
if(ops['u']) { if(OPT_ISSET(ops,'u')) {
/* unload modules */ /* unload modules */
const char *mname = *args; const char *mname = *args;
for(; *args; args++) { for(; *args; args++) {
@ -1579,7 +1586,7 @@ bin_zmodload_load(char *nam, char **args, char *ops)
ret = 1; ret = 1;
if (del) if (del)
m->wrapper--; m->wrapper--;
} else if (!ops['i']) { } else if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "no such module %s", *args, 0); zwarnnam(nam, "no such module %s", *args, 0);
ret = 1; ret = 1;
} }
@ -1591,7 +1598,7 @@ bin_zmodload_load(char *nam, char **args, char *ops)
for (node = firstnode(modules); node; incnode(node)) { for (node = firstnode(modules); node; incnode(node)) {
m = (Module) getdata(node); m = (Module) getdata(node);
if (m->u.handle && !(m->flags & (MOD_UNLOAD|MOD_ALIAS))) { if (m->u.handle && !(m->flags & (MOD_UNLOAD|MOD_ALIAS))) {
if(ops['L']) { if(OPT_ISSET(ops,'L')) {
printf("zmodload "); printf("zmodload ");
if(m->nam[0] == '-') if(m->nam[0] == '-')
fputs("-- ", stdout); fputs("-- ", stdout);
@ -1605,7 +1612,7 @@ bin_zmodload_load(char *nam, char **args, char *ops)
} else { } else {
/* load modules */ /* load modules */
for (; *args; args++) for (; *args; args++)
if (!require_module(nam, *args, 1, (!ops['i']))) if (!require_module(nam, *args, 1, (!OPT_ISSET(ops,'i'))))
ret = 1; ret = 1;
return ret; return ret;

View file

@ -481,7 +481,7 @@ setoption(HashNode hn, int value)
/**/ /**/
int int
bin_setopt(char *nam, char **args, char *ops, int isun) bin_setopt(char *nam, char **args, Options ops, int isun)
{ {
int action, optno, match = 0; int action, optno, match = 0;

View file

@ -2396,24 +2396,26 @@ dump_find_func(Wordcode h, char *name)
/**/ /**/
int int
bin_zcompile(char *nam, char **args, char *ops, int func) bin_zcompile(char *nam, char **args, Options ops, int func)
{ {
int map, flags, ret; int map, flags, ret;
char *dump; char *dump;
if ((ops['k'] && ops['z']) || (ops['R'] && ops['M']) || if ((OPT_ISSET(ops,'k') && OPT_ISSET(ops,'z')) ||
(ops['c'] && (ops['U'] || ops['k'] || ops['z'])) || (OPT_ISSET(ops,'R') && OPT_ISSET(ops,'M')) ||
(!(ops['c'] || ops['a']) && ops['m'])) { (OPT_ISSET(ops,'c') &&
(OPT_ISSET(ops,'U') || OPT_ISSET(ops,'k') || OPT_ISSET(ops,'z'))) ||
(!(OPT_ISSET(ops,'c') || OPT_ISSET(ops,'a')) && OPT_ISSET(ops,'m'))) {
zwarnnam(nam, "illegal combination of options", NULL, 0); zwarnnam(nam, "illegal combination of options", NULL, 0);
return 1; return 1;
} }
if ((ops['c'] || ops['a']) && isset(KSHAUTOLOAD)) if ((OPT_ISSET(ops,'c') || OPT_ISSET(ops,'a')) && isset(KSHAUTOLOAD))
zwarnnam(nam, "functions will use zsh style autoloading", NULL, 0); zwarnnam(nam, "functions will use zsh style autoloading", NULL, 0);
flags = (ops['k'] ? FDHF_KSHLOAD : flags = (OPT_ISSET(ops,'k') ? FDHF_KSHLOAD :
(ops['z'] ? FDHF_ZSHLOAD : 0)); (OPT_ISSET(ops,'z') ? FDHF_ZSHLOAD : 0));
if (ops['t']) { if (OPT_ISSET(ops,'t')) {
Wordcode f; Wordcode f;
if (!*args) { if (!*args) {
@ -2443,21 +2445,23 @@ bin_zcompile(char *nam, char **args, char *ops, int func)
zwarnnam(nam, "too few arguments", NULL, 0); zwarnnam(nam, "too few arguments", NULL, 0);
return 1; return 1;
} }
map = (ops['M'] ? 2 : (ops['R'] ? 0 : 1)); map = (OPT_ISSET(ops,'M') ? 2 : (OPT_ISSET(ops,'R') ? 0 : 1));
if (!args[1] && !(ops['c'] || ops['a'])) { if (!args[1] && !(OPT_ISSET(ops,'c') || OPT_ISSET(ops,'a'))) {
queue_signals(); queue_signals();
ret = build_dump(nam, dyncat(*args, FD_EXT), args, ops['U'], map, flags); ret = build_dump(nam, dyncat(*args, FD_EXT), args, OPT_ISSET(ops,'U'),
map, flags);
unqueue_signals(); unqueue_signals();
return ret; return ret;
} }
dump = (strsfx(FD_EXT, *args) ? *args : dyncat(*args, FD_EXT)); dump = (strsfx(FD_EXT, *args) ? *args : dyncat(*args, FD_EXT));
queue_signals(); queue_signals();
ret = ((ops['c'] || ops['a']) ? ret = ((OPT_ISSET(ops,'c') || OPT_ISSET(ops,'a')) ?
build_cur_dump(nam, dump, args + 1, ops['m'], map, build_cur_dump(nam, dump, args + 1, OPT_ISSET(ops,'m'), map,
(ops['c'] ? 1 : 0) | (ops['a'] ? 2 : 0)) : (OPT_ISSET(ops,'c') ? 1 : 0) |
build_dump(nam, dump, args + 1, ops['U'], map, flags)); (OPT_ISSET(ops,'a') ? 2 : 0)) :
build_dump(nam, dump, args + 1, OPT_ISSET(ops,'U'), map, flags));
unqueue_signals(); unqueue_signals();
return ret; return ret;
@ -3217,7 +3221,7 @@ closedumps(void)
/**/ /**/
int int
dump_autoload(char *nam, char *file, int on, char *ops, int func) dump_autoload(char *nam, char *file, int on, Options ops, int func)
{ {
Wordcode h; Wordcode h;
FDHead n, e; FDHead n, e;
@ -3236,7 +3240,7 @@ dump_autoload(char *nam, char *file, int on, char *ops, int func)
shf->flags = on; shf->flags = on;
shf->funcdef = mkautofn(shf); shf->funcdef = mkautofn(shf);
shfunctab->addnode(shfunctab, ztrdup(fdname(n) + fdhtail(n)), shf); shfunctab->addnode(shfunctab, ztrdup(fdname(n) + fdhtail(n)), shf);
if (ops['X'] && eval_autoload(shf, shf->nam, ops, func)) if (OPT_ISSET(ops,'X') && eval_autoload(shf, shf->nam, ops, func))
ret = 1; ret = 1;
} }
return ret; return ret;

View file

@ -559,7 +559,7 @@ dowatch(void)
/**/ /**/
int int
bin_log(char *nam, char **argv, char *ops, int func) bin_log(char *nam, char **argv, Options ops, int func)
{ {
if (!watch) if (!watch)
return 1; return 1;
@ -581,7 +581,7 @@ void dowatch(void)
/**/ /**/
int int
bin_log(char *nam, char **argv, char *ops, int func) bin_log(char *nam, char **argv, Options ops, int func)
{ {
return bin_notavail(nam, argv, ops, func); return bin_notavail(nam, argv, ops, func);
} }

View file

@ -298,6 +298,7 @@ typedef struct cmdnam *Cmdnam;
typedef struct shfunc *Shfunc; typedef struct shfunc *Shfunc;
typedef struct funcstack *Funcstack; typedef struct funcstack *Funcstack;
typedef struct funcwrap *FuncWrap; typedef struct funcwrap *FuncWrap;
typedef struct options *Options;
typedef struct builtin *Builtin; typedef struct builtin *Builtin;
typedef struct nameddir *Nameddir; typedef struct nameddir *Nameddir;
typedef struct module *Module; typedef struct module *Module;
@ -934,7 +935,49 @@ struct funcwrap {
/* node in builtin command hash table (builtintab) */ /* node in builtin command hash table (builtintab) */
typedef int (*HandlerFunc) _((char *, char **, char *, int)); /*
* Handling of options.
*
* Option strings are standard in that a trailing `:' indicates
* a mandatory argument. In addtion, `::' indicates an optional
* argument which must immediately follow the option letter if it is present.
* `:%' indicates an optional numeric argument which may follow
* the option letter or be in the next word; the only test is
* that the next character is a digit, and no actual conversion is done.
*/
#define MAX_OPS 128
/* Macros taking struct option * and char argument */
/* Option was set as -X */
#define OPT_MINUS(ops,c) ((ops)->ind[c] & 1)
/* Option was set as +X */
#define OPT_PLUS(ops,c) ((ops)->ind[c] & 2)
/*
* Option was set any old how, maybe including an argument
* (cheap test when we don't care).
*/
#define OPT_ISSET(ops,c) ((ops)->ind[c])
/* Option has an argument */
#define OPT_HASARG(ops,c) ((ops)->ind[c] > 3)
/* The argument for the option; not safe if it doesn't have one */
#define OPT_ARG(ops,c) ((ops)->args[((ops)->ind[c] >> 2) - 1])
/* Ditto, but safely returns NULL if there is no argument. */
#define OPT_ARG_SAFE(ops,c) (OPT_HASARG(ops,c) ? OPT_ARG(ops,c) : NULL)
struct options {
unsigned char ind[MAX_OPS];
char **args;
int argscount, argsalloc;
};
/*
* Handler arguments are: builtin name, null-terminated argument
* list excluding command name, option structure, the funcid element from the
* builtin structure.
*/
typedef int (*HandlerFunc) _((char *, char **, Options, int));
#define NULLBINCMD ((HandlerFunc) 0) #define NULLBINCMD ((HandlerFunc) 0)
struct builtin { struct builtin {
@ -957,22 +1000,17 @@ struct builtin {
/* builtin flags */ /* builtin flags */
/* DISABLE IS DEFINED AS (1<<0) */ /* DISABLE IS DEFINED AS (1<<0) */
#define BINF_PLUSOPTS (1<<1) /* +xyz legal */ #define BINF_PLUSOPTS (1<<1) /* +xyz legal */
#define BINF_R (1<<2) /* this is the builtin `r' (fc -e -) */ #define BINF_PRINTOPTS (1<<2)
#define BINF_PRINTOPTS (1<<3) #define BINF_ADDED (1<<3) /* is in the builtins hash table */
#define BINF_ADDED (1<<4) /* is in the builtins hash table */ #define BINF_ECHOPTS (1<<4)
#define BINF_FCOPTS (1<<5) #define BINF_MAGICEQUALS (1<<5) /* needs automatic MAGIC_EQUAL_SUBST substitution */
#define BINF_TYPEOPT (1<<6) #define BINF_PREFIX (1<<6)
#define BINF_ECHOPTS (1<<7) #define BINF_DASH (1<<7)
#define BINF_MAGICEQUALS (1<<8) /* needs automatic MAGIC_EQUAL_SUBST substitution */ #define BINF_BUILTIN (1<<8)
#define BINF_PREFIX (1<<9) #define BINF_COMMAND (1<<9)
#define BINF_DASH (1<<10) #define BINF_EXEC (1<<10)
#define BINF_BUILTIN (1<<11) #define BINF_NOGLOB (1<<11)
#define BINF_COMMAND (1<<12) #define BINF_PSPECIAL (1<<12)
#define BINF_EXEC (1<<13)
#define BINF_NOGLOB (1<<14)
#define BINF_PSPECIAL (1<<15)
#define BINF_TYPEOPTS (BINF_TYPEOPT|BINF_PLUSOPTS)
struct module { struct module {
char *nam; char *nam;
@ -1711,7 +1749,7 @@ struct heap {
/* compctl entry point pointers */ /* compctl entry point pointers */
typedef int (*CompctlReadFn) _((char *, char **, char *, char *)); typedef int (*CompctlReadFn) _((char *, char **, Options, char *));
/* ZLE entry point pointers */ /* ZLE entry point pointers */