PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/syslinux-4.05/com32/menu/menu.h

#
C Header | 236 lines | 164 code | 42 blank | 30 comment | 1 complexity | c33416c0e423ddd5a859c4344bc8a22f MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0, BSD-3-Clause
  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. * menu.h
  14. *
  15. * Header file for the simple menu system
  16. */
  17. #ifndef MENU_H
  18. #define MENU_H
  19. #include <time.h>
  20. #include <sys/time.h>
  21. #include <sys/times.h>
  22. #include <inttypes.h>
  23. #include <unistd.h>
  24. #include <colortbl.h>
  25. #include <stdbool.h>
  26. #include <getkey.h>
  27. #include "refstr.h"
  28. /* #define DEBUG 1 */
  29. #include <dprintf.h>
  30. #ifndef CLK_TCK
  31. # define CLK_TCK sysconf(_SC_CLK_TCK)
  32. #endif
  33. struct menu;
  34. /* Note: the _UNRES variants must always be immediately after their
  35. "normal" versions. */
  36. enum menu_action {
  37. MA_NONE, /* Undefined value */
  38. MA_CMD, /* Execute a command */
  39. MA_DISABLED, /* Disabled menu entry */
  40. MA_SUBMENU, /* This is a submenu entry */
  41. MA_GOTO, /* Go to another menu */
  42. MA_GOTO_UNRES, /* Unresolved go to */
  43. MA_QUIT, /* Quit to CLI */
  44. MA_EXIT, /* Exit to higher-level menu */
  45. MA_EXIT_UNRES, /* Unresolved exit */
  46. MA_HELP, /* Show help text */
  47. };
  48. struct menu_entry {
  49. struct menu *menu; /* Parent menu */
  50. const char *displayname;
  51. const char *label;
  52. const char *passwd;
  53. char *helptext;
  54. const char *cmdline;
  55. const char *background;
  56. struct menu *submenu;
  57. struct menu_entry *next; /* Linked list of all labels across menus */
  58. int entry; /* Entry number inside menu */
  59. enum menu_action action;
  60. unsigned char hotkey;
  61. bool immediate; /* Hotkey action does not require Enter */
  62. bool save; /* Save this entry if selected */
  63. };
  64. static inline bool is_disabled(struct menu_entry *me)
  65. {
  66. return me->action == MA_DISABLED;
  67. }
  68. enum kernel_type {
  69. /* Meta-types for internal use */
  70. KT_NONE,
  71. KT_LOCALBOOT,
  72. /* The ones we can pass off to SYSLINUX, in order */
  73. KT_KERNEL, /* Undefined type */
  74. KT_LINUX, /* Linux kernel */
  75. KT_BOOT, /* Bootstrap program */
  76. KT_BSS, /* Boot sector with patch */
  77. KT_PXE, /* PXE NBP */
  78. KT_FDIMAGE, /* Floppy disk image */
  79. KT_COMBOOT, /* COMBOOT image */
  80. KT_COM32, /* COM32 image */
  81. KT_CONFIG, /* Configuration file */
  82. };
  83. extern const char *const kernel_types[];
  84. /* Configurable integer parameters */
  85. enum parameter_number {
  86. P_WIDTH,
  87. P_MARGIN,
  88. P_PASSWD_MARGIN,
  89. P_MENU_ROWS,
  90. P_TABMSG_ROW,
  91. P_CMDLINE_ROW,
  92. P_END_ROW,
  93. P_PASSWD_ROW,
  94. P_TIMEOUT_ROW,
  95. P_HELPMSG_ROW,
  96. P_HELPMSGEND_ROW,
  97. P_HSHIFT,
  98. P_VSHIFT,
  99. P_HIDDEN_ROW,
  100. NPARAMS
  101. };
  102. /* Configurable messages */
  103. enum message_number {
  104. MSG_TITLE,
  105. MSG_AUTOBOOT,
  106. MSG_TAB,
  107. MSG_NOTAB,
  108. MSG_PASSPROMPT,
  109. MSG_COUNT
  110. };
  111. struct messages {
  112. const char *name; /* Message configuration name */
  113. const char *defmsg; /* Default message text */
  114. };
  115. struct menu_parameter {
  116. const char *name;
  117. int value;
  118. };
  119. extern const struct menu_parameter mparm[NPARAMS];
  120. struct fkey_help {
  121. const char *textname;
  122. const char *background;
  123. };
  124. struct menu {
  125. struct menu *next; /* Linked list of all menus */
  126. const char *label; /* Goto label for this menu */
  127. struct menu *parent;
  128. struct menu_entry *parent_entry; /* Entry for self in parent */
  129. struct menu_entry **menu_entries;
  130. struct menu_entry *menu_hotkeys[256];
  131. const char *messages[MSG_COUNT];
  132. int mparm[NPARAMS];
  133. int nentries;
  134. int nentries_space;
  135. int defentry;
  136. int timeout;
  137. bool allowedit;
  138. bool immediate; /* MENU IMMEDIATE default for this menu */
  139. bool save; /* MENU SAVE default for this menu */
  140. int curentry;
  141. int curtop;
  142. const char *title;
  143. const char *ontimeout;
  144. const char *onerror;
  145. const char *menu_master_passwd;
  146. const char *menu_background;
  147. struct color_table *color_table;
  148. struct fkey_help fkeyhelp[12];
  149. };
  150. extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list;
  151. /* 2048 is the current definition inside syslinux */
  152. #define MAX_CMDLINE_LEN 2048
  153. /* These are global parameters regardless of which menu we're displaying */
  154. extern int shiftkey;
  155. extern int hiddenmenu;
  156. extern int clearmenu;
  157. extern long long totaltimeout;
  158. extern const char *hide_key[KEY_MAX];
  159. void parse_configs(char **argv);
  160. int draw_background(const char *filename);
  161. void set_resolution(int x, int y);
  162. void start_console(void);
  163. void local_cursor_enable(bool);
  164. static inline int my_isspace(char c)
  165. {
  166. return (unsigned char)c <= ' ';
  167. }
  168. int my_isxdigit(char c);
  169. unsigned int hexval(char c);
  170. unsigned int hexval2(const char *p);
  171. uint32_t parse_argb(char **p);
  172. extern const int message_base_color, menu_color_table_size;
  173. int mygetkey(clock_t timeout);
  174. int show_message_file(const char *filename, const char *background);
  175. /* passwd.c */
  176. int passwd_compare(const char *passwd, const char *entry);
  177. /* colors.c */
  178. #define MSG_COLORS_DEF_FG 0x90ffffff
  179. #define MSG_COLORS_DEF_BG 0x80ffffff
  180. #define MSG_COLORS_DEF_SHADOW SHADOW_NORMAL
  181. void set_msg_colors_global(struct color_table *tbl,
  182. unsigned int fg, unsigned int bg,
  183. enum color_table_shadow shadow);
  184. struct color_table *default_color_table(void);
  185. struct color_table *copy_color_table(const struct color_table *master);
  186. extern const int message_base_color;
  187. /* background.c */
  188. extern const char *current_background;
  189. void set_background(const char *new_background);
  190. /* execute.c */
  191. void execute(const char *cmdline, enum kernel_type type);
  192. /* drain.c */
  193. void drain_keyboard(void);
  194. #endif /* MENU_H */