/[LeafOK_CVS]/lbbs/include/menu.h
ViewVC logotype

Contents of /lbbs/include/menu.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.33 - (show annotations)
Tue Nov 4 14:58:55 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Changes since 1.32: +1 -1 lines
Content type: text/x-chdr
Refine file header information comments

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

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1