1 /* ----------------------------------------------------------------------- * 2 * 3 * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 8 * Boston MA 02110-1301, USA; either version 2 of the License, or 9 * (at your option) any later version; incorporated herein by reference. 10 * 11 * ----------------------------------------------------------------------- */ 12 13 /* 14 * menu.h 15 * 16 * Header file for the simple menu system 17 */ 18 19 #ifndef MENU_H 20 #define MENU_H 21 22 #include <time.h> 23 #include <sys/time.h> 24 #include <sys/times.h> 25 #include <inttypes.h> 26 #include <unistd.h> 27 #include <colortbl.h> 28 #include <stdbool.h> 29 #include <getkey.h> 30 #include "refstr.h" 31 32 /* #define DEBUG 1 */ 33 #include <dprintf.h> 34 35 #ifndef CLK_TCK 36 # define CLK_TCK sysconf(_SC_CLK_TCK) 37 #endif 38 39 struct menu; 40 41 /* Note: the _UNRES variants must always be immediately after their 42 "normal" versions. */ 43 enum menu_action { 44 MA_NONE, /* Undefined value */ 45 MA_CMD, /* Execute a command */ 46 MA_DISABLED, /* Disabled menu entry */ 47 MA_SUBMENU, /* This is a submenu entry */ 48 MA_GOTO, /* Go to another menu */ 49 MA_GOTO_UNRES, /* Unresolved go to */ 50 MA_QUIT, /* Quit to CLI */ 51 MA_EXIT, /* Exit to higher-level menu */ 52 MA_EXIT_UNRES, /* Unresolved exit */ 53 MA_HELP, /* Show help text */ 54 }; 55 56 struct menu_entry { 57 struct menu *menu; /* Parent menu */ 58 const char *displayname; 59 const char *label; 60 const char *passwd; 61 char *helptext; 62 const char *cmdline; 63 const char *background; 64 struct menu *submenu; 65 struct menu_entry *next; /* Linked list of all labels across menus */ 66 int entry; /* Entry number inside menu */ 67 enum menu_action action; 68 unsigned char hotkey; 69 bool immediate; /* Hotkey action does not require Enter */ 70 bool save; /* Save this entry if selected */ 71 }; 72 73 static inline bool is_disabled(struct menu_entry *me) 74 { 75 return me->action == MA_DISABLED; 76 } 77 78 enum kernel_type { 79 /* Meta-types for internal use */ 80 KT_NONE, 81 KT_LOCALBOOT, 82 83 /* The ones we can pass off to SYSLINUX, in order */ 84 KT_KERNEL, /* Undefined type */ 85 KT_LINUX, /* Linux kernel */ 86 KT_BOOT, /* Bootstrap program */ 87 KT_BSS, /* Boot sector with patch */ 88 KT_PXE, /* PXE NBP */ 89 KT_FDIMAGE, /* Floppy disk image */ 90 KT_COM32, /* COM32 image */ 91 KT_CONFIG, /* Configuration file */ 92 }; 93 94 /* Configurable integer parameters */ 95 enum parameter_number { 96 P_WIDTH, 97 P_MARGIN, 98 P_PASSWD_MARGIN, 99 P_MENU_ROWS, 100 P_TABMSG_ROW, 101 P_CMDLINE_ROW, 102 P_END_ROW, 103 P_PASSWD_ROW, 104 P_TIMEOUT_ROW, 105 P_HELPMSG_ROW, 106 P_HELPMSGEND_ROW, 107 P_HSHIFT, 108 P_VSHIFT, 109 P_HIDDEN_ROW, 110 111 NPARAMS 112 }; 113 114 /* Configurable messages */ 115 enum message_number { 116 MSG_TITLE, 117 MSG_AUTOBOOT, 118 MSG_TAB, 119 MSG_NOTAB, 120 MSG_PASSPROMPT, 121 122 MSG_COUNT 123 }; 124 125 struct messages { 126 const char *name; /* Message configuration name */ 127 const char *defmsg; /* Default message text */ 128 }; 129 130 struct menu_parameter { 131 const char *name; 132 int value; 133 }; 134 135 extern const struct menu_parameter mparm[NPARAMS]; 136 137 struct fkey_help { 138 const char *textname; 139 const char *background; 140 }; 141 142 struct menu { 143 struct menu *next; /* Linked list of all menus */ 144 const char *label; /* Goto label for this menu */ 145 struct menu *parent; 146 struct menu_entry *parent_entry; /* Entry for self in parent */ 147 148 struct menu_entry **menu_entries; 149 struct menu_entry *menu_hotkeys[256]; 150 151 const char *messages[MSG_COUNT]; 152 int mparm[NPARAMS]; 153 154 int nentries; 155 int nentries_space; 156 int defentry; 157 int timeout; 158 159 bool allowedit; 160 bool immediate; /* MENU IMMEDIATE default for this menu */ 161 bool save; /* MENU SAVE default for this menu */ 162 163 int curentry; 164 int curtop; 165 166 const char *title; 167 const char *ontimeout; 168 const char *onerror; 169 const char *menu_master_passwd; 170 const char *menu_background; 171 172 struct color_table *color_table; 173 174 struct fkey_help fkeyhelp[12]; 175 }; 176 177 extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list; 178 179 /* 2048 is the current definition inside syslinux */ 180 #define MAX_CMDLINE_LEN 2048 181 182 /* These are global parameters regardless of which menu we're displaying */ 183 extern int shiftkey; 184 extern int hiddenmenu; 185 extern int clearmenu; 186 extern long long totaltimeout; 187 extern clock_t kbdtimeout; 188 extern const char *hide_key[KEY_MAX]; 189 190 void parse_configs(char **argv); 191 int draw_background(const char *filename); 192 void set_resolution(int x, int y); 193 void start_console(void); 194 void local_cursor_enable(bool); 195 196 static inline int my_isspace(char c) 197 { 198 return (unsigned char)c <= ' '; 199 } 200 201 int my_isxdigit(char c); 202 unsigned int hexval(char c); 203 unsigned int hexval2(const char *p); 204 uint32_t parse_argb(char **p); 205 206 extern const int message_base_color, menu_color_table_size; 207 int mygetkey(clock_t timeout); 208 int show_message_file(const char *filename, const char *background); 209 210 /* passwd.c */ 211 int passwd_compare(const char *passwd, const char *entry); 212 213 /* colors.c */ 214 #define MSG_COLORS_DEF_FG 0x90ffffff 215 #define MSG_COLORS_DEF_BG 0x80ffffff 216 #define MSG_COLORS_DEF_SHADOW SHADOW_NORMAL 217 void set_msg_colors_global(struct color_table *tbl, 218 unsigned int fg, unsigned int bg, 219 enum color_table_shadow shadow); 220 struct color_table *default_color_table(void); 221 struct color_table *copy_color_table(const struct color_table *master); 222 extern const int message_base_color; 223 224 /* background.c */ 225 extern const char *current_background; 226 void set_background(const char *new_background); 227 228 /* drain.c */ 229 void drain_keyboard(void); 230 231 /* chainboot.c */ 232 void chainboot_file(const char *file, enum kernel_type type); 233 234 #endif /* MENU_H */ 235