From: Herbert Xu <herbert@gondor.apana.org.au>
To: dash@vger.kernel.org
Subject: [PATCH] input: Disable lleft in SMALL mode
Date: Tue, 3 Jan 2023 17:08:37 +0800 [thread overview]
Message-ID: <Y7PwlSeCwzgXztfc@gondor.apana.org.au> (raw)
Counting lleft is only necessary if history support is enabled.
Therefore it can be safely disabled if SMALL is defined.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/src/input.c b/src/input.c
index 8691617..7b37ae2 100644
--- a/src/input.c
+++ b/src/input.c
@@ -54,9 +54,7 @@
#include "alias.h"
#include "parser.h"
#include "main.h"
-#ifndef SMALL
#include "myhistedit.h"
-#endif
#define IBUFSIZ (BUFSIZ + 1)
@@ -256,12 +254,10 @@ retry:
static int preadbuffer(void)
{
- char *q;
- int more;
-#ifndef SMALL
int something;
-#endif
char savec;
+ int more;
+ char *q;
if (unlikely(parsefile->strpush)) {
popstring();
@@ -271,11 +267,11 @@ static int preadbuffer(void)
return PEOF;
flushall();
- more = parsefile->lleft;
+ more = input_get_lleft(parsefile);
if (more <= 0) {
again:
if ((more = preadfd()) <= 0) {
- parsefile->lleft = parsefile->nleft = 0;
+ input_set_lleft(parsefile, parsefile->nleft = 0);
return PEOF;
}
}
@@ -283,37 +279,38 @@ again:
q = parsefile->nextc;
/* delete nul characters */
-#ifndef SMALL
something = 0;
-#endif
for (;;) {
int c;
more--;
c = *q;
- if (!c)
+ if (!c) {
memmove(q, q + 1, more);
- else {
- q++;
+ goto check;
+ }
- if (c == '\n') {
- parsefile->nleft = q - parsefile->nextc - 1;
- break;
- }
+ q++;
-#ifndef SMALL
- switch (c) {
- default:
- something = 1;
- /* fall through */
- case '\t':
- case ' ':
- break;
- }
-#endif
+ if (IS_DEFINED_SMALL)
+ goto check;
+
+ switch (c) {
+ case '\n':
+ parsefile->nleft = q - parsefile->nextc - 1;
+ goto check;
+
+ default:
+ something = 1;
+ /* fall through */
+
+ case '\t':
+ case ' ':
+ break;
}
+check:
if (more <= 0) {
parsefile->nleft = q - parsefile->nextc - 1;
if (parsefile->nleft < 0)
@@ -321,12 +318,12 @@ again:
break;
}
}
- parsefile->lleft = more;
+ input_set_lleft(parsefile, more);
- savec = *q;
+ if (!IS_DEFINED_SMALL)
+ savec = *q;
*q = '\0';
-#ifndef SMALL
if (parsefile->fd == 0 && hist && something) {
HistEvent he;
INTOFF;
@@ -334,7 +331,6 @@ again:
parsefile->nextc);
INTON;
}
-#endif
if (vflag) {
out2str(parsefile->nextc);
@@ -343,7 +339,8 @@ again:
#endif
}
- *q = savec;
+ if (!IS_DEFINED_SMALL)
+ *q = savec;
return (signed char)*parsefile->nextc++;
}
@@ -458,7 +455,7 @@ setinputfd(int fd, int push)
parsefile->fd = fd;
if (parsefile->buf == NULL)
parsefile->buf = ckmalloc(IBUFSIZ);
- parsefile->lleft = parsefile->nleft = 0;
+ input_set_lleft(parsefile, parsefile->nleft = 0);
plinno = 1;
}
diff --git a/src/input.h b/src/input.h
index 8830b66..1ff5773 100644
--- a/src/input.h
+++ b/src/input.h
@@ -76,7 +76,9 @@ struct parsefile {
int linno; /* current line */
int fd; /* file descriptor (or -1 if string) */
int nleft; /* number of chars left in this line */
+#ifndef SMALL
int lleft; /* number of chars left in this buffer */
+#endif
char *nextc; /* next char in buffer */
char *buf; /* input buffer */
struct strpush *strpush; /* for pushing strings at this level */
@@ -110,3 +112,19 @@ void setinputstring(char *);
void popfile(void);
void unwindfiles(struct parsefile *);
void popallfiles(void);
+
+static inline int input_get_lleft(struct parsefile *pf)
+{
+#ifdef SMALL
+ return 0;
+#else
+ return pf->lleft;
+#endif
+}
+
+static inline void input_set_lleft(struct parsefile *pf, int len)
+{
+#ifndef SMALL
+ pf->lleft = len;
+#endif
+}
diff --git a/src/myhistedit.h b/src/myhistedit.h
index 22e5c43..1736f62 100644
--- a/src/myhistedit.h
+++ b/src/myhistedit.h
@@ -31,9 +31,27 @@
* @(#)myhistedit.h 8.2 (Berkeley) 5/4/95
*/
+#ifdef SMALL
+typedef void History;
+typedef void EditLine;
+typedef int HistEvent;
+
+enum {
+ H_APPEND,
+ H_ENTER,
+};
+
+#define hist NULL
+
+static inline void history(History *h, HistEvent *he, int action, char *p)
+{
+}
+#else
#include <histedit.h>
extern History *hist;
+#endif
+
extern EditLine *el;
extern int displayhist;
--
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-03 9:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=Y7PwlSeCwzgXztfc@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).