#define TDOT 17
/* Strings for names to make debug easier */
-char *T_CMD_NAMES[] = {
+#ifdef MSHDEBUG
+static char *T_CMD_NAMES[] = {
"PLACEHOLDER",
"TCOM",
"TPAREN",
"TASYNC",
"TDOT",
};
-
+#endif
/*
* actions determining the environment of a process
static struct wdblock *glob(char *cp, struct wdblock *wb);
static int my_getc(int ec);
static int subgetc(int ec, int quoted);
-static char **makenv(int all);
+static char **makenv(int all, struct wdblock *wb);
static char **eval(char **ap, int f);
static int setstatus(int s);
static int waitfor(int lastpid, int canintr);
#define GROWBY (256)
/* #define SHRINKBY (64) */
#undef SHRINKBY
-#define FREE (32767)
-#define BUSY (0)
-#define ALIGN (sizeof(int)-1)
+#define FREE (32767)
+#define BUSY (0)
+#define ALIGN (sizeof(int)-1)
struct region {
static int readc(void);
static void unget(int c);
static void ioecho(int c);
-static void prs(char *s);
+static void prs(const char *s);
static void prn(unsigned u);
static void closef(int i);
static void closeall(void);
struct here *h_next;
};
-static char *signame[] = {
+static const char * const signame[] = {
"Signal 0",
"Hangup",
(char *) NULL, /* interrupt */
#define NSIGNAL (sizeof(signame)/sizeof(signame[0]))
struct res {
- char *r_name;
+ const char *r_name;
int r_val;
};
-static struct res restab[] = {
+static const struct res restab[] = {
{"for", FOR},
{"case", CASE},
{"esac", ESAC},
{0, 0}
};
-static int expand_dotnode(struct op *);
-struct op *scantree(struct op *);
+static struct op *scantree(struct op *);
static struct op *dowholefile(int, int);
/* Globals */
static int dolc;
static int exstat;
static char gflg;
-static int interactive = 0; /* Is this an interactive shell */
+static int interactive; /* Is this an interactive shell */
static int execflg;
static int multiline; /* \n changed to ; */
static struct op *outtree; /* result from parser */
*/
-extern int msh_main(int argc, char **argv)
+int msh_main(int argc, char **argv)
{
REGISTER int f;
REGISTER char *s;
shell = lookup("SHELL");
if (shell->value == null)
- setval(shell, DEFAULT_SHELL);
+ setval(shell, (char *)DEFAULT_SHELL);
export(shell);
homedir = lookup("HOME");
interactive++;
#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET
#ifdef MSHDEBUG
- printf("\n\n" BB_BANNER " Built-in shell (msh with debug)\n");
+ printf("\n\n%s Built-in shell (msh with debug)\n", BB_BANNER);
#else
- printf("\n\n" BB_BANNER " Built-in shell (msh)\n");
+ printf("\n\n%s Built-in shell (msh)\n", BB_BANNER);
#endif
printf("Enter 'help' for a list of built-in commands.\n\n");
#endif
}
-static int expand_dotnode(node)
-struct op *node;
-{
- struct op *outtree_save = outtree;
-
- node->type = TDOT;
- newfile(node->words[1]);
-
- node->left = dowholefile(TDOT, 0);
-
- node->right = NULL;
-
- outtree = outtree_save;
-
- return (1);
-}
-
struct op *scantree(head)
struct op *head;
{
brkaddr = malloc(AREASIZE);
brktop = brkaddr + AREASIZE;
- while ((int) sbrk(0) & ALIGN)
+ while ((long) sbrk(0) & ALIGN)
sbrk(1);
areabot = (struct region *) sbrk(REGSIZE);
static int rlookup(n)
REGISTER char *n;
{
- REGISTER struct res *rp;
+ REGISTER const struct res *rp;
DBGPRINTF7(("RLOOKUP: enter, n is %s\n", n));
interactive = 0;
if (pin == NULL) {
close(0);
- open("/dev/null", 0);
+ open(bb_dev_null, 0);
}
_exit(execute(t->left, pin, pout, FEXEC));
}
if (wp[0] == NULL)
_exit(0);
- cp = rexecve(wp[0], wp, makenv(0));
+ cp = rexecve(wp[0], wp, makenv(0, NULL));
prs(wp[0]);
prs(": ");
err(cp);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}
- cp = rexecve(t->words[0], t->words, makenv(0));
+ cp = rexecve(t->words[0], t->words, makenv(0, NULL));
prs(t->words[0]);
prs(": ");
err(cp);
* names in the dictionary. Keyword assignments
* will already have been done.
*/
-static char **makenv(int all)
+static char **makenv(int all, struct wdblock *wb)
{
- REGISTER struct wdblock *wb;
REGISTER struct var *vp;
DBGPRINTF5(("MAKENV: enter, all=%d\n", all));
- wb = NULL;
for (vp = vlist; vp; vp = vp->next)
if (all || vp->status & EXPORT)
wb = addword(vp->name, wb);
int ignore;
int ignore_once;
char *argument_list[4];
+ struct wdblock *wb = NULL;
#if __GNUC__
/* Avoid longjmp clobbering */
}
var_name[var_index++] = *src++;
- while (isalnum(*src))
+ while (isalnum(*src) || *src=='_')
var_name[var_index++] = *src++;
var_name[var_index] = 0;
src++;
}
- vp = lookup(var_name);
- if (vp->value != null)
- value = (operator == '+') ? alt_value : vp->value;
- else if (operator == '?') {
- err(alt_value);
- return (0);
- } else if (alt_index && (operator != '+')) {
- value = alt_value;
- if (operator == '=')
- setval(vp, value);
- } else
- continue;
+ if (isalpha(*var_name)) {
+ /* let subshell handle it instead */
+
+ char *namep = var_name;
+
+ *dest++ = '$';
+ if (braces)
+ *dest++ = '{';
+ while (*namep)
+ *dest++ = *namep++;
+ if (operator) {
+ char *altp = alt_value;
+ *dest++ = operator;
+ while (*altp)
+ *dest++ = *altp++;
+ }
+ if (braces)
+ *dest++ = '}';
- while (*value && (count < LINELIM)) {
- *dest++ = *value++;
- count++;
+ wb = addword(lookup(var_name)->name, wb);
+ } else {
+ /* expand */
+
+ vp = lookup(var_name);
+ if (vp->value != null)
+ value = (operator == '+') ?
+ alt_value : vp->value;
+ else if (operator == '?') {
+ err(alt_value);
+ return (0);
+ } else if (alt_index && (operator != '+')) {
+ value = alt_value;
+ if (operator == '=')
+ setval(vp, value);
+ } else
+ continue;
+
+ while (*value && (count < LINELIM)) {
+ *dest++ = *value++;
+ count++;
+ }
}
} else {
*dest++ = *src++;
argument_list[2] = child_cmd;
argument_list[3] = 0;
- cp = rexecve(argument_list[0], argument_list, makenv(1));
+ cp = rexecve(argument_list[0], argument_list, makenv(1, wb));
prs(argument_list[0]);
prs(": ");
err(cp);
return (wd);
}
-int (*func) (char *, char *);
-int globv;
+static int (*func) (char *, char *);
+static int globv;
static void glob0(a0, a1, a2, a3)
char *a0;
}
static void prs(s)
-REGISTER char *s;
+REGISTER const char *s;
{
if (*s)
write(2, s, strlen(s));