#include <bootretry.h>
#include <cli.h>
#include <command.h>
+#include <hang.h>
+#include <malloc.h>
#include <time.h>
#include <watchdog.h>
#include <asm/global_data.h>
static unsigned hist_num;
static char *hist_list[HIST_MAX];
-static char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */
#define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
getcmd_putch(ch);
}
-static void hist_init(void)
+static int hist_init(void)
{
+ unsigned char *hist;
int i;
hist_max = 0;
hist_cur = -1;
hist_num = 0;
- for (i = 0; i < HIST_MAX; i++) {
- hist_list[i] = hist_lines[i];
- hist_list[i][0] = '\0';
- }
+ hist = calloc(HIST_MAX, HIST_SIZE + 1);
+ if (!hist)
+ return -ENOMEM;
+
+ for (i = 0; i < HIST_MAX; i++)
+ hist_list[i] = hist + (i * (HIST_SIZE + 1));
+
+ return 0;
}
static void cread_add_to_hist(char *line)
break;
case CTL_CH('p'):
case CTL_CH('n'):
- {
- char *hline;
+ if (cls->history) {
+ char *hline;
- if (ichar == CTL_CH('p'))
- hline = hist_prev();
- else
- hline = hist_next();
+ if (ichar == CTL_CH('p'))
+ hline = hist_prev();
+ else
+ hline = hist_next();
- if (!hline) {
- getcmd_cbeep();
- break;
- }
+ if (!hline) {
+ getcmd_cbeep();
+ break;
+ }
- /* nuke the current line */
- /* first, go home */
- BEGINNING_OF_LINE();
+ /* nuke the current line */
+ /* first, go home */
+ BEGINNING_OF_LINE();
- /* erase to end of line */
- ERASE_TO_EOL();
+ /* erase to end of line */
+ ERASE_TO_EOL();
- /* copy new line into place and display */
- strcpy(buf, hline);
- cls->eol_num = strlen(buf);
- REFRESH_TO_EOL();
+ /* copy new line into place and display */
+ strcpy(buf, hline);
+ cls->eol_num = strlen(buf);
+ REFRESH_TO_EOL();
+ break;
+ }
break;
- }
case '\t':
- if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
+ if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && cls->cmd_complete) {
int num2, col;
/* do not autocomplete when in the middle */
return -EAGAIN;
}
+void cli_cread_init(struct cli_line_state *cls, char *buf, uint buf_size)
+{
+ int init_len = strlen(buf);
+
+ memset(cls, '\0', sizeof(struct cli_line_state));
+ cls->insert = true;
+ cls->buf = buf;
+ cls->len = buf_size;
+
+ if (init_len)
+ cread_add_str(buf, init_len, 0, &cls->num, &cls->eol_num, buf,
+ buf_size);
+}
+
static int cread_line(const char *const prompt, char *buf, unsigned int *len,
int timeout)
{
struct cli_ch_state s_cch, *cch = &s_cch;
struct cli_line_state s_cls, *cls = &s_cls;
char ichar;
- int init_len = strlen(buf);
int first = 1;
cli_ch_init(cch);
- memset(cls, '\0', sizeof(struct cli_line_state));
- cls->insert = true;
- cls->len = *len;
+ cli_cread_init(cls, buf, *len);
cls->prompt = prompt;
- cls->buf = buf;
-
- if (init_len)
- cread_add_str(buf, init_len, 1, &cls->num, &cls->eol_num, buf,
- *len);
+ cls->history = true;
+ cls->cmd_complete = true;
while (1) {
int ret;
#else /* !CONFIG_CMDLINE_EDITING */
-static inline void hist_init(void)
+static inline int hist_init(void)
{
+ return 0;
}
static int cread_line(const char *const prompt, char *buf, unsigned int *len,
int n = 0; /* buffer index */
int plen = 0; /* prompt length */
int col; /* output column cnt */
- char c;
+ int c;
/* print prompt */
if (prompt) {
*/
if (IS_ENABLED(CONFIG_CMDLINE_EDITING) && (gd->flags & GD_FLG_RELOC)) {
if (!initted) {
- hist_init();
- initted = 1;
+ rc = hist_init();
+ if (rc == 0)
+ initted = 1;
}
if (prompt)