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/xntpd/xntpdc | |
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/xntpd/xntpdc')
-rw-r--r-- | usr.sbin/xntpd/xntpdc/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/xntpd/xntpdc/ntpdc.c | 36 |
2 files changed, 33 insertions, 9 deletions
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); } |