]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
cli: Drop #ifdefs for CONFIG_AUTO_COMPLETE in cli_readline
authorSimon Glass <sjg@chromium.org>
Mon, 2 Oct 2023 01:13:08 +0000 (19:13 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 11 Oct 2023 19:43:54 +0000 (15:43 -0400)
Use a static inline and adjust the logic to avoid the need for #ifdefs in
cli_readline_into_buffer()

Signed-off-by: Simon Glass <sjg@chromium.org>
common/cli_readline.c
include/command.h

index 61f9ba99068a1171b342e1b6331351a7ab04d06b..458e927e4922c5c09d8f63ea23f1a99c5b753052 100644 (file)
@@ -386,27 +386,27 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
                        REFRESH_TO_EOL();
                        continue;
                }
-#ifdef CONFIG_AUTO_COMPLETE
-               case '\t': {
-                       int num2, col;
+               case '\t':
+                       if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
+                               int num2, col;
+
+                               /* do not autocomplete when in the middle */
+                               if (num < eol_num) {
+                                       getcmd_cbeep();
+                                       break;
+                               }
 
-                       /* do not autocomplete when in the middle */
-                       if (num < eol_num) {
-                               getcmd_cbeep();
+                               buf[num] = '\0';
+                               col = strlen(prompt) + eol_num;
+                               num2 = num;
+                               if (cmd_auto_complete(prompt, buf, &num2, &col)) {
+                                       col = num2 - num;
+                                       num += col;
+                                       eol_num += col;
+                               }
                                break;
                        }
-
-                       buf[num] = '\0';
-                       col = strlen(prompt) + eol_num;
-                       num2 = num;
-                       if (cmd_auto_complete(prompt, buf, &num2, &col)) {
-                               col = num2 - num;
-                               num += col;
-                               eol_num += col;
-                       }
-                       break;
-               }
-#endif
+                       fallthrough;
                default:
                        cread_add_char(ichar, insert, &num, &eol_num, buf,
                                       *len);
@@ -519,14 +519,15 @@ static int cread_line_simple(const char *const prompt, char *p)
                        continue;
 
                default:
-                       /*
-                        * Must be a normal character then
-                        */
-                       if (n < CONFIG_SYS_CBSIZE-2) {
-                               if (c == '\t') {        /* expand TABs */
-#ifdef CONFIG_AUTO_COMPLETE
+                       /* Must be a normal character then */
+                       if (n >= CONFIG_SYS_CBSIZE - 2) { /* Buffer full */
+                               putc('\a');
+                               break;
+                       }
+                       if (c == '\t') {        /* expand TABs */
+                               if (IS_ENABLED(CONFIG_AUTO_COMPLETE)) {
                                        /*
-                                        * if auto completion triggered just
+                                        * if auto-completion triggered just
                                         * continue
                                         */
                                        *p = '\0';
@@ -536,26 +537,24 @@ static int cread_line_simple(const char *const prompt, char *p)
                                                p = p_buf + n;  /* reset */
                                                continue;
                                        }
-#endif
-                                       puts(tab_seq + (col & 07));
-                                       col += 8 - (col & 07);
-                               } else {
-                                       char __maybe_unused buf[2];
-
-                                       /*
-                                        * Echo input using puts() to force an
-                                        * LCD flush if we are using an LCD
-                                        */
-                                       ++col;
-                                       buf[0] = c;
-                                       buf[1] = '\0';
-                                       puts(buf);
                                }
-                               *p++ = c;
-                               ++n;
-                       } else {                        /* Buffer full */
-                               putc('\a');
+                               puts(tab_seq + (col & 07));
+                               col += 8 - (col & 07);
+                       } else {
+                               char __maybe_unused buf[2];
+
+                               /*
+                                * Echo input using puts() to force an LCD
+                                * flush if we are using an LCD
+                                */
+                               ++col;
+                               buf[0] = c;
+                               buf[1] = '\0';
+                               puts(buf);
                        }
+                       *p++ = c;
+                       ++n;
+                       break;
                }
        }
 }
index 34ea989b39b4fe3667895edd30692941aeeae411..1c4ec4257a5e1525df37b3ced6dd6fd5ef02e3de 100644 (file)
@@ -95,6 +95,12 @@ int var_complete(int argc, char *const argv[], char last_char, int maxv,
                 char *cmdv[]);
 int cmd_auto_complete(const char *const prompt, char *buf, int *np,
                      int *colp);
+#else
+static inline int cmd_auto_complete(const char *const prompt, char *buf,
+                                   int *np, int *colp)
+{
+       return 0;
+}
 #endif
 
 /**