diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-02 23:47:34 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-10-02 23:47:34 +0200 |
commit | ce332a23a3ff45a5aeb3e737da15b469badd5d12 (patch) | |
tree | 88de12acf709b1d3a84b9bdd6dd6ea679347ebfe /shell | |
parent | 80729a4472e3876c885139414e035fe50e696cbf (diff) | |
download | busybox-w32-ce332a23a3ff45a5aeb3e737da15b469badd5d12.tar.gz busybox-w32-ce332a23a3ff45a5aeb3e737da15b469badd5d12.tar.bz2 busybox-w32-ce332a23a3ff45a5aeb3e737da15b469badd5d12.zip |
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>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/shell/ash.c b/shell/ash.c index 714b011a5..a317d0080 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -10030,6 +10030,19 @@ preadbuffer(void) | |||
10030 | return (unsigned char)*g_parsefile->next_to_pgetc++; | 10030 | return (unsigned char)*g_parsefile->next_to_pgetc++; |
10031 | } | 10031 | } |
10032 | 10032 | ||
10033 | static void | ||
10034 | nlprompt(void) | ||
10035 | { | ||
10036 | g_parsefile->linno++; | ||
10037 | setprompt_if(doprompt, 2); | ||
10038 | } | ||
10039 | static void | ||
10040 | nlnoprompt(void) | ||
10041 | { | ||
10042 | g_parsefile->linno++; | ||
10043 | needprompt = doprompt; | ||
10044 | } | ||
10045 | |||
10033 | static int | 10046 | static int |
10034 | pgetc(void) | 10047 | pgetc(void) |
10035 | { | 10048 | { |
@@ -10118,8 +10131,7 @@ pgetc_eatbnl(void) | |||
10118 | break; | 10131 | break; |
10119 | } | 10132 | } |
10120 | 10133 | ||
10121 | g_parsefile->linno++; | 10134 | nlprompt(); |
10122 | setprompt_if(doprompt, 2); | ||
10123 | } | 10135 | } |
10124 | 10136 | ||
10125 | return c; | 10137 | return c; |
@@ -11409,8 +11421,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
11409 | if (syntax == BASESYNTAX) | 11421 | if (syntax == BASESYNTAX) |
11410 | goto endword; /* exit outer loop */ | 11422 | goto endword; /* exit outer loop */ |
11411 | USTPUTC(c, out); | 11423 | USTPUTC(c, out); |
11412 | g_parsefile->linno++; | 11424 | nlprompt(); |
11413 | setprompt_if(doprompt, 2); | ||
11414 | c = pgetc(); | 11425 | c = pgetc(); |
11415 | goto loop; /* continue outer loop */ | 11426 | goto loop; /* continue outer loop */ |
11416 | case CWORD: | 11427 | case CWORD: |
@@ -11444,7 +11455,7 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) | |||
11444 | USTPUTC('\\', out); | 11455 | USTPUTC('\\', out); |
11445 | pungetc(); | 11456 | pungetc(); |
11446 | } else if (c == '\n') { | 11457 | } else if (c == '\n') { |
11447 | setprompt_if(doprompt, 2); | 11458 | nlprompt(); |
11448 | } else { | 11459 | } else { |
11449 | #if ENABLE_ASH_EXPAND_PRMT | 11460 | #if ENABLE_ASH_EXPAND_PRMT |
11450 | if (c == '$' && pssyntax) { | 11461 | if (c == '$' && pssyntax) { |
@@ -11615,8 +11626,7 @@ checkend: { | |||
11615 | continue; | 11626 | continue; |
11616 | if (*p == '\n' && *q == '\0') { | 11627 | if (*p == '\n' && *q == '\0') { |
11617 | c = PEOF; | 11628 | c = PEOF; |
11618 | g_parsefile->linno++; | 11629 | nlnoprompt(); |
11619 | needprompt = doprompt; | ||
11620 | } else { | 11630 | } else { |
11621 | pushstring(line, NULL); | 11631 | pushstring(line, NULL); |
11622 | } | 11632 | } |
@@ -11898,8 +11908,7 @@ parsebackq: { | |||
11898 | case '\\': | 11908 | case '\\': |
11899 | pc = pgetc(); | 11909 | pc = pgetc(); |
11900 | if (pc == '\n') { | 11910 | if (pc == '\n') { |
11901 | g_parsefile->linno++; | 11911 | nlprompt(); |
11902 | setprompt_if(doprompt, 2); | ||
11903 | /* | 11912 | /* |
11904 | * If eating a newline, avoid putting | 11913 | * If eating a newline, avoid putting |
11905 | * the newline into the new character | 11914 | * the newline into the new character |
@@ -11924,8 +11933,7 @@ parsebackq: { | |||
11924 | raise_error_syntax("EOF in backquote substitution"); | 11933 | raise_error_syntax("EOF in backquote substitution"); |
11925 | 11934 | ||
11926 | case '\n': | 11935 | case '\n': |
11927 | g_parsefile->linno++; | 11936 | nlnoprompt(); |
11928 | needprompt = doprompt; | ||
11929 | break; | 11937 | break; |
11930 | 11938 | ||
11931 | default: | 11939 | default: |
@@ -12057,16 +12065,14 @@ xxreadtoken(void) | |||
12057 | pungetc(); | 12065 | pungetc(); |
12058 | break; /* return readtoken1(...) */ | 12066 | break; /* return readtoken1(...) */ |
12059 | } | 12067 | } |
12060 | startlinno = ++g_parsefile->linno; | 12068 | nlprompt(); |
12061 | setprompt_if(doprompt, 2); | ||
12062 | } else { | 12069 | } else { |
12063 | const char *p; | 12070 | const char *p; |
12064 | 12071 | ||
12065 | p = xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1; | 12072 | p = xxreadtoken_chars + sizeof(xxreadtoken_chars) - 1; |
12066 | if (c != PEOF) { | 12073 | if (c != PEOF) { |
12067 | if (c == '\n') { | 12074 | if (c == '\n') { |
12068 | g_parsefile->linno++; | 12075 | nlnoprompt(); |
12069 | needprompt = doprompt; | ||
12070 | } | 12076 | } |
12071 | 12077 | ||
12072 | p = strchr(xxreadtoken_chars, c); | 12078 | p = strchr(xxreadtoken_chars, c); |
@@ -12119,15 +12125,13 @@ xxreadtoken(void) | |||
12119 | continue; | 12125 | continue; |
12120 | case '\\': | 12126 | case '\\': |
12121 | if (pgetc() == '\n') { | 12127 | if (pgetc() == '\n') { |
12122 | startlinno = ++g_parsefile->linno; | 12128 | nlprompt(); |
12123 | setprompt_if(doprompt, 2); | ||
12124 | continue; | 12129 | continue; |
12125 | } | 12130 | } |
12126 | pungetc(); | 12131 | pungetc(); |
12127 | goto breakloop; | 12132 | goto breakloop; |
12128 | case '\n': | 12133 | case '\n': |
12129 | g_parsefile->linno++; | 12134 | nlnoprompt(); |
12130 | needprompt = doprompt; | ||
12131 | RETURN(TNL); | 12135 | RETURN(TNL); |
12132 | case PEOF: | 12136 | case PEOF: |
12133 | RETURN(TEOF); | 12137 | RETURN(TEOF); |