--- /usr/src/usr.bin/tftp/main.c 2003-10-11 20:27:55.000000000 -0400 +++ main.c 2008-03-08 00:33:18.000000000 -0500 @@ -106,7 +106,7 @@ void setverbose(int, char **); void status(int, char **); -static void command(void) __dead2; +static void command(int, EditLine *, History *, HistEvent *); static const char *command_prompt(void); static void getusage(char *); @@ -161,17 +161,42 @@ int argc; char *argv[]; { + int vrbose; + EditLine *el; + History *hist; + HistEvent he; + f = -1; strcpy(mode, "netascii"); signal(SIGINT, intr); + + vrbose = isatty(0); + el = 0; + hist = 0; + + if (vrbose) { + 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); + } + if (argc > 1) { if (setjmp(toplevel) != 0) exit(txrx_error); setpeer(argc, argv); } - if (setjmp(toplevel) != 0) + if (setjmp(toplevel) != 0) { + if (vrbose) { + el_reset(el); + } (void)putchar('\n'); - command(); + } + command(vrbose, el, hist, &he); } char hostname[MAXHOSTNAMELEN]; @@ -621,35 +646,21 @@ * Command parser. */ static void -command() +command(int vrbose, EditLine *el, History *hist, HistEvent *hep) { - HistEvent he; struct cmd *c; - static EditLine *el; - static History *hist; const char *bp; char *cp; - int len, num, vrbose; + int len, num; - vrbose = isatty(0); - if (vrbose) { - 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 (;;) { if (vrbose) { - 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); + 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, hep, H_ENTER, bp); } else { if (fgets(line, sizeof line , stdin) == 0) { if (feof(stdin)) {