ash: shrink by folding an if check into setprompt; unindent big block

function                                             old     new   delta
setprompt_if                                           -      66     +66
parseheredoc                                         126     124      -2
parsecmd                                              68      66      -2
redirect                                            1254    1249      -5
xxreadtoken                                          351     343      -8
readtoken1                                          3219    3204     -15
setprompt                                             62       -     -62
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/5 up/down: 66/-94)            Total: -28 bytes

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko 2010-09-12 15:04:27 +02:00
parent 6040fe88f4
commit 958581a8d9

View File

@ -2433,12 +2433,13 @@ static const char *expandstr(const char *ps);
#endif
static void
setprompt(int whichprompt)
setprompt_if(smallint do_set, int whichprompt)
{
const char *prompt;
#if ENABLE_ASH_EXPAND_PRMT
struct stackmark smark;
#endif
IF_ASH_EXPAND_PRMT(struct stackmark smark;)
if (!do_set)
return;
needprompt = 0;
@ -6022,9 +6023,7 @@ argstr(char *p, int flags, struct strlist *var_str_list)
c = p[length];
if (c) {
if (!(c & 0x80)
#if ENABLE_SH_MATH_SUPPORT
|| c == CTLENDARI
#endif
IF_SH_MATH_SUPPORT(|| c == CTLENDARI)
) {
/* c == '=' || c == ':' || c == CTLENDARI */
length++;
@ -6107,8 +6106,7 @@ argstr(char *p, int flags, struct strlist *var_str_list)
#endif
}
}
breakloop:
;
breakloop: ;
}
static char *
@ -11054,7 +11052,6 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
STARTSTACKSTR(out);
loop:
/* For each line, until end of word */
{
CHECKEND(); /* set c to PEOF if at end of here document */
for (;;) { /* until end of line or end of word */
CHECKSTRSPACE(4, out); /* permit 4 calls to USTPUTC */
@ -11064,8 +11061,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
goto endword; /* exit outer loop */
USTPUTC(c, out);
g_parsefile->linno++;
if (doprompt)
setprompt(2);
setprompt_if(doprompt, 2);
c = pgetc();
goto loop; /* continue outer loop */
case CWORD:
@ -11092,8 +11088,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
USTPUTC('\\', out);
pungetc();
} else if (c == '\n') {
if (doprompt)
setprompt(2);
setprompt_if(doprompt, 2);
} else {
#if ENABLE_ASH_EXPAND_PRMT
if (c == '$' && pssyntax) {
@ -11205,8 +11200,8 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
}
c = pgetc_fast();
} /* for (;;) */
}
endword:
#if ENABLE_SH_MATH_SUPPORT
if (syntax == ARISYNTAX)
raise_error_syntax("missing '))'");
@ -11542,16 +11537,14 @@ parsebackq: {
treatment to some slashes, and then push the string and
reread it as input, interpreting it normally. */
char *pout;
int pc;
size_t psavelen;
char *pstr;
STARTSTACKSTR(pout);
for (;;) {
if (needprompt) {
setprompt(2);
}
int pc;
setprompt_if(needprompt, 2);
pc = pgetc();
switch (pc) {
case '`':
@ -11561,8 +11554,7 @@ parsebackq: {
pc = pgetc();
if (pc == '\n') {
g_parsefile->linno++;
if (doprompt)
setprompt(2);
setprompt_if(doprompt, 2);
/*
* If eating a newline, avoid putting
* the newline into the new character
@ -11725,9 +11717,7 @@ xxreadtoken(void)
tokpushback = 0;
return lasttoken;
}
if (needprompt) {
setprompt(2);
}
setprompt_if(needprompt, 2);
startlinno = g_parsefile->linno;
for (;;) { /* until token or start of word found */
c = pgetc_fast();
@ -11744,8 +11734,7 @@ xxreadtoken(void)
break; /* return readtoken1(...) */
}
startlinno = ++g_parsefile->linno;
if (doprompt)
setprompt(2);
setprompt_if(doprompt, 2);
} else {
const char *p;
@ -11791,9 +11780,7 @@ xxreadtoken(void)
tokpushback = 0;
return lasttoken;
}
if (needprompt) {
setprompt(2);
}
setprompt_if(needprompt, 2);
startlinno = g_parsefile->linno;
for (;;) { /* until token or start of word found */
c = pgetc_fast();
@ -11809,8 +11796,7 @@ xxreadtoken(void)
case '\\':
if (pgetc() == '\n') {
startlinno = ++g_parsefile->linno;
if (doprompt)
setprompt(2);
setprompt_if(doprompt, 2);
continue;
}
pungetc();
@ -11936,8 +11922,7 @@ parsecmd(int interact)
tokpushback = 0;
doprompt = interact;
if (doprompt)
setprompt(doprompt);
setprompt_if(doprompt, doprompt);
needprompt = 0;
t = readtoken();
if (t == TEOF)
@ -11961,9 +11946,7 @@ parseheredoc(void)
heredoclist = NULL;
while (here) {
if (needprompt) {
setprompt(2);
}
setprompt_if(needprompt, 2);
readtoken1(pgetc(), here->here->type == NHERE ? SQSYNTAX : DQSYNTAX,
here->eofmark, here->striptabs);
n = stzalloc(sizeof(struct narg));