/[LeafOK_CVS]/lbbs/src/menu.c
ViewVC logotype

Diff of /lbbs/src/menu.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.78 by sysadm, Wed Oct 29 07:36:38 2025 UTC Revision 1.86 by sysadm, Mon Nov 17 12:16:48 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                    menu.c  -  description  /*
3                                                           -------------------   * menu
4          Copyright            : (C) 2004-2025 by Leaflet   *   - configurable user interactive menu feature
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "bbs.h"  #include "bbs.h"
14  #include "bbs_cmd.h"  #include "bbs_cmd.h"
# Line 32  Line 28 
28  #include <sys/ipc.h>  #include <sys/ipc.h>
29  #include <sys/shm.h>  #include <sys/shm.h>
30    
31  #define MENU_SCREEN_PATH_PREFIX "var/MENU_SCR_"  enum _menu_constant_t
32  #define MENU_CONF_DELIM_WITH_SPACE " ,\t\r\n"  {
33  #define MENU_CONF_DELIM_WITHOUT_SPACE "\r\n"          MENU_SET_RESERVED_LENGTH = sizeof(int16_t) * 4,
34            MENU_SHMGET_RETRY_LIMIT = 10,
35  #define MENU_SET_RESERVED_LENGTH (sizeof(int16_t) * 4)  };
36    
37  #define MENU_SHMGET_RETRY_LIMIT 3  static const char MENU_CONF_DELIM_WITH_SPACE[] = " ,\t\r\n";
38    static const char MENU_CONF_DELIM_WITHOUT_SPACE[] = "\r\n";
39    
40  MENU_SET bbs_menu;  MENU_SET bbs_menu;
41  MENU_SET top10_menu;  MENU_SET top10_menu;
# Line 104  int load_menu(MENU_SET *p_menu_set, cons Line 101  int load_menu(MENU_SET *p_menu_set, cons
101                  key = ftok(conf_file, proj_id + retry_cnt);                  key = ftok(conf_file, proj_id + retry_cnt);
102                  if (key == -1)                  if (key == -1)
103                  {                  {
104                          log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id, errno);                          log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id + retry_cnt, errno);
105                          return -2;                          return -3;
106                  }                  }
107    
108                  p_menu_set->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600);                  p_menu_set->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600);
   
109                  if (p_menu_set->shmid == -1)                  if (p_menu_set->shmid == -1)
110                  {                  {
111                          if (errno != EEXIST || retry_cnt + 1 >= MENU_SHMGET_RETRY_LIMIT)                          if (errno != EEXIST || retry_cnt + 1 >= MENU_SHMGET_RETRY_LIMIT)
112                          {                          {
113                                  log_error("shmget(conf_file=%s, size=%d) error (%d) %d times\n",                                  log_error("shmget(conf_file=%s, size=%d) error (%d) %d times\n",
114                                                    conf_file, size, errno, retry_cnt + 1);                                                    conf_file, size, errno, retry_cnt + 1);
115                                  break;                                  return -3;
116                          }                          }
117                          log_error("shmget(conf_file=%s, proj_id=%d, key=0x%x, size=%d) error (%d), retry ...\n",                          log_error("shmget(conf_file=%s, proj_id=%d, key=0x%x, size=%d) error (%d), retry ...\n",
118                                            conf_file, proj_id + retry_cnt, key, size, errno);                                            conf_file, proj_id + retry_cnt, key, size, errno);
# Line 196  int load_menu(MENU_SET *p_menu_set, cons Line 192  int load_menu(MENU_SET *p_menu_set, cons
192                                          return -1;                                          return -1;
193                                  }                                  }
194                                  p = q;                                  p = q;
195                                  while (isalnum(*q) || *q == '_' || *q == '-')                                  while (isalnum((int)*q) || *q == '_' || *q == '-')
196                                  {                                  {
197                                          q++;                                          q++;
198                                  }                                  }
# Line 279  int load_menu(MENU_SET *p_menu_set, cons Line 275  int load_menu(MENU_SET *p_menu_set, cons
275                                                  else                                                  else
276                                                  {                                                  {
277                                                          q = p;                                                          q = p;
278                                                          while (isalnum(*q) || *q == '_' || *q == '-')                                                          while (isalnum((int)*q) || *q == '_' || *q == '-')
279                                                          {                                                          {
280                                                                  q++;                                                                  q++;
281                                                          }                                                          }
# Line 306  int load_menu(MENU_SET *p_menu_set, cons Line 302  int load_menu(MENU_SET *p_menu_set, cons
302                                                          return -1;                                                          return -1;
303                                                  }                                                  }
304                                                  p = q;                                                  p = q;
305                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
306                                                  {                                                  {
307                                                          q++;                                                          q++;
308                                                  }                                                  }
# Line 325  int load_menu(MENU_SET *p_menu_set, cons Line 321  int load_menu(MENU_SET *p_menu_set, cons
321                                                          return -1;                                                          return -1;
322                                                  }                                                  }
323                                                  p = q;                                                  p = q;
324                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
325                                                  {                                                  {
326                                                          q++;                                                          q++;
327                                                  }                                                  }
# Line 344  int load_menu(MENU_SET *p_menu_set, cons Line 340  int load_menu(MENU_SET *p_menu_set, cons
340                                                          return -1;                                                          return -1;
341                                                  }                                                  }
342                                                  p = q;                                                  p = q;
343                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
344                                                  {                                                  {
345                                                          q++;                                                          q++;
346                                                  }                                                  }
# Line 363  int load_menu(MENU_SET *p_menu_set, cons Line 359  int load_menu(MENU_SET *p_menu_set, cons
359                                                          return -1;                                                          return -1;
360                                                  }                                                  }
361                                                  p = q;                                                  p = q;
362                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
363                                                  {                                                  {
364                                                          q++;                                                          q++;
365                                                  }                                                  }
# Line 468  int load_menu(MENU_SET *p_menu_set, cons Line 464  int load_menu(MENU_SET *p_menu_set, cons
464                                                          return -1;                                                          return -1;
465                                                  }                                                  }
466                                                  p = q;                                                  p = q;
467                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
468                                                  {                                                  {
469                                                          q++;                                                          q++;
470                                                  }                                                  }
# Line 487  int load_menu(MENU_SET *p_menu_set, cons Line 483  int load_menu(MENU_SET *p_menu_set, cons
483                                                          return -1;                                                          return -1;
484                                                  }                                                  }
485                                                  p = q;                                                  p = q;
486                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
487                                                  {                                                  {
488                                                          q++;                                                          q++;
489                                                  }                                                  }
# Line 555  int load_menu(MENU_SET *p_menu_set, cons Line 551  int load_menu(MENU_SET *p_menu_set, cons
551                                                          return -1;                                                          return -1;
552                                                  }                                                  }
553                                                  p = q;                                                  p = q;
554                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
555                                                  {                                                  {
556                                                          q++;                                                          q++;
557                                                  }                                                  }
# Line 574  int load_menu(MENU_SET *p_menu_set, cons Line 570  int load_menu(MENU_SET *p_menu_set, cons
570                                                          return -1;                                                          return -1;
571                                                  }                                                  }
572                                                  p = q;                                                  p = q;
573                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
574                                                  {                                                  {
575                                                          q++;                                                          q++;
576                                                  }                                                  }
# Line 593  int load_menu(MENU_SET *p_menu_set, cons Line 589  int load_menu(MENU_SET *p_menu_set, cons
589                                                          return -1;                                                          return -1;
590                                                  }                                                  }
591                                                  p = q;                                                  p = q;
592                                                  while (isalnum(*q) || *q == '_' || *q == '-')                                                  while (isalnum((int)*q) || *q == '_' || *q == '-')
593                                                  {                                                  {
594                                                          q++;                                                          q++;
595                                                  }                                                  }
# Line 623  int load_menu(MENU_SET *p_menu_set, cons Line 619  int load_menu(MENU_SET *p_menu_set, cons
619                                                          return -1;                                                          return -1;
620                                                  }                                                  }
621                                                  p = q;                                                  p = q;
622                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
623                                                  {                                                  {
624                                                          q++;                                                          q++;
625                                                  }                                                  }
# Line 642  int load_menu(MENU_SET *p_menu_set, cons Line 638  int load_menu(MENU_SET *p_menu_set, cons
638                                                          return -1;                                                          return -1;
639                                                  }                                                  }
640                                                  p = q;                                                  p = q;
641                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
642                                                  {                                                  {
643                                                          q++;                                                          q++;
644                                                  }                                                  }
# Line 661  int load_menu(MENU_SET *p_menu_set, cons Line 657  int load_menu(MENU_SET *p_menu_set, cons
657                                                          return -1;                                                          return -1;
658                                                  }                                                  }
659                                                  p = q;                                                  p = q;
660                                                  while (isdigit(*q))                                                  while (isdigit((int)*q))
661                                                  {                                                  {
662                                                          q++;                                                          q++;
663                                                  }                                                  }
# Line 707  int load_menu(MENU_SET *p_menu_set, cons Line 703  int load_menu(MENU_SET *p_menu_set, cons
703                                  p_screen = get_menu_screen_by_id(p_menu_set, screen_id);                                  p_screen = get_menu_screen_by_id(p_menu_set, screen_id);
704    
705                                  q = p;                                  q = p;
706                                  while (isalnum(*q) || *q == '_' || *q == '-')                                  while (isalnum((int)*q) || *q == '_' || *q == '-')
707                                  {                                  {
708                                          q++;                                          q++;
709                                  }                                  }
# Line 1393  int unload_menu(MENU_SET *p_menu_set) Line 1389  int unload_menu(MENU_SET *p_menu_set)
1389    
1390          detach_menu_shm(p_menu_set);          detach_menu_shm(p_menu_set);
1391    
1392          if (shmctl(shmid, IPC_RMID, NULL) == -1)          if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1)
1393          {          {
1394                  log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno);                  log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno);
1395                  return -1;                  return -1;
# Line 1432  int set_menu_shm_readonly(MENU_SET *p_me Line 1428  int set_menu_shm_readonly(MENU_SET *p_me
1428          void *p_shm;          void *p_shm;
1429    
1430          // Remap shared memory in read-only mode          // Remap shared memory in read-only mode
1431    #if defined(__MSYS__) || defined(__MINGW32__)
1432            if (shmdt(p_menu_set->p_reserved) == -1)
1433            {
1434                    log_error("shmdt() error (%d)\n", errno);
1435                    return -1;
1436            }
1437            p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY);
1438    #else
1439          p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY | SHM_REMAP);          p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY | SHM_REMAP);
1440    #endif
1441          if (p_shm == (void *)-1)          if (p_shm == (void *)-1)
1442          {          {
1443                  log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno);                  log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno);


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

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