drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / demos / tuidemo.c
blob6f4d9f21df430f6296c2121ccb53f1fa9f2cf6b9
1 /*
2 * $Id: tuidemo.c,v 1.22 2008/07/14 12:35:23 wmcbrine Exp $
4 * Author : P.J. Kunst <kunst@prl.philips.nl>
5 * Date : 25-02-93
7 * Purpose: This program demonstrates the use of the 'curses' library
8 * for the creation of (simple) menu-operated programs.
9 * In the PDCurses version, use is made of colors for the
10 * highlighting of subwindows (title bar, status bar etc).
12 * Acknowledgement: some ideas were borrowed from Mark Hessling's
13 * version of the 'testcurs' program.
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <locale.h>
20 #include "tui.h"
22 /* change this if source at other location */
24 #ifdef XCURSES
25 # define FNAME "../demos/tui.c"
26 #else
27 # define FNAME "..\\demos\\tui.c"
28 #endif
30 /**************************** strings entry box ***************************/
32 void address(void)
34 char *fieldname[6] =
36 "Name", "Street", "City", "State", "Country", (char *)0
39 char *fieldbuf[5];
40 WINDOW *wbody = bodywin();
41 int i, field = 50;
43 for (i = 0; i < 5; i++)
44 fieldbuf[i] = calloc(1, field + 1);
46 if (getstrings(fieldname, fieldbuf, field) != KEY_ESC)
48 for (i = 0; fieldname[i]; i++)
49 wprintw(wbody, "%10s : %s\n",
50 fieldname[i], fieldbuf[i]);
52 wrefresh(wbody);
55 for (i = 0; i < 5; i++)
56 free(fieldbuf[i]);
59 /**************************** string entry box ****************************/
61 char *getfname(char *desc, char *fname, int field)
63 char *fieldname[2];
64 char *fieldbuf[1];
66 fieldname[0] = desc;
67 fieldname[1] = 0;
68 fieldbuf[0] = fname;
70 return (getstrings(fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname;
73 /**************************** a very simple file browser ******************/
75 void showfile(char *fname)
77 int i, bh = bodylen();
78 FILE *fp;
79 char buf[MAXSTRLEN];
80 bool ateof = FALSE;
82 statusmsg("FileBrowser: Hit key to continue, Q to quit");
84 if ((fp = fopen(fname, "r")) != NULL) /* file available? */
86 while (!ateof)
88 clsbody();
90 for (i = 0; i < bh - 1 && !ateof; i++)
92 buf[0] = '\0';
93 fgets(buf, MAXSTRLEN, fp);
95 if (strlen(buf))
96 bodymsg(buf);
97 else
98 ateof = TRUE;
101 switch (waitforkey())
103 case 'Q':
104 case 'q':
105 case 0x1b:
106 ateof = TRUE;
110 fclose(fp);
112 else
114 sprintf(buf, "ERROR: file '%s' not found", fname);
115 errormsg(buf);
119 /***************************** forward declarations ***********************/
121 void sub0(void), sub1(void), sub2(void), sub3(void);
122 void func1(void), func2(void);
123 void subfunc1(void), subfunc2(void);
124 void subsub(void);
126 /***************************** menus initialization ***********************/
128 menu MainMenu[] =
130 { "Asub", sub0, "Go inside first submenu" },
131 { "Bsub", sub1, "Go inside second submenu" },
132 { "Csub", sub2, "Go inside third submenu" },
133 { "Dsub", sub3, "Go inside fourth submenu" },
134 { "", (FUNC)0, "" } /* always add this as the last item! */
137 menu SubMenu0[] =
139 { "Exit", DoExit, "Terminate program" },
140 { "", (FUNC)0, "" }
143 menu SubMenu1[] =
145 { "OneBeep", func1, "Sound one beep" },
146 { "TwoBeeps", func2, "Sound two beeps" },
147 { "", (FUNC)0, "" }
150 menu SubMenu2[] =
152 { "Browse", subfunc1, "Source file lister" },
153 { "Input", subfunc2, "Interactive file lister" },
154 { "Address", address, "Get address data" },
155 { "", (FUNC)0, "" }
158 menu SubMenu3[] =
160 { "SubSub", subsub, "Go inside sub-submenu" },
161 { "", (FUNC)0, "" }
164 /***************************** main menu functions ************************/
166 void sub0(void)
168 domenu(SubMenu0);
171 void sub1(void)
173 domenu(SubMenu1);
176 void sub2(void)
178 domenu(SubMenu2);
181 void sub3(void)
183 domenu(SubMenu3);
186 /***************************** submenu1 functions *************************/
188 void func1(void)
190 beep();
191 bodymsg("One beep! ");
194 void func2(void)
196 beep();
197 bodymsg("Two beeps! ");
198 beep();
201 /***************************** submenu2 functions *************************/
203 void subfunc1(void)
205 showfile(FNAME);
208 void subfunc2(void)
210 char fname[MAXSTRLEN];
212 strcpy(fname, FNAME);
213 if (getfname ("File to browse:", fname, 50))
214 showfile(fname);
217 /***************************** submenu3 functions *************************/
219 void subsub(void)
221 domenu(SubMenu2);
224 /***************************** start main menu ***************************/
226 int main(int argc, char **argv)
228 setlocale(LC_ALL, "");
230 startmenu(MainMenu, "TUI - 'textual user interface' demonstration program");
232 return 0;