ash: [PARSER] Add nlprompt/nlnoprompt helpers

Upstream commit:

    Date: Mon, 29 Sep 2014 22:53:53 +0800
    [PARSER] Add nlprompt/nlnoprompt helpers

    This patch adds the nlprompt/nlnoprompt helpers to isolate code
    dealing with newlines and prompting.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2016-10-02 23:47:34 +02:00
parent 80729a4472
commit ce332a23a3

View File

@ -10030,6 +10030,19 @@ preadbuffer(void)
return (unsigned char)*g_parsefile->next_to_pgetc++; return (unsigned char)*g_parsefile->next_to_pgetc++;
} }
static void
nlprompt(void)
{
g_parsefile->linno++;
setprompt_if(doprompt, 2);
}
static void
nlnoprompt(void)
{
g_parsefile->linno++;
needprompt = doprompt;
}
static int static int
pgetc(void) pgetc(void)
{ {
@ -10118,8 +10131,7 @@ pgetc_eatbnl(void)
break; break;
} }
g_parsefile->linno++; nlprompt();
setprompt_if(doprompt, 2);
} }
return c; return c;
@ -11409,8 +11421,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
if (syntax == BASESYNTAX) if (syntax == BASESYNTAX)
goto endword; /* exit outer loop */ goto endword; /* exit outer loop */
USTPUTC(c, out); USTPUTC(c, out);
g_parsefile->linno++; nlprompt();
setprompt_if(doprompt, 2);
c = pgetc(); c = pgetc();
goto loop; /* continue outer loop */ goto loop; /* continue outer loop */
case CWORD: case CWORD:
@ -11444,7 +11455,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
USTPUTC('\\', out); USTPUTC('\\', out);
pungetc(); pungetc();
} else if (c == '\n') { } else if (c == '\n') {
setprompt_if(doprompt, 2); nlprompt();
} else { } else {
#if ENABLE_ASH_EXPAND_PRMT #if ENABLE_ASH_EXPAND_PRMT
if (c == '$' && pssyntax) { if (c == '$' && pssyntax) {
@ -11615,8 +11626,7 @@ checkend: {
continue; continue;
if (*p == '\n' && *q == '\0') { if (*p == '\n' && *q == '\0') {
c = PEOF; c = PEOF;
g_parsefile->linno++; nlnoprompt();
needprompt = doprompt;
} else { } else {
pushstring(line, NULL); pushstring(line, NULL);
} }
@ -11898,8 +11908,7 @@ parsebackq: {
case '\\': case '\\':
pc = pgetc(); pc = pgetc();
if (pc == '\n') { if (pc == '\n') {
g_parsefile->linno++; nlprompt();
setprompt_if(doprompt, 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
@ -11924,8 +11933,7 @@ parsebackq: {
raise_error_syntax("EOF in backquote substitution"); raise_error_syntax("EOF in backquote substitution");
case '\n': case '\n':
g_parsefile->linno++; nlnoprompt();
needprompt = doprompt;
break; break;
default: default:
@ -12057,16 +12065,14 @@ xxreadtoken(void)
pungetc(); pungetc();
break; /* return readtoken1(...) */ break; /* return readtoken1(...) */
} }
startlinno = ++g_parsefile->linno; nlprompt();
setprompt_if(doprompt, 2);
} else { } else {
const char *p; const char *p;
p = xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1; p = xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1;
if (c != PEOF) { if (c != PEOF) {
if (c == '\n') { if (c == '\n') {
g_parsefile->linno++; nlnoprompt();
needprompt = doprompt;
} }
p = strchr(xxreadtoken_chars, c); p = strchr(xxreadtoken_chars, c);
@ -12119,15 +12125,13 @@ xxreadtoken(void)
continue; continue;
case '\\': case '\\':
if (pgetc() == '\n') { if (pgetc() == '\n') {
startlinno = ++g_parsefile->linno; nlprompt();
setprompt_if(doprompt, 2);
continue; continue;
} }
pungetc(); pungetc();
goto breakloop; goto breakloop;
case '\n': case '\n':
g_parsefile->linno++; nlnoprompt();
needprompt = doprompt;
RETURN(TNL); RETURN(TNL);
case PEOF: case PEOF:
RETURN(TEOF); RETURN(TEOF);