All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vincent Pelletier <subdino2004@yahoo.fr>
To: Grub-devel@gnu.org
Subject: [PATCH] normal/cmdline.c : history contains empty lines
Date: Tue, 14 Dec 2004 08:08:09 +0100	[thread overview]
Message-ID: <41BE9159.7010500@yahoo.fr> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 382 bytes --]

Hi.
Here is my first patch to grub2 :) .

Changelog :

2004-12-13 Vincent Pelletier <subdino2004@yahoo.fr>
* 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


[-- Attachment #1.2: normal_cmdline_history_fixes.diff --]
[-- Type: text/plain, Size: 2646 bytes --]

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 ();


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 256 bytes --]

             reply	other threads:[~2004-12-14  7:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-14  7:08 Vincent Pelletier [this message]
2004-12-19 15:15 ` [PATCH] normal/cmdline.c : history contains empty lines Yoshinori K. Okuji
2004-12-19 15:46   ` Vincent Pelletier
2004-12-19 15:59     ` Yoshinori K. Okuji
2004-12-29 19:31 ` Marco Gerards
2004-12-29 19:49   ` Vincent Pelletier
2004-12-29 21:06     ` Marco Gerards

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=41BE9159.7010500@yahoo.fr \
    --to=subdino2004@yahoo.fr \
    --cc=Grub-devel@gnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.