/[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.30 by sysadm, Tue May 6 05:31:26 2025 UTC Revision 1.32 by sysadm, Thu May 8 09:06:03 2025 UTC
# Line 27  Line 27 
27  #include <string.h>  #include <string.h>
28  #include <stdio.h>  #include <stdio.h>
29  #include <ctype.h>  #include <ctype.h>
 #include <regex.h>  
30  #include <stdlib.h>  #include <stdlib.h>
31    
32  #define MENU_TEMP_DIR "var"  #define MENU_SCREEN_PATH_PREFIX "var/MENU_SCR_"
33    #define MENU_CONF_DELIM_WITH_SPACE " ,\t\r\n"
34    #define MENU_CONF_DELIM_WITHOUT_SPACE "\r\n"
35    
36  MENU_SET bbs_menu;  MENU_SET bbs_menu;
37    
38  int load_menu(MENU_SET *p_menu_set, const char *conf_file)  int load_menu(MENU_SET *p_menu_set, const char *conf_file)
39  {  {
40          FILE *fin, *fout;          FILE *fin, *fout;
41          int i = 0, j;          int fin_line = 0;
42            int i = 0;
43            int j = 0;
44          char buffer[LINE_BUFFER_LEN];          char buffer[LINE_BUFFER_LEN];
45          char screen_filename[FILE_PATH_LEN];          char screen_filename[FILE_PATH_LEN];
46          char temp[LINE_BUFFER_LEN];          char *p = NULL;
47          regmatch_t pmatch[10];          char *q = NULL;
48            char *saveptr = NULL;
49            MENU *p_menu = NULL;
50            MENU_ITEM *p_item = NULL;
51    
52            p_menu_set->menu_count = 0;
53    
54          if ((fin = fopen(conf_file, "r")) == NULL)          if ((fin = fopen(conf_file, "r")) == NULL)
55          {          {
56                  log_error("Open %s failed", conf_file);                  log_error("Open %s failed", conf_file);
57                  return -1;                  return -2;
58          }          }
59    
60          strncpy(p_menu_set->conf_file, conf_file, sizeof(p_menu_set->conf_file) - 1);          strncpy(p_menu_set->conf_file, conf_file, sizeof(p_menu_set->conf_file) - 1);
# Line 54  int load_menu(MENU_SET *p_menu_set, cons Line 62  int load_menu(MENU_SET *p_menu_set, cons
62    
63          while (fgets(buffer, sizeof(buffer), fin))          while (fgets(buffer, sizeof(buffer), fin))
64          {          {
65                  switch (buffer[0])                  fin_line++;
66    
67                    p = strtok_r(buffer, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
68                    if (p == NULL) // Blank line
69                  {                  {
70                  case '#':                          continue;
71                          break;                  }
                 case '%':  
                         if (ireg("^%S_([A-Za-z0-9_]+)", buffer, 2, pmatch) == 0)  
                         {  
                                 strncpy(temp, buffer + pmatch[1].rm_so,  
                                                 (size_t)(pmatch[1].rm_eo - pmatch[1].rm_so));  
                                 temp[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0';  
                                 snprintf(screen_filename, sizeof(screen_filename), "%s/MENU_SCR_%s", MENU_TEMP_DIR, temp);  
72    
73                                  if ((fout = fopen(screen_filename, "w")) == NULL)                  if (*p == '#' || *p == '\r' || *p == '\n') // Comment or blank line
74                    {
75                            continue;
76                    }
77    
78                    if (*p == '%')
79                    {
80                            p++;
81    
82                            if (strcmp(p, "menu") == 0) // BEGIN of sub-menu
83                            {
84                                    if (p_menu != NULL)
85                                  {                                  {
86                                          log_error("Open %s failed", screen_filename);                                          log_error("Begin new menu without end the prior one, in menu config line %d\n", fin_line);
87                                          return -2;                                          return -1;
88                                  }                                  }
89                                    p_menu = (MENU *)malloc(sizeof(MENU));
90                                  while (fgets(buffer, sizeof(buffer), fin))                                  if (p_menu == NULL)
91                                  {                                  {
92                                          if (buffer[0] != '%')                                          log_error("Unable to allocate memory for menu\n");
93                                                  fputs(buffer, fout);                                          return -3;
                                         else  
                                                 break;  
94                                  }                                  }
95                                    p_menu_set->p_menu[i] = p_menu;
96                                    i++;
97                                    p_menu_set->menu_count = i;
98    
99                                  fclose(fout);                                  j = 0; // Menu item counter
100                                  break;                                  p_menu->item_count = 0;
101                          }                                  p_menu->item_cur_pos = 0;
102                                    p_menu->title.show = 0;
103                                    p_menu->screen.show = 0;
104    
105                          if (ireg("^%menu ([A-Za-z0-9_]+)", buffer, 2, pmatch) == 0)                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
106                          {                                  if (q == NULL)
107                                  p_menu_set->p_menu[i] = malloc(sizeof(MENU));                                  {
108                                  p_menu_set->p_menu[i]->title.show = 0;                                          log_error("Error menu name in menu config line %d\n", fin_line);
109                                  p_menu_set->p_menu[i]->screen.show = 0;                                          return -1;
110                                    }
111                                  strncpy(p_menu_set->p_menu[i]->name,                                  p = q;
112                                                  buffer + pmatch[1].rm_so,                                  while (isalnum(*q) || *q == '_')
113                                                  (size_t)(pmatch[1].rm_eo - pmatch[1].rm_so));                                  {
114                                  p_menu_set->p_menu[i]->name[pmatch[1].rm_eo - pmatch[1].rm_so] =                                          q++;
115                                          '\0';                                  }
116                                    if (*q != '\0')
117                                    {
118                                            log_error("Error menu name in menu config line %d\n", fin_line);
119                                            return -1;
120                                    }
121    
122                                  j = 0;                                  if (q - p > sizeof(p_menu->name) - 1)
123                                    {
124                                            log_error("Too longer menu name in menu config line %d\n", fin_line);
125                                            return -1;
126                                    }
127                                    strncpy(p_menu->name, p, sizeof(p_menu->name) - 1);
128                                    p_menu->name[sizeof(p_menu->name) - 1] = '\0';
129    
130                                    // Check syntax
131                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
132                                    if (q != NULL)
133                                    {
134                                            log_error("Unknown extra content in menu config line %d\n", fin_line);
135                                            return -1;
136                                    }
137    
138                                  while (fgets(buffer, sizeof(buffer), fin))                                  while (fgets(buffer, sizeof(buffer), fin))
139                                  {                                  {
140                                          if (buffer[0] == '#')                                          fin_line++;
141    
142                                            p = strtok_r(buffer, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
143                                            if (p == NULL) // Blank line
144                                            {
145                                                    continue;
146                                            }
147    
148                                            if (*p == '#' || *p == '\r' || *p == '\n') // Comment or blank line
149                                          {                                          {
150                                                  continue;                                                  continue;
151                                          }                                          }
152                                          if (buffer[0] == '%')  
153                                            if (*p == '%') // END of sub-menu
154                                          {                                          {
155                                                  p_menu_set->p_menu[i]->item_count = j;                                                  p_menu = NULL;
                                                 p_menu_set->p_menu[i]->item_cur_pos = 0;  
                                                 i++;  
156                                                  break;                                                  break;
157                                          }                                          }
158                                          if (ireg("^!([A-Za-z0-9_.]+)[[:space:]]*([0-9]+),"                                          else if (*p == '!' || *p == '@')
                                                          "[[:space:]]*([0-9]+),[[:space:]]*([0-9]+),"  
                                                          "[[:space:]]*([0-9]+),[[:space:]]*\"([^\"]+)\","  
                                                          "[[:space:]]*\"([^\"]+)\"",  
                                                          buffer, 8, pmatch) == 0)  
159                                          {                                          {
160                                                  p_menu_set->p_menu[i]->items[j] =                                                  // BEGIN of menu item
161                                                          malloc(sizeof(MENU_ITEM));                                                  p_item = (MENU_ITEM *)malloc(sizeof(MENU_ITEM));
162                                                  p_menu_set->p_menu[i]->items[j]->submenu = 1;                                                  if (p_item == NULL)
163                                                  strncpy(p_menu_set->p_menu[i]->items[j]->action,                                                  {
164                                                                  buffer + pmatch[1].rm_so,                                                          log_error("Unable to allocate memory for menu item\n");
165                                                                  (size_t)(pmatch[1].rm_eo - pmatch[1].rm_so));                                                          return -3;
166                                                  p_menu_set->p_menu[i]->items[j]->action[pmatch[1].rm_eo -                                                  }
167                                                                                                                                  pmatch[1].rm_so] = '\0';                                                  p_menu->items[j] = p_item;
                                                 strncpy(temp, buffer + pmatch[2].rm_so,  
                                                                 (size_t)(pmatch[2].rm_eo - pmatch[2].rm_so));  
                                                 temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0';  
                                                 p_menu_set->p_menu[i]->items[j]->row = atoi(temp);  
                                                 strncpy(temp,  
                                                                 buffer + pmatch[3].rm_so,  
                                                                 (size_t)(pmatch[3].rm_eo - pmatch[3].rm_so));  
                                                 temp[pmatch[3].rm_eo - pmatch[3].rm_so] = '\0';  
                                                 p_menu_set->p_menu[i]->items[j]->col = atoi(temp);  
                                                 strncpy(temp,  
                                                                 buffer + pmatch[4].rm_so,  
                                                                 (size_t)(pmatch[4].rm_eo - pmatch[4].rm_so));  
                                                 temp[pmatch[4].rm_eo - pmatch[4].rm_so] = '\0';  
                                                 p_menu_set->p_menu[i]->items[j]->priv = atoi(temp);  
                                                 strncpy(temp,  
                                                                 buffer + pmatch[5].rm_so,  
                                                                 (size_t)(pmatch[5].rm_eo - pmatch[5].rm_so));  
                                                 temp[pmatch[5].rm_eo - pmatch[5].rm_so] = '\0';  
                                                 p_menu_set->p_menu[i]->items[j]->level = atoi(temp);  
                                                 strncpy(p_menu_set->p_menu[i]->items[j]->name,  
                                                                 buffer + pmatch[6].rm_so,  
                                                                 (size_t)(pmatch[6].rm_eo - pmatch[6].rm_so));  
                                                 p_menu_set->p_menu[i]->items[j]->name[pmatch[6].rm_eo -  
                                                                                                                           pmatch[6].rm_so] =  
                                                         '\0';  
                                                 strncpy(p_menu_set->p_menu[i]->items[j]->text,  
                                                                 buffer + pmatch[7].rm_so,  
                                                                 (size_t)(pmatch[7].rm_eo - pmatch[7].rm_so));  
                                                 p_menu_set->p_menu[i]->items[j]->text[pmatch[7].rm_eo -  
                                                                                                                           pmatch[7].rm_so] =  
                                                         '\0';  
168                                                  j++;                                                  j++;
169                                                  continue;                                                  p_menu->item_count = j;
170    
171                                                    p_item->submenu = (*p == '!' ? 1 : 0);
172    
173                                                    // Menu item action
174                                                    p++;
175                                                    if (strcmp(p, "..") == 0) // Return to parent menu
176                                                    {
177                                                            q = p + 2; // strlen("..")
178                                                    }
179                                                    else
180                                                    {
181                                                            q = p;
182                                                            while (isalnum(*q) || *q == '_')
183                                                            {
184                                                                    q++;
185                                                            }
186                                                            if (*q != '\0')
187                                                            {
188                                                                    log_error("Error menu item action in menu config line %d\n", fin_line);
189                                                                    return -1;
190                                                            }
191                                                    }
192    
193                                                    if (q - p > sizeof(p_item->action) - 1)
194                                                    {
195                                                            log_error("Too longer menu action in menu config line %d\n", fin_line);
196                                                            return -1;
197                                                    }
198                                                    strncpy(p_item->action, p, sizeof(p_item->action) - 1);
199                                                    p_item->action[sizeof(p_item->action) - 1] = '\0';
200    
201                                                    // Menu item row
202                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
203                                                    if (q == NULL)
204                                                    {
205                                                            log_error("Error menu item row in menu config line %d\n", fin_line);
206                                                            return -1;
207                                                    }
208                                                    p = q;
209                                                    while (isdigit(*q))
210                                                    {
211                                                            q++;
212                                                    }
213                                                    if (*q != '\0')
214                                                    {
215                                                            log_error("Error menu item row in menu config line %d\n", fin_line);
216                                                            return -1;
217                                                    }
218                                                    p_item->row = atoi(p);
219    
220                                                    // Menu item col
221                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
222                                                    if (q == NULL)
223                                                    {
224                                                            log_error("Error menu item col in menu config line %d\n", fin_line);
225                                                            return -1;
226                                                    }
227                                                    p = q;
228                                                    while (isdigit(*q))
229                                                    {
230                                                            q++;
231                                                    }
232                                                    if (*q != '\0')
233                                                    {
234                                                            log_error("Error menu item col in menu config line %d\n", fin_line);
235                                                            return -1;
236                                                    }
237                                                    p_item->col = atoi(p);
238    
239                                                    // Menu item priv
240                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
241                                                    if (q == NULL)
242                                                    {
243                                                            log_error("Error menu item priv in menu config line %d\n", fin_line);
244                                                            return -1;
245                                                    }
246                                                    p = q;
247                                                    while (isdigit(*q))
248                                                    {
249                                                            q++;
250                                                    }
251                                                    if (*q != '\0')
252                                                    {
253                                                            log_error("Error menu item priv in menu config line %d\n", fin_line);
254                                                            return -1;
255                                                    }
256                                                    p_item->priv = atoi(p);
257    
258                                                    // Menu item level
259                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
260                                                    if (q == NULL)
261                                                    {
262                                                            log_error("Error menu item level in menu config line %d\n", fin_line);
263                                                            return -1;
264                                                    }
265                                                    p = q;
266                                                    while (isdigit(*q))
267                                                    {
268                                                            q++;
269                                                    }
270                                                    if (*q != '\0')
271                                                    {
272                                                            log_error("Error menu item level in menu config line %d\n", fin_line);
273                                                            return -1;
274                                                    }
275                                                    p_item->level = atoi(p);
276    
277                                                    // Menu item name
278                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
279                                                    if (q == NULL || *q != '\"')
280                                                    {
281                                                            log_error("Error menu item name in menu config line %d\n", fin_line);
282                                                            return -1;
283                                                    }
284                                                    q++;
285                                                    p = q;
286                                                    while (*q != '\0' && *q != '\"')
287                                                    {
288                                                            q++;
289                                                    }
290                                                    if (*q != '\"' || *(q + 1) != '\0')
291                                                    {
292                                                            log_error("Error menu item name in menu config line %d\n", fin_line);
293                                                            return -1;
294                                                    }
295                                                    *q = '\0';
296    
297                                                    if (q - p > sizeof(p_item->name) - 1)
298                                                    {
299                                                            log_error("Too longer menu name in menu config line %d\n", fin_line);
300                                                            return -1;
301                                                    }
302                                                    strncpy(p_item->name, p, sizeof(p_item->name) - 1);
303                                                    p_item->name[sizeof(p_item->name) - 1] = '\0';
304    
305                                                    // Menu item text
306                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);
307                                                    if (q == NULL || (q = strchr(q, '\"')) == NULL)
308                                                    {
309                                                            log_error("Error menu item text in menu config line %d\n", fin_line);
310                                                            return -1;
311                                                    }
312                                                    q++;
313                                                    p = q;
314                                                    while (*q != '\0' && *q != '\"')
315                                                    {
316                                                            q++;
317                                                    }
318                                                    if (*q != '\"')
319                                                    {
320                                                            log_error("Error menu item text in menu config line %d\n", fin_line);
321                                                            return -1;
322                                                    }
323                                                    *q = '\0';
324    
325                                                    if (q - p > sizeof(p_item->text) - 1)
326                                                    {
327                                                            log_error("Too longer menu item text in menu config line %d\n", fin_line);
328                                                            return -1;
329                                                    }
330                                                    strncpy(p_item->text, p, sizeof(p_item->text) - 1);
331                                                    p_item->text[sizeof(p_item->text) - 1] = '\0';
332    
333                                                    // Check syntax
334                                                    q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
335                                                    if (q != NULL)
336                                                    {
337                                                            log_error("Unknown extra content in menu config line %d\n", fin_line);
338                                                            return -1;
339                                                    }
340                                          }                                          }
341                                          if (ireg("^@([A-Za-z0-9_]+)[[:space:]]*([0-9]+),"                                          else if (strcmp(p, "title") == 0)
                                                          "[[:space:]]*([0-9]+),[[:space:]]*([0-9]+),"  
                                                          "[[:space:]]*([0-9]+),[[:space:]]*\"([^\"]+)\","  
                                                          "[[:space:]]*\"([^\"]+)\"",  
                                                          buffer, 8, pmatch) == 0)  
342                                          {                                          {
343                                                  p_menu_set->p_menu[i]->items[j] =                                                  p_menu->title.show = 1;
344                                                          malloc(sizeof(MENU_ITEM));  
345                                                  p_menu_set->p_menu[i]->items[j]->submenu = 0;                                                  // Menu title row
346                                                  strncpy(p_menu_set->p_menu[i]->items[j]->action,                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
347                                                                  buffer + pmatch[1].rm_so,                                                  if (q == NULL)
348                                                                  (size_t)(pmatch[1].rm_eo - pmatch[1].rm_so));                                                  {
349                                                  p_menu_set->p_menu[i]->items[j]->action[pmatch[1].rm_eo -                                                          log_error("Error menu title row in menu config line %d\n", fin_line);
350                                                                                                                                  pmatch[1].rm_so] = '\0';                                                          return -1;
351                                                  strncpy(temp, buffer + pmatch[2].rm_so,                                                  }
352                                                                  (size_t)(pmatch[2].rm_eo - pmatch[2].rm_so));                                                  p = q;
353                                                  temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0';                                                  while (isdigit(*q))
354                                                  p_menu_set->p_menu[i]->items[j]->row = atoi(temp);                                                  {
355                                                  strncpy(temp,                                                          q++;
356                                                                  buffer + pmatch[3].rm_so,                                                  }
357                                                                  (size_t)(pmatch[3].rm_eo - pmatch[3].rm_so));                                                  if (*q != '\0')
358                                                  temp[pmatch[3].rm_eo - pmatch[3].rm_so] = '\0';                                                  {
359                                                  p_menu_set->p_menu[i]->items[j]->col = atoi(temp);                                                          log_error("Error menu title row in menu config line %d\n", fin_line);
360                                                  strncpy(temp,                                                          return -1;
361                                                                  buffer + pmatch[4].rm_so,                                                  }
362                                                                  (size_t)(pmatch[4].rm_eo - pmatch[4].rm_so));                                                  p_menu->title.row = atoi(p);
363                                                  temp[pmatch[4].rm_eo - pmatch[4].rm_so] = '\0';  
364                                                  p_menu_set->p_menu[i]->items[j]->priv = atoi(temp);                                                  // Menu title col
365                                                  strncpy(temp,                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
366                                                                  buffer + pmatch[5].rm_so,                                                  if (q == NULL)
367                                                                  (size_t)(pmatch[5].rm_eo - pmatch[5].rm_so));                                                  {
368                                                  temp[pmatch[5].rm_eo - pmatch[5].rm_so] = '\0';                                                          log_error("Error menu title col in menu config line %d\n", fin_line);
369                                                  p_menu_set->p_menu[i]->items[j]->level = atoi(temp);                                                          return -1;
370                                                  strncpy(p_menu_set->p_menu[i]->items[j]->name,                                                  }
371                                                                  buffer + pmatch[6].rm_so,                                                  p = q;
372                                                                  (size_t)(pmatch[6].rm_eo - pmatch[6].rm_so));                                                  while (isdigit(*q))
373                                                  p_menu_set->p_menu[i]->items[j]->name[pmatch[6].rm_eo -                                                  {
374                                                                                                                            pmatch[6].rm_so] =                                                          q++;
375                                                          '\0';                                                  }
376                                                  strncpy(p_menu_set->p_menu[i]->items[j]->text,                                                  if (*q != '\0')
377                                                                  buffer + pmatch[7].rm_so,                                                  {
378                                                                  (size_t)(pmatch[7].rm_eo - pmatch[7].rm_so));                                                          log_error("Error menu title col in menu config line %d\n", fin_line);
379                                                  p_menu_set->p_menu[i]->items[j]->text[pmatch[7].rm_eo -                                                          return -1;
380                                                                                                                            pmatch[7].rm_so] =                                                  }
381                                                          '\0';                                                  p_menu->title.col = atoi(p);
382                                                  j++;  
383                                                  continue;                                                  // Menu title text
384                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITHOUT_SPACE, &saveptr);
385                                                    if (q == NULL || (q = strchr(q, '\"')) == NULL)
386                                                    {
387                                                            log_error("Error menu title text in menu config line %d\n", fin_line);
388                                                            return -1;
389                                                    }
390                                                    q++;
391                                                    p = q;
392                                                    while (*q != '\0' && *q != '\"')
393                                                    {
394                                                            q++;
395                                                    }
396                                                    if (*q != '\"')
397                                                    {
398                                                            log_error("Error menu title text in menu config line %d\n", fin_line);
399                                                            return -1;
400                                                    }
401                                                    *q = '\0';
402    
403                                                    if (q - p > sizeof(p_item->text) - 1)
404                                                    {
405                                                            log_error("Too longer menu title text in menu config line %d\n", fin_line);
406                                                            return -1;
407                                                    }
408                                                    strncpy(p_menu->title.text, p, sizeof(p_menu->title.text) - 1);
409                                                    p_menu->title.text[sizeof(p_menu->title.text) - 1] = '\0';
410    
411                                                    // Check syntax
412                                                    q = strtok_r(q + 1, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
413                                                    if (q != NULL)
414                                                    {
415                                                            log_error("Unknown extra content in menu config line %d\n", fin_line);
416                                                            return -1;
417                                                    }
418                                          }                                          }
419                                          if (ireg("^title[[:space:]]*([0-9]+),"                                          else if (strcmp(p, "screen") == 0)
                                                          "[[:space:]]*([0-9]+),[[:space:]]*\"([^\"]+)\"",  
                                                          buffer, 4, pmatch) == 0)  
420                                          {                                          {
421                                                  p_menu_set->p_menu[i]->title.show = 1;                                                  p_menu->screen.show = 1;
422                                                  strncpy(temp,  
423                                                                  buffer + pmatch[1].rm_so,                                                  // Menu screen row
424                                                                  (size_t)(pmatch[1].rm_eo - pmatch[1].rm_so));                                                  q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
425                                                  temp[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0';                                                  if (q == NULL)
426                                                  p_menu_set->p_menu[i]->title.row = atoi(temp);                                                  {
427                                                  strncpy(temp,                                                          log_error("Error menu screen row in menu config line %d\n", fin_line);
428                                                                  buffer + pmatch[2].rm_so,                                                          return -1;
429                                                                  (size_t)(pmatch[2].rm_eo - pmatch[2].rm_so));                                                  }
430                                                  temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0';                                                  p = q;
431                                                  p_menu_set->p_menu[i]->title.col = atoi(temp);                                                  while (isdigit(*q))
432                                                  strncpy(p_menu_set->p_menu[i]->title.text,                                                  {
433                                                                  buffer + pmatch[3].rm_so,                                                          q++;
434                                                                  (size_t)(pmatch[3].rm_eo - pmatch[3].rm_so));                                                  }
435                                                  p_menu_set->p_menu[i]->title.text[pmatch[3].rm_eo -                                                  if (*q != '\0')
436                                                                                                                    pmatch[3].rm_so] =                                                  {
437                                                          '\0';                                                          log_error("Error menu screen row in menu config line %d\n", fin_line);
438                                                  continue;                                                          return -1;
439                                                    }
440                                                    p_menu->screen.row = atoi(p);
441    
442                                                    // Menu screen col
443                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
444                                                    if (q == NULL)
445                                                    {
446                                                            log_error("Error menu screen col in menu config line %d\n", fin_line);
447                                                            return -1;
448                                                    }
449                                                    p = q;
450                                                    while (isdigit(*q))
451                                                    {
452                                                            q++;
453                                                    }
454                                                    if (*q != '\0')
455                                                    {
456                                                            log_error("Error menu screen col in menu config line %d\n", fin_line);
457                                                            return -1;
458                                                    }
459                                                    p_menu->screen.col = atoi(p);
460    
461                                                    // Menu screen name
462                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
463                                                    if (q == NULL)
464                                                    {
465                                                            log_error("Error menu screen name in menu config line %d\n", fin_line);
466                                                            return -1;
467                                                    }
468                                                    p = q;
469                                                    while (isalnum(*q) || *q == '_')
470                                                    {
471                                                            q++;
472                                                    }
473                                                    if (*q != '\0')
474                                                    {
475                                                            log_error("Error menu screen name in menu config line %d\n", fin_line);
476                                                            return -1;
477                                                    }
478    
479                                                    snprintf(p_menu->screen.filename, sizeof(p_menu->screen.filename), "%s%s", MENU_SCREEN_PATH_PREFIX, p);
480    
481                                                    // Check syntax
482                                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
483                                                    if (q != NULL)
484                                                    {
485                                                            log_error("Unknown extra content in menu config line %d\n", fin_line);
486                                                            return -1;
487                                                    }
488                                          }                                          }
489                                          if (ireg("^screen[[:space:]]*([0-9]+),"                                  }
490                                                           "[[:space:]]*([0-9]+),[[:space:]]*S_([A-Za-z0-9_]+)",                          }
491                                                           buffer, 4, pmatch) == 0)                          else // BEGIN of menu screen
492                            {
493                                    q = p;
494                                    while (isalnum(*q) || *q == '_')
495                                    {
496                                            q++;
497                                    }
498                                    if (*q != '\0')
499                                    {
500                                            log_error("Error menu screen name in menu config line %d\n", fin_line);
501                                            return -1;
502                                    }
503    
504                                    snprintf(screen_filename, sizeof(screen_filename), "%s%s", MENU_SCREEN_PATH_PREFIX, p);
505    
506                                    // Check syntax
507                                    q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
508                                    if (q != NULL)
509                                    {
510                                            log_error("Unknown extra content in menu config line %d\n", fin_line);
511                                            return -1;
512                                    }
513    
514                                    if ((fout = fopen(screen_filename, "w")) == NULL)
515                                    {
516                                            log_error("Open %s failed", screen_filename);
517                                            return -2;
518                                    }
519    
520                                    while (fgets(buffer, sizeof(buffer), fin))
521                                    {
522                                            fin_line++;
523    
524                                            p = strtok_r(buffer, MENU_CONF_DELIM_WITH_SPACE, &saveptr);
525                                            if (p != NULL && *p == '%') // END of menu screen
526                                          {                                          {
527                                                  p_menu_set->p_menu[i]->screen.show = 1;                                                  break;
528                                                  strncpy(temp,                                          }
529                                                                  buffer + pmatch[1].rm_so,  
530                                                                  (size_t)(pmatch[1].rm_eo - pmatch[1].rm_so));                                          if (fputs(buffer, fout) < 0)
531                                                  temp[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0';                                          {
532                                                  p_menu_set->p_menu[i]->screen.row = atoi(temp);                                                  log_error("Write %s failed", screen_filename);
533                                                  strncpy(temp,                                                  return -2;
                                                                 buffer + pmatch[2].rm_so,  
                                                                 (size_t)(pmatch[2].rm_eo - pmatch[2].rm_so));  
                                                 temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0';  
                                                 p_menu_set->p_menu[i]->screen.col = atoi(temp);  
                                                 strncpy(temp,  
                                                                 buffer + pmatch[3].rm_so,  
                                                                 (size_t)(pmatch[3].rm_eo - pmatch[3].rm_so));  
                                                 temp[pmatch[3].rm_eo - pmatch[3].rm_so] = '\0';  
                                                 snprintf(p_menu_set->p_menu[i]->screen.filename,  
                                                                  sizeof(p_menu_set->p_menu[i]->screen.filename),  
                                                                  "%s/MENU_SCR_%s", MENU_TEMP_DIR, temp);  
                                                 continue;  
534                                          }                                          }
535                                  }                                  }
536    
537                                    fclose(fout);
538                          }                          }
539                          break;                  }
540                    else // Invalid prefix
541                    {
542                            log_error("Error in menu config line %d\n", fin_line);
543                            return -1;
544                  }                  }
545          }          }
546          fclose(fin);          fclose(fin);
# Line 268  int load_menu(MENU_SET *p_menu_set, cons Line 552  int load_menu(MENU_SET *p_menu_set, cons
552          return 0;          return 0;
553  }  }
554    
555  MENU *  MENU *get_menu(MENU_SET *p_menu_set, const char *menu_name)
 get_menu(MENU_SET *p_menu_set, const char *menu_name)  
556  {  {
557          int i;          int i;
558    
# Line 460  int menu_control(MENU_SET *p_menu_set, i Line 743  int menu_control(MENU_SET *p_menu_set, i
743                  display_menu_cursor(p_menu, 1);                  display_menu_cursor(p_menu, 1);
744                  break;                  break;
745          default:          default:
746                  for (i = 0; i < p_menu->item_count; i++)                  if (isalnum(key))
                 {  
                         if (key == p_menu->items[i]->name[0] &&  
                                 p_menu->items[i]->display)  
                         {  
                                 display_menu_cursor(p_menu, 0);  
                                 p_menu->item_cur_pos = i;  
                                 display_menu_cursor(p_menu, 1);  
                                 return 0;  
                         }  
                 }  
                 if (isalpha(key))  
747                  {                  {
748                          for (i = 0; i < p_menu->item_count; i++)                          for (i = 0; i < p_menu->item_count; i++)
749                          {                          {
# Line 502  void unload_menu(MENU_SET *p_menu_set) Line 774  void unload_menu(MENU_SET *p_menu_set)
774                  {                  {
775                          free(p_menu->items[j]);                          free(p_menu->items[j]);
776                  }                  }
                 remove(p_menu->screen.filename);  
777                  free(p_menu);                  free(p_menu);
778          }          }
779    


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

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