/[LeafOK_CVS]/lbbs/src/menu.c
ViewVC logotype

Contents of /lbbs/src/menu.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Sat Mar 19 08:23:05 2005 UTC (21 years ago) by sysadm
Branch: MAIN
Changes since 1.1: +48 -6 lines
Content type: text/x-csrc
*** empty log message ***

1 /***************************************************************************
2 menu.c - description
3 -------------------
4 begin : Wed Mar 16 2004
5 copyright : (C) 2005 by Leaflet
6 email : leaflet@leafok.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "menu.h"
19 #include "io.h"
20 #include "common.h"
21 #include <stdio.h>
22 #include <ctype.h>
23 #include <regex.h>
24
25 MENU_SET bbs_menu;
26
27 int
28 load_menu (MENU *p_menu, const char *conf_file)
29 {
30 FILE *fin, *fout;
31 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)
36 {
37 log_error ("Open %s failed", conf_file);
38 return -1;
39 }
40
41 while (fgets (buffer, 255, fin))
42 {
43 switch (buffer[0])
44 {
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++;
82 }
83
84 fclose (fin);
85
86 p_menu->item_count = i;
87 p_menu->item_cur_pos = 0;
88
89 return 0;
90 }
91
92 void
93 display_menu_cursor (MENU *p_menu, int show)
94 {
95 moveto ((p_menu->items[p_menu->item_cur_pos]).row,
96 (p_menu->items[p_menu->item_cur_pos]).col - 2);
97 prints (show ? ">" : " ");
98 iflush ();
99 }
100
101 int
102 display_menu (MENU *p_menu)
103 {
104 int i;
105
106 for (i = 0; i < p_menu->item_count; i++)
107 {
108 moveto ((p_menu->items[i]).row, (p_menu->items[i]).col);
109 prints ((p_menu->items[i]).text);
110 iflush ();
111 }
112 display_menu_cursor (p_menu, 1);
113
114 return 0;
115 }
116
117 char
118 menu_control (MENU *p_menu, int key)
119 {
120 int i;
121
122 switch (key)
123 {
124 case CR:
125 case KEY_RIGHT:
126 return ((p_menu->items[p_menu->item_cur_pos]).key);
127 case KEY_UP:
128 display_menu_cursor (p_menu, 0);
129 p_menu->item_cur_pos --;
130 if (p_menu->item_cur_pos < 0)
131 p_menu->item_cur_pos = p_menu->item_count - 1;
132 display_menu_cursor (p_menu, 1);
133 break;
134 case KEY_DOWN:
135 display_menu_cursor (p_menu, 0);
136 p_menu->item_cur_pos ++;
137 if (p_menu->item_cur_pos >= p_menu->item_count)
138 p_menu->item_cur_pos = 0;
139 display_menu_cursor (p_menu, 1);
140 break;
141 default:
142 for (i = 0; i < p_menu->item_count; i++)
143 {
144 if (toupper(key) == toupper((p_menu->items[i]).key))
145 {
146 display_menu_cursor (p_menu, 0);
147 p_menu->item_cur_pos = i;
148 display_menu_cursor (p_menu, 1);
149 break;
150 }
151 }
152 }
153
154 return '\0';
155 }

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