--- lbbs/include/menu.h 2005/03/19 14:44:21 1.4 +++ lbbs/include/menu.h 2025/05/15 06:24:11 1.17 @@ -1,75 +1,153 @@ /*************************************************************************** - menu.h - description - ------------------- - begin : Wed Mar 16 2004 - copyright : (C) 2005 by Leaflet - email : leaflet@leafok.com + menu.h - description + ------------------- + Copyright : (C) 2004-2025 by Leaflet + Email : leaflet@leafok.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * + * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ -#define MAX_MENUITEM_LENGTH 50 -#define MAX_MENUITEMS 30 -#define MAX_MENUNAME_LENGTH 20 -#define MAX_MENUACTION_LENGTH 20 -#define MAX_MENUTITLE_LENGTH 50 -#define MAX_MENUS 256 -#define MAX_MENU_DEPTH 50 +#ifndef _MENU_H_ +#define _MENU_H_ -struct _menu_item { - int row, col, r_row, r_col; +#include "common.h" +#include "trie_dict.h" +#include +#include + +#define MAX_MENUITEM_LENGTH 50 +#define MAX_ITEMS_PER_MENU 30 +#define MAX_MENUNAME_LENGTH 256 +#define MAX_MENUACTION_LENGTH 20 +#define MAX_MENUTITLE_LENGTH 50 +#define MAX_MENU_SCR_NAME_LENGTH 20 +#define MAX_MENU_SCR_BUF_LENGTH 2000 +#define MAX_MENUS 256 +#define MAX_MENUITEMS 5120 +#define MAX_MENU_DEPTH 50 + +typedef uint64_t MENU_ID; +typedef uint64_t MENU_ITEM_ID; +typedef uint64_t MENU_SCREEN_ID; + +struct menu_item_t +{ + int16_t row, col; char action[MAX_MENUACTION_LENGTH]; - int submenu; - int priv, display; + MENU_ID action_menu_id; + int8_t submenu; + int priv, level; char name[MAX_MENUNAME_LENGTH]; char text[MAX_MENUITEM_LENGTH]; }; -typedef struct _menu_item MENU_ITEM; +typedef struct menu_item_t MENU_ITEM; -struct _menu_title { - int row, col; +struct menu_title_t +{ + int16_t row, col; + int8_t show; char text[MAX_MENUTITLE_LENGTH]; }; -typedef struct _menu_title MENU_TITLE; +typedef struct menu_title_t MENU_TITLE; -struct _menu_screen { - int row, col; - char filename[256]; +struct menu_screen_t +{ + char name[MAX_MENU_SCR_NAME_LENGTH]; + int64_t buf_offset; + int64_t buf_length; }; -typedef struct _menu_screen MENU_SCREEN; +typedef struct menu_screen_t MENU_SCREEN; -struct _menu { +struct menu_t +{ char name[MAX_MENUNAME_LENGTH]; MENU_TITLE title; - MENU_SCREEN screen; - MENU_ITEM *items[MAX_MENUITEMS]; - int item_count, item_cur_pos; + MENU_SCREEN_ID screen_id; + int8_t screen_show; + int16_t screen_row, screen_col; + MENU_ITEM_ID items[MAX_ITEMS_PER_MENU]; + int16_t item_count; }; -typedef struct _menu MENU; +typedef struct menu_t MENU; -struct _menu_set { - MENU *p_menu[MAX_MENUS]; - MENU *p_menu_select[MAX_MENU_DEPTH]; - int menu_count; - int menu_select_depth; +struct menu_set_t +{ + int shmid; + void *p_reserved; + void *p_menu_pool; + void *p_menu_item_pool; + void *p_menu_screen_pool; + char *p_menu_screen_buf; + char *p_menu_screen_buf_free; + int16_t menu_count; + int16_t menu_item_count; + int16_t menu_screen_count; + TRIE_NODE *p_menu_name_dict; + TRIE_NODE *p_menu_screen_dict; + MENU_ID menu_id_path[MAX_MENU_DEPTH]; + int16_t menu_item_pos[MAX_MENU_DEPTH]; + int16_t choose_step; + int8_t menu_item_display[MAX_ITEMS_PER_MENU]; + int16_t menu_item_r_row[MAX_ITEMS_PER_MENU]; + int16_t menu_item_r_col[MAX_ITEMS_PER_MENU]; }; -typedef struct _menu_set MENU_SET; - -extern MENU_SET bbs_menu; +typedef struct menu_set_t MENU_SET; -const char * -menu_control (MENU_SET * p_menu_set, int key); +extern MENU_SET *p_bbs_menu; -int -display_menu (MENU * p_menu); +extern int load_menu(MENU_SET *p_menu_set, const char *conf_file); +extern int unload_menu(MENU_SET *p_menu_set); -MENU * -get_menu (MENU_SET * p_menu_set, const char * menu_name); +extern int load_menu_shm(MENU_SET *p_menu_set); +extern int unload_menu_shm(MENU_SET *p_menu_set); +extern int menu_control(MENU_SET *p_menu_set, int key); +extern int display_menu(MENU_SET *p_menu_set); + +inline MENU *get_menu(MENU_SET *p_menu_set, const char *menu_name) +{ + MENU *value = NULL; + + trie_dict_get(p_menu_set->p_menu_name_dict, menu_name, (int64_t *)&value); + + return ((MENU *)value); +} + +inline MENU *get_menu_by_id(MENU_SET *p_menu_set, MENU_ID menu_id) +{ + if (menu_id < 0 || menu_id >= p_menu_set->menu_count) + { + return NULL; + } + + return (p_menu_set->p_menu_pool + sizeof(MENU) * menu_id); +} + +inline MENU_ITEM *get_menu_item_by_id(MENU_SET *p_menu_set, MENU_ITEM_ID menu_item_id) +{ + if (menu_item_id < 0 || menu_item_id >= p_menu_set->menu_item_count) + { + return NULL; + } + + return (p_menu_set->p_menu_item_pool + sizeof(MENU_ITEM) * menu_item_id); +} + +inline MENU_SCREEN *get_menu_screen_by_id(MENU_SET *p_menu_set, MENU_SCREEN_ID menu_screen_id) +{ + if (menu_screen_id < 0 || menu_screen_id >= p_menu_set->menu_screen_count) + { + return NULL; + } + + return (p_menu_set->p_menu_screen_pool + sizeof(MENU_ITEM) * menu_screen_id); +} + +#endif //_MENU_H_