]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2005-08-28 Marco Gerards <metgerards@student.han.nl>
authormarco_g <marco_g@localhost>
Sun, 28 Aug 2005 17:01:16 +0000 (17:01 +0000)
committermarco_g <marco_g@localhost>
Sun, 28 Aug 2005 17:01:16 +0000 (17:01 +0000)
* include/grub/normal.h (enum grub_completion_type): Added
`GRUB_COMPLETION_TYPE_ARGUMENT'.

* normal/cmdline.c (print_completion): Handle
the `GRUB_COMPLETION_TYPE_ARGUMENT' type.
* normal/menu_entry.c (store_completion): Likewise.

* normal/completion.c (complete_arguments): New function.
(grub_normal_do_completion): Call `complete_arguments' when the
current words start with a dash.

ChangeLog
include/grub/normal.h
normal/cmdline.c
normal/completion.c
normal/menu_entry.c

index 73c88a27b7fe51d8531ecce165690ce2113d958d..a230190d28ec890e3db41ffe1ace62054984f704 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-08-28  Marco Gerards  <metgerards@student.han.nl>
+
+       * include/grub/normal.h (enum grub_completion_type): Added
+       `GRUB_COMPLETION_TYPE_ARGUMENT'.
+
+       * normal/cmdline.c (print_completion): Handle
+       the `GRUB_COMPLETION_TYPE_ARGUMENT' type.
+       * normal/menu_entry.c (store_completion): Likewise.
+
+       * normal/completion.c (complete_arguments): New function.
+       (grub_normal_do_completion): Call `complete_arguments' when the
+       current words start with a dash.
+
 2005-08-27  Marco Gerards  <metgerards@student.han.nl>
 
        * conf/powerpc-ieee1275.rmk (pkgdata_MODULES): Fix typo (use
index 5e0a2a9b32c10d1107565898fadc56e5c8f9e59c..89d0d74ac4deed6fe9d8080d550c0e3e5fbc2079 100644 (file)
@@ -51,6 +51,7 @@ enum grub_completion_type
     GRUB_COMPLETION_TYPE_DEVICE,
     GRUB_COMPLETION_TYPE_PARTITION,
     GRUB_COMPLETION_TYPE_FILE,
+    GRUB_COMPLETION_TYPE_ARGUMENT
   };
 typedef enum grub_completion_type grub_completion_type_t;
 
index 844864147f6a2486b4f8c7acc793e1ae0755a405..5403fa6cd31d9bab58e1f46c62fc84a9afa88661 100644 (file)
@@ -187,6 +187,9 @@ print_completion (const char *item, grub_completion_type_t type, int count)
        case GRUB_COMPLETION_TYPE_PARTITION:
          what = "partitions";
          break;
+       case GRUB_COMPLETION_TYPE_ARGUMENT:
+         what = "arguments";
+         break;
        default:
          what = "things";
          break;
index 7e4e77d2cbd1ae25324d4b27dabef4b0a0b2597c..b587a36ac5a0332b44e0fb4f34c4ce9c0cd69b07 100644 (file)
@@ -303,6 +303,61 @@ complete_file (void)
   return ret;
 }
 
+/* Complete an argument.  */
+static int
+complete_arguments (char *command)
+{
+  grub_command_t cmd;
+  struct grub_arg_option *option;
+  char shortarg[] = "- ";
+
+  cmd = grub_command_find (command); 
+
+  if (!cmd || !cmd->options)
+    return 0;
+
+  if (add_completion ("-u", " ", GRUB_COMPLETION_TYPE_ARGUMENT))
+    return 1;
+
+  /* Add the short arguments.  */
+  for (option = cmd->options; option->doc; option++)
+    {
+      if (!option->shortarg)
+       continue;
+
+      shortarg[1] = option->shortarg;
+      if (add_completion (shortarg, " ", GRUB_COMPLETION_TYPE_ARGUMENT))
+       return 1;
+
+    }
+
+  /* First add the built-in arguments.  */
+  if (add_completion ("--help", " ", GRUB_COMPLETION_TYPE_ARGUMENT))
+    return 1;
+  if (add_completion ("--usage", " ", GRUB_COMPLETION_TYPE_ARGUMENT))
+    return 1;
+
+  /* Add the long arguments.  */
+  for (option = cmd->options; option->doc; option++)
+    {
+      char *longarg;
+      if (!option->longarg)
+       continue;
+
+      longarg = grub_malloc (grub_strlen (option->longarg));
+      grub_sprintf (longarg, "--%s", option->longarg);
+
+      if (add_completion (longarg, " ", GRUB_COMPLETION_TYPE_ARGUMENT))
+       {
+         grub_free (longarg);
+         return 1;
+       }
+      grub_free (longarg);
+    }
+
+  return 0;
+}
+
 /* Try to complete the string in BUF. Return the characters that
    should be added to the string.  This command outputs the possible
    completions by calling HOOK, in that case set RESTORE to 1 so the
@@ -342,7 +397,12 @@ grub_normal_do_completion (char *buf, int *restore,
     {
       current_word++;
       
-      if (*current_word == '(' && ! grub_strchr (current_word, ')'))
+      if (*current_word == '-')
+       {
+         if (complete_arguments (buf))
+           goto fail;
+       }
+      else if (*current_word == '(' && ! grub_strchr (current_word, ')'))
        {
          /* Complete a device.  */
          if (complete_device ())
index 9cde3d4f0c27a1cc044a2b3e6d8d222b3693595d..987756c588c836a33cf742b4a09e36dfa3299c0a 100644 (file)
@@ -840,6 +840,9 @@ store_completion (const char *item, grub_completion_type_t type, int count)
        case GRUB_COMPLETION_TYPE_PARTITION:
          what = "partitions";
          break;
+       case GRUB_COMPLETION_TYPE_ARGUMENT:
+         what = "arguments";
+         break;
        default:
          what = "things";
          break;