libpayload: remove trailing whitespace and run dos2unix
[coreboot.git] / payloads / libpayload / curses / PDCurses-3.4 / demos / ptest.c
1 /* $Id: ptest.c,v 1.24 2008/07/13 16:08:17 wmcbrine Exp $ */
2
3 #include <curses.h>
4 #include <panel.h>
5 #include <stdlib.h>
6
7 PANEL *p1, *p2, *p3, *p4, *p5;
8 WINDOW *w4, *w5;
9
10 long nap_msec = 1;
11
12 char *mod[] =
13 {
14     "test ", "TEST ", "(**) ", "*()* ", "<--> ", "LAST "
15 };
16
17 void pflush(void)
18 {
19     update_panels();
20     doupdate();
21 }
22
23 void backfill(void)
24 {
25     int y, x;
26
27     erase();
28
29     for (y = 0; y < LINES - 1; y++)
30         for (x = 0; x < COLS; x++)
31             printw("%d", (y + x) % 10);
32 }
33
34 void wait_a_while(long msec)
35 {
36     int c;
37
38     if (msec != 1)
39         timeout(msec);
40
41     c = getch();
42
43     if (c == 'q')
44     {
45         endwin();
46         exit(1);
47     }
48 }
49
50 void saywhat(const char *text)
51 {
52     mvprintw(LINES - 1, 0, "%-20.20s", text);
53 }
54
55 /* mkpanel - alloc a win and panel and associate them */
56
57 PANEL *mkpanel(int rows, int cols, int tly, int tlx)
58 {
59     WINDOW *win = newwin(rows, cols, tly, tlx);
60     PANEL *pan = (PANEL *)0;
61
62     if (win)
63     {
64         pan = new_panel(win);
65
66         if (!pan)
67             delwin(win);
68     }
69
70     return pan;
71 }
72
73 void rmpanel(PANEL *pan)
74 {
75     WINDOW *win = pan->win;
76
77     del_panel(pan);
78     delwin(win);
79 }
80
81 void fill_panel(PANEL *pan)
82 {
83     WINDOW *win = pan->win;
84     char num = *((char *)pan->user + 1);
85     int y, x, maxy, maxx;
86
87     box(win, 0, 0);
88     mvwprintw(win, 1, 1, "-pan%c-", num);
89     getmaxyx(win, maxy, maxx);
90
91     for (y = 2; y < maxy - 1; y++)
92         for (x = 1; x < maxx - 1; x++)
93             mvwaddch(win, y, x, num);
94 }
95
96 int main(int argc, char **argv)
97 {
98     int itmp, y;
99
100     if (argc > 1 && atol(argv[1]))
101         nap_msec = atol(argv[1]);
102
103 #ifdef XCURSES
104     Xinitscr(argc, argv);
105 #else
106     initscr();
107 #endif
108     backfill();
109
110     for (y = 0; y < 5; y++)
111     {
112         p1 = mkpanel(10, 10, 0, 0);
113         set_panel_userptr(p1, "p1");
114
115         p2 = mkpanel(14, 14, 5, 5);
116         set_panel_userptr(p2, "p2");
117
118         p3 = mkpanel(6, 8, 12, 12);
119         set_panel_userptr(p3, "p3");
120
121         p4 = mkpanel(10, 10, 10, 30);
122         w4 = panel_window(p4);
123         set_panel_userptr(p4, "p4");
124
125         p5 = mkpanel(10, 10, 13, 37);
126         w5 = panel_window(p5);
127         set_panel_userptr(p5, "p5");
128
129         fill_panel(p1);
130         fill_panel(p2);
131         fill_panel(p3);
132         fill_panel(p4);
133         fill_panel(p5);
134         hide_panel(p4);
135         hide_panel(p5);
136         pflush();
137         wait_a_while(nap_msec);
138
139         saywhat("h3 s1 s2 s4 s5;");
140         move_panel(p1, 0, 0);
141         hide_panel(p3);
142         show_panel(p1);
143         show_panel(p2);
144         show_panel(p4);
145         show_panel(p5);
146         pflush();
147         wait_a_while(nap_msec);
148
149         saywhat("s1;");
150         show_panel(p1);
151         pflush();
152         wait_a_while(nap_msec);
153
154         saywhat("s2;");
155         show_panel(p2);
156         pflush();
157         wait_a_while(nap_msec);
158
159         saywhat("m2;");
160         move_panel(p2, 10, 10);
161         pflush();
162         wait_a_while(nap_msec);
163
164         saywhat("s3;");
165         show_panel(p3);
166         pflush();
167         wait_a_while(nap_msec);
168
169         saywhat("m3;");
170         move_panel(p3, 5, 5);
171         pflush();
172         wait_a_while(nap_msec);
173
174         saywhat("b3;");
175         bottom_panel(p3);
176         pflush();
177         wait_a_while(nap_msec);
178
179         saywhat("s4;");
180         show_panel(p4);
181         pflush();
182         wait_a_while(nap_msec);
183
184         saywhat("s5;");
185         show_panel(p5);
186         pflush();
187         wait_a_while(nap_msec);
188
189         saywhat("t3;");
190         top_panel(p3);
191         pflush();
192         wait_a_while(nap_msec);
193
194         saywhat("t1;");
195         top_panel(p1);
196         pflush();
197         wait_a_while(nap_msec);
198
199         saywhat("t2;");
200         top_panel(p2);
201         pflush();
202         wait_a_while(nap_msec);
203
204         saywhat("t3;");
205         top_panel(p3);
206         pflush();
207         wait_a_while(nap_msec);
208
209         saywhat("t4;");
210         top_panel(p4);
211         pflush();
212         wait_a_while(nap_msec);
213
214         for (itmp = 0; itmp < 6; itmp++)
215         {
216             saywhat("m4;");
217             mvwaddstr(w4, 3, 1, mod[itmp]);
218             move_panel(p4, 4, itmp * 10);
219             mvwaddstr(w5, 4, 1, mod[itmp]);
220             pflush();
221             wait_a_while(nap_msec);
222
223             saywhat("m5;");
224             mvwaddstr(w4, 4, 1, mod[itmp]);
225             move_panel(p5, 7, itmp * 10 + 6);
226             mvwaddstr(w5, 3, 1, mod[itmp]);
227             pflush();
228             wait_a_while(nap_msec);
229         }
230
231         saywhat("m4;");
232         move_panel(p4, 4, itmp * 10);
233         pflush();
234         wait_a_while(nap_msec);
235
236         saywhat("t5;");
237         top_panel(p5);
238         pflush();
239         wait_a_while(nap_msec);
240
241         saywhat("t2;");
242         top_panel(p2);
243         pflush();
244         wait_a_while(nap_msec);
245
246         saywhat("t1;");
247         top_panel(p1);
248         pflush();
249         wait_a_while(nap_msec);
250
251         saywhat("d2;");
252         rmpanel(p2);
253         pflush();
254         wait_a_while(nap_msec);
255
256         saywhat("h3;");
257         hide_panel(p3);
258         pflush();
259         wait_a_while(nap_msec);
260
261         saywhat("d1;");
262         rmpanel(p1);
263         pflush();
264         wait_a_while(nap_msec);
265
266         saywhat("d4; ");
267         rmpanel(p4);
268         pflush();
269         wait_a_while(nap_msec);
270
271         saywhat("d5; ");
272         rmpanel(p5);
273         pflush();
274         wait_a_while(nap_msec);
275
276         if (nap_msec == 1)
277             break;
278
279         nap_msec = 100L;
280     }
281
282     endwin();
283
284     return 0;
285 }   /* end of main */