3 @@ -1569,14 +1569,14 @@
4 static char *optptr; /* used by nextopt */
7 - * XXX - should get rid of. have all builtins use getopt(3). the
8 - * library getopt must have the BSD extension static variable "optreset"
9 - * otherwise it can't be used within the shell safely.
10 + * XXX - should get rid of. Have all builtins use getopt(3).
11 + * The library getopt must have the BSD extension static variable
12 + * "optreset", otherwise it can't be used within the shell safely.
14 - * Standard option processing (a la getopt) for builtin routines. The
15 - * only argument that is passed to nextopt is the option string; the
16 - * other arguments are unnecessary. It return the character, or '\0' on
18 + * Standard option processing (a la getopt) for builtin routines.
19 + * The only argument that is passed to nextopt is the option string;
20 + * the other arguments are unnecessary. It returns the character,
21 + * or '\0' on end of input.
24 nextopt(const char *optstring)
25 @@ -1587,13 +1587,20 @@
28 if (p == NULL || *p == '\0') {
29 + /* We ate entire "-param", take next one */
31 - if (p == NULL || *p != '-' || *++p == '\0')
36 + if (*++p == '\0') /* just "-" ? */
39 - if (LONE_DASH(p)) /* check for "--" */
40 + if (LONE_DASH(p)) /* "--" ? */
42 + /* p => next "-param" */
44 + /* p => some option char in the middle of a "-param" */
46 for (q = optstring; *q != c;) {
48 @@ -1602,8 +1609,11 @@
52 - if (*p == '\0' && (p = *argptr++) == NULL)
53 - ash_msg_and_raise_error("no arg for -%c option", c);
57 + ash_msg_and_raise_error("no arg for -%c option", c);
62 @@ -7428,8 +7438,10 @@
67 + /* Mimic bash: just "command -v" doesn't complain, it's a nop */
68 + if (verify && (*argptr != NULL)) {
69 return describe_command(*argptr, verify - VERIFY_BRIEF);
74 @@ -7788,16 +7800,33 @@
76 evaltree(union node *n, int flags)
79 + struct jmploc *volatile savehandler = exception_handler;
80 + struct jmploc jmploc;
82 void (*evalfn)(union node *, int);
87 TRACE(("evaltree(NULL) called\n"));
91 TRACE(("pid %d, evaltree(%p: %d, %d) called\n",
92 getpid(), n, n->type, flags));
94 + exception_handler = &jmploc;
96 + int err = setjmp(jmploc.loc);
98 + /* if it was a signal, check for trap handlers */
99 + if (exception == EXSIG)
101 + /* continue on the way out */
102 + exception_handler = savehandler;
103 + longjmp(exception_handler->loc, err);
110 @@ -7843,19 +7872,20 @@
118 #error NAND + 1 != NOR
121 #error NOR + 1 != NSEMI
123 - isor = n->type - NAND;
124 + unsigned is_or = n->type - NAND;
127 - (flags | ((isor >> 1) - 1)) & EV_TESTED
128 + (flags | ((is_or >> 1) - 1)) & EV_TESTED
130 - if (!exitstatus == isor)
131 + if (!exitstatus == is_or)
135 @@ -7866,6 +7896,7 @@
141 evaltree(n->nif.test, EV_TESTED);
143 @@ -7886,8 +7917,11 @@
149 - if ((checkexit & exitstatus))
150 + exception_handler = savehandler;
152 + if (checkexit & exitstatus)
153 evalskip |= SKIPEVAL;
154 else if (pendingsig && dotrap())