* term.c: Use fgets() if readline() is not available.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk@243 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
parent
1013b4d56e
commit
8e79c164cb
|
@ -24,8 +24,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#if defined(HAVE_LIBREADLINE)
|
||||||
# include <readline/readline.h>
|
# include <readline/readline.h>
|
||||||
# include <readline/history.h>
|
# include <readline/history.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "avr.h"
|
#include "avr.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -621,21 +624,40 @@ int do_cmd(PROGRAMMER * pgm, struct avrpart * p, int argc, char * argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
int terminal_mode(PROGRAMMER * pgm, struct avrpart * p)
|
||||||
{
|
{
|
||||||
char * cmdbuf;
|
char * cmdbuf;
|
||||||
int i, len;
|
int i;
|
||||||
char * q;
|
char * q;
|
||||||
int rc;
|
int rc;
|
||||||
int argc;
|
int argc;
|
||||||
char ** argv;
|
char ** argv;
|
||||||
|
|
||||||
rc = 0;
|
rc = 0;
|
||||||
while ((cmdbuf = readline("avrdude> ")) != NULL) {
|
while ((cmdbuf = terminal_get_input("avrdude> ")) != NULL) {
|
||||||
len = strlen(cmdbuf);
|
|
||||||
if (len >= 1)
|
|
||||||
add_history(cmdbuf);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* find the start of the command, skipping any white space
|
* find the start of the command, skipping any white space
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue