All of lore.kernel.org
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: Harald van Dijk <harald@gigawatt.nl>
Cc: наб <nabijaczleweli@nabijaczleweli.xyz>, dash@vger.kernel.org
Subject: [PATCH] input: Only skip blank lines on PS1
Date: Thu, 5 Jan 2023 15:26:10 +0800	[thread overview]
Message-ID: <Y7Z7kiVnwF+sltL+@gondor.apana.org.au> (raw)
In-Reply-To: <83fb967d-19e3-d7de-becc-179af3045e59@gigawatt.nl>

On Wed, Jan 04, 2023 at 11:18:49AM +0000, Harald van Dijk wrote:
> 
> One is that because of what you say, the history recording for commands
> greater than BUFSIZ is already buggy, but unlikely to pose a problem in
> practice currently because normally, people don't write such long commands.

It's not just that people don't write long lines, it's the fact
that most people use the shell with a terminal device in canonical
mode and the line length is capped in canonical mode to some value
less than 8K.

> Another is that the stripping of blank lines from history breaks when blank
> lines are significant, as in
> 
>   $ cat <<EOF
>   > hello
>   >
>   > world
>   > EOF
>   hello
> 
>   world
>   $ fc 1
>   26
>   q
>   hello
>   world
> 
> Note how the blank line was lost.
> 
> If there was already "something" (as the code puts it), then when more data
> is appended, blanks must be preserved.

Good point.  This patch should fix it.

---8<---
Blank line should not be skipped if they're found on PS2.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/src/input.c b/src/input.c
index 7b37ae2..5dcc8a2 100644
--- a/src/input.c
+++ b/src/input.c
@@ -254,6 +254,7 @@ retry:
 
 static int preadbuffer(void)
 {
+	int first = whichprompt == 1;
 	int something;
 	char savec;
 	int more;
@@ -279,7 +280,7 @@ again:
 	q = parsefile->nextc;
 
 	/* delete nul characters */
-	something = 0;
+	something = !first;
 	for (;;) {
 		int c;
 
@@ -327,7 +328,7 @@ check:
 	if (parsefile->fd == 0 && hist && something) {
 		HistEvent he;
 		INTOFF;
-		history(hist, &he, whichprompt == 1? H_ENTER : H_APPEND,
+		history(hist, &he, first ? H_ENTER : H_APPEND,
 			parsefile->nextc);
 		INTON;
 	}
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

  reply	other threads:[~2023-01-05  7:26 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-13 22:17 [PATCH] input: preadfd: read standard input byte-wise наб
2022-12-13 22:37 ` Harald van Dijk
2022-12-14  1:05   ` наб
2022-12-14  1:06     ` [PATCH v2 1/3] parser: fixredir: invalid redirections are run-time, not syntax наб
2023-01-05  9:43       ` Herbert Xu
2022-12-14  1:06     ` [PATCH v2 2/3] parser: synerror: explicitly consume the entire invalid line наб
2023-01-03  1:53       ` Herbert Xu
2023-01-03  5:32         ` [PATCH] input: Eat rest of line upon reset Herbert Xu
2023-01-03 11:47         ` [PATCH v2 2/3] parser: synerror: explicitly consume the entire invalid line Harald van Dijk
2023-01-04  9:51           ` Herbert Xu
2023-01-04 11:25             ` Harald van Dijk
2023-01-04 14:10               ` Herbert Xu
2023-01-04 14:30                 ` Harald van Dijk
2023-01-04 14:41                   ` Herbert Xu
2023-01-04 14:59                     ` Harald van Dijk
2023-01-05  7:12                       ` [PATCH] input: Check for int_pending while clearing input Herbert Xu
2022-12-14  1:06     ` [PATCH v2 3/3] input: preadfd: read standard input byte-wise наб
2023-01-03  6:15       ` [v3 PATCH] input: Read " Herbert Xu
2023-01-03 11:54         ` Harald van Dijk
2023-01-04  8:59           ` Herbert Xu
2023-01-04 11:18             ` Harald van Dijk
2023-01-05  7:26               ` Herbert Xu [this message]
2023-01-05  8:33                 ` [PATCH] input: Only skip blank lines on PS1 Harald van Dijk

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=Y7Z7kiVnwF+sltL+@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=dash@vger.kernel.org \
    --cc=harald@gigawatt.nl \
    --cc=nabijaczleweli@nabijaczleweli.xyz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.