Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JWJ5W-0005Ch-T1 for mharc-grub-devel@gnu.org; Mon, 03 Mar 2008 17:24:50 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JWJ5U-0005AF-Lh for grub-devel@gnu.org; Mon, 03 Mar 2008 17:24:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JWJ5T-00057z-3Q for grub-devel@gnu.org; Mon, 03 Mar 2008 17:24:47 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JWJ5S-00057o-QB for grub-devel@gnu.org; Mon, 03 Mar 2008 17:24:46 -0500 Received: from aybabtu.com ([69.60.117.155]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JWJ5S-0004Hf-8V for grub-devel@gnu.org; Mon, 03 Mar 2008 17:24:46 -0500 Received: from [192.168.10.6] (helo=thorin) by aybabtu.com with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1JWJ5P-0001XC-Tz for grub-devel@gnu.org; Mon, 03 Mar 2008 23:24:44 +0100 Received: from rmh by thorin with local (Exim 4.63) (envelope-from ) id 1JWJ3j-00023x-3M for grub-devel@gnu.org; Mon, 03 Mar 2008 23:22:59 +0100 Date: Mon, 3 Mar 2008 23:22:59 +0100 From: Robert Millan To: The development of GRUB 2 Message-ID: <20080303222259.GE22431@thorin> References: <20080208161855.GA19377@thorin> <200802092103.09542.okuji@enbug.org> <20080228105756.GA2341@thorin> <200802282325.17822.okuji@enbug.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="BXVAT5kNtrzKuDFl" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <200802282325.17822.okuji@enbug.org> Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.13 (2006-08-11) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. Subject: Re: [PATCH] if timeout is set to zero, don't bother drawing the menu X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Mar 2008 22:24:49 -0000 --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Okay here's a preliminar patch. We still need to define in which ways can the user interrupt it. What do we do on '\n' ? and on ESC ? -- Robert Millan I know my rights; I want my phone call! What use is a phone call… if you are unable to speak? (as seen on /.) --BXVAT5kNtrzKuDFl Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="timeout.diff" diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../grub2/commands/read.c ./commands/read.c --- ../grub2/commands/read.c 2008-02-02 21:35:08.000000000 +0100 +++ ./commands/read.c 2008-03-03 23:13:24.000000000 +0100 @@ -23,13 +23,39 @@ #include #include #include +#include + +static const struct grub_arg_option options[] = + { + {"timeout", 't', 0, "timeout (in seconds)", 0, ARG_TYPE_INT}, + {"print-timeout", 'p', 0, "print timeout counter", 0, 0}, + {0, 0, 0, 0, 0, 0} + }; + +static grub_uint8_t x, y; + +static void +do_print (int n) +{ + grub_gotoxy (x, y); + /* NOTE: Do not remove the trailing space characters. + They are required to clear the line. */ + grub_printf ("%d ", n); +} static char * -grub_getline (void) +grub_getline (int timeout, int print_timeout) { int i; char *line; char *tmp; + grub_uint32_t end_at, print_at; + + if (timeout) + end_at = grub_get_rtc () + timeout * GRUB_TICKS_PER_SECOND; + + if (print_timeout) + print_at = grub_get_rtc (); i = 0; line = grub_malloc (1 + i + sizeof('\0')); @@ -38,27 +64,53 @@ grub_getline (void) while ((line[i - 1] != '\n') && (line[i - 1] != '\r')) { + /* If a timeout was requested, perform busy wait here so we can do other + things... */ + while (timeout && (grub_checkkey () == -1)) + { + /* ...such as printing the timeout, if applicable. */ + if (print_timeout && grub_get_rtc () > print_at) + { + do_print (grub_div_roundup (end_at - grub_get_rtc (), GRUB_TICKS_PER_SECOND)); + print_at += GRUB_TICKS_PER_SECOND; + } + /* ...or aborting when time is up. */ + if (grub_get_rtc () > end_at) + goto abort; + } + line[i] = grub_getkey (); if (grub_isprint (line[i])) grub_putchar (line[i]); i++; + tmp = grub_realloc (line, 1 + i + sizeof('\0')); if (! tmp) - { - grub_free (line); - return NULL; - } + goto abort; line = tmp; } line[i] = '\0'; return line; + +abort: + if (print_timeout) + do_print (0); + grub_free (line); + return NULL; } static grub_err_t -grub_cmd_read (struct grub_arg_list *state UNUSED, int argc, char **args) +grub_cmd_read (struct grub_arg_list *state, int argc, char **args) { - char *line = grub_getline (); + char *line; + grub_uint16_t xy; + + xy = grub_getxy (); + x = xy >> 8; + y = xy & 0xff; + + line = grub_getline ((state[0].set) ? grub_strtoul (state[0].arg, 0, 10) : 0, state[1].set); if (! line) return grub_errno; if (argc > 0) @@ -72,7 +124,7 @@ grub_cmd_read (struct grub_arg_list *sta GRUB_MOD_INIT(read) { grub_register_command ("read", grub_cmd_read, GRUB_COMMAND_FLAG_CMDLINE, - "read [ENVVAR]", "Set variable with user input", 0); + "read [ENVVAR]", "Set variable with user input", options); } GRUB_MOD_FINI(read) --BXVAT5kNtrzKuDFl--