--- lbbs/src/menu.c 2025/11/04 14:15:49 1.81 +++ lbbs/src/menu.c 2025/11/17 14:01:13 1.87 @@ -3,9 +3,13 @@ * menu * - configurable user interactive menu feature * - * Copyright (C) 2004-2025 by Leaflet + * Copyright (C) 2004-2025 Leaflet */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "bbs.h" #include "bbs_cmd.h" #include "bbs_cmd.h" @@ -24,13 +28,14 @@ #include #include -#define MENU_SCREEN_PATH_PREFIX "var/MENU_SCR_" -#define MENU_CONF_DELIM_WITH_SPACE " ,\t\r\n" -#define MENU_CONF_DELIM_WITHOUT_SPACE "\r\n" - -#define MENU_SET_RESERVED_LENGTH (sizeof(int16_t) * 4) +enum _menu_constant_t +{ + MENU_SET_RESERVED_LENGTH = sizeof(int16_t) * 4, + MENU_SHMGET_RETRY_LIMIT = 10, +}; -#define MENU_SHMGET_RETRY_LIMIT 10 +static const char MENU_CONF_DELIM_WITH_SPACE[] = " ,\t\r\n"; +static const char MENU_CONF_DELIM_WITHOUT_SPACE[] = "\r\n"; MENU_SET bbs_menu; MENU_SET top10_menu; @@ -187,7 +192,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isalnum(*q) || *q == '_' || *q == '-') + while (isalnum((int)*q) || *q == '_' || *q == '-') { q++; } @@ -270,7 +275,7 @@ int load_menu(MENU_SET *p_menu_set, cons else { q = p; - while (isalnum(*q) || *q == '_' || *q == '-') + while (isalnum((int)*q) || *q == '_' || *q == '-') { q++; } @@ -297,7 +302,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -316,7 +321,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -335,7 +340,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -354,7 +359,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -459,7 +464,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -478,7 +483,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -546,7 +551,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -565,7 +570,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -584,7 +589,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isalnum(*q) || *q == '_' || *q == '-') + while (isalnum((int)*q) || *q == '_' || *q == '-') { q++; } @@ -614,7 +619,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -633,7 +638,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -652,7 +657,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -698,7 +703,7 @@ int load_menu(MENU_SET *p_menu_set, cons p_screen = get_menu_screen_by_id(p_menu_set, screen_id); q = p; - while (isalnum(*q) || *q == '_' || *q == '-') + while (isalnum((int)*q) || *q == '_' || *q == '-') { q++; } @@ -1384,7 +1389,7 @@ int unload_menu(MENU_SET *p_menu_set) detach_menu_shm(p_menu_set); - if (shmctl(shmid, IPC_RMID, NULL) == -1) + if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1) { log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno); return -1; @@ -1423,7 +1428,16 @@ int set_menu_shm_readonly(MENU_SET *p_me void *p_shm; // Remap shared memory in read-only mode +#if defined(__CYGWIN__) + if (shmdt(p_menu_set->p_reserved) == -1) + { + log_error("shmdt() error (%d)\n", errno); + return -1; + } + p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY); +#else p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY | SHM_REMAP); +#endif if (p_shm == (void *)-1) { log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno);