diff options
Diffstat (limited to 'Src/Modules')
-rw-r--r-- | Src/Modules/cap.c | 37 | ||||
-rw-r--r-- | Src/Modules/clone.c | 2 | ||||
-rw-r--r-- | Src/Modules/datetime.c | 2 | ||||
-rw-r--r-- | Src/Modules/example.c | 174 | ||||
-rw-r--r-- | Src/Modules/files.c | 40 | ||||
-rw-r--r-- | Src/Modules/pcre.c | 16 | ||||
-rw-r--r-- | Src/Modules/socket.c | 12 | ||||
-rw-r--r-- | Src/Modules/stat.c | 56 | ||||
-rw-r--r-- | Src/Modules/tcp.c | 18 | ||||
-rw-r--r-- | Src/Modules/termcap.c | 2 | ||||
-rw-r--r-- | Src/Modules/terminfo.c | 2 | ||||
-rw-r--r-- | Src/Modules/zftp.c | 2 | ||||
-rw-r--r-- | Src/Modules/zprof.c | 4 | ||||
-rw-r--r-- | Src/Modules/zpty.c | 39 | ||||
-rw-r--r-- | Src/Modules/zselect.c | 2 | ||||
-rw-r--r-- | Src/Modules/zutil.c | 10 |
16 files changed, 297 insertions, 121 deletions
diff --git a/Src/Modules/cap.c b/Src/Modules/cap.c index 008b6932d..ba377f876 100644 --- a/Src/Modules/cap.c +++ b/Src/Modules/cap.c @@ -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 !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); + return 0; } -#ifdef MODULE +/**/ +int +boot_(Module m) +{ + return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); +} /**/ 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; +} diff --git a/Src/Modules/clone.c b/Src/Modules/clone.c index 1a41b7448..335f0fc80 100644 --- a/Src/Modules/clone.c +++ b/Src/Modules/clone.c @@ -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; diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c index 4c2bcf791..e43f12b24 100644 --- a/Src/Modules/datetime.c +++ b/Src/Modules/datetime.c @@ -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; diff --git a/Src/Modules/example.c b/Src/Modules/example.c index 45ef3c28f..793d743fc 100644 --- a/Src/Modules/example.c +++ b/Src/Modules/example.c @@ -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), }; +static struct conddef cotab[] = { + CONDDEF("len", 0, cond_p_len, 1, 2, 0), + CONDDEF("ex", CONDF_INFIX, cond_i_ex, 0, 0, 0), +}; + +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 -boot_example(Module m) +setup_(Module m) { - return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); + printf("The example module has now been set up.\n"); + fflush(stdout); + return 0; } -#ifdef MODULE +/**/ +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_example(Module m) +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 diff --git a/Src/Modules/files.c b/Src/Modules/files.c index 6d962efd1..51f362631 100644 --- a/Src/Modules/files.c +++ b/Src/Modules/files.c @@ -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); } diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c index b6304ff01..36c437bc3 100644 --- a/Src/Modules/pcre.c +++ b/Src/Modules/pcre.c @@ -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); diff --git a/Src/Modules/socket.c b/Src/Modules/socket.c index b676e2d36..2b70eba6d 100644 --- a/Src/Modules/socket.c +++ b/Src/Modules/socket.c @@ -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; diff --git a/Src/Modules/stat.c b/Src/Modules/stat.c index 335f7271e..5b5479711 100644 --- a/Src/Modules/stat.c +++ b/Src/Modules/stat.c @@ -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)) diff --git a/Src/Modules/tcp.c b/Src/Modules/tcp.c index 5dc00d0bc..96dde66e3 100644 --- a/Src/Modules/tcp.c +++ b/Src/Modules/tcp.c @@ -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'; diff --git a/Src/Modules/termcap.c b/Src/Modules/termcap.c index 8ec8919d9..177a0d5c7 100644 --- a/Src/Modules/termcap.c +++ b/Src/Modules/termcap.c @@ -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; diff --git a/Src/Modules/terminfo.c b/Src/Modules/terminfo.c index 3f62f0367..732495891 100644 --- a/Src/Modules/terminfo.c +++ b/Src/Modules/terminfo.c @@ -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; diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c index de762e883..918061e42 100644 --- a/Src/Modules/zftp.c +++ b/Src/Modules/zftp.c @@ -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; diff --git a/Src/Modules/zprof.c b/Src/Modules/zprof.c index 9c7acb334..3121efacf 100644 --- a/Src/Modules/zprof.c +++ b/Src/Modules/zprof.c @@ -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; diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c index ad5d2ab39..1be615610 100644 --- a/Src/Modules/zpty.c +++ b/Src/Modules/zpty.c @@ -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) diff --git a/Src/Modules/zselect.c b/Src/Modules/zselect.c index 2eee59d03..25954559b 100644 --- a/Src/Modules/zselect.c +++ b/Src/Modules/zselect.c @@ -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; diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index cb099bbcc..4ef237d90 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -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; |