--- grub/ChangeLog.05 Mon Oct 14 15:12:34 2002 +++ grub/ChangeLog Mon Oct 14 15:16:00 2002 @@ -1,5 +1,9 @@ 2002-10-14 Adam Lackorzynski + * stage2/stage2.c: Add menu history support. + (cmain): Save history in history buffer. + (run_menu): Add history, go one entry back in history on key left. + * stage2/stage2.c (run_menu): Make right key to do the same as enter in the menu. --- grub/stage2/stage2.c.05 Mon Oct 14 01:31:22 2002 +++ grub/stage2/stage2.c Mon Oct 14 01:46:20 2002 @@ -76,6 +76,21 @@ #endif /* ! PRESET_MENU_STRING && ! SUPPORT_DISKLESS */ +/* config_file is 128 Bytes long (see grub/asmstub.c) */ +#define CONFIG_FILE_LEN 128 +#define CONFIG_FILE_HISTORY_ENTRIES 10 +struct config_file_history_struct { + char filename[CONFIG_FILE_LEN]; + int entryno; + int first_entry; +}; +static struct config_file_history_struct + config_file_history[CONFIG_FILE_HISTORY_ENTRIES]; +static int config_file_history_pos, config_file_history_start, + config_file_history_prev_pos; +static int config_file_history_menu_pos = -1; + + static char * get_entry (char *list, int num, int nested) { @@ -234,6 +249,15 @@ */ restart: + + if (config_file_history_menu_pos != -1) + { + /* we're in a history back movement, set menu values to previous ones */ + entryno = config_file_history[config_file_history_menu_pos].entryno; + first_entry = config_file_history[config_file_history_menu_pos].first_entry; + config_file_history_menu_pos = -1; + } + /* Dumb terminal always use all entries for display invariant for TERM_DUMB: first_entry == 0 */ if (! (current_term->flags & TERM_DUMB)) @@ -314,8 +338,9 @@ if (config_entries) printf ("\ Press enter or %c to boot the selected OS, \'e\' to edit the\n\ - commands before booting, \'c\' for a command-line, or \'r\' to reload.", - DISP_RIGHT); + commands before booting, \'c\' for a command-line, \'r\' to reload or\n\ + or %c to go back if possible.", + DISP_RIGHT, DISP_LEFT); else printf ("\ Press \'b\' to boot, \'e\' to edit the selected command in the\n\ @@ -534,7 +559,30 @@ return; if ((c == '\n') || (c == '\r') || (c == 6)) - break; + { + config_file_history[config_file_history_prev_pos].entryno = + entryno; + config_file_history[config_file_history_prev_pos].first_entry = + first_entry; + + break; + } + + if (c == 2) /* KEY_LEFT */ + { + /* go back in history if possible */ + int p = config_file_history_prev_pos; + if (p != config_file_history_start) + { + p = (p == 0) ? CONFIG_FILE_HISTORY_ENTRIES - 1 : p - 1; + memmove(config_file, config_file_history[p].filename, + CONFIG_FILE_LEN); + config_file_history_pos = p; + config_file_history_menu_pos = p; + + return; + } + } } else { @@ -1021,6 +1069,18 @@ close_preset_menu (); else grub_close (); + + /* Save history for config_file */ + memmove(config_file_history[config_file_history_pos].filename, + config_file, + CONFIG_FILE_LEN); + config_file_history_prev_pos = config_file_history_pos; + if (++config_file_history_pos == CONFIG_FILE_HISTORY_ENTRIES) + config_file_history_pos = 0; + if (config_file_history_start == config_file_history_pos && + ++config_file_history_start == CONFIG_FILE_HISTORY_ENTRIES) + config_file_history_start = 0; + } while (is_preset); }