From: Vladimir 'phcoder' Serbinenko Date: Mon, 28 Jun 2010 10:42:50 +0000 (+0200) Subject: Use normal parser for menu entries. X-Git-Tag: 1.99~787 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4045dee1b9eafeb912cb7056ea5c2067d688e5a2;p=thirdparty%2Fgrub.git Use normal parser for menu entries. Reported by: Thomas Frauendorfer * include/grub/parser.h (grub_parser_execute): Don't export. * normal/menu.c (grub_menu_execute_entry_real): New function. (grub_menu_execute_entry): Use grub_menu_execute_entry_real. --- diff --git a/ChangeLog b/ChangeLog index b9f4544b3..bccc55dea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-06-28 Vladimir Serbinenko + + Use normal parser for menu entries. + Reported by: Thomas Frauendorfer + + * include/grub/parser.h (grub_parser_execute): Don't export. + * normal/menu.c (grub_menu_execute_entry_real): New function. + (grub_menu_execute_entry): Use grub_menu_execute_entry_real. + 2010-06-28 Colin Watson * docs/grub.texi (Embedded configuration): New section (replacing diff --git a/include/grub/parser.h b/include/grub/parser.h index 064f73fcb..de4da05ad 100644 --- a/include/grub/parser.h +++ b/include/grub/parser.h @@ -83,7 +83,7 @@ struct grub_parser }; typedef struct grub_parser *grub_parser_t; -grub_err_t EXPORT_FUNC(grub_parser_execute) (char *source); +grub_err_t grub_parser_execute (char *source); grub_err_t grub_rescue_parse_line (char *line, grub_reader_getline_t getline); diff --git a/normal/menu.c b/normal/menu.c index 09c5fd1eb..f98cfed66 100644 --- a/normal/menu.c +++ b/normal/menu.c @@ -29,6 +29,7 @@ #include #include #include +#include /* Time to delay after displaying an error message about a default/fallback entry failing to boot. */ @@ -141,6 +142,44 @@ get_and_remove_first_entry_number (const char *name) return entry; } +static void +grub_menu_execute_entry_real (grub_menu_entry_t entry) +{ + const char *source; + + auto grub_err_t getline (char **line, int cont); + grub_err_t getline (char **line, int cont __attribute__ ((unused))) + { + const char *p; + + if (!source) + { + *line = 0; + return 0; + } + + p = grub_strchr (source, '\n'); + + if (p) + *line = grub_strndup (source, p - source); + else + *line = grub_strdup (source); + source = p ? p + 1 : 0; + return 0; + } + + source = entry->sourcecode; + + while (source) + { + char *line; + + getline (&line, 0); + grub_normal_parse_line (line, getline); + grub_free (line); + } +} + /* Run a menu entry. */ void grub_menu_execute_entry(grub_menu_entry_t entry) @@ -159,7 +198,7 @@ grub_menu_execute_entry(grub_menu_entry_t entry) grub_env_set ("chosen", entry->title); - grub_parser_execute ((char *) entry->sourcecode); + grub_menu_execute_entry_real (entry); if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ()) /* Implicit execution of boot, only if something is loaded. */