| 17 |
#ifndef _MENU_H_ |
#ifndef _MENU_H_ |
| 18 |
#define _MENU_H_ |
#define _MENU_H_ |
| 19 |
|
|
| 20 |
|
#include "bbs_cmd.h" |
| 21 |
#include "common.h" |
#include "common.h" |
| 22 |
|
#include "trie_dict.h" |
| 23 |
|
#include <stdint.h> |
| 24 |
|
|
| 25 |
#define MAX_MENUITEM_LENGTH 50 |
#define MAX_MENU_NAME_LENGTH 30 |
| 26 |
#define MAX_MENUITEMS 30 |
#define MAX_ITEMS_PER_MENU 256 |
| 27 |
#define MAX_MENUNAME_LENGTH 256 |
#define MAX_MENUITEM_NAME_LENGTH 256 |
| 28 |
#define MAX_MENUACTION_LENGTH 20 |
#define MAX_MENUITEM_TEXT_LENGTH 200 |
| 29 |
#define MAX_MENUTITLE_LENGTH 50 |
#define MAX_MENUITEM_ACTION_LENGTH 30 |
| 30 |
|
#define MAX_MENUTITLE_TEXT_LENGTH 100 |
| 31 |
|
#define MAX_MENU_SCR_NAME_LENGTH 20 |
| 32 |
|
#define MAX_MENU_SCR_BUF_LENGTH 2000 |
| 33 |
#define MAX_MENUS 256 |
#define MAX_MENUS 256 |
| 34 |
|
#define MAX_MENUITEMS 5120 |
| 35 |
#define MAX_MENU_DEPTH 50 |
#define MAX_MENU_DEPTH 50 |
| 36 |
|
|
| 37 |
struct _menu_item |
typedef uint64_t MENU_ID; |
| 38 |
|
typedef uint64_t MENU_ITEM_ID; |
| 39 |
|
typedef uint64_t MENU_SCREEN_ID; |
| 40 |
|
|
| 41 |
|
struct menu_item_t |
| 42 |
{ |
{ |
| 43 |
int row, col, r_row, r_col; |
int16_t row, col; |
| 44 |
char action[MAX_MENUACTION_LENGTH]; |
char action[MAX_MENUITEM_ACTION_LENGTH]; |
| 45 |
int submenu; |
MENU_ID action_menu_id; |
| 46 |
int priv, level, display; |
bbs_cmd_handler action_cmd_handler; |
| 47 |
char name[MAX_MENUNAME_LENGTH]; |
int8_t submenu; |
| 48 |
char text[MAX_MENUITEM_LENGTH]; |
int priv, level; |
| 49 |
|
char name[MAX_MENUITEM_NAME_LENGTH]; |
| 50 |
|
char text[MAX_MENUITEM_TEXT_LENGTH]; |
| 51 |
}; |
}; |
| 52 |
typedef struct _menu_item MENU_ITEM; |
typedef struct menu_item_t MENU_ITEM; |
| 53 |
|
|
| 54 |
struct _menu_title |
struct menu_title_t |
| 55 |
{ |
{ |
| 56 |
int row, col, show; |
int16_t row, col; |
| 57 |
char text[MAX_MENUTITLE_LENGTH]; |
int8_t show; |
| 58 |
|
char text[MAX_MENUTITLE_TEXT_LENGTH]; |
| 59 |
}; |
}; |
| 60 |
typedef struct _menu_title MENU_TITLE; |
typedef struct menu_title_t MENU_TITLE; |
| 61 |
|
|
| 62 |
struct _menu_screen |
struct menu_screen_t |
| 63 |
{ |
{ |
| 64 |
int row, col, show; |
char name[MAX_MENU_SCR_NAME_LENGTH]; |
| 65 |
char filename[FILE_PATH_LEN]; |
int64_t buf_offset; |
| 66 |
|
int64_t buf_length; |
| 67 |
}; |
}; |
| 68 |
typedef struct _menu_screen MENU_SCREEN; |
typedef struct menu_screen_t MENU_SCREEN; |
| 69 |
|
|
| 70 |
struct _menu |
struct menu_t |
| 71 |
{ |
{ |
| 72 |
char name[MAX_MENUNAME_LENGTH]; |
char name[MAX_MENU_NAME_LENGTH]; |
| 73 |
MENU_TITLE title; |
MENU_TITLE title; |
| 74 |
MENU_SCREEN screen; |
char screen_name[MAX_MENU_SCR_NAME_LENGTH]; |
| 75 |
MENU_ITEM *items[MAX_MENUITEMS]; |
MENU_SCREEN_ID screen_id; |
| 76 |
int item_count, item_cur_pos; |
int8_t screen_show; |
| 77 |
|
int16_t screen_row, screen_col; |
| 78 |
|
MENU_ITEM_ID items[MAX_ITEMS_PER_MENU]; |
| 79 |
|
int16_t item_count; |
| 80 |
|
int16_t page_row, page_col; |
| 81 |
|
int16_t page_item_limit; |
| 82 |
|
int8_t use_filter; |
| 83 |
|
bbs_cmd_handler filter_handler; |
| 84 |
}; |
}; |
| 85 |
typedef struct _menu MENU; |
typedef struct menu_t MENU; |
| 86 |
|
|
| 87 |
struct _menu_set |
struct menu_set_t |
| 88 |
{ |
{ |
| 89 |
char conf_file[FILE_PATH_LEN]; |
int shmid; |
| 90 |
MENU *p_menu[MAX_MENUS]; |
void *p_reserved; |
| 91 |
MENU *p_menu_select[MAX_MENU_DEPTH]; |
void *p_menu_pool; |
| 92 |
int menu_count; |
void *p_menu_item_pool; |
| 93 |
int menu_select_depth; |
void *p_menu_screen_pool; |
| 94 |
|
char *p_menu_screen_buf; |
| 95 |
|
char *p_menu_screen_buf_free; |
| 96 |
|
int16_t menu_count; |
| 97 |
|
int16_t menu_item_count; |
| 98 |
|
int16_t menu_screen_count; |
| 99 |
|
TRIE_NODE *p_menu_name_dict; |
| 100 |
|
TRIE_NODE *p_menu_screen_dict; |
| 101 |
|
MENU_ID menu_id_path[MAX_MENU_DEPTH]; |
| 102 |
|
int16_t menu_item_pos[MAX_MENU_DEPTH]; |
| 103 |
|
int16_t choose_step; |
| 104 |
|
int8_t menu_item_display[MAX_ITEMS_PER_MENU]; |
| 105 |
|
int16_t menu_item_r_row[MAX_ITEMS_PER_MENU]; |
| 106 |
|
int16_t menu_item_r_col[MAX_ITEMS_PER_MENU]; |
| 107 |
|
int16_t menu_item_page_id[MAX_ITEMS_PER_MENU]; |
| 108 |
|
int8_t allow_exit; |
| 109 |
}; |
}; |
| 110 |
typedef struct _menu_set MENU_SET; |
typedef struct menu_set_t MENU_SET; |
| 111 |
|
|
| 112 |
extern MENU_SET bbs_menu; |
extern MENU_SET bbs_menu; |
| 113 |
|
extern MENU_SET top10_menu; |
| 114 |
|
|
| 115 |
extern int load_menu(MENU_SET *p_menu_set, const char *conf_file); |
extern int load_menu(MENU_SET *p_menu_set, const char *conf_file); |
| 116 |
|
extern int unload_menu(MENU_SET *p_menu_set); |
| 117 |
|
|
| 118 |
extern void unload_menu(MENU_SET *p_menu_set); |
extern int get_menu_shm_readonly(MENU_SET *p_menu_set); |
| 119 |
|
extern int set_menu_shm_readonly(MENU_SET *p_menu_set); |
| 120 |
extern int reload_menu(MENU_SET *p_menu_set); |
extern int detach_menu_shm(MENU_SET *p_menu_set); |
| 121 |
|
|
| 122 |
|
extern int display_menu_cursor(MENU_SET *p_menu_set, int show); |
| 123 |
extern int menu_control(MENU_SET *p_menu_set, int key); |
extern int menu_control(MENU_SET *p_menu_set, int key); |
| 124 |
|
extern int display_menu(MENU_SET *p_menu_set); |
| 125 |
|
|
| 126 |
|
inline MENU *get_menu(MENU_SET *p_menu_set, const char *menu_name) |
| 127 |
|
{ |
| 128 |
|
MENU *value = NULL; |
| 129 |
|
|
| 130 |
|
trie_dict_get(p_menu_set->p_menu_name_dict, menu_name, (int64_t *)&value); |
| 131 |
|
|
| 132 |
|
return ((MENU *)value); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
extern int display_menu(MENU *p_menu); |
inline MENU *get_menu_by_id(MENU_SET *p_menu_set, MENU_ID menu_id) |
| 136 |
|
{ |
| 137 |
|
if (menu_id < 0 || menu_id >= p_menu_set->menu_count) |
| 138 |
|
{ |
| 139 |
|
return NULL; |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
return (p_menu_set->p_menu_pool + sizeof(MENU) * menu_id); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
inline MENU_ITEM *get_menu_item_by_id(MENU_SET *p_menu_set, MENU_ITEM_ID menu_item_id) |
| 146 |
|
{ |
| 147 |
|
if (menu_item_id < 0 || menu_item_id >= p_menu_set->menu_item_count) |
| 148 |
|
{ |
| 149 |
|
return NULL; |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
return (p_menu_set->p_menu_item_pool + sizeof(MENU_ITEM) * menu_item_id); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
extern int display_current_menu(MENU_SET *p_menu_set); |
inline MENU_SCREEN *get_menu_screen_by_id(MENU_SET *p_menu_set, MENU_SCREEN_ID menu_screen_id) |
| 156 |
|
{ |
| 157 |
|
if (menu_screen_id < 0 || menu_screen_id >= p_menu_set->menu_screen_count) |
| 158 |
|
{ |
| 159 |
|
return NULL; |
| 160 |
|
} |
| 161 |
|
|
| 162 |
extern MENU *get_menu(MENU_SET *p_menu_set, const char *menu_name); |
return (p_menu_set->p_menu_screen_pool + sizeof(MENU_ITEM) * menu_screen_id); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
#endif //_MENU_H_ |
#endif //_MENU_H_ |