/* ============ Prompt */
-static int doprompt; /* if set, prompt the user */
-static int needprompt; /* true if interactive and at start of line */
+static smallint doprompt; /* if set, prompt the user */
+static smallint needprompt; /* true if interactive and at start of line */
#if ENABLE_FEATURE_EDITING
static line_input_t *line_input_state;
/* ============ ... */
-#define IBUFSIZ (BUFSIZ + 1)
+#define IBUFSIZ COMMON_BUFSIZE
#define basebuf bb_common_bufsiz1 /* buffer for top level input file */
/* Syntax classes */
INPUT_NOFILE_OK = 2,
};
-/*
- * NEOF is returned by parsecmd when it encounters an end of file. It
- * must be distinct from NULL, so we use the address of a variable that
- * happens to be handy.
- */
static int plinno = 1; /* input line number */
/* number of characters left in input buffer */
static int parsenleft; /* copy of parsefile->nleft */
/* times of mailboxes */
static time_t mailtime[MAXMBOXES];
/* Set if MAIL or MAILPATH is changed. */
-static int mail_var_path_changed;
+static smallint mail_var_path_changed;
/*
* Print appropriate message(s) if mail has arrived.
static void
changemail(const char *val)
{
- mail_var_path_changed++;
+ mail_var_path_changed = 1;
}
#endif /* ASH_MAIL */
/* ============ Shell parser */
-static int tokpushback; /* last token pushed back */
+/*
+ * NEOF is returned by parsecmd when it encounters an end of file. It
+ * must be distinct from NULL, so we use the address of a variable that
+ * happens to be handy.
+ */
+static smallint tokpushback; /* last token pushed back */
#define NEOF ((union node *)&tokpushback)
-static int parsebackquote; /* nonzero if we are inside backquotes */
+static smallint parsebackquote; /* nonzero if we are inside backquotes */
static int lasttoken; /* last token read */
static char *wordtext; /* text of last word returned by readtoken */
static struct nodelist *backquotelist;
static union node *redirnode;
static struct heredoc *heredoc;
-static int quoteflag; /* set if (part of) last token was quoted */
+static smallint quoteflag; /* set if (part of) last token was quoted */
static void raise_error_syntax(const char *) ATTRIBUTE_NORETURN;
static void
if (nlflag == 1)
return n1;
} else {
- tokpushback++;
+ tokpushback = 1;
}
checkkwd = CHKNL | CHKKWD | CHKALIAS;
if (peektoken())
default:
if (nlflag == 1)
raise_error_unexpected_syntax(-1);
- tokpushback++;
+ tokpushback = 1;
return n1;
}
}
} else if (t == TOR) {
t = NOR;
} else {
- tokpushback++;
+ tokpushback = 1;
return n1;
}
checkkwd = CHKNL | CHKKWD | CHKALIAS;
negate = !negate;
checkkwd = CHKKWD | CHKALIAS;
} else
- tokpushback++;
+ tokpushback = 1;
n1 = parse_command();
if (readtoken() == TPIPE) {
pipenode = stalloc(sizeof(struct npipe));
lp->next = NULL;
n1 = pipenode;
}
- tokpushback++;
+ tokpushback = 1;
if (negate) {
n2 = stalloc(sizeof(struct nnot));
n2->type = NNOT;
}
/* fall through */
default:
- tokpushback++;
+ tokpushback = 1;
goto out;
}
}
n2->nif.elsepart = list(0);
else {
n2->nif.elsepart = NULL;
- tokpushback++;
+ tokpushback = 1;
}
t = TFI;
break;
* that the original Bourne shell only allowed NL).
*/
if (lasttoken != TNL && lasttoken != TSEMI)
- tokpushback++;
+ tokpushback = 1;
}
checkkwd = CHKNL | CHKKWD | CHKALIAS;
if (readtoken() != TDO)
break;
case TWORD:
case TREDIR:
- tokpushback++;
+ tokpushback = 1;
return simplecmd();
}
rpp = &n2->nfile.next;
parsefname();
}
- tokpushback++;
+ tokpushback = 1;
*rpp = NULL;
if (redir) {
if (n1->type != NSUBSHELL) {
* will run code that appears at the end of readtoken1.
*/
-static int parsebackquote; /* nonzero if we are inside backquotes */
-
#define CHECKEND() {goto checkend; checkend_return:;}
#define PARSEREDIR() {goto parseredir; parseredir_return:;}
#define PARSESUB() {goto parsesub; parsesub_return:;}
static int
readtoken1(int firstc, int syntax, char *eofmark, int striptabs)
{
+ /* NB: syntax parameter fits into smallint */
int c = firstc;
char *out;
int len;
char line[EOFMARKLEN + 1];
- struct nodelist *bqlist = 0;
- int quotef = 0;
- int dblquote = 0;
- int varnest = 0; /* levels of variables expansion */
- int arinest = 0; /* levels of arithmetic expansion */
- int parenlevel = 0; /* levels of parens in arithmetic */
- int dqvarnest = 0; /* levels of variables expansion within double quotes */
- int oldstyle = 0;
- int prevsyntax = 0; /* syntax before arithmetic */
+ struct nodelist *bqlist;
+ smallint quotef;
+ smallint dblquote;
+ smallint oldstyle;
+ smallint prevsyntax; /* syntax before arithmetic */
+ int varnest; /* levels of variables expansion */
+ int arinest; /* levels of arithmetic expansion */
+ int parenlevel; /* levels of parens in arithmetic */
+ int dqvarnest; /* levels of variables expansion within double quotes */
+
#if __GNUC__
/* Avoid longjmp clobbering */
(void) &out;
(void) &prevsyntax;
(void) &syntax;
#endif
-
startlinno = plinno;
- dblquote = 0;
- if (syntax == DQSYNTAX)
- dblquote = 1;
- quotef = 0;
bqlist = NULL;
+ quotef = 0;
+ dblquote = (syntax == DQSYNTAX);
+ oldstyle = 0;
+ prevsyntax = 0;
varnest = 0;
arinest = 0;
parenlevel = 0;
if (SIT(c, SQSYNTAX) == CCTL)
USTPUTC(CTLESC, out);
USTPUTC(c, out);
- quotef++;
+ quotef = 1;
}
break;
case CSQUOTE:
syntax = BASESYNTAX;
dblquote = 0;
}
- quotef++;
+ quotef = 1;
goto quotemark;
}
break;
if (--arinest == 0) {
USTPUTC(CTLENDARI, out);
syntax = prevsyntax;
- if (syntax == DQSYNTAX)
- dblquote = 1;
- else
- dblquote = 0;
+ dblquote = (syntax == DQSYNTAX);
} else
USTPUTC(')', out);
} else {
*/
parsebackq: {
struct nodelist **nlpp;
- int savepbq;
+ smallint savepbq;
union node *n;
char *volatile str;
struct jmploc jmploc;
struct jmploc *volatile savehandler;
size_t savelen;
- int saveprompt = 0;
+ smallint saveprompt = 0;
+
#ifdef __GNUC__
(void) &saveprompt;
#endif
-
savepbq = parsebackquote;
if (setjmp(jmploc.loc)) {
if (str)
{
int t;
#if DEBUG
- int alreadyseen = tokpushback;
+ smallint alreadyseen = tokpushback;
#endif
#if ENABLE_ASH_ALIAS
int t;
t = readtoken();
- tokpushback++;
+ tokpushback = 1;
return tokname_array[t][0];
}
return NEOF;
if (t == TNL)
return NULL;
- tokpushback++;
+ tokpushback = 1;
return list(1);
}