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