mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 3/4] console_countdown: Add pattern list
Date: Wed, 24 Apr 2019 12:26:49 +0200	[thread overview]
Message-ID: <20190424102650.9257-3-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20190424102650.9257-1-s.hauer@pengutronix.de>

This adds an optional string argument to console_countdown() which can
hold a list of keys which also abort the countdown.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/timeout.c          |  2 +-
 common/console_countdown.c  | 19 ++++++++++++++++++-
 include/console_countdown.h |  2 +-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/commands/timeout.c b/commands/timeout.c
index d197cedd8b..db88900287 100644
--- a/commands/timeout.c
+++ b/commands/timeout.c
@@ -61,7 +61,7 @@ static int do_timeout(int argc, char *argv[])
 		return COMMAND_ERROR_USAGE;
 
 	timeout = simple_strtoul(argv[optind], NULL, 0);
-	ret = console_countdown(timeout, flags, str);
+	ret = console_countdown(timeout, flags, NULL, str);
 
 	if (varname && str[0])
 		setenv(varname, str);
diff --git a/common/console_countdown.c b/common/console_countdown.c
index 36da1ce577..8d09894c30 100644
--- a/common/console_countdown.c
+++ b/common/console_countdown.c
@@ -30,7 +30,22 @@ void console_countdown_abort(void)
 	console_countdown_timeout_abort = true;
 }
 
-int console_countdown(int timeout_s, unsigned flags, char *out_key)
+static int key_in_list(char key, const char *keys)
+{
+	if (!keys)
+		return false;
+
+	while (*keys) {
+		if (key == *keys)
+			return true;
+		keys++;
+	}
+
+	return false;
+}
+
+int console_countdown(int timeout_s, unsigned flags, const char *keys,
+		      char *out_key)
 {
 	uint64_t start, second;
 	int countdown, ret = -EINTR;
@@ -48,6 +63,8 @@ int console_countdown(int timeout_s, unsigned flags, char *out_key)
 		if (tstc()) {
 			key = getchar();
 			if (key >= 0) {
+				if (key_in_list(key, keys))
+					goto out;
 				if (flags & CONSOLE_COUNTDOWN_ANYKEY)
 					goto out;
 				if (flags & CONSOLE_COUNTDOWN_RETURN && key == '\n')
diff --git a/include/console_countdown.h b/include/console_countdown.h
index c6c2d5c00e..88cadf11ec 100644
--- a/include/console_countdown.h
+++ b/include/console_countdown.h
@@ -7,7 +7,7 @@
 #define CONSOLE_COUNTDOWN_CTRLC (1 << 4)
 #define CONSOLE_COUNTDOWN_EXTERN (1 << 5)
 
-int console_countdown(int timeout_s, unsigned flags, char *out_key);
+int console_countdown(int timeout_s, unsigned flags, const char *keys, char *out_key);
 void console_countdown_abort(void);
 
 #endif /* __CONSOLE_COUNTDOWN_H */
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2019-04-24 10:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 10:26 [PATCH 1/4] Shell: Handle aborting loops better Sascha Hauer
2019-04-24 10:26 ` [PATCH 2/4] console: forbid ctrlc during startup Sascha Hauer
2019-04-24 10:26 ` Sascha Hauer [this message]
2019-04-24 10:26 ` [PATCH 4/4] defaultenv: Convert init script to C Sascha Hauer
2019-04-26 12:37   ` Roland Hieber
2019-04-29  6:57     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190424102650.9257-3-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox