/[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.89 by sysadm, Wed Nov 19 14:47:08 2025 UTC Revision 1.96 by sysadm, Fri Feb 13 12:38:09 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 40  static const char MENU_CONF_DELIM_WITHOU Line 40  static const char MENU_CONF_DELIM_WITHOU
40  MENU_SET bbs_menu;  MENU_SET bbs_menu;
41  MENU_SET top10_menu;  MENU_SET top10_menu;
42    
43    // External definitions for inline functions
44    extern inline MENU *get_menu(MENU_SET *p_menu_set, const char *menu_name);
45    extern inline MENU *get_menu_by_id(MENU_SET *p_menu_set, MENU_ID menu_id);
46    extern inline MENU_ITEM *get_menu_item_by_id(MENU_SET *p_menu_set, MENU_ITEM_ID menu_item_id);
47    extern inline MENU_SCREEN *get_menu_screen_by_id(MENU_SET *p_menu_set, MENU_SCREEN_ID menu_screen_id);
48    
49  int load_menu(MENU_SET *p_menu_set, const char *conf_file)  int load_menu(MENU_SET *p_menu_set, const char *conf_file)
50  {  {
51          char filepath[FILE_PATH_LEN];          char filepath[FILE_PATH_LEN];
52          int fd;          int fd;
53          void *p_shm = NULL;          size_t size;
54            void *p_shm;
55          FILE *fin;          FILE *fin;
56          int fin_line = 0;          int fin_line = 0;
57          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
# Line 59  int load_menu(MENU_SET *p_menu_set, cons Line 66  int load_menu(MENU_SET *p_menu_set, cons
66          MENU_ID menu_id;          MENU_ID menu_id;
67          MENU_ITEM_ID menu_item_id;          MENU_ITEM_ID menu_item_id;
68          MENU_SCREEN_ID screen_id;          MENU_SCREEN_ID screen_id;
         size_t size;  
69    
70          if (p_menu_set == NULL || conf_file == NULL)          if (p_menu_set == NULL || conf_file == NULL)
71          {          {
72                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
73                  return -1;                  return -1;
74          }          }
75    
# Line 74  int load_menu(MENU_SET *p_menu_set, cons Line 80  int load_menu(MENU_SET *p_menu_set, cons
80          p_menu_set->p_menu_name_dict = trie_dict_create();          p_menu_set->p_menu_name_dict = trie_dict_create();
81          if (p_menu_set->p_menu_name_dict == NULL)          if (p_menu_set->p_menu_name_dict == NULL)
82          {          {
83                  log_error("trie_dict_create() error\n");                  log_error("trie_dict_create() error");
84                  return -1;                  return -1;
85          }          }
86    
# Line 82  int load_menu(MENU_SET *p_menu_set, cons Line 88  int load_menu(MENU_SET *p_menu_set, cons
88          p_menu_set->p_menu_screen_dict = trie_dict_create();          p_menu_set->p_menu_screen_dict = trie_dict_create();
89          if (p_menu_set->p_menu_screen_dict == NULL)          if (p_menu_set->p_menu_screen_dict == NULL)
90          {          {
91                  log_error("trie_dict_create() error\n");                  log_error("trie_dict_create() error");
92                  return -1;                  return -1;
93          }          }
94    
95          if ((fin = fopen(conf_file, "r")) == NULL)          if ((fin = fopen(conf_file, "r")) == NULL)
96          {          {
97                  log_error("Open %s failed\n", conf_file);                  log_error("Open %s error: %d", conf_file, errno);
98                  return -2;                  return -2;
99          }          }
100    
# Line 105  int load_menu(MENU_SET *p_menu_set, cons Line 111  int load_menu(MENU_SET *p_menu_set, cons
111    
112          if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT)          if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT)
113          {          {
114                  log_error("shm_unlink(%s) error (%d)\n", p_menu_set->shm_name, errno);                  log_error("shm_unlink(%s) error (%d)", p_menu_set->shm_name, errno);
115                  return -2;                  return -2;
116          }          }
117    
118          if ((fd = shm_open(p_menu_set->shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)          if ((fd = shm_open(p_menu_set->shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)
119          {          {
120                  log_error("shm_open(%s) error (%d)\n", p_menu_set->shm_name, errno);                  log_error("shm_open(%s) error (%d)", p_menu_set->shm_name, errno);
121                  return -2;                  return -2;
122          }          }
123          if (ftruncate(fd, (off_t)size) == -1)          if (ftruncate(fd, (off_t)size) == -1)
124          {          {
125                  log_error("ftruncate(size=%d) error (%d)\n", size, errno);                  log_error("ftruncate(size=%d) error (%d)", size, errno);
126                  close(fd);                  close(fd);
127                  return -2;                  return -2;
128          }          }
# Line 124  int load_menu(MENU_SET *p_menu_set, cons Line 130  int load_menu(MENU_SET *p_menu_set, cons
130          p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L);          p_shm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0L);
131          if (p_shm == MAP_FAILED)          if (p_shm == MAP_FAILED)
132          {          {
133                  log_error("mmap() error (%d)\n", errno);                  log_error("mmap() error (%d)", errno);
134                  close(fd);                  close(fd);
135                  return -2;                  return -2;
136          }          }
137    
138          if (close(fd) < 0)          if (close(fd) < 0)
139          {          {
140                  log_error("close(fd) error (%d)\n", errno);                  log_error("close(fd) error (%d)", errno);
141                  return -1;                  return -1;
142          }          }
143    
# Line 175  int load_menu(MENU_SET *p_menu_set, cons Line 181  int load_menu(MENU_SET *p_menu_set, cons
181                          {                          {
182                                  if (p_menu != NULL)                                  if (p_menu != NULL)
183                                  {                                  {
184                                          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);
185                                          return -1;                                          return -1;
186                                  }                                  }
187    
188                                  if (p_menu_set->menu_count >= MAX_MENUS)                                  if (p_menu_set->menu_count >= MAX_MENUS)
189                                  {                                  {
190                                          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);
191                                          return -3;                                          return -3;
192                                  }                                  }
193                                  menu_id = (MENU_ID)p_menu_set->menu_count;                                  menu_id = (MENU_ID)p_menu_set->menu_count;
# Line 199  int load_menu(MENU_SET *p_menu_set, cons Line 205  int load_menu(MENU_SET *p_menu_set, cons
205                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
206                                  if (q == NULL)                                  if (q == NULL)
207                                  {                                  {
208                                          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);
209                                          return -1;                                          return -1;
210                                  }                                  }
211                                  p = q;                                  p = q;
# Line 209  int load_menu(MENU_SET *p_menu_set, cons Line 215  int load_menu(MENU_SET *p_menu_set, cons
215                                  }                                  }
216                                  if (*q != '\0')                                  if (*q != '\0')
217                                  {                                  {
218                                          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);
219                                          return -1;                                          return -1;
220                                  }                                  }
221    
222                                  if (q - p > sizeof(p_menu->name) - 1)                                  if (q - p > sizeof(p_menu->name) - 1)
223                                  {                                  {
224                                          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);
225                                          return -1;                                          return -1;
226                                  }                                  }
227                                  strncpy(p_menu->name, p, sizeof(p_menu->name) - 1);                                  strncpy(p_menu->name, p, sizeof(p_menu->name) - 1);
# Line 223  int load_menu(MENU_SET *p_menu_set, cons Line 229  int load_menu(MENU_SET *p_menu_set, cons
229    
230                                  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)
231                                  {                                  {
232                                          log_error("Error set menu dict [%s]\n", p_menu->name);                                          log_error("Error set menu dict [%s]", p_menu->name);
233                                  }                                  }
234    
235                                  // Check syntax                                  // Check syntax
236                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
237                                  if (q != NULL)                                  if (q != NULL)
238                                  {                                  {
239                                          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);
240                                          return -1;                                          return -1;
241                                  }                                  }
242    
# Line 259  int load_menu(MENU_SET *p_menu_set, cons Line 265  int load_menu(MENU_SET *p_menu_set, cons
265                                                  // BEGIN of menu item                                                  // BEGIN of menu item
266                                                  if (p_menu->item_count >= MAX_ITEMS_PER_MENU)                                                  if (p_menu->item_count >= MAX_ITEMS_PER_MENU)
267                                                  {                                                  {
268                                                          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);
269                                                          return -1;                                                          return -1;
270                                                  }                                                  }
271                                                  if (p_menu_set->menu_item_count >= MAX_MENUITEMS)                                                  if (p_menu_set->menu_item_count >= MAX_MENUITEMS)
272                                                  {                                                  {
273                                                          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);
274                                                          return -3;                                                          return -3;
275                                                  }                                                  }
276                                                  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 292  int load_menu(MENU_SET *p_menu_set, cons Line 298  int load_menu(MENU_SET *p_menu_set, cons
298                                                          }                                                          }
299                                                          if (*q != '\0')                                                          if (*q != '\0')
300                                                          {                                                          {
301                                                                  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);
302                                                                  return -1;                                                                  return -1;
303                                                          }                                                          }
304                                                  }                                                  }
305    
306                                                  if (q - p > sizeof(p_menu_item->action) - 1)                                                  if (q - p > sizeof(p_menu_item->action) - 1)
307                                                  {                                                  {
308                                                          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);
309                                                          return -1;                                                          return -1;
310                                                  }                                                  }
311                                                  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 309  int load_menu(MENU_SET *p_menu_set, cons Line 315  int load_menu(MENU_SET *p_menu_set, cons
315                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
316                                                  if (q == NULL)                                                  if (q == NULL)
317                                                  {                                                  {
318                                                          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);
319                                                          return -1;                                                          return -1;
320                                                  }                                                  }
321                                                  p = q;                                                  p = q;
# Line 319  int load_menu(MENU_SET *p_menu_set, cons Line 325  int load_menu(MENU_SET *p_menu_set, cons
325                                                  }                                                  }
326                                                  if (*q != '\0')                                                  if (*q != '\0')
327                                                  {                                                  {
328                                                          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);
329                                                          return -1;                                                          return -1;
330                                                  }                                                  }
331                                                  p_menu_item->row = (int16_t)atoi(p);                                                  p_menu_item->row = (int16_t)atoi(p);
# Line 328  int load_menu(MENU_SET *p_menu_set, cons Line 334  int load_menu(MENU_SET *p_menu_set, cons
334                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
335                                                  if (q == NULL)                                                  if (q == NULL)
336                                                  {                                                  {
337                                                          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);
338                                                          return -1;                                                          return -1;
339                                                  }                                                  }
340                                                  p = q;                                                  p = q;
# Line 338  int load_menu(MENU_SET *p_menu_set, cons Line 344  int load_menu(MENU_SET *p_menu_set, cons
344                                                  }                                                  }
345                                                  if (*q != '\0')                                                  if (*q != '\0')
346                                                  {                                                  {
347                                                          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);
348                                                          return -1;                                                          return -1;
349                                                  }                                                  }
350                                                  p_menu_item->col = (int16_t)atoi(p);                                                  p_menu_item->col = (int16_t)atoi(p);
# Line 347  int load_menu(MENU_SET *p_menu_set, cons Line 353  int load_menu(MENU_SET *p_menu_set, cons
353                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
354                                                  if (q == NULL)                                                  if (q == NULL)
355                                                  {                                                  {
356                                                          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);
357                                                          return -1;                                                          return -1;
358                                                  }                                                  }
359                                                  p = q;                                                  p = q;
# Line 357  int load_menu(MENU_SET *p_menu_set, cons Line 363  int load_menu(MENU_SET *p_menu_set, cons
363                                                  }                                                  }
364                                                  if (*q != '\0')                                                  if (*q != '\0')
365                                                  {                                                  {
366                                                          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);
367                                                          return -1;                                                          return -1;
368                                                  }                                                  }
369                                                  p_menu_item->priv = atoi(p);                                                  p_menu_item->priv = atoi(p);
# Line 366  int load_menu(MENU_SET *p_menu_set, cons Line 372  int load_menu(MENU_SET *p_menu_set, cons
372                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
373                                                  if (q == NULL)                                                  if (q == NULL)
374                                                  {                                                  {
375                                                          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);
376                                                          return -1;                                                          return -1;
377                                                  }                                                  }
378                                                  p = q;                                                  p = q;
# Line 376  int load_menu(MENU_SET *p_menu_set, cons Line 382  int load_menu(MENU_SET *p_menu_set, cons
382                                                  }                                                  }
383                                                  if (*q != '\0')                                                  if (*q != '\0')
384                                                  {                                                  {
385                                                          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);
386                                                          return -1;                                                          return -1;
387                                                  }                                                  }
388                                                  p_menu_item->level = atoi(p);                                                  p_menu_item->level = atoi(p);
# Line 385  int load_menu(MENU_SET *p_menu_set, cons Line 391  int load_menu(MENU_SET *p_menu_set, cons
391                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
392                                                  if (q == NULL || *q != '\"')                                                  if (q == NULL || *q != '\"')
393                                                  {                                                  {
394                                                          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);
395                                                          return -1;                                                          return -1;
396                                                  }                                                  }
397                                                  q++;                                                  q++;
# Line 405  int load_menu(MENU_SET *p_menu_set, cons Line 411  int load_menu(MENU_SET *p_menu_set, cons
411                                                  }                                                  }
412                                                  if (*q != '\"' || *(q + 1) != '\0')                                                  if (*q != '\"' || *(q + 1) != '\0')
413                                                  {                                                  {
414                                                          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);
415                                                          return -1;                                                          return -1;
416                                                  }                                                  }
417                                                  *q = '\0';                                                  *q = '\0';
418    
419                                                  if (q - p > sizeof(p_menu_item->name) - 1)                                                  if (q - p > sizeof(p_menu_item->name) - 1)
420                                                  {                                                  {
421                                                          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);
422                                                          return -1;                                                          return -1;
423                                                  }                                                  }
424                                                  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 422  int load_menu(MENU_SET *p_menu_set, cons Line 428  int load_menu(MENU_SET *p_menu_set, cons
428                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);
429                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)
430                                                  {                                                  {
431                                                          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);
432                                                          return -1;                                                          return -1;
433                                                  }                                                  }
434                                                  q++;                                                  q++;
# Line 442  int load_menu(MENU_SET *p_menu_set, cons Line 448  int load_menu(MENU_SET *p_menu_set, cons
448                                                  }                                                  }
449                                                  if (*q != '\"')                                                  if (*q != '\"')
450                                                  {                                                  {
451                                                          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);
452                                                          return -1;                                                          return -1;
453                                                  }                                                  }
454                                                  *q = '\0';                                                  *q = '\0';
455    
456                                                  if (q - p > sizeof(p_menu_item->text) - 1)                                                  if (q - p > sizeof(p_menu_item->text) - 1)
457                                                  {                                                  {
458                                                          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);
459                                                          return -1;                                                          return -1;
460                                                  }                                                  }
461                                                  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 459  int load_menu(MENU_SET *p_menu_set, cons Line 465  int load_menu(MENU_SET *p_menu_set, cons
465                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
466                                                  if (q != NULL)                                                  if (q != NULL)
467                                                  {                                                  {
468                                                          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);
469                                                          return -1;                                                          return -1;
470                                                  }                                                  }
471                                          }                                          }
# Line 471  int load_menu(MENU_SET *p_menu_set, cons Line 477  int load_menu(MENU_SET *p_menu_set, cons
477                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
478                                                  if (q == NULL)                                                  if (q == NULL)
479                                                  {                                                  {
480                                                          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);
481                                                          return -1;                                                          return -1;
482                                                  }                                                  }
483                                                  p = q;                                                  p = q;
# Line 481  int load_menu(MENU_SET *p_menu_set, cons Line 487  int load_menu(MENU_SET *p_menu_set, cons
487                                                  }                                                  }
488                                                  if (*q != '\0')                                                  if (*q != '\0')
489                                                  {                                                  {
490                                                          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);
491                                                          return -1;                                                          return -1;
492                                                  }                                                  }
493                                                  p_menu->title.row = (int16_t)atoi(p);                                                  p_menu->title.row = (int16_t)atoi(p);
# Line 490  int load_menu(MENU_SET *p_menu_set, cons Line 496  int load_menu(MENU_SET *p_menu_set, cons
496                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
497                                                  if (q == NULL)                                                  if (q == NULL)
498                                                  {                                                  {
499                                                          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);
500                                                          return -1;                                                          return -1;
501                                                  }                                                  }
502                                                  p = q;                                                  p = q;
# Line 500  int load_menu(MENU_SET *p_menu_set, cons Line 506  int load_menu(MENU_SET *p_menu_set, cons
506                                                  }                                                  }
507                                                  if (*q != '\0')                                                  if (*q != '\0')
508                                                  {                                                  {
509                                                          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);
510                                                          return -1;                                                          return -1;
511                                                  }                                                  }
512                                                  p_menu->title.col = (int16_t)atoi(p);                                                  p_menu->title.col = (int16_t)atoi(p);
# Line 509  int load_menu(MENU_SET *p_menu_set, cons Line 515  int load_menu(MENU_SET *p_menu_set, cons
515                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);
516                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)                                                  if (q == NULL || (q = strchr(q, '\"')) == NULL)
517                                                  {                                                  {
518                                                          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);
519                                                          return -1;                                                          return -1;
520                                                  }                                                  }
521                                                  q++;                                                  q++;
# Line 529  int load_menu(MENU_SET *p_menu_set, cons Line 535  int load_menu(MENU_SET *p_menu_set, cons
535                                                  }                                                  }
536                                                  if (*q != '\"')                                                  if (*q != '\"')
537                                                  {                                                  {
538                                                          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);
539                                                          return -1;                                                          return -1;
540                                                  }                                                  }
541                                                  *q = '\0';                                                  *q = '\0';
542    
543                                                  if (q - p > sizeof(p_menu->title.text) - 1)                                                  if (q - p > sizeof(p_menu->title.text) - 1)
544                                                  {                                                  {
545                                                          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);
546                                                          return -1;                                                          return -1;
547                                                  }                                                  }
548                                                  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 546  int load_menu(MENU_SET *p_menu_set, cons Line 552  int load_menu(MENU_SET *p_menu_set, cons
552                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
553                                                  if (q != NULL)                                                  if (q != NULL)
554                                                  {                                                  {
555                                                          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);
556                                                          return -1;                                                          return -1;
557                                                  }                                                  }
558                                          }                                          }
# Line 558  int load_menu(MENU_SET *p_menu_set, cons Line 564  int load_menu(MENU_SET *p_menu_set, cons
564                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
565                                                  if (q == NULL)                                                  if (q == NULL)
566                                                  {                                                  {
567                                                          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);
568                                                          return -1;                                                          return -1;
569                                                  }                                                  }
570                                                  p = q;                                                  p = q;
# Line 568  int load_menu(MENU_SET *p_menu_set, cons Line 574  int load_menu(MENU_SET *p_menu_set, cons
574                                                  }                                                  }
575                                                  if (*q != '\0')                                                  if (*q != '\0')
576                                                  {                                                  {
577                                                          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);
578                                                          return -1;                                                          return -1;
579                                                  }                                                  }
580                                                  p_menu->screen_row = (int16_t)atoi(p);                                                  p_menu->screen_row = (int16_t)atoi(p);
# Line 577  int load_menu(MENU_SET *p_menu_set, cons Line 583  int load_menu(MENU_SET *p_menu_set, cons
583                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
584                                                  if (q == NULL)                                                  if (q == NULL)
585                                                  {                                                  {
586                                                          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);
587                                                          return -1;                                                          return -1;
588                                                  }                                                  }
589                                                  p = q;                                                  p = q;
# Line 587  int load_menu(MENU_SET *p_menu_set, cons Line 593  int load_menu(MENU_SET *p_menu_set, cons
593                                                  }                                                  }
594                                                  if (*q != '\0')                                                  if (*q != '\0')
595                                                  {                                                  {
596                                                          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);
597                                                          return -1;                                                          return -1;
598                                                  }                                                  }
599                                                  p_menu->screen_col = (int16_t)atoi(p);                                                  p_menu->screen_col = (int16_t)atoi(p);
# Line 596  int load_menu(MENU_SET *p_menu_set, cons Line 602  int load_menu(MENU_SET *p_menu_set, cons
602                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
603                                                  if (q == NULL)                                                  if (q == NULL)
604                                                  {                                                  {
605                                                          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);
606                                                          return -1;                                                          return -1;
607                                                  }                                                  }
608                                                  p = q;                                                  p = q;
# Line 606  int load_menu(MENU_SET *p_menu_set, cons Line 612  int load_menu(MENU_SET *p_menu_set, cons
612                                                  }                                                  }
613                                                  if (*q != '\0')                                                  if (*q != '\0')
614                                                  {                                                  {
615                                                          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);
616                                                          return -1;                                                          return -1;
617                                                  }                                                  }
618                                                  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 616  int load_menu(MENU_SET *p_menu_set, cons Line 622  int load_menu(MENU_SET *p_menu_set, cons
622                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
623                                                  if (q != NULL)                                                  if (q != NULL)
624                                                  {                                                  {
625                                                          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);
626                                                          return -1;                                                          return -1;
627                                                  }                                                  }
628                                          }                                          }
# Line 626  int load_menu(MENU_SET *p_menu_set, cons Line 632  int load_menu(MENU_SET *p_menu_set, cons
632                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
633                                                  if (q == NULL)                                                  if (q == NULL)
634                                                  {                                                  {
635                                                          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);
636                                                          return -1;                                                          return -1;
637                                                  }                                                  }
638                                                  p = q;                                                  p = q;
# Line 636  int load_menu(MENU_SET *p_menu_set, cons Line 642  int load_menu(MENU_SET *p_menu_set, cons
642                                                  }                                                  }
643                                                  if (*q != '\0')                                                  if (*q != '\0')
644                                                  {                                                  {
645                                                          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);
646                                                          return -1;                                                          return -1;
647                                                  }                                                  }
648                                                  p_menu->page_row = (int16_t)atoi(p);                                                  p_menu->page_row = (int16_t)atoi(p);
# Line 645  int load_menu(MENU_SET *p_menu_set, cons Line 651  int load_menu(MENU_SET *p_menu_set, cons
651                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
652                                                  if (q == NULL)                                                  if (q == NULL)
653                                                  {                                                  {
654                                                          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);
655                                                          return -1;                                                          return -1;
656                                                  }                                                  }
657                                                  p = q;                                                  p = q;
# Line 655  int load_menu(MENU_SET *p_menu_set, cons Line 661  int load_menu(MENU_SET *p_menu_set, cons
661                                                  }                                                  }
662                                                  if (*q != '\0')                                                  if (*q != '\0')
663                                                  {                                                  {
664                                                          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);
665                                                          return -1;                                                          return -1;
666                                                  }                                                  }
667                                                  p_menu->page_col = (int16_t)atoi(p);                                                  p_menu->page_col = (int16_t)atoi(p);
# Line 664  int load_menu(MENU_SET *p_menu_set, cons Line 670  int load_menu(MENU_SET *p_menu_set, cons
670                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
671                                                  if (q == NULL)                                                  if (q == NULL)
672                                                  {                                                  {
673                                                          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);
674                                                          return -1;                                                          return -1;
675                                                  }                                                  }
676                                                  p = q;                                                  p = q;
# Line 674  int load_menu(MENU_SET *p_menu_set, cons Line 680  int load_menu(MENU_SET *p_menu_set, cons
680                                                  }                                                  }
681                                                  if (*q != '\0')                                                  if (*q != '\0')
682                                                  {                                                  {
683                                                          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);
684                                                          return -1;                                                          return -1;
685                                                  }                                                  }
686                                                  p_menu->page_item_limit = (int16_t)atoi(p);                                                  p_menu->page_item_limit = (int16_t)atoi(p);
# Line 683  int load_menu(MENU_SET *p_menu_set, cons Line 689  int load_menu(MENU_SET *p_menu_set, cons
689                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
690                                                  if (q != NULL)                                                  if (q != NULL)
691                                                  {                                                  {
692                                                          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);
693                                                          return -1;                                                          return -1;
694                                                  }                                                  }
695                                          }                                          }
# Line 695  int load_menu(MENU_SET *p_menu_set, cons Line 701  int load_menu(MENU_SET *p_menu_set, cons
701                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
702                                                  if (q != NULL)                                                  if (q != NULL)
703                                                  {                                                  {
704                                                          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);
705                                                          return -1;                                                          return -1;
706                                                  }                                                  }
707                                          }                                          }
# Line 705  int load_menu(MENU_SET *p_menu_set, cons Line 711  int load_menu(MENU_SET *p_menu_set, cons
711                          {                          {
712                                  if (p_menu_set->menu_item_count >= MAX_MENUS)                                  if (p_menu_set->menu_item_count >= MAX_MENUS)
713                                  {                                  {
714                                          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);
715                                          return -3;                                          return -3;
716                                  }                                  }
717                                  screen_id = (MENU_SCREEN_ID)p_menu_set->menu_screen_count;                                  screen_id = (MENU_SCREEN_ID)p_menu_set->menu_screen_count;
# Line 720  int load_menu(MENU_SET *p_menu_set, cons Line 726  int load_menu(MENU_SET *p_menu_set, cons
726                                  }                                  }
727                                  if (*q != '\0')                                  if (*q != '\0')
728                                  {                                  {
729                                          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);
730                                          return -1;                                          return -1;
731                                  }                                  }
732                                  strncpy(p_screen->name, p, sizeof(p_screen->name) - 1);                                  strncpy(p_screen->name, p, sizeof(p_screen->name) - 1);
# Line 728  int load_menu(MENU_SET *p_menu_set, cons Line 734  int load_menu(MENU_SET *p_menu_set, cons
734    
735                                  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)
736                                  {                                  {
737                                          log_error("Error set menu screen dict [%s]\n", p_screen->name);                                          log_error("Error set menu screen dict [%s]", p_screen->name);
738                                  }                                  }
739    
740                                  // Check syntax                                  // Check syntax
741                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
742                                  if (q != NULL)                                  if (q != NULL)
743                                  {                                  {
744                                          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);
745                                          return -1;                                          return -1;
746                                  }                                  }
747    
# Line 756  int load_menu(MENU_SET *p_menu_set, cons Line 762  int load_menu(MENU_SET *p_menu_set, cons
762                                          {                                          {
763                                                  if (p_menu_set->p_menu_screen_buf_free + 1 > q)                                                  if (p_menu_set->p_menu_screen_buf_free + 1 > q)
764                                                  {                                                  {
765                                                          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);
766                                                          return -3;                                                          return -3;
767                                                  }                                                  }
768    
# Line 769  int load_menu(MENU_SET *p_menu_set, cons Line 775  int load_menu(MENU_SET *p_menu_set, cons
775                                          // Clear line                                          // Clear line
776                                          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)
777                                          {                                          {
778                                                  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));
779                                                  return -3;                                                  return -3;
780                                          }                                          }
781                                          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 779  int load_menu(MENU_SET *p_menu_set, cons Line 785  int load_menu(MENU_SET *p_menu_set, cons
785                                          {                                          {
786                                                  if (p_menu_set->p_menu_screen_buf_free + 2 > q)                                                  if (p_menu_set->p_menu_screen_buf_free + 2 > q)
787                                                  {                                                  {
788                                                          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);
789                                                          return -3;                                                          return -3;
790                                                  }                                                  }
791    
# Line 797  int load_menu(MENU_SET *p_menu_set, cons Line 803  int load_menu(MENU_SET *p_menu_set, cons
803    
804                                  if (p_screen->buf_length == -1)                                  if (p_screen->buf_length == -1)
805                                  {                                  {
806                                          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);
807                                  }                                  }
808                          }                          }
809                  }                  }
810                  else // Invalid prefix                  else // Invalid prefix
811                  {                  {
812                          log_error("Error in menu config line %d\n", fin_line);                          log_error("Error in menu config line %d", fin_line);
813                          return -1;                          return -1;
814                  }                  }
815          }          }
# Line 815  int load_menu(MENU_SET *p_menu_set, cons Line 821  int load_menu(MENU_SET *p_menu_set, cons
821    
822                  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)
823                  {                  {
824                          log_error("Undefined menu screen [%s]\n", p);                          log_error("Undefined menu screen [%s]", p);
825                          return -1;                          return -1;
826                  }                  }
827    
# Line 824  int load_menu(MENU_SET *p_menu_set, cons Line 830  int load_menu(MENU_SET *p_menu_set, cons
830                  {                  {
831                          if ((p_menu->filter_handler = get_cmd_handler(p_menu->name)) == NULL)                          if ((p_menu->filter_handler = get_cmd_handler(p_menu->name)) == NULL)
832                          {                          {
833                                  log_error("Undefined menu filter handler [%s]\n", p_menu->name);                                  log_error("Undefined menu filter handler [%s]", p_menu->name);
834                                  return -1;                                  return -1;
835                          }                          }
836                  }                  }
# Line 839  int load_menu(MENU_SET *p_menu_set, cons Line 845  int load_menu(MENU_SET *p_menu_set, cons
845                  {                  {
846                          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)
847                          {                          {
848                                  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);
849                                  return -1;                                  return -1;
850                          }                          }
851                  }                  }
# Line 848  int load_menu(MENU_SET *p_menu_set, cons Line 854  int load_menu(MENU_SET *p_menu_set, cons
854                  {                  {
855                          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)
856                          {                          {
857                                  log_error("Undefined sub menu id [%s]\n", p_menu_item->action);                                  log_error("Undefined sub menu id [%s]", p_menu_item->action);
858                                  return -1;                                  return -1;
859                          }                          }
860                          p_menu_item->action_menu_id = menu_id;                          p_menu_item->action_menu_id = menu_id;
# Line 875  int display_menu_cursor(MENU_SET *p_menu Line 881  int display_menu_cursor(MENU_SET *p_menu
881          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
882          if (p_menu == NULL)          if (p_menu == NULL)
883          {          {
884                  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);
885                  return -1;                  return -1;
886          }          }
887    
# Line 884  int display_menu_cursor(MENU_SET *p_menu Line 890  int display_menu_cursor(MENU_SET *p_menu
890          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);
891          if (p_menu_item == NULL)          if (p_menu_item == NULL)
892          {          {
893                  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);
894                  return -1;                  return -1;
895          }          }
896    
# Line 910  static int display_menu_current_page(MEN Line 916  static int display_menu_current_page(MEN
916          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
917          if (p_menu == NULL)          if (p_menu == NULL)
918          {          {
919                  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);
920                  return -1;                  return -1;
921          }          }
922    
# Line 934  static int display_menu_current_page(MEN Line 940  static int display_menu_current_page(MEN
940                  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);
941                  if (p_menu_screen == NULL)                  if (p_menu_screen == NULL)
942                  {                  {
943                          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);
944                          return -1;                          return -1;
945                  }                  }
946    
# Line 1006  int display_menu(MENU_SET *p_menu_set) Line 1012  int display_menu(MENU_SET *p_menu_set)
1012          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
1013          if (p_menu == NULL)          if (p_menu == NULL)
1014          {          {
1015                  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);
1016                  if (p_menu_set->choose_step > 0)                  if (p_menu_set->choose_step > 0)
1017                  {                  {
1018                          p_menu_set->choose_step--;                          p_menu_set->choose_step--;
# Line 1029  int display_menu(MENU_SET *p_menu_set) Line 1035  int display_menu(MENU_SET *p_menu_set)
1035          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);
1036          if (p_menu_item == NULL)          if (p_menu_item == NULL)
1037          {          {
1038                  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);
1039                  return EXITMENU;                  return EXITMENU;
1040          }          }
1041    
# Line 1122  int menu_control(MENU_SET *p_menu_set, i Line 1128  int menu_control(MENU_SET *p_menu_set, i
1128    
1129          if (p_menu_set->menu_count == 0)          if (p_menu_set->menu_count == 0)
1130          {          {
1131                  log_error("Empty menu set\n");                  log_error("Empty menu set");
1132                  return EXITBBS;                  return EXITBBS;
1133          }          }
1134    
# Line 1130  int menu_control(MENU_SET *p_menu_set, i Line 1136  int menu_control(MENU_SET *p_menu_set, i
1136          p_menu = get_menu_by_id(p_menu_set, menu_id);          p_menu = get_menu_by_id(p_menu_set, menu_id);
1137          if (p_menu == NULL)          if (p_menu == NULL)
1138          {          {
1139                  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);
1140                  if (p_menu_set->choose_step > 0)                  if (p_menu_set->choose_step > 0)
1141                  {                  {
1142                          p_menu_set->choose_step--;                          p_menu_set->choose_step--;
# Line 1141  int menu_control(MENU_SET *p_menu_set, i Line 1147  int menu_control(MENU_SET *p_menu_set, i
1147    
1148          if (p_menu->item_count == 0)          if (p_menu->item_count == 0)
1149          {          {
1150  #ifdef _DEBUG                  log_debug("Empty menu (%s)", p_menu->name);
                 log_error("Empty menu (%s)\n", p_menu->name);  
 #endif  
1151                  if (p_menu_set->choose_step > 0)                  if (p_menu_set->choose_step > 0)
1152                  {                  {
1153                          p_menu_set->choose_step--;                          p_menu_set->choose_step--;
# Line 1159  int menu_control(MENU_SET *p_menu_set, i Line 1163  int menu_control(MENU_SET *p_menu_set, i
1163          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);
1164          if (p_menu_item == NULL)          if (p_menu_item == NULL)
1165          {          {
1166                  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);
1167                  p_menu_set->menu_item_pos[p_menu_set->choose_step] = 0;                  p_menu_set->menu_item_pos[p_menu_set->choose_step] = 0;
1168                  return REDRAW;                  return REDRAW;
1169          }          }
# Line 1210  int menu_control(MENU_SET *p_menu_set, i Line 1214  int menu_control(MENU_SET *p_menu_set, i
1214                                  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);
1215                                  if (p_menu_item == NULL)                                  if (p_menu_item == NULL)
1216                                  {                                  {
1217                                          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);
1218                                          return -1;                                          return -1;
1219                                  }                                  }
1220    
# Line 1243  int menu_control(MENU_SET *p_menu_set, i Line 1247  int menu_control(MENU_SET *p_menu_set, i
1247                          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);
1248                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1249                          {                          {
1250                                  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);
1251                                  return -1;                                  return -1;
1252                          }                          }
1253                          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 1274  int menu_control(MENU_SET *p_menu_set, i Line 1278  int menu_control(MENU_SET *p_menu_set, i
1278                          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);
1279                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1280                          {                          {
1281                                  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);
1282                                  return -1;                                  return -1;
1283                          }                          }
1284                          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 1298  int menu_control(MENU_SET *p_menu_set, i Line 1302  int menu_control(MENU_SET *p_menu_set, i
1302                          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);
1303                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1304                          {                          {
1305                                  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);
1306                                  return -1;                                  return -1;
1307                          }                          }
1308    
# Line 1325  int menu_control(MENU_SET *p_menu_set, i Line 1329  int menu_control(MENU_SET *p_menu_set, i
1329                          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);
1330                          if (p_menu_item == NULL)                          if (p_menu_item == NULL)
1331                          {                          {
1332                                  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);
1333                                  return -1;                                  return -1;
1334                          }                          }
1335    
# Line 1352  int menu_control(MENU_SET *p_menu_set, i Line 1356  int menu_control(MENU_SET *p_menu_set, i
1356                                  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);
1357                                  if (p_menu_item == NULL)                                  if (p_menu_item == NULL)
1358                                  {                                  {
1359                                          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);
1360                                          return -1;                                          return -1;
1361                                  }                                  }
1362    
# Line 1379  int unload_menu(MENU_SET *p_menu_set) Line 1383  int unload_menu(MENU_SET *p_menu_set)
1383  {  {
1384          if (p_menu_set == NULL)          if (p_menu_set == NULL)
1385          {          {
1386                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
1387                  return -1;                  return -1;
1388          }          }
1389    
# Line 1399  int unload_menu(MENU_SET *p_menu_set) Line 1403  int unload_menu(MENU_SET *p_menu_set)
1403    
1404          if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT)          if (shm_unlink(p_menu_set->shm_name) == -1 && errno != ENOENT)
1405          {          {
1406                  log_error("shm_unlink(%s) error (%d)\n", p_menu_set->shm_name, errno);                  log_error("shm_unlink(%s) error (%d)", p_menu_set->shm_name, errno);
1407                  return -2;                  return -2;
1408          }          }
1409    
# Line 1415  int get_menu_shm_readonly(MENU_SET *p_me Line 1419  int get_menu_shm_readonly(MENU_SET *p_me
1419    
1420          if (p_menu_set == NULL)          if (p_menu_set == NULL)
1421          {          {
1422                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
1423                  return -1;                  return -1;
1424          }          }
1425    
1426          if ((fd = shm_open(p_menu_set->shm_name, O_RDONLY, 0600)) == -1)          if ((fd = shm_open(p_menu_set->shm_name, O_RDONLY, 0600)) == -1)
1427          {          {
1428                  log_error("shm_open(%s) error (%d)\n", p_menu_set->shm_name, errno);                  log_error("shm_open(%s) error (%d)", p_menu_set->shm_name, errno);
1429                  return -2;                  return -2;
1430          }          }
1431    
1432          if (fstat(fd, &sb) < 0)          if (fstat(fd, &sb) < 0)
1433          {          {
1434                  log_error("fstat(fd) error (%d)\n", errno);                  log_error("fstat(fd) error (%d)", errno);
1435                  close(fd);                  close(fd);
1436                  return -2;                  return -2;
1437          }          }
# Line 1437  int get_menu_shm_readonly(MENU_SET *p_me Line 1441  int get_menu_shm_readonly(MENU_SET *p_me
1441          p_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0L);          p_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0L);
1442          if (p_shm == MAP_FAILED)          if (p_shm == MAP_FAILED)
1443          {          {
1444                  log_error("mmap() error (%d)\n", errno);                  log_error("mmap() error (%d)", errno);
1445                  close(fd);                  close(fd);
1446                  return -2;                  return -2;
1447          }          }
1448    
1449          if (close(fd) < 0)          if (close(fd) < 0)
1450          {          {
1451                  log_error("close(fd) error (%d)\n", errno);                  log_error("close(fd) error (%d)", errno);
1452                  return -1;                  return -1;
1453          }          }
1454    
# Line 1468  int set_menu_shm_readonly(MENU_SET *p_me Line 1472  int set_menu_shm_readonly(MENU_SET *p_me
1472  {  {
1473          if (p_menu_set == NULL)          if (p_menu_set == NULL)
1474          {          {
1475                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
1476                  return -1;                  return -1;
1477          }          }
1478    
1479          if (p_menu_set->p_reserved != NULL && munmap(p_menu_set->p_reserved, p_menu_set->shm_size) < 0)          if (p_menu_set->p_reserved != NULL && mprotect(p_menu_set->p_reserved, p_menu_set->shm_size, PROT_READ) < 0)
1480          {          {
1481                  log_error("munmap() error (%d)\n", errno);                  log_error("mprotect() error (%d)", errno);
1482                  return -2;                  return -2;
1483          }          }
1484    
         if (get_menu_shm_readonly(p_menu_set) < 0)  
         {  
                 log_error("get_menu_shm_readonly() error\n");  
                 return -3;  
         }  
   
1485          return 0;          return 0;
1486  }  }
1487    
# Line 1491  int detach_menu_shm(MENU_SET *p_menu_set Line 1489  int detach_menu_shm(MENU_SET *p_menu_set
1489  {  {
1490          if (p_menu_set == NULL)          if (p_menu_set == NULL)
1491          {          {
1492                  log_error("NULL pointer error\n");                  log_error("NULL pointer error");
1493                  return -1;                  return -1;
1494          }          }
1495    
# Line 1511  int detach_menu_shm(MENU_SET *p_menu_set Line 1509  int detach_menu_shm(MENU_SET *p_menu_set
1509    
1510          if (p_menu_set->p_reserved != NULL && munmap(p_menu_set->p_reserved, p_menu_set->shm_size) < 0)          if (p_menu_set->p_reserved != NULL && munmap(p_menu_set->p_reserved, p_menu_set->shm_size) < 0)
1511          {          {
1512                  log_error("munmap() error (%d)\n", errno);                  log_error("munmap() error (%d)", errno);
1513                  return -2;                  return -2;
1514          }          }
1515    


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

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