Add libedit support to tftp.
This commit is contained in:
parent
3a691e0043
commit
7fc1eccefc
@ -1,6 +1,8 @@
|
|||||||
|
# $FreeBSD$
|
||||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||||
|
|
||||||
PROG= tftp
|
PROG= tftp
|
||||||
SRCS= main.c tftp.c tftpsubs.c
|
SRCS= main.c tftp.c tftpsubs.c
|
||||||
|
LDADD= -ledit -ltermcap
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
@ -70,10 +70,14 @@ static const char rcsid[] =
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <histedit.h>
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
|
|
||||||
#define TIMEOUT 5 /* secs between rexmt's */
|
#define TIMEOUT 5 /* secs between rexmt's */
|
||||||
|
|
||||||
|
#define MAXLINE 200
|
||||||
|
|
||||||
struct sockaddr_in peeraddr;
|
struct sockaddr_in peeraddr;
|
||||||
int f;
|
int f;
|
||||||
short port;
|
short port;
|
||||||
@ -81,10 +85,9 @@ int trace;
|
|||||||
int verbose;
|
int verbose;
|
||||||
int connected;
|
int connected;
|
||||||
char mode[32];
|
char mode[32];
|
||||||
char line[200];
|
char line[MAXLINE];
|
||||||
int margc;
|
int margc;
|
||||||
char *margv[20];
|
char *margv[20];
|
||||||
char *prompt = "tftp";
|
|
||||||
jmp_buf toplevel;
|
jmp_buf toplevel;
|
||||||
void intr();
|
void intr();
|
||||||
struct servent *sp;
|
struct servent *sp;
|
||||||
@ -589,6 +592,11 @@ tail(filename)
|
|||||||
return (filename);
|
return (filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
command_prompt() {
|
||||||
|
return ("tftp> ");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Command parser.
|
* Command parser.
|
||||||
*/
|
*/
|
||||||
@ -597,14 +605,42 @@ command()
|
|||||||
{
|
{
|
||||||
register struct cmd *c;
|
register struct cmd *c;
|
||||||
char *cp;
|
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 (;;) {
|
for (;;) {
|
||||||
printf("%s> ", prompt);
|
if (verbose) {
|
||||||
if (fgets(line, sizeof line , stdin) == 0) {
|
if ((bp = el_gets(el, &num)) == NULL || num == 0)
|
||||||
if (feof(stdin)) {
|
exit(0);
|
||||||
exit(0);
|
|
||||||
} else {
|
len = (num > MAXLINE) ? MAXLINE : num;
|
||||||
continue;
|
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')))
|
if ((cp = strchr(line, '\n')))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user