Edata jreturn, star;
if (sigsetjmp(j.j, 1))
return;
- starassign(*av, av+1, TRUE);
+ starassign(*av, av+1, true);
jreturn.jb = &j;
star.name = "*";
except(eReturn, jreturn, &e1);
except(eVarstack, star, &e2);
- walk(treecpy(fnlookup(*av), nalloc), TRUE);
- varrm("*", TRUE);
+ walk(treecpy(fnlookup(*av), nalloc), true);
+ varrm("*", true);
unexcept(); /* eVarstack */
unexcept(); /* eReturn */
}
static void arg_count(char *name) {
fprint(2, RC "too many arguments to %s\n", name);
- set(FALSE);
+ set(false);
}
static void badnum(char *num) {
fprint(2, RC "`%s' is a bad number\n", num);
- set(FALSE);
+ set(false);
}
/* a dummy command. (exec() performs "exec" simply by not forking) */
av++;
}
fprint(1, format, av);
- set(TRUE);
+ set(true);
}
/* cd. traverse $cdpath if the directory given is not an absolute pathname */
}
if (isabsolute(*av) || streq(*av, ".") || streq(*av, "..")) { /* absolute pathname? */
if (chdir(*av) < 0) {
- set(FALSE);
+ set(false);
uerror(*av);
} else
- set(TRUE);
+ set(true);
} else {
s = varlookup("cdpath");
if (s == NULL) {
path = *av;
}
if (chdir(path) >= 0) {
- set(TRUE);
+ set(true);
if (interactive && *s->w != '\0' && !streq(s->w, "."))
fprint(1, "%s\n", path);
return;
s = s->n;
} while (s != NULL);
fprint(2, "couldn't cd to %s\n", *av);
- set(FALSE);
+ set(false);
}
}
static void b_umask(char **av) {
int i;
if (*++av == NULL) {
- set(TRUE);
+ set(true);
i = umask(0);
umask(i);
fprint(1, "0%o\n", i);
i = o2u(*av);
if ((unsigned int) i > 0777) {
fprint(2, "bad umask\n");
- set(FALSE);
+ set(false);
} else {
umask(i);
- set(TRUE);
+ set(true);
}
} else {
arg_count("umask");
}
if (s == NULL && shift != 0) {
fprint(2, "cannot shift\n");
- set(FALSE);
+ set(false);
} else {
- varassign("*", append(dollarzero, s), FALSE);
- set(TRUE);
+ varassign("*", append(dollarzero, s), false);
+ set(true);
}
}
badnum(av[1]);
return;
}
- if (rc_wait4(pid, &status, FALSE) > 0)
+ if (rc_wait4(pid, &status, false) > 0)
setstatus(pid, status);
else
- set(FALSE);
+ set(false);
sigchk();
}
is defined as a variable, function or pathname.
*/
-#define not(b) ((b)^TRUE)
+#define not(b) ((b)^true)
#define show(b) (not(eff|vee|pee|bee|ess)|(b))
static bool issig(char *s) {
int i;
for (i = 0; i < NSIG; i++)
if (streq(s, signals[i].name))
- return TRUE;
- return FALSE;
+ return true;
+ return false;
}
/* push a string to be eval'ed onto the input stack. evaluate it */
bool i = interactive;
if (av[1] == NULL)
return;
- interactive = FALSE;
+ interactive = false;
pushstring(av + 1, i); /* don't reset line numbers on noninteractive eval */
- doit(TRUE);
+ doit(true);
interactive = i;
}
extern void b_dot(char **av) {
int fd;
- bool old_i = interactive, i = FALSE;
+ bool old_i = interactive, i = false;
Estack e;
Edata star;
av++;
return;
if (streq(*av, "-i")) {
av++;
- i = TRUE;
+ i = true;
}
- if (dasheye) { /* rc -i file has to do the right thing. reset the dasheye state to FALSE, though. */
- dasheye = FALSE;
- i = TRUE;
+ if (dasheye) { /* rc -i file has to do the right thing. reset the dasheye state to false, though. */
+ dasheye = false;
+ i = true;
}
if (*av == NULL)
return;
fd = rc_open(*av, rFrom);
if (fd < 0) {
uerror(*av);
- set(FALSE);
+ set(false);
return;
}
- starassign(*av, av+1, TRUE);
+ starassign(*av, av+1, true);
interactive = i;
pushfd(fd);
star.name = "*";
except(eVarstack, star, &e);
- doit(TRUE);
- varrm("*", TRUE);
+ doit(true);
+ varrm("*", true);
unexcept(); /* eVarstack */
interactive = old_i;
}
*limit = 1;
if (streq(s, "unlimited")) {
*limit = RLIM_INFINITY;
- return TRUE;
+ return true;
}
if (suf == TIMESUF && (t = strchr(s, ':')) != NULL) {
int min, sec;
*t++ = '\0';
min = a2u(s); sec = a2u(t);
- if (min == -1 || sec == -1) return FALSE;
+ if (min == -1 || sec == -1) return false;
*limit = 60 * min + sec;
} else {
int n;
break;
}
n = a2u(s);
- if (n == -1) return FALSE;
+ if (n == -1) return false;
*limit *= n;
}
- return TRUE;
+ return true;
}
static void b_limit(char **av) {
const struct Limit *lp = limits;
- bool hard = FALSE;
+ bool hard = false;
if (*++av != NULL && streq(*av, "-h")) {
av++;
- hard = TRUE;
+ hard = true;
}
if (*av == NULL) {
for (; lp->name != NULL; lp++)
for (;; lp++) {
if (lp->name == NULL) {
fprint(2, "no such limit\n");
- set(FALSE);
+ set(false);
return;
}
if (streq(*av, lp->name))
getrlimit(lp->flag, &rlim);
if (!parselimit(lp, &pl, *av)) {
fprint(2, "bad limit\n");
- set(FALSE);
+ set(false);
return;
}
if (hard)
rlim.rlim_cur = pl;
if (setrlimit(lp->flag, &rlim) == -1) {
uerror("setrlimit");
- set(FALSE);
+ set(false);
} else
- set(TRUE);
+ set(true);
}
}
not. A signal goes to the last interactive level. (see below)
*/
-bool nl_on_intr = TRUE;
+bool nl_on_intr = true;
static Estack *estack;
default:
break;
case eVarstack:
- varrm(estack->data.name, TRUE);
+ varrm(estack->data.name, true);
break;
case eArena:
restoreblock(estack->data.b);
extern void rc_error(char *s) {
pr_error(s, -1);
- set(FALSE);
+ set(false);
redirq = NULL;
- cond = FALSE; /* no longer inside conditional */
+ cond = false; /* no longer inside conditional */
rc_raise(eError);
}
/* this is the newline you see when you hit ^C while typing a command */
if (interactive && nl_on_intr)
fprint(2, "\n");
- nl_on_intr = TRUE;
+ nl_on_intr = true;
redirq = NULL;
- cond = FALSE;
+ cond = false;
rc_raise(eError);
}
char *path = NULL;
bool didfork, returning, saw_exec, saw_builtin;
av = list2array(s, dashex);
- saw_builtin = saw_exec = FALSE;
+ saw_builtin = saw_exec = false;
do {
if (*av == NULL || isabsolute(*av))
b = NULL;
a builtin applies only to the immmediately following
command, e.g., builtin exec echo hi
*/
- saw_builtin = FALSE;
+ saw_builtin = false;
if (b == b_exec) {
av++;
- saw_exec = TRUE;
- parent = FALSE;
+ saw_exec = true;
+ parent = false;
} else if (b == b_builtin) {
av++;
- saw_builtin = TRUE;
+ saw_builtin = true;
}
} while (b == b_exec || b == b_builtin);
if (*av == NULL && saw_exec) { /* do redirs and return on a null exec */
if (saw_exec)
rc_pid = -1;
if (b == NULL) {
- path = which(*av, TRUE);
+ path = which(*av, true);
if (path == NULL && *av != NULL) { /* perform null commands for redirections */
- set(FALSE);
+ set(false);
redirq = NULL;
if (parent)
return;
*/
if ((parent && (b == NULL || redirq != NULL)) || outstanding_cmdarg()) {
pid = rc_fork();
- didfork = TRUE;
+ didfork = true;
} else {
pid = 0;
- didfork = FALSE;
+ didfork = false;
}
returning = (!didfork && parent);
switch (pid) {
/* NOTREACHED */
case 0:
if (!returning)
- setsigdefaults(FALSE);
- pop_cmdarg(FALSE);
+ setsigdefaults(false);
+ pop_cmdarg(false);
doredirs();
/* null commands performed for redirections */
/* NOTREACHED */
default:
redirq = NULL;
- rc_wait4(pid, &stat, TRUE);
+ rc_wait4(pid, &stat, true);
setstatus(-1, stat);
/*
There is a very good reason for having this weird
vector.
*/
if (WIFEXITED(stat))
- nl_on_intr = FALSE;
+ nl_on_intr = false;
sigchk();
- nl_on_intr = TRUE;
- pop_cmdarg(TRUE);
+ nl_on_intr = true;
+ pop_cmdarg(true);
}
}
static void fn_handler(int), dud_handler(int);
-static bool runexit = FALSE;
+static bool runexit = false;
static Node *handlers[NSIG], null;
static void (*def_sigint)(int) = SIG_DFL;
static void (*def_sigquit)(int) = SIG_DFL;
}
}
delete_fn("sigexit");
- runexit = FALSE; /* No sigexit on subshells */
+ runexit = false; /* No sigexit on subshells */
}
/* rc's exit. if runexit is set, run the sigexit function. */
char *sig[2];
sig[0] = "sigexit";
sig[1] = NULL;
- runexit = FALSE;
+ runexit = false;
funcall(sig);
stat = getstatus();
}
new->extdef = NULL;
if (strncmp(name, "sig", conststrlen("sig")) == 0) { /* slight optimization */
if (streq(name, "sigexit"))
- runexit = TRUE;
+ runexit = true;
for (i = 1; i < NSIG; i++) /* zero is a bogus signal */
if (streq(signals[i].name, name)) {
handlers[i] = newdef;
}
}
if (streq(name, "sigexit"))
- runexit = FALSE;
+ runexit = false;
delete_fn(name);
}
fmtprint(f, "__%02x", c);
else
fmtputc(f, c);
- return FALSE;
+ return false;
}
#endif
case rHerestring: name = "<<<"; break;
}
fmtcat(f, name);
- return FALSE;
+ return false;
}
/* defaultfd -- return the default fd for a given redirection operation */
if (n == NULL) {
fmtprint(f, "()");
- return FALSE;
+ return false;
}
switch (n->type) {
case nBang: fmtprint(f, "!%T", n->u[0].p); break;
case nLappend: {
static bool inlist;
if (!inlist) {
- inlist = TRUE;
+ inlist = true;
fmtprint(f, "(%T %T)", n->u[0].p, n->u[1].p);
- inlist = FALSE;
+ inlist = false;
} else {
fmtprint(f, "%T %T", n->u[0].p, n->u[1].p);
}
break;
}
}
- return FALSE;
+ return false;
}
/* convert a List to an array, for execve() */
while (*++a != NULL)
fmtprint(f, " %s", *a);
}
- return FALSE;
+ return false;
}
/* %L -- print a list */
if (n != NULL) fmtputc(f, *sep);
}
}
- return FALSE;
+ return false;
}
/* %W -- print a list for exporting */
n = l->n;
if (n != NULL) fmtputc(f, ENV_SEP);
}
- return FALSE;
+ return false;
}
#define ISMETA(c) (c == '*' || c == '?' || c == '[')
bool metaquote = (f->flags & FMT_leftside) != 0; /* '-' */
if (*s == '\0') {
fmtprint(f, "''");
- return FALSE;
+ return false;
}
if (!quoted) {
while ((c = *t++) != '\0')
if (nw[c] == 1 || (metaquote && ISMETA(c)))
goto quoteit;
fmtprint(f, "%s", s);
- return FALSE;
+ return false;
}
quoteit:
fmtputc(f, '\'');
}
fmtputc(f, '\'');
- return FALSE;
+ return false;
}
void initprint(void) {
List *q;
if (s == NULL) {
if (p == NULL) /* null matches null */
- return TRUE;
+ return true;
for (; p != NULL; p = p->n) /* one or more stars match null */
if (strspn(p->w, "*") == strlen(p->w) &&
p->m != NULL && strlen(p->m) == strlen(p->w))
- return TRUE;
- return FALSE;
+ return true;
+ return false;
}
for (; s != NULL; s = s->n)
for (q = p; q != NULL; q = q->n)
if (match(q->w, q->m, s->w))
- return TRUE;
- return FALSE;
+ return true;
+ return false;
}
/*
extern List *glob(List *s) {
List *top, *r;
bool meta;
- for (r = s, meta = FALSE; r != NULL; r = r->n)
+ for (r = s, meta = false; r != NULL; r = r->n)
if (r->m != NULL)
- meta = TRUE;
+ meta = true;
if (!meta)
return s; /* don't copy lists with no metacharacters in them */
for (top = r = NULL; s != NULL; s = s->n) {
return a match if there are no metacharacters; allows globbing through
directories with no read permission. make sure the file exists, though.
*/
- matched = TRUE;
+ matched = true;
if (m != NULL)
for (i = 0; p[i] != '\0'; i++)
if (m[i]) {
- matched = FALSE;
+ matched = false;
break;
}
}
while ((dp = readdir(dirp)) != NULL)
if ((*dp->d_name != '.' || *p == '.') && match(p, m, dp->d_name)) { /* match ^. explicitly */
- matched = TRUE;
+ matched = true;
if (top == NULL)
top = r = nnew(List);
else
if (nel > 1) {
char **a;
List *t;
- qsort(a = list2array(s, FALSE), nel, sizeof(char *), starstrcmp);
+ qsort(a = list2array(s, false), nel, sizeof(char *), starstrcmp);
for (t = s; t != NULL; t = t->n)
t->w = *a++;
}
int n, state; /* a simple FSA is used to read in data */
memzero(isifs, sizeof isifs);
- for (isifs['\0'] = TRUE; ifs != NULL; ifs = ifs->n)
+ for (isifs['\0'] = true; ifs != NULL; ifs = ifs->n)
for (s = ifs->w; *s != '\0'; s++)
- isifs[*(unsigned char *)s] = TRUE;
+ isifs[*(unsigned char *)s] = true;
remain = bufsize = BUFSIZE;
top = r = nnew(List);
r->w = end = nalloc(bufsize + 1);
mvfd(p[1], 1);
close(p[0]);
redirq = NULL;
- walk(n, FALSE);
+ walk(n, false);
exit(getstatus());
}
close(p[1]);
bq = bqinput(glom(ifs), p[0]);
close(p[0]);
- rc_wait4(pid, &sp, TRUE);
+ rc_wait4(pid, &sp, true);
statprint(-1, sp);
- varassign("bqstatus", word(strstatus(sp), NULL), FALSE);
+ varassign("bqstatus", word(strstatus(sp), NULL), false);
sigchk();
return bq;
}
return NULL;
}
if (rc_fork() == 0) {
- setsigdefaults(FALSE);
+ setsigdefaults(false);
fd = rc_open(name, (n->u[0].i != rFrom) ? rFrom : rCreate); /* stupid hack */
if (fd < 0) {
uerror("open");
if (mvfd(fd, (n->u[0].i == rFrom)) < 0) /* same stupid hack */
exit(1);
redirq = NULL;
- walk(n->u[2].p, FALSE);
+ walk(n->u[2].p, false);
exit(getstatus());
}
efifo.name = name;
static char **env;
static int bozosize;
static int envsize;
-static bool env_dirty = TRUE;
+static bool env_dirty = true;
static char *dead = "";
#define HASHSIZE 64 /* rc was debugged with HASHSIZE == 2; 64 is about right for normal use */
Htab *newhtab;
if (ht == fp) {
if (fsize > 2 * fused)
- return FALSE;
+ return false;
size = fsize;
} else {
if (vsize > 2 * vused)
- return FALSE;
+ return false;
size = vsize;
}
newsize = 2 * size;
vsize = newsize;
}
efree(ht);
- return TRUE;
+ return true;
}
#define varfind(s) find(s, vp, vsize)
extern rc_Function *get_fn_place(char *s) {
int h = fnfind(s);
- env_dirty = TRUE;
+ env_dirty = true;
if (fp[h].name == NULL) {
if (rehash(fp))
h = fnfind(s);
Variable *new;
int h = varfind(s);
- env_dirty = TRUE;
+ env_dirty = true;
if (vp[h].name == NULL) {
if (rehash(vp))
int h = fnfind(s);
if (fp[h].name == NULL)
return; /* not found */
- env_dirty = TRUE;
+ env_dirty = true;
free_fn(fp[h].p);
efree(fp[h].p);
efree(fp[h].name);
Variable *v;
if (vp[h].name == NULL)
return; /* not found */
- env_dirty = TRUE;
+ env_dirty = true;
v = vp[h].p;
efree(v->extdef);
listfree(v->def);
};
/* for a few variables that have default values, we export them only
-if they've been explicitly set; maybeexport[n].flag is TRUE if this
+if they've been explicitly set; maybeexport[n].flag is true if this
has occurred. */
struct nameflag {
char *name;
bool flag;
};
static struct nameflag maybeexport[] = {
- { "prompt", FALSE },
- { "version", FALSE }
+ { "prompt", false },
+ { "version", false }
};
void set_exportable(char *s, bool b) {
int i;
for (i = 0; i < arraysize(neverexport); i++)
if (streq(s, neverexport[i]))
- return FALSE;
+ return false;
for (i = 0; i < arraysize(maybeexport); i++)
- if (maybeexport[i].flag == FALSE && streq(s, maybeexport[i].name))
- return FALSE;
- return TRUE;
+ if (maybeexport[i].flag == false && streq(s, maybeexport[i].name))
+ return false;
+ return true;
}
static bool fn_exportable(char *s) {
if (strncmp(s, "sig", conststrlen("sig")) == 0) { /* small speed hack */
for (i = 0; i < NSIG; i++)
if (streq(s, signals[i].name))
- return FALSE;
+ return false;
if (streq(s, "sigexit"))
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
extern char **makeenv() {
char *v;
if (!env_dirty)
return env;
- env_dirty = FALSE;
+ env_dirty = false;
ep = bozosize;
if (vsize + fsize + 1 + bozosize > envsize) {
envsize = 2 * (bozosize + vsize + fsize + 1);
bool quoted;
} *hq;
-static bool dead = FALSE;
+static bool dead = false;
/*
* read in a heredocument. A clever trick: skip over any partially matched end-of-file
size_t bufsize;
t = buf = nalloc(bufsize = 512);
bufend = &buf[bufsize];
- dead = FALSE;
+ dead = false;
#define RESIZE(extra) { \
char *nbuf; \
bufsize = bufsize * 2 + extra; \
for (;; c = gchar()) {
if (c == EOF) {
yyerror("heredoc incomplete");
- dead = TRUE;
+ dead = true;
return NULL;
}
if (t + 1 >= bufend)
static Node *parseheredoc(char *s) {
int c = *s;
Node *result = NULL;
- while (TRUE) {
+ while (true) {
Node *node;
switch (c) {
default: {
hq = NULL;
if (end) {
yyerror("heredoc incomplete");
- return FALSE;
+ return false;
}
do {
Node *n = here->doc;
char *s = readheredoc(here->name);
if (dead)
- return FALSE;
- n->u[2].p = here->quoted ? mk(nWord, s, NULL, FALSE) : parseheredoc(s);
+ return false;
+ n->u[2].p = here->quoted ? mk(nWord, s, NULL, false) : parseheredoc(s);
n->u[0].i = rHerestring;
} while ((here = here->n) != NULL);
}
- return TRUE;
+ return true;
}
/* queue pending heredocs into a queue. called from yyparse */
if (name->type != nWord) {
yyerror("eof-marker not a single literal word");
skiptonl();
- return FALSE;
+ return false;
}
for (prev = &hq; (new = *prev) != NULL; prev = &new->n)
;
new->quoted = name->u[2].i;
new->doc = n;
new->n = NULL;
- return TRUE;
+ return true;
}
static char *inbuf;
static size_t istacksize, chars_out, chars_in;
-static bool save_lineno = TRUE;
+static bool save_lineno = true;
static Input *istack, *itop;
int lastchar;
extern void pushfd(int fd) {
pushcommon();
- save_lineno = TRUE;
+ save_lineno = true;
istack->fd = fd;
lineno = 1;
istack->t = iFd;
Edata jerror;
if (dashen)
- clobberexecit = FALSE;
+ clobberexecit = false;
execit = clobberexecit;
sigsetjmp(j.j, 1);
jerror.jb = &j;
except(eError, jerror, &e1);
- for (eof = FALSE; !eof;) {
+ for (eof = false; !eof;) {
Edata block;
Estack e2;
if (interactive) {
List *s;
if (!dashen && fnlookup("prompt") != NULL) {
- static bool died = FALSE;
+ static bool died = false;
static char *arglist[] = { "prompt", NULL };
if (!died) {
- died = TRUE;
+ died = true;
funcall(arglist);
}
- died = FALSE;
+ died = false;
}
s = varlookup("prompt");
if (s != NULL) {
eof = (lastchar == EOF); /* "lastchar" can be clobbered during a walk() */
if (parsetree != NULL) {
if (execit)
- walk(parsetree, TRUE);
+ walk(parsetree, true);
else if (dashex && dashen)
fprint(2, "%T\n", parsetree);
}
Node *fun;
in[0] = extdef;
in[1] = NULL;
- interactive = FALSE;
- pushstring(in, TRUE);
- fun = doit(FALSE);
+ interactive = false;
+ pushstring(in, true);
+ fun = doit(false);
interactive = i;
return fun;
}
special cases. In our case, \ cannot be a word character, since
we wish to read in all word characters in a tight loop.
- Note: to save the trouble of declaring these arrays with TRUEs
- and FALSEs, I am assuming that FALSE = 0, TRUE = 1. (and so is
+ Note: to save the trouble of declaring these arrays with trues
+ and falses, I am assuming that false = 0, true = 1. (and so is
it declared in rc.h)
*/
static size_t bufsize = BUFSIZE;
static char *realbuf = NULL;
-static bool newline = FALSE;
-static bool errset = FALSE;
-static bool prerror = FALSE;
+static bool newline = false;
+static bool errset = false;
+static bool prerror = false;
static wordstates w = NW;
static int fd_left, fd_right;
meta = dollar ? dnw : q;
while ((c = *s++))
if (meta[c])
- return TRUE;
- return FALSE;
+ return true;
+ return false;
}
extern int yylex() {
- static bool dollar = FALSE;
- bool saw_meta = FALSE;
+ static bool dollar = false;
+ bool saw_meta = false;
int c;
size_t i; /* The purpose of all these local assignments is to */
const char *meta; /* allow optimizing compilers like gcc to load these */
char *buf = realbuf; /* values into registers. On a sparc this is a */
YYSTYPE *y = &yylval; /* win, in code size *and* execution time */
if (errset) {
- errset = FALSE;
+ errset = false;
return '\n';
}
/* rc variable-names may contain only alnum, '*' and '_', so use dnw if we are scanning one. */
if (newline) {
--lineno; /* slight space optimization; nextline() always increments lineno */
nextline();
- newline = FALSE;
+ newline = false;
}
top: while ((c = gchar()) == ' ' || c == '\t')
w = NW;
- if (c != '(') dollar = FALSE;
+ if (c != '(') dollar = false;
if (c == EOF)
return END;
if (!meta[(unsigned char) c]) { /* it's a word or keyword. */
read: do {
buf[i++] = c;
if (c == '?' || c == '[' || c == '*')
- saw_meta = TRUE;
+ saw_meta = true;
if (i >= bufsize)
buf = realbuf = erealloc(buf, bufsize *= 2);
} while ((c = gchar()) != EOF && !meta[(unsigned char) c]);
} else {
y->word.m = NULL;
}
- y->word.q = FALSE;
+ y->word.q = false;
return WORD;
}
if (c == '`' || c == '!' || c == '@' || c == '~' || c == '$' || c == '\'') {
ugchar(c);
return '`';
case '$':
- dollar = TRUE;
+ dollar = true;
c = gchar();
if (c == '#')
return COUNT;
buf[i] = '\0';
y->word.w = ncpy(buf);
y->word.m = NULL;
- y->word.q = TRUE;
+ y->word.q = true;
return WORD;
case '\\':
if ((c = gchar()) == '\n') {
/* FALLTHROUGH */
case '\n':
lineno++;
- newline = TRUE;
+ newline = true;
/* FALLTHROUGH */
case ';':
case '^':
extern void yyerror(const char *s) {
char *tok;
if (prerror) { /* don't print "syntax error" if there's a more informative scanerror */
- prerror = FALSE;
+ prerror = false;
return;
}
if (!interactive) {
extern void scanerror(char *s) {
skiptonl(); /* flush up to newline */
yyerror(s);
- errset = prerror = TRUE;
+ errset = prerror = true;
}
extern void inityy() {
- newline = FALSE;
+ newline = false;
w = NW;
hq = NULL;
/* return memory to the system if the buffer got too large */
dashell = (*argv[0] == '-'); /* login shell, per unix tradition */
OPTBEGIN {
- case 'd': dashdee = TRUE; break;
- case 'e': dashee = TRUE; break;
- case 'l': dashell = TRUE; break;
- case 'n': dashen = TRUE; break;
- case 'o': dashoh = TRUE; break;
- case 'p': dashpee = TRUE; break;
- case 's': dashess = TRUE; break;
- case 'v': dashvee = TRUE; break;
- case 'x': dashex = TRUE; break;
+ case 'd': dashdee = true; break;
+ case 'e': dashee = true; break;
+ case 'l': dashell = true; break;
+ case 'n': dashen = true; break;
+ case 'o': dashoh = true; break;
+ case 'p': dashpee = true; break;
+ case 's': dashess = true; break;
+ case 'v': dashvee = true; break;
+ case 'x': dashex = true; break;
case 'i':
- dasheye = TRUE;
- interactive = TRUE;
+ dasheye = true;
+ interactive = true;
break;
case 'I':
- dashEYE = TRUE;
- interactive = FALSE;
+ dashEYE = true;
+ interactive = false;
break;
case 'c':
dashsee[0] = EOPTARG(usage());
initenv(envp);
initinput();
null[0] = NULL;
- starassign(dollarzero, null, FALSE); /* assign $0 to $* */
+ starassign(dollarzero, null, false); /* assign $0 to $* */
inithandler();
if (dashell) {
pushfd(fd);
push_interactive = interactive;
- interactive = FALSE;
- doit(TRUE);
+ interactive = false;
+ doit(true);
interactive = push_interactive;
close(fd);
}
if (dashsee[0] != NULL || dashess) { /* input from -c or -s? */
if (*argv != NULL)
- starassign(dollarzero, argv, FALSE);
+ starassign(dollarzero, argv, false);
if (dashess)
pushfd(0);
else
- pushstring(dashsee, TRUE);
+ pushstring(dashsee, true);
} else if (*argv != NULL) { /* else from a file? */
b_dot(--argv);
rc_exit(getstatus());
} else { /* else stdin */
pushfd(0);
}
- dasheye = FALSE;
- doit(TRUE);
+ dasheye = false;
+ doit(true);
rc_exit(getstatus());
return 0; /* Never really reached. */
}
va_start(ap, name);
for (l = NULL; (v = va_arg(ap, char *)) != NULL;)
l = append(l, word(v, NULL));
- varassign(name, l, FALSE);
- set_exportable(name, FALSE);
+ varassign(name, l, false);
+ set_exportable(name, false);
if (streq(name, "path"))
- alias(name, l, FALSE);
+ alias(name, l, false);
va_end(ap);
}
switch (p[i++]) {
case '?':
if (*s++ == '\0')
- return FALSE;
+ return false;
break;
case '*':
while (p[i] == '*' && m[i] == 1) /* collapse multiple stars */
i++;
if (p[i] == '\0') /* star at end of pattern? */
- return TRUE;
+ return true;
while (*s != '\0')
if (match(p + i, m + i, s++))
- return TRUE;
- return FALSE;
+ return true;
+ return false;
case '[':
if (*s == '\0')
- return FALSE;
+ return false;
switch (j = rangematch(p + i, *s)) {
default:
i += j;
break;
case RANGE_FAIL:
- return FALSE;
+ return false;
case RANGE_ERROR:
if (*s != '[')
- return FALSE;
+ return false;
}
s++;
break;
default:
panic("bad metacharacter in match");
/* NOTREACHED */
- return FALSE; /* hush up gcc -Wall */
+ return false; /* hush up gcc -Wall */
}
} else if (p[i++] != *s++)
- return FALSE;
+ return false;
}
}
static int rangematch(char *p, char c) {
char *orig = p;
bool neg = (*p == '~');
- bool matched = FALSE;
+ bool matched = false;
if (neg)
p++;
if (*p == ']') {
rc_error(NULL);
}
if (! (flags & O_NONBLOCK))
- return FALSE;
+ return false;
flags &= ~O_NONBLOCK;
if (fcntl(fd, F_SETFL, (long) flags) == -1) {
uerror("fcntl");
rc_error(NULL);
}
- return TRUE;
+ return true;
}
-/* make a file descriptor the same pgrp as us. Returns TRUE if
+/* make a file descriptor the same pgrp as us. Returns true if
it changes anything. */
extern bool makesamepgrp(int fd) {
grp = getpgrp();
if (tcgetpgrp(fd) == grp)
- return FALSE;
+ return false;
if (tcsetpgrp(fd, grp) < 0) {
uerror("tcsetgrp");
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
#define Flag(name, flag) \
static bool name(Format *format, int ignore) { \
format->flags |= flag; \
- return TRUE; \
+ return true; \
}
Flag(uconv, FMT_unsigned)
format->flags |= FMT_f1set;
format->f1 = 10 * format->f1 + c - '0';
}
- return TRUE;
+ return true;
}
static bool zeroconv(Format *format, int ignore) {
if (format->flags & (FMT_f1set | FMT_f2set))
return digitconv(format, '0');
format->flags |= FMT_zeropad;
- return TRUE;
+ return true;
}
static void pad(Format *format, size_t len, int c) {
fmtappend(format, s, len);
}
}
- return FALSE;
+ return false;
}
static char *rc_utoa(unsigned long u, char *t, unsigned int radix, const char *digit) {
static bool cconv(Format *format, int ignore) {
fmtputc(format, va_arg(format->args, int));
- return FALSE;
+ return false;
}
static bool dconv(Format *format, int ignore) {
intconv(format, 10, 0, "");
- return FALSE;
+ return false;
}
static bool oconv(Format *format, int ignore) {
intconv(format, 8, 0, "0");
- return FALSE;
+ return false;
}
static bool xconv(Format *format, int ignore) {
intconv(format, 16, 0, "0x");
- return FALSE;
+ return false;
}
static bool pctconv(Format *format, int ignore) {
fmtputc(format, '%');
- return FALSE;
+ return false;
}
static bool badconv(Format *ignore, int ign0re) {
panic("bad conversion character in printfmt");
/* NOTREACHED */
- return FALSE; /* hush up gcc -Wall */
+ return false; /* hush up gcc -Wall */
}
-#undef NDEBUG
+#undef NDEBUG // We really want the asserts?
#define _XOPEN_SOURCE 700
/* Configuration options */
typedef long align_t;
-#define TRUE true
-#define FALSE false
-
/* If we have POSIX sigjmp_buf and friends, use them. If we don't, just
use a jmp_buf. This probably fails on a traditional SysV machine, where
jmp_bufs don't preserve signal masks. I'm not worrying about this till
rc_error(NULL);
}
if (rc_fork() == 0) { /* child writes to pipe */
- setsigdefaults(FALSE);
+ setsigdefaults(false);
close(p[0]);
if (fname != NULL)
writeall(p[1], fname->w, strlen(fname->w));
int i;
for (i = 0; i < pipelength; i++)
if (statuses[i] != 0)
- return FALSE;
- return TRUE;
+ return false;
+ return true;
}
/*
statuses[l - i] = j << 8;
continue;
}
- found = FALSE;
+ found = false;
for (k = 0; k < NSIG; k++) {
if (streq(signals[k].name, av[i])) {
statuses[l - i] = k;
- found = TRUE;
+ found = true;
break;
}
else {
size_t len = strlen(signals[k].name);
if (strncmp(signals[k].name, av[i], len) == 0 && streq(av[i] + len, "+core")) {
statuses[l - i] = k + 0x80;
- found = TRUE;
+ found = true;
break;
}
}
}
if (!found) {
fprint(2, "bad status\n");
- set(FALSE);
+ set(false);
return;
}
}
new = get_var_place(name, stack);
new->def = newdef;
new->extdef = NULL;
- set_exportable(name, TRUE);
+ set_exportable(name, true);
}
/* assign a variable in string form. Check to see if it is aliased (e.g., PATH and path) */
extern bool varassign_string(char *extdef) {
static bool aliasset[arraysize(aliases)] = {
- FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
+ false, false, false, false, false, false
};
char *name = get_name(extdef);
Variable *new;
int i;
if (name == NULL)
- return FALSE; /* add it to bozo env */
+ return false; /* add it to bozo env */
if ((i = hasalias(name)) != -1) {
- aliasset[i] = TRUE;
+ aliasset[i] = true;
i ^= 1; /* set i to the "opposite" case subscript and */
if (i&1 && aliasset[i]) /* don't alias variables that are already set in upper case */
- return TRUE;
+ return true;
}
- new = get_var_place(name, FALSE);
+ new = get_var_place(name, false);
new->def = NULL;
new->extdef = ealloc(strlen(extdef) + 1);
strcpy(new->extdef, extdef);
if (i != -1)
- alias(name, varlookup(name), FALSE);
- set_exportable(name, TRUE);
- return TRUE;
+ alias(name, varlookup(name), false);
+ set_exportable(name, true);
+ return true;
}
/*
extern void varrm(char *name, bool stack) {
int i = hasalias(name);
if (streq(name, "*") && !stack) { /* when assigning () to $*, we want to preserve $0 */
- varassign("*", varlookup("0"), FALSE);
+ varassign("*", varlookup("0"), false);
return;
}
delete_var(name, stack);
#include "rc.h"
-bool forked = FALSE;
+bool forked = false;
typedef struct Pid Pid;
rc_error(NULL);
/* NOTREACHED */
case 0:
- forked = TRUE;
+ forked = true;
sigchk();
p = plist; q = 0;
while (p) {
default:
new = enew(Pid);
new->pid = pid;
- new->alive = TRUE;
+ new->alive = true;
new->n = plist;
plist = new;
return pid;
for (q = plist; q != NULL; q = q->n)
if (q->pid == ret) {
- q->alive = FALSE;
+ q->alive = false;
q->stat = *stat;
break;
}
int stat;
while (plist != NULL) {
- pid_t pid = rc_wait4(plist->pid, &stat, FALSE);
+ pid_t pid = rc_wait4(plist->pid, &stat, false);
if (pid > 0)
setstatus(pid, stat);
else {
- set(FALSE);
+ set(false);
if (errno == EINTR)
return;
}
global which indicates whether rc is executing a test;
used by rc -e so that if (false) does not exit.
*/
-bool cond = FALSE;
+bool cond = false;
static bool haspreredir(Node *);
static bool isallpre(Node *);
if (n == NULL) {
if (!parent)
exit(0);
- set(TRUE);
- return TRUE;
+ set(true);
+ return true;
}
switch (n->type) {
case nArgs: case nBackq: case nConcat: case nCount:
exec(glob(glom(n)), parent); /* simple command */
break;
case nBody:
- walk(n->u[0].p, TRUE);
+ walk(n->u[0].p, true);
WALK(n->u[1].p, parent);
/* WALK doesn't fall through */
case nNowait: {
int pid;
if ((pid = rc_fork()) == 0) {
#if defined(RC_JOB) && defined(SIGTTOU) && defined(SIGTTIN) && defined(SIGTSTP)
- setsigdefaults(FALSE);
+ setsigdefaults(false);
rc_signal(SIGTTOU, SIG_IGN); /* Berkeleyized version: put it in a new pgroup. */
rc_signal(SIGTTIN, SIG_IGN);
rc_signal(SIGTSTP, SIG_IGN);
setpgid(0, getpid());
#else
- setsigdefaults(TRUE); /* ignore SIGINT, SIGQUIT, SIGTERM */
+ setsigdefaults(true); /* ignore SIGINT, SIGQUIT, SIGTERM */
#endif
mvfd(rc_open("/dev/null", rFrom), 0);
- walk(n->u[0].p, FALSE);
+ walk(n->u[0].p, false);
exit(getstatus());
}
if (interactive)
fprint(2, "%d\n", pid);
- varassign("apid", word(nprint("%d", pid), NULL), FALSE);
+ varassign("apid", word(nprint("%d", pid), NULL), false);
redirq = NULL; /* kill pre-redir queue */
break;
}
case nAndalso: {
bool oldcond = cond;
- cond = TRUE;
- if (walk(n->u[0].p, TRUE)) {
+ cond = true;
+ if (walk(n->u[0].p, true)) {
cond = oldcond;
WALK(n->u[1].p, parent);
} else
}
case nOrelse: {
bool oldcond = cond;
- cond = TRUE;
- if (!walk(n->u[0].p, TRUE)) {
+ cond = true;
+ if (!walk(n->u[0].p, true)) {
cond = oldcond;
WALK(n->u[1].p, parent);
} else
break;
}
case nBang:
- set(!walk(n->u[0].p, TRUE));
+ set(!walk(n->u[0].p, true));
break;
case nIf: {
bool oldcond = cond;
false_cmd = true_cmd->u[1].p;
true_cmd = true_cmd->u[0].p;
}
- cond = TRUE;
- if (!walk(n->u[0].p, TRUE))
+ cond = true;
+ if (!walk(n->u[0].p, true))
true_cmd = false_cmd; /* run the else clause */
cond = oldcond;
WALK(true_cmd, parent);
Edata jbreak;
Estack e1, e2;
bool testtrue, oldcond = cond;
- cond = TRUE;
- if (!walk(n->u[0].p, TRUE)) { /* prevent spurious breaks inside test */
+ cond = true;
+ if (!walk(n->u[0].p, true)) { /* prevent spurious breaks inside test */
cond = oldcond;
break;
}
block.b = newblock();
cond = oldcond;
except(eArena, block, &e2);
- walk(n->u[1].p, TRUE);
- testtrue = walk(n->u[0].p, TRUE);
+ walk(n->u[1].p, true);
+ testtrue = walk(n->u[0].p, true);
unexcept(); /* eArena */
- cond = TRUE;
+ cond = true;
} while (testtrue);
cond = oldcond;
unexcept(); /* eBreak */
except(eBreak, jbreak, &e1);
for (l = listcpy(glob(glom(n->u[1].p)), nalloc); l != NULL; l = l->n) {
Edata block;
- assign(var, word(l->w, NULL), FALSE);
+ assign(var, word(l->w, NULL), false);
block.b = newblock();
except(eArena, block, &e2);
- walk(n->u[2].p, TRUE);
+ walk(n->u[2].p, true);
unexcept(); /* eArena */
}
unexcept(); /* eBreak */
break;
}
case nSubshell:
- if (dofork(TRUE)) {
- setsigdefaults(FALSE);
- walk(n->u[0].p, FALSE);
+ if (dofork(true)) {
+ setsigdefaults(false);
+ walk(n->u[0].p, false);
rc_exit(getstatus());
}
break;
case nAssign:
if (n->u[0].p == NULL)
rc_error("null variable name");
- assign(glom(n->u[0].p), glob(glom(n->u[1].p)), FALSE);
- set(TRUE);
+ assign(glom(n->u[0].p), glob(glom(n->u[1].p)), false);
+ set(true);
break;
case nPipe:
dopipe(n);
fnassign(l->w, n->u[1].p);
l = l->n;
}
- set(TRUE);
+ set(true);
break;
}
case nRmfn: {
fnrm(l->w);
l = l->n;
}
- set(TRUE);
+ set(true);
break;
}
case nDup:
} while (n->u[0].p == NULL || n->u[0].p->type != nCase);
if (lmatch(v, glom(n->u[0].p->u[0].p))) {
for (n = n->u[1].p; n != NULL && (n->u[0].p == NULL || n->u[0].p->type != nCase); n = n->u[1].p)
- walk(n->u[0].p, TRUE);
+ walk(n->u[0].p, true);
break;
}
}
if (n->u[0].p->type == nRedir || n->u[0].p->type == nDup) {
if (redirq == NULL && !dofork(parent)) /* subshell on first preredir */
break;
- setsigdefaults(FALSE);
+ setsigdefaults(false);
qredir(n->u[0].p);
if (!haspreredir(n->u[1].p))
doredirs(); /* no more preredirs, empty queue */
- walk(n->u[1].p, FALSE);
+ walk(n->u[1].p, false);
rc_exit(getstatus());
/* NOTREACHED */
} else if (n->u[0].p->type == nAssign) {
if (isallpre(n->u[1].p)) {
- walk(n->u[0].p, TRUE);
+ walk(n->u[0].p, true);
WALK(n->u[1].p, parent);
} else {
Estack e;
Edata var;
v = glom(n->u[0].p->u[0].p);
- assign(v, glob(glom(n->u[0].p->u[1].p)), TRUE);
+ assign(v, glob(glom(n->u[0].p->u[1].p)), true);
var.name = v->w;
except(eVarstack, var, &e);
walk(n->u[1].p, parent);
- varrm(v->w, TRUE);
+ varrm(v->w, true);
unexcept(); /* eVarstack */
}
} else
if (n->u[1].p == NULL) {
WALK(n->u[0].p, parent);
} else if (dofork(parent)) {
- setsigdefaults(FALSE);
- walk(n->u[1].p, TRUE); /* Do redirections */
+ setsigdefaults(false);
+ walk(n->u[1].p, true); /* Do redirections */
redirq = NULL; /* Reset redirection queue */
- walk(n->u[0].p, FALSE); /* Do commands */
+ walk(n->u[0].p, false); /* Do commands */
rc_exit(getstatus());
/* NOTREACHED */
}
static bool haspreredir(Node *n) {
while (n != NULL && n->type == nPre) {
if (n->u[0].p->type == nDup || n->u[0].p->type == nRedir)
- return TRUE;
+ return true;
n = n->u[1].p;
}
- return FALSE;
+ return false;
}
/* checks to see whether a subtree is all pre-command directives, i.e., assignments and redirs only */
int pid, sp;
if (!parent || (pid = rc_fork()) == 0)
- return TRUE;
+ return true;
redirq = NULL; /* clear out the pre-redirection queue in the parent */
- rc_wait4(pid, &sp, TRUE);
+ rc_wait4(pid, &sp, true);
setstatus(-1, sp);
sigchk();
- return FALSE;
+ return false;
}
static void dopipe(Node *n) {
rc_error(NULL);
}
if ((pid = rc_fork()) == 0) {
- setsigdefaults(FALSE);
+ setsigdefaults(false);
redirq = NULL; /* clear preredir queue */
mvfd(p[0], r->u[1].i);
if (fd_prev != 1)
mvfd(fd_prev, fd_out);
close(p[1]);
- walk(r->u[3].p, FALSE);
+ walk(r->u[3].p, false);
exit(getstatus());
}
if (fd_prev != 1)
close(p[0]);
}
if ((pid = rc_fork()) == 0) {
- setsigdefaults(FALSE);
+ setsigdefaults(false);
mvfd(fd_prev, fd_out);
- walk(r, FALSE);
+ walk(r, false);
exit(getstatus());
/* NOTREACHED */
}
/* collect statuses */
- intr = FALSE;
+ intr = false;
for (j = 0; j < i; j++) {
- rc_wait4(pids[j], &sp, TRUE);
+ rc_wait4(pids[j], &sp, true);
stats[j] = sp;
intr |= (sp == SIGINT);
}
#define X_OTH 0001
#define X_ALL (X_USR|X_GRP|X_OTH)
-static bool initialized = FALSE;
+static bool initialized = false;
static uid_t uid;
static gid_t gid;
if (stat(path, &st) != 0) {
if (verbose) /* verbose flag only set for absolute pathname */
uerror(path);
- return FALSE;
+ return false;
}
if (uid == 0)
mask = X_ALL;
else
mask = X_OTH;
if (((st.st_mode & S_IFMT) == S_IFREG) && (st.st_mode & mask))
- return TRUE;
+ return true;
errno = EACCES;
if (verbose)
uerror(path);
- return FALSE;
+ return false;
}
/* replace non-printing characters with question marks in a freshly
if (name == NULL) /* no filename? can happen with "> foo" as a command */
return NULL;
if (!initialized) {
- initialized = TRUE;
+ initialized = true;
uid = geteuid();
gid = getegid();
ngroups = getgroups(0, (gid_t *)0);
strcat(test, "/");
strcat(test, name);
}
- if (rc_access(test, FALSE))
+ if (rc_access(test, false))
return test;
}
if (verbose) {