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 | |
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')
-rw-r--r-- | usr.sbin/cdcontrol/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/cdcontrol/cdcontrol.c | 49 | ||||
-rw-r--r-- | usr.sbin/lpr/lpc/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/lpr/lpc/lpc.c | 67 | ||||
-rw-r--r-- | usr.sbin/nslookup/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/xntpd/xntpdc/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/xntpd/xntpdc/ntpdc.c | 36 |
7 files changed, 126 insertions, 47 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); diff --git a/usr.sbin/lpr/lpc/Makefile b/usr.sbin/lpr/lpc/Makefile index 46a4166..855b8ed 100644 --- a/usr.sbin/lpr/lpc/Makefile +++ b/usr.sbin/lpr/lpc/Makefile @@ -1,5 +1,5 @@ # From: @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $Id: Makefile,v 1.4 1997/12/16 17:53:19 bde Exp $ +# $Id: Makefile,v 1.5 1998/03/07 09:47:57 bde Exp $ PROG= lpc CFLAGS+=-I${.CURDIR}/../common_source ${CWARNFLAGS} @@ -8,7 +8,7 @@ SRCS= lpc.c cmds.c cmdtab.c BINGRP= daemon BINMODE=2555 .PATH: ${.CURDIR}/../common_source -DPADD= ${LIBLPR} -LDADD= ${LIBLPR} +DPADD= ${LIBLPR} ${LIBEDIT} ${LIBTERMCAP} +LDADD= ${LIBLPR} -ledit -ltermcap .include <bsd.prog.mk> diff --git a/usr.sbin/lpr/lpc/lpc.c b/usr.sbin/lpr/lpc/lpc.c index 7724b36..5684c46 100644 --- a/usr.sbin/lpr/lpc/lpc.c +++ b/usr.sbin/lpr/lpc/lpc.c @@ -43,7 +43,7 @@ static const char copyright[] = static char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95"; #endif static const char rcsid[] = - "$Id: lpc.c,v 1.7 1998/03/22 20:19:27 jb Exp $"; + "$Id: lpc.c,v 1.8 1998/09/11 18:49:31 wollman Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -59,6 +59,7 @@ static const char rcsid[] = #include <syslog.h> #include <string.h> #include <unistd.h> +#include <histedit.h> #include "lp.h" #include "lpc.h" @@ -79,13 +80,10 @@ static int fromatty; static char cmdline[MAX_CMDLINE]; static int margc; static char *margv[MAX_MARGV]; -static int top; uid_t uid, euid; -static jmp_buf toplevel; - int main __P((int, char *[])); -static void cmdscanner __P((int)); +static void cmdscanner __P((void)); static struct cmd *getcmd __P((char *)); static void intr __P((int)); static void makeargv __P((void)); @@ -125,12 +123,10 @@ main(argc, argv) exit(0); } fromatty = isatty(fileno(stdin)); - top = setjmp(toplevel) == 0; - if (top) + if (!fromatty) signal(SIGINT, intr); for (;;) { - cmdscanner(top); - top = 1; + cmdscanner(); } } @@ -138,32 +134,58 @@ static void intr(signo) int signo; { - if (!fromatty) - exit(0); - longjmp(toplevel, 1); + exit(0); +} + +static char * +lpc_prompt() +{ + return("lpc> "); } /* * Command parser. */ static void -cmdscanner(top) - int top; +cmdscanner() { register struct cmd *c; + static EditLine *el = NULL; + static History *hist = NULL; + int num = 0; + const char *bp = NULL; - if (!top) - putchar('\n'); for (;;) { if (fromatty) { - printf("lpc> "); - fflush(stdout); + if (!el) { + el = el_init("lpc", 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, lpc_prompt); + el_set(el, EL_SIGNAL, 1); + } + if ((bp = el_gets(el, &num)) == NULL || num == 0) + return; + + memcpy(cmdline, bp, (MAX_CMDLINE > num ? MAX_CMDLINE : num)); + cmdline[num] = 0; + history(hist, H_ENTER, bp); + + } else { + if (fgets(cmdline, MAX_CMDLINE, stdin) == 0) + quit(0, NULL); + if (cmdline[0] == 0 || cmdline[0] == '\n') + break; } - if (fgets(cmdline, MAX_CMDLINE, stdin) == 0) - quit(0, NULL); - if (cmdline[0] == 0 || cmdline[0] == '\n') - break; + makeargv(); + if (margc == 0) + continue; + if (el_parse(el, margc, margv) != -1) + continue; + c = getcmd(margv[0]); if (c == (struct cmd *)-1) { printf("?Ambiguous command\n"); @@ -182,7 +204,6 @@ cmdscanner(top) else (*c->c_handler)(margc, margv); } - longjmp(toplevel, 0); } static struct cmd * diff --git a/usr.sbin/nslookup/Makefile b/usr.sbin/nslookup/Makefile index 13f7a41..eb30268 100644 --- a/usr.sbin/nslookup/Makefile +++ b/usr.sbin/nslookup/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.6 1998/05/03 05:14:56 peter Exp $ +# $Id: Makefile,v 1.7 1998/05/04 20:00:14 bde Exp $ .include "${.CURDIR}/../named/Makefile.inc" @@ -10,8 +10,8 @@ SRCS= main.c getinfo.c debug.c send.c skip.c list.c subr.c commands.l MAN8= nslookup.8 CFLAGS+=-D_PATH_HELPFILE=\"${DESTHELP}/nslookup.help\" -LDADD+= -ll -DPADD+= ${LIBL} +LDADD+= -ll -ledit -ltermcap +DPADD+= ${LIBL} ${LIBEDIT} ${LIBTERMCAP} beforeinstall: ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 \ diff --git a/usr.sbin/xntpd/xntpdc/Makefile b/usr.sbin/xntpd/xntpdc/Makefile index a3c2ad8..6bfab3d 100644 --- a/usr.sbin/xntpd/xntpdc/Makefile +++ b/usr.sbin/xntpd/xntpdc/Makefile @@ -1,11 +1,11 @@ # -# $Id: Makefile,v 1.8 1998/03/07 09:46:17 bde Exp $ +# $Id: Makefile,v 1.9 1998/03/19 15:12:05 bde Exp $ # CFLAGS+= -I${.CURDIR}/../include -DPADD= ${LIBNTP} -LDADD= ${LIBNTP} +DPADD= ${LIBNTP} ${LIBEDIT} ${LIBTERMCAP} +LDADD= ${LIBNTP} -ledit -ltermcap PROG= xntpdc MAN8= ${.CURDIR}/../doc/xntpdc.8 diff --git a/usr.sbin/xntpd/xntpdc/ntpdc.c b/usr.sbin/xntpd/xntpdc/ntpdc.c index 6af6d1a..84bc15d 100644 --- a/usr.sbin/xntpd/xntpdc/ntpdc.c +++ b/usr.sbin/xntpd/xntpdc/ntpdc.c @@ -8,6 +8,7 @@ #include <sys/types.h> #include <sys/time.h> #include <netdb.h> +#include <histedit.h> #include "ntpdc.h" #include "ntp_select.h" @@ -210,7 +211,7 @@ int debug; /* * main - parse arguments and handle options */ -void +int main(argc, argv) int argc; char *argv[]; @@ -791,6 +792,11 @@ doquery(implcode, reqcode, auth, qitems, qsize, qdata, ritems, rsize, rdata, return res; } +const char * +xntpdc_prompt() +{ + return (prompt); +} /* * getcmds - read commands from the standard input and execute them @@ -798,16 +804,34 @@ doquery(implcode, reqcode, auth, qitems, qsize, qdata, ritems, rsize, rdata, static void getcmds() { + static EditLine *el = NULL; + static History *hist = NULL; char line[MAXLINE]; + int num = 0; + const char *bp = NULL; for (;;) { if (interactive) { - (void) fputs(prompt, stderr); - (void) fflush(stderr); - } + if (!el) { + el = el_init("xntpdc", 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, xntpdc_prompt); + el_set(el, EL_SIGNAL, 1); + } + if ((bp = el_gets(el, &num)) == NULL || num == 0) + return; - if (fgets(line, sizeof line, stdin) == NULL) - return; + memcpy(line, bp, (MAXLINE > num ? MAXLINE : num)); + line[num] = 0; + history(hist, H_ENTER, bp); + + } else { + if (fgets(line, sizeof line, stdin) == NULL) + return; + } docmd(line); } |