From: Herbert Xu <herbert@gondor.apana.org.au>
To: DASH Mailing List <dash@vger.kernel.org>
Subject: [v3 PATCH 10/13] input: Always push in setinputfile
Date: Sun, 05 May 2024 17:15:20 +0800 [thread overview]
Message-ID: <8d9afe982b262ddee001fcaca4bec5de5958ad91.1714900377.git.herbert@gondor.apana.org.au> (raw)
In-Reply-To: <cover.1714900377.git.herbert@gondor.apana.org.au>
Push the input file even in the case of "sh file". This is because
the base parsefile will be used for read(1).
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
src/input.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/input.c b/src/input.c
index bedc581..1712e5f 100644
--- a/src/input.c
+++ b/src/input.c
@@ -61,6 +61,7 @@
MKINIT struct parsefile basepf; /* top level input file */
MKINIT char basebuf[IBUFSIZ]; /* buffer for top level input file */
+MKINIT struct parsefile *toppf = &basepf;
struct parsefile *parsefile = &basepf; /* current input file */
int whichprompt; /* 1 == PS1, 2 == PS2 */
@@ -89,8 +90,8 @@ RESET {
popallfiles();
c = PEOF;
- if (basepf.nextc - basebuf > basepf.unget)
- c = basepf.nextc[-basepf.unget - 1];
+ if (toppf->nextc - toppf->buf > toppf->unget)
+ c = toppf->nextc[-toppf->unget - 1];
while (c != '\n' && c != PEOF && !int_pending())
c = pgetc();
}
@@ -473,13 +474,11 @@ out:
static void
setinputfd(int fd, int push)
{
- if (push) {
- pushfile();
- parsefile->buf = 0;
- }
+ pushfile();
+ if (!push)
+ toppf = parsefile;
parsefile->fd = fd;
- if (parsefile->buf == NULL)
- parsefile->nextc = parsefile->buf = ckmalloc(IBUFSIZ);
+ parsefile->nextc = parsefile->buf = ckmalloc(IBUFSIZ);
input_set_lleft(parsefile, parsefile->nleft = 0);
plinno = 1;
}
@@ -560,5 +559,5 @@ void unwindfiles(struct parsefile *stop)
void
popallfiles(void)
{
- unwindfiles(&basepf);
+ unwindfiles(toppf);
}
--
2.39.2
next prev parent reply other threads:[~2024-05-05 9:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-05 9:14 [v3 PATCH 00/13] Add multi-byte support Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 01/13] shell: Call setlocale Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 02/13] shell: Use strcoll instead of strcmp where applicable Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 03/13] expand: Count multi-byte characters for VSLENGTH Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 04/13] expand: Process multi-byte characters in subevalvar Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 05/13] expand: Process multi-byte characters in expmeta Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 06/13] expand: Support multi-byte characters during field splitting Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 07/13] input: Allow MB_LEN_MAX calls to pungetc Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 08/13] input: Add pgetc_eoa Herbert Xu
2024-05-05 9:14 ` [v3 PATCH 09/13] parser: Add support for multi-byte characters Herbert Xu
2024-05-05 9:15 ` Herbert Xu [this message]
2024-05-05 9:15 ` [v3 PATCH 11/13] memalloc: Use void * instead of pointer Herbert Xu
2024-05-05 9:15 ` [v3 PATCH 12/13] builtin: Use pgetc in read(1) Herbert Xu
2024-05-05 9:15 ` [v3 PATCH 13/13] builtin: Process multi-byte characters " Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8d9afe982b262ddee001fcaca4bec5de5958ad91.1714900377.git.herbert@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).