1
0
mirror of https://github.com/zsh-users/zsh synced 2024-07-08 19:55:44 +00:00

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>
* 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
# `=' signs.
VERSION=4.1.0-dev-5
VERSION_DATE='June 17, 2002'
VERSION=4.1.0-dev-6
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
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.
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))(
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.
)
item(tt(-u)var(n))(
Input is read from file descriptor var(n), where var(n) is a single
digit and must em(not) be separated from tt(-u) by any whitespace.
Input is read from file descriptor var(n).
)
item(tt(-p))(
Input is read from the coprocess.

View File

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

View File

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

View File

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

View File

@ -41,7 +41,7 @@
/**/
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;

View File

@ -32,7 +32,7 @@
#include <time.h>
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;
char *endptr = NULL, *buffer = NULL;

View File

@ -30,47 +30,203 @@
#include "example.mdh"
#include "example.pro"
/* parameters */
static zlong intparam;
static char *strparam;
static char **arrparam;
/**/
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;
char **oargs = args, **p = arrparam;
long i = 0;
printf("Options: ");
for (c = 32; ++c < 128;)
if (ops[c])
if (OPT_ISSET(ops,c))
putchar(c);
printf("\nArguments:");
for (; *args; args++) {
for (; *args; i++, args++) {
putchar(' ');
fputs(*args, stdout);
}
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;
}
/**/
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[] = {
BUILTIN("example", 0, bin_example, 0, -1, 0, "flags", NULL),
};
/**/
int
boot_example(Module m)
{
return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab));
}
static struct conddef cotab[] = {
CONDDEF("len", 0, cond_p_len, 1, 2, 0),
CONDDEF("ex", CONDF_INFIX, cond_i_ex, 0, 0, 0),
};
#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
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;
}
#endif

View File

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

View File

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

View File

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

View File

@ -341,7 +341,7 @@ statprint(struct stat *sbuf, char *outbuf, char *fname, int iwhich, int flags)
*/
/**/
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 *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 (iwhich == ST_READLINK)
ops['L'] = 1;
ops->ind['L'] = 1;
flags |= STF_PICK;
} else {
for (; *arg; arg++) {
if (strchr("glLnNorstT", *arg))
ops[STOUC(*arg)] = 1;
ops->ind[STOUC(*arg)] = 1;
else if (*arg == 'A') {
if (arg[1]) {
arrnam = arg+1;
@ -404,7 +404,7 @@ bin_stat(char *name, char **args, char *ops, int func)
break;
} else if (*arg == 'f') {
char *sfd;
ops['f'] = 1;
ops->ind['f'] = 1;
if (arg[1]) {
sfd = arg+1;
} else if (!(sfd = *++args)) {
@ -425,7 +425,7 @@ bin_stat(char *name, char **args, char *ops, int func)
return 1;
}
/* force string format in order to use time format */
ops['s'] = 1;
ops->ind['s'] = 1;
break;
} else {
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 */
}
if (ops['l']) {
if (OPT_ISSET(ops,'l')) {
/* list types and return: can also list to array */
if (arrnam) {
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;
}
if (!*args && !ops['f']) {
if (!*args && !OPT_ISSET(ops,'f')) {
zwarnnam(name, "no files given", NULL, 0);
return 1;
} else if (*args && ops['f']) {
} else if (*args && OPT_ISSET(ops,'f')) {
zwarnnam(name, "no files allowed with -f", NULL, 0);
return 1;
}
nargs = 0;
if (ops['f'])
if (OPT_ISSET(ops,'f'))
nargs = 1;
else
for (aptr = args; *aptr; aptr++)
nargs++;
if (ops['g']) {
if (OPT_ISSET(ops,'g')) {
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;
if (ops['r'] || !ops['s'])
if (OPT_ISSET(ops,'r') || !OPT_ISSET(ops,'s'))
flags |= STF_RAW;
if (ops['n'])
if (OPT_ISSET(ops,'n'))
flags |= STF_FILE;
if (ops['o'])
if (OPT_ISSET(ops,'o'))
flags |= STF_OCTAL;
if (ops['t'])
if (OPT_ISSET(ops,'t'))
flags |= STF_NAME;
if (!(arrnam || hashnam)) {
@ -505,9 +505,9 @@ bin_stat(char *name, char **args, char *ops, int func)
flags |= STF_NAME;
}
if (ops['N'] || ops['f'])
if (OPT_ISSET(ops,'N') || OPT_ISSET(ops,'f'))
flags &= ~STF_FILE;
if (ops['T'] || ops['H'])
if (OPT_ISSET(ops,'T') || OPT_ISSET(ops,'H'))
flags &= ~STF_NAME;
if (hashnam) {
@ -529,16 +529,18 @@ bin_stat(char *name, char **args, char *ops, int func)
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 */
int rval = ops['f'] ? fstat(fd, &statbuf) :
ops['L'] ? lstat(*args, &statbuf) : stat(*args, &statbuf);
int rval = OPT_ISSET(ops,'f') ? fstat(fd, &statbuf) :
OPT_ISSET(ops,'L') ? lstat(*args, &statbuf) :
stat(*args, &statbuf);
if (rval) {
if (ops['f'])
if (OPT_ISSET(ops,'f'))
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;
if (ops['f'] || arrnam)
if (OPT_ISSET(ops,'f') || arrnam)
break;
else
continue;
@ -558,7 +560,7 @@ bin_stat(char *name, char **args, char *ops, int func)
if (arrnam)
*arrptr++ = ztrdup(outbuf);
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(outbuf);
} else
@ -570,14 +572,14 @@ bin_stat(char *name, char **args, char *ops, int func)
if (arrnam)
*arrptr++= ztrdup(outbuf);
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(outbuf);
} else
printf("%s\n", outbuf);
}
}
if (ops['f'])
if (OPT_ISSET(ops,'f'))
break;
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
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;
SOCKLEN_T len;
@ -345,16 +345,16 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
struct servent *srv;
Tcp_session sess = NULL;
if (ops['f'])
if (OPT_ISSET(ops,'f'))
force = 1;
if (ops['v'])
if (OPT_ISSET(ops,'v'))
verbose = 1;
if (ops['t'])
if (OPT_ISSET(ops,'t'))
test = 1;
if (ops['d']) {
if (OPT_ISSET(ops,'d')) {
targetfd = atoi(args[0]);
dargs = args + 1;
if (!targetfd) {
@ -366,7 +366,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
dargs = args;
if (ops['c']) {
if (OPT_ISSET(ops,'c')) {
if (!dargs[0]) {
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;
if (!dargs[0]) {
@ -462,7 +462,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
return 0;
}
else if (ops['a'])
else if (OPT_ISSET(ops,'a'))
{
int lfd, rfd;
@ -571,7 +571,7 @@ bin_ztcp(char *nam, char **args, char *ops, int func)
remotename = ztpeer->h_name;
else
remotename = ztrdup(inet_ntoa(sess->peer.in.sin_addr));
if (ops['L']) {
if (OPT_ISSET(ops,'L')) {
int schar;
if (sess->flags & ZTCP_ZFTP)
schar = 'Z';

View File

@ -103,7 +103,7 @@ ztgetflag(char *s)
/**/
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;
int num, argct;

View File

@ -57,7 +57,7 @@ static Param terminfo_pm;
/**/
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;
int num;

View File

@ -2951,7 +2951,7 @@ zftp_rmsession(char *name, char **args, int flags)
/**/
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 *cnam = *args++, *prefs, *ptr;

View File

@ -136,9 +136,9 @@ cmpparcs(Parc *a, Parc *b)
}
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);
calls = NULL;
ncalls = 0;

View File

@ -603,20 +603,23 @@ ptywrite(Ptycmd cmd, char **args, int nonl)
/**/
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']) ||
((ops['r'] || ops['w']) && (ops['d'] || ops['e'] ||
ops['b'] || ops['L'])) ||
(ops['w'] && ops['t']) ||
(ops['n'] && (ops['b'] || ops['e'] || ops['r'] || ops['t'] ||
ops['d'] || ops['L'])) ||
(ops['d'] && (ops['b'] || ops['e'] || ops['L'] || ops['t'])) ||
(ops['L'] && (ops['b'] || ops['e']))) {
if ((OPT_ISSET(ops,'r') && OPT_ISSET(ops,'w')) ||
((OPT_ISSET(ops,'r') || OPT_ISSET(ops,'w')) &&
(OPT_ISSET(ops,'d') || OPT_ISSET(ops,'e') ||
OPT_ISSET(ops,'b') || OPT_ISSET(ops,'L'))) ||
(OPT_ISSET(ops,'w') && OPT_ISSET(ops,'t')) ||
(OPT_ISSET(ops,'n') && (OPT_ISSET(ops,'b') || OPT_ISSET(ops,'e') ||
OPT_ISSET(ops,'r') || OPT_ISSET(ops,'t') ||
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);
return 1;
}
if (ops['r'] || ops['w']) {
if (OPT_ISSET(ops,'r') || OPT_ISSET(ops,'w')) {
Ptycmd p;
if (!*args) {
@ -628,13 +631,14 @@ bin_zpty(char *nam, char **args, char *ops, int func)
}
if (p->fin)
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 (ops['r'] ?
return (OPT_ISSET(ops,'r') ?
ptyread(nam, p, args + 1) :
ptywrite(p, args + 1, ops['n']));
} else if (ops['d']) {
ptywrite(p, args + 1, OPT_ISSET(ops,'n')));
} else if (OPT_ISSET(ops,'d')) {
Ptycmd p;
int ret = 0;
@ -650,7 +654,7 @@ bin_zpty(char *nam, char **args, char *ops, int func)
deleteallptycmds();
return ret;
} else if (ops['t']) {
} else if (OPT_ISSET(ops,'t')) {
Ptycmd p;
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);
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 {
Ptycmd p;
char **a;
for (p = ptycmds; p; p = p->next) {
checkptycmd(p);
if (ops['L'])
if (OPT_ISSET(ops,'L'))
printf("%s %s%s%s ", nam, (p->echo ? "-e " : ""),
(p->nblock ? "-b " : ""), p->name);
else if (p->fin)

View File

@ -62,7 +62,7 @@ handle_digits(char *nam, char *argptr, fd_set *fdset, int *fdmax)
/**/
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
int i, fd, fdsetind = 0, fdmax = 0, fdcount;

View File

@ -254,7 +254,7 @@ lookupstyle(char *ctxt, char *style)
}
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;
@ -550,7 +550,7 @@ bin_zstyle(char *nam, char **args, char *ops, int func)
/* Format stuff. */
static int
bin_zformat(char *nam, char **args, char *ops, int func)
bin_zformat(char *nam, char **args, Options ops, int func)
{
char opt;
@ -1161,7 +1161,7 @@ rmatch(RParseResult *sm, char *subj, char *var1, char *var2, int comp)
*/
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];
char *var1 = args[0];
@ -1187,7 +1187,7 @@ bin_zregexparse(char *nam, char **args, char *ops, int func)
ret = 0;
if (!ret)
ret = rmatch(&result, subj, var1, var2, ops['c']);
ret = rmatch(&result, subj, var1, var2, OPT_ISSET(ops,'c'));
popheap();
opts[EXTENDEDGLOB] = oldextendedglob;
@ -1315,7 +1315,7 @@ add_opt_val(Zoptdesc d, char *arg)
}
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;
int del = 0, f, extract = 0, keep = 0;

View File

@ -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));
}
/*

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -1175,7 +1175,7 @@ mod_export CompctlReadFn compctlreadptr = fallback_compctlread;
/**/
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",
NULL, 0);

View File

@ -1252,11 +1252,11 @@ init_hackzero(char **argv, char **envp)
/**/
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;
if (ops['Z']) {
if (OPT_ISSET(ops,'Z')) {
int len;
if(isset(RESTRICTED)) {
@ -1277,8 +1277,8 @@ bin_fg(char *name, char **argv, char *ops, int func)
return 0;
}
lng = (ops['l']) ? 1 : (ops['p']) ? 2 : 0;
if (ops['d'])
lng = (OPT_ISSET(ops,'l')) ? 1 : (OPT_ISSET(ops,'p')) ? 2 : 0;
if (OPT_ISSET(ops,'d'))
lng |= 4;
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++)
if (job != ignorejob && jobptr->stat) {
if ((!ops['r'] && !ops['s']) ||
(ops['r'] && ops['s']) ||
(ops['r'] && !(jobptr->stat & STAT_STOPPED)) ||
(ops['s'] && jobptr->stat & STAT_STOPPED))
if ((!OPT_ISSET(ops,'r') && !OPT_ISSET(ops,'s')) ||
(OPT_ISSET(ops,'r') && OPT_ISSET(ops,'s')) ||
(OPT_ISSET(ops,'r') &&
!(jobptr->stat & STAT_STOPPED)) ||
(OPT_ISSET(ops,'s') && jobptr->stat & STAT_STOPPED))
printjob(jobptr, lng, 2);
}
unqueue_signals();
@ -1498,7 +1499,7 @@ bin_fg(char *name, char **argv, char *ops, int func)
/**/
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 returnval = 0;
@ -1642,10 +1643,10 @@ bin_kill(char *nam, char **argv, char *ops, int func)
/**/
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 */
if (islogin && !ops['f']) {
if (islogin && !OPT_ISSET(ops,'f')) {
zwarnnam(name, "can't suspend login shell", NULL, 0);
return 1;
}

View File

@ -1238,7 +1238,7 @@ calloc(MALLOC_ARG_T n, MALLOC_ARG_T size)
/**/
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;
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;
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 difference between them, i.e. the size of the heap.\n\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)));
if (ops['v']) {
if (OPT_ISSET(ops,'v')) {
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("via brk().\n");
}
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("For each size that were used the number of mallocs and\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])
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("information is shown:\n\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;
}
if (ops['v']) {
if (OPT_ISSET(ops,'v')) {
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("number of used blocks are shown.\n");
@ -1353,7 +1353,7 @@ bin_mem(char *name, char **argv, char *ops, int func)
}
putchar('\n');
}
if (ops['v']) {
if (OPT_ISSET(ops,'v')) {
printf("\n\nBelow is some information about the allocation\n");
printf("behaviour of the zsh heaps. First the number of times\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);
if (ops['v']) {
if (OPT_ISSET(ops,'v')) {
printf("\nThe next list shows for several sizes the number of times\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
printmodalias(Module m, char *ops)
printmodalias(Module m, Options ops)
{
if (ops['L']) {
if (OPT_ISSET(ops,'L')) {
printf("zmodload -A ");
if (m->nam[0] == '-')
fputs("-- ", stdout);
@ -956,10 +956,11 @@ autoloadscan(HashNode hn, int printflags)
/**/
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_au = ops['a'] || ops['u'];
int ops_bcpf = OPT_ISSET(ops,'b') || OPT_ISSET(ops,'c') ||
OPT_ISSET(ops,'p') || OPT_ISSET(ops,'f');
int ops_au = OPT_ISSET(ops,'a') || OPT_ISSET(ops,'u');
int ret = 1;
if (ops_bcpf && !ops_au) {
@ -967,41 +968,45 @@ bin_zmodload(char *nam, char **args, char *ops, int func)
NULL, 0);
return 1;
}
if (ops['A'] || ops['R']) {
if (ops_bcpf || ops_au || ops['d'] || (ops['R'] && ops['e'])) {
if (OPT_ISSET(ops,'A') || OPT_ISSET(ops,'R')) {
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);
return 1;
}
if (!ops['e'])
if (!OPT_ISSET(ops,'e'))
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);
return 1;
}
if (ops['u'] && !*args) {
if (OPT_ISSET(ops,'u') && !*args) {
zwarnnam(nam, "what do you want to unload?", NULL, 0);
return 1;
}
if (ops['e'] && (ops['I'] || ops['L'] || ops['a'] || ops['d'] ||
ops['i'] || ops['u'])) {
if (OPT_ISSET(ops,'e') && (OPT_ISSET(ops,'I') || OPT_ISSET(ops,'L') ||
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);
return 1;
}
queue_signals();
if (ops['e'])
if (OPT_ISSET(ops,'e'))
ret = bin_zmodload_exist(nam, args, ops);
else if (ops['d'])
else if (OPT_ISSET(ops,'d'))
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);
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);
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);
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);
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);
else
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
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
@ -1032,7 +1037,7 @@ bin_zmodload_alias(char *nam, char **args, char *ops)
int ret = 0;
if (!*args) {
if (ops['R']) {
if (OPT_ISSET(ops,'R')) {
zwarnnam(nam, "no module alias to remove", NULL, 0);
return 1;
}
@ -1053,7 +1058,7 @@ bin_zmodload_alias(char *nam, char **args, char *ops)
zwarnnam(nam, "invalid module name `%s'", *args, 0);
return 1;
}
if (ops['R']) {
if (OPT_ISSET(ops,'R')) {
if (aliasname) {
zwarnnam(nam, "bad syntax for removing module alias: %s",
*args, 0);
@ -1123,7 +1128,7 @@ bin_zmodload_alias(char *nam, char **args, char *ops)
/**/
static int
bin_zmodload_exist(char *nam, char **args, char *ops)
bin_zmodload_exist(char *nam, char **args, Options ops)
{
LinkNode node;
Module m;
@ -1135,7 +1140,8 @@ bin_zmodload_exist(char *nam, char **args, char *ops)
modname = m->nam;
if (m->flags & MOD_ALIAS) {
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);
else
continue;
@ -1161,11 +1167,11 @@ bin_zmodload_exist(char *nam, char **args, char *ops)
/**/
static int
bin_zmodload_dep(char *nam, char **args, char *ops)
bin_zmodload_dep(char *nam, char **args, Options ops)
{
LinkNode node;
Module m;
if (ops['u']) {
if (OPT_ISSET(ops,'u')) {
/* remove dependencies, which can't pertain to aliases */
const char *tnam = *args++;
node = find_module(tnam, 1, &tnam);
@ -1201,7 +1207,7 @@ bin_zmodload_dep(char *nam, char **args, char *ops)
m = (Module) getdata(node);
if (m->deps && (!args[0] || !strcmp(args[0], m->nam))) {
LinkNode n;
if (ops['L']) {
if (OPT_ISSET(ops,'L')) {
printf("zmodload -d ");
if(m->nam[0] == '-')
fputs("-- ", stdout);
@ -1212,7 +1218,7 @@ bin_zmodload_dep(char *nam, char **args, char *ops)
}
for (n = firstnode(m->deps); n; incnode(n)) {
putchar(' ');
if(ops['L'])
if(OPT_ISSET(ops,'L'))
quotedzputs((char *) getdata(n), stdout);
else
nicezputs((char *) getdata(n), stdout);
@ -1234,15 +1240,15 @@ bin_zmodload_dep(char *nam, char **args, char *ops)
/**/
static int
bin_zmodload_auto(char *nam, char **args, char *ops)
bin_zmodload_auto(char *nam, char **args, Options ops)
{
int ret = 0;
if(ops['u']) {
if(OPT_ISSET(ops,'u')) {
/* remove autoloaded builtins */
for (; *args; args++) {
Builtin bn = (Builtin) builtintab->getnode2(builtintab, *args);
if (!bn) {
if(!ops['i']) {
if(!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such builtin", *args, 0);
ret = 1;
}
@ -1256,7 +1262,7 @@ bin_zmodload_auto(char *nam, char **args, char *ops)
} else if(!*args) {
/* list autoloaded builtins */
scanhashtable(builtintab, 0, 0, 0,
autoloadscan, ops['L'] ? PRINT_LIST : 0);
autoloadscan, OPT_ISSET(ops,'L') ? PRINT_LIST : 0);
return 0;
} else {
/* add autoloaded builtins */
@ -1267,7 +1273,7 @@ bin_zmodload_auto(char *nam, char **args, char *ops)
if (strchr(bnam, '/')) {
zwarnnam(nam, "%s: `/' is illegal in a builtin", bnam, 0);
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);
ret = 1;
}
@ -1278,17 +1284,17 @@ bin_zmodload_auto(char *nam, char **args, char *ops)
/**/
static int
bin_zmodload_cond(char *nam, char **args, char *ops)
bin_zmodload_cond(char *nam, char **args, Options ops)
{
int ret = 0;
if (ops['u']) {
if (OPT_ISSET(ops,'u')) {
/* remove autoloaded conditions */
for (; *args; args++) {
Conddef cd = getconddef(ops['I'], *args, 0);
Conddef cd = getconddef(OPT_ISSET(ops,'I'), *args, 0);
if (!cd) {
if (!ops['i']) {
if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such condition", *args, 0);
ret = 1;
}
@ -1305,7 +1311,7 @@ bin_zmodload_cond(char *nam, char **args, char *ops)
for (p = condtab; p; p = p->next) {
if (p->module) {
if (ops['L']) {
if (OPT_ISSET(ops,'L')) {
fputs("zmodload -ac", stdout);
if (p->flags & CONDF_INFIX)
putchar('I');
@ -1330,7 +1336,8 @@ bin_zmodload_cond(char *nam, char **args, char *ops)
if (strchr(cnam, '/')) {
zwarnnam(nam, "%s: `/' is illegal in a condition", cnam, 0);
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);
ret = 1;
}
@ -1341,17 +1348,17 @@ bin_zmodload_cond(char *nam, char **args, char *ops)
/**/
static int
bin_zmodload_math(char *nam, char **args, char *ops)
bin_zmodload_math(char *nam, char **args, Options ops)
{
int ret = 0;
if (ops['u']) {
if (OPT_ISSET(ops,'u')) {
/* remove autoloaded math functions */
for (; *args; args++) {
MathFunc f = getmathfunc(*args, 0);
if (!f) {
if (!ops['i']) {
if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such math function", *args, 0);
ret = 1;
}
@ -1368,7 +1375,7 @@ bin_zmodload_math(char *nam, char **args, char *ops)
for (p = mathfuncs; p; p = p->next) {
if (p->module) {
if (ops['L']) {
if (OPT_ISSET(ops,'L')) {
fputs("zmodload -af", stdout);
printf(" %s %s\n", p->module, p->name);
} else
@ -1387,7 +1394,7 @@ bin_zmodload_math(char *nam, char **args, char *ops)
zwarnnam(nam, "%s: `/' is illegal in a math function",
fnam, 0);
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);
ret = 1;
}
@ -1411,17 +1418,17 @@ printautoparams(HashNode hn, int lon)
/**/
static int
bin_zmodload_param(char *nam, char **args, char *ops)
bin_zmodload_param(char *nam, char **args, Options ops)
{
int ret = 0;
if (ops['u']) {
if (OPT_ISSET(ops,'u')) {
/* remove autoloaded parameters */
for (; *args; args++) {
Param pm = (Param) gethashnode2(paramtab, *args);
if (!pm) {
if (!ops['i']) {
if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "%s: no such parameter", *args, 0);
ret = 1;
}
@ -1433,7 +1440,7 @@ bin_zmodload_param(char *nam, char **args, char *ops)
}
return ret;
} else if (!*args) {
scanhashtable(paramtab, 1, 0, 0, printautoparams, ops['L']);
scanhashtable(paramtab, 1, 0, 0, printautoparams, OPT_ISSET(ops,'L'));
return 0;
} else {
/* add autoloaded parameters */
@ -1544,12 +1551,12 @@ unload_module(Module m, LinkNode node)
/**/
static int
bin_zmodload_load(char *nam, char **args, char *ops)
bin_zmodload_load(char *nam, char **args, Options ops)
{
LinkNode node;
Module m;
int ret = 0;
if(ops['u']) {
if(OPT_ISSET(ops,'u')) {
/* unload modules */
const char *mname = *args;
for(; *args; args++) {
@ -1579,7 +1586,7 @@ bin_zmodload_load(char *nam, char **args, char *ops)
ret = 1;
if (del)
m->wrapper--;
} else if (!ops['i']) {
} else if (!OPT_ISSET(ops,'i')) {
zwarnnam(nam, "no such module %s", *args, 0);
ret = 1;
}
@ -1591,7 +1598,7 @@ bin_zmodload_load(char *nam, char **args, char *ops)
for (node = firstnode(modules); node; incnode(node)) {
m = (Module) getdata(node);
if (m->u.handle && !(m->flags & (MOD_UNLOAD|MOD_ALIAS))) {
if(ops['L']) {
if(OPT_ISSET(ops,'L')) {
printf("zmodload ");
if(m->nam[0] == '-')
fputs("-- ", stdout);
@ -1605,7 +1612,7 @@ bin_zmodload_load(char *nam, char **args, char *ops)
} else {
/* load modules */
for (; *args; args++)
if (!require_module(nam, *args, 1, (!ops['i'])))
if (!require_module(nam, *args, 1, (!OPT_ISSET(ops,'i'))))
ret = 1;
return ret;

View File

@ -481,7 +481,7 @@ setoption(HashNode hn, int value)
/**/
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;

View File

@ -2396,24 +2396,26 @@ dump_find_func(Wordcode h, char *name)
/**/
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;
char *dump;
if ((ops['k'] && ops['z']) || (ops['R'] && ops['M']) ||
(ops['c'] && (ops['U'] || ops['k'] || ops['z'])) ||
(!(ops['c'] || ops['a']) && ops['m'])) {
if ((OPT_ISSET(ops,'k') && OPT_ISSET(ops,'z')) ||
(OPT_ISSET(ops,'R') && OPT_ISSET(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);
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);
flags = (ops['k'] ? FDHF_KSHLOAD :
(ops['z'] ? FDHF_ZSHLOAD : 0));
flags = (OPT_ISSET(ops,'k') ? FDHF_KSHLOAD :
(OPT_ISSET(ops,'z') ? FDHF_ZSHLOAD : 0));
if (ops['t']) {
if (OPT_ISSET(ops,'t')) {
Wordcode f;
if (!*args) {
@ -2443,21 +2445,23 @@ bin_zcompile(char *nam, char **args, char *ops, int func)
zwarnnam(nam, "too few arguments", NULL, 0);
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();
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();
return ret;
}
dump = (strsfx(FD_EXT, *args) ? *args : dyncat(*args, FD_EXT));
queue_signals();
ret = ((ops['c'] || ops['a']) ?
build_cur_dump(nam, dump, args + 1, ops['m'], map,
(ops['c'] ? 1 : 0) | (ops['a'] ? 2 : 0)) :
build_dump(nam, dump, args + 1, ops['U'], map, flags));
ret = ((OPT_ISSET(ops,'c') || OPT_ISSET(ops,'a')) ?
build_cur_dump(nam, dump, args + 1, OPT_ISSET(ops,'m'), map,
(OPT_ISSET(ops,'c') ? 1 : 0) |
(OPT_ISSET(ops,'a') ? 2 : 0)) :
build_dump(nam, dump, args + 1, OPT_ISSET(ops,'U'), map, flags));
unqueue_signals();
return ret;
@ -3217,7 +3221,7 @@ closedumps(void)
/**/
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;
FDHead n, e;
@ -3236,7 +3240,7 @@ dump_autoload(char *nam, char *file, int on, char *ops, int func)
shf->flags = on;
shf->funcdef = mkautofn(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;
}
return ret;

View File

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

View File

@ -298,6 +298,7 @@ typedef struct cmdnam *Cmdnam;
typedef struct shfunc *Shfunc;
typedef struct funcstack *Funcstack;
typedef struct funcwrap *FuncWrap;
typedef struct options *Options;
typedef struct builtin *Builtin;
typedef struct nameddir *Nameddir;
typedef struct module *Module;
@ -934,7 +935,49 @@ struct funcwrap {
/* 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)
struct builtin {
@ -957,22 +1000,17 @@ struct builtin {
/* builtin flags */
/* DISABLE IS DEFINED AS (1<<0) */
#define BINF_PLUSOPTS (1<<1) /* +xyz legal */
#define BINF_R (1<<2) /* this is the builtin `r' (fc -e -) */
#define BINF_PRINTOPTS (1<<3)
#define BINF_ADDED (1<<4) /* is in the builtins hash table */
#define BINF_FCOPTS (1<<5)
#define BINF_TYPEOPT (1<<6)
#define BINF_ECHOPTS (1<<7)
#define BINF_MAGICEQUALS (1<<8) /* needs automatic MAGIC_EQUAL_SUBST substitution */
#define BINF_PREFIX (1<<9)
#define BINF_DASH (1<<10)
#define BINF_BUILTIN (1<<11)
#define BINF_COMMAND (1<<12)
#define BINF_EXEC (1<<13)
#define BINF_NOGLOB (1<<14)
#define BINF_PSPECIAL (1<<15)
#define BINF_TYPEOPTS (BINF_TYPEOPT|BINF_PLUSOPTS)
#define BINF_PRINTOPTS (1<<2)
#define BINF_ADDED (1<<3) /* is in the builtins hash table */
#define BINF_ECHOPTS (1<<4)
#define BINF_MAGICEQUALS (1<<5) /* needs automatic MAGIC_EQUAL_SUBST substitution */
#define BINF_PREFIX (1<<6)
#define BINF_DASH (1<<7)
#define BINF_BUILTIN (1<<8)
#define BINF_COMMAND (1<<9)
#define BINF_EXEC (1<<10)
#define BINF_NOGLOB (1<<11)
#define BINF_PSPECIAL (1<<12)
struct module {
char *nam;
@ -1711,7 +1749,7 @@ struct heap {
/* compctl entry point pointers */
typedef int (*CompctlReadFn) _((char *, char **, char *, char *));
typedef int (*CompctlReadFn) _((char *, char **, Options, char *));
/* ZLE entry point pointers */