grub_err_t grub_env_extractor_close (int source) { grub_menu_t menu = NULL; grub_menu_entry_t *last; grub_err_t err; if (source) { menu = grub_env_get_menu (); grub_env_unset_menu (); } err = grub_env_context_close (); if (source && menu) { grub_menu_t menu2; menu2 = grub_env_get_menu (); last = &menu2->entry_list; while (*last) last = &(*last)->next; *last = menu->entry_list; menu2->size += menu->size; } grub_extractor_level--; return err; }
static grub_menu_t read_config_file (const char *config) { grub_file_t file; auto grub_err_t getline (char **line, int cont); grub_err_t getline (char **line, int cont __attribute__ ((unused))) { while (1) { char *buf; *line = buf = grub_file_getline (file); if (! buf) return grub_errno; if (buf[0] == '#') grub_free (*line); else break; } return GRUB_ERR_NONE; } grub_menu_t newmenu; newmenu = grub_env_get_menu (); if (! newmenu) { newmenu = grub_zalloc (sizeof (*newmenu)); if (! newmenu) return 0; grub_env_set_menu (newmenu); } /* Try to open the config file. */ file = grub_file_open (config); if (! file) return 0; while (1) { char *line; /* Print an error, if any. */ grub_print_error (); grub_errno = GRUB_ERR_NONE; if ((getline (&line, 0)) || (! line)) break; grub_normal_parse_line (line, getline); grub_free (line); } grub_file_close (file); return newmenu; }