ash: more renaming and style fixes
This commit is contained in:
parent
b012b10dbd
commit
2da584fc4e
102
shell/ash.c
102
shell/ash.c
@ -168,7 +168,7 @@ static char *arg0; /* value of $0 */
|
||||
struct jmploc {
|
||||
jmp_buf loc;
|
||||
};
|
||||
static struct jmploc *handler;
|
||||
static struct jmploc *exception_handler;
|
||||
static int exception;
|
||||
/* exceptions */
|
||||
#define EXINT 0 /* SIGINT received */
|
||||
@ -208,12 +208,12 @@ static void
|
||||
raise_exception(int e)
|
||||
{
|
||||
#if DEBUG
|
||||
if (handler == NULL)
|
||||
if (exception_handler == NULL)
|
||||
abort();
|
||||
#endif
|
||||
INT_OFF;
|
||||
exception = e;
|
||||
longjmp(handler->loc, 1);
|
||||
longjmp(exception_handler->loc, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1039,7 +1039,7 @@ static int SIT(int c, int syntax)
|
||||
return CCTL;
|
||||
else {
|
||||
s = strchr(spec_symbls, c);
|
||||
if (s == 0 || *s == 0)
|
||||
if (s == NULL || *s == '\0')
|
||||
return CWORD;
|
||||
indx = syntax_index_table[(s - spec_symbls)];
|
||||
}
|
||||
@ -3007,7 +3007,8 @@ expredir(union node *n)
|
||||
|
||||
for (redir = n; redir; redir = redir->nfile.next) {
|
||||
struct arglist fn;
|
||||
memset(&fn, 0, sizeof(struct arglist));
|
||||
|
||||
memset(&fn, 0, sizeof(fn));
|
||||
fn.lastp = &fn.list;
|
||||
switch (redir->type) {
|
||||
case NFROMTO:
|
||||
@ -3022,10 +3023,9 @@ expredir(union node *n)
|
||||
case NTOFD:
|
||||
if (redir->ndup.vname) {
|
||||
expandarg(redir->ndup.vname, &fn, EXP_FULL | EXP_TILDE);
|
||||
if (fn.list != NULL)
|
||||
fixredir(redir, fn.list->text, 1);
|
||||
else
|
||||
if (fn.list == NULL)
|
||||
ash_msg_and_raise_error("redir error");
|
||||
fixredir(redir, fn.list->text, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3401,7 +3401,7 @@ evalcommand(union node *cmd, int flags)
|
||||
|
||||
if (i == EXINT || spclbltin > 0) {
|
||||
raise:
|
||||
longjmp(handler->loc, 1);
|
||||
longjmp(exception_handler->loc, 1);
|
||||
}
|
||||
FORCE_INT_ON;
|
||||
}
|
||||
@ -3437,8 +3437,8 @@ evalbltin(const struct builtincmd *cmd, int argc, char **argv)
|
||||
i = setjmp(jmploc.loc);
|
||||
if (i)
|
||||
goto cmddone;
|
||||
savehandler = handler;
|
||||
handler = &jmploc;
|
||||
savehandler = exception_handler;
|
||||
exception_handler = &jmploc;
|
||||
commandname = argv[0];
|
||||
argptr = argv + 1;
|
||||
optptr = NULL; /* initialize nextopt */
|
||||
@ -3449,7 +3449,7 @@ evalbltin(const struct builtincmd *cmd, int argc, char **argv)
|
||||
clearerr(stdout);
|
||||
commandname = savecmdname;
|
||||
exsig = 0;
|
||||
handler = savehandler;
|
||||
exception_handler = savehandler;
|
||||
|
||||
return i;
|
||||
}
|
||||
@ -3470,8 +3470,8 @@ evalfun(struct funcnode *func, int argc, char **argv, int flags)
|
||||
goto funcdone;
|
||||
}
|
||||
INT_OFF;
|
||||
savehandler = handler;
|
||||
handler = &jmploc;
|
||||
savehandler = exception_handler;
|
||||
exception_handler = &jmploc;
|
||||
localvars = NULL;
|
||||
shellparam.malloc = 0;
|
||||
func->count++;
|
||||
@ -3492,7 +3492,7 @@ funcdone:
|
||||
localvars = savelocalvars;
|
||||
freeparam(&shellparam);
|
||||
shellparam = saveparam;
|
||||
handler = savehandler;
|
||||
exception_handler = savehandler;
|
||||
INT_ON;
|
||||
evalskip &= ~SKIPFUNC;
|
||||
return e;
|
||||
@ -3649,7 +3649,7 @@ static void delete_cmd_entry(void);
|
||||
* Exec a program. Never returns. If you change this routine, you may
|
||||
* have to change the find_command routine as well.
|
||||
*/
|
||||
|
||||
static void shellexec(char **, const char *, int) ATTRIBUTE_NORETURN;
|
||||
static void
|
||||
shellexec(char **argv, const char *path, int idx)
|
||||
{
|
||||
@ -4499,8 +4499,7 @@ static int cvtnum(arith_t);
|
||||
static size_t esclen(const char *, const char *);
|
||||
static char *scanleft(char *, char *, char *, char *, int, int);
|
||||
static char *scanright(char *, char *, char *, char *, int, int);
|
||||
static void varunset(const char *, const char *, const char *, int)
|
||||
ATTRIBUTE_NORETURN;
|
||||
static void varunset(const char *, const char *, const char *, int) ATTRIBUTE_NORETURN;
|
||||
|
||||
|
||||
#define pmatch(a, b) !fnmatch((a), (b), 0)
|
||||
@ -5874,6 +5873,7 @@ cvtnum(arith_t num)
|
||||
return len;
|
||||
}
|
||||
|
||||
static void varunset(const char *, const char *, const char *, int) ATTRIBUTE_NORETURN;
|
||||
static void
|
||||
varunset(const char *end, const char *var, const char *umsg, int varflags)
|
||||
{
|
||||
@ -6573,10 +6573,9 @@ killcmd(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
name = get_signame(signo);
|
||||
if (isdigit(*name))
|
||||
out1fmt(snlfmt, name);
|
||||
else
|
||||
if (!isdigit(*name))
|
||||
ash_msg_and_raise_error("invalid signal number or exit status: %s", *argptr);
|
||||
out1fmt(snlfmt, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -7869,7 +7868,7 @@ int ash_main(int argc, char **argv)
|
||||
else
|
||||
goto state4;
|
||||
}
|
||||
handler = &jmploc;
|
||||
exception_handler = &jmploc;
|
||||
#if DEBUG
|
||||
opentrace();
|
||||
trputs("Shell args: "); trargs(argv);
|
||||
@ -9378,7 +9377,7 @@ pipeline(void)
|
||||
n2->type = NNOT;
|
||||
n2->nnot.com = n1;
|
||||
return n2;
|
||||
} else
|
||||
}
|
||||
return n1;
|
||||
}
|
||||
|
||||
@ -10464,8 +10463,8 @@ parsebackq: {
|
||||
if (str)
|
||||
free(str);
|
||||
parsebackquote = 0;
|
||||
handler = savehandler;
|
||||
longjmp(handler->loc, 1);
|
||||
exception_handler = savehandler;
|
||||
longjmp(exception_handler->loc, 1);
|
||||
}
|
||||
INT_OFF;
|
||||
str = NULL;
|
||||
@ -10474,8 +10473,8 @@ parsebackq: {
|
||||
str = ckmalloc(savelen);
|
||||
memcpy(str, stackblock(), savelen);
|
||||
}
|
||||
savehandler = handler;
|
||||
handler = &jmploc;
|
||||
savehandler = exception_handler;
|
||||
exception_handler = &jmploc;
|
||||
INT_ON;
|
||||
if (oldstyle) {
|
||||
/* We must read until the closing backquote, giving special
|
||||
@ -10586,7 +10585,7 @@ parsebackq: {
|
||||
INT_ON;
|
||||
}
|
||||
parsebackquote = savepbq;
|
||||
handler = savehandler;
|
||||
exception_handler = savehandler;
|
||||
if (arinest || dblquote)
|
||||
USTPUTC(CTLBACKQ | CTLQUOTE, out);
|
||||
else
|
||||
@ -11075,7 +11074,6 @@ copyfd(int from, int to)
|
||||
if (newfd < 0) {
|
||||
if (errno == EMFILE)
|
||||
return EMPTY;
|
||||
else
|
||||
ash_msg_and_raise_error("%d: %m", from);
|
||||
}
|
||||
return newfd;
|
||||
@ -11087,18 +11085,18 @@ redirectsafe(union node *redir, int flags)
|
||||
{
|
||||
int err;
|
||||
volatile int saveint;
|
||||
struct jmploc *volatile savehandler = handler;
|
||||
struct jmploc *volatile savehandler = exception_handler;
|
||||
struct jmploc jmploc;
|
||||
|
||||
SAVE_INT(saveint);
|
||||
err = setjmp(jmploc.loc) * 2;
|
||||
if (!err) {
|
||||
handler = &jmploc;
|
||||
exception_handler = &jmploc;
|
||||
redirect(redir, flags);
|
||||
}
|
||||
handler = savehandler;
|
||||
exception_handler = savehandler;
|
||||
if (err && exception != EXERROR)
|
||||
longjmp(handler->loc, 1);
|
||||
longjmp(exception_handler->loc, 1);
|
||||
RESTORE_INT(saveint);
|
||||
return err;
|
||||
}
|
||||
@ -11376,7 +11374,8 @@ trstring(char *s)
|
||||
case CTLVAR+CTLQUOTE: c = 'V'; goto backslash;
|
||||
case CTLBACKQ: c = 'q'; goto backslash;
|
||||
case CTLBACKQ+CTLQUOTE: c = 'Q'; goto backslash;
|
||||
backslash: putc('\\', tracefile);
|
||||
backslash:
|
||||
putc('\\', tracefile);
|
||||
putc(c, tracefile);
|
||||
break;
|
||||
default:
|
||||
@ -11596,8 +11595,8 @@ setsignal(int signo)
|
||||
return;
|
||||
}
|
||||
if (act.sa_handler == SIG_IGN) {
|
||||
if (mflag && (signo == SIGTSTP || signo == SIGTTIN
|
||||
|| signo == SIGTTOU)
|
||||
if (mflag
|
||||
&& (signo == SIGTSTP || signo == SIGTTIN || signo == SIGTTOU)
|
||||
) {
|
||||
tsig = S_IGN; /* don't hard ignore these */
|
||||
} else
|
||||
@ -11675,7 +11674,7 @@ dotrap(void)
|
||||
for (i = 0, q = gotsig; i < NSIG - 1; i++, q++) {
|
||||
if (!*q)
|
||||
continue;
|
||||
*q = 0;
|
||||
*q = '\0';
|
||||
|
||||
p = trap[i + 1];
|
||||
if (!p)
|
||||
@ -11711,8 +11710,10 @@ setinteractive(int on)
|
||||
|
||||
if (!do_banner) {
|
||||
out1fmt(
|
||||
"\n\n%s Built-in shell (ash)\n"
|
||||
"Enter 'help' for a list of built-in commands.\n\n",
|
||||
"\n\n"
|
||||
"%s Built-in shell (ash)\n"
|
||||
"Enter 'help' for a list of built-in commands."
|
||||
"\n\n",
|
||||
BB_BANNER);
|
||||
do_banner++;
|
||||
}
|
||||
@ -11773,7 +11774,7 @@ exitshell(void)
|
||||
status = exitstatus;
|
||||
goto out;
|
||||
}
|
||||
handler = &loc;
|
||||
exception_handler = &loc;
|
||||
p = trap[0];
|
||||
if (p) {
|
||||
trap[0] = NULL;
|
||||
@ -11807,18 +11808,18 @@ setvarsafe(const char *name, const char *val, int flags)
|
||||
{
|
||||
int err;
|
||||
volatile int saveint;
|
||||
struct jmploc *volatile savehandler = handler;
|
||||
struct jmploc *volatile savehandler = exception_handler;
|
||||
struct jmploc jmploc;
|
||||
|
||||
SAVE_INT(saveint);
|
||||
if (setjmp(jmploc.loc))
|
||||
err = 1;
|
||||
else {
|
||||
handler = &jmploc;
|
||||
exception_handler = &jmploc;
|
||||
setvar(name, val, flags);
|
||||
err = 0;
|
||||
}
|
||||
handler = savehandler;
|
||||
exception_handler = savehandler;
|
||||
RESTORE_INT(saveint);
|
||||
return err;
|
||||
}
|
||||
@ -12050,10 +12051,11 @@ exportcmd(int argc, char **argv)
|
||||
const char *p;
|
||||
char **aptr;
|
||||
int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT;
|
||||
int notp;
|
||||
|
||||
notp = nextopt("p") - 'p';
|
||||
if (notp && ((name = *(aptr = argptr)))) {
|
||||
if (nextopt("p") != 'p') {
|
||||
aptr = argptr;
|
||||
name = *aptr;
|
||||
if (name) {
|
||||
do {
|
||||
p = strchr(name, '=');
|
||||
if (p != NULL) {
|
||||
@ -12067,9 +12069,10 @@ exportcmd(int argc, char **argv)
|
||||
}
|
||||
setvar(name, p, flag);
|
||||
} while ((name = *++aptr) != NULL);
|
||||
} else {
|
||||
showvars(argv[0], flag, 0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
showvars(argv[0], flag, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -13368,7 +13371,8 @@ static arith_t arith(const char *expr, int *perrcode)
|
||||
numstackptr++;
|
||||
lasttok = TOK_NUM;
|
||||
continue;
|
||||
} else if (is_digit(arithval)) {
|
||||
}
|
||||
if (is_digit(arithval)) {
|
||||
numstackptr->var = NULL;
|
||||
#if ENABLE_ASH_MATH_SUPPORT_64
|
||||
numstackptr->val = strtoll(expr, (char **) &expr, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user