Re: History for bc(1)
On Wed, Mar 02, 2011 at 12:33:49PM +0100, Otto Moerbeek wrote: On Wed, Mar 02, 2011 at 10:18:08AM +, Jason McIntyre wrote: On Wed, Mar 02, 2011 at 10:13:35AM +0100, Otto Moerbeek wrote: Lets try to make some progress here. This is the diff I have had in my tree for a while. It is a port of the freebsd code. What is lacking is the man page stuff. So if sombody could merge that from freebsd, I'd be happy. if you can mail me (privately) the page, and indicate what parts are relevant, i can do that. jmc Hmm, glanced at the freebsd page, but they do not mention anything with respect to editline, I wrongly supposed to would have included that. I think we could nick the relevant lines from e.g. ftp(1). -Otto I just commited the diff, including a few lines in the man page. -Otto
Re: History for bc(1)
On Tue, Feb 15, 2011 at 01:01:33PM +0100, Otto Moerbeek wrote: On Tue, Feb 15, 2011 at 12:23:41PM +0100, Gabriel Linder wrote: On 02/14/11 17:43, Christiano F. Haesbaert wrote: Any news on this ? The diff still apply on -current. If there are changes needed I can work on it, but I have no news. sorry, in have a diff in my tree, but I see myself always ignoring it. I just almost never actually use the editing capabilities. It seems my 25yr finger memory is too strong. So I'm not a proper tester for this diff, other than it does not seem to cause a regression. -Otto Lets try to make some progress here. This is the diff I have had in my tree for a while. It is a port of the freebsd code. What is lacking is the man page stuff. So if sombody could merge that from freebsd, I'd be happy. -Otto Index: Makefile === RCS file: /cvs/src/usr.bin/bc/Makefile,v retrieving revision 1.5 diff -u -p -r1.5 Makefile --- Makefile17 Oct 2010 22:54:37 - 1.5 +++ Makefile28 Oct 2010 07:22:05 - @@ -5,6 +5,9 @@ SRCS= bc.y scan.l CPPFLAGS+= -I. -I${.CURDIR} CFLAGS+= -Wall -Wno-unused YFLAGS+= +LDADD+=-ledit -lcurses +DPADD+=${LIBEDIT} ${LIBCURSES} + beforeinstall: install -c -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/bc.library \ Index: bc.y === RCS file: /cvs/src/usr.bin/bc/bc.y,v retrieving revision 1.33 diff -u -p -r1.33 bc.y --- bc.y27 Oct 2009 23:59:36 - 1.33 +++ bc.y5 Feb 2010 19:09:43 - @@ -36,6 +36,7 @@ #include ctype.h #include err.h #include errno.h +#include histedit.h #include limits.h #include search.h #include signal.h @@ -1073,6 +1074,13 @@ sigchld(int signo) } } +static const char * +dummy_prompt(void) +{ + +return (); +} + int main(int argc, char *argv[]) { @@ -1129,6 +1137,16 @@ main(int argc, char *argv[]) dup(p[1]); close(p[0]); close(p[1]); + if (interactive) { + el = el_init(bc, stdin, stderr, stderr); + hist = history_init(); + history(hist, he, H_SETSIZE, 100); + el_set(el, EL_HIST, history, hist); + el_set(el, EL_EDITOR, emacs); + el_set(el, EL_SIGNAL, 1); + el_set(el, EL_PROMPT, dummy_prompt); + el_source(el, NULL); + } } else { close(STDIN_FILENO); dup(p[0]); Index: extern.h === RCS file: /cvs/src/usr.bin/bc/extern.h,v retrieving revision 1.6 diff -u -p -r1.6 extern.h --- extern.h18 Mar 2006 20:44:43 - 1.6 +++ extern.h5 Feb 2010 09:23:08 - @@ -35,5 +35,10 @@ extern int fileindex; extern int sargc; extern char**sargv; extern char*filename; +extern bool interactive; +extern EditLine*el; +extern History *hist; +extern HistEventhe; extern char*cmdexpr; + bool interactive; Index: scan.l === RCS file: /cvs/src/usr.bin/bc/scan.l,v retrieving revision 1.23 diff -u -p -r1.23 scan.l --- scan.l 27 Oct 2009 23:59:36 - 1.23 +++ scan.l 5 Feb 2010 19:10:39 - @@ -18,6 +18,7 @@ */ #include err.h +#include histedit.h #include signal.h #include stdbool.h #include string.h @@ -30,6 +31,10 @@ intlineno; bool interactive; +HistEvent he; +EditLine *el; +History*hist; + static char*strbuf = NULL; static size_t strbuf_sz = 1; static booldot_seen; @@ -37,6 +42,12 @@ static bool dot_seen; static voidinit_strbuf(void); static voidadd_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 @@ -279,4 +290,33 @@ yywrap(void) } return (1); } + +static int +bc_yyinput(char *buf, int maxlen) +{ + int num; + if (yyin == stdin interactive) { + const char *bp; + + if ((bp = el_gets(el, num)) == NULL || num == 0) + return (0); + if (num maxlen) { + el_push(el, (char *)(void *)bp + maxlen); + num = maxlen; + } + memcpy(buf, bp, num); + history(hist, he, H_ENTER, bp); + } else { + int c = '*'; + for (num = 0; num maxlen + (c
Re: History for bc(1)
On Wed, Mar 02, 2011 at 10:13:35AM +0100, Otto Moerbeek wrote: Lets try to make some progress here. This is the diff I have had in my tree for a while. It is a port of the freebsd code. What is lacking is the man page stuff. So if sombody could merge that from freebsd, I'd be happy. if you can mail me (privately) the page, and indicate what parts are relevant, i can do that. jmc
Re: History for bc(1)
On Wed, Mar 02, 2011 at 10:18:08AM +, Jason McIntyre wrote: On Wed, Mar 02, 2011 at 10:13:35AM +0100, Otto Moerbeek wrote: Lets try to make some progress here. This is the diff I have had in my tree for a while. It is a port of the freebsd code. What is lacking is the man page stuff. So if sombody could merge that from freebsd, I'd be happy. if you can mail me (privately) the page, and indicate what parts are relevant, i can do that. jmc Hmm, glanced at the freebsd page, but they do not mention anything with respect to editline, I wrongly supposed to would have included that. I think we could nick the relevant lines from e.g. ftp(1). -Otto
Re: History for bc(1)
On 02/15/11 13:01, Otto Moerbeek wrote: sorry, in have a diff in my tree, but I see myself always ignoring it. I just almost never actually use the editing capabilities. It seems my 25yr finger memory is too strong. So I'm not a proper tester for this diff, other than it does not seem to cause a regression. I use it almost daily, and some people have shown their interest for this feature.
Re: History for bc(1)
On 02/14/11 17:43, Christiano F. Haesbaert wrote: Any news on this ? The diff still apply on -current. If there are changes needed I can work on it, but I have no news.
Re: History for bc(1)
On Tue, Feb 15, 2011 at 12:23:41PM +0100, Gabriel Linder wrote: On 02/14/11 17:43, Christiano F. Haesbaert wrote: Any news on this ? The diff still apply on -current. If there are changes needed I can work on it, but I have no news. sorry, in have a diff in my tree, but I see myself always ignoring it. I just almost never actually use the editing capabilities. It seems my 25yr finger memory is too strong. So I'm not a proper tester for this diff, other than it does not seem to cause a regression. -Otto
Re: History for bc(1)
Any news on this ?
Re: History for bc(1)
On 20 August 2010 03:48, Matthieu Herrb matthieu.he...@laas.fr wrote: On Fri, Aug 13, 2010 at 02:30:50PM +0200, Otto Moerbeek wrote: On Fri, Aug 13, 2010 at 01:26:37PM +0200, Gabriel Linder wrote: This diff implements history for bc(1) using editline(3). History is not persistent, I can add this feature if needed. el_init with stderr should not be a problem for an interactive program, let me know otherwise. This is my first diff, so hints/advices/crucifixion are welcome :) Take a look at freebsd. They have added editline support to bc. If (big if) we're going to add command line editing and history, I'd rather take that. I would like to see command line editing and history in bc(1) too. +1
History for bc(1)
This diff implements history for bc(1) using editline(3). History is not persistent, I can add this feature if needed. el_init with stderr should not be a problem for an interactive program, let me know otherwise. This is my first diff, so hints/advices/crucifixion are welcome :) Index: Makefile === RCS file: /cvs/src/usr.bin/bc/Makefile,v retrieving revision 1.4 diff -u -r1.4 Makefile --- Makefile30 Jun 2006 19:02:28 - 1.4 +++ Makefile13 Aug 2010 11:23:19 - @@ -5,6 +5,8 @@ CPPFLAGS+= -I. -I${.CURDIR} CFLAGS+= -Wall -Wno-unused YFLAGS+= +LDADD= -lcurses -ledit +DPADD= ${LIBCURSES} ${LIBEDIT} beforeinstall: install -c -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/bc.library \ Index: bc.y === RCS file: /cvs/src/usr.bin/bc/bc.y,v retrieving revision 1.33 diff -u -r1.33 bc.y --- bc.y27 Oct 2009 23:59:36 - 1.33 +++ bc.y13 Aug 2010 11:23:19 - @@ -43,6 +43,7 @@ #include stdbool.h #include string.h #include unistd.h +#include histedit.h #include extern.h #include pathnames.h @@ -1073,6 +1074,27 @@ } } +static void +init_editline(void) +{ + if (interactive) { + /* +* Our stdout will be stdin for dc, so we pass stderr as stdout. +*/ + if ((el = el_init(__progname, stdin, stderr, stderr)) == NULL) + err(1, cannot initialise editline); + if ((hl = history_init()) == NULL) + err(1, cannot initialise editline history); + history(hl, hev, H_SETSIZE, 100); + el_set(el, EL_HIST, history, hl); + el_set(el, EL_PROMPT, prompt); + el_set(el, EL_EDITOR, emacs); + el_set(el, EL_TERMINAL, NULL); + el_set(el, EL_SIGNAL, 1); + el_source(el, NULL); + } +} + int main(int argc, char *argv[]) { @@ -1129,6 +1151,7 @@ dup(p[1]); close(p[0]); close(p[1]); + init_editline(); } else { close(STDIN_FILENO); dup(p[0]); Index: extern.h === RCS file: /cvs/src/usr.bin/bc/extern.h,v retrieving revision 1.6 diff -u -r1.6 extern.h --- extern.h18 Mar 2006 20:44:43 - 1.6 +++ extern.h13 Aug 2010 11:23:19 - @@ -23,17 +23,23 @@ ssize_t store; }; -intyylex(void); -void yyerror(char *); -void fatal(const char *); -void abort_line(int); +intyylex(void); +void yyerror(char *); +void fatal(const char *); +void abort_line(int); -extern int lineno; -extern char*yytext; -extern FILE*yyin; -extern int fileindex; -extern int sargc; -extern char**sargv; -extern char*filename; -extern char*cmdexpr; -bool interactive; +extern int lineno; +extern char*yytext; +extern FILE*yyin; +extern int fileindex; +extern int sargc; +extern char**sargv; +extern char*filename; +extern char*cmdexpr; +extern boolinteractive; + +const char *prompt(EditLine *); + +extern History *hl; +extern HistEvent hev; +extern EditLine*el; Index: scan.l === RCS file: /cvs/src/usr.bin/bc/scan.l,v retrieving revision 1.23 diff -u -r1.23 scan.l --- scan.l 27 Oct 2009 23:59:36 - 1.23 +++ scan.l 13 Aug 2010 11:23:19 - @@ -22,6 +22,7 @@ #include stdbool.h #include string.h #include unistd.h +#include histedit.h #include extern.h #include pathnames.h @@ -30,6 +31,10 @@ intlineno; bool interactive; +History*hl; +HistEvent hev; +EditLine *el; + static char*strbuf = NULL; static size_t strbuf_sz = 1; static booldot_seen; @@ -37,6 +42,10 @@ static voidinit_strbuf(void); static voidadd_str(const char *); +static voidyy_input(char *, int *, const int); + +#define YY_INPUT(buf, result, max_size)(yy_input(buf, result, max_size)) + %} %option always-interactive @@ -280,3 +289,38 @@ return (1); } +/* ARGSUSED */ +const char * +prompt(EditLine *el) +{ + return ; +} + +static void +yy_input(char *buf, int *result, const int max_size) +{ + if (interactive) { + const char *line; + int count; + if ((line = el_gets(el, count)) == NULL || count = 0) { + if (count == 0) { + *result = YY_NULL
Re: History for bc(1)
On Fri, Aug 13, 2010 at 01:26:37PM +0200, Gabriel Linder wrote: This diff implements history for bc(1) using editline(3). History is not persistent, I can add this feature if needed. el_init with stderr should not be a problem for an interactive program, let me know otherwise. This is my first diff, so hints/advices/crucifixion are welcome :) Take a look at freebsd. They have added editline support to bc. If (big if) we're going to add command line editing and history, I'd rather take that. -Otto Index: Makefile === RCS file: /cvs/src/usr.bin/bc/Makefile,v retrieving revision 1.4 diff -u -r1.4 Makefile --- Makefile 30 Jun 2006 19:02:28 - 1.4 +++ Makefile 13 Aug 2010 11:23:19 - @@ -5,6 +5,8 @@ CPPFLAGS+= -I. -I${.CURDIR} CFLAGS+= -Wall -Wno-unused YFLAGS+= +LDADD= -lcurses -ledit +DPADD= ${LIBCURSES} ${LIBEDIT} beforeinstall: install -c -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/bc.library \ Index: bc.y === RCS file: /cvs/src/usr.bin/bc/bc.y,v retrieving revision 1.33 diff -u -r1.33 bc.y --- bc.y 27 Oct 2009 23:59:36 - 1.33 +++ bc.y 13 Aug 2010 11:23:19 - @@ -43,6 +43,7 @@ #include stdbool.h #include string.h #include unistd.h +#include histedit.h #include extern.h #include pathnames.h @@ -1073,6 +1074,27 @@ } } +static void +init_editline(void) +{ + if (interactive) { + /* + * Our stdout will be stdin for dc, so we pass stderr as stdout. + */ + if ((el = el_init(__progname, stdin, stderr, stderr)) == NULL) + err(1, cannot initialise editline); + if ((hl = history_init()) == NULL) + err(1, cannot initialise editline history); + history(hl, hev, H_SETSIZE, 100); + el_set(el, EL_HIST, history, hl); + el_set(el, EL_PROMPT, prompt); + el_set(el, EL_EDITOR, emacs); + el_set(el, EL_TERMINAL, NULL); + el_set(el, EL_SIGNAL, 1); + el_source(el, NULL); + } +} + int main(int argc, char *argv[]) { @@ -1129,6 +1151,7 @@ dup(p[1]); close(p[0]); close(p[1]); + init_editline(); } else { close(STDIN_FILENO); dup(p[0]); Index: extern.h === RCS file: /cvs/src/usr.bin/bc/extern.h,v retrieving revision 1.6 diff -u -r1.6 extern.h --- extern.h 18 Mar 2006 20:44:43 - 1.6 +++ extern.h 13 Aug 2010 11:23:19 - @@ -23,17 +23,23 @@ ssize_t store; }; -int yylex(void); -void yyerror(char *); -void fatal(const char *); -void abort_line(int); +int yylex(void); +void yyerror(char *); +void fatal(const char *); +void abort_line(int); -extern int lineno; -extern char *yytext; -extern FILE *yyin; -extern int fileindex; -extern int sargc; -extern char **sargv; -extern char *filename; -extern char *cmdexpr; -bool interactive; +extern int lineno; +extern char *yytext; +extern FILE *yyin; +extern int fileindex; +extern int sargc; +extern char **sargv; +extern char *filename; +extern char *cmdexpr; +extern bool interactive; + +const char *prompt(EditLine *); + +extern History *hl; +extern HistEvent hev; +extern EditLine *el; Index: scan.l === RCS file: /cvs/src/usr.bin/bc/scan.l,v retrieving revision 1.23 diff -u -r1.23 scan.l --- scan.l27 Oct 2009 23:59:36 - 1.23 +++ scan.l13 Aug 2010 11:23:19 - @@ -22,6 +22,7 @@ #include stdbool.h #include string.h #include unistd.h +#include histedit.h #include extern.h #include pathnames.h @@ -30,6 +31,10 @@ int lineno; bool interactive; +History *hl; +HistEventhev; +EditLine *el; + static char *strbuf = NULL; static size_tstrbuf_sz = 1; static bool dot_seen; @@ -37,6 +42,10 @@ static void init_strbuf(void); static void add_str(const char *); +static void yy_input(char *, int *, const int); + +#define YY_INPUT(buf, result, max_size) (yy_input(buf, result, max_size)) + %} %option always-interactive @@ -280,3 +289,38 @@ return (1); } +/* ARGSUSED */ +const char * +prompt(EditLine *el) +{ + return ; +} + +static void +yy_input(char *buf, int *result, const int
Re: History for bc(1)
On Fri, 13 Aug 2010 14:30:50 +0200 Otto Moerbeek o...@drijf.net wrote: Take a look at freebsd. They have added editline support to bc. If (big if) we're going to add command line editing and history, I'd rather take that. I will take a look at their implementation then, thank you.