diff options
author | mdodd <mdodd@FreeBSD.org> | 2001-10-19 00:23:07 +0000 |
---|---|---|
committer | mdodd <mdodd@FreeBSD.org> | 2001-10-19 00:23:07 +0000 |
commit | 7fc1eccefc3093a5858dbca88842ecd5b79d1beb (patch) | |
tree | 71d6ca963b710f406532889fbe3ad20fc41a82d9 /usr.bin/tftp | |
parent | 3a691e004307779c313606efc26388cdf09ead3c (diff) | |
download | FreeBSD-src-7fc1eccefc3093a5858dbca88842ecd5b79d1beb.zip FreeBSD-src-7fc1eccefc3093a5858dbca88842ecd5b79d1beb.tar.gz |
Add libedit support to tftp.
Diffstat (limited to 'usr.bin/tftp')
-rw-r--r-- | usr.bin/tftp/Makefile | 2 | ||||
-rw-r--r-- | usr.bin/tftp/main.c | 52 |
2 files changed, 46 insertions, 8 deletions
diff --git a/usr.bin/tftp/Makefile b/usr.bin/tftp/Makefile index d91ba61..f8ecb69 100644 --- a/usr.bin/tftp/Makefile +++ b/usr.bin/tftp/Makefile @@ -1,6 +1,8 @@ +# $FreeBSD$ # @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= tftp SRCS= main.c tftp.c tftpsubs.c +LDADD= -ledit -ltermcap .include <bsd.prog.mk> diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index 4ae5dc4..4d7f5f2 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -70,10 +70,14 @@ static const char rcsid[] = #include <string.h> #include <unistd.h> +#include <histedit.h> + #include "extern.h" #define TIMEOUT 5 /* secs between rexmt's */ +#define MAXLINE 200 + struct sockaddr_in peeraddr; int f; short port; @@ -81,10 +85,9 @@ int trace; int verbose; int connected; char mode[32]; -char line[200]; +char line[MAXLINE]; int margc; char *margv[20]; -char *prompt = "tftp"; jmp_buf toplevel; void intr(); struct servent *sp; @@ -589,6 +592,11 @@ tail(filename) return (filename); } +static const char * +command_prompt() { + return ("tftp> "); +} + /* * Command parser. */ @@ -597,14 +605,42 @@ command() { register struct cmd *c; char *cp; + static EditLine *el = NULL; + static History *hist = NULL; + HistEvent he; + const char * bp; + int len, num; + int verbose; + + verbose = isatty(0); + + if (verbose) { + el = el_init("tftp", stdin, stdout, stderr); + hist = history_init(); + history(hist, &he, H_EVENT, 100); + el_set(el, EL_HIST, history, hist); + el_set(el, EL_EDITOR, "emacs"); + el_set(el, EL_PROMPT, command_prompt); + el_set(el, EL_SIGNAL, 1); + el_source(el, NULL); + } for (;;) { - printf("%s> ", prompt); - if (fgets(line, sizeof line , stdin) == 0) { - if (feof(stdin)) { - exit(0); - } else { - continue; + if (verbose) { + if ((bp = el_gets(el, &num)) == NULL || num == 0) + exit(0); + + len = (num > MAXLINE) ? MAXLINE : num; + memcpy(line, bp, len); + line[len] = '\0'; + history(hist, &he, H_ENTER, bp); + } else { + if (fgets(line, sizeof line , stdin) == 0) { + if (feof(stdin)) { + exit(0); + } else { + continue; + } } } if ((cp = strchr(line, '\n'))) |