summaryrefslogtreecommitdiffstats
path: root/usr.bin/tftp/main.c
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2001-10-19 00:23:07 +0000
committermdodd <mdodd@FreeBSD.org>2001-10-19 00:23:07 +0000
commit7fc1eccefc3093a5858dbca88842ecd5b79d1beb (patch)
tree71d6ca963b710f406532889fbe3ad20fc41a82d9 /usr.bin/tftp/main.c
parent3a691e004307779c313606efc26388cdf09ead3c (diff)
downloadFreeBSD-src-7fc1eccefc3093a5858dbca88842ecd5b79d1beb.zip
FreeBSD-src-7fc1eccefc3093a5858dbca88842ecd5b79d1beb.tar.gz
Add libedit support to tftp.
Diffstat (limited to 'usr.bin/tftp/main.c')
-rw-r--r--usr.bin/tftp/main.c52
1 files changed, 44 insertions, 8 deletions
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')))
OpenPOWER on IntegriCloud