]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Store only command line input in history buffer, but not data (i.e mm command)
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 22 Apr 2016 09:21:03 +0000 (11:21 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 22 Apr 2016 09:21:03 +0000 (11:21 +0200)
avr/cli.c
avr/cli_readline.c
avr/cmd_boot.c
avr/cmd_mem.c
avr/debug.c
include/cli.h
include/cli_readline.h
include/config.h
include/debug.h

index 8763ed1dff7a775c59af2522ed29d0e2ed5ec4a2..aa2c38883b1f58fe230166aa11bc9e814b73c080 100644 (file)
--- 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) {
index 5545015c27436cd17370702882bca0007f99646b..e4c3f5ad5893fbee9e75d62a9c7fe5481b056c3e 100644 (file)
@@ -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);
 }
index ce280acf817961dd2cf4e20269cddb610e76ca02..f3bce9d9544e9d5eda4c13591727e4d6acf5dc37 100644 (file)
@@ -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;
index effa416d86315c99a3d83d180117e970cec81724..a725c612056b956fb68a05121abba015fc9a7b68 100644 (file)
@@ -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.
index e29a0858b91dd41004fe9f7aabd8aae123c5773e..384a5ad9fab1ff32c5eb9b3fdb7477ca09874b7a 100644 (file)
@@ -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.
index 4920cc47e45bed7d1372370a31f21f3ce0f5e3d3..20e852fbe882d8019c01a68d0592a885f3bb53d8 100644 (file)
@@ -4,7 +4,7 @@
  * (C) Copyright 2014 Google, Inc
  * Simon Glass <sjg@chromium.org>
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #ifndef CLI_H
index 44715687400c4877272f32bab529816b6c74f64a..0e165cc11e1ebe65d58b588074de3b9239691cb7 100644 (file)
@@ -4,12 +4,15 @@
  * (C) Copyright 2014 Google, Inc
  * Simon Glass <sjg@chromium.org>
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #ifndef CLI_READLINE_H
 #define CLI_READLINE_H
 
+#include "common.h"
+#include <stdbool.h>
+
 extern char console_buffer[];  /* console I/O buffer   */
 
 /**
@@ -18,9 +21,10 @@ extern char console_buffer[];        /* console I/O buffer   */
  * This is a convenience function which calls cli_readline_into_buffer().
  *
  * @prompt: Prompt to display
+ * @enable_history: Use history buffer if true
  * @return command line length excluding terminator, or -ve on error
  */
-int cli_readline(const FLASH char *const prompt);
+int cli_readline(const FLASH char *const prompt, bool enable_history);
 
 /**
  * readline_into_buffer() - read a line into a buffer
@@ -44,7 +48,8 @@ int cli_readline(const FLASH char *const prompt);
  * parameter), then -2 is returned. If a break is detected (Ctrl-C) then
  * -1 is returned.
  */
-//int cli_readline_into_buffer(const char *const prompt, char *buffer, int timeout);
+//int cli_readline_into_buffer(const char *const prompt, char *buffer,
+//                     int timeout, bool enable_history);
 
 
 #endif /* CLI_READLINE_H */
index 1501989ea94ba7661ac5dd8dffab8b414a116a41..efc793ebc5cf44e1d1dc9e54f109667b919b68a2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
 #ifndef CONFIG_H
index 39c15b0ab88c77d52c568347c7031c6a6b6dc1fd..0ee0129fa45dae5ebeeb14a71f2f7f43b7c0a881 100644 (file)
@@ -4,7 +4,7 @@
  * (C) Copyright 2000-2009
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */