| 17 |
|
|
| 18 |
#include "menu.h" |
#include "menu.h" |
| 19 |
#include "io.h" |
#include "io.h" |
| 20 |
|
#include "common.h" |
| 21 |
#include <stdio.h> |
#include <stdio.h> |
| 22 |
#include <ctype.h> |
#include <ctype.h> |
| 23 |
|
#include <regex.h> |
| 24 |
|
|
| 25 |
MENU bbs_main_menu; |
MENU_SET bbs_menu; |
| 26 |
|
|
| 27 |
int |
int |
| 28 |
load_menu (MENU *p_menu, const char *conf_file) |
load_menu (MENU *p_menu, const char *conf_file) |
| 29 |
{ |
{ |
| 30 |
FILE *fin; |
FILE *fin, *fout; |
| 31 |
int i = 0; |
int i = 0; |
| 32 |
|
char buffer[256], screen_filename[256], temp[256]; |
| 33 |
|
regmatch_t pmatch[10]; |
| 34 |
|
|
| 35 |
if ((fin = fopen (conf_file, "r")) == NULL) |
if ((fin = fopen (conf_file, "r")) == NULL) |
| 36 |
{ |
{ |
| 38 |
return -1; |
return -1; |
| 39 |
} |
} |
| 40 |
|
|
| 41 |
while (fscanf (fin, "%d %d %c ", &((p_menu->items[i]).row), |
while (fgets (buffer, 255, fin)) |
| 42 |
&((p_menu->items[i]).col), &((p_menu->items[i]).key)) != EOF) |
{ |
| 43 |
{ |
switch (buffer[0]) |
| 44 |
fgets((p_menu->items[i]).text, MAX_MENUITEM_LENGTH, fin); |
{ |
| 45 |
|
case '#': |
| 46 |
|
break; |
| 47 |
|
case '%': |
| 48 |
|
if (ireg ("^%S_([A-Za-z0-9_]+)", buffer, 1, pmatch) == 0) |
| 49 |
|
{ |
| 50 |
|
strncpy (temp, buffer + pmatch[0].rm_so, |
| 51 |
|
pmatch[0].rm_eo - pmatch[0].rm_so + 1); |
| 52 |
|
sprintf (screen_filename, "%sMENU_SCR_%s", |
| 53 |
|
app_temp_dir, temp); |
| 54 |
|
|
| 55 |
|
if ((fout = fopen (screen_filename, "w")) == NULL) |
| 56 |
|
{ |
| 57 |
|
log_error ("Open %s failed", screen_filename); |
| 58 |
|
return -2; |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
while (fgets (buffer, 255, fin)) |
| 62 |
|
{ |
| 63 |
|
if (buffer[0] != '%') |
| 64 |
|
fputs (buffer, fout); |
| 65 |
|
else |
| 66 |
|
break; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
fclose (fout); |
| 70 |
|
break; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
if (ireg ("^%S_([A-Za-z0-9_]+)", buffer, 1, pmatch) == 0) |
| 74 |
|
{ |
| 75 |
|
} |
| 76 |
|
break; |
| 77 |
|
} |
| 78 |
|
fscanf (fin, "%d %d %s ", &((p_menu->items[i]).row), |
| 79 |
|
&((p_menu->items[i]).col), &((p_menu->items[i]).name)); |
| 80 |
|
fgets ((p_menu->items[i]).text, MAX_MENUITEM_LENGTH, fin); |
| 81 |
i++; |
i++; |
| 82 |
} |
} |
| 83 |
|
|
| 84 |
|
fclose (fin); |
| 85 |
|
|
| 86 |
p_menu->item_count = i; |
p_menu->item_count = i; |
| 87 |
p_menu->item_cur_pos = 0; |
p_menu->item_cur_pos = 0; |
| 88 |
|
|