--- lbbs/src/menu.c 2025/10/29 05:30:05 1.77 +++ lbbs/src/menu.c 2025/11/18 15:15:18 1.88 @@ -1,18 +1,14 @@ -/*************************************************************************** - menu.c - 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 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * menu + * - configurable user interactive menu feature + * + * Copyright (C) 2004-2025 Leaflet + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "bbs.h" #include "bbs_cmd.h" @@ -32,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 3 +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; @@ -104,24 +101,21 @@ int load_menu(MENU_SET *p_menu_set, cons key = ftok(conf_file, proj_id + retry_cnt); if (key == -1) { - log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id, errno); - return -2; + log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id + retry_cnt, errno); + return -3; } p_menu_set->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600); - if (p_menu_set->shmid == -1) { if (errno != EEXIST || retry_cnt + 1 >= MENU_SHMGET_RETRY_LIMIT) { log_error("shmget(conf_file=%s, size=%d) error (%d) %d times\n", conf_file, size, errno, retry_cnt + 1); - break; + return -3; } -#ifdef _DEBUG log_error("shmget(conf_file=%s, proj_id=%d, key=0x%x, size=%d) error (%d), retry ...\n", conf_file, proj_id + retry_cnt, key, size, errno); -#endif retry_cnt++; } } while (p_menu_set->shmid == -1); @@ -198,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++; } @@ -281,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++; } @@ -308,7 +302,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -327,7 +321,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -346,7 +340,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -365,7 +359,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -470,7 +464,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -489,7 +483,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -557,7 +551,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -576,7 +570,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -595,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++; } @@ -625,7 +619,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -644,7 +638,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -663,7 +657,7 @@ int load_menu(MENU_SET *p_menu_set, cons return -1; } p = q; - while (isdigit(*q)) + while (isdigit((int)*q)) { q++; } @@ -709,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++; } @@ -1395,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; @@ -1431,6 +1425,7 @@ int get_menu_shm_readonly(MENU_SET *p_me int set_menu_shm_readonly(MENU_SET *p_menu_set) { +#ifndef __CYGWIN__ void *p_shm; // Remap shared memory in read-only mode @@ -1442,6 +1437,7 @@ int set_menu_shm_readonly(MENU_SET *p_me } p_menu_set->p_reserved = p_shm; +#endif return 0; }