msh: cleaning up for -Wwrite-strings part #4

This commit is contained in:
Denis Vlasenko 2007-02-01 01:43:54 +00:00
parent 6b50f73171
commit 1e3b068689

View File

@ -105,6 +105,27 @@ typedef void xint; /* base type of jmp_buf, for not broken compilers */
#define NOWORDS ((char **)NULL) #define NOWORDS ((char **)NULL)
#define NOPIPE ((int *)NULL) #define NOPIPE ((int *)NULL)
/*
* redirection
*/
struct ioword {
short io_unit; /* unit affected */
short io_flag; /* action (below) */
char *io_name; /* file name */
};
#define IOREAD 1 /* < */
#define IOHERE 2 /* << (here file) */
#define IOWRITE 4 /* > */
#define IOCAT 8 /* >> */
#define IOXHERE 16 /* ${}, ` in << */
#define IODUP 32 /* >&digit */
#define IOCLOSE 64 /* >&- */
#define IODEFAULT (-1) /* token for default IO unit */
/* /*
* Description of a command or an operation on commands. * Description of a command or an operation on commands.
* Might eventually use a union. * Might eventually use a union.
@ -183,7 +204,6 @@ static const char *const T_CMD_NAMES[] = {
/* PROTOTYPES */ /* PROTOTYPES */
static int newfile(char *s); static int newfile(char *s);
static char *cclass(char *p, int sub);
struct brkcon { struct brkcon {
@ -192,39 +212,6 @@ struct brkcon {
}; };
/*
* redirection
*/
struct ioword {
short io_unit; /* unit affected */
short io_flag; /* action (below) */
char *io_name; /* file name */
};
#define IOREAD 1 /* < */
#define IOHERE 2 /* << (here file) */
#define IOWRITE 4 /* > */
#define IOCAT 8 /* >> */
#define IOXHERE 16 /* ${}, ` in << */
#define IODUP 32 /* >&digit */
#define IOCLOSE 64 /* >&- */
#define IODEFAULT (-1) /* token for default IO unit */
/*
* parsing & execution environment
*/
static struct env {
char *linep;
struct io *iobase;
struct io *iop;
xint *errpt; /* void * */
int iofd;
struct env *oenv;
} e;
/* /*
* flags: * flags:
* -e: quit on error * -e: quit on error
@ -264,10 +251,7 @@ static int areanum; /* current allocation area */
/* /*
* other functions * other functions
*/ */
typedef int (*builtin_func_ptr)(struct op *); static const char *rexecve(char *c, char **v, char **envp);
static builtin_func_ptr inbuilt(char *s);
static char *rexecve(char *c, char **v, char **envp);
static char *evalstr(char *cp, int f); static char *evalstr(char *cp, int f);
static char *putn(int n); static char *putn(int n);
static char *unquote(char *as); static char *unquote(char *as);
@ -284,13 +268,10 @@ static void onintr(int s); /* SIGINT handler */
static int newenv(int f); static int newenv(int f);
static void quitenv(void); static void quitenv(void);
static int anys(const char *s1, const char *s2);
static int any(int c, const char *s);
static void next(int f); static void next(int f);
static void setdash(void); static void setdash(void);
static void onecommand(void); static void onecommand(void);
static void runtrap(int i); static void runtrap(int i);
static int gmatch(char *s, char *p);
/* -------- area stuff -------- */ /* -------- area stuff -------- */
@ -391,6 +372,10 @@ static int yyparse(void);
static int execute(struct op *t, int *pin, int *pout, int act); static int execute(struct op *t, int *pin, int *pout, int act);
#define AFID_NOBUF (~0)
#define AFID_ID 0
/* -------- io.h -------- */ /* -------- io.h -------- */
/* io buffer */ /* io buffer */
struct iobuf { struct iobuf {
@ -402,7 +387,7 @@ struct iobuf {
/* possible arguments to an IO function */ /* possible arguments to an IO function */
struct ioarg { struct ioarg {
char *aword; const char *aword;
char **awordlist; char **awordlist;
int afile; /* file descriptor */ int afile; /* file descriptor */
unsigned afid; /* buffer id */ unsigned afid; /* buffer id */
@ -410,10 +395,6 @@ struct ioarg {
struct iobuf *afbuf; /* buffer for this file */ struct iobuf *afbuf; /* buffer for this file */
}; };
//static struct ioarg ioargstack[NPUSH];
#define AFID_NOBUF (~0)
#define AFID_ID 0
/* an input generator's state */ /* an input generator's state */
struct io { struct io {
int (*iofn) (struct ioarg *, struct io *); int (*iofn) (struct ioarg *, struct io *);
@ -425,7 +406,6 @@ struct io {
char task; /* reason for pushed IO */ char task; /* reason for pushed IO */
}; };
//static struct io iostack[NPUSH];
#define XOTHER 0 /* none of the below */ #define XOTHER 0 /* none of the below */
#define XDOLL 1 /* expanding ${} */ #define XDOLL 1 /* expanding ${} */
#define XGRAVE 2 /* expanding `'s */ #define XGRAVE 2 /* expanding `'s */
@ -434,6 +414,29 @@ struct io {
/* in substitution */ /* in substitution */
#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) #define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */
static struct ioarg ioargstack[NPUSH];
static struct io iostack[NPUSH];
static struct iobuf sharedbuf = { AFID_NOBUF };
static struct iobuf mainbuf = { AFID_NOBUF };
static unsigned bufid = AFID_ID; /* buffer id counter */
#define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen)))
#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
/*
* parsing & execution environment
*/
static struct env {
char *linep;
struct io *iobase;
struct io *iop;
xint *errpt; /* void * */
int iofd;
struct env *oenv;
} e;
/* /*
* input generators for IO structure * input generators for IO structure
@ -471,9 +474,6 @@ static int openpipe(int *pv);
static void closepipe(int *pv); static void closepipe(int *pv);
static struct io *setbase(struct io *ip); static struct io *setbase(struct io *ip);
#define PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen)))
#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
/* -------- word.h -------- */ /* -------- word.h -------- */
#define NSTART 16 /* default number of words to allow for initially */ #define NSTART 16 /* default number of words to allow for initially */
@ -493,9 +493,6 @@ static char **getwords(struct wdblock *wb);
static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp); static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp);
static int iosetup(struct ioword *iop, int pipein, int pipeout); static int iosetup(struct ioword *iop, int pipein, int pipeout);
static void echo(char **wp);
static struct op **find1case(struct op *t, char *w);
static struct op *findcase(struct op *t, char *w);
static void brkset(struct brkcon *bc); static void brkset(struct brkcon *bc);
static int dolabel(struct op *t); static int dolabel(struct op *t);
static int dohelp(struct op *t); static int dohelp(struct op *t);
@ -523,7 +520,7 @@ static void badid(char *s);
static int doset(struct op *t); static int doset(struct op *t);
static void varput(char *s, int out); static void varput(char *s, int out);
static int dotimes(struct op *t); static int dotimes(struct op *t);
static int expand(char *cp, struct wdblock **wbp, int f); static int expand(const char *cp, struct wdblock **wbp, int f);
static char *blank(int f); static char *blank(int f);
static int dollar(int quoted); static int dollar(int quoted);
static int grave(int quoted); static int grave(int quoted);
@ -533,9 +530,6 @@ static int anyspcl(struct wdblock *wb);
static int xstrcmp(char *p1, char *p2); static int xstrcmp(char *p1, char *p2);
static void glob0(char *a0, unsigned a1, int a2, static void glob0(char *a0, unsigned a1, int a2,
int (*a3) (char *, char *)); int (*a3) (char *, char *));
static void glob1(char *base, char *lim);
static void glob2(char *i, char *j);
static void glob3(char *i, char *j, char *k);
static void readhere(char **name, char *s, int ec); static void readhere(char **name, char *s, int ec);
static void pushio(struct ioarg *argp, int (*f) (struct ioarg *)); static void pushio(struct ioarg *argp, int (*f) (struct ioarg *));
static int xxchar(struct ioarg *ap); static int xxchar(struct ioarg *ap);
@ -661,7 +655,7 @@ static struct var *ifs; /* field separators */
static int areanum; /* current allocation area */ static int areanum; /* current allocation area */
static int intr; static int intr;
static int inparse; static int inparse;
static char *null = ""; static char *null = (char*)"";
static int heedint = 1; static int heedint = 1;
static void (*qflag) (int) = SIG_IGN; static void (*qflag) (int) = SIG_IGN;
static int startl; static int startl;
@ -671,12 +665,6 @@ static int iounit = IODEFAULT;
static YYSTYPE yylval; static YYSTYPE yylval;
static char *elinep = line + sizeof(line) - 5; static char *elinep = line + sizeof(line) - 5;
static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */
static struct ioarg ioargstack[NPUSH];
static struct io iostack[NPUSH];
static struct iobuf sharedbuf = { AFID_NOBUF };
static struct iobuf mainbuf = { AFID_NOBUF };
static unsigned bufid = AFID_ID; /* buffer id counter */
static struct here *inhere; /* list of hear docs while parsing */ static struct here *inhere; /* list of hear docs while parsing */
static struct here *acthere; /* list of active here documents */ static struct here *acthere; /* list of active here documents */
@ -739,6 +727,19 @@ static void prn(unsigned u)
prs(itoa(u)); prs(itoa(u));
} }
static void echo(char **wp)
{
int i;
prs("+");
for (i = 0; wp[i]; i++) {
if (i)
prs(" ");
prs(wp[i]);
}
prs("\n");
}
static void closef(int i) static void closef(int i)
{ {
if (i > 2) if (i > 2)
@ -968,7 +969,7 @@ static char *space(int n)
char *cp; char *cp;
cp = getcell(n); cp = getcell(n);
if (cp == '\0') if (cp == NULL)
err("out of string space"); err("out of string space");
return cp; return cp;
} }
@ -978,13 +979,14 @@ static char *strsave(const char *s, int a)
char *cp; char *cp;
cp = space(strlen(s) + 1); cp = space(strlen(s) + 1);
if (cp != NULL) { if (cp == NULL) {
// FIXME: I highly doubt this is good.
return (char*)"";
}
setarea(cp, a); setarea(cp, a);
strcpy(cp, s); strcpy(cp, s);
return cp; return cp;
} }
return "";
}
/* -------- var.c -------- */ /* -------- var.c -------- */
@ -997,7 +999,7 @@ static int eqname(const char *n1, const char *n2)
return *n2 == '\0' || *n2 == '='; return *n2 == '\0' || *n2 == '=';
} }
static char *findeq(const char *cp) static const char *findeq(const char *cp)
{ {
while (*cp != '\0' && *cp != '=') while (*cp != '\0' && *cp != '=')
cp++; cp++;
@ -1012,32 +1014,39 @@ static char *findeq(const char *cp)
*/ */
static struct var *lookup(const char *n) static struct var *lookup(const char *n)
{ {
struct var *vp; // FIXME: dirty hack
char *cp;
int c;
static struct var dummy; static struct var dummy;
struct var *vp;
const char *cp;
char *xp;
int c;
if (isdigit(*n)) { if (isdigit(*n)) {
dummy.name = n; dummy.name = (char*)n;
for (c = 0; isdigit(*n) && c < 1000; n++) for (c = 0; isdigit(*n) && c < 1000; n++)
c = c * 10 + *n - '0'; c = c * 10 + *n - '0';
dummy.status = RONLY; dummy.status = RONLY;
dummy.value = (c <= dolc ? dolv[c] : null); dummy.value = (c <= dolc ? dolv[c] : null);
return &dummy; return &dummy;
} }
for (vp = vlist; vp; vp = vp->next) for (vp = vlist; vp; vp = vp->next)
if (eqname(vp->name, n)) if (eqname(vp->name, n))
return vp; return vp;
cp = findeq(n); cp = findeq(n);
vp = (struct var *) space(sizeof(*vp)); vp = (struct var *) space(sizeof(*vp));
if (vp == 0 || (vp->name = space((int) (cp - n) + 2)) == 0) { if (vp == 0 || (vp->name = space((int) (cp - n) + 2)) == 0) {
dummy.name = dummy.value = ""; dummy.name = dummy.value = (char*)"";
return &dummy; return &dummy;
} }
for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++);
if (*cp == '\0') xp = vp->name;
*cp = '='; while ((*xp = *n++) != '\0' && *xp != '=')
*++cp = '\0'; xp++;
*xp++ = '=';
*xp = '\0';
setarea((char *) vp, 0); setarea((char *) vp, 0);
setarea((char *) vp->name, 0); setarea((char *) vp->name, 0);
vp->value = null; vp->value = null;
@ -1085,8 +1094,8 @@ static void nameval(struct var *vp, const char *val, const char *name)
} }
if (vp->status & GETCELL) if (vp->status & GETCELL)
freecell(vp->name); /* form new string `name=value' */ freecell(vp->name); /* form new string `name=value' */
vp->name = name; vp->name = (char*)name;
vp->value = val; vp->value = (char*)val;
vp->status |= fl; vp->status |= fl;
} }
@ -1139,7 +1148,7 @@ static int isassign(const char *s)
static int assign(const char *s, int cf) static int assign(const char *s, int cf)
{ {
char *cp; const char *cp;
struct var *vp; struct var *vp;
DBGPRINTF7(("ASSIGN: enter, s=%s, cf=%d\n", s, cf)); DBGPRINTF7(("ASSIGN: enter, s=%s, cf=%d\n", s, cf));
@ -1172,7 +1181,7 @@ static void putvlist(int f, int out)
{ {
struct var *vp; struct var *vp;
for (vp = vlist; vp; vp = vp->next) for (vp = vlist; vp; vp = vp->next) {
if (vp->status & f && (isalpha(*vp->name) || *vp->name == '_')) { if (vp->status & f && (isalpha(*vp->name) || *vp->name == '_')) {
if (vp->status & EXPORT) if (vp->status & EXPORT)
write(out, "export ", 7); write(out, "export ", 7);
@ -1182,6 +1191,7 @@ static void putvlist(int f, int out)
write(out, "\n", 1); write(out, "\n", 1);
} }
} }
}
/* /*
@ -1429,6 +1439,7 @@ static void onintr(int s) /* ANSI C requires a parameter */
} }
} }
/* -------- gmatch.c -------- */ /* -------- gmatch.c -------- */
/* /*
* int gmatch(string, pattern) * int gmatch(string, pattern)
@ -1442,12 +1453,36 @@ static void onintr(int s) /* ANSI C requires a parameter */
#define QMASK (CMASK&~QUOTE) #define QMASK (CMASK&~QUOTE)
#define NOT '!' /* might use ^ */ #define NOT '!' /* might use ^ */
static int gmatch(char *s, char *p) static const char *cclass(const char *p, int sub)
{
int c, d, not, found;
not = (*p == NOT);
if (not != 0)
p++;
found = not;
do {
if (*p == '\0')
return NULL;
c = *p & CMASK;
if (p[1] == '-' && p[2] != ']') {
d = p[2] & CMASK;
p++;
} else
d = c;
if (c == sub || (c <= sub && sub <= d))
found = !not;
} while (*++p != ']');
return found ? p + 1 : NULL;
}
static int gmatch(const char *s, const char *p)
{ {
int sc, pc; int sc, pc;
if (s == NULL || p == NULL) if (s == NULL || p == NULL)
return 0; return 0;
while ((pc = *p++ & CMASK) != '\0') { while ((pc = *p++ & CMASK) != '\0') {
sc = *s++ & QMASK; sc = *s++ & QMASK;
switch (pc) { switch (pc) {
@ -1478,29 +1513,6 @@ static int gmatch(char *s, char *p)
return *s == '\0'; return *s == '\0';
} }
static char *cclass(char *p, int sub)
{
int c, d, not, found;
not = (*p == NOT);
if (not != 0)
p++;
found = not;
do {
if (*p == '\0')
return NULL;
c = *p & CMASK;
if (p[1] == '-' && p[2] != ']') {
d = p[2] & CMASK;
p++;
} else
d = c;
if (c == sub || (c <= sub && sub <= d))
found = !not;
} while (*++p != ']');
return found ? p + 1 : NULL;
}
/* -------- csyn.c -------- */ /* -------- csyn.c -------- */
/* /*
@ -2323,21 +2335,68 @@ static char *tree(unsigned size)
return t; return t;
} }
/* VARARGS1 */ /* VARARGS1 */
/* ARGSUSED */ /* ARGSUSED */
/* -------- exec.c -------- */ /* -------- exec.c -------- */
static struct op **find1case(struct op *t, const char *w)
{
struct op *t1;
struct op **tp;
char **wp;
char *cp;
if (t == NULL) {
DBGPRINTF3(("FIND1CASE: enter, t==NULL, returning.\n"));
return NULL;
}
DBGPRINTF3(("FIND1CASE: enter, t->type=%d (%s)\n", t->type,
T_CMD_NAMES[t->type]));
if (t->type == TLIST) {
tp = find1case(t->left, w);
if (tp != NULL) {
DBGPRINTF3(("FIND1CASE: found one to the left, returning tp=%p\n", tp));
return tp;
}
t1 = t->right; /* TPAT */
} else
t1 = t;
for (wp = t1->words; *wp;) {
cp = evalstr(*wp++, DOSUB);
if (cp && gmatch(w, cp)) {
DBGPRINTF3(("FIND1CASE: returning &t1->left= %p.\n",
&t1->left));
return &t1->left;
}
}
DBGPRINTF(("FIND1CASE: returning NULL\n"));
return NULL;
}
static struct op *findcase(struct op *t, const char *w)
{
struct op **tp;
tp = find1case(t, w);
return tp != NULL ? *tp : NULL;
}
/* /*
* execute tree * execute tree
*/ */
static int execute(struct op *t, int *pin, int *pout, int act) static int execute(struct op *t, int *pin, int *pout, int act)
{ {
struct op *t1; struct op *t1;
volatile int i, rv, a; volatile int i, rv, a;
char *cp, **wp, **wp2; const char *cp;
char **wp, **wp2;
struct var *vp; struct var *vp;
struct op *outtree_save; struct op *outtree_save;
struct brkcon bc; struct brkcon bc;
@ -2551,14 +2610,25 @@ static int execute(struct op *t, int *pin, int *pout, int act)
return rv; return rv;
} }
static int typedef int (*builtin_func_ptr)(struct op *);
forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
static builtin_func_ptr inbuilt(const char *s) {
const struct builtincmd *bp;
for (bp = builtincmds; bp->name != NULL; bp++)
if (strcmp(bp->name, s) == 0)
return bp->builtinfunc;
return NULL;
}
static int forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
{ {
pid_t newpid; pid_t newpid;
int i, rv; int i, rv;
builtin_func_ptr shcom = NULL; builtin_func_ptr shcom = NULL;
int f; int f;
char *cp = NULL; const char *cp = NULL;
struct ioword **iopp; struct ioword **iopp;
int resetsig; int resetsig;
char **owp; char **owp;
@ -2592,7 +2662,7 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
resetsig = 0; resetsig = 0;
rv = -1; /* system-detected error */ rv = -1; /* system-detected error */
if (t->type == TCOM) { if (t->type == TCOM) {
while ((cp = *wp++) != NULL); while (*wp++ != NULL);
cp = *wp; cp = *wp;
/* strip all initial assignments */ /* strip all initial assignments */
@ -2755,7 +2825,8 @@ forkexec(struct op *t, int *pin, int *pout, int act, char **wp)
static int iosetup(struct ioword *iop, int pipein, int pipeout) static int iosetup(struct ioword *iop, int pipein, int pipeout)
{ {
int u = -1; int u = -1;
char *cp = NULL, *msg; char *cp = NULL;
const char *msg;
DBGPRINTF(("IOSETUP: iop %p, pipein %i, pipeout %i\n", iop, DBGPRINTF(("IOSETUP: iop %p, pipein %i, pipeout %i\n", iop,
pipein, pipeout)); pipein, pipeout));
@ -2795,7 +2866,7 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout)
case IOHERE: case IOHERE:
case IOHERE | IOXHERE: case IOHERE | IOXHERE:
u = herein(iop->io_name, iop->io_flag & IOXHERE); u = herein(iop->io_name, iop->io_flag & IOXHERE);
cp = "here file"; cp = (char*)"here file";
break; break;
case IOWRITE | IOCAT: case IOWRITE | IOCAT:
@ -2829,64 +2900,6 @@ static int iosetup(struct ioword *iop, int pipein, int pipeout)
return 0; return 0;
} }
static void echo(char **wp)
{
int i;
prs("+");
for (i = 0; wp[i]; i++) {
if (i)
prs(" ");
prs(wp[i]);
}
prs("\n");
}
static struct op **find1case(struct op *t, char *w)
{
struct op *t1;
struct op **tp;
char **wp, *cp;
if (t == NULL) {
DBGPRINTF3(("FIND1CASE: enter, t==NULL, returning.\n"));
return NULL;
}
DBGPRINTF3(("FIND1CASE: enter, t->type=%d (%s)\n", t->type,
T_CMD_NAMES[t->type]));
if (t->type == TLIST) {
tp = find1case(t->left, w);
if (tp != NULL) {
DBGPRINTF3(("FIND1CASE: found one to the left, returning tp=%p\n", tp));
return tp;
}
t1 = t->right; /* TPAT */
} else
t1 = t;
for (wp = t1->words; *wp;) {
cp = evalstr(*wp++, DOSUB);
if (cp && gmatch(w, cp)) {
DBGPRINTF3(("FIND1CASE: returning &t1->left= %p.\n",
&t1->left));
return &t1->left;
}
}
DBGPRINTF(("FIND1CASE: returning NULL\n"));
return NULL;
}
static struct op *findcase(struct op *t, char *w)
{
struct op **tp;
tp = find1case(t, w);
return tp != NULL ? *tp : NULL;
}
/* /*
* Enter a new loop level (marked for break/continue). * Enter a new loop level (marked for break/continue).
*/ */
@ -2971,10 +2984,11 @@ static int setstatus(int s)
* If getenv("PATH") were kept up-to-date, * If getenv("PATH") were kept up-to-date,
* execvp might be used. * execvp might be used.
*/ */
static char *rexecve(char *c, char **v, char **envp) static const char *rexecve(char *c, char **v, char **envp)
{ {
int i; int i;
char *sp, *tp; const char *sp;
char *tp;
int eacces = 0, asis = 0; int eacces = 0, asis = 0;
char *name = c; char *name = c;
@ -2991,7 +3005,7 @@ static char *rexecve(char *c, char **v, char **envp)
DBGPRINTF(("REXECVE: c=%p, v=%p, envp=%p\n", c, v, envp)); DBGPRINTF(("REXECVE: c=%p, v=%p, envp=%p\n", c, v, envp));
sp = any('/', c) ? "" : path->value; sp = any('/', c) ? "" : path->value;
asis = *sp == '\0'; asis = (*sp == '\0');
while (asis || *sp != '\0') { while (asis || *sp != '\0') {
asis = 0; asis = 0;
tp = e.linep; tp = e.linep;
@ -3138,7 +3152,7 @@ static int dolabel(struct op *t)
static int dochdir(struct op *t) static int dochdir(struct op *t)
{ {
char *cp, *er; const char *cp, *er;
cp = t->words[1]; cp = t->words[1];
if (cp == NULL) { if (cp == NULL) {
@ -3175,7 +3189,7 @@ static int doshift(struct op *t)
*/ */
static int dologin(struct op *t) static int dologin(struct op *t)
{ {
char *cp; const char *cp;
if (interactive) { if (interactive) {
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
@ -3232,7 +3246,8 @@ static int doexec(struct op *t)
static int dodot(struct op *t) static int dodot(struct op *t)
{ {
int i; int i;
char *sp, *tp; const char *sp;
char *tp;
char *cp; char *cp;
int maltmp; int maltmp;
@ -3578,16 +3593,6 @@ static int dotimes(struct op *t)
} }
static builtin_func_ptr inbuilt(char *s) {
const struct builtincmd *bp;
for (bp = builtincmds; bp->name != NULL; bp++)
if (strcmp(bp->name, s) == 0)
return bp->builtinfunc;
return NULL;
}
/* -------- eval.c -------- */ /* -------- eval.c -------- */
/* /*
@ -3639,6 +3644,7 @@ static char **eval(char **ap, int f)
return gflg ? (char **) NULL : wp; return gflg ? (char **) NULL : wp;
} }
/* /*
* Make the exported environment from the exported * Make the exported environment from the exported
* names in the dictionary. Keyword assignments * names in the dictionary. Keyword assignments
@ -3657,26 +3663,10 @@ static char **makenv(int all, struct wdblock *wb)
return getwords(wb); return getwords(wb);
} }
static char *evalstr(char *cp, int f) static int expand(const char *cp, struct wdblock **wbp, int f)
{
struct wdblock *wb;
DBGPRINTF6(("EVALSTR: enter, cp=%p, f=%d\n", cp, f));
wb = NULL;
if (expand(cp, &wb, f)) {
if (wb == NULL || wb->w_nword == 0
|| (cp = wb->w_words[0]) == NULL)
cp = "";
DELETE(wb);
} else
cp = NULL;
return cp;
}
static int expand(char *cp, struct wdblock **wbp, int f)
{ {
jmp_buf ev; jmp_buf ev;
char *xp;
#if __GNUC__ #if __GNUC__
/* Avoid longjmp clobbering */ /* Avoid longjmp clobbering */
@ -3690,27 +3680,28 @@ static int expand(char *cp, struct wdblock **wbp, int f)
if (cp == NULL) if (cp == NULL)
return 0; return 0;
if (!anys("$`'\"", cp) && if (!anys("$`'\"", cp) && !anys(ifs->value, cp)
!anys(ifs->value, cp) && ((f & DOGLOB) == 0 || !anys("[*?", cp))) { && ((f & DOGLOB) == 0 || !anys("[*?", cp))
cp = strsave(cp, areanum); ) {
xp = strsave(cp, areanum);
if (f & DOTRIM) if (f & DOTRIM)
unquote(cp); unquote(xp);
*wbp = addword(cp, *wbp); *wbp = addword(xp, *wbp);
return 1; return 1;
} }
errpt = ev; errpt = ev;
if (newenv(setjmp(errpt)) == 0) { if (newenv(setjmp(errpt)) == 0) {
PUSHIO(aword, cp, strchar); PUSHIO(aword, cp, strchar);
e.iobase = e.iop; e.iobase = e.iop;
while ((cp = blank(f)) && gflg == 0) { while ((xp = blank(f)) && gflg == 0) {
e.linep = cp; e.linep = xp;
cp = strsave(cp, areanum); xp = strsave(xp, areanum);
if ((f & DOGLOB) == 0) { if ((f & DOGLOB) == 0) {
if (f & DOTRIM) if (f & DOTRIM)
unquote(cp); unquote(xp);
*wbp = addword(cp, *wbp); *wbp = addword(xp, *wbp);
} else } else
*wbp = glob(cp, *wbp); *wbp = glob(xp, *wbp);
} }
quitenv(); quitenv();
} else } else
@ -3718,6 +3709,29 @@ static int expand(char *cp, struct wdblock **wbp, int f)
return gflg == 0; return gflg == 0;
} }
static char *evalstr(char *cp, int f)
{
struct wdblock *wb;
DBGPRINTF6(("EVALSTR: enter, cp=%p, f=%d\n", cp, f));
wb = NULL;
if (expand(cp, &wb, f)) {
if (wb == NULL || wb->w_nword == 0
|| (cp = wb->w_words[0]) == NULL
) {
// TODO: I suspect that
// char *evalstr(char *cp, int f) is actually
// const char *evalstr(const char *cp, int f)!
cp = (char*)"";
}
DELETE(wb);
} else
cp = NULL;
return cp;
}
/* /*
* Blank interpretation and quoting * Blank interpretation and quoting
*/ */
@ -3927,12 +3941,12 @@ static int dollar(int quoted)
static int grave(int quoted) static int grave(int quoted)
{ {
char *cp; const char *cp;
int i; int i;
int j; int j;
int pf[2]; int pf[2];
static char child_cmd[LINELIM]; static char child_cmd[LINELIM];
char *src; const char *src;
char *dest; char *dest;
int count; int count;
int ignore; int ignore;
@ -3945,11 +3959,12 @@ static int grave(int quoted)
(void) &cp; (void) &cp;
#endif #endif
for (cp = e.iop->argp->aword; *cp != '`'; cp++) for (cp = e.iop->argp->aword; *cp != '`'; cp++) {
if (*cp == 0) { if (*cp == 0) {
err("no closing `"); err("no closing `");
return 0; return 0;
} }
}
/* string copy with dollar expansion */ /* string copy with dollar expansion */
src = e.iop->argp->aword; src = e.iop->argp->aword;
@ -4078,8 +4093,7 @@ static int grave(int quoted)
e.iop->argp->aword = ++cp; e.iop->argp->aword = ++cp;
close(pf[1]); close(pf[1]);
PUSHIO(afile, remap(pf[0]), PUSHIO(afile, remap(pf[0]),
(int (*)(struct ioarg *)) ((quoted) ? qgravechar : (int (*)(struct ioarg *)) ((quoted) ? qgravechar : gravechar));
gravechar));
return 1; return 1;
} }
/* allow trapped signals */ /* allow trapped signals */
@ -4092,9 +4106,9 @@ static int grave(int quoted)
closepipe(pf); closepipe(pf);
argument_list[0] = (char *) DEFAULT_SHELL; argument_list[0] = (char *) DEFAULT_SHELL;
argument_list[1] = "-c"; argument_list[1] = (char *) "-c";
argument_list[2] = child_cmd; argument_list[2] = child_cmd;
argument_list[3] = 0; argument_list[3] = NULL;
cp = rexecve(argument_list[0], argument_list, makenv(1, wb)); cp = rexecve(argument_list[0], argument_list, makenv(1, wb));
prs(argument_list[0]); prs(argument_list[0]);
@ -4263,6 +4277,7 @@ static int xstrcmp(char *p1, char *p2)
return strcmp(*(char **) p1, *(char **) p2); return strcmp(*(char **) p1, *(char **) p2);
} }
/* -------- word.c -------- */ /* -------- word.c -------- */
static struct wdblock *newword(int nw) static struct wdblock *newword(int nw)
@ -4316,11 +4331,37 @@ char **getwords(struct wdblock *wb)
static int (*func) (char *, char *); static int (*func) (char *, char *);
static int globv; static int globv;
static void glob0(char *a0, unsigned a1, int a2, int (*a3) (char *, char *)) static void glob3(char *i, char *j, char *k)
{ {
func = a3; char *index1, *index2, *index3;
globv = a2; int c;
glob1(a0, a0 + a1 * a2); int m;
m = globv;
index1 = i;
index2 = j;
index3 = k;
do {
c = *index1;
*index1++ = *index3;
*index3++ = *index2;
*index2++ = c;
} while (--m);
}
static void glob2(char *i, char *j)
{
char *index1, *index2, c;
int m;
m = globv;
index1 = i;
index2 = j;
do {
c = *index1;
*index1++ = *index2;
*index2++ = c;
} while (--m);
} }
static void glob1(char *base, char *lim) static void glob1(char *base, char *lim)
@ -4397,38 +4438,13 @@ static void glob1(char *base, char *lim)
} }
} }
static void glob2(char *i, char *j) static void glob0(char *a0, unsigned a1, int a2, int (*a3) (char *, char *))
{ {
char *index1, *index2, c; func = a3;
int m; globv = a2;
glob1(a0, a0 + a1 * a2);
m = globv;
index1 = i;
index2 = j;
do {
c = *index1;
*index1++ = *index2;
*index2++ = c;
} while (--m);
} }
static void glob3(char *i, char *j, char *k)
{
char *index1, *index2, *index3;
int c;
int m;
m = globv;
index1 = i;
index2 = j;
index3 = k;
do {
c = *index1;
*index1++ = *index3;
*index3++ = *index2;
*index2++ = c;
} while (--m);
}
/* -------- io.c -------- */ /* -------- io.c -------- */
@ -4875,6 +4891,7 @@ static void closepipe(int *pv)
} }
} }
/* -------- here.c -------- */ /* -------- here.c -------- */
/* /*