forked from mirrors/tftp-hpa-google
Fix the handling of continuation prompts when using readline
This commit is contained in:
parent
713e1fe868
commit
13849b4a32
1 changed files with 41 additions and 17 deletions
54
tftp/main.c
54
tftp/main.c
|
@ -220,15 +220,47 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
char *hostname;
|
char *hostname;
|
||||||
|
|
||||||
|
/* Called when a command is incomplete; modifies
|
||||||
|
the global variable "line" */
|
||||||
|
static void
|
||||||
|
getmoreargs(const char *partial, const char *mprompt)
|
||||||
|
{
|
||||||
|
#ifdef WITH_READLINE
|
||||||
|
char *eline;
|
||||||
|
int len, elen;
|
||||||
|
|
||||||
|
len = strlen(partial);
|
||||||
|
eline = readline(mprompt);
|
||||||
|
if (!eline)
|
||||||
|
exit(0); /* EOF */
|
||||||
|
|
||||||
|
elen = strlen(eline);
|
||||||
|
|
||||||
|
if (line)
|
||||||
|
free(line);
|
||||||
|
line = xmalloc(len+elen+1);
|
||||||
|
strcpy(line, partial);
|
||||||
|
strcpy(line+len, eline);
|
||||||
|
|
||||||
|
add_history(line);
|
||||||
|
#else
|
||||||
|
int len = strlen(partial);
|
||||||
|
|
||||||
|
strcpy(line, partial);
|
||||||
|
fputs(mprompt, stdout);
|
||||||
|
if ( fgets(line+len, LBUFLEN-len, stdin) == 0 )
|
||||||
|
if ( feof(stdin) )
|
||||||
|
exit(0); /* EOF */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
setpeer(int argc, char *argv[])
|
setpeer(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct hostent *host;
|
struct hostent *host;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
strcpy(line, "Connect ");
|
getmoreargs("connect ", "(to) ");
|
||||||
printf("(to) ");
|
|
||||||
fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
|
|
||||||
makeargv();
|
makeargv();
|
||||||
argc = margc;
|
argc = margc;
|
||||||
argv = margv;
|
argv = margv;
|
||||||
|
@ -344,9 +376,7 @@ put(int argc, char *argv[])
|
||||||
char *cp, *targ;
|
char *cp, *targ;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
strcpy(line, "send ");
|
getmoreargs("send ", "(file) ");
|
||||||
printf("(file) ");
|
|
||||||
fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
|
|
||||||
makeargv();
|
makeargv();
|
||||||
argc = margc;
|
argc = margc;
|
||||||
argv = margv;
|
argv = margv;
|
||||||
|
@ -434,9 +464,7 @@ get(int argc, char *argv[])
|
||||||
char *src;
|
char *src;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
strcpy(line, "get ");
|
getmoreargs("get ", "(files) ");
|
||||||
printf("(files) ");
|
|
||||||
fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
|
|
||||||
makeargv();
|
makeargv();
|
||||||
argc = margc;
|
argc = margc;
|
||||||
argv = margv;
|
argv = margv;
|
||||||
|
@ -515,9 +543,7 @@ setrexmt(int argc, char *argv[])
|
||||||
int t;
|
int t;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
strcpy(line, "Rexmt-timeout ");
|
getmoreargs("rexmt-timeout ", "(value) ");
|
||||||
printf("(value) ");
|
|
||||||
fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
|
|
||||||
makeargv();
|
makeargv();
|
||||||
argc = margc;
|
argc = margc;
|
||||||
argv = margv;
|
argv = margv;
|
||||||
|
@ -541,9 +567,7 @@ settimeout(int argc, char *argv[])
|
||||||
int t;
|
int t;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
strcpy(line, "Maximum-timeout ");
|
getmoreargs("maximum-timeout ", "(value) ");
|
||||||
printf("(value) ");
|
|
||||||
fgets(&line[strlen(line)], LBUFLEN-strlen(line), stdin);
|
|
||||||
makeargv();
|
makeargv();
|
||||||
argc = margc;
|
argc = margc;
|
||||||
argv = margv;
|
argv = margv;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue