diff options
author | hpa <hpa> | 2001-11-12 23:27:48 +0000 |
---|---|---|
committer | hpa <hpa> | 2001-11-12 23:27:48 +0000 |
commit | 9753e234c6f923b9082da29506e24722831fc9c5 (patch) | |
tree | 1520c6b58ed9c50cda6594bc562871f2d2f7e68a /tftp | |
parent | 9570005ba20ae2d4c068cc01b97256b01d5107eb (diff) | |
download | tftp-hpa-9753e234c6f923b9082da29506e24722831fc9c5.tar.gz |
Add readline support in tftp client; some additional minor cleanups.
Diffstat (limited to 'tftp')
-rw-r--r-- | tftp/main.c | 32 | ||||
-rw-r--r-- | tftp/tftp.c | 11 | ||||
-rw-r--r-- | tftp/tftpsubs.c | 2 |
3 files changed, 26 insertions, 19 deletions
diff --git a/tftp/main.c b/tftp/main.c index a5fcef8..9b3ad39 100644 --- a/tftp/main.c +++ b/tftp/main.c @@ -69,12 +69,12 @@ static const char *rcsid UNUSED = #include <string.h> #include <unistd.h> #include <fcntl.h> +#ifdef WITH_READLINE +#include <readline/readline.h> +#include <readline/history.h> +#endif #include "extern.h" -#include "../config.h" -#ifdef HAVE_STRINGS_H -#include <strings.h> -#endif #define TIMEOUT 5 /* secs between rexmt's */ #define LBUFLEN 200 /* size of input buffer */ @@ -86,10 +86,14 @@ int trace; int verbose; int connected; char mode[32]; +#ifdef WITH_READLINE +char *line = NULL; +#else char line[LBUFLEN]; +#endif int margc; char *margv[20]; -const char *prompt = "tftp"; +const char *prompt = "tftp> "; sigjmp_buf toplevel; void intr(int); struct servent *sp; @@ -205,6 +209,10 @@ main(int argc, char *argv[]) if (sigsetjmp(toplevel,1) != 0) (void)putchar('\n'); +#ifdef WITH_READLINE + using_history(); +#endif + command(); return 0; /* Never reached */ @@ -600,7 +608,14 @@ command(void) struct cmd *c; for (;;) { - printf("%s> ", prompt); +#ifdef WITH_READLINE + if ( line ) + free(line); + line = readline(prompt); + if ( !line ) + exit(0); /* EOF */ +#else + fputs(prompt, stdout); if (fgets(line, LBUFLEN, stdin) == 0) { if (feof(stdin)) { exit(0); @@ -608,11 +623,16 @@ command(void) continue; } } +#endif if ((line[0] == 0) || (line[0] == '\n')) continue; +#ifdef WITH_READLINE + add_history(line); +#endif makeargv(); if (margc == 0) continue; + c = getcmd(margv[0]); if (c == (struct cmd *)-1) { printf("?Ambiguous command\n"); diff --git a/tftp/tftp.c b/tftp/tftp.c index eb1a8a5..89297d2 100644 --- a/tftp/tftp.c +++ b/tftp/tftp.c @@ -65,19 +65,8 @@ static const char *rcsid UNUSED = #include <string.h> #include <unistd.h> -#include "../config.h" #include "extern.h" -#ifdef HAVE_STRINGS_H -#include <strings.h> -#endif - -#ifndef HAVE_SIGSETJMP -#define sigsetjmp(x,y) setjmp(x) -#define siglongjmp(x,y) longjmp(x,y) -#define sigjmp_buf jmp_buf -#endif - extern struct sockaddr_in peeraddr; /* filled in by main */ extern int f; /* the opened socket */ extern int trace; diff --git a/tftp/tftpsubs.c b/tftp/tftpsubs.c index 8b739cf..c358ccd 100644 --- a/tftp/tftpsubs.c +++ b/tftp/tftpsubs.c @@ -66,8 +66,6 @@ static const char *rcsid UNUSED = #include <string.h> #include <unistd.h> -#include "../config.h" - #define PKTSIZE MAX_SEGSIZE+4 /* should be moved to tftp.h */ int segsize = SEGSIZE; /* Default segsize */ |