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

Annotation of /lbbs/src/menu.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Mar 18 16:04:16 2005 UTC (21 years ago) by sysadm
Branch: MAIN
Content type: text/x-csrc
*** empty log message ***

1 sysadm 1.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 <stdio.h>
21     #include <ctype.h>
22    
23     MENU bbs_main_menu;
24    
25     int
26     load_menu (MENU *p_menu, const char *conf_file)
27     {
28     FILE *fin;
29     int i = 0;
30    
31     if ((fin = fopen (conf_file, "r")) == NULL)
32     {
33     log_error ("Open %s failed", conf_file);
34     return -1;
35     }
36    
37     while (fscanf (fin, "%d %d %c ", &((p_menu->items[i]).row),
38     &((p_menu->items[i]).col), &((p_menu->items[i]).key)) != EOF)
39     {
40     fgets((p_menu->items[i]).text, MAX_MENUITEM_LENGTH, fin);
41     i++;
42     }
43    
44     p_menu->item_count = i;
45     p_menu->item_cur_pos = 0;
46    
47     return 0;
48     }
49    
50     void
51     display_menu_cursor (MENU *p_menu, int show)
52     {
53     moveto ((p_menu->items[p_menu->item_cur_pos]).row,
54     (p_menu->items[p_menu->item_cur_pos]).col - 2);
55     prints (show ? ">" : " ");
56     iflush ();
57     }
58    
59     int
60     display_menu (MENU *p_menu)
61     {
62     int i;
63    
64     for (i = 0; i < p_menu->item_count; i++)
65     {
66     moveto ((p_menu->items[i]).row, (p_menu->items[i]).col);
67     prints ((p_menu->items[i]).text);
68     iflush ();
69     }
70     display_menu_cursor (p_menu, 1);
71    
72     return 0;
73     }
74    
75     char
76     menu_control (MENU *p_menu, int key)
77     {
78     int i;
79    
80     switch (key)
81     {
82     case CR:
83     case KEY_RIGHT:
84     return ((p_menu->items[p_menu->item_cur_pos]).key);
85     case KEY_UP:
86     display_menu_cursor (p_menu, 0);
87     p_menu->item_cur_pos --;
88     if (p_menu->item_cur_pos < 0)
89     p_menu->item_cur_pos = p_menu->item_count - 1;
90     display_menu_cursor (p_menu, 1);
91     break;
92     case KEY_DOWN:
93     display_menu_cursor (p_menu, 0);
94     p_menu->item_cur_pos ++;
95     if (p_menu->item_cur_pos >= p_menu->item_count)
96     p_menu->item_cur_pos = 0;
97     display_menu_cursor (p_menu, 1);
98     break;
99     default:
100     for (i = 0; i < p_menu->item_count; i++)
101     {
102     if (toupper(key) == toupper((p_menu->items[i]).key))
103     {
104     display_menu_cursor (p_menu, 0);
105     p_menu->item_cur_pos = i;
106     display_menu_cursor (p_menu, 1);
107     break;
108     }
109     }
110     }
111    
112     return '\0';
113     }

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