30 |
open_preset_menu (void) |
open_preset_menu (void) |
31 |
{ |
{ |
32 |
preset_menu_offset = 0; |
preset_menu_offset = 0; |
33 |
return 1; |
return preset_menu != 0; |
34 |
} |
} |
35 |
|
|
36 |
static int |
static int |
50 |
static void |
static void |
51 |
close_preset_menu (void) |
close_preset_menu (void) |
52 |
{ |
{ |
53 |
/* Do nothing. */ |
/* Disable the preset menu. */ |
54 |
|
preset_menu = 0; |
55 |
} |
} |
56 |
|
|
57 |
#else /* ! PRESET_MENU_STRING */ |
#else /* ! PRESET_MENU_STRING */ |
900 |
char *config_entries, *menu_entries; |
char *config_entries, *menu_entries; |
901 |
char *kill_buf = (char *) KILL_BUF; |
char *kill_buf = (char *) KILL_BUF; |
902 |
|
|
903 |
|
auto void reset (void); |
904 |
|
void reset (void) |
905 |
|
{ |
906 |
|
auto_fill = 1; |
907 |
|
config_len = 0; |
908 |
|
menu_len = 0; |
909 |
|
num_entries = 0; |
910 |
|
config_entries = (char *) mbi.drives_addr + mbi.drives_length; |
911 |
|
menu_entries = (char *) MENU_BUF; |
912 |
|
init_config (); |
913 |
|
} |
914 |
|
|
915 |
/* Initialize the environment for restarting Stage 2. */ |
/* Initialize the environment for restarting Stage 2. */ |
916 |
grub_setjmp (restart_env); |
grub_setjmp (restart_env); |
917 |
|
|
921 |
/* Never return. */ |
/* Never return. */ |
922 |
for (;;) |
for (;;) |
923 |
{ |
{ |
924 |
int is_opened = 0; |
int is_opened, is_preset; |
|
int is_preset = 0; |
|
|
|
|
|
auto_fill = 1; |
|
|
config_len = 0; |
|
|
menu_len = 0; |
|
|
num_entries = 0; |
|
|
config_entries = (char *) mbi.drives_addr + mbi.drives_length; |
|
|
menu_entries = (char *) MENU_BUF; |
|
|
init_config (); |
|
925 |
|
|
926 |
|
reset (); |
927 |
|
|
928 |
/* Here load the configuration file. */ |
/* Here load the configuration file. */ |
929 |
|
|
930 |
#ifdef GRUB_UTIL |
#ifdef GRUB_UTIL |
931 |
if (use_config_file) |
if (use_config_file) |
932 |
#endif /* GRUB_UTIL */ |
#endif /* GRUB_UTIL */ |
933 |
{ |
{ |
934 |
is_opened = grub_open (config_file); |
do |
|
errnum = ERR_NONE; |
|
|
if (! is_opened) |
|
|
is_opened = is_preset = open_preset_menu (); |
|
|
} |
|
|
|
|
|
if (is_opened) |
|
|
{ |
|
|
/* STATE 0: Before any title command. |
|
|
STATE 1: In a title command. |
|
|
STATE >1: In a entry after a title command. */ |
|
|
int state = 0, prev_config_len = 0, prev_menu_len = 0; |
|
|
char *cmdline; |
|
|
|
|
|
cmdline = (char *) CMDLINE_BUF; |
|
|
while (get_line_from_config (cmdline, NEW_HEAPSIZE, ! is_preset)) |
|
935 |
{ |
{ |
936 |
struct builtin *builtin; |
/* STATE 0: Before any title command. |
937 |
|
STATE 1: In a title command. |
938 |
|
STATE >1: In a entry after a title command. */ |
939 |
|
int state = 0, prev_config_len = 0, prev_menu_len = 0; |
940 |
|
char *cmdline; |
941 |
|
|
942 |
|
/* Try the preset menu first. This will succeed at most once, |
943 |
|
because close_preset_menu disables the preset menu. */ |
944 |
|
is_opened = is_preset = open_preset_menu (); |
945 |
|
if (! is_opened) |
946 |
|
{ |
947 |
|
is_opened = grub_open (config_file); |
948 |
|
errnum = ERR_NONE; |
949 |
|
} |
950 |
|
|
951 |
/* Get the pointer to the builtin structure. */ |
if (! is_opened) |
952 |
builtin = find_command (cmdline); |
break; |
|
errnum = 0; |
|
|
if (! builtin) |
|
|
/* Unknown command. Just skip now. */ |
|
|
continue; |
|
953 |
|
|
954 |
if (builtin->flags & BUILTIN_TITLE) |
/* This is necessary, because the menu must be overrided. */ |
955 |
|
reset (); |
956 |
|
|
957 |
|
cmdline = (char *) CMDLINE_BUF; |
958 |
|
while (get_line_from_config (cmdline, NEW_HEAPSIZE, |
959 |
|
! is_preset)) |
960 |
{ |
{ |
961 |
char *ptr; |
struct builtin *builtin; |
962 |
|
|
963 |
/* the command "title" is specially treated. */ |
/* Get the pointer to the builtin structure. */ |
964 |
if (state > 1) |
builtin = find_command (cmdline); |
965 |
|
errnum = 0; |
966 |
|
if (! builtin) |
967 |
|
/* Unknown command. Just skip now. */ |
968 |
|
continue; |
969 |
|
|
970 |
|
if (builtin->flags & BUILTIN_TITLE) |
971 |
{ |
{ |
972 |
/* The next title is found. */ |
char *ptr; |
973 |
num_entries++; |
|
974 |
config_entries[config_len++] = 0; |
/* the command "title" is specially treated. */ |
975 |
prev_menu_len = menu_len; |
if (state > 1) |
976 |
prev_config_len = config_len; |
{ |
977 |
|
/* The next title is found. */ |
978 |
|
num_entries++; |
979 |
|
config_entries[config_len++] = 0; |
980 |
|
prev_menu_len = menu_len; |
981 |
|
prev_config_len = config_len; |
982 |
|
} |
983 |
|
else |
984 |
|
{ |
985 |
|
/* The first title is found. */ |
986 |
|
menu_len = prev_menu_len; |
987 |
|
config_len = prev_config_len; |
988 |
|
} |
989 |
|
|
990 |
|
/* Reset the state. */ |
991 |
|
state = 1; |
992 |
|
|
993 |
|
/* Copy title into menu area. */ |
994 |
|
ptr = skip_to (1, cmdline); |
995 |
|
while ((menu_entries[menu_len++] = *(ptr++)) != 0) |
996 |
|
; |
997 |
|
} |
998 |
|
else if (! state) |
999 |
|
{ |
1000 |
|
/* Run a command found is possible. */ |
1001 |
|
if (builtin->flags & BUILTIN_MENU) |
1002 |
|
{ |
1003 |
|
char *arg = skip_to (1, cmdline); |
1004 |
|
(builtin->func) (arg, BUILTIN_MENU); |
1005 |
|
errnum = 0; |
1006 |
|
} |
1007 |
|
else |
1008 |
|
/* Ignored. */ |
1009 |
|
continue; |
1010 |
} |
} |
1011 |
else |
else |
1012 |
{ |
{ |
1013 |
/* The first title is found. */ |
char *ptr = cmdline; |
1014 |
menu_len = prev_menu_len; |
|
1015 |
config_len = prev_config_len; |
state++; |
1016 |
|
/* Copy config file data to config area. */ |
1017 |
|
while ((config_entries[config_len++] = *ptr++) != 0) |
1018 |
|
; |
1019 |
} |
} |
|
|
|
|
/* Reset the state. */ |
|
|
state = 1; |
|
|
|
|
|
/* Copy title into menu area. */ |
|
|
ptr = skip_to (1, cmdline); |
|
|
while ((menu_entries[menu_len++] = *(ptr++)) != 0) |
|
|
; |
|
1020 |
} |
} |
1021 |
else if (! state) |
|
1022 |
|
if (state > 1) |
1023 |
{ |
{ |
1024 |
/* Run a command found is possible. */ |
/* Finish the last entry. */ |
1025 |
if (builtin->flags & BUILTIN_MENU) |
num_entries++; |
1026 |
{ |
config_entries[config_len++] = 0; |
|
char *arg = skip_to (1, cmdline); |
|
|
(builtin->func) (arg, BUILTIN_MENU); |
|
|
errnum = 0; |
|
|
} |
|
|
else |
|
|
/* Ignored. */ |
|
|
continue; |
|
1027 |
} |
} |
1028 |
else |
else |
1029 |
{ |
{ |
1030 |
char *ptr = cmdline; |
menu_len = prev_menu_len; |
1031 |
|
config_len = prev_config_len; |
|
state++; |
|
|
/* Copy config file data to config area. */ |
|
|
while ((config_entries[config_len++] = *ptr++) != 0) |
|
|
; |
|
1032 |
} |
} |
1033 |
} |
|
1034 |
|
menu_entries[menu_len++] = 0; |
|
if (state > 1) |
|
|
{ |
|
|
/* Finish the last entry. */ |
|
|
num_entries++; |
|
1035 |
config_entries[config_len++] = 0; |
config_entries[config_len++] = 0; |
1036 |
} |
grub_memmove (config_entries + config_len, menu_entries, |
1037 |
else |
menu_len); |
1038 |
{ |
menu_entries = config_entries + config_len; |
1039 |
menu_len = prev_menu_len; |
|
1040 |
config_len = prev_config_len; |
/* Check if the default entry is present. Otherwise reset |
1041 |
} |
it to fallback if fallback is valid, or to DEFAULT_ENTRY |
1042 |
|
if not. */ |
1043 |
menu_entries[menu_len++] = 0; |
if (default_entry >= num_entries) |
1044 |
config_entries[config_len++] = 0; |
{ |
1045 |
grub_memmove (config_entries + config_len, menu_entries, menu_len); |
if (fallback_entry < 0 || fallback_entry >= num_entries) |
1046 |
menu_entries = config_entries + config_len; |
default_entry = 0; |
1047 |
|
else |
1048 |
/* Check if the default entry is present. Otherwise reset |
default_entry = fallback_entry; |
1049 |
it to fallback if fallback is valid, or to DEFAULT_ENTRY |
} |
1050 |
if not. */ |
|
1051 |
if (default_entry >= num_entries) |
if (is_preset) |
1052 |
{ |
close_preset_menu (); |
|
if (fallback_entry < 0 || fallback_entry >= num_entries) |
|
|
default_entry = 0; |
|
1053 |
else |
else |
1054 |
default_entry = fallback_entry; |
grub_close (); |
1055 |
} |
} |
1056 |
|
while (is_preset); |
|
if (is_preset) |
|
|
close_preset_menu (); |
|
|
else |
|
|
grub_close (); |
|
1057 |
} |
} |
1058 |
|
|
1059 |
if (! num_entries) |
if (! num_entries) |