diff options
author | mdodd <mdodd@FreeBSD.org> | 1999-08-19 03:29:15 +0000 |
---|---|---|
committer | mdodd <mdodd@FreeBSD.org> | 1999-08-19 03:29:15 +0000 |
commit | fb1440bad5cc00c25587f3b0fd43054fcd16e25e (patch) | |
tree | 3242df8d07f39194c3672c747f71ad962f1ada3e /usr.sbin/cdcontrol | |
parent | 527fa149136dffd80f5b36c338b544f09df1fe10 (diff) | |
download | FreeBSD-src-fb1440bad5cc00c25587f3b0fd43054fcd16e25e.zip FreeBSD-src-fb1440bad5cc00c25587f3b0fd43054fcd16e25e.tar.gz |
Add support for command line editing and history.
Remove src/contrib/bind/bin/nslookup/commands.c as it is generated by lex
from commands.l.
Submitted by: lpc/cdcontrol patches originally by msmith.
Reviewed by: msmith (in theory)
Diffstat (limited to 'usr.sbin/cdcontrol')
-rw-r--r-- | usr.sbin/cdcontrol/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/cdcontrol/cdcontrol.c | 49 |
2 files changed, 43 insertions, 9 deletions
diff --git a/usr.sbin/cdcontrol/Makefile b/usr.sbin/cdcontrol/Makefile index 86a42eb..1c5be4ef 100644 --- a/usr.sbin/cdcontrol/Makefile +++ b/usr.sbin/cdcontrol/Makefile @@ -1,4 +1,7 @@ PROG= cdcontrol CFLAGS+= -Wall +DPADD += ${LIBEDIT} ${LIBTERMCAP} +LDADD += -ledit -ltermcap + .include <bsd.prog.mk> diff --git a/usr.sbin/cdcontrol/cdcontrol.c b/usr.sbin/cdcontrol/cdcontrol.c index 121600d..6f9d786 100644 --- a/usr.sbin/cdcontrol/cdcontrol.c +++ b/usr.sbin/cdcontrol/cdcontrol.c @@ -20,7 +20,7 @@ #ifndef lint static const char rcsid[] = - "$Id: cdcontrol.c,v 1.17 1998/01/26 00:57:54 jmz Exp $"; + "$Id: cdcontrol.c,v 1.18 1999/01/31 15:30:21 billf Exp $"; #endif /* not lint */ #include <ctype.h> @@ -33,6 +33,7 @@ static const char rcsid[] = #include <sys/file.h> #include <sys/cdio.h> #include <sys/ioctl.h> +#include <histedit.h> #define VERSION "2.0" @@ -922,18 +923,48 @@ int status (int *trk, int *min, int *sec, int *frame) return s.data->header.audio_status; } -char *input (int *cmd) +const char * +cdcontrol_prompt() { - static char buf[80]; + return ("cdcontrol> "); +} + +char * +input (int *cmd) +{ +#define MAXLINE 80 + static EditLine *el = NULL; + static History *hist = NULL; + static char buf[MAXLINE]; + int num = 0; + const char *bp = NULL; char *p; do { - if (verbose) - fprintf (stderr, "cdcontrol> "); - if (! fgets (buf, sizeof (buf), stdin)) { - *cmd = CMD_QUIT; - fprintf (stderr, "\r\n"); - return (0); + if (verbose) { + if (!el) { + el = el_init("cdcontrol", stdin, stdout); + hist = history_init(); + history(hist, H_EVENT, 100); + el_set(el, EL_HIST, history, hist); + el_set(el, EL_EDITOR, "emacs"); + el_set(el, EL_PROMPT, cdcontrol_prompt); + el_set(el, EL_SIGNAL, 1); + } + if ((bp = el_gets(el, &num)) == NULL || num == 0) + return (0); + + memcpy(buf, bp, (MAXLINE > num ? MAXLINE : num)); + buf[num] = 0; + history(hist, H_ENTER, bp); +#undef MAXLINE + + } else { + if (! fgets (buf, sizeof (buf), stdin)) { + *cmd = CMD_QUIT; + fprintf (stderr, "\r\n"); + return (0); + } } p = parse (buf, cmd); } while (! p); |