/[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.88 by sysadm, Tue Nov 18 15:15:18 2025 UTC Revision 1.95 by sysadm, Mon Jan 5 05:41:34 2026 UTC
# Line 3  Line 3 
3   * menu   * menu
4   *   - configurable user interactive menu feature   *   - configurable user interactive menu feature
5   *   *
6   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>   * Copyright (C) 2004-2026  Leaflet <leaflet@leafok.com>
7   */   */
8    
9  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 21  Line 21 
21  #include "user_priv.h"  #include "user_priv.h"
22  #include <ctype.h>  #include <ctype.h>
23  #include <errno.h>  #include <errno.h>
24    #include <fcntl.h>
25  #include <stdio.h>  #include <stdio.h>
26  #include <stdlib.h>  #include <stdlib.h>
27  #include <string.h>  #include <string.h>
28  #include <unistd.h>  #include <unistd.h>
29  #include <sys/ipc.h>  #include <sys/mman.h>
30  #include <sys/shm.h>  #include <sys/stat.h>
31    
32  enum _menu_constant_t  enum _menu_constant_t
33  {  {
34          MENU_SET_RESERVED_LENGTH = sizeof(int16_t) * 4,          MENU_SET_RESERVED_LENGTH = sizeof(int16_t) * 4,
         MENU_SHMGET_RETRY_LIMIT = 10,  
35  };  };
36    
37  static const char MENU_CONF_DELIM_WITH_SPACE[] = " ,\t\r\n";  static const char MENU_CONF_DELIM_WITH_SPACE[] = " ,\t\r\n";
# Line 42  MENU_SET top10_menu; Line 42  MENU_SET top10_menu;
42    
43  int load_menu(MENU_SET *p_menu_set, const char *conf_file)  int load_menu(MENU_SET *p_menu_set, const char *conf_file)
44  {  {
45            char filepath[FILE_PATH_LEN];
46            int fd;
47            size_t size;
48            void *p_shm;
49          FILE *fin;          FILE *fin;
50          int fin_line = 0;          int fin_line = 0;
51          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
# Line 56  int load_menu(MENU_SET *p_menu_set, cons Line 60  int load_menu(MENU_SET *p_menu_set, cons
60          MENU_ID menu_id;          MENU_ID menu_id;
61          MENU_ITEM_ID menu_item_id;          MENU_ITEM_ID menu_item_id;
62          MENU_SCREEN_ID screen_id;          MENU_SCREEN_ID screen_id;
63          int proj_id;  
64          key_t key;          if (p_menu_set == NULL || conf_file == NULL)
65          size_t size;          {
66          int retry_cnt;                  log_error("NULL pointer error");
67                    return -1;
68            }
69    
70          // Initialize the data structure          // Initialize the data structure
71          memset(p_menu_set, 0, sizeof(*p_menu_set));          memset(p_menu_set, 0, sizeof(*p_menu_set));
# Line 68  int load_menu(MENU_SET *p_menu_set, cons Line 74  int load_menu(MENU_SET *p_menu_set, cons
74          p_menu_set->p_menu_name_dict = trie_dict_create();          p_menu_set->p_menu_name_dict = trie_dict_create();
75          if (p_menu_set->p_menu_name_dict == NULL)          if (p_menu_set->p_menu_name_dict == NULL)
76          {          {
77                  log_error("trie_dict_create() error\n");                  log_error("trie_dict_create() error");
78                  return -3;                  return -1;
79          }          }
80    
81          // Use trie_dict to search screen_id by menu screen name          // Use trie_dict to search screen_id by menu screen name
82          p_menu_set->p_menu_screen_dict = trie_dict_create();          p_menu_set->p_menu_screen_dict = trie_dict_create();
83          if (p_menu_set->p_menu_screen_dict == NULL)          if (p_menu_set->p_menu_screen_dict == NULL)
84          {          {
85                  log_error("trie_dict_create() error\n");                  log_error("trie_dict_create() error");
86                  return -3;                  return -1;
87          }          }
88    
89          if ((fin = fopen(conf_file, "r")) == NULL)          if ((fin = fopen(conf_file, "r")) == NULL)
90          {          {
91                  log_error("Open %s failed\n", conf_file);                  log_error("Open %s error: %d", conf_file, errno);
92                  return -2;                  return -2;
93          }          }
94    
# Line 93  int load_menu(MENU_SET *p_menu_set, cons Line 99  int load_menu(MENU_SET *p_menu_set, cons
99                     sizeof(MENU_SCREEN) * MAX_MENUS +                     sizeof(MENU_SCREEN) * MAX_MENUS +
100                     MAX_MENU_SCR_BUF_LENGTH * MAX_MENUS;                     MAX_MENU_SCR_BUF_LENGTH * MAX_MENUS;
101    
102          proj_id = (int)(time(NULL) % getpid());          strncpy(filepath, conf_file, sizeof(filepath) - 1);
103          retry_cnt = 0;          filepath[sizeof(filepath) - 1] = '\0';
104            snprintf(p_menu_set->shm_name, sizeof(p_menu_set->shm_name), "/MENU_SHM_%s", basename(filepath));
105    
106          do          if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT)
107          {          {
108                  key = ftok(conf_file, proj_id + retry_cnt);                  log_error("shm_unlink(%s) error (%d)", p_menu_set->shm_name, errno);
109                  if (key == -1)                  return -2;
110                  {          }
                         log_error("ftok(%s %d) error (%d)\n", conf_file, proj_id + retry_cnt, errno);  
                         return -3;  
                 }  
111    
112                  p_menu_set->shmid = shmget(key, size, IPC_CREAT | IPC_EXCL | 0600);          if ((fd = shm_open(p_menu_set->shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)
113                  if (p_menu_set->shmid == -1)          {
114                  {                  log_error("shm_open(%s) error (%d)", p_menu_set->shm_name, errno);
115                          if (errno != EEXIST || retry_cnt + 1 >= MENU_SHMGET_RETRY_LIMIT)                  return -2;
116                          {          }
117                                  log_error("shmget(conf_file=%s, size=%d) error (%d) %d times\n",          if (ftruncate(fd, (off_t)size) == -1)
118                                                    conf_file, size, errno, retry_cnt + 1);          {
119                                  return -3;                  log_error("ftruncate(size=%d) error (%d)", size, errno);
120                          }                  close(fd);
121                          log_error("shmget(conf_file=%s, proj_id=%d, key=0x%x, size=%d) error (%d), retry ...\n",                  return -2;
122                                            conf_file, proj_id + retry_cnt, key, size, errno);          }
                         retry_cnt++;  
                 }  
         } while (p_menu_set->shmid == -1);  
123    
124          p_menu_set->p_reserved = shmat(p_menu_set->shmid, NULL, 0);          p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L);
125          if (p_menu_set->p_reserved == (void *)-1)          if (p_shm == MAP_FAILED)
126          {          {
127                  log_error("shmat() error (%d)\n", errno);                  log_error("mmap() error (%d)", errno);
128                  return -3;                  close(fd);
129                    return -2;
130          }          }
131    
132            if (close(fd) < 0)
133            {
134                    log_error("close(fd) error (%d)", errno);
135                    return -1;
136            }
137    
138            p_menu_set->shm_size = size;
139            p_menu_set->p_reserved = p_shm;
140    
141          p_menu_set->p_menu_pool = (char *)(p_menu_set->p_reserved) + MENU_SET_RESERVED_LENGTH;          p_menu_set->p_menu_pool = (char *)(p_menu_set->p_reserved) + MENU_SET_RESERVED_LENGTH;
142          p_menu_set->p_menu_item_pool = (char *)(p_menu_set->p_menu_pool) + sizeof(MENU) * MAX_MENUS;          p_menu_set->p_menu_item_pool = (char *)(p_menu_set->p_menu_pool) + sizeof(MENU) * MAX_MENUS;
143          p_menu_set->p_menu_screen_pool = (char *)(p_menu_set->p_menu_item_pool) + sizeof(MENU_ITEM) * MAX_MENUITEMS;          p_menu_set->p_menu_screen_pool = (char *)(p_menu_set->p_menu_item_pool) + sizeof(MENU_ITEM) * MAX_MENUITEMS;
# Line 164  int load_menu(MENU_SET *p_menu_set, cons Line 175  int load_menu(MENU_SET *p_menu_set, cons
175                          {                          {
176                                  if (p_menu != NULL)                                  if (p_menu != NULL)
177                                  {                                  {
178                                          log_error("Incomplete menu definition in menu config line %d\n", fin_line);                                          log_error("Incomplete menu definition in menu config line %d", fin_line);
179                                          return -1;                                          return -1;
180                                  }                                  }
181    
182                                  if (p_menu_set->menu_count >= MAX_MENUS)                                  if (p_menu_set->menu_count >= MAX_MENUS)
183                                  {                                  {
184                                          log_error("Menu count (%d) exceed limit (%d)\n", p_menu_set->menu_count, MAX_MENUS);                                          log_error("Menu count (%d) exceed limit (%d)", p_menu_set->menu_count, MAX_MENUS);
185                                          return -3;                                          return -3;
186                                  }                                  }
187                                  menu_id = (MENU_ID)p_menu_set->menu_count;                                  menu_id = (MENU_ID)p_menu_set->menu_count;
# Line 188  int load_menu(MENU_SET *p_menu_set, cons Line 199  int load_menu(MENU_SET *p_menu_set, cons
199                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
200                                  if (q == NULL)                                  if (q == NULL)
201                                  {                                  {
202                                          log_error("Error menu name in menu config line %d\n", fin_line);                                          log_error("Error menu name in menu config line %d", fin_line);
203                                          return -1;                                          return -1;
204                                  }                                  }
205                                  p = q;                                  p = q;
# Line 198  int load_menu(MENU_SET *p_menu_set, cons Line 209  int load_menu(MENU_SET *p_menu_set, cons
209                                  }                                  }
210                                  if (*q != '\0')                                  if (*q != '\0')
211                                  {                                  {
212                                          log_error("Error menu name in menu config line %d\n", fin_line);                                          log_error("Error menu name in menu config line %d", fin_line);
213                                          return -1;                                          return -1;
214                                  }                                  }
215    
216                                  if (q - p > sizeof(p_menu->name) - 1)                                  if (q - p > sizeof(p_menu->name) - 1)
217                                  {                                  {
218                                          log_error("Too longer menu name in menu config line %d\n", fin_line);                                          log_error("Too longer menu name in menu config line %d", fin_line);
219                                          return -1;                                          return -1;
220                                  }                                  }
221                                  strncpy(p_menu->name, p, sizeof(p_menu->name) - 1);                                  strncpy(p_menu->name, p, sizeof(p_menu->name) - 1);
# Line 212  int load_menu(MENU_SET *p_menu_set, cons Line 223  int load_menu(MENU_SET *p_menu_set, cons
223    
224                                  if (trie_dict_set(p_menu_set->p_menu_name_dict, p_menu->name, (int64_t)menu_id) != 1)                                  if (trie_dict_set(p_menu_set->p_menu_name_dict, p_menu->name, (int64_t)menu_id) != 1)
225                                  {                                  {
226                                          log_error("Error set menu dict [%s]\n", p_menu->name);                                          log_error("Error set menu dict [%s]", p_menu->name);
227                                  }                                  }
228    
229                                  // Check syntax                                  // Check syntax
230                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
231                                  if (q != NULL)                                  if (q != NULL)
232                                  {                                  {
233                                          log_error("Unknown extra content in menu config line %d\n", fin_line);                                          log_error("Unknown extra content in menu config line %d", fin_line);
234                                          return -1;                                          return -1;
235                                  }                                  }
236    
# Line 248  int load_menu(MENU_SET *p_menu_set, cons Line 259  int load_menu(MENU_SET *p_menu_set, cons
259                                                  // BEGIN of menu item                                                  // BEGIN of menu item
260                                                  if (p_menu->item_count >= MAX_ITEMS_PER_MENU)                                                  if (p_menu->item_count >= MAX_ITEMS_PER_MENU)
261                                                  {                                                  {
262                                                          log_error("Menuitem count per menu (%d) exceed limit (%d)\n", p_menu->item_count, MAX_ITEMS_PER_MENU);                                                          log_error("Menuitem count per menu (%d) exceed limit (%d)", p_menu->item_count, MAX_ITEMS_PER_MENU);
263                                                          return -1;                                                          return -1;
264                                                  }                                                  }
265                                                  if (p_menu_set->menu_item_count >= MAX_MENUITEMS)                                                  if (p_menu_set->menu_item_count >= MAX_MENUITEMS)
266                                                  {                                                  {
267                                                          log_error("Menuitem count (%d) exceed limit (%d)\n", p_menu_set->menu_item_count, MAX_MENUITEMS);                                                          log_error("Menuitem count (%d) exceed limit (%d)", p_menu_set->menu_item_count, MAX_MENUITEMS);
268                                                          return -3;                                                          return -3;
269                                                  }                                                  }
270                                                  menu_item_id = (MENU_ITEM_ID)p_menu_set->menu_item_count;                                                  menu_item_id = (MENU_ITEM_ID)p_menu_set->menu_item_count;
# Line 281  int load_menu(MENU_SET *p_menu_set, cons Line 292  int load_menu(MENU_SET *p_menu_set, cons
292                                                          }                                                          }
293                                                          if (*q != '\0')                                                          if (*q != '\0')
294                                                          {                                                          {
295                                                                  log_error("Error menu item action in menu config line %d\n", fin_line);                                                                  log_error("Error menu item action in menu config line %d", fin_line);
296                                                                  return -1;                                                                  return -1;
297                                                          }                                                          }
298                                                  }                                                  }
299    
300                                                  if (q - p > sizeof(p_menu_item->action) - 1)                                                  if (q - p > sizeof(p_menu_item->action) - 1)
301                                                  {                                                  {
302                                                          log_error("Too longer menu action in menu config line %d\n", fin_line);                                                          log_error("Too longer menu action in menu config line %d", fin_line);
303                                                          return -1;                                                          return -1;
304                                                  }                                                  }
305                                                  strncpy(p_menu_item->action, p, sizeof(p_menu_item->action) - 1);                                                  strncpy(p_menu_item->action, p, sizeof(p_menu_item->action) - 1);
# Line 298  int load_menu(MENU_SET *p_menu_set, cons Line 309  int load_menu(MENU_SET *p_menu_set, cons
309                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
310                                                  if (q == NULL)                                                  if (q == NULL)
311                                                  {                                                  {
312                                                          log_error("Error menu item row in menu config line %d\n", fin_line);                                                          log_error("Error menu item row in menu config line %d", fin_line);
313                                                          return -1;                                                          return -1;
314                                                  }                                                  }
315                                                  p = q;                                                  p = q;
# Line 308  int load_menu(MENU_SET *p_menu_set, cons Line 319  int load_menu(MENU_SET *p_menu_set, cons
319                                                  }                                                  }
320                                                  if (*q != '\0')                                                  if (*q != '\0')
321                                                  {                                                  {
322                                                          log_error("Error menu item row in menu config line %d\n", fin_line);                                                          log_error("Error menu item row in menu config line %d", fin_line);
323                                                          return -1;                                                          return -1;
324                                                  }                                                  }
325                                                  p_menu_item->row = (int16_t)atoi(p);                                                  p_menu_item->row = (int16_t)atoi(p);
# Line 317  int load_menu(MENU_SET *p_menu_set, cons Line 328  int load_menu(MENU_SET *p_menu_set, cons
328                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
329                                                  if (q == NULL)                                                  if (q == NULL)
330                                                  {                                                  {
331                                                          log_error("Error menu item col in menu config line %d\n", fin_line);                                                          log_error("Error menu item col in menu config line %d", fin_line);
332                                                          return -1;                                                          return -1;
333                                                  }                                                  }
334                                                  p = q;                                                  p = q;
# Line 327  int load_menu(MENU_SET *p_menu_set, cons Line 338  int load_menu(MENU_SET *p_menu_set, cons
338                                                  }                                                  }
339                                                  if (*q != '\0')                                                  if (*q != '\0')
340                                                  {                                                  {
341                                                          log_error("Error menu item col in menu config line %d\n", fin_line);                                                          log_error("Error menu item col in menu config line %d", fin_line);
342                                                          return -1;                                                          return -1;
343                                                  }                                                  }
344                                                  p_menu_item->col = (int16_t)atoi(p);                                                  p_menu_item->col = (int16_t)atoi(p);
# Line 336  int load_menu(MENU_SET *p_menu_set, cons Line 347  int load_menu(MENU_SET *p_menu_set, cons
347                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
348                                                  if (q == NULL)                                                  if (q == NULL)
349                                                  {                                                  {
350                                                          log_error("Error menu item priv in menu config line %d\n", fin_line);                                                          log_error("Error menu item priv in menu config line %d", fin_line);
351                                                          return -1;                                                          return -1;
352                                                  }                                                  }
353                                                  p = q;                                                  p = q;
# Line 346  int load_menu(MENU_SET *p_menu_set, cons Line 357  int load_menu(MENU_SET *p_menu_set, cons
357                                                  }                                                  }
358                                                  if (*q != '\0')                                                  if (*q != '\0')
359                                                  {                                                  {
360                                                          log_error("Error menu item priv in menu config line %d\n", fin_line);                                                          log_error("Error menu item priv in menu config line %d", fin_line);
361                                                          return -1;                                                          return -1;
362                                                  }                                                  }
363                                                  p_menu_item->priv = atoi(p);                                                  p_menu_item->priv = atoi(p);
# Line 355  int load_menu(MENU_SET *p_menu_set, cons Line 366  int load_menu(MENU_SET *p_menu_set, cons
366                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
367                                                  if (q == NULL)                                                  if (q == NULL)
368                                                  {                                                  {
369                                                          log_error("Error menu item level in menu config line %d\n", fin_line);                                                          log_error("Error menu item level in menu config line %d", fin_line);
370                                                          return -1;                                                          return -1;
371                                                  }                                                  }
372                                                  p = q;                                                  p = q;
# Line 365  int load_menu(MENU_SET *p_menu_set, cons Line 376  int load_menu(MENU_SET *p_menu_set, cons
376                                                  }                                                  }
377                                                  if (*q != '\0')                                                  if (*q != '\0')
378                                                  {                                                  {
379                                                          log_error("Error menu item level in menu config line %d\n", fin_line);                                                          log_error("Error menu item level in menu config line %d", fin_line);
380                                                          return -1;                                                          return -1;
381                                                  }                                                  }
382                                                  p_menu_item->level = atoi(p);                                                  p_menu_item->level = atoi(p);
# Line 374  int load_menu(MENU_SET *p_menu_set, cons Line 385  int load_menu(MENU_SET *p_menu_set, cons
385                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
386                                                  if (q == NULL || *q != '\"')                                                  if (q == NULL || *q != '\"')
387                                                  {                                                  {
388                                                          log_error("Error menu item name in menu config line %d\n", fin_line);                                                          log_error("Error menu item name in menu config line %d", fin_line);
389                                                          return -1;                                                          return -1;
390                                                  }                                                  }
391                                                  q++;                                                  q++;
# Line 394  int load_menu(MENU_SET *p_menu_set, cons Line 405  int load_menu(MENU_SET *p_menu_set, cons
405                                                  }                                                  }
406                                                  if (*q != '\"' || *(q + 1) != '\0')                                                  if (*q != '\"' || *(q + 1) != '\0')
407                                                  {                                                  {
408                                                          log_error("Error menu item name in menu config line %d\n", fin_line);                                                          log_error("Error menu item name in menu config line %d", fin_line);
409                                                          return -1;                                                          return -1;
410                                                  }                                                  }
411                                                  *q = '\0';                                                  *q = '\0';
412    
413                                                  if (q - p > sizeof(p_menu_item->name) - 1)                                                  if (q - p > sizeof(p_menu_item->name) - 1)
414                                                  {                                                  {
415                                                          log_error("Too longer menu name in menu config line %d\n", fin_line);                                                          log_error("Too longer menu name in menu config line %d", fin_line);
416                                                          return -1;                                                          return -1;
417                                                  }                                                  }
418                                                  strncpy(p_menu_item->name, p, sizeof(p_menu_item->name) - 1);                                                  strncpy(p_menu_item->name, p, sizeof(p_menu_item->name) - 1);
# Line 411  int load_menu(MENU_SET *p_menu_set, cons Line 422  int load_menu(MENU_SET *p_menu_set, cons
422                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);
423                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)
424                                                  {                                                  {
425                                                          log_error("Error menu item text in menu config line %d\n", fin_line);                                                          log_error("Error menu item text in menu config line %d", fin_line);
426                                                          return -1;                                                          return -1;
427                                                  }                                                  }
428                                                  q++;                                                  q++;
# Line 431  int load_menu(MENU_SET *p_menu_set, cons Line 442  int load_menu(MENU_SET *p_menu_set, cons
442                                                  }                                                  }
443                                                  if (*q != '\"')                                                  if (*q != '\"')
444                                                  {                                                  {
445                                                          log_error("Error menu item text in menu config line %d\n", fin_line);                                                          log_error("Error menu item text in menu config line %d", fin_line);
446                                                          return -1;                                                          return -1;
447                                                  }                                                  }
448                                                  *q = '\0';                                                  *q = '\0';
449    
450                                                  if (q - p > sizeof(p_menu_item->text) - 1)                                                  if (q - p > sizeof(p_menu_item->text) - 1)
451                                                  {                                                  {
452                                                          log_error("Too longer menu item text in menu config line %d\n", fin_line);                                                          log_error("Too longer menu item text in menu config line %d", fin_line);
453                                                          return -1;                                                          return -1;
454                                                  }                                                  }
455                                                  strncpy(p_menu_item->text, p, sizeof(p_menu_item->text) - 1);                                                  strncpy(p_menu_item->text, p, sizeof(p_menu_item->text) - 1);
# Line 448  int load_menu(MENU_SET *p_menu_set, cons Line 459  int load_menu(MENU_SET *p_menu_set, cons
459                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
460                                                  if (q != NULL)                                                  if (q != NULL)
461                                                  {                                                  {
462                                                          log_error("Unknown extra content in menu config line %d\n", fin_line);                                                          log_error("Unknown extra content in menu config line %d", fin_line);
463                                                          return -1;                                                          return -1;
464                                                  }                                                  }
465                                          }                                          }
# Line 460  int load_menu(MENU_SET *p_menu_set, cons Line 471  int load_menu(MENU_SET *p_menu_set, cons
471                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
472                                                  if (q == NULL)                                                  if (q == NULL)
473                                                  {                                                  {
474                                                          log_error("Error menu title row in menu config line %d\n", fin_line);                                                          log_error("Error menu title row in menu config line %d", fin_line);
475                                                          return -1;                                                          return -1;
476                                                  }                                                  }
477                                                  p = q;                                                  p = q;
# Line 470  int load_menu(MENU_SET *p_menu_set, cons Line 481  int load_menu(MENU_SET *p_menu_set, cons
481                                                  }                                                  }
482                                                  if (*q != '\0')                                                  if (*q != '\0')
483                                                  {                                                  {
484                                                          log_error("Error menu title row in menu config line %d\n", fin_line);                                                          log_error("Error menu title row in menu config line %d", fin_line);
485                                                          return -1;                                                          return -1;
486                                                  }                                                  }
487                                                  p_menu->title.row = (int16_t)atoi(p);                                                  p_menu->title.row = (int16_t)atoi(p);
# Line 479  int load_menu(MENU_SET *p_menu_set, cons Line 490  int load_menu(MENU_SET *p_menu_set, cons
490                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
491                                                  if (q == NULL)                                                  if (q == NULL)
492                                                  {                                                  {
493                                                          log_error("Error menu title col in menu config line %d\n", fin_line);                                                          log_error("Error menu title col in menu config line %d", fin_line);
494                                                          return -1;                                                          return -1;
495                                                  }                                                  }
496                                                  p = q;                                                  p = q;
# Line 489  int load_menu(MENU_SET *p_menu_set, cons Line 500  int load_menu(MENU_SET *p_menu_set, cons
500                                                  }                                                  }
501                                                  if (*q != '\0')                                                  if (*q != '\0')
502                                                  {                                                  {
503                                                          log_error("Error menu title col in menu config line %d\n", fin_line);                                                          log_error("Error menu title col in menu config line %d", fin_line);
504                                                          return -1;                                                          return -1;
505                                                  }                                                  }
506                                                  p_menu->title.col = (int16_t)atoi(p);                                                  p_menu->title.col = (int16_t)atoi(p);
# Line 498  int load_menu(MENU_SET *p_menu_set, cons Line 509  int load_menu(MENU_SET *p_menu_set, cons
509                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);
510                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)
511                                                  {                                                  {
512                                                          log_error("Error menu title text in menu config line %d\n", fin_line);                                                          log_error("Error menu title text in menu config line %d", fin_line);
513                                                          return -1;                                                          return -1;
514                                                  }                                                  }
515                                                  q++;                                                  q++;
# Line 518  int load_menu(MENU_SET *p_menu_set, cons Line 529  int load_menu(MENU_SET *p_menu_set, cons
529                                                  }                                                  }
530                                                  if (*q != '\"')                                                  if (*q != '\"')
531                                                  {                                                  {
532                                                          log_error("Error menu title text in menu config line %d\n", fin_line);                                                          log_error("Error menu title text in menu config line %d", fin_line);
533                                                          return -1;                                                          return -1;
534                                                  }                                                  }
535                                                  *q = '\0';                                                  *q = '\0';
536    
537                                                  if (q - p > sizeof(p_menu->title.text) - 1)                                                  if (q - p > sizeof(p_menu->title.text) - 1)
538                                                  {                                                  {
539                                                          log_error("Too longer menu title text in menu config line %d\n", fin_line);                                                          log_error("Too longer menu title text in menu config line %d", fin_line);
540                                                          return -1;                                                          return -1;
541                                                  }                                                  }
542                                                  strncpy(p_menu->title.text, p, sizeof(p_menu->title.text) - 1);                                                  strncpy(p_menu->title.text, p, sizeof(p_menu->title.text) - 1);
# Line 535  int load_menu(MENU_SET *p_menu_set, cons Line 546  int load_menu(MENU_SET *p_menu_set, cons
546                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
547                                                  if (q != NULL)                                                  if (q != NULL)
548                                                  {                                                  {
549                                                          log_error("Unknown extra content in menu config line %d\n", fin_line);                                                          log_error("Unknown extra content in menu config line %d", fin_line);
550                                                          return -1;                                                          return -1;
551                                                  }                                                  }
552                                          }                                          }
# Line 547  int load_menu(MENU_SET *p_menu_set, cons Line 558  int load_menu(MENU_SET *p_menu_set, cons
558                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
559                                                  if (q == NULL)                                                  if (q == NULL)
560                                                  {                                                  {
561                                                          log_error("Error menu screen row in menu config line %d\n", fin_line);                                                          log_error("Error menu screen row in menu config line %d", fin_line);
562                                                          return -1;                                                          return -1;
563                                                  }                                                  }
564                                                  p = q;                                                  p = q;
# Line 557  int load_menu(MENU_SET *p_menu_set, cons Line 568  int load_menu(MENU_SET *p_menu_set, cons
568                                                  }                                                  }
569                                                  if (*q != '\0')                                                  if (*q != '\0')
570                                                  {                                                  {
571                                                          log_error("Error menu screen row in menu config line %d\n", fin_line);                                                          log_error("Error menu screen row in menu config line %d", fin_line);
572                                                          return -1;                                                          return -1;
573                                                  }                                                  }
574                                                  p_menu->screen_row = (int16_t)atoi(p);                                                  p_menu->screen_row = (int16_t)atoi(p);
# Line 566  int load_menu(MENU_SET *p_menu_set, cons Line 577  int load_menu(MENU_SET *p_menu_set, cons
577                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
578                                                  if (q == NULL)                                                  if (q == NULL)
579                                                  {                                                  {
580                                                          log_error("Error menu screen col in menu config line %d\n", fin_line);                                                          log_error("Error menu screen col in menu config line %d", fin_line);
581                                                          return -1;                                                          return -1;
582                                                  }                                                  }
583                                                  p = q;                                                  p = q;
# Line 576  int load_menu(MENU_SET *p_menu_set, cons Line 587  int load_menu(MENU_SET *p_menu_set, cons
587                                                  }                                                  }
588                                                  if (*q != '\0')                                                  if (*q != '\0')
589                                                  {                                                  {
590                                                          log_error("Error menu screen col in menu config line %d\n", fin_line);                                                          log_error("Error menu screen col in menu config line %d", fin_line);
591                                                          return -1;                                                          return -1;
592                                                  }                                                  }
593                                                  p_menu->screen_col = (int16_t)atoi(p);                                                  p_menu->screen_col = (int16_t)atoi(p);
# Line 585  int load_menu(MENU_SET *p_menu_set, cons Line 596  int load_menu(MENU_SET *p_menu_set, cons
596                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
597                                                  if (q == NULL)                                                  if (q == NULL)
598                                                  {                                                  {
599                                                          log_error("Error menu screen name in menu config line %d\n", fin_line);                                                          log_error("Error menu screen name in menu config line %d", fin_line);
600                                                          return -1;                                                          return -1;
601                                                  }                                                  }
602                                                  p = q;                                                  p = q;
# Line 595  int load_menu(MENU_SET *p_menu_set, cons Line 606  int load_menu(MENU_SET *p_menu_set, cons
606                                                  }                                                  }
607                                                  if (*q != '\0')                                                  if (*q != '\0')
608                                                  {                                                  {
609                                                          log_error("Error menu screen name in menu config line %d\n", fin_line);                                                          log_error("Error menu screen name in menu config line %d", fin_line);
610                                                          return -1;                                                          return -1;
611                                                  }                                                  }
612                                                  strncpy(p_menu->screen_name, p, sizeof(p_menu->screen_name) - 1);                                                  strncpy(p_menu->screen_name, p, sizeof(p_menu->screen_name) - 1);
# Line 605  int load_menu(MENU_SET *p_menu_set, cons Line 616  int load_menu(MENU_SET *p_menu_set, cons
616                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
617                                                  if (q != NULL)                                                  if (q != NULL)
618                                                  {                                                  {
619                                                          log_error("Unknown extra content in menu config line %d\n", fin_line);                                                          log_error("Unknown extra content in menu config line %d", fin_line);
620                                                          return -1;                                                          return -1;
621                                                  }                                                  }
622                                          }                                          }
# Line 615  int load_menu(MENU_SET *p_menu_set, cons Line 626  int load_menu(MENU_SET *p_menu_set, cons
626                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
627                                                  if (q == NULL)                                                  if (q == NULL)
628                                                  {                                                  {
629                                                          log_error("Error menu page row in menu config line %d\n", fin_line);                                                          log_error("Error menu page row in menu config line %d", fin_line);
630                                                          return -1;                                                          return -1;
631                                                  }                                                  }
632                                                  p = q;                                                  p = q;
# Line 625  int load_menu(MENU_SET *p_menu_set, cons Line 636  int load_menu(MENU_SET *p_menu_set, cons
636                                                  }                                                  }
637                                                  if (*q != '\0')                                                  if (*q != '\0')
638                                                  {                                                  {
639                                                          log_error("Error menu page row in menu config line %d\n", fin_line);                                                          log_error("Error menu page row in menu config line %d", fin_line);
640                                                          return -1;                                                          return -1;
641                                                  }                                                  }
642                                                  p_menu->page_row = (int16_t)atoi(p);                                                  p_menu->page_row = (int16_t)atoi(p);
# Line 634  int load_menu(MENU_SET *p_menu_set, cons Line 645  int load_menu(MENU_SET *p_menu_set, cons
645                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
646                                                  if (q == NULL)                                                  if (q == NULL)
647                                                  {                                                  {
648                                                          log_error("Error menu page col in menu config line %d\n", fin_line);                                                          log_error("Error menu page col in menu config line %d", fin_line);
649                                                          return -1;                                                          return -1;
650                                                  }                                                  }
651                                                  p = q;                                                  p = q;
# Line 644  int load_menu(MENU_SET *p_menu_set, cons Line 655  int load_menu(MENU_SET *p_menu_set, cons
655                                                  }                                                  }
656                                                  if (*q != '\0')                                                  if (*q != '\0')
657                                                  {                                                  {
658                                                          log_error("Error menu page col in menu config line %d\n", fin_line);                                                          log_error("Error menu page col in menu config line %d", fin_line);
659                                                          return -1;                                                          return -1;
660                                                  }                                                  }
661                                                  p_menu->page_col = (int16_t)atoi(p);                                                  p_menu->page_col = (int16_t)atoi(p);
# Line 653  int load_menu(MENU_SET *p_menu_set, cons Line 664  int load_menu(MENU_SET *p_menu_set, cons
664                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
665                                                  if (q == NULL)                                                  if (q == NULL)
666                                                  {                                                  {
667                                                          log_error("Error menu page item limit in menu config line %d\n", fin_line);                                                          log_error("Error menu page item limit in menu config line %d", fin_line);
668                                                          return -1;                                                          return -1;
669                                                  }                                                  }
670                                                  p = q;                                                  p = q;
# Line 663  int load_menu(MENU_SET *p_menu_set, cons Line 674  int load_menu(MENU_SET *p_menu_set, cons
674                                                  }                                                  }
675                                                  if (*q != '\0')                                                  if (*q != '\0')
676                                                  {                                                  {
677                                                          log_error("Error menu page item limit in menu config line %d\n", fin_line);                                                          log_error("Error menu page item limit in menu config line %d", fin_line);
678                                                          return -1;                                                          return -1;
679                                                  }                                                  }
680                                                  p_menu->page_item_limit = (int16_t)atoi(p);                                                  p_menu->page_item_limit = (int16_t)atoi(p);
# Line 672  int load_menu(MENU_SET *p_menu_set, cons Line 683  int load_menu(MENU_SET *p_menu_set, cons
683                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
684                                                  if (q != NULL)                                                  if (q != NULL)
685                                                  {                                                  {
686                                                          log_error("Unknown extra content in menu config line %d\n", fin_line);                                                          log_error("Unknown extra content in menu config line %d", fin_line);
687                                                          return -1;                                                          return -1;
688                                                  }                                                  }
689                                          }                                          }
# Line 684  int load_menu(MENU_SET *p_menu_set, cons Line 695  int load_menu(MENU_SET *p_menu_set, cons
695                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
696                                                  if (q != NULL)                                                  if (q != NULL)
697                                                  {                                                  {
698                                                          log_error("Unknown extra content in menu config line %d\n", fin_line);                                                          log_error("Unknown extra content in menu config line %d", fin_line);
699                                                          return -1;                                                          return -1;
700                                                  }                                                  }
701                                          }                                          }
# Line 694  int load_menu(MENU_SET *p_menu_set, cons Line 705  int load_menu(MENU_SET *p_menu_set, cons
705                          {                          {
706                                  if (p_menu_set->menu_item_count >= MAX_MENUS)                                  if (p_menu_set->menu_item_count >= MAX_MENUS)
707                                  {                                  {
708                                          log_error("Menu screen count (%d) exceed limit (%d)\n", p_menu_set->menu_screen_count, MAX_MENUS);                                          log_error("Menu screen count (%d) exceed limit (%d)", p_menu_set->menu_screen_count, MAX_MENUS);
709                                          return -3;                                          return -3;
710                                  }                                  }
711                                  screen_id = (MENU_SCREEN_ID)p_menu_set->menu_screen_count;                                  screen_id = (MENU_SCREEN_ID)p_menu_set->menu_screen_count;
# Line 709  int load_menu(MENU_SET *p_menu_set, cons Line 720  int load_menu(MENU_SET *p_menu_set, cons
720                                  }                                  }
721                                  if (*q != '\0')                                  if (*q != '\0')
722                                  {                                  {
723                                          log_error("Error menu screen name in menu config line %d\n", fin_line);                                          log_error("Error menu screen name in menu config line %d", fin_line);
724                                          return -1;                                          return -1;
725                                  }                                  }
726                                  strncpy(p_screen->name, p, sizeof(p_screen->name) - 1);                                  strncpy(p_screen->name, p, sizeof(p_screen->name) - 1);
# Line 717  int load_menu(MENU_SET *p_menu_set, cons Line 728  int load_menu(MENU_SET *p_menu_set, cons
728    
729                                  if (trie_dict_set(p_menu_set->p_menu_screen_dict, p_screen->name, (int64_t)screen_id) != 1)                                  if (trie_dict_set(p_menu_set->p_menu_screen_dict, p_screen->name, (int64_t)screen_id) != 1)
730                                  {                                  {
731                                          log_error("Error set menu screen dict [%s]\n", p_screen->name);                                          log_error("Error set menu screen dict [%s]", p_screen->name);
732                                  }                                  }
733    
734                                  // Check syntax                                  // Check syntax
735                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
736                                  if (q != NULL)                                  if (q != NULL)
737                                  {                                  {
738                                          log_error("Unknown extra content in menu config line %d\n", fin_line);                                          log_error("Unknown extra content in menu config line %d", fin_line);
739                                          return -1;                                          return -1;
740                                  }                                  }
741    
# Line 745  int load_menu(MENU_SET *p_menu_set, cons Line 756  int load_menu(MENU_SET *p_menu_set, cons
756                                          {                                          {
757                                                  if (p_menu_set->p_menu_screen_buf_free + 1 > q)                                                  if (p_menu_set->p_menu_screen_buf_free + 1 > q)
758                                                  {                                                  {
759                                                          log_error("Menu screen buffer depleted (%p + 1 > %p)\n", p_menu_set->p_menu_screen_buf_free, q);                                                          log_error("Menu screen buffer depleted (%p + 1 > %p)", p_menu_set->p_menu_screen_buf_free, q);
760                                                          return -3;                                                          return -3;
761                                                  }                                                  }
762    
# Line 758  int load_menu(MENU_SET *p_menu_set, cons Line 769  int load_menu(MENU_SET *p_menu_set, cons
769                                          // Clear line                                          // Clear line
770                                          if (p_menu_set->p_menu_screen_buf_free + strlen(CTRL_SEQ_CLR_LINE) > q)                                          if (p_menu_set->p_menu_screen_buf_free + strlen(CTRL_SEQ_CLR_LINE) > q)
771                                          {                                          {
772                                                  log_error("Menu screen buffer depleted (%p + %d > %p)\n", p_menu_set->p_menu_screen_buf_free, q, strlen(CTRL_SEQ_CLR_LINE));                                                  log_error("Menu screen buffer depleted (%p + %d > %p)", p_menu_set->p_menu_screen_buf_free, q, strlen(CTRL_SEQ_CLR_LINE));
773                                                  return -3;                                                  return -3;
774                                          }                                          }
775                                          p_menu_set->p_menu_screen_buf_free = stpcpy(p_menu_set->p_menu_screen_buf_free, CTRL_SEQ_CLR_LINE);                                          p_menu_set->p_menu_screen_buf_free = stpcpy(p_menu_set->p_menu_screen_buf_free, CTRL_SEQ_CLR_LINE);
# Line 768  int load_menu(MENU_SET *p_menu_set, cons Line 779  int load_menu(MENU_SET *p_menu_set, cons
779                                          {                                          {
780                                                  if (p_menu_set->p_menu_screen_buf_free + 2 > q)                                                  if (p_menu_set->p_menu_screen_buf_free + 2 > q)
781                                                  {                                                  {
782                                                          log_error("Menu screen buffer depleted (%p + 2 > %p)\n", p_menu_set->p_menu_screen_buf_free, q);                                                          log_error("Menu screen buffer depleted (%p + 2 > %p)", p_menu_set->p_menu_screen_buf_free, q);
783                                                          return -3;                                                          return -3;
784                                                  }                                                  }
785    
# Line 786  int load_menu(MENU_SET *p_menu_set, cons Line 797  int load_menu(MENU_SET *p_menu_set, cons
797    
798                                  if (p_screen->buf_length == -1)                                  if (p_screen->buf_length == -1)
799                                  {                                  {
800                                          log_error("End of menu screen [%s] not found\n", p_screen->name);                                          log_error("End of menu screen [%s] not found", p_screen->name);
801                                  }                                  }
802                          }                          }
803                  }                  }
804                  else // Invalid prefix                  else // Invalid prefix
805                  {                  {
806                          log_error("Error in menu config line %d\n", fin_line);                          log_error("Error in menu config line %d", fin_line);
807                          return -1;                          return -1;
808                  }                  }
809          }          }
# Line 804  int load_menu(MENU_SET *p_menu_set, cons Line 815  int load_menu(MENU_SET *p_menu_set, cons
815    
816                  if (trie_dict_get(p_menu_set->p_menu_screen_dict, p_menu->screen_name, (int64_t *)(&(p_menu->screen_id))) != 1)                  if (trie_dict_get(p_menu_set->p_menu_screen_dict, p_menu->screen_name, (int64_t *)(&(p_menu->screen_id))) != 1)
817                  {                  {
818                          log_error("Undefined menu screen [%s]\n", p);                          log_error("Undefined menu screen [%s]", p);
819                          return -1;                          return -1;
820                  }                  }
821    
# Line 813  int load_menu(MENU_SET *p_menu_set, cons Line 824  int load_menu(MENU_SET *p_menu_set, cons
824                  {                  {
825                          if ((p_menu->filter_handler = get_cmd_handler(p_menu->name)) == NULL)                          if ((p_menu->filter_handler = get_cmd_handler(p_menu->name)) == NULL)
826                          {                          {
827                                  log_error("Undefined menu filter handler [%s]\n", p_menu->name);                                  log_error("Undefined menu filter handler [%s]", p_menu->name);
828                                  return -1;                                  return -1;
829                          }                          }
830                  }                  }
# Line 828  int load_menu(MENU_SET *p_menu_set, cons Line 839  int load_menu(MENU_SET *p_menu_set, cons
839                  {                  {
840                          if ((p_menu_item->action_cmd_handler = get_cmd_handler(p_menu_item->action)) == NULL)                          if ((p_menu_item->action_cmd_handler = get_cmd_handler(p_menu_item->action)) == NULL)
841                          {                          {
842                                  log_error("Undefined menu action cmd handler [%s]\n", p_menu_item->action);                                  log_error("Undefined menu action cmd handler [%s]", p_menu_item->action);
843                                  return -1;                                  return -1;
844                          }                          }
845                  }                  }
# Line 837  int load_menu(MENU_SET *p_menu_set, cons Line 848  int load_menu(MENU_SET *p_menu_set, cons
848                  {                  {
849                          if (trie_dict_get(p_menu_set->p_menu_name_dict, p_menu_item->action, (int64_t *)&menu_id) != 1)                          if (trie_dict_get(p_menu_set->p_menu_name_dict, p_menu_item->action, (int64_t *)&menu_id) != 1)
850                          {                          {
851                                  log_error("Undefined sub menu id [%s]\n", p_menu_item->action);                                  log_error("Undefined sub menu id [%s]", p_menu_item->action);
852                                  return -1;                                  return -1;
853                          }                          }
854                          p_menu_item->action_menu_id = menu_id;                          p_menu_item->action_menu_id = menu_id;
# Line 864  int display_menu_cursor(MENU_SET *p_menu Line 875  int display_menu_cursor(MENU_SET *p_menu
875          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
876          if (p_menu == NULL)          if (p_menu == NULL)
877          {          {
878                  log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id);                  log_error("get_menu_by_id(%d) return NULL pointer", menu_id);
879                  return -1;                  return -1;
880          }          }
881    
# Line 873  int display_menu_cursor(MENU_SET *p_menu Line 884  int display_menu_cursor(MENU_SET *p_menu
884          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
885          if (p_menu_item == NULL)          if (p_menu_item == NULL)
886          {          {
887                  log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                  log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
888                  return -1;                  return -1;
889          }          }
890    
# Line 899  static int display_menu_current_page(MEN Line 910  static int display_menu_current_page(MEN
910          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
911          if (p_menu == NULL)          if (p_menu == NULL)
912          {          {
913                  log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id);                  log_error("get_menu_by_id(%d) return NULL pointer", menu_id);
914                  return -1;                  return -1;
915          }          }
916    
# Line 923  static int display_menu_current_page(MEN Line 934  static int display_menu_current_page(MEN
934                  p_menu_screen = get_menu_screen_by_id(p_menu_set, p_menu->screen_id);                  p_menu_screen = get_menu_screen_by_id(p_menu_set, p_menu->screen_id);
935                  if (p_menu_screen == NULL)                  if (p_menu_screen == NULL)
936                  {                  {
937                          log_error("get_menu_screen_by_id(%d) return NULL pointer\n", p_menu->screen_id);                          log_error("get_menu_screen_by_id(%d) return NULL pointer", p_menu->screen_id);
938                          return -1;                          return -1;
939                  }                  }
940    
# Line 995  int display_menu(MENU_SET *p_menu_set) Line 1006  int display_menu(MENU_SET *p_menu_set)
1006          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
1007          if (p_menu == NULL)          if (p_menu == NULL)
1008          {          {
1009                  log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id);                  log_error("get_menu_by_id(%d) return NULL pointer", menu_id);
1010                  if (p_menu_set->choose_step > 0)                  if (p_menu_set->choose_step > 0)
1011                  {                  {
1012                          p_menu_set->choose_step--;                          p_menu_set->choose_step--;
# Line 1018  int display_menu(MENU_SET *p_menu_set) Line 1029  int display_menu(MENU_SET *p_menu_set)
1029          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1030          if (p_menu_item == NULL)          if (p_menu_item == NULL)
1031          {          {
1032                  log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                  log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1033                  return EXITMENU;                  return EXITMENU;
1034          }          }
1035    
# Line 1111  int menu_control(MENU_SET *p_menu_set, i Line 1122  int menu_control(MENU_SET *p_menu_set, i
1122    
1123          if (p_menu_set->menu_count == 0)          if (p_menu_set->menu_count == 0)
1124          {          {
1125                  log_error("Empty menu set\n");                  log_error("Empty menu set");
1126                  return EXITBBS;                  return EXITBBS;
1127          }          }
1128    
# Line 1119  int menu_control(MENU_SET *p_menu_set, i Line 1130  int menu_control(MENU_SET *p_menu_set, i
1130          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
1131          if (p_menu == NULL)          if (p_menu == NULL)
1132          {          {
1133                  log_error("get_menu_by_id(%d) return NULL pointer\n", menu_id);                  log_error("get_menu_by_id(%d) return NULL pointer", menu_id);
1134                  if (p_menu_set->choose_step > 0)                  if (p_menu_set->choose_step > 0)
1135                  {                  {
1136                          p_menu_set->choose_step--;                          p_menu_set->choose_step--;
# Line 1130  int menu_control(MENU_SET *p_menu_set, i Line 1141  int menu_control(MENU_SET *p_menu_set, i
1141    
1142          if (p_menu->item_count == 0)          if (p_menu->item_count == 0)
1143          {          {
1144  #ifdef _DEBUG                  log_debug("Empty menu (%s)", p_menu->name);
                 log_error("Empty menu (%s)\n", p_menu->name);  
 #endif  
1145                  if (p_menu_set->choose_step > 0)                  if (p_menu_set->choose_step > 0)
1146                  {                  {
1147                          p_menu_set->choose_step--;                          p_menu_set->choose_step--;
# Line 1148  int menu_control(MENU_SET *p_menu_set, i Line 1157  int menu_control(MENU_SET *p_menu_set, i
1157          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1158          if (p_menu_item == NULL)          if (p_menu_item == NULL)
1159          {          {
1160                  log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                  log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1161                  p_menu_set->menu_item_pos[p_menu_set->choose_step] = 0;                  p_menu_set->menu_item_pos[p_menu_set->choose_step] = 0;
1162                  return REDRAW;                  return REDRAW;
1163          }          }
# Line 1199  int menu_control(MENU_SET *p_menu_set, i Line 1208  int menu_control(MENU_SET *p_menu_set, i
1208                                  p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);                                  p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1209                                  if (p_menu_item == NULL)                                  if (p_menu_item == NULL)
1210                                  {                                  {
1211                                          log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                                          log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1212                                          return -1;                                          return -1;
1213                                  }                                  }
1214    
# Line 1232  int menu_control(MENU_SET *p_menu_set, i Line 1241  int menu_control(MENU_SET *p_menu_set, i
1241                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1242                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1243                          {                          {
1244                                  log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                                  log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1245                                  return -1;                                  return -1;
1246                          }                          }
1247                          if (require_page_change && p_menu_set->menu_item_page_id[menu_item_pos] != page_id)                          if (require_page_change && p_menu_set->menu_item_page_id[menu_item_pos] != page_id)
# Line 1263  int menu_control(MENU_SET *p_menu_set, i Line 1272  int menu_control(MENU_SET *p_menu_set, i
1272                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1273                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1274                          {                          {
1275                                  log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                                  log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1276                                  return -1;                                  return -1;
1277                          }                          }
1278                          if (require_page_change && p_menu_set->menu_item_page_id[menu_item_pos] != page_id)                          if (require_page_change && p_menu_set->menu_item_page_id[menu_item_pos] != page_id)
# Line 1287  int menu_control(MENU_SET *p_menu_set, i Line 1296  int menu_control(MENU_SET *p_menu_set, i
1296                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1297                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1298                          {                          {
1299                                  log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                                  log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1300                                  return -1;                                  return -1;
1301                          }                          }
1302    
# Line 1314  int menu_control(MENU_SET *p_menu_set, i Line 1323  int menu_control(MENU_SET *p_menu_set, i
1323                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);                          p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1324                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1325                          {                          {
1326                                  log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                                  log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1327                                  return -1;                                  return -1;
1328                          }                          }
1329    
# Line 1341  int menu_control(MENU_SET *p_menu_set, i Line 1350  int menu_control(MENU_SET *p_menu_set, i
1350                                  p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);                                  p_menu_item = get_menu_item_by_id(p_menu_set, menu_item_id);
1351                                  if (p_menu_item == NULL)                                  if (p_menu_item == NULL)
1352                                  {                                  {
1353                                          log_error("get_menu_item_by_id(%d) return NULL pointer\n", menu_item_id);                                          log_error("get_menu_item_by_id(%d) return NULL pointer", menu_item_id);
1354                                          return -1;                                          return -1;
1355                                  }                                  }
1356    
# Line 1366  int menu_control(MENU_SET *p_menu_set, i Line 1375  int menu_control(MENU_SET *p_menu_set, i
1375    
1376  int unload_menu(MENU_SET *p_menu_set)  int unload_menu(MENU_SET *p_menu_set)
1377  {  {
         int shmid;  
   
1378          if (p_menu_set == NULL)          if (p_menu_set == NULL)
1379          {          {
1380                    log_error("NULL pointer error");
1381                  return -1;                  return -1;
1382          }          }
1383    
# Line 1385  int unload_menu(MENU_SET *p_menu_set) Line 1393  int unload_menu(MENU_SET *p_menu_set)
1393                  p_menu_set->p_menu_screen_dict = NULL;                  p_menu_set->p_menu_screen_dict = NULL;
1394          }          }
1395    
         shmid = p_menu_set->shmid;  
   
1396          detach_menu_shm(p_menu_set);          detach_menu_shm(p_menu_set);
1397    
1398          if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1)          if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT)
1399          {          {
1400                  log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno);                  log_error("shm_unlink(%s) error (%d)", p_menu_set->shm_name, errno);
1401                  return -1;                  return -2;
1402          }          }
1403    
1404          return 0;          return 0;
# Line 1400  int unload_menu(MENU_SET *p_menu_set) Line 1406  int unload_menu(MENU_SET *p_menu_set)
1406    
1407  int get_menu_shm_readonly(MENU_SET *p_menu_set)  int get_menu_shm_readonly(MENU_SET *p_menu_set)
1408  {  {
1409            int fd;
1410          void *p_shm;          void *p_shm;
1411            struct stat sb;
1412            size_t size;
1413    
1414          p_shm = shmat(p_menu_set->shmid, NULL, SHM_RDONLY);          if (p_menu_set == NULL)
         if (p_shm == (void *)-1)  
1415          {          {
1416                  log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno);                  log_error("NULL pointer error");
1417                  return -1;                  return -1;
1418          }          }
1419    
1420            if ((fd = shm_open(p_menu_set->shm_name, O_RDONLY, 0600)) == -1)
1421            {
1422                    log_error("shm_open(%s) error (%d)", p_menu_set->shm_name, errno);
1423                    return -2;
1424            }
1425    
1426            if (fstat(fd, &sb) < 0)
1427            {
1428                    log_error("fstat(fd) error (%d)", errno);
1429                    close(fd);
1430                    return -2;
1431            }
1432    
1433            size = (size_t)sb.st_size;
1434    
1435            p_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0L);
1436            if (p_shm == MAP_FAILED)
1437            {
1438                    log_error("mmap() error (%d)", errno);
1439                    close(fd);
1440                    return -2;
1441            }
1442    
1443            if (close(fd) < 0)
1444            {
1445                    log_error("close(fd) error (%d)", errno);
1446                    return -1;
1447            }
1448    
1449            p_menu_set->shm_size = size;
1450          p_menu_set->p_reserved = p_shm;          p_menu_set->p_reserved = p_shm;
1451    
1452          p_menu_set->p_menu_pool = (char *)(p_menu_set->p_reserved) + MENU_SET_RESERVED_LENGTH;          p_menu_set->p_menu_pool = (char *)(p_menu_set->p_reserved) + MENU_SET_RESERVED_LENGTH;
1453          p_menu_set->p_menu_item_pool = (char *)(p_menu_set->p_menu_pool) + sizeof(MENU) * MAX_MENUS;          p_menu_set->p_menu_item_pool = (char *)(p_menu_set->p_menu_pool) + sizeof(MENU) * MAX_MENUS;
1454          p_menu_set->p_menu_screen_pool = (char *)(p_menu_set->p_menu_item_pool) + sizeof(MENU_ITEM) * MAX_MENUITEMS;          p_menu_set->p_menu_screen_pool = (char *)(p_menu_set->p_menu_item_pool) + sizeof(MENU_ITEM) * MAX_MENUITEMS;
# Line 1425  int get_menu_shm_readonly(MENU_SET *p_me Line 1464  int get_menu_shm_readonly(MENU_SET *p_me
1464    
1465  int set_menu_shm_readonly(MENU_SET *p_menu_set)  int set_menu_shm_readonly(MENU_SET *p_menu_set)
1466  {  {
1467  #ifndef __CYGWIN__          if (p_menu_set == NULL)
         void *p_shm;  
   
         // Remap shared memory in read-only mode  
         p_shm = shmat(p_menu_set->shmid, p_menu_set->p_reserved, SHM_RDONLY | SHM_REMAP);  
         if (p_shm == (void *)-1)  
1468          {          {
1469                  log_error("shmat(menu_shm shmid = %d) error (%d)\n", p_menu_set->shmid, errno);                  log_error("NULL pointer error");
1470                  return -1;                  return -1;
1471          }          }
1472    
1473          p_menu_set->p_reserved = p_shm;          if (p_menu_set->p_reserved != NULL && mprotect(p_menu_set->p_reserved, p_menu_set->shm_size, PROT_READ) < 0)
1474  #endif          {
1475                    log_error("mprotect() error (%d)", errno);
1476                    return -2;
1477            }
1478    
1479          return 0;          return 0;
1480  }  }
1481    
1482  int detach_menu_shm(MENU_SET *p_menu_set)  int detach_menu_shm(MENU_SET *p_menu_set)
1483  {  {
1484            if (p_menu_set == NULL)
1485            {
1486                    log_error("NULL pointer error");
1487                    return -1;
1488            }
1489    
1490          p_menu_set->menu_count = 0;          p_menu_set->menu_count = 0;
1491          p_menu_set->menu_item_count = 0;          p_menu_set->menu_item_count = 0;
1492          p_menu_set->menu_screen_count = 0;          p_menu_set->menu_screen_count = 0;
# Line 1458  int detach_menu_shm(MENU_SET *p_menu_set Line 1501  int detach_menu_shm(MENU_SET *p_menu_set
1501          p_menu_set->p_menu_name_dict = NULL;          p_menu_set->p_menu_name_dict = NULL;
1502          p_menu_set->p_menu_screen_dict = NULL;          p_menu_set->p_menu_screen_dict = NULL;
1503    
1504          if (p_menu_set->p_reserved != NULL && shmdt(p_menu_set->p_reserved) == -1)          if (p_menu_set->p_reserved != NULL && munmap(p_menu_set->p_reserved, p_menu_set->shm_size) < 0)
1505          {          {
1506                  log_error("shmdt() error (%d)\n", errno);                  log_error("munmap() error (%d)", errno);
1507                  return -1;                  return -2;
1508          }          }
1509    
1510          p_menu_set->p_reserved = NULL;          p_menu_set->p_reserved = NULL;


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

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