summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2016-04-22 11:21:03 +0200
committerLeo C2016-04-22 11:21:03 +0200
commit8ed660166ce9cdeb63b4cf710c663407b7ec9128 (patch)
tree57518c1b7ed4c6f3f28a23e16a6f165b998527f2 /avr
parentc647afca0ab5d67de1c18b52b4e50262fcb73425 (diff)
downloadz180-stamp-8ed660166ce9cdeb63b4cf710c663407b7ec9128.zip
Store only command line input in history buffer, but not data (i.e mm command)
Diffstat (limited to 'avr')
-rw-r--r--avr/cli.c6
-rw-r--r--avr/cli_readline.c72
-rw-r--r--avr/cmd_boot.c2
-rw-r--r--avr/cmd_mem.c4
-rw-r--r--avr/debug.c6
5 files changed, 47 insertions, 43 deletions
diff --git a/avr/cli.c b/avr/cli.c
index 8763ed1..aa2c388 100644
--- a/avr/cli.c
+++ b/avr/cli.c
@@ -8,9 +8,10 @@
* (C) Copyright 2005
* JinHua Luo, GuangDong Linux Center, <luo.jinhua@gd-linux.com>
*
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0
*/
+#include "cli.h"
#include "common.h"
#include <string.h>
@@ -25,7 +26,6 @@
#include "env.h"
#include "cli_readline.h"
#include "con-utils.h"
-#include "cli.h"
/* FIXME: Quoting problems */
@@ -364,7 +364,7 @@ void cli_loop(void)
int rc = 1;
for (;;) {
- len = cli_readline(PSTR(CONFIG_SYS_PROMPT));
+ len = cli_readline(PSTR(CONFIG_SYS_PROMPT), 1);
flag = 0; /* assume no special flags for now */
if (len > 0) {
diff --git a/avr/cli_readline.c b/avr/cli_readline.c
index 5545015..e4c3f5a 100644
--- a/avr/cli_readline.c
+++ b/avr/cli_readline.c
@@ -11,6 +11,7 @@
* SPDX-License-Identifier: GPL-2.0
*/
+#include "cli_readline.h"
#include "common.h"
#include <string.h>
#include <stdio.h>
@@ -22,7 +23,6 @@
#include "con-utils.h"
#include "print-utils.h"
#include "command.h"
-#include "cli_readline.h"
@@ -357,7 +357,8 @@ static void cread_add_str(char *str, int strsize, bool insert,
}
}
-static int cread_line(const FLASH char *const prompt, char *buf, uint_fast8_t *len)
+static int cread_line(const FLASH char *const prompt, char *buf,
+ uint_fast8_t *len, bool enable_history)
{
uint_fast8_t num = 0;
uint_fast8_t eol_num = 0;
@@ -455,32 +456,33 @@ static int cread_line(const FLASH char *const prompt, char *buf, uint_fast8_t *l
case CTL_CH('p'): /* previous-history */
case KEY_DOWN:
case CTL_CH('n'): /* next-history */
- {
- char *hline;
-
- if (ichar == CTL_CH('p') || ichar == KEY_UP)
- hline = hist_prev();
- else
- hline = hist_next();
-
- if (!hline) {
+ if (enable_history) {
+ char *hline;
+
+ if (ichar == CTL_CH('p') || ichar == KEY_UP)
+ hline = hist_prev();
+ else
+ hline = hist_next();
+
+ if (hline) {
+ /* nuke the current line */
+ /* first, go home */
+ BEGINNING_OF_LINE();
+
+ /* erase to end of line */
+ ERASE_TO_EOL();
+
+ /* copy new line into place and display */
+ strcpy(buf, hline);
+ eol_num = strlen(buf);
+ REFRESH_TO_EOL();
+ } else {
+ getcmd_cbeep();
+ }
+ } else {
getcmd_cbeep();
- continue;
}
-
- /* nuke the current line */
- /* first, go home */
- BEGINNING_OF_LINE();
-
- /* erase to end of line */
- ERASE_TO_EOL();
-
- /* copy new line into place and display */
- strcpy(buf, hline);
- eol_num = strlen(buf);
- REFRESH_TO_EOL();
- continue;
- }
+ break;
#ifdef CONFIG_AUTO_COMPLETE
case '\t': {
int num2, col;
@@ -512,16 +514,18 @@ static int cread_line(const FLASH char *const prompt, char *buf, uint_fast8_t *l
*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;
-
+ if (enable_history) {
+ if (buf[0])
+ cread_add_to_hist(buf);
+ hist_cur = hist_add_idx;
+ }
return 0;
}
/****************************************************************************/
-static int cli_readline_into_buffer(const FLASH char *const prompt, char *buffer)
+static int cli_readline_into_buffer(const FLASH char *const prompt,
+ char *buffer, bool enable_history)
{
char *p = buffer;
uint_fast8_t len = CONFIG_SYS_CBSIZE;
@@ -530,11 +534,11 @@ static int cli_readline_into_buffer(const FLASH char *const prompt, char *buffer
if (prompt)
my_puts_P(prompt);
- rc = cread_line(prompt, p, &len);
+ rc = cread_line(prompt, p, &len, enable_history);
return rc < 0 ? rc : (int) len;
}
-int cli_readline(const FLASH char *const prompt)
+int cli_readline(const FLASH char *const prompt, bool enable_history)
{
/*
* If console_buffer isn't 0-length the user will be prompted to modify
@@ -542,5 +546,5 @@ int cli_readline(const FLASH char *const prompt)
*/
console_buffer[0] = '\0';
- return cli_readline_into_buffer(prompt, console_buffer);
+ return cli_readline_into_buffer(prompt, console_buffer, enable_history);
}
diff --git a/avr/cmd_boot.c b/avr/cmd_boot.c
index ce280ac..f3bce9d 100644
--- a/avr/cmd_boot.c
+++ b/avr/cmd_boot.c
@@ -241,7 +241,7 @@ command_ret_t do_console(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
case ':':
putchar('\n');
- int cmdlen = cli_readline(PSTR(": "));
+ int cmdlen = cli_readline(PSTR(": "), 1);
if (cmdlen > 0)
run_command(console_buffer, 0);
break;
diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c
index effa416..a725c61 100644
--- a/avr/cmd_mem.c
+++ b/avr/cmd_mem.c
@@ -4,7 +4,7 @@
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0
*/
/*
@@ -151,7 +151,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
z80_bus_cmd(Release);
printf_P(PSTR("%05lx: %02x"), addr, data);
- nbytes = cli_readline(PSTR(" ? "));
+ nbytes = cli_readline(PSTR(" ? "), 0);
if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
/* <CR> pressed as only input, don't modify current
* location and move to next. "-" pressed will go back.
diff --git a/avr/debug.c b/avr/debug.c
index e29a085..384a5ad 100644
--- a/avr/debug.c
+++ b/avr/debug.c
@@ -1,9 +1,10 @@
/*
* (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
*
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0
*/
+#include "debug.h"
#include "common.h"
#include <stdlib.h>
#include <string.h>
@@ -13,7 +14,6 @@
#include "command.h"
#include "cli_readline.h"
#include "print-utils.h"
-#include "debug.h"
/*
* Debugging
@@ -170,7 +170,7 @@ mod_mem_avr(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const arg
data = *addr;
printf_P(PSTR("%04x: %02x"), addr, data);
- nbytes = cli_readline(PSTR(" ? "));
+ nbytes = cli_readline(PSTR(" ? "), 0);
if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
/* <CR> pressed as only input, don't modify current
* location and move to next. "-" pressed will go back.