static const char homestr[] ALIGN1 = "HOME";
static const char snlfmt[] ALIGN1 = "%s\n";
-static const char illnum[] ALIGN1 = "Illegal number: %s";
+static const char msg_illnum[] ALIGN1 = "Illegal number: %s";
/*
* We enclose jmp_buf in a structure so that we can declare pointers to
struct jmploc *exception_handler;
-// disabled by vda: cannot understand how it was supposed to work -
-// cannot fix bugs. That's why you have to explain your non-trivial designs!
-// /* do we generate EXSIG events */
-// int exsig; /* counter */
- volatile int suppressint; /* counter */
-// TODO: rename
-// pendingsig -> pending_sig
-// intpending -> pending_int
- volatile /*sig_atomic_t*/ smallint intpending; /* 1 = got SIGINT */
+ volatile int suppress_int; /* counter */
+ volatile /*sig_atomic_t*/ smallint pending_int; /* 1 = got SIGINT */
/* last pending signal */
- volatile /*sig_atomic_t*/ smallint pendingsig;
+ volatile /*sig_atomic_t*/ smallint pending_sig;
smallint exception_type; /* kind of exception (0..5) */
/* exceptions */
#define EXINT 0 /* SIGINT received */
#define arg0 (G_misc.arg0 )
#define exception_handler (G_misc.exception_handler)
#define exception_type (G_misc.exception_type )
-#define suppressint (G_misc.suppressint )
-#define intpending (G_misc.intpending )
-//#define exsig (G_misc.exsig )
-#define pendingsig (G_misc.pendingsig )
+#define suppress_int (G_misc.suppress_int )
+#define pending_int (G_misc.pending_int )
+#define pending_sig (G_misc.pending_sig )
#define isloginsh (G_misc.isloginsh )
#define nullstr (G_misc.nullstr )
#define optlist (G_misc.optlist )
* more fun than worrying about efficiency and portability. :-))
*/
#define INT_OFF do { \
- suppressint++; \
+ suppress_int++; \
xbarrier(); \
} while (0)
{
int ex_type;
- intpending = 0;
+ pending_int = 0;
/* Signal is not automatically unmasked after it is raised,
* do it ourself - unmask all signals */
sigprocmask_allsigs(SIG_UNBLOCK);
- /* pendingsig = 0; - now done in onsig() */
+ /* pending_sig = 0; - now done in onsig() */
ex_type = EXSIG;
if (gotsig[SIGINT - 1] && !trap[SIGINT]) {
int_on(void)
{
xbarrier();
- if (--suppressint == 0 && intpending) {
+ if (--suppress_int == 0 && pending_int) {
raise_interrupt();
}
}
force_int_on(void)
{
xbarrier();
- suppressint = 0;
- if (intpending)
+ suppress_int = 0;
+ if (pending_int)
raise_interrupt();
}
#define FORCE_INT_ON force_int_on()
-#define SAVE_INT(v) ((v) = suppressint)
+#define SAVE_INT(v) ((v) = suppress_int)
#define RESTORE_INT(v) do { \
xbarrier(); \
- suppressint = (v); \
- if (suppressint == 0 && intpending) \
+ suppress_int = (v); \
+ if (suppress_int == 0 && pending_int) \
raise_interrupt(); \
} while (0)
if (DEBUG_PID)
fprintf(tracefile, "[%u] ", (int) getpid());
if (DEBUG_SIG)
- fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pendingsig, intpending, suppressint);
+ fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pending_sig, pending_int, suppress_int);
va_start(va, fmt);
vfprintf(tracefile, fmt, va);
va_end(va);
if (DEBUG_PID)
fprintf(tracefile, "[%u] ", (int) getpid());
if (DEBUG_SIG)
- fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pendingsig, intpending, suppressint);
+ fprintf(tracefile, "pending s:%d i:%d(supp:%d) ", pending_sig, pending_int, suppress_int);
vfprintf(tracefile, fmt, va);
}
number(const char *s)
{
if (!is_number(s))
- ash_msg_and_raise_error(illnum, s);
+ ash_msg_and_raise_error(msg_illnum, s);
return atoi(s);
}
#define CD_PHYSICAL 1
#define CD_PRINT 2
-static int docd(const char *, int);
-
static int
cdopt(void)
{
int i, j;
j = 'L';
- while ((i = nextopt("LP"))) {
+ while ((i = nextopt("LP")) != '\0') {
if (i != j) {
flags ^= CD_PHYSICAL;
j = i;
{
gotsig[signo - 1] = 1;
- if (/* exsig || */ (signo == SIGINT && !trap[SIGINT])) {
- if (!suppressint) {
- pendingsig = 0;
+ if (signo == SIGINT && !trap[SIGINT]) {
+ if (!suppress_int) {
+ pending_sig = 0;
raise_interrupt(); /* does not return */
}
- intpending = 1;
+ pending_int = 1;
} else {
- pendingsig = signo;
+ pending_sig = signo;
}
}
}
if (is_number(p)) {
-// TODO: number() instead? It does error checking...
num = atoi(p);
if (num < njobs) {
jp = jobtab + num - 1;
blocking_wait_with_raise_on_sig(struct job *job)
{
pid_t pid = dowait(DOWAIT_BLOCK, job);
- if (pid <= 0 && pendingsig)
+ if (pid <= 0 && pending_sig)
raise_exception(EXSIG);
return pid;
}
int mode, m;
mode = 0;
- while ((m = nextopt("lp"))) {
+ while ((m = nextopt("lp")) != '\0') {
if (m == 'l')
mode |= SHOW_PIDS;
else
int retval;
struct job *jp;
-// exsig++;
-// xbarrier();
- if (pendingsig)
+ if (pending_sig)
raise_exception(EXSIG);
nextopt(nullstr);
if (!str)
continue;
dostr:
- while ((c = *str++)) {
+ while ((c = *str++) != '\0') {
USTPUTC(c, nextc);
}
}
#if ENABLE_ASH_BASH_COMPAT
case VSSUBSTR:
loc = str = stackblock() + strloc;
-// TODO: number() instead? It does error checking...
- pos = atoi(loc);
+ /* Read POS in ${var:POS:LEN} */
+ pos = atoi(loc); /* number(loc) errors out on "1:4" */
len = str - startp - 1;
/* *loc != '\0', guaranteed by parser */
if (quotes) {
char *ptr;
- /* We must adjust the length by the number of escapes we find. */
+ /* Adjust the length by the number of escapes */
for (ptr = startp; ptr < (str - 1); ptr++) {
if (*ptr == CTLESC) {
len--;
orig_len = len;
if (*loc++ == ':') {
-// TODO: number() instead? It does error checking...
- len = atoi(loc);
+ /* ${var::LEN} */
+ len = number(loc);
} else {
+ /* Skip POS in ${var:POS:LEN} */
len = orig_len;
- while (*loc && *loc != ':')
+ while (*loc && *loc != ':') {
+ /* TODO?
+ * bash complains on: var=qwe; echo ${var:1a:123}
+ if (!isdigit(*loc))
+ ash_msg_and_raise_error(msg_illnum, str);
+ */
loc++;
- if (*loc++ == ':')
-// TODO: number() instead? It does error checking...
- len = atoi(loc);
+ }
+ if (*loc++ == ':') {
+ len = number(loc);
+ }
}
if (pos >= orig_len) {
pos = 0;
ap = shellparam.p;
if (!ap)
return -1;
- while ((p = *ap++)) {
+ while ((p = *ap++) != NULL) {
size_t partlen;
partlen = strlen(p);
case '7':
case '8':
case '9':
-// TODO: number() instead? It does error checking...
- num = atoi(name);
+ num = number(name);
if (num < 0 || num > shellparam.nparam)
return -1;
p = num ? shellparam.p[num - 1] : arg0;
p++;
if (*p == '.')
matchdot++;
- while (!intpending && (dp = readdir(dirp)) != NULL) {
+ while (!pending_int && (dp = readdir(dirp)) != NULL) {
if (dp->d_name[0] == '.' && !matchdot)
continue;
if (pmatch(start, dp->d_name)) {
break;
}
exitstatus = exerrno;
- TRACE(("shellexec failed for %s, errno %d, suppressint %d\n",
- argv[0], e, suppressint));
+ TRACE(("shellexec failed for %s, errno %d, suppress_int %d\n",
+ argv[0], e, suppress_int));
ash_msg_and_raise(EXEXEC, "%s: %s", argv[0], errmsg(e, "not found"));
/* NOTREACHED */
}
uint8_t savestatus;
savestatus = exitstatus;
- pendingsig = 0;
+ pending_sig = 0;
xbarrier();
TRACE(("dotrap entered\n"));
out1:
if (checkexit & exitstatus)
evalskip |= SKIPEVAL;
- else if (pendingsig && dotrap())
+ else if (pending_sig && dotrap())
goto exexit;
if (flags & EV_EXIT) {
if (i == EXINT)
exit_status = 128 + SIGINT;
if (i == EXSIG)
- exit_status = 128 + pendingsig;
+ exit_status = 128 + pending_sig;
exitstatus = exit_status;
if (i == EXINT || spclbltin > 0) {
raise:
exitstatus |= ferror(stdout);
clearerr(stdout);
commandname = savecmdname;
-// exsig = 0;
exception_handler = savehandler;
return i;
int n = argv[1] ? number(argv[1]) : 1;
if (n <= 0)
- ash_msg_and_raise_error(illnum, argv[1]);
+ ash_msg_and_raise_error(msg_illnum, argv[1]);
if (n > loopnest)
n = loopnest;
if (n > 0) {
mask = 0;
do {
if (*ap >= '8' || *ap < '0')
- ash_msg_and_raise_error(illnum, argv[1]);
+ ash_msg_and_raise_error(msg_illnum, argv[1]);
mask = (mask << 3) + (*ap - '0');
} while (*++ap != '\0');
umask(mask);