| 1 |
/*************************************************************************** |
/*************************************************************************** |
| 2 |
menu.c - description |
menu.c - description |
| 3 |
------------------- |
------------------- |
| 4 |
begin : Wed Mar 16 2004 |
Copyright : (C) 2004-2025 by Leaflet |
| 5 |
copyright : (C) 2005 by Leaflet |
Email : leaflet@leafok.com |
|
email : leaflet@leafok.com |
|
| 6 |
***************************************************************************/ |
***************************************************************************/ |
| 7 |
|
|
| 8 |
/*************************************************************************** |
/*************************************************************************** |
| 9 |
* * |
* * |
| 10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
| 11 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
| 12 |
* the Free Software Foundation; either version 2 of the License, or * |
* the Free Software Foundation; either version 3 of the License, or * |
| 13 |
* (at your option) any later version. * |
* (at your option) any later version. * |
| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
| 17 |
#include "bbs.h" |
#include "bbs.h" |
| 18 |
#include "bbs_cmd.h" |
#include "bbs_cmd.h" |
| 19 |
|
#include "user_priv.h" |
| 20 |
|
#include "reg_ex.h" |
| 21 |
|
#include "bbs_cmd.h" |
| 22 |
#include "menu.h" |
#include "menu.h" |
| 23 |
|
#include "log.h" |
| 24 |
#include "io.h" |
#include "io.h" |
| 25 |
|
#include "screen.h" |
| 26 |
#include "common.h" |
#include "common.h" |
| 27 |
|
#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_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 |
int load_menu(MENU_SET *p_menu_set, const char *conf_file) |
|
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 |
char buffer[256], screen_filename[256], temp[256]; |
int i = 0; |
| 43 |
regmatch_t pmatch[10]; |
int j = 0; |
| 44 |
|
char buffer[LINE_BUFFER_LEN]; |
| 45 |
if ((fin = fopen (conf_file, "r")) == NULL) |
char screen_filename[FILE_PATH_LEN]; |
| 46 |
{ |
char *p = NULL; |
| 47 |
log_error ("Open %s failed", conf_file); |
char *q = NULL; |
| 48 |
return -1; |
char *saveptr = NULL; |
| 49 |
} |
MENU *p_menu = NULL; |
| 50 |
|
MENU_ITEM *p_item = NULL; |
| 51 |
while (fgets (buffer, 255, fin)) |
|
| 52 |
{ |
p_menu_set->menu_count = 0; |
| 53 |
switch (buffer[0]) |
|
| 54 |
{ |
if ((fin = fopen(conf_file, "r")) == NULL) |
| 55 |
case '#': |
{ |
| 56 |
break; |
log_error("Open %s failed", conf_file); |
| 57 |
case '%': |
return -2; |
| 58 |
if (ireg ("^%S_([A-Za-z0-9_]+)", buffer, 2, pmatch) == 0) |
} |
| 59 |
{ |
|
| 60 |
strncpy (temp, buffer + pmatch[1].rm_so, |
strncpy(p_menu_set->conf_file, conf_file, sizeof(p_menu_set->conf_file) - 1); |
| 61 |
pmatch[1].rm_eo - pmatch[1].rm_so); |
p_menu_set->conf_file[sizeof(p_menu_set->conf_file) - 1] = '\0'; |
| 62 |
temp[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0'; |
|
| 63 |
sprintf (screen_filename, "%sMENU_SCR_%s", app_temp_dir, temp); |
while (fgets(buffer, sizeof(buffer), fin)) |
| 64 |
|
{ |
| 65 |
if ((fout = fopen (screen_filename, "w")) == NULL) |
fin_line++; |
| 66 |
{ |
|
| 67 |
log_error ("Open %s failed", screen_filename); |
p = strtok_r(buffer, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 68 |
return -2; |
if (p == NULL) // Blank line |
| 69 |
} |
{ |
| 70 |
|
continue; |
| 71 |
while (fgets (buffer, 255, fin)) |
} |
| 72 |
{ |
|
| 73 |
if (buffer[0] != '%') |
if (*p == '#' || *p == '\r' || *p == '\n') // Comment or blank line |
| 74 |
fputs (buffer, fout); |
{ |
| 75 |
else |
continue; |
| 76 |
break; |
} |
| 77 |
} |
|
| 78 |
|
if (*p == '%') |
| 79 |
fclose (fout); |
{ |
| 80 |
break; |
p++; |
| 81 |
} |
|
| 82 |
|
if (strcmp(p, "menu") == 0) // BEGIN of sub-menu |
| 83 |
if (ireg ("^%menu ([A-Za-z0-9_]+)", buffer, 2, pmatch) == 0) |
{ |
| 84 |
{ |
if (p_menu != NULL) |
| 85 |
p_menu_set->p_menu[i] = malloc (sizeof (MENU)); |
{ |
| 86 |
p_menu_set->p_menu[i]->title.show = 0; |
log_error("Begin new menu without end the prior one, in menu config line %d\n", fin_line); |
| 87 |
p_menu_set->p_menu[i]->screen.show = 0; |
return -1; |
| 88 |
|
} |
| 89 |
strncpy (p_menu_set->p_menu[i]->name, |
p_menu = (MENU *)malloc(sizeof(MENU)); |
| 90 |
buffer + pmatch[1].rm_so, |
if (p_menu == NULL) |
| 91 |
pmatch[1].rm_eo - pmatch[1].rm_so); |
{ |
| 92 |
p_menu_set->p_menu[i]->name[pmatch[1].rm_eo - pmatch[1].rm_so] = |
log_error("Unable to allocate memory for menu\n"); |
| 93 |
'\0'; |
return -3; |
| 94 |
|
} |
| 95 |
j = 0; |
p_menu_set->p_menu[i] = p_menu; |
| 96 |
|
i++; |
| 97 |
while (fgets (buffer, 255, fin)) |
p_menu_set->menu_count = i; |
| 98 |
{ |
|
| 99 |
if (buffer[0] == '#') |
j = 0; // Menu item counter |
| 100 |
{ |
p_menu->item_count = 0; |
| 101 |
continue; |
p_menu->item_cur_pos = 0; |
| 102 |
} |
p_menu->title.show = 0; |
| 103 |
if (buffer[0] == '%') |
p_menu->screen.show = 0; |
| 104 |
{ |
|
| 105 |
p_menu_set->p_menu[i]->item_count = j; |
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 106 |
p_menu_set->p_menu[i]->item_cur_pos = 0; |
if (q == NULL) |
| 107 |
i++; |
{ |
| 108 |
break; |
log_error("Error menu name in menu config line %d\n", fin_line); |
| 109 |
} |
return -1; |
| 110 |
if (ireg ("^!([A-Za-z0-9_.]+)[[:space:]]*([0-9]+)," |
} |
| 111 |
"[[:space:]]*([0-9]+),[[:space:]]*([0-9]+)," |
p = q; |
| 112 |
"[[:space:]]*([0-9]+),[[:space:]]*\"([^\"]+)\"," |
while (isalnum(*q) || *q == '_') |
| 113 |
"[[:space:]]*\"([^\"]+)\"", |
{ |
| 114 |
buffer, 8, pmatch) == 0) |
q++; |
| 115 |
{ |
} |
| 116 |
p_menu_set->p_menu[i]->items[j] = |
if (*q != '\0') |
| 117 |
malloc (sizeof (MENU_ITEM)); |
{ |
| 118 |
p_menu_set->p_menu[i]->items[j]->submenu = 1; |
log_error("Error menu name in menu config line %d\n", fin_line); |
| 119 |
strncpy (p_menu_set->p_menu[i]->items[j]->action, |
return -1; |
| 120 |
buffer + pmatch[1].rm_so, |
} |
| 121 |
pmatch[1].rm_eo - pmatch[1].rm_so); |
|
| 122 |
p_menu_set->p_menu[i]->items[j]->action[pmatch[1]. |
if (q - p > sizeof(p_menu->name) - 1) |
| 123 |
rm_eo - |
{ |
| 124 |
pmatch[1]. |
log_error("Too longer menu name in menu config line %d\n", fin_line); |
| 125 |
rm_so] = '\0'; |
return -1; |
| 126 |
strncpy (temp, buffer + pmatch[2].rm_so, |
} |
| 127 |
pmatch[2].rm_eo - pmatch[2].rm_so); |
strncpy(p_menu->name, p, sizeof(p_menu->name) - 1); |
| 128 |
temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0'; |
p_menu->name[sizeof(p_menu->name) - 1] = '\0'; |
| 129 |
p_menu_set->p_menu[i]->items[j]->row = atoi (temp); |
|
| 130 |
strncpy (temp, |
// Check syntax |
| 131 |
buffer + pmatch[3].rm_so, |
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 132 |
pmatch[3].rm_eo - pmatch[3].rm_so); |
if (q != NULL) |
| 133 |
temp[pmatch[3].rm_eo - pmatch[3].rm_so] = '\0'; |
{ |
| 134 |
p_menu_set->p_menu[i]->items[j]->col = atoi (temp); |
log_error("Unknown extra content in menu config line %d\n", fin_line); |
| 135 |
strncpy (temp, |
return -1; |
| 136 |
buffer + pmatch[4].rm_so, |
} |
| 137 |
pmatch[4].rm_eo - pmatch[4].rm_so); |
|
| 138 |
temp[pmatch[4].rm_eo - pmatch[4].rm_so] = '\0'; |
while (fgets(buffer, sizeof(buffer), fin)) |
| 139 |
p_menu_set->p_menu[i]->items[j]->priv = atoi (temp); |
{ |
| 140 |
strncpy (temp, |
fin_line++; |
| 141 |
buffer + pmatch[5].rm_so, |
|
| 142 |
pmatch[5].rm_eo - pmatch[5].rm_so); |
p = strtok_r(buffer, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 143 |
temp[pmatch[5].rm_eo - pmatch[5].rm_so] = '\0'; |
if (p == NULL) // Blank line |
| 144 |
p_menu_set->p_menu[i]->items[j]->level = atoi (temp); |
{ |
| 145 |
strncpy (p_menu_set->p_menu[i]->items[j]->name, |
continue; |
| 146 |
buffer + pmatch[6].rm_so, |
} |
| 147 |
pmatch[6].rm_eo - pmatch[6].rm_so); |
|
| 148 |
p_menu_set->p_menu[i]->items[j]->name[pmatch[6].rm_eo - |
if (*p == '#' || *p == '\r' || *p == '\n') // Comment or blank line |
| 149 |
pmatch[6].rm_so] = |
{ |
| 150 |
'\0'; |
continue; |
| 151 |
strncpy (p_menu_set->p_menu[i]->items[j]->text, |
} |
| 152 |
buffer + pmatch[7].rm_so, |
|
| 153 |
pmatch[7].rm_eo - pmatch[7].rm_so); |
if (*p == '%') // END of sub-menu |
| 154 |
p_menu_set->p_menu[i]->items[j]->text[pmatch[7].rm_eo - |
{ |
| 155 |
pmatch[7].rm_so] = |
p_menu = NULL; |
| 156 |
'\0'; |
break; |
| 157 |
j++; |
} |
| 158 |
continue; |
else if (*p == '!' || *p == '@') |
| 159 |
} |
{ |
| 160 |
if (ireg ("^@([A-Za-z0-9_]+)[[:space:]]*([0-9]+)," |
// BEGIN of menu item |
| 161 |
"[[:space:]]*([0-9]+),[[:space:]]*([0-9]+)," |
p_item = (MENU_ITEM *)malloc(sizeof(MENU_ITEM)); |
| 162 |
"[[:space:]]*([0-9]+),[[:space:]]*\"([^\"]+)\"," |
if (p_item == NULL) |
| 163 |
"[[:space:]]*\"([^\"]+)\"", |
{ |
| 164 |
buffer, 8, pmatch) == 0) |
log_error("Unable to allocate memory for menu item\n"); |
| 165 |
{ |
return -3; |
| 166 |
p_menu_set->p_menu[i]->items[j] = |
} |
| 167 |
malloc (sizeof (MENU_ITEM)); |
p_menu->items[j] = p_item; |
| 168 |
p_menu_set->p_menu[i]->items[j]->submenu = 0; |
j++; |
| 169 |
strncpy (p_menu_set->p_menu[i]->items[j]->action, |
p_menu->item_count = j; |
| 170 |
buffer + pmatch[1].rm_so, |
|
| 171 |
pmatch[1].rm_eo - pmatch[1].rm_so); |
p_item->submenu = (*p == '!' ? 1 : 0); |
| 172 |
p_menu_set->p_menu[i]->items[j]->action[pmatch[1]. |
|
| 173 |
rm_eo - |
// Menu item action |
| 174 |
pmatch[1]. |
p++; |
| 175 |
rm_so] = '\0'; |
if (strcmp(p, "..") == 0) // Return to parent menu |
| 176 |
strncpy (temp, buffer + pmatch[2].rm_so, |
{ |
| 177 |
pmatch[2].rm_eo - pmatch[2].rm_so); |
q = p + 2; // strlen("..") |
| 178 |
temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0'; |
} |
| 179 |
p_menu_set->p_menu[i]->items[j]->row = atoi (temp); |
else |
| 180 |
strncpy (temp, |
{ |
| 181 |
buffer + pmatch[3].rm_so, |
q = p; |
| 182 |
pmatch[3].rm_eo - pmatch[3].rm_so); |
while (isalnum(*q) || *q == '_') |
| 183 |
temp[pmatch[3].rm_eo - pmatch[3].rm_so] = '\0'; |
{ |
| 184 |
p_menu_set->p_menu[i]->items[j]->col = atoi (temp); |
q++; |
| 185 |
strncpy (temp, |
} |
| 186 |
buffer + pmatch[4].rm_so, |
if (*q != '\0') |
| 187 |
pmatch[4].rm_eo - pmatch[4].rm_so); |
{ |
| 188 |
temp[pmatch[4].rm_eo - pmatch[4].rm_so] = '\0'; |
log_error("Error menu item action in menu config line %d\n", fin_line); |
| 189 |
p_menu_set->p_menu[i]->items[j]->priv = atoi (temp); |
return -1; |
| 190 |
strncpy (temp, |
} |
| 191 |
buffer + pmatch[5].rm_so, |
} |
| 192 |
pmatch[5].rm_eo - pmatch[5].rm_so); |
|
| 193 |
temp[pmatch[5].rm_eo - pmatch[5].rm_so] = '\0'; |
if (q - p > sizeof(p_item->action) - 1) |
| 194 |
p_menu_set->p_menu[i]->items[j]->level = atoi (temp); |
{ |
| 195 |
strncpy (p_menu_set->p_menu[i]->items[j]->name, |
log_error("Too longer menu action in menu config line %d\n", fin_line); |
| 196 |
buffer + pmatch[6].rm_so, |
return -1; |
| 197 |
pmatch[6].rm_eo - pmatch[6].rm_so); |
} |
| 198 |
p_menu_set->p_menu[i]->items[j]->name[pmatch[6].rm_eo - |
strncpy(p_item->action, p, sizeof(p_item->action) - 1); |
| 199 |
pmatch[6].rm_so] = |
p_item->action[sizeof(p_item->action) - 1] = '\0'; |
| 200 |
'\0'; |
|
| 201 |
strncpy (p_menu_set->p_menu[i]->items[j]->text, |
// Menu item row |
| 202 |
buffer + pmatch[7].rm_so, |
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 203 |
pmatch[7].rm_eo - pmatch[7].rm_so); |
if (q == NULL) |
| 204 |
p_menu_set->p_menu[i]->items[j]->text[pmatch[7].rm_eo - |
{ |
| 205 |
pmatch[7].rm_so] = |
log_error("Error menu item row in menu config line %d\n", fin_line); |
| 206 |
'\0'; |
return -1; |
| 207 |
j++; |
} |
| 208 |
continue; |
p = q; |
| 209 |
} |
while (isdigit(*q)) |
| 210 |
if (ireg ("^title[[:space:]]*([0-9]+)," |
{ |
| 211 |
"[[:space:]]*([0-9]+),[[:space:]]*\"([^\"]+)\"", |
q++; |
| 212 |
buffer, 4, pmatch) == 0) |
} |
| 213 |
{ |
if (*q != '\0') |
| 214 |
p_menu_set->p_menu[i]->title.show = 1; |
{ |
| 215 |
strncpy (temp, |
log_error("Error menu item row in menu config line %d\n", fin_line); |
| 216 |
buffer + pmatch[1].rm_so, |
return -1; |
| 217 |
pmatch[1].rm_eo - pmatch[1].rm_so); |
} |
| 218 |
temp[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0'; |
p_item->row = atoi(p); |
| 219 |
p_menu_set->p_menu[i]->title.row = atoi (temp); |
|
| 220 |
strncpy (temp, |
// Menu item col |
| 221 |
buffer + pmatch[2].rm_so, |
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 222 |
pmatch[2].rm_eo - pmatch[2].rm_so); |
if (q == NULL) |
| 223 |
temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0'; |
{ |
| 224 |
p_menu_set->p_menu[i]->title.col = atoi (temp); |
log_error("Error menu item col in menu config line %d\n", fin_line); |
| 225 |
strncpy (p_menu_set->p_menu[i]->title.text, |
return -1; |
| 226 |
buffer + pmatch[3].rm_so, |
} |
| 227 |
pmatch[3].rm_eo - pmatch[3].rm_so); |
p = q; |
| 228 |
p_menu_set->p_menu[i]->title.text[pmatch[3].rm_eo - |
while (isdigit(*q)) |
| 229 |
pmatch[3].rm_so] = |
{ |
| 230 |
'\0'; |
q++; |
| 231 |
continue; |
} |
| 232 |
} |
if (*q != '\0') |
| 233 |
if (ireg ("^screen[[:space:]]*([0-9]+)," |
{ |
| 234 |
"[[:space:]]*([0-9]+),[[:space:]]*S_([A-Za-z0-9_]+)", |
log_error("Error menu item col in menu config line %d\n", fin_line); |
| 235 |
buffer, 4, pmatch) == 0) |
return -1; |
| 236 |
{ |
} |
| 237 |
p_menu_set->p_menu[i]->screen.show = 1; |
p_item->col = atoi(p); |
| 238 |
strncpy (temp, |
|
| 239 |
buffer + pmatch[1].rm_so, |
// Menu item priv |
| 240 |
pmatch[1].rm_eo - pmatch[1].rm_so); |
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 241 |
temp[pmatch[1].rm_eo - pmatch[1].rm_so] = '\0'; |
if (q == NULL) |
| 242 |
p_menu_set->p_menu[i]->screen.row = atoi (temp); |
{ |
| 243 |
strncpy (temp, |
log_error("Error menu item priv in menu config line %d\n", fin_line); |
| 244 |
buffer + pmatch[2].rm_so, |
return -1; |
| 245 |
pmatch[2].rm_eo - pmatch[2].rm_so); |
} |
| 246 |
temp[pmatch[2].rm_eo - pmatch[2].rm_so] = '\0'; |
p = q; |
| 247 |
p_menu_set->p_menu[i]->screen.col = atoi (temp); |
while (isdigit(*q)) |
| 248 |
strncpy (temp, |
{ |
| 249 |
buffer + pmatch[3].rm_so, |
q++; |
| 250 |
pmatch[3].rm_eo - pmatch[3].rm_so); |
} |
| 251 |
temp[pmatch[3].rm_eo - pmatch[3].rm_so] = '\0'; |
if (*q != '\0') |
| 252 |
sprintf (p_menu_set->p_menu[i]->screen.filename, |
{ |
| 253 |
"%sMENU_SCR_%s", app_temp_dir, temp); |
log_error("Error menu item priv in menu config line %d\n", fin_line); |
| 254 |
continue; |
return -1; |
| 255 |
} |
} |
| 256 |
} |
p_item->priv = atoi(p); |
| 257 |
} |
|
| 258 |
break; |
// Menu item level |
| 259 |
} |
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 260 |
} |
if (q == NULL) |
| 261 |
fclose (fin); |
{ |
| 262 |
|
log_error("Error menu item level in menu config line %d\n", fin_line); |
| 263 |
p_menu_set->menu_count = i; |
return -1; |
| 264 |
p_menu_set->menu_select_depth = 0; |
} |
| 265 |
p_menu_set->p_menu_select[p_menu_set->menu_select_depth] |
p = q; |
| 266 |
= (i == 0 ? NULL : p_menu_set->p_menu[0]); |
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 |
|
else if (strcmp(p, "title") == 0) |
| 342 |
|
{ |
| 343 |
|
p_menu->title.show = 1; |
| 344 |
|
|
| 345 |
|
// Menu title row |
| 346 |
|
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 347 |
|
if (q == NULL) |
| 348 |
|
{ |
| 349 |
|
log_error("Error menu title row in menu config line %d\n", fin_line); |
| 350 |
|
return -1; |
| 351 |
|
} |
| 352 |
|
p = q; |
| 353 |
|
while (isdigit(*q)) |
| 354 |
|
{ |
| 355 |
|
q++; |
| 356 |
|
} |
| 357 |
|
if (*q != '\0') |
| 358 |
|
{ |
| 359 |
|
log_error("Error menu title row in menu config line %d\n", fin_line); |
| 360 |
|
return -1; |
| 361 |
|
} |
| 362 |
|
p_menu->title.row = atoi(p); |
| 363 |
|
|
| 364 |
|
// Menu title col |
| 365 |
|
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 366 |
|
if (q == NULL) |
| 367 |
|
{ |
| 368 |
|
log_error("Error menu title col in menu config line %d\n", fin_line); |
| 369 |
|
return -1; |
| 370 |
|
} |
| 371 |
|
p = q; |
| 372 |
|
while (isdigit(*q)) |
| 373 |
|
{ |
| 374 |
|
q++; |
| 375 |
|
} |
| 376 |
|
if (*q != '\0') |
| 377 |
|
{ |
| 378 |
|
log_error("Error menu title col in menu config line %d\n", fin_line); |
| 379 |
|
return -1; |
| 380 |
|
} |
| 381 |
|
p_menu->title.col = atoi(p); |
| 382 |
|
|
| 383 |
|
// 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 |
|
else if (strcmp(p, "screen") == 0) |
| 420 |
|
{ |
| 421 |
|
p_menu->screen.show = 1; |
| 422 |
|
|
| 423 |
|
// Menu screen row |
| 424 |
|
q = strtok_r(NULL, MENU_CONF_DELIM_WITH_SPACE, &saveptr); |
| 425 |
|
if (q == NULL) |
| 426 |
|
{ |
| 427 |
|
log_error("Error menu screen row in menu config line %d\n", fin_line); |
| 428 |
|
return -1; |
| 429 |
|
} |
| 430 |
|
p = q; |
| 431 |
|
while (isdigit(*q)) |
| 432 |
|
{ |
| 433 |
|
q++; |
| 434 |
|
} |
| 435 |
|
if (*q != '\0') |
| 436 |
|
{ |
| 437 |
|
log_error("Error menu screen row in menu config line %d\n", fin_line); |
| 438 |
|
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 |
|
} |
| 490 |
|
} |
| 491 |
|
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 |
|
break; |
| 528 |
|
} |
| 529 |
|
|
| 530 |
|
if (fputs(buffer, fout) < 0) |
| 531 |
|
{ |
| 532 |
|
log_error("Write %s failed", screen_filename); |
| 533 |
|
return -2; |
| 534 |
|
} |
| 535 |
|
} |
| 536 |
|
|
| 537 |
return 0; |
fclose(fout); |
| 538 |
|
} |
| 539 |
|
} |
| 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); |
| 547 |
|
|
| 548 |
|
p_menu_set->menu_count = i; |
| 549 |
|
p_menu_set->menu_select_depth = 0; |
| 550 |
|
p_menu_set->p_menu_select[p_menu_set->menu_select_depth] = (i == 0 ? NULL : p_menu_set->p_menu[0]); |
| 551 |
|
|
| 552 |
|
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 |
|
|
| 559 |
for (i = 0; i < p_menu_set->menu_count; i++) |
for (i = 0; i < p_menu_set->menu_count; i++) |
|
{ |
|
|
if (strcmp (p_menu_set->p_menu[i]->name, menu_name) == 0) |
|
| 560 |
{ |
{ |
| 561 |
return p_menu_set->p_menu[i]; |
if (strcmp(p_menu_set->p_menu[i]->name, menu_name) == 0) |
| 562 |
|
{ |
| 563 |
|
return p_menu_set->p_menu[i]; |
| 564 |
|
} |
| 565 |
} |
} |
|
} |
|
| 566 |
|
|
| 567 |
return NULL; |
return NULL; |
| 568 |
} |
} |
| 569 |
|
|
| 570 |
void |
static void display_menu_cursor(MENU *p_menu, int show) |
|
display_menu_cursor (MENU * p_menu, int show) |
|
| 571 |
{ |
{ |
| 572 |
moveto ((p_menu->items[p_menu->item_cur_pos])->r_row, |
moveto((p_menu->items[p_menu->item_cur_pos])->r_row, |
| 573 |
(p_menu->items[p_menu->item_cur_pos])->r_col - 2); |
(p_menu->items[p_menu->item_cur_pos])->r_col - 2); |
| 574 |
prints (show ? ">" : " "); |
outc(show ? '>' : ' '); |
| 575 |
iflush (); |
iflush(); |
| 576 |
} |
} |
| 577 |
|
|
| 578 |
int |
int display_menu(MENU *p_menu) |
|
display_menu (MENU * p_menu) |
|
| 579 |
{ |
{ |
| 580 |
int i, row, col, menu_selectable = 0; |
int row = 0; |
| 581 |
|
int col = 0; |
| 582 |
if (p_menu == NULL) |
int menu_selectable = 0; |
|
return -1; |
|
| 583 |
|
|
| 584 |
if (p_menu->title.show) |
if (p_menu == NULL) |
| 585 |
show_top (p_menu->title.text); |
{ |
| 586 |
|
return -1; |
| 587 |
if (p_menu->screen.show) |
} |
|
{ |
|
|
moveto (p_menu->screen.row, p_menu->screen.col); |
|
|
if (display_file (p_menu->screen.filename) != 0) |
|
|
log_error ("Display menu screen <%s> failed!\n", |
|
|
p_menu->screen.filename); |
|
|
} |
|
| 588 |
|
|
| 589 |
row = p_menu->items[0]->row; |
if (p_menu->title.show) |
| 590 |
col = p_menu->items[0]->col; |
{ |
| 591 |
|
show_top(p_menu->title.text); |
| 592 |
|
} |
| 593 |
|
|
| 594 |
for (i = 0; i < p_menu->item_count; i++) |
if (p_menu->screen.show) |
|
{ |
|
|
if (checkpriv (&BBS_priv, 0, p_menu->items[i]->priv) == 0 |
|
|
|| checklevel (&BBS_priv, p_menu->items[i]->level) == 0) |
|
| 595 |
{ |
{ |
| 596 |
p_menu->items[i]->display = 0; |
moveto(p_menu->screen.row, p_menu->screen.col); |
| 597 |
|
if (display_file(p_menu->screen.filename) != 0) |
| 598 |
|
{ |
| 599 |
|
log_error("Display menu screen <%s> failed!\n", |
| 600 |
|
p_menu->screen.filename); |
| 601 |
|
} |
| 602 |
} |
} |
| 603 |
else |
|
| 604 |
|
for (int i = 0; i < p_menu->item_count; i++) |
| 605 |
{ |
{ |
| 606 |
p_menu->items[i]->display = 1; |
if (p_menu->items[i]->row != 0) |
| 607 |
|
{ |
| 608 |
|
row = p_menu->items[i]->row; |
| 609 |
|
} |
| 610 |
|
if (p_menu->items[i]->col != 0) |
| 611 |
|
{ |
| 612 |
|
col = p_menu->items[i]->col; |
| 613 |
|
} |
| 614 |
|
|
| 615 |
|
if (checkpriv(&BBS_priv, 0, p_menu->items[i]->priv) == 0 || checklevel(&BBS_priv, p_menu->items[i]->level) == 0) |
| 616 |
|
{ |
| 617 |
|
p_menu->items[i]->display = 0; |
| 618 |
|
p_menu->items[i]->r_row = 0; |
| 619 |
|
p_menu->items[i]->r_col = 0; |
| 620 |
|
} |
| 621 |
|
else |
| 622 |
|
{ |
| 623 |
|
p_menu->items[i]->display = 1; |
| 624 |
|
|
| 625 |
|
if (!menu_selectable) |
| 626 |
|
{ |
| 627 |
|
p_menu->item_cur_pos = i; |
| 628 |
|
menu_selectable = 1; |
| 629 |
|
} |
| 630 |
|
|
| 631 |
|
p_menu->items[i]->r_row = row; |
| 632 |
|
p_menu->items[i]->r_col = col; |
| 633 |
|
|
| 634 |
menu_selectable = 1; |
moveto(row, col); |
| 635 |
|
prints("%s", p_menu->items[i]->text); |
| 636 |
|
|
| 637 |
if (p_menu->items[i]->row != 0) |
row++; |
| 638 |
row = p_menu->items[i]->row; |
} |
|
else |
|
|
row++; |
|
|
p_menu->items[i]->r_row = row; |
|
|
if (p_menu->items[i]->col != 0) |
|
|
col = p_menu->items[i]->col; |
|
|
p_menu->items[i]->r_col = col; |
|
|
moveto (row, col); |
|
|
prints (p_menu->items[i]->text); |
|
|
iflush (); |
|
| 639 |
} |
} |
|
} |
|
| 640 |
|
|
| 641 |
if (!menu_selectable) |
if (!menu_selectable) |
| 642 |
return -1; |
{ |
| 643 |
|
return -1; |
| 644 |
|
} |
| 645 |
|
|
| 646 |
display_menu_cursor (p_menu, 1); |
display_menu_cursor(p_menu, 1); |
| 647 |
|
|
| 648 |
return 0; |
return 0; |
| 649 |
} |
} |
| 650 |
|
|
| 651 |
int |
int display_current_menu(MENU_SET *p_menu_set) |
|
display_current_menu (MENU_SET * p_menu_set) |
|
| 652 |
{ |
{ |
| 653 |
MENU *p_menu; |
MENU *p_menu; |
| 654 |
|
|
| 655 |
p_menu = p_menu_set->p_menu_select[p_menu_set->menu_select_depth]; |
p_menu = p_menu_set->p_menu_select[p_menu_set->menu_select_depth]; |
| 656 |
|
|
| 657 |
return display_menu (p_menu); |
return display_menu(p_menu); |
| 658 |
} |
} |
| 659 |
|
|
| 660 |
int |
int menu_control(MENU_SET *p_menu_set, int key) |
|
menu_control (MENU_SET * p_menu_set, int key) |
|
| 661 |
{ |
{ |
| 662 |
int i; |
int i; |
| 663 |
MENU *p_menu; |
MENU *p_menu; |
| 664 |
|
|
| 665 |
if (p_menu_set->menu_count == 0) |
if (p_menu_set->menu_count == 0) |
| 666 |
return 0; |
{ |
| 667 |
|
return 0; |
| 668 |
|
} |
| 669 |
|
|
| 670 |
p_menu = p_menu_set->p_menu_select[p_menu_set->menu_select_depth]; |
p_menu = p_menu_set->p_menu_select[p_menu_set->menu_select_depth]; |
| 671 |
|
|
| 672 |
switch (key) |
switch (key) |
| 673 |
{ |
{ |
| 674 |
case CR: |
case CR: |
| 675 |
case KEY_RIGHT: |
igetch(1); // Cleanup remaining '\n' in the buffer |
| 676 |
if (p_menu->items[p_menu->item_cur_pos]->submenu) |
case KEY_RIGHT: |
| 677 |
{ |
if (p_menu->items[p_menu->item_cur_pos]->submenu) |
| 678 |
if (strcmp (p_menu->items[p_menu->item_cur_pos]->action, "..") == 0) |
{ |
| 679 |
return menu_control (p_menu_set, KEY_LEFT); |
if (strcmp(p_menu->items[p_menu->item_cur_pos]->action, "..") == 0) |
| 680 |
p_menu_set->menu_select_depth++; |
{ |
| 681 |
p_menu = |
return menu_control(p_menu_set, KEY_LEFT); |
| 682 |
p_menu_set->p_menu_select[p_menu_set->menu_select_depth] = |
} |
| 683 |
get_menu (p_menu_set, |
p_menu_set->menu_select_depth++; |
| 684 |
p_menu->items[p_menu->item_cur_pos]->action); |
p_menu = get_menu(p_menu_set, p_menu->items[p_menu->item_cur_pos]->action); |
| 685 |
if (display_menu (p_menu) != 0) |
p_menu_set->p_menu_select[p_menu_set->menu_select_depth] = p_menu; |
| 686 |
return menu_control (p_menu_set, KEY_LEFT); |
|
| 687 |
break; |
if (display_menu(p_menu) != 0) |
| 688 |
} |
{ |
| 689 |
else |
return menu_control(p_menu_set, KEY_LEFT); |
| 690 |
{ |
} |
| 691 |
return (exec_cmd(p_menu->items[p_menu->item_cur_pos]->action, |
break; |
| 692 |
p_menu->items[p_menu->item_cur_pos]->name)); |
} |
| 693 |
} |
else |
| 694 |
case KEY_LEFT: |
{ |
| 695 |
if (p_menu_set->menu_select_depth > 0) |
return (exec_cmd(p_menu->items[p_menu->item_cur_pos]->action, |
| 696 |
{ |
p_menu->items[p_menu->item_cur_pos]->name)); |
| 697 |
p_menu_set->menu_select_depth--; |
} |
| 698 |
if (display_current_menu (p_menu_set) != 0) |
case KEY_LEFT: |
| 699 |
return menu_control (p_menu_set, KEY_LEFT); |
if (p_menu_set->menu_select_depth > 0) |
| 700 |
break; |
{ |
| 701 |
} |
p_menu_set->menu_select_depth--; |
| 702 |
else |
if (display_current_menu(p_menu_set) != 0) |
| 703 |
{ |
{ |
| 704 |
display_menu_cursor (p_menu, 0); |
return menu_control(p_menu_set, KEY_LEFT); |
| 705 |
p_menu->item_cur_pos = p_menu->item_count - 1; |
} |
| 706 |
while (!p_menu->items[p_menu->item_cur_pos]->display |
break; |
| 707 |
|| p_menu->items[p_menu->item_cur_pos]->priv != 0 |
} |
| 708 |
|| p_menu->items[p_menu->item_cur_pos]->level != 0) |
else |
| 709 |
p_menu->item_cur_pos--; |
{ |
| 710 |
display_menu_cursor (p_menu, 1); |
display_menu_cursor(p_menu, 0); |
| 711 |
break; |
p_menu->item_cur_pos = p_menu->item_count - 1; |
| 712 |
} |
while (!p_menu->items[p_menu->item_cur_pos]->display || |
| 713 |
case KEY_UP: |
p_menu->items[p_menu->item_cur_pos]->priv != 0 || |
| 714 |
display_menu_cursor (p_menu, 0); |
p_menu->items[p_menu->item_cur_pos]->level != 0) |
| 715 |
do |
{ |
| 716 |
{ |
p_menu->item_cur_pos--; |
| 717 |
p_menu->item_cur_pos--; |
} |
| 718 |
if (p_menu->item_cur_pos < 0) |
display_menu_cursor(p_menu, 1); |
| 719 |
p_menu->item_cur_pos = p_menu->item_count - 1; |
break; |
| 720 |
} |
} |
| 721 |
while (!p_menu->items[p_menu->item_cur_pos]->display); |
case KEY_UP: |
| 722 |
display_menu_cursor (p_menu, 1); |
display_menu_cursor(p_menu, 0); |
| 723 |
break; |
do |
| 724 |
case KEY_DOWN: |
{ |
| 725 |
display_menu_cursor (p_menu, 0); |
p_menu->item_cur_pos--; |
| 726 |
do |
if (p_menu->item_cur_pos < 0) |
| 727 |
{ |
{ |
| 728 |
p_menu->item_cur_pos++; |
p_menu->item_cur_pos = p_menu->item_count - 1; |
| 729 |
if (p_menu->item_cur_pos >= p_menu->item_count) |
} |
| 730 |
p_menu->item_cur_pos = 0; |
} while (!p_menu->items[p_menu->item_cur_pos]->display); |
| 731 |
} |
display_menu_cursor(p_menu, 1); |
| 732 |
while (!p_menu->items[p_menu->item_cur_pos]->display); |
break; |
| 733 |
display_menu_cursor (p_menu, 1); |
case KEY_DOWN: |
| 734 |
break; |
display_menu_cursor(p_menu, 0); |
| 735 |
default: |
do |
| 736 |
for (i = 0; i < p_menu->item_count; i++) |
{ |
| 737 |
{ |
p_menu->item_cur_pos++; |
| 738 |
if (key == p_menu->items[i]->name[0]) |
if (p_menu->item_cur_pos >= p_menu->item_count) |
| 739 |
{ |
{ |
| 740 |
display_menu_cursor (p_menu, 0); |
p_menu->item_cur_pos = 0; |
| 741 |
p_menu->item_cur_pos = i; |
} |
| 742 |
display_menu_cursor (p_menu, 1); |
} while (!p_menu->items[p_menu->item_cur_pos]->display); |
| 743 |
return 0; |
display_menu_cursor(p_menu, 1); |
| 744 |
} |
break; |
| 745 |
} |
default: |
| 746 |
if (isalpha (key)) |
if (isalnum(key)) |
| 747 |
{ |
{ |
| 748 |
for (i = 0; i < p_menu->item_count; i++) |
for (i = 0; i < p_menu->item_count; i++) |
| 749 |
{ |
{ |
| 750 |
if (toupper (key) == toupper (p_menu->items[i]->name[0])) |
if (toupper(key) == toupper(p_menu->items[i]->name[0]) && |
| 751 |
{ |
p_menu->items[i]->display) |
| 752 |
display_menu_cursor (p_menu, 0); |
{ |
| 753 |
p_menu->item_cur_pos = i; |
display_menu_cursor(p_menu, 0); |
| 754 |
display_menu_cursor (p_menu, 1); |
p_menu->item_cur_pos = i; |
| 755 |
return 0; |
display_menu_cursor(p_menu, 1); |
| 756 |
|
return 0; |
| 757 |
|
} |
| 758 |
|
} |
| 759 |
} |
} |
|
} |
|
| 760 |
} |
} |
|
} |
|
| 761 |
|
|
| 762 |
return 0; |
return 0; |
| 763 |
} |
} |
| 764 |
|
|
| 765 |
void |
void unload_menu(MENU_SET *p_menu_set) |
|
unload_menu (MENU_SET * p_menu_set) |
|
| 766 |
{ |
{ |
| 767 |
MENU *p_menu; |
MENU *p_menu; |
| 768 |
MENU_ITEM *p_menuitem; |
int i, j; |
| 769 |
int i, j; |
|
| 770 |
|
for (i = 0; i < p_menu_set->menu_count; i++) |
|
for (i = 0; i < p_menu_set->menu_count; i++) |
|
|
{ |
|
|
p_menu = p_menu_set->p_menu[i]; |
|
|
for (j = 0; j < p_menu->item_count; j++) |
|
| 771 |
{ |
{ |
| 772 |
free (p_menu->items[j]); |
p_menu = p_menu_set->p_menu[i]; |
| 773 |
|
for (j = 0; j < p_menu->item_count; j++) |
| 774 |
|
{ |
| 775 |
|
free(p_menu->items[j]); |
| 776 |
|
} |
| 777 |
|
free(p_menu); |
| 778 |
} |
} |
|
free (p_menu); |
|
|
} |
|
| 779 |
|
|
| 780 |
p_menu_set->menu_count = 0; |
p_menu_set->menu_count = 0; |
| 781 |
p_menu_set->menu_select_depth = 0; |
p_menu_set->menu_select_depth = 0; |
| 782 |
|
} |
| 783 |
|
|
| 784 |
|
int reload_menu(MENU_SET *p_menu_set) |
| 785 |
|
{ |
| 786 |
|
int result; |
| 787 |
|
char conf_file[FILE_PATH_LEN]; |
| 788 |
|
|
| 789 |
|
strncpy(conf_file, p_menu_set->conf_file, sizeof(conf_file) - 1); |
| 790 |
|
conf_file[sizeof(conf_file) - 1] = '\0'; |
| 791 |
|
|
| 792 |
|
unload_menu(p_menu_set); |
| 793 |
|
result = load_menu(p_menu_set, conf_file); |
| 794 |
|
|
| 795 |
|
return result; |
| 796 |
} |
} |