From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.33) id 1Ce6xS-00061i-RR for mharc-grub-devel@gnu.org; Tue, 14 Dec 2004 02:18:54 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Ce6xR-00061I-14 for grub-devel@gnu.org; Tue, 14 Dec 2004 02:18:53 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Ce6xQ-00060g-1G for Grub-devel@gnu.org; Tue, 14 Dec 2004 02:18:52 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Ce6xP-00060d-Uo for Grub-devel@gnu.org; Tue, 14 Dec 2004 02:18:52 -0500 Received: from [217.12.11.32] (helo=smtp001.mail.ukl.yahoo.com) by monty-python.gnu.org with smtp (Exim 4.34) id 1Ce6nA-0002kc-VW for Grub-devel@gnu.org; Tue, 14 Dec 2004 02:08:17 -0500 Received: from unknown (HELO ?192.168.0.2?) (subdino2004@83.194.33.228 with plain) by smtp001.mail.ukl.yahoo.com with SMTP; 14 Dec 2004 07:08:15 -0000 Message-ID: <41BE9159.7010500@yahoo.fr> Date: Tue, 14 Dec 2004 08:08:09 +0100 From: Vincent Pelletier User-Agent: Mozilla Thunderbird 0.9 (X11/20041124) X-Accept-Language: fr, en MIME-Version: 1.0 To: Grub-devel@gnu.org X-Enigmail-Version: 0.89.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig223C4DE6FE4F6A68ED9D67A8" Cc: Subject: [PATCH] normal/cmdline.c : history contains empty lines 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: Tue, 14 Dec 2004 07:18:53 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig223C4DE6FE4F6A68ED9D67A8 Content-Type: multipart/mixed; boundary="------------010607030502010407060001" This is a multi-part message in MIME format. --------------010607030502010407060001 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi. Here is my first patch to grub2 :) . Changelog : 2004-12-13 Vincent Pelletier * grub_history_get : doesn't add empty lines, exits if called with NULL argument * grub_cmdline_get : command is added to history after user hit "return", when pressing "down" arrow when on the most recent item in history an empty line is shown Vincent "Subdino" Pelletier --------------010607030502010407060001 Content-Type: text/plain; name="normal_cmdline_history_fixes.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="normal_cmdline_history_fixes.diff" Index: cmdline.c =================================================================== RCS file: /cvsroot/grub/grub2/normal/cmdline.c,v retrieving revision 1.10 diff -p -u -r1.10 cmdline.c --- cmdline.c 13 Dec 2004 17:26:17 -0000 1.10 +++ cmdline.c 13 Dec 2004 22:35:46 -0000 @@ -102,26 +102,30 @@ grub_history_get (int pos) static void grub_history_add (char *s) { - /* Remove the oldest entry in the history to make room for a new - entry. */ - if (hist_used + 1 > hist_size) - { - hist_end--; - if (hist_end < 0) - hist_end = hist_size + hist_end; + /* avoid inserting empty lines & protect from mistakes */ + if(s && grub_strlen(s)) + { + /* Remove the oldest entry in the history to make room for a new + entry. */ + if (hist_used + 1 > hist_size) + { + hist_end--; + if (hist_end < 0) + hist_end = hist_size + hist_end; - grub_free (hist_lines[hist_end]); - } - else - hist_used++; + grub_free (hist_lines[hist_end]); + } + else + hist_used++; - /* Move to the next position. */ - hist_pos--; - if (hist_pos < 0) - hist_pos = hist_size + hist_pos; + /* Move to the next position. */ + hist_pos--; + if (hist_pos < 0) + hist_pos = hist_size + hist_pos; - /* Insert into history. */ - hist_lines[hist_pos] = grub_strdup (s); + /* Insert into history. */ + hist_lines[hist_pos] = grub_strdup (s); + } } /* Replace the history entry on position POS with the string S. */ @@ -475,6 +479,7 @@ grub_cmdline_get (const char *prompt, ch auto void cl_delete (unsigned len); auto void cl_print (int pos, int c); auto void cl_set_pos (void); + const char empty_line[] = ""; void cl_set_pos (void) { @@ -556,8 +561,6 @@ grub_cmdline_get (const char *prompt, ch cl_insert (cmdline); - grub_history_add (buf); - while ((key = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && key != '\r') { if (readline) @@ -640,12 +643,16 @@ grub_cmdline_get (const char *prompt, ch lpos = 0; + cl_delete (llen); if (histpos > 0) - histpos--; + { + histpos--; + hist = grub_history_get (histpos); + } + else + hist = empty_line; - cl_delete (llen); - hist = grub_history_get (histpos); - cl_insert (hist); + cl_insert (hist); break; } @@ -726,6 +733,7 @@ grub_cmdline_get (const char *prompt, ch grub_history_replace (histpos, buf); } + grub_history_add (buf); grub_putchar ('\n'); grub_refresh (); --------------010607030502010407060001-- --------------enig223C4DE6FE4F6A68ED9D67A8 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBvpFeFEQoKRQyjtURArY0AJsGaA7Gd9XU1GFkHXOxUJk21W+t1gCglZ+G k6muKHGlts7pWL2OlMz6bGQ= =30+G -----END PGP SIGNATURE----- --------------enig223C4DE6FE4F6A68ED9D67A8--