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