* [PATCH] Using enum symbols as indices into menuentry options
@ 2012-03-03 20:50 Andreas Vogel
2012-03-03 21:03 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Vogel @ 2012-03-03 20:50 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 349 bytes --]
Here is another tiny patch which uses a enum to reference the options
array when dealing with command line options for a menuentry.
This method is already used by some other modules. I have some more
patches which are adding more options for the menuentry command so
finally readabilty will be improved using these symbols.
Any comments?
Andreas
[-- Attachment #2: 02-menuentry_options_enum.patch --]
[-- Type: text/plain, Size: 2131 bytes --]
------------------------------------------------------------
revno: 4099
committer: Andreas Vogel <Andreas.F.Vogel@gmail.com>
branch nick: 02-menuentry_options_enum
timestamp: Thu 2012-03-01 22:40:25 +0100
message:
* grub-core/commands/menuentry.c: use enum symbols for indexing
the options array in order to improve readability
diff:
=== modified file 'grub-core/commands/menuentry.c'
--- grub-core/commands/menuentry.c 2012-03-01 21:38:32 +0000
+++ grub-core/commands/menuentry.c 2012-03-01 21:40:25 +0000
@@ -25,6 +25,14 @@
#include <grub/i18n.h>
#include <grub/normal.h>
+enum options
+ {
+ O_CLASS = 0,
+ O_USERS,
+ O_HOTKEY,
+ O_SOURCE,
+ };
+
static const struct grub_arg_option options[] =
{
{"class", 1, GRUB_ARG_OPTION_REPEATABLE,
@@ -324,18 +332,18 @@
if (! argc)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing arguments");
- if (ctxt->state[3].set && ctxt->script)
+ if (ctxt->state[O_SOURCE].set && ctxt->script)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "multiple menuentry definitions");
- if (! ctxt->state[3].set && ! ctxt->script)
+ if (! ctxt->state[O_SOURCE].set && ! ctxt->script)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no menuentry definition");
if (! ctxt->script)
return grub_normal_add_menu_entry (argc, (const char **) args,
- (ctxt->state[0].set ? ctxt->state[0].args
- : NULL), ctxt->state[1].arg,
- ctxt->state[2].arg, 0,
- ctxt->state[3].arg,
+ (ctxt->state[O_CLASS].set ? ctxt->state[O_CLASS].args
+ : NULL), ctxt->state[O_USERS].arg,
+ ctxt->state[O_HOTKEY].arg, 0,
+ ctxt->state[O_SOURCE].arg,
ctxt->extcmd->cmd->name[0] == 's');
src = args[argc - 1];
@@ -350,8 +358,8 @@
return grub_errno;
r = grub_normal_add_menu_entry (argc - 1, (const char **) args,
- ctxt->state[0].args, ctxt->state[1].arg,
- ctxt->state[2].arg, prefix, src + 1,
+ ctxt->state[O_CLASS].args, ctxt->state[O_USERS].arg,
+ ctxt->state[O_HOTKEY].arg, prefix, src + 1,
ctxt->extcmd->cmd->name[0] == 's');
src[len - 1] = ch;
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] Using enum symbols as indices into menuentry options 2012-03-03 20:50 [PATCH] Using enum symbols as indices into menuentry options Andreas Vogel @ 2012-03-03 21:03 ` Vladimir 'φ-coder/phcoder' Serbinenko [not found] ` <4F528960.7040308@anvo-it.de> 0 siblings, 1 reply; 4+ messages in thread From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-03-03 21:03 UTC (permalink / raw) To: The development of GNU GRUB; +Cc: Andreas Vogel On 03.03.2012 21:50, Andreas Vogel wrote: > +enum options > + { Please don't define a type here, especially that a type "options" can easily conflict with something else. -- Regards Vladimir 'φ-coder/phcoder' Serbinenko ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <4F528960.7040308@anvo-it.de>]
* Re: [PATCH] Using enum symbols as indices into menuentry options [not found] ` <4F528960.7040308@anvo-it.de> @ 2012-03-03 21:24 ` Vladimir 'φ-coder/phcoder' Serbinenko 2012-03-03 21:56 ` Andreas Vogel 0 siblings, 1 reply; 4+ messages in thread From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-03-03 21:24 UTC (permalink / raw) To: The development of GRUB 2 Keep list CC'ed. On 03.03.2012 22:13, Andreas Vogel wrote: >> On 03.03.2012 21:50, Andreas Vogel wrote: >>> +enum options >>> + { >> Please don't define a type here, especially that a type "options" can >> easily conflict with something else. >> > I reused that idea from commands/search_wrap.c and basically i liked > that idea. Just use an anonymous enum. -- Regards Vladimir 'φ-coder/phcoder' Serbinenko ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Using enum symbols as indices into menuentry options 2012-03-03 21:24 ` Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-03-03 21:56 ` Andreas Vogel 0 siblings, 0 replies; 4+ messages in thread From: Andreas Vogel @ 2012-03-03 21:56 UTC (permalink / raw) To: The development of GNU GRUB Cc: Vladimir 'φ-coder/phcoder' Serbinenko [-- Attachment #1: Type: text/plain, Size: 443 bytes --] > Keep list CC'ed. > On 03.03.2012 22:13, Andreas Vogel wrote: >>> On 03.03.2012 21:50, Andreas Vogel wrote: >>>> +enum options >>>> + { >>> Please don't define a type here, especially that a type "options" can >>> easily conflict with something else. >>> >> I reused that idea from commands/search_wrap.c and basically i liked >> that idea. > Just use an anonymous enum. > Please find attached the corrected patch using an anonymous enum. [-- Attachment #2: 02-menuentry_options_enum.patch --] [-- Type: text/plain, Size: 1781 bytes --] === modified file 'grub-core/commands/menuentry.c' --- grub-core/commands/menuentry.c 2012-03-01 21:38:32 +0000 +++ grub-core/commands/menuentry.c 2012-03-02 21:46:55 +0000 @@ -25,6 +25,14 @@ #include <grub/i18n.h> #include <grub/normal.h> +enum + { + O_CLASS = 0, + O_USERS, + O_HOTKEY, + O_SOURCE, + }; + static const struct grub_arg_option options[] = { {"class", 1, GRUB_ARG_OPTION_REPEATABLE, @@ -324,18 +332,18 @@ if (! argc) return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing arguments"); - if (ctxt->state[3].set && ctxt->script) + if (ctxt->state[O_SOURCE].set && ctxt->script) return grub_error (GRUB_ERR_BAD_ARGUMENT, "multiple menuentry definitions"); - if (! ctxt->state[3].set && ! ctxt->script) + if (! ctxt->state[O_SOURCE].set && ! ctxt->script) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no menuentry definition"); if (! ctxt->script) return grub_normal_add_menu_entry (argc, (const char **) args, - (ctxt->state[0].set ? ctxt->state[0].args - : NULL), ctxt->state[1].arg, - ctxt->state[2].arg, 0, - ctxt->state[3].arg, + (ctxt->state[O_CLASS].set ? ctxt->state[O_CLASS].args + : NULL), ctxt->state[O_USERS].arg, + ctxt->state[O_HOTKEY].arg, 0, + ctxt->state[O_SOURCE].arg, ctxt->extcmd->cmd->name[0] == 's'); src = args[argc - 1]; @@ -350,8 +358,8 @@ return grub_errno; r = grub_normal_add_menu_entry (argc - 1, (const char **) args, - ctxt->state[0].args, ctxt->state[1].arg, - ctxt->state[2].arg, prefix, src + 1, + ctxt->state[O_CLASS].args, ctxt->state[O_USERS].arg, + ctxt->state[O_HOTKEY].arg, prefix, src + 1, ctxt->extcmd->cmd->name[0] == 's'); src[len - 1] = ch; ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-03 21:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-03 20:50 [PATCH] Using enum symbols as indices into menuentry options Andreas Vogel
2012-03-03 21:03 ` Vladimir 'φ-coder/phcoder' Serbinenko
[not found] ` <4F528960.7040308@anvo-it.de>
2012-03-03 21:24 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-03-03 21:56 ` Andreas Vogel
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.