2003-02-27 Theodore A. Roth * term.c: Use fgets() if readline() is not available. Index: term.c =================================================================== RCS file: /cvsroot/avrdude/avrdude/term.c,v retrieving revision 1.29 diff -u -r1.29 term.c --- term.c 14 Feb 2003 20:34:03 -0000 1.29 +++ term.c 27 Feb 2003 17:05:16 -0000 @@ -24,8 +24,11 @@ #include #include #include -#include -#include + +#if defined(HAVE_LIBREADLINE) +# include +# include +#endif #include "avr.h" #include "config.h" @@ -621,21 +624,40 @@ } +char * terminal_get_input(const char *prompt) +{ +#if defined(HAVE_LIBREADLINE) + char *input; + input = readline(prompt); + if ((input != NULL) && (strlen(input) >= 1)) + add_history(input); + + return input; +#else + char input[256]; + printf("%s", prompt); + if (fgets(input, sizeof(input), stdin)) + { + /* FIXME: readline strips the '\n', should this too? */ + strdup(input); + } + else + return NULL; +#endif +} + + int terminal_mode(PROGRAMMER * pgm, struct avrpart * p) { char * cmdbuf; - int i, len; + int i; char * q; int rc; int argc; char ** argv; rc = 0; - while ((cmdbuf = readline("avrdude> ")) != NULL) { - len = strlen(cmdbuf); - if (len >= 1) - add_history(cmdbuf); - + while ((cmdbuf = terminal_get_input("avrdude> ")) != NULL) { /* * find the start of the command, skipping any white space */