From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1E8mVS-00064r-6D for mharc-grub-devel@gnu.org; Fri, 26 Aug 2005 18:17:02 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1E8mVP-00064P-Ox for grub-devel@gnu.org; Fri, 26 Aug 2005 18:17:00 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1E8mVJ-00061w-3R for grub-devel@gnu.org; Fri, 26 Aug 2005 18:16:58 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1E8mVI-00061O-Qh for grub-devel@gnu.org; Fri, 26 Aug 2005 18:16:52 -0400 Received: from [145.74.66.11] (helo=mail-cn.han.nl) by monty-python.gnu.org with esmtp (Exim 4.34) id 1E8mRk-0004IH-QI for grub-devel@gnu.org; Fri, 26 Aug 2005 18:13:13 -0400 Received: from vscan-cn.han.nl (venus.han.nl [145.74.65.6]) by mail-cn.han.nl (Postfix) with ESMTP id 2AA698991 for ; Sat, 27 Aug 2005 00:11:32 +0200 (CEST) Received: from mail-cn.han.nl ([145.74.66.11]) by vscan-cn.han.nl (venus.han.nl [145.74.65.6]) (amavisd-new, port 10024) with ESMTP id 11515-04 for ; Sat, 27 Aug 2005 00:11:24 +0200 (CEST) Received: from mail1.han.nl (mail1.han.nl [145.74.103.11]) by mail-cn.han.nl (Postfix) with ESMTP id 1AF188AFF for ; Sat, 27 Aug 2005 00:11:24 +0200 (CEST) Received: from localhost.localdomain (mgerards.xs4all.nl [82.92.27.129]) by mail1.han.nl (Postfix) with ESMTP id 4A587C046 for ; Sat, 27 Aug 2005 00:11:23 +0200 (CEST) Mail-Copies-To: metgerards@student.han.nl To: grub-devel@gnu.org From: Marco Gerards Date: Sat, 27 Aug 2005 00:11:27 +0200 Message-ID: <87r7cg73hs.fsf@student.han.nl> User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new (2.2.0) at vscan-cn.han.nl Subject: Completion for arguments 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: Fri, 26 Aug 2005 22:17:00 -0000 Hi, Here is a patch that makes it possible to complete arguments. If no one objects, I will apply it on Sunday. Thanks, Marco 2005-08-27 Marco Gerards * 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. Index: include/grub/normal.h =================================================================== RCS file: /cvsroot/grub/grub2/include/grub/normal.h,v retrieving revision 1.21 diff -u -p -u -p -r1.21 normal.h --- include/grub/normal.h 20 Aug 2005 07:49:01 -0000 1.21 +++ include/grub/normal.h 26 Aug 2005 22:02:28 -0000 @@ -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: normal/cmdline.c =================================================================== RCS file: /cvsroot/grub/grub2/normal/cmdline.c,v retrieving revision 1.18 diff -u -p -u -p -r1.18 cmdline.c --- normal/cmdline.c 18 Aug 2005 03:14:38 -0000 1.18 +++ normal/cmdline.c 26 Aug 2005 22:02:28 -0000 @@ -187,6 +187,9 @@ print_completion (const char *item, grub case GRUB_COMPLETION_TYPE_PARTITION: what = "partitions"; break; + case GRUB_COMPLETION_TYPE_ARGUMENT: + what = "arguments"; + break; default: what = "things"; break; Index: normal/completion.c =================================================================== RCS file: /cvsroot/grub/grub2/normal/completion.c,v retrieving revision 1.2 diff -u -p -u -p -r1.2 completion.c --- normal/completion.c 18 Aug 2005 03:14:38 -0000 1.2 +++ normal/completion.c 26 Aug 2005 22:02:28 -0000 @@ -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, in { 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: normal/menu_entry.c =================================================================== RCS file: /cvsroot/grub/grub2/normal/menu_entry.c,v retrieving revision 1.3 diff -u -p -u -p -r1.3 menu_entry.c --- normal/menu_entry.c 18 Aug 2005 03:14:38 -0000 1.3 +++ normal/menu_entry.c 26 Aug 2005 22:02:28 -0000 @@ -840,6 +840,9 @@ store_completion (const char *item, grub case GRUB_COMPLETION_TYPE_PARTITION: what = "partitions"; break; + case GRUB_COMPLETION_TYPE_ARGUMENT: + what = "arguments"; + break; default: what = "things"; break;