mirror of
https://kernel.googlesource.com/pub/scm/network/tftp/tftp-hpa
synced 2025-05-12 01:35:51 +03:00
Add readline support in tftp client; some additional minor cleanups.
This commit is contained in:
parent
9570005ba2
commit
9753e234c6
5 changed files with 46 additions and 19 deletions
2
README
2
README
|
@ -40,6 +40,8 @@ Changes in 0.22:
|
||||||
|
|
||||||
Some source cleanups; change to autoconf 2.52.
|
Some source cleanups; change to autoconf 2.52.
|
||||||
|
|
||||||
|
Add support for readline command-line editing in tftp.
|
||||||
|
|
||||||
|
|
||||||
Changes in 0.21:
|
Changes in 0.21:
|
||||||
Support running in standalone mode, without inetd.
|
Support running in standalone mode, without inetd.
|
||||||
|
|
18
configure.in
18
configure.in
|
@ -101,6 +101,24 @@ PA_WITH_BOOL(remap, 1,
|
||||||
])
|
])
|
||||||
],:)
|
],:)
|
||||||
|
|
||||||
|
AH_TEMPLATE([WITH_READLINE],
|
||||||
|
[Define if we are compiling with readline command-line editing.])
|
||||||
|
|
||||||
|
PA_WITH_BOOL(readline, 1,
|
||||||
|
[ --without-readline Disable the use of readline command-line editing],
|
||||||
|
[
|
||||||
|
USE_READLINE=true
|
||||||
|
AC_CHECK_HEADER(readline/readline.h, [], [USE_READLINE=false])
|
||||||
|
AC_CHECK_HEADER(readline/history.h, [], [USE_READLINE=false])
|
||||||
|
if $USE_READLINE
|
||||||
|
then
|
||||||
|
AC_SEARCH_LIBS(readline, [readline history],
|
||||||
|
[
|
||||||
|
AC_DEFINE(WITH_READLINE)
|
||||||
|
])
|
||||||
|
fi
|
||||||
|
],:)
|
||||||
|
|
||||||
AH_TEMPLATE([HAVE_SIGSETJMP],
|
AH_TEMPLATE([HAVE_SIGSETJMP],
|
||||||
[Define if we have sigsetjmp, siglongjmp and sigjmp_buf.])
|
[Define if we have sigsetjmp, siglongjmp and sigjmp_buf.])
|
||||||
PA_SIGSETJMP([AC_DEFINE(HAVE_SIGSETJMP)])
|
PA_SIGSETJMP([AC_DEFINE(HAVE_SIGSETJMP)])
|
||||||
|
|
32
tftp/main.c
32
tftp/main.c
|
@ -69,12 +69,12 @@ static const char *rcsid UNUSED =
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#ifdef WITH_READLINE
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#include <readline/history.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "extern.h"
|
#include "extern.h"
|
||||||
#include "../config.h"
|
|
||||||
#ifdef HAVE_STRINGS_H
|
|
||||||
#include <strings.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TIMEOUT 5 /* secs between rexmt's */
|
#define TIMEOUT 5 /* secs between rexmt's */
|
||||||
#define LBUFLEN 200 /* size of input buffer */
|
#define LBUFLEN 200 /* size of input buffer */
|
||||||
|
@ -86,10 +86,14 @@ int trace;
|
||||||
int verbose;
|
int verbose;
|
||||||
int connected;
|
int connected;
|
||||||
char mode[32];
|
char mode[32];
|
||||||
|
#ifdef WITH_READLINE
|
||||||
|
char *line = NULL;
|
||||||
|
#else
|
||||||
char line[LBUFLEN];
|
char line[LBUFLEN];
|
||||||
|
#endif
|
||||||
int margc;
|
int margc;
|
||||||
char *margv[20];
|
char *margv[20];
|
||||||
const char *prompt = "tftp";
|
const char *prompt = "tftp> ";
|
||||||
sigjmp_buf toplevel;
|
sigjmp_buf toplevel;
|
||||||
void intr(int);
|
void intr(int);
|
||||||
struct servent *sp;
|
struct servent *sp;
|
||||||
|
@ -205,6 +209,10 @@ main(int argc, char *argv[])
|
||||||
if (sigsetjmp(toplevel,1) != 0)
|
if (sigsetjmp(toplevel,1) != 0)
|
||||||
(void)putchar('\n');
|
(void)putchar('\n');
|
||||||
|
|
||||||
|
#ifdef WITH_READLINE
|
||||||
|
using_history();
|
||||||
|
#endif
|
||||||
|
|
||||||
command();
|
command();
|
||||||
|
|
||||||
return 0; /* Never reached */
|
return 0; /* Never reached */
|
||||||
|
@ -600,7 +608,14 @@ command(void)
|
||||||
struct cmd *c;
|
struct cmd *c;
|
||||||
|
|
||||||
for (;;) {
|
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 (fgets(line, LBUFLEN, stdin) == 0) {
|
||||||
if (feof(stdin)) {
|
if (feof(stdin)) {
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -608,11 +623,16 @@ command(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if ((line[0] == 0) || (line[0] == '\n'))
|
if ((line[0] == 0) || (line[0] == '\n'))
|
||||||
continue;
|
continue;
|
||||||
|
#ifdef WITH_READLINE
|
||||||
|
add_history(line);
|
||||||
|
#endif
|
||||||
makeargv();
|
makeargv();
|
||||||
if (margc == 0)
|
if (margc == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
c = getcmd(margv[0]);
|
c = getcmd(margv[0]);
|
||||||
if (c == (struct cmd *)-1) {
|
if (c == (struct cmd *)-1) {
|
||||||
printf("?Ambiguous command\n");
|
printf("?Ambiguous command\n");
|
||||||
|
|
11
tftp/tftp.c
11
tftp/tftp.c
|
@ -65,19 +65,8 @@ static const char *rcsid UNUSED =
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "../config.h"
|
|
||||||
#include "extern.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 struct sockaddr_in peeraddr; /* filled in by main */
|
||||||
extern int f; /* the opened socket */
|
extern int f; /* the opened socket */
|
||||||
extern int trace;
|
extern int trace;
|
||||||
|
|
|
@ -66,8 +66,6 @@ static const char *rcsid UNUSED =
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "../config.h"
|
|
||||||
|
|
||||||
#define PKTSIZE MAX_SEGSIZE+4 /* should be moved to tftp.h */
|
#define PKTSIZE MAX_SEGSIZE+4 /* should be moved to tftp.h */
|
||||||
|
|
||||||
int segsize = SEGSIZE; /* Default segsize */
|
int segsize = SEGSIZE; /* Default segsize */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue