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

Contents of /lbbs/include/menu.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (show annotations)
Sat May 17 15:39:51 2025 UTC (10 months ago) by sysadm
Branch: MAIN
Changes since 1.17: +2 -0 lines
Content type: text/x-chdr
Refact bbs_cmd with trie_dict

1 /***************************************************************************
2 menu.h - description
3 -------------------
4 Copyright : (C) 2004-2025 by Leaflet
5 Email : leaflet@leafok.com
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 3 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17 #ifndef _MENU_H_
18 #define _MENU_H_
19
20 #include "common.h"
21 #include "trie_dict.h"
22 #include "bbs_cmd.h"
23 #include <stdint.h>
24 #include <sys/shm.h>
25
26 #define MAX_MENUITEM_LENGTH 50
27 #define MAX_ITEMS_PER_MENU 30
28 #define MAX_MENUNAME_LENGTH 256
29 #define MAX_MENUACTION_LENGTH 20
30 #define MAX_MENUTITLE_LENGTH 50
31 #define MAX_MENU_SCR_NAME_LENGTH 20
32 #define MAX_MENU_SCR_BUF_LENGTH 2000
33 #define MAX_MENUS 256
34 #define MAX_MENUITEMS 5120
35 #define MAX_MENU_DEPTH 50
36
37 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 int16_t row, col;
44 char action[MAX_MENUACTION_LENGTH];
45 MENU_ID action_menu_id;
46 bbs_cmd_handler action_cmd_handler;
47 int8_t submenu;
48 int priv, level;
49 char name[MAX_MENUNAME_LENGTH];
50 char text[MAX_MENUITEM_LENGTH];
51 };
52 typedef struct menu_item_t MENU_ITEM;
53
54 struct menu_title_t
55 {
56 int16_t row, col;
57 int8_t show;
58 char text[MAX_MENUTITLE_LENGTH];
59 };
60 typedef struct menu_title_t MENU_TITLE;
61
62 struct menu_screen_t
63 {
64 char name[MAX_MENU_SCR_NAME_LENGTH];
65 int64_t buf_offset;
66 int64_t buf_length;
67 };
68 typedef struct menu_screen_t MENU_SCREEN;
69
70 struct menu_t
71 {
72 char name[MAX_MENUNAME_LENGTH];
73 MENU_TITLE title;
74 MENU_SCREEN_ID screen_id;
75 int8_t screen_show;
76 int16_t screen_row, screen_col;
77 MENU_ITEM_ID items[MAX_ITEMS_PER_MENU];
78 int16_t item_count;
79 };
80 typedef struct menu_t MENU;
81
82 struct menu_set_t
83 {
84 int shmid;
85 void *p_reserved;
86 void *p_menu_pool;
87 void *p_menu_item_pool;
88 void *p_menu_screen_pool;
89 char *p_menu_screen_buf;
90 char *p_menu_screen_buf_free;
91 int16_t menu_count;
92 int16_t menu_item_count;
93 int16_t menu_screen_count;
94 TRIE_NODE *p_menu_name_dict;
95 TRIE_NODE *p_menu_screen_dict;
96 MENU_ID menu_id_path[MAX_MENU_DEPTH];
97 int16_t menu_item_pos[MAX_MENU_DEPTH];
98 int16_t choose_step;
99 int8_t menu_item_display[MAX_ITEMS_PER_MENU];
100 int16_t menu_item_r_row[MAX_ITEMS_PER_MENU];
101 int16_t menu_item_r_col[MAX_ITEMS_PER_MENU];
102 };
103 typedef struct menu_set_t MENU_SET;
104
105 extern MENU_SET *p_bbs_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 load_menu_shm(MENU_SET *p_menu_set);
111 extern int unload_menu_shm(MENU_SET *p_menu_set);
112
113 extern int menu_control(MENU_SET *p_menu_set, int key);
114 extern int display_menu(MENU_SET *p_menu_set);
115
116 inline MENU *get_menu(MENU_SET *p_menu_set, const char *menu_name)
117 {
118 MENU *value = NULL;
119
120 trie_dict_get(p_menu_set->p_menu_name_dict, menu_name, (int64_t *)&value);
121
122 return ((MENU *)value);
123 }
124
125 inline MENU *get_menu_by_id(MENU_SET *p_menu_set, MENU_ID menu_id)
126 {
127 if (menu_id < 0 || menu_id >= p_menu_set->menu_count)
128 {
129 return NULL;
130 }
131
132 return (p_menu_set->p_menu_pool + sizeof(MENU) * menu_id);
133 }
134
135 inline MENU_ITEM *get_menu_item_by_id(MENU_SET *p_menu_set, MENU_ITEM_ID menu_item_id)
136 {
137 if (menu_item_id < 0 || menu_item_id >= p_menu_set->menu_item_count)
138 {
139 return NULL;
140 }
141
142 return (p_menu_set->p_menu_item_pool + sizeof(MENU_ITEM) * menu_item_id);
143 }
144
145 inline MENU_SCREEN *get_menu_screen_by_id(MENU_SET *p_menu_set, MENU_SCREEN_ID menu_screen_id)
146 {
147 if (menu_screen_id < 0 || menu_screen_id >= p_menu_set->menu_screen_count)
148 {
149 return NULL;
150 }
151
152 return (p_menu_set->p_menu_screen_pool + sizeof(MENU_ITEM) * menu_screen_id);
153 }
154
155 #endif //_MENU_H_

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