svn_rev_381
change readline prototype to be independent of global console_buffer
This commit is contained in:
parent
af347d05ab
commit
abbe1817c3
|
@ -1,5 +1,7 @@
|
|||
#include <common.h>
|
||||
#include <readkey.h>
|
||||
#include <init.h>
|
||||
#include <xfuncs.h>
|
||||
|
||||
extern char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */
|
||||
|
||||
|
@ -36,7 +38,7 @@ char hist_lines[HIST_MAX][HIST_SIZE];
|
|||
|
||||
#define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
|
||||
|
||||
static void hist_init(void)
|
||||
static int hist_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -49,8 +51,11 @@ static void hist_init(void)
|
|||
hist_list[i] = hist_lines[i];
|
||||
hist_list[i][0] = '\0';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
core_initcall(hist_init);
|
||||
|
||||
static void cread_add_to_hist(char *line)
|
||||
{
|
||||
strcpy(hist_list[hist_add_idx], line);
|
||||
|
@ -167,7 +172,7 @@ static void cread_add_char(char ichar, int insert, unsigned long *num,
|
|||
}
|
||||
}
|
||||
|
||||
static int cread_line(char *buf, unsigned int *len)
|
||||
int readline(const char *prompt, char *buf, int len)
|
||||
{
|
||||
unsigned long num = 0;
|
||||
unsigned long eol_num = 0;
|
||||
|
@ -177,6 +182,8 @@ static int cread_line(char *buf, unsigned int *len)
|
|||
int insert = 1;
|
||||
int rc = 0;
|
||||
|
||||
puts (prompt);
|
||||
|
||||
while (1) {
|
||||
rlen = 1;
|
||||
ichar = read_key();
|
||||
|
@ -279,42 +286,17 @@ static int cread_line(char *buf, unsigned int *len)
|
|||
continue;
|
||||
}
|
||||
default:
|
||||
cread_add_char(ichar, insert, &num, &eol_num, buf, *len);
|
||||
cread_add_char(ichar, insert, &num, &eol_num, buf, len);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*len = eol_num;
|
||||
len = eol_num;
|
||||
buf[eol_num] = '\0'; /* lose the newline */
|
||||
|
||||
if (buf[0] && buf[0] != CREAD_HIST_CHAR)
|
||||
cread_add_to_hist(buf);
|
||||
hist_cur = hist_add_idx;
|
||||
|
||||
return (rc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Prompt for input and read a line.
|
||||
* If CONFIG_BOOT_RETRY_TIME is defined and retry_time >= 0,
|
||||
* time out when time goes past endtime (timebase time in ticks).
|
||||
* Return: number of read characters
|
||||
* -1 if break
|
||||
* -2 if timed out
|
||||
*/
|
||||
int readline (const char *const prompt)
|
||||
{
|
||||
char *p = console_buffer;
|
||||
unsigned int len=MAX_CMDBUF_SIZE;
|
||||
int rc;
|
||||
static int initted = 0;
|
||||
|
||||
if (!initted) {
|
||||
hist_init();
|
||||
initted = 1;
|
||||
}
|
||||
|
||||
puts (prompt);
|
||||
|
||||
rc = cread_line(p, &len);
|
||||
return rc < 0 ? rc : len;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#include <common.h>
|
||||
#include <watchdog.h>
|
||||
|
||||
extern char console_buffer[CONFIG_CBSIZE]; /* console I/O buffer */
|
||||
|
||||
static char erase_seq[] = "\b \b"; /* erase sequence */
|
||||
static char tab_seq[] = " "; /* used to expand TABs */
|
||||
|
||||
|
@ -44,9 +42,9 @@ static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen)
|
|||
* -1 if break
|
||||
* -2 if timed out
|
||||
*/
|
||||
int readline (const char *const prompt)
|
||||
int readline (const char *prompt, char *line, int len)
|
||||
{
|
||||
char *p = console_buffer;
|
||||
char *p = line;
|
||||
int n = 0; /* buffer index */
|
||||
int plen = 0; /* prompt length */
|
||||
int col; /* output column cnt */
|
||||
|
@ -84,13 +82,13 @@ int readline (const char *const prompt)
|
|||
case '\n':
|
||||
*p = '\0';
|
||||
puts ("\r\n");
|
||||
return (p - console_buffer);
|
||||
return (p - line);
|
||||
|
||||
case '\0': /* nul */
|
||||
continue;
|
||||
|
||||
case 0x03: /* ^C - break */
|
||||
console_buffer[0] = '\0'; /* discard input */
|
||||
line[0] = '\0'; /* discard input */
|
||||
return (-1);
|
||||
|
||||
case 0x15: /* ^U - erase line */
|
||||
|
@ -98,20 +96,20 @@ int readline (const char *const prompt)
|
|||
puts (erase_seq);
|
||||
--col;
|
||||
}
|
||||
p = console_buffer;
|
||||
p = line;
|
||||
n = 0;
|
||||
continue;
|
||||
|
||||
case 0x17: /* ^W - erase word */
|
||||
p=delete_char(console_buffer, p, &col, &n, plen);
|
||||
p=delete_char(line, p, &col, &n, plen);
|
||||
while ((n > 0) && (*p != ' ')) {
|
||||
p=delete_char(console_buffer, p, &col, &n, plen);
|
||||
p=delete_char(line, p, &col, &n, plen);
|
||||
}
|
||||
continue;
|
||||
|
||||
case 0x08: /* ^H - backspace */
|
||||
case 0x7F: /* DEL - backspace */
|
||||
p=delete_char(console_buffer, p, &col, &n, plen);
|
||||
p=delete_char(line, p, &col, &n, plen);
|
||||
continue;
|
||||
|
||||
default:
|
||||
|
@ -123,8 +121,8 @@ int readline (const char *const prompt)
|
|||
#ifdef CONFIG_AUTO_COMPLETE
|
||||
/* if auto completion triggered just continue */
|
||||
*p = '\0';
|
||||
if (cmd_auto_complete(prompt, console_buffer, &n, &col)) {
|
||||
p = console_buffer + n; /* reset */
|
||||
if (cmd_auto_complete(prompt, line, &n, &col)) {
|
||||
p = line + n; /* reset */
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -101,7 +101,7 @@ void print_size (ulong, const char *);
|
|||
/* common/main.c */
|
||||
void main_loop (void);
|
||||
int run_command (const char *cmd, int flag);
|
||||
int readline (const char *const prompt);
|
||||
int readline (const char *prompt, char *buf, int len);
|
||||
void init_cmd_timeout(void);
|
||||
void reset_cmd_timeout(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue