summaryrefslogtreecommitdiffstats
path: root/usr.bin/bc/scan.l
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/bc/scan.l')
-rw-r--r--usr.bin/bc/scan.l39
1 files changed, 39 insertions, 0 deletions
diff --git a/usr.bin/bc/scan.l b/usr.bin/bc/scan.l
index 81dd862..40f8ae6 100644
--- a/usr.bin/bc/scan.l
+++ b/usr.bin/bc/scan.l
@@ -22,6 +22,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
+#include <histedit.h>
#include <signal.h>
#include <stdbool.h>
#include <string.h>
@@ -33,13 +34,22 @@ __FBSDID("$FreeBSD$");
int lineno;
+bool interactive;
+HistEvent he;
+EditLine *el;
+History *hist;
+
static char *strbuf = NULL;
static size_t strbuf_sz = 1;
static bool dot_seen;
static void init_strbuf(void);
static void add_str(const char *);
+static int bc_yyinput(char *, int);
+#undef YY_INPUT
+#define YY_INPUT(buf,retval,max) \
+ (retval = bc_yyinput(buf, max))
%}
%option always-interactive
@@ -286,3 +296,32 @@ yywrap(void)
}
return (1);
}
+
+static int
+bc_yyinput(char *buf, int maxlen)
+{
+ int num;
+ if (interactive) {
+ const char *bp;
+
+ if ((bp = el_gets(el, &num)) == NULL || num == 0)
+ return (0);
+ if (num > maxlen) {
+ el_push(el, (char *)(uintptr_t)(bp) + maxlen);
+ num = maxlen;
+ }
+ memcpy(buf, bp, num);
+ history(hist, &he, H_ENTER, bp);
+ } else {
+ int c = '*';
+ for (num = 0; num < maxlen &&
+ (c = getc(yyin)) != EOF && c != '\n'; ++num)
+ buf[num] = (char) c;
+ if (c == '\n')
+ buf[num++] = (char) c;
+ if (c == EOF && ferror(yyin))
+ YY_FATAL_ERROR( "input in flex scanner failed" );
+ }
+ return (num);
+}
+
OpenPOWER on IntegriCloud