From patchwork Sat Oct 26 15:14:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 286287 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 0C06F2C0199 for ; Sun, 27 Oct 2013 02:17:12 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B203C4A241; Sat, 26 Oct 2013 17:17:03 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RK7mF0wMn02Q; Sat, 26 Oct 2013 17:17:03 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6EBC84A25B; Sat, 26 Oct 2013 17:16:33 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 085B14A1FD for ; Sat, 26 Oct 2013 17:16:29 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vICgx5k0rjHH for ; Sat, 26 Oct 2013 17:16:23 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 BL_NJABL=ERR(-1.5) (only DNSBL check requested) Received: from mail-ob0-f202.google.com (mail-ob0-f202.google.com [209.85.214.202]) by theia.denx.de (Postfix) with ESMTPS id 36AF14A1D9 for ; Sat, 26 Oct 2013 17:16:10 +0200 (CEST) Received: by mail-ob0-f202.google.com with SMTP id wn1so420306obc.3 for ; Sat, 26 Oct 2013 08:16:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=K9VDjkEUpZSsWVcCbo0cKU7bECxjDiU0t/GXgF1CwY8=; b=eU9tZbs+lqPmSjJRoMj0AVTJCAH5ndCHgF+DDNGUP/VFWeIvc3JG+tBGZFzzL2bUFJ 0EZ5nj7/q5fqjLnQjU9NP99WaebHO0k1jLrGyJhrhXqZsXN6QWAxbG9H7XXk9ve1/nK2 DQnnTk8Y7dTcpLWl2/aW3hae4tsJ5UkT+LsfsqurcVfsWS3Hrcxm+6VDA0xJBkHfx62n MLh7WJU3uchWZ5mEJY+h94BF24Xl3cUQstRYx3uKOXDWCo54VA85JuyVAVqHksyUqOmQ RjnJ8ItalVrXFVydGdDrFIulfNYEPQ8zmk4sgiJ2NCWdGnC9YyVtShQigUNav+j1K+U9 U2fA== X-Gm-Message-State: ALoCoQl1vEqe5J56B88Aa5oG9HVAtD6bd3f8pqL9sGOM0m6s5S9cAFBMZW78JsJN0D8I23VoFk/QPrkaRV861o8nWPtjIj05yHXAxZgHNtMr2wanj7eNGZ8gOGr0VXTNCVxNfIo/cmo8aach407E3kQY1s/NzmAWnMoh5X2cn+gAsJrwY7JvjE2wsZ7Lm7BCMlnj6pVOXxCb X-Received: by 10.43.152.202 with SMTP id kx10mr4895587icc.3.1382800568914; Sat, 26 Oct 2013 08:16:08 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id t42si674604yhm.3.2013.10.26.08.16.08 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 26 Oct 2013 08:16:08 -0700 (PDT) Received: from kaki.bld.corp.google.com (kaki.bld.corp.google.com [172.29.216.32]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id B13635A42A1; Sat, 26 Oct 2013 08:16:08 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 10C7E2208CD; Sat, 26 Oct 2013 09:15:24 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 26 Oct 2013 09:14:16 -0600 Message-Id: <1382800457-26608-8-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.4.1 In-Reply-To: <1382800457-26608-1-git-send-email-sjg@chromium.org> References: <1382800457-26608-1-git-send-email-sjg@chromium.org> Cc: David Hendrix , Joe Hershberger , Tom Rini , Vadim Bendebury Subject: [U-Boot] [PATCH v4 7/8] main: Use autoconf in command line reading X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Remove #ifdefs in favour of autoconf for this code. This involves removing a few unnecessary #ifdefs in headers also. We have two versions of the code - one that handles command line editing and one that is just a simple implementation. Create a new function called readline_into_buffer() which calls either cread_line() or the new simple_readline(), created to hold the 'simple' code. The cread_print_hist_list() function is not actually used anywhere, so punt it. Signed-off-by: Simon Glass Reviewed-by: Joe Hershberger --- Changes in v4: None Changes in v3: None Changes in v2: None common/main.c | 164 ++++++++++++++++++++++++------------------------------ include/command.h | 2 - include/common.h | 2 - 3 files changed, 73 insertions(+), 95 deletions(-) diff --git a/common/main.c b/common/main.c index 060da11..94f1e24 100644 --- a/common/main.c +++ b/common/main.c @@ -497,8 +497,6 @@ void reset_cmd_timeout(void) } #endif -#ifdef CONFIG_CMDLINE_EDITING - /* * cmdline-editing related codes from vivi. * Author: Janghoon Lyu @@ -601,27 +599,6 @@ static char* hist_next(void) return (ret); } -#ifndef CONFIG_CMDLINE_EDITING -static void cread_print_hist_list(void) -{ - int i; - unsigned long n; - - n = hist_num - hist_max; - - i = hist_add_idx + 1; - while (1) { - if (i > hist_max) - i = 0; - if (i == hist_add_idx) - break; - printf("%s\n", hist_list[i]); - n++; - i++; - } -} -#endif /* CONFIG_CMDLINE_EDITING */ - #define BEGINNING_OF_LINE() { \ while (num) { \ getcmd_putch(CTL_BACKSPACE); \ @@ -883,27 +860,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 (autoconf_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(); + 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; + 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; } - break; - } -#endif default: cread_add_char(ichar, insert, &num, &eol_num, buf, *len); break; @@ -919,8 +896,6 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len, return 0; } -#endif /* CONFIG_CMDLINE_EDITING */ - /****************************************************************************/ /* @@ -942,46 +917,14 @@ int readline (const char *const prompt) return readline_into_buffer(prompt, console_buffer, 0); } - -int readline_into_buffer(const char *const prompt, char *buffer, int timeout) +static int simple_readline(const char *const prompt, int plen, char *p, + int timeout) { - char *p = buffer; -#ifdef CONFIG_CMDLINE_EDITING - unsigned int len = CONFIG_SYS_CBSIZE; - int rc; - static int initted = 0; - - /* - * History uses a global array which is not - * writable until after relocation to RAM. - * Revert to non-history version if still - * running from flash. - */ - if (gd->flags & GD_FLG_RELOC) { - if (!initted) { - hist_init(); - initted = 1; - } - - if (prompt) - puts (prompt); - - rc = cread_line(prompt, p, &len, timeout); - return rc < 0 ? rc : len; - - } else { -#endif /* CONFIG_CMDLINE_EDITING */ char * p_buf = p; int n = 0; /* buffer index */ - int plen = 0; /* prompt length */ int col; /* output column cnt */ char c; - /* print prompt */ - if (prompt) { - plen = strlen (prompt); - puts (prompt); - } col = plen; for (;;) { @@ -994,12 +937,12 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout) } WATCHDOG_RESET(); /* Trigger watchdog, if needed */ -#ifdef CONFIG_SHOW_ACTIVITY - while (!tstc()) { - show_activity(0); - WATCHDOG_RESET(); + if (autoconf_show_activity()) { + while (!tstc()) { + show_activity(0); + WATCHDOG_RESET(); + } } -#endif c = getc(); /* @@ -1046,14 +989,20 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout) */ if (n < CONFIG_SYS_CBSIZE-2) { if (c == '\t') { /* expand TABs */ -#ifdef CONFIG_AUTO_COMPLETE - /* if auto completion triggered just continue */ - *p = '\0'; - if (cmd_auto_complete(prompt, console_buffer, &n, &col)) { - p = p_buf + n; /* reset */ - continue; + if (autoconf_auto_complete()) { + /* + * if auto completion triggered + * just continue + */ + *p = '\0'; + if (cmd_auto_complete(prompt, + console_buffer, + &n, &col)) { + /* reset */ + p = p_buf + n; + continue; + } } -#endif puts (tab_seq+(col&07)); col += 8 - (col&07); } else { @@ -1075,9 +1024,42 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout) } } } -#ifdef CONFIG_CMDLINE_EDITING +} + +int readline_into_buffer(const char *const prompt, char *buffer, int timeout) +{ + unsigned int len = CONFIG_SYS_CBSIZE; + int rc; + static int initted; + + /* + * History uses a global array which is not + * writable until after relocation to RAM. + * Revert to non-history version if still + * running from flash. + */ + if (autoconf_cmdline_editing() && (gd->flags & GD_FLG_RELOC)) { + if (!initted) { + hist_init(); + initted = 1; + } + + if (prompt) + puts(prompt); + + rc = cread_line(prompt, buffer, &len, timeout); + return rc < 0 ? rc : len; + + } else { + int plen = 0; /* prompt length */ + + /* print prompt */ + if (prompt) { + plen = strlen(prompt); + puts(prompt); + } + return simple_readline(prompt, plen, buffer, timeout); } -#endif } /****************************************************************************/ diff --git a/include/command.h b/include/command.h index f782779..d3ed6ed 100644 --- a/include/command.h +++ b/include/command.h @@ -59,10 +59,8 @@ cmd_tbl_t *find_cmd_tbl (const char *cmd, cmd_tbl_t *table, int table_len); extern int cmd_usage(const cmd_tbl_t *cmdtp); -#ifdef CONFIG_AUTO_COMPLETE extern int var_complete(int argc, char * const argv[], char last_char, int maxv, char *cmdv[]); extern int cmd_auto_complete(const char *const prompt, char *buf, int *np, int *colp); -#endif /* * Monitor Command diff --git a/include/common.h b/include/common.h index f07f740..735258e 100644 --- a/include/common.h +++ b/include/common.h @@ -903,9 +903,7 @@ int pcmcia_init (void); #include -#ifdef CONFIG_SHOW_ACTIVITY void show_activity(int arg); -#endif /* Multicore arch functions */ #ifdef CONFIG_MP