menu.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #ifndef MENU_H
  2. #define MENU_H
  3. /* A single menu */
  4. typedef void (*menu_finish_callback)(struct menu_s *menu);
  5. typedef struct menu_s
  6. {
  7. char *name; /* Menu name */
  8. int num_options; /* Number of options in this menu */
  9. int flags; /* Various flags - see below */
  10. int option_align; /* Aligns options to a field width of this much characters if != 0 */
  11. struct menu_option_s **options; /* Pointer to this menu's options */
  12. menu_finish_callback callback; /* Called when the menu closes */
  13. } menu_t;
  14. /*
  15. * type: Type of the option (see below)
  16. * name: Name to display for this option
  17. * help: Optional help string
  18. * id : optional id number
  19. * sys : pointer for system-specific data, init to NULL and don't touch
  20. */
  21. #define OPTION_PREAMBLE \
  22. int type; \
  23. char *name; \
  24. char *help; \
  25. int id; \
  26. void *sys; \
  27. /*
  28. * Menu option types.
  29. * There are a number of different layouts for menu options depending
  30. * on their types. Currently there are the following possibilities:
  31. *
  32. * Submenu:
  33. * This entry links to a new menu.
  34. *
  35. * Boolean:
  36. * A simple on/off toggle entry. Booleans can be either yes/no, 0/1 or on/off.
  37. * Optionally, this entry can enable/disable a set of other options. An example would
  38. * be to enable/disable on-board USB, and if enabled give access to further options like
  39. * irq settings, base address etc.
  40. *
  41. * Text:
  42. * A single line/limited number of characters text entry box. Text can be restricted
  43. * to a certain charset (digits/hex digits/all/custom). Result is also available as an
  44. * int if numeric.
  45. *
  46. * Selection:
  47. * One-of-many type of selection entry. User may choose on of a set of strings, which
  48. * maps to a specific value for the variable.
  49. *
  50. * Routine:
  51. * Selecting this calls an entry-specific routine. This can be used for saving contents etc.
  52. *
  53. * Custom:
  54. * Display and behaviour of this entry is defined by a set of callbacks.
  55. */
  56. #define MENU_SUBMENU_TYPE 0
  57. typedef struct menu_submenu_s
  58. {
  59. OPTION_PREAMBLE
  60. menu_t * submenu; /* Pointer to the submenu */
  61. } menu_submenu_t;
  62. #define MENU_BOOLEAN_TYPE 1
  63. typedef struct menu_boolean_s
  64. {
  65. OPTION_PREAMBLE
  66. char *variable; /* Name of the variable to getenv()/setenv() */
  67. int subtype; /* Subtype (on/off, 0/1, yes/no, enable/disable), see below */
  68. int mutex; /* Bit mask of options to enable/disable. Bit 0 is the option
  69. immediately following this one, bit 1 is the next one etc.
  70. bit 7 = 0 means to disable when this option is off,
  71. bit 7 = 1 means to disable when this option is on.
  72. An option is disabled when the type field's upper bit is set */
  73. } menu_boolean_t;
  74. /* BOOLEAN Menu flags */
  75. #define MENU_BOOLEAN_ONOFF 0x01
  76. #define MENU_BOOLEAN_01 0x02
  77. #define MENU_BOOLEAN_YESNO 0x03
  78. #define MENU_BOOLEAN_ENDIS 0x04
  79. #define MENU_BOOLEAN_TYPE_MASK 0x07
  80. #define MENU_TEXT_TYPE 2
  81. typedef struct menu_text_s
  82. {
  83. OPTION_PREAMBLE
  84. char *variable; /* Name of the variable to getenv()/setenv() */
  85. int maxchars; /* Max number of characters */
  86. char *charset; /* Optional charset to use */
  87. int flags; /* Flags - see below */
  88. } menu_text_t;
  89. /* TEXT entry menu flags */
  90. #define MENU_TEXT_NUMERIC 0x01
  91. #define MENU_TEXT_HEXADECIMAL 0x02
  92. #define MENU_TEXT_FREE 0x03
  93. #define MENU_TEXT_TYPE_MASK 0x07
  94. #define MENU_SELECTION_TYPE 3
  95. typedef struct menu_select_option_s
  96. {
  97. char *map_from; /* Map this variable contents ... */
  98. char *map_to; /* ... to this menu text and vice versa */
  99. } menu_select_option_t;
  100. typedef struct menu_select_s
  101. {
  102. OPTION_PREAMBLE
  103. int num_options; /* Number of mappings */
  104. menu_select_option_t **options;
  105. /* Option list array */
  106. } menu_select_t;
  107. #define MENU_ROUTINE_TYPE 4
  108. typedef void (*menu_routine_callback)(struct menu_routine_s *);
  109. typedef struct menu_routine_s
  110. {
  111. OPTION_PREAMBLE
  112. menu_routine_callback callback;
  113. /* routine to be called */
  114. void *user_data; /* User data, don't care for system */
  115. } menu_routine_t;
  116. #define MENU_CUSTOM_TYPE 5
  117. typedef void (*menu_custom_draw)(struct menu_custom_s *);
  118. typedef void (*menu_custom_key)(struct menu_custom_s *, int);
  119. typedef struct menu_custom_s
  120. {
  121. OPTION_PREAMBLE
  122. menu_custom_draw drawfunc;
  123. menu_custom_key keyfunc;
  124. void *user_data;
  125. } menu_custom_t;
  126. /*
  127. * The menu option superstructure
  128. */
  129. typedef struct menu_option_s
  130. {
  131. union
  132. {
  133. menu_submenu_t m_sub_menu;
  134. menu_boolean_t m_boolean;
  135. menu_text_t m_text;
  136. menu_select_t m_select;
  137. menu_routine_t m_routine;
  138. };
  139. } menu_option_t;
  140. /* Init the menu system. Returns <0 on error */
  141. int menu_init(menu_t *root);
  142. /* Execute a single menu. Returns <0 on error */
  143. int menu_do(menu_t *menu);
  144. #endif