From patchwork Sun Feb 24 17:26:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 222789 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 808C82C02A2 for ; Mon, 25 Feb 2013 04:35:44 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E956A4A19D; Sun, 24 Feb 2013 18:35:42 +0100 (CET) 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 lVqxqutTdmCH; Sun, 24 Feb 2013 18:35:42 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3F5274A15C; Sun, 24 Feb 2013 18:35:40 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 55ACC4A15C for ; Sun, 24 Feb 2013 18:35:38 +0100 (CET) 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 yEiGmH1vrVn4 for ; Sun, 24 Feb 2013 18:35:37 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ye0-f201.google.com (mail-ye0-f201.google.com [209.85.213.201]) by theia.denx.de (Postfix) with ESMTPS id 2F0BB4A155 for ; Sun, 24 Feb 2013 18:35:36 +0100 (CET) Received: by mail-ye0-f201.google.com with SMTP id m12so17560yen.2 for ; Sun, 24 Feb 2013 09:35:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=oBMS5mTQt6oARwY725VFfpVlRNpR9giqUYgfg6YGJQQ=; b=QOkwQbF1jScxXILiDA4g4lSoIwFmjOqyFDlZ8i7fnSd87B+yZ75lxFww7OmFynRw55 4EL78bchnNc/5HJEIQvWkm8uqUmA4YSajH0fzoHH47zCgak6KcRFfCtr3rHxrxWIiHk5 BqGf054jvtpARc1iCi67OwhVuhMsjKs6HMIUx9KsOgyulgAgeTveSeoZcbe63csXmMlQ v8c1/Z2Jk7AptOzmFutq5xv9ZaaF6b/CDxWYJDkJFsJiyZq+1QbzmTUrWkCs9keMc41p 5l0/ipoT60c1k57yFyKs3S7/oHGR61UFNlhEEhLJYpbpetQqZeRMTyr9IbcuO65r9pkV kN3g== X-Received: by 10.236.124.235 with SMTP id x71mr5224145yhh.25.1361727000786; Sun, 24 Feb 2013 09:30:00 -0800 (PST) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id f47si746651yhg.4.2013.02.24.09.30.00 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sun, 24 Feb 2013 09:30:00 -0800 (PST) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 8F73331C224; Sun, 24 Feb 2013 09:30:00 -0800 (PST) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 7126616033D; Sun, 24 Feb 2013 09:30:00 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Sun, 24 Feb 2013 09:26:09 -0800 Message-Id: <1361726773-18639-12-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1361726773-18639-1-git-send-email-sjg@chromium.org> References: <1361726773-18639-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQkTr9GkMI3RPamgr/+BOhQGIVhkd5/laPwyRxtgRkqrdfq4xELrWOH9hHOaFn1YdH3uZiKaN5namheVHWREBrglsERbLwYN3ZjzxA6CgVmUBK6BxEnqTc+G1VcGa7uDBMx2xw9zH3bC8R8H+qBMR9McdPFdYq80q/vypi6cX+AyFkjY3It3LvQknGIx47oQzl9BGEAj Cc: David Hendrix , Graeme Russ , Joe Hershberger , Tom Rini , Vadim Bendebury Subject: [U-Boot] [RFC PATCH v2 11/15] 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 v2: None common/main.c | 186 ++++++++++++++++++++++++------------------------------ include/command.h | 2 - include/common.h | 2 - 3 files changed, 84 insertions(+), 106 deletions(-) diff --git a/common/main.c b/common/main.c index e1483db..3966321 100644 --- a/common/main.c +++ b/common/main.c @@ -514,8 +514,6 @@ void reset_cmd_timeout(void) } #endif -#ifdef CONFIG_CMDLINE_EDITING - /* * cmdline-editing related codes from vivi. * Author: Janghoon Lyu @@ -618,27 +616,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); \ @@ -900,27 +877,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; @@ -936,8 +913,6 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len, return 0; } -#endif /* CONFIG_CMDLINE_EDITING */ - /****************************************************************************/ /* @@ -959,46 +934,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 (;;) { @@ -1011,32 +954,32 @@ 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(); /* * Special character handling */ switch (c) { - case '\r': /* Enter */ + case '\r': /* Enter */ case '\n': *p = '\0'; puts ("\r\n"); - return (p - p_buf); + return p - p_buf; - case '\0': /* nul */ + case '\0': /* nul */ continue; - case 0x03: /* ^C - break */ + case 0x03: /* ^C - break */ p_buf[0] = '\0'; /* discard input */ - return (-1); + return -1; - case 0x15: /* ^U - erase line */ + case 0x15: /* ^U - erase line */ while (col > plen) { puts (erase_seq); --col; @@ -1045,15 +988,15 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout) n = 0; continue; - case 0x17: /* ^W - erase word */ + case 0x17: /* ^W - erase word */ p=delete_char(p_buf, p, &col, &n, plen); while ((n > 0) && (*p != ' ')) { p=delete_char(p_buf, p, &col, &n, plen); } continue; - case 0x08: /* ^H - backspace */ - case 0x7F: /* DEL - backspace */ + case 0x08: /* ^H - backspace */ + case 0x7F: /* DEL - backspace */ p=delete_char(p_buf, p, &col, &n, plen); continue; @@ -1062,22 +1005,28 @@ int readline_into_buffer(const char *const prompt, char *buffer, int timeout) * Must be a normal character then */ 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 (c == '\t') { /* expand TABs */ + 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 { char buf[2]; /* - * Echo input using puts() to force am + * Echo input using puts() to force an * LCD flush if we are using an LCD */ ++col; @@ -1092,9 +1041,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 3785eb9..80da938 100644 --- a/include/command.h +++ b/include/command.h @@ -75,10 +75,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 fb219fd..1457349 100644 --- a/include/common.h +++ b/include/common.h @@ -857,9 +857,7 @@ int pcmcia_init (void); #include -#ifdef CONFIG_SHOW_ACTIVITY void show_activity(int arg); -#endif /* Multicore arch functions */ #ifdef CONFIG_MP