aboutsummaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Builtins/rlimits.c17
-rw-r--r--Src/Makefile.in8
-rw-r--r--Src/Modules/zftp.c11
-rw-r--r--Src/Zle/zle_misc.c5
-rw-r--r--Src/Zle/zle_tricky.c91
-rw-r--r--Src/builtin.c63
-rw-r--r--Src/cond.c91
-rw-r--r--Src/exec.c396
-rw-r--r--Src/glob.c24
-rw-r--r--Src/hashtable.c4
-rw-r--r--Src/hist.c110
-rw-r--r--Src/init.c31
-rw-r--r--Src/jobs.c35
-rw-r--r--Src/lex.c76
-rw-r--r--Src/linklist.c4
-rw-r--r--Src/loop.c64
-rw-r--r--Src/math.c14
-rw-r--r--Src/mem.c55
-rw-r--r--Src/params.c21
-rw-r--r--Src/parse.c56
-rw-r--r--Src/signals.c2
-rw-r--r--Src/subst.c4
-rw-r--r--Src/text.c36
-rw-r--r--Src/utils.c641
-rw-r--r--Src/zsh.export3
-rw-r--r--Src/zsh.h14
-rw-r--r--Src/zsh.mdd11
27 files changed, 966 insertions, 921 deletions
diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c
index f8167a106..505b024e4 100644
--- a/Src/Builtins/rlimits.c
+++ b/Src/Builtins/rlimits.c
@@ -222,8 +222,21 @@ printulimit(int lim, int hard, int head)
/* display the limit */
if (limit == RLIM_INFINITY)
printf("unlimited\n");
- else
- printf("%ld\n", (long)limit);
+ else {
+# ifdef RLIM_T_IS_QUAD_T
+ printf("%qd\n", limit);
+# else
+# ifdef RLIM_T_IS_LONG_LONG
+ printf("%lld\n", limit);
+# else
+# ifdef RLIM_T_IS_UNSIGNED
+ printf("%lu\n", limit);
+# else
+ printf("%ld\n", limit);
+# endif /* RLIM_T_IS_UNSIGNED */
+# endif /* RLIM_T_IS_LONG_LONG */
+# endif /* RLIM_T_IS_QUAD_T */
+ }
}
/* limit: set or show resource limits. The variable hard indicates *
diff --git a/Src/Makefile.in b/Src/Makefile.in
index dd96aaf90..e98a696e4 100644
--- a/Src/Makefile.in
+++ b/Src/Makefile.in
@@ -205,8 +205,12 @@ clean: clean-modules
distclean: distclean-modules
realclean: realclean-modules
-mostlyclean-modules clean-modules distclean-modules realclean-modules: Makemod
- @$(MAKE) -f Makemod $(MAKEDEFS) `echo $@ | sed 's/-modules//'`
+# Don't remake Makemod just to delete things, even if it doesn't exist.
+mostlyclean-modules clean-modules distclean-modules realclean-modules:
+ if test -f Makemod; then \
+ @$(MAKE) -f Makemod $(MAKEDEFS) `echo $@ | sed 's/-modules//'`; \
+ fi; \
+ exit 0
@CLEAN_MK@
diff --git a/Src/Modules/zftp.c b/Src/Modules/zftp.c
index 873617e95..63bca854c 100644
--- a/Src/Modules/zftp.c
+++ b/Src/Modules/zftp.c
@@ -230,7 +230,7 @@ static char *lastmsg, lastcodestr[4];
static int lastcode;
/* flag for remote system is UNIX --- useful to know as things are simpler */
-static int zfis_unix, zfpassive_conn;
+static int zfpassive_conn;
/* remote system has size, mdtm commands */
enum {
@@ -1786,7 +1786,6 @@ zftp_open(char *name, char **args, int flags)
return 1;
}
- zfis_unix = 0;
zfhas_size = zfhas_mdtm = ZFCP_UNKN;
zdfd = -1;
/* initial status: open, ASCII data, stream mode 'n' stuff */
@@ -2039,14 +2038,12 @@ zftp_login(char *name, char **args, int flags)
/*
* Use binary for transfers. This simple test saves much
* hassle for all concerned, particularly me.
+ *
+ * We could set this based just on the UNIX part,
+ * but I don't really know the consequences of that.
*/
zfstatus |= ZFST_IMAG;
- zfis_unix = 1;
}
- /*
- * we could set zfis_unix based just on the UNIX part,
- * but I don't really know the consequences of that.
- */
zfsetparam("ZFTP_SYSTEM", systype, ZFPM_READONLY);
}
zfstatus |= ZFST_SYST;
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index c12c5894b..e2ccfbc46 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -788,9 +788,8 @@ static char *suffixfunc;
void
makesuffix(int n)
{
- suffixlen[256] = suffixlen[' '] = suffixlen['\t'] = suffixlen['\n'] =
- suffixlen[';'] = suffixlen['|'] = suffixlen['&'] =
- suffixlen['<'] = suffixlen['>'] = n;
+ suffixlen[256] = suffixlen[' '] = suffixlen['\t'] = suffixlen['\n'] =
+ suffixlen[';'] = suffixlen['&'] = suffixlen['|'] = n;
}
/* Set up suffix for parameter names: the last n characters are a suffix *
diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c
index 281fe211d..8c2ae7bb6 100644
--- a/Src/Zle/zle_tricky.c
+++ b/Src/Zle/zle_tricky.c
@@ -681,12 +681,11 @@ cmphaswilds(char *str)
/* Check if we have to complete a parameter name. */
static char *
-check_param(char *s, int set, char **ep)
+check_param(char *s, int set, int test)
{
char *p;
- int bq = 0, eq = 0, i;
- if (!ep)
+ if (!test)
ispar = parq = eparq = 0;
/* Try to find a `$'. */
for (p = s + offs; p > s && *p != String && *p != Qstring; p--);
@@ -726,9 +725,9 @@ check_param(char *s, int set, char **ep)
e = b;
if (br) {
- while (*e == (ep ? Dnull : '"'))
- e++, parq++, bq++;
- if (!ep)
+ while (*e == (test ? Dnull : '"'))
+ e++, parq++;
+ if (!test)
b = e;
}
/* Find the end of the name. */
@@ -749,14 +748,12 @@ check_param(char *s, int set, char **ep)
if (offs <= e - s && offs >= b - s && n <= 0) {
if (br) {
p = e;
- while (*p == (ep ? Dnull : '"'))
- p++, parq--, eparq++, eq++;
+ while (*p == (test ? Dnull : '"'))
+ p++, parq--, eparq++;
}
/* It is. */
- if (ep) {
- *ep = e;
+ if (test)
return b;
- }
/* If we were called from makecomplistflags(), we have to set the
* global variables. */
@@ -765,21 +762,12 @@ check_param(char *s, int set, char **ep)
mflags |= CMF_PARBR;
/* Get the prefix (anything up to the character before the name). */
- for (i = eq, p = e; i; i--, p++)
- *p = '.';
- isuf = quotename(e, NULL);
- for (i = eq, p = isuf; i; i--, p++)
- *p = '"';
+ isuf = dupstring(e);
+ untokenize(isuf);
*e = '\0';
ripre = dupstring(s);
ripre[b - s] = '\0';
- for (i = bq, p = ripre + (b - s) - 1; i; i--, p--)
- *p = '.';
- ipre = quotename(ripre, NULL);
- for (i = bq, p = ripre + strlen(ripre) - 1; i; i--, p--)
- *p = '"';
- for (i = bq, p = ipre + strlen(ipre) - 1; i; i--, p--)
- *p = '"';
+ ipre = dupstring(ripre);
untokenize(ipre);
}
else
@@ -1231,8 +1219,7 @@ get_comp_string(void)
clwpos = -1;
lexsave();
inpush(dupstrspace((char *) linptr), 0, NULL);
- strinbeg();
- stophist = 2;
+ strinbeg(0);
i = tt0 = cp = rd = ins = oins = linarr = parct = ia = 0;
/* This loop is possibly the wrong way to do this. It goes through *
@@ -1535,11 +1522,12 @@ get_comp_string(void)
/* This variable will hold the current word in quoted form. */
qword = ztrdup(s);
offs = cs - wb;
- if ((p = check_param(s, 0, &tt))) {
- for (; *p == Dnull; p++)
- *p = '"';
- for (; *tt == Dnull; tt++)
- *tt = '"';
+ if ((p = check_param(s, 0, 1))) {
+ for (p = s; *p; p++)
+ if (*p == Dnull)
+ *p = '"';
+ else if (*p == Snull)
+ *p = '\'';
}
if (*s == Snull || *s == Dnull) {
char *q = (*s == Snull ? "'" : "\""), *n = tricat(qipre, q, "");
@@ -3427,7 +3415,7 @@ add_match_data(int alt, char *str, Cline line,
Aminfo ai = (alt ? fainfo : ainfo);
int palen, salen, qipl, ipl, pl, ppl, qisl, isl, psl;
- palen = salen = qipl = ipl = pl = ppl = isl = psl = 0;
+ palen = salen = qipl = ipl = pl = ppl = qisl = isl = psl = 0;
DPUTS(!line, "BUG: add_match_data() without cline");
@@ -4369,10 +4357,10 @@ docompletion(char *s, int lst, int incmd)
invalidatelist();
/* Print the explanation strings if needed. */
- if (!showinglist && validlist && nmatches != 1) {
+ if (!showinglist && validlist && usemenu != 2 && nmatches != 1) {
Cmgroup g = amatches;
Cexpl *e;
- int up = 0, tr = 1;
+ int up = 0, tr = 1, nn = 0;
if (!nmatches)
feep();
@@ -4385,7 +4373,12 @@ docompletion(char *s, int lst, int incmd)
trashzle();
tr = 0;
}
+ if (nn) {
+ up++;
+ putc('\n', shout);
+ }
up += printfmt((*e)->str, (*e)->count, 1);
+ nn = 1;
}
e++;
}
@@ -4915,6 +4908,9 @@ sep_comp_string(char *ss, char *s, int noffs, int rec)
int ois = instring, oib = inbackt;
char *tmp, *p, *ns, *ol = (char *) line, sav, oaq = autoq, *qp, *qs;
+ swb = swe = soffs = 0;
+ ns = NULL;
+
/* Put the string in the lexer buffer and call the lexer to *
* get the words we have to expand. */
zleparse = 1;
@@ -4930,8 +4926,7 @@ sep_comp_string(char *ss, char *s, int noffs, int rec)
inpush(dupstrspace(tmp), 0, NULL);
line = (unsigned char *) tmp;
ll = tl - 1;
- strinbeg();
- stophist = 2;
+ strinbeg(0);
noaliases = 1;
do {
ctxtlex();
@@ -4979,11 +4974,21 @@ sep_comp_string(char *ss, char *s, int noffs, int rec)
ll = oll;
if (cur < 0 || i < 1)
return 1;
+ owb = offs;
+ offs = soffs;
+ if ((p = check_param(ns, 0, 1))) {
+ for (p = ns; *p; p++)
+ if (*p == Dnull)
+ *p = '"';
+ else if (*p == Snull)
+ *p = '\'';
+ }
+ offs = owb;
if (*ns == Snull || *ns == Dnull) {
instring = (*ns == Snull ? 1 : 2);
inbackt = 0;
swb++;
- if (ns[strlen(ns) - 1] == *ns)
+ if (ns[strlen(ns) - 1] == *ns && ns[1])
swe--;
autoq = (*ns == Snull ? '\'' : '"');
} else {
@@ -5028,7 +5033,8 @@ sep_comp_string(char *ss, char *s, int noffs, int rec)
char **ow = clwords, *os = cmdstr, *oqp = qipre, *oqs = qisuf;
int olws = clwsize, olwn = clwnum, olwp = clwpos;
int obr = brange, oer = erange, oof = offs;
-
+ unsigned long occ = ccont;
+
clwsize = clwnum = countlinknodes(foo);
clwords = (char **) zalloc((clwnum + 1) * sizeof(char *));
for (n = firstnode(foo), i = 0; n; incnode(n), i++) {
@@ -5043,7 +5049,9 @@ sep_comp_string(char *ss, char *s, int noffs, int rec)
qipre = qp;
qisuf = qs;
offs = soffs;
+ ccont = CC_CCCONT;
makecomplistcmd(ns, !clwpos, CFN_FIRST);
+ ccont = occ;
offs = oof;
zsfree(cmdstr);
cmdstr = os;
@@ -6341,7 +6349,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
tmpbuf = (char *)zhalloc(strlen(cc->str) + 5);
sprintf(tmpbuf, "foo %s", cc->str); /* KLUDGE! */
inpush(tmpbuf, 0, NULL);
- strinbeg();
+ strinbeg(0);
noaliases = 1;
do {
ctxtlex();
@@ -6502,7 +6510,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd)
int oldn = clwnum, oldp = clwpos;
unsigned long occ = ccont;
- ccont = 0;
+ ccont = CC_CCCONT;
/* So we restrict the words-array. */
if (brange >= clwnum)
@@ -8099,14 +8107,13 @@ doexpandhist(void)
lexsave();
/* We push ol as it will remain unchanged */
inpush((char *) ol, 0, NULL);
- strinbeg();
+ strinbeg(1);
noaliases = 1;
noerrs = 1;
exlast = inbufct;
do {
ctxtlex();
} while (tok != ENDINPUT && tok != LEXERR);
- stophist = 2;
while (!lexstop)
hgetc();
/* We have to save errflags because it's reset in lexrestore. Since *
@@ -8178,7 +8185,7 @@ getcurcmd(void)
metafy_line();
inpush(dupstrspace((char *) line), 0, NULL);
unmetafy_line();
- strinbeg();
+ strinbeg(1);
pushheap();
do {
curlincmd = incmdpos;
diff --git a/Src/builtin.c b/Src/builtin.c
index 4c9b159dd..d74d9cd88 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -43,7 +43,7 @@ static struct builtin builtins[] =
BUILTIN(".", BINF_PSPECIAL, bin_dot, 1, -1, 0, NULL, NULL),
BUILTIN(":", BINF_PSPECIAL, bin_true, 0, -1, 0, NULL, NULL),
BUILTIN("alias", BINF_MAGICEQUALS, bin_alias, 0, -1, 0, "Lgmr", NULL),
- BUILTIN("autoload", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "t", "u"),
+ BUILTIN("autoload", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "tU", "u"),
BUILTIN("bg", 0, bin_fg, 0, -1, BIN_BG, NULL, NULL),
BUILTIN("break", BINF_PSPECIAL, bin_break, 0, 1, BIN_BREAK, NULL, NULL),
BUILTIN("bye", 0, bin_break, 0, 1, BIN_EXIT, NULL, NULL),
@@ -64,7 +64,7 @@ static struct builtin builtins[] =
BUILTIN("false", 0, bin_false, 0, -1, 0, NULL, NULL),
BUILTIN("fc", BINF_FCOPTS, bin_fc, 0, -1, BIN_FC, "nlreIRWAdDfEim", NULL),
BUILTIN("fg", 0, bin_fg, 0, -1, BIN_FG, NULL, NULL),
- BUILTIN("functions", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "mtu", NULL),
+ BUILTIN("functions", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "mtuU", NULL),
BUILTIN("getln", 0, bin_read, 0, -1, 0, "ecnAlE", "zr"),
BUILTIN("getopts", 0, bin_getopts, 2, -1, 0, NULL, NULL),
BUILTIN("hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "dfmrv", NULL),
@@ -209,7 +209,7 @@ execbuiltin(LinkList args, Builtin bn)
LinkNode n;
char ops[MAX_OPS], *arg, *pp, *name, **argv, **oargv, *optstr;
char *oxarg, *xarg = NULL;
- int flags, sense, argc = 0, execop;
+ int flags, sense, argc = 0, execop, xtr = isset(XTRACE), lxarg = 0;
/* initialise some static variables */
auxdata = NULL;
@@ -250,12 +250,21 @@ execbuiltin(LinkList args, Builtin bn)
break;
}
/* save the options in xarg, for execution tracing */
- if (xarg) {
- oxarg = tricat(xarg, " ", arg);
- zsfree(xarg);
- xarg = oxarg;
- } else
- xarg = ztrdup(arg);
+ if (xtr) {
+ if (xarg) {
+ int l = strlen(arg) + lxarg + 1;
+
+ oxarg = zhalloc(l + 1);
+ strcpy(oxarg, xarg);
+ oxarg[lxarg] = ' ';
+ strcpy(oxarg + lxarg + 1, arg);
+ xarg = oxarg;
+ lxarg = l + 1;
+ } else {
+ xarg = dupstring(arg);
+ lxarg = strlen(xarg);
+ }
+ }
/* handle -- or - (ops['-']), and + (ops['-'] and ops['+']) */
if (arg[1] == '-')
arg++;
@@ -283,7 +292,6 @@ execbuiltin(LinkList args, Builtin bn)
if(*arg == Meta)
*++arg ^= 32;
zerr("bad option: -%c", NULL, *arg);
- zsfree(xarg);
return 1;
}
arg = (char *) ugetnode(args);
@@ -330,7 +338,6 @@ execbuiltin(LinkList args, Builtin bn)
while ((*argv++ = (char *)ugetnode(args)));
argv = oargv;
if (errflag) {
- zsfree(xarg);
errflag = 0;
return 1;
}
@@ -339,12 +346,11 @@ execbuiltin(LinkList args, Builtin bn)
if (argc < bn->minargs || (argc > bn->maxargs && bn->maxargs != -1)) {
zwarnnam(name, (argc < bn->minargs)
? "not enough arguments" : "too many arguments", NULL, 0);
- zsfree(xarg);
return 1;
}
/* display execution trace information, if required */
- if (isset(XTRACE)) {
+ if (xtr) {
fprintf(stderr, "%s%s", (prompt4) ? prompt4 : "", name);
if (xarg)
fprintf(stderr, " %s", xarg);
@@ -353,7 +359,6 @@ execbuiltin(LinkList args, Builtin bn)
fputc('\n', stderr);
fflush(stderr);
}
- zsfree(xarg);
/* call the handler function, and return its return value */
return (*(bn->handlerfunc)) (name, argv, ops, bn->funcid);
}
@@ -1824,17 +1829,18 @@ bin_functions(char *name, char **argv, char *ops, int func)
int on = 0, off = 0;
/* Do we have any flags defined? */
- if (ops['u'] || ops['t']) {
- if (ops['u'] == 1)
- on |= PM_UNDEFINED;
- else if (ops['u'] == 2)
- off |= PM_UNDEFINED;
-
- if (ops['t'] == 1)
- on |= PM_TAGGED;
- else if (ops['t'] == 2)
- off |= PM_TAGGED;
- }
+ if (ops['u'] == 1)
+ on |= PM_UNDEFINED;
+ else if (ops['u'] == 2)
+ off |= PM_UNDEFINED;
+ if (ops['U'] == 1)
+ on |= PM_UNALIASED|PM_UNDEFINED;
+ else if (ops['U'] == 2)
+ off |= PM_UNALIASED;
+ if (ops['t'] == 1)
+ on |= PM_TAGGED;
+ else if (ops['t'] == 2)
+ off |= PM_TAGGED;
if (off & PM_UNDEFINED) {
zwarnnam(name, "invalid option(s)", NULL, 0);
@@ -1845,6 +1851,8 @@ bin_functions(char *name, char **argv, char *ops, int func)
* are given, we will print only functions containing these *
* flags, else we'll print them all. */
if (!*argv) {
+ if (ops['U'] && !ops['u'])
+ on &= ~PM_UNDEFINED;
scanhashtable(shfunctab, 1, on|off, DISABLED, shfunctab->printnode, 0);
return 0;
}
@@ -3078,8 +3086,7 @@ bin_eval(char *nam, char **argv, char *ops, int func)
List list;
inpush(zjoin(argv, ' '), 0, NULL);
- strinbeg();
- stophist = 2;
+ strinbeg(0);
list = parse_list();
strinend();
inpop();
@@ -3584,7 +3591,7 @@ bin_trap(char *name, char **argv, char *ops, int func)
if (!sigfuncs[sig])
printf("trap -- '' %s\n", sigs[sig]);
else {
- s = getpermtext((void *) dupstruct((void *) sigfuncs[sig]));
+ s = getpermtext((void *) sigfuncs[sig]);
printf("trap -- ");
quotedzputs(s, stdout);
printf(" %s\n", sigs[sig]);
diff --git a/Src/cond.c b/Src/cond.c
index a8387a454..98deea2bf 100644
--- a/Src/cond.c
+++ b/Src/cond.c
@@ -42,6 +42,7 @@ int
evalcond(Cond c)
{
struct stat *st;
+ char *left, *right = NULL;
switch (c->type) {
case COND_NOT:
@@ -103,107 +104,109 @@ evalcond(Cond c)
return 0;
}
}
- singsub((char **)&c->left);
- untokenize(c->left);
+ left = dupstring((char *) c->left);
+ singsub(&left);
+ untokenize(left);
if (c->right) {
- singsub((char **)&c->right);
+ right = dupstring((char *) c->right);
+ singsub(&right);
if (c->type != COND_STREQ && c->type != COND_STRNEQ)
- untokenize(c->right);
+ untokenize(right);
}
if (tracingcond) {
if (c->type < COND_MOD) {
- char *rt = (char *)c->right;
+ char *rt = (char *)right;
if (c->type == COND_STREQ || c->type == COND_STRNEQ) {
rt = dupstring(rt);
untokenize(rt);
}
- fprintf(stderr, " %s %s %s", (char *)c->left, condstr[c->type],
+ fprintf(stderr, " %s %s %s", (char *)left, condstr[c->type],
rt);
} else
- fprintf(stderr, " -%c %s", c->type, (char *)c->left);
+ fprintf(stderr, " -%c %s", c->type, (char *)left);
}
switch (c->type) {
case COND_STREQ:
- return matchpat(c->left, c->right);
+ return matchpat(left, right);
case COND_STRNEQ:
- return !matchpat(c->left, c->right);
+ return !matchpat(left, right);
case COND_STRLT:
- return strcmp(c->left, c->right) < 0;
+ return strcmp(left, right) < 0;
case COND_STRGTR:
- return strcmp(c->left, c->right) > 0;
+ return strcmp(left, right) > 0;
case 'e':
case 'a':
- return (doaccess(c->left, F_OK));
+ return (doaccess(left, F_OK));
case 'b':
- return (S_ISBLK(dostat(c->left)));
+ return (S_ISBLK(dostat(left)));
case 'c':
- return (S_ISCHR(dostat(c->left)));
+ return (S_ISCHR(dostat(left)));
case 'd':
- return (S_ISDIR(dostat(c->left)));
+ return (S_ISDIR(dostat(left)));
case 'f':
- return (S_ISREG(dostat(c->left)));
+ return (S_ISREG(dostat(left)));
case 'g':
- return (!!(dostat(c->left) & S_ISGID));
+ return (!!(dostat(left) & S_ISGID));
case 'k':
- return (!!(dostat(c->left) & S_ISVTX));
+ return (!!(dostat(left) & S_ISVTX));
case 'n':
- return (!!strlen(c->left));
+ return (!!strlen(left));
case 'o':
- return (optison(c->left));
+ return (optison(left));
case 'p':
- return (S_ISFIFO(dostat(c->left)));
+ return (S_ISFIFO(dostat(left)));
case 'r':
- return (doaccess(c->left, R_OK));
+ return (doaccess(left, R_OK));
case 's':
- return ((st = getstat(c->left)) && !!(st->st_size));
+ return ((st = getstat(left)) && !!(st->st_size));
case 'S':
- return (S_ISSOCK(dostat(c->left)));
+ return (S_ISSOCK(dostat(left)));
case 'u':
- return (!!(dostat(c->left) & S_ISUID));
+ return (!!(dostat(left) & S_ISUID));
case 'w':
- return (doaccess(c->left, W_OK));
+ return (doaccess(left, W_OK));
case 'x':
if (privasserted()) {
- mode_t mode = dostat(c->left);
+ mode_t mode = dostat(left);
return (mode & S_IXUGO) || S_ISDIR(mode);
}
- return doaccess(c->left, X_OK);
+ return doaccess(left, X_OK);
case 'z':
- return (!strlen(c->left));
+ return (!strlen(left));
case 'h':
case 'L':
- return (S_ISLNK(dolstat(c->left)));
+ return (S_ISLNK(dolstat(left)));
case 'O':
- return ((st = getstat(c->left)) && st->st_uid == geteuid());
+ return ((st = getstat(left)) && st->st_uid == geteuid());
case 'G':
- return ((st = getstat(c->left)) && st->st_gid == getegid());
+ return ((st = getstat(left)) && st->st_gid == getegid());
case 'N':
- return ((st = getstat(c->left)) && st->st_atime <= st->st_mtime);
+ return ((st = getstat(left)) && st->st_atime <= st->st_mtime);
case 't':
- return isatty(matheval(c->left));
+ return isatty(matheval(left));
case COND_EQ:
- return matheval(c->left) == matheval(c->right);
+ return matheval(left) == matheval(right);
case COND_NE:
- return matheval(c->left) != matheval(c->right);
+ return matheval(left) != matheval(right);
case COND_LT:
- return matheval(c->left) < matheval(c->right);
+ return matheval(left) < matheval(right);
case COND_GT:
- return matheval(c->left) > matheval(c->right);
+ return matheval(left) > matheval(right);
case COND_LE:
- return matheval(c->left) <= matheval(c->right);
+ return matheval(left) <= matheval(right);
case COND_GE:
- return matheval(c->left) >= matheval(c->right);
+ return matheval(left) >= matheval(right);
case COND_NT:
case COND_OT:
{
time_t a;
- if (!(st = getstat(c->left)))
+ if (!(st = getstat(left)))
return 0;
a = st->st_mtime;
- if (!(st = getstat(c->right)))
+ if (!(st = getstat(right)))
return 0;
return (c->type == COND_NT) ? a > st->st_mtime : a < st->st_mtime;
}
@@ -212,11 +215,11 @@ evalcond(Cond c)
dev_t d;
ino_t i;
- if (!(st = getstat(c->left)))
+ if (!(st = getstat(left)))
return 0;
d = st->st_dev;
i = st->st_ino;
- if (!(st = getstat(c->right)))
+ if (!(st = getstat(right)))
return 0;
return d == st->st_dev && i == st->st_ino;
}
diff --git a/Src/exec.c b/Src/exec.c
index 952dfbb78..5cfe3e3ef 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -139,8 +139,7 @@ parse_string(char *s)
lexsave();
inpush(s, 0, NULL);
- strinbeg();
- stophist = 2;
+ strinbeg(0);
l = parse_list();
strinend();
inpop();
@@ -298,12 +297,12 @@ static char list_pipe_text[JOBTEXTSIZE];
/**/
static int
-execcursh(Cmd cmd)
+execcursh(Cmd cmd, LinkList args, int flags)
{
if (!list_pipe)
deletejob(jobtab + thisjob);
- execlist(cmd->u.list, 1, cmd->flags & CFLAG_EXEC);
- cmd->u.list = NULL;
+ execlist(cmd->u.list, 1, flags & CFLAG_EXEC);
+
return lastval;
}
@@ -718,7 +717,6 @@ execlist(List list, int dont_change_job, int exiting)
/* Reset donetrap: this ensures that a trap is only *
* called once for each sublist that fails. */
donetrap = 0;
- simplifyright(list);
slist = list->left;
/* Loop through code followed by &&, ||, or end of sublist. */
@@ -1009,11 +1007,13 @@ execpline2(Pline pline, int how, int input, int output, int last1)
lineno = pline->left->lineno;
if (pline_level == 1)
- strcpy(list_pipe_text, getjobtext((void *) pline->left));
- if (pline->type == END) {
+ if (!sfcontext)
+ strcpy(list_pipe_text, getjobtext((void *) pline->left));
+ else
+ list_pipe_text[0] = '\0';
+ if (pline->type == END)
execcmd(pline->left, input, output, how, last1 ? 1 : 2);
- pline->left = NULL;
- } else {
+ else {
int old_list_pipe = list_pipe;
mpipe(pipes);
@@ -1046,11 +1046,10 @@ execpline2(Pline pline, int how, int input, int output, int last1)
_exit(lastval);
}
} else {
- /* otherwise just do the pipeline normally. */
+ /* otherwise just do the pipeline normally. */
subsh_close = pipes[0];
execcmd(pline->left, input, pipes[1], how, 0);
}
- pline->left = NULL;
zclose(pipes[1]);
if (pline->right) {
/* if another execpline() is invoked because the command is *
@@ -1102,13 +1101,17 @@ makecline(LinkList list)
void
untokenize(char *s)
{
- for (; *s; s++)
- if (itok(*s)) {
- if (*s == Nularg)
- chuck(s--);
- else
- *s = ztokens[*s - Pound];
- }
+ if (*s) {
+ char *p = s, c;
+
+ while ((c = *s++))
+ if (itok(c)) {
+ if (c != Nularg)
+ *p++ = ztokens[c - Pound];
+ } else
+ *p++ = c;
+ *p = '\0';
+ }
}
/* Open a file for writing redicection */
@@ -1152,34 +1155,34 @@ clobber_open(struct redir *f)
static void
closemn(struct multio **mfds, int fd)
{
- struct multio *mn = mfds[fd];
- char buf[TCBUFSIZE];
- int len, i;
+ if (fd >= 0 && mfds[fd] && mfds[fd]->ct >= 2) {
+ struct multio *mn = mfds[fd];
+ char buf[TCBUFSIZE];
+ int len, i;
- if (fd < 0 || !mfds[fd] || mfds[fd]->ct < 2)
- return;
- if (zfork()) {
- for (i = 0; i < mn->ct; i++)
- zclose(mn->fds[i]);
- zclose(mn->pipe);
- mn->ct = 1;
- mn->fds[0] = fd;
- return;
- }
- /* pid == 0 */
- closeallelse(mn);
- if (mn->rflag) {
- /* tee process */
- while ((len = read(mn->pipe, buf, TCBUFSIZE)) > 0)
+ if (zfork()) {
for (i = 0; i < mn->ct; i++)
- write(mn->fds[i], buf, len);
- } else {
- /* cat process */
- for (i = 0; i < mn->ct; i++)
- while ((len = read(mn->fds[i], buf, TCBUFSIZE)) > 0)
- write(mn->pipe, buf, len);
+ zclose(mn->fds[i]);
+ zclose(mn->pipe);
+ mn->ct = 1;
+ mn->fds[0] = fd;
+ return;
+ }
+ /* pid == 0 */
+ closeallelse(mn);
+ if (mn->rflag) {
+ /* tee process */
+ while ((len = read(mn->pipe, buf, TCBUFSIZE)) > 0)
+ for (i = 0; i < mn->ct; i++)
+ write(mn->fds[i], buf, len);
+ } else {
+ /* cat process */
+ for (i = 0; i < mn->ct; i++)
+ while ((len = read(mn->fds[i], buf, TCBUFSIZE)) > 0)
+ write(mn->pipe, buf, len);
+ }
+ _exit(0);
}
- _exit(0);
}
/* close all the mnodes (failure) */
@@ -1273,9 +1276,10 @@ static void
addvars(LinkList l, int export)
{
Varasg v;
+ LinkNode n;
LinkList vl;
int xtr;
- char **arr, **ptr;
+ char **arr, **ptr, *name;
xtr = isset(XTRACE);
if (xtr && nonempty(l)) {
@@ -1283,26 +1287,30 @@ addvars(LinkList l, int export)
doneps4 = 1;
}
- while (nonempty(l)) {
- v = (Varasg) ugetnode(l);
- singsub(&v->name);
+ for (n = firstnode(l); n; incnode(n)) {
+ v = (Varasg) getdata(n);
+ name = dupstring(v->name);
+ singsub(&name);
if (errflag)
return;
- untokenize(v->name);
+ untokenize(name);
if (xtr)
- fprintf(stderr, "%s=", v->name);
+ fprintf(stderr, "%s=", name);
if (v->type == PM_SCALAR) {
vl = newlinklist();
- addlinknode(vl, v->str);
+ addlinknode(vl, dupstring(v->str));
} else
- vl = v->arr;
- prefork(vl, v->type == PM_SCALAR ? (PF_SINGLE|PF_ASSIGN) : PF_ASSIGN);
- if (errflag)
- return;
- if (isset(GLOBASSIGN) || v->type != PM_SCALAR)
- globlist(vl);
- if (errflag)
- return;
+ vl = listdup(v->arr);
+ if (vl) {
+ prefork(vl, v->type == PM_SCALAR ? (PF_SINGLE|PF_ASSIGN) :
+ PF_ASSIGN);
+ if (errflag)
+ return;
+ if (isset(GLOBASSIGN) || v->type != PM_SCALAR)
+ globlist(vl);
+ if (errflag)
+ return;
+ }
if (v->type == PM_SCALAR && (empty(vl) || !nextnode(firstnode(vl)))) {
Param pm;
char *val;
@@ -1319,7 +1327,7 @@ addvars(LinkList l, int export)
if (export) {
if (export < 0) {
/* We are going to fork so do not bother freeing this */
- pm = (Param) paramtab->removenode(paramtab, v->name);
+ pm = (Param) paramtab->removenode(paramtab, name);
if (isset(RESTRICTED) && (pm->flags & PM_RESTRICTED)) {
zerr("%s: restricted", pm->nam, 0);
zsfree(val);
@@ -1328,18 +1336,22 @@ addvars(LinkList l, int export)
}
allexp = opts[ALLEXPORT];
opts[ALLEXPORT] = 1;
- pm = setsparam(v->name, val);
+ pm = setsparam(name, val);
opts[ALLEXPORT] = allexp;
} else
- pm = setsparam(v->name, val);
+ pm = setsparam(name, val);
if (errflag)
return;
continue;
}
- ptr = arr = (char **) zalloc(sizeof(char **) * (countlinknodes(vl) + 1));
+ if (vl) {
+ ptr = arr = (char **) zalloc(sizeof(char **) *
+ (countlinknodes(vl) + 1));
- while (nonempty(vl))
- *ptr++ = ztrdup((char *) ugetnode(vl));
+ while (nonempty(vl))
+ *ptr++ = ztrdup((char *) ugetnode(vl));
+ } else
+ ptr = arr = (char **) zalloc(sizeof(char **));
*ptr = NULL;
if (xtr) {
@@ -1348,7 +1360,7 @@ addvars(LinkList l, int export)
fprintf(stderr, "%s ", *ptr);
fprintf(stderr, ") ");
}
- setaparam(v->name, arr);
+ setaparam(name, arr);
if (errflag)
return;
}
@@ -1364,15 +1376,19 @@ execcmd(Cmd cmd, int input, int output, int how, int last1)
struct multio *mfds[10];
char *text;
int save[10];
- int