* rewrites.
*
* Other credits:
- * simple_itoa() was lifted from boa-0.93.15
* b_addchr() derived from similar w_addchar function in glibc-2.2
* setup_redirect(), redirect_opt_num(), and big chunks of main()
* and many builtins derived from contributions by Erik Andersen
/* belongs in busybox.h */
static int max(int a, int b)
{
- return (a>b)?a:b;
+ return (a > b) ? a : b;
}
/* This should be in utility.c */
return b_addchr(o, ch);
}
-/* belongs in utility.c */
-static char *simple_itoa(unsigned i)
-{
- static char local[sizeof(int)*3 + 2];
- char *p = &local[sizeof(int)*3 + 2 - 1];
- *p-- = '\0';
- do {
- *p-- = '0' + i % 10;
- i /= 10;
- } while (i > 0);
- return p + 1;
-}
-
static int b_adduint(o_string *o, unsigned i)
{
int r;
- char *p = simple_itoa(i);
+ char buf[sizeof(unsigned)*3 + 1];
+ char *p = buf;
+ *(utoa_to_buf(i, buf, sizeof(buf))) = '\0';
/* no escape checking necessary */
do r = b_addchr(o, *p++); while (r == 0 && *p);
return r;
{ "do", RES_DO, FLAG_DONE },
{ "done", RES_DONE, FLAG_END }
};
+ enum { NRES = sizeof(reserved_list)/sizeof(reserved_list[0]) };
const struct reserved_combo *r;
-#define NRES sizeof(reserved_list)/sizeof(reserved_list[0])
for (r = reserved_list; r < reserved_list+NRES; r++) {
if (strcmp(dest->data, r->literal) == 0) {
struct child_prog *prog = ctx->child;
if (prog && prog->group == NULL
- && prog->argv == NULL
- && prog->redirects == NULL) {
+ && prog->argv == NULL
+ && prog->redirects == NULL
+ ) {
debug_printf("done_command: skipping null command\n");
return 0;
- } else if (prog) {
+ }
+ if (prog) {
pi->num_progs++;
debug_printf("done_command: num_progs incremented to %d\n", pi->num_progs);
} else {
return -3; /* "-" represents "close me" */
}
while (isdigit(ch)) {
- d = d*10+(ch-'0');
+ d = d*10 + (ch-'0');
ok = 1;
b_getch(input);
ch = b_peek(input);
} else if (pid == 0) {
close(channel[0]);
if (channel[1] != 1) {
- dup2(channel[1],1);
+ dup2(channel[1], 1);
close(channel[1]);
}
_exit(run_list_real(head)); /* leaks memory */
#define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
-/* PROTOTYPES */
-static int newfile(char *s);
-
-
struct brkcon {
jmp_buf brkpt;
struct brkcon *nextlev;
* -u: unset variables net diagnostic
*/
static char flags['z' - 'a' + 1];
-/* this looks weird, but is OK ... we index flag with 'a'...'z' */
-static char *flag = flags - 'a';
+/* this looks weird, but is OK ... we index FLAG with 'a'...'z' */
+#define FLAG (flags - 'a')
/* moved to G: static char *trap[_NSIG + 1]; */
/* moved to G: static char ourtrap[_NSIG + 1]; */
static int inparse;
static char *null = (char*)""; /* null value for variable */
static int heedint = 1; /* heed interrupt signals */
-static void (*qflag) (int) = SIG_IGN;
+static void (*qflag)(int) = SIG_IGN;
static int startl;
static int peeksym;
static int nlseen;
exstat = -1;
}
prs("\n");
- if (flag['e'])
+ if (FLAG['e'])
leave();
}
static void err(const char *s)
{
warn(s);
- if (flag['n'])
+ if (FLAG['n'])
return;
if (!interactive)
leave();
cp = m;
for (c = 'a'; c <= 'z'; c++)
- if (flag[c])
+ if (FLAG[c])
*cp++ = c;
*cp = '\0';
setval(lookup("-"), m);
intr = 0;
execflg = 0;
- if (!flag['n']) {
+ if (!FLAG['n']) {
DBGPRINTF(("ONECOMMAND: calling execute, t=outtree=%p\n",
outtree));
execute(outtree, NOPIPE, NOPIPE, 0);
/* strip all initial assignments */
/* not correct wrt PATH=yyy command etc */
- if (flag['x']) {
+ if (FLAG['x']) {
DBGPRINTF9(("FORKEXEC: echo'ing, cp=%p, wp=%p, owp=%p\n",
cp, wp, owp));
echo(cp ? wp : owp);
/* bad: t->words++; */
for (n = 0; (t->words[n] = t->words[n + 1]) != NULL; n++);
if (*++cp == 0)
- flag['x'] = flag['v'] = 0;
+ FLAG['x'] = FLAG['v'] = 0;
else {
for (; *cp; cp++) {
switch (*cp) {
case 'e':
if (!interactive)
- flag['e']++;
+ FLAG['e']++;
break;
default:
if (*cp >= 'a' && *cp <= 'z')
- flag[(int) *cp]++;
+ FLAG[(int) *cp]++;
break;
}
}
if (newenv(setjmp(errpt)) == 0) {
while (*ap && isassign(*ap))
expand(*ap++, &wb, f & ~DOGLOB);
- if (flag['k']) {
+ if (FLAG['k']) {
for (wf = ap; *wf; wf++) {
if (isassign(*wf))
expand(*wf, &wb, f & ~DOGLOB);
}
}
for (wb = addword((char *) 0, wb); *ap; ap++) {
- if (!flag['k'] || !isassign(*ap))
+ if (!FLAG['k'] || !isassign(*ap))
expand(*ap, &wb, f & ~DOKEY);
}
wb = addword((char *) 0, wb);
}
} else if (c == '+')
dolp = strsave(cp, areanum);
- if (flag['u'] && dolp == null) {
+ if (FLAG['u'] && dolp == null) {
prs("unset variable: ");
err(s);
gflg++;
static void ioecho(char c)
{
- if (flag['v'])
+ if (FLAG['v'])
write(2, &c, sizeof c);
}
interactive++;
default:
if (*s >= 'a' && *s <= 'z')
- flag[(int) *s]++;
+ FLAG[(int) *s]++;
}
} else {
argv--;