You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2020/08/22 12:11:16 UTC

[incubator-nuttx-apps] 02/02: system/readline/readline_common.c: Don't save the command again in the history buffer if it's the one at the top.

This is an automated email from the ASF dual-hosted git repository.

davids5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git

commit aa717d59fd5cfaeca84729235e2456438f7bfc63
Author: Ouss4 <ab...@gmail.com>
AuthorDate: Sat Aug 22 11:57:22 2020 +0100

    system/readline/readline_common.c: Don't save the command again in the
    history buffer if it's the one at the top.
---
 system/readline/readline_common.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/system/readline/readline_common.c b/system/readline/readline_common.c
index 7cc1ec9..4fe7c6c 100644
--- a/system/readline/readline_common.c
+++ b/system/readline/readline_common.c
@@ -694,19 +694,26 @@ ssize_t readline_common(FAR struct rl_common_s *vtbl, FAR char *buf,
 
           if (nch >= 1)
             {
-              g_cmdhist.head = (g_cmdhist.head + 1) % RL_CMDHIST_LEN;
+              /* If this command is the one at the top of the circular
+               * buffer, don't save it again.
+               */
 
-              for (i = 0; (i < nch) && i < (RL_CMDHIST_LINELEN - 1); i++)
+              if (strncmp(buf, g_cmdhist.buf[g_cmdhist.head], nch) != 0)
                 {
-                  g_cmdhist.buf[g_cmdhist.head][i] = buf[i];
-                }
+                  g_cmdhist.head = (g_cmdhist.head + 1) % RL_CMDHIST_LEN;
+
+                  for (i = 0; (i < nch) && i < (RL_CMDHIST_LINELEN - 1); i++)
+                    {
+                      g_cmdhist.buf[g_cmdhist.head][i] = buf[i];
+                    }
 
-              g_cmdhist.buf[g_cmdhist.head][i] = '\0';
-              g_cmdhist.offset = 1;
+                  g_cmdhist.buf[g_cmdhist.head][i] = '\0';
+                  g_cmdhist.offset = 1;
 
-              if (g_cmdhist.len < RL_CMDHIST_LEN)
-                {
-                  g_cmdhist.len++;
+                  if (g_cmdhist.len < RL_CMDHIST_LEN)
+                    {
+                      g_cmdhist.len++;
+                    }
                 }
             }
 #endif /* CONFIG_READLINE_CMD_HISTORY */