drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / payloads / libpayload / curses / PDCurses / demos / ptest.c
blob6071f79d0e9b34a98b9c4471653c31695d31f45c
1 /* $Id: ptest.c,v 1.24 2008/07/13 16:08:17 wmcbrine Exp $ */
3 #include <curses.h>
4 #include <panel.h>
5 #include <stdlib.h>
7 PANEL *p1, *p2, *p3, *p4, *p5;
8 WINDOW *w4, *w5;
10 long nap_msec = 1;
12 char *mod[] =
14 "test ", "TEST ", "(**) ", "*()* ", "<--> ", "LAST "
17 void pflush(void)
19 update_panels();
20 doupdate();
23 void backfill(void)
25 int y, x;
27 erase();
29 for (y = 0; y < LINES - 1; y++)
30 for (x = 0; x < COLS; x++)
31 printw("%d", (y + x) % 10);
34 void wait_a_while(long msec)
36 int c;
38 if (msec != 1)
39 timeout(msec);
41 c = getch();
43 if (c == 'q')
45 endwin();
46 exit(1);
50 void saywhat(const char *text)
52 mvprintw(LINES - 1, 0, "%-20.20s", text);
55 /* mkpanel - alloc a win and panel and associate them */
57 PANEL *mkpanel(int rows, int cols, int tly, int tlx)
59 WINDOW *win = newwin(rows, cols, tly, tlx);
60 PANEL *pan = (PANEL *)0;
62 if (win)
64 pan = new_panel(win);
66 if (!pan)
67 delwin(win);
70 return pan;
73 void rmpanel(PANEL *pan)
75 WINDOW *win = pan->win;
77 del_panel(pan);
78 delwin(win);
81 void fill_panel(PANEL *pan)
83 WINDOW *win = pan->win;
84 char num = *((char *)pan->user + 1);
85 int y, x, maxy, maxx;
87 box(win, 0, 0);
88 mvwprintw(win, 1, 1, "-pan%c-", num);
89 getmaxyx(win, maxy, maxx);
91 for (y = 2; y < maxy - 1; y++)
92 for (x = 1; x < maxx - 1; x++)
93 mvwaddch(win, y, x, num);
96 int main(int argc, char **argv)
98 int itmp, y;
100 if (argc > 1 && atol(argv[1]))
101 nap_msec = atol(argv[1]);
103 #ifdef XCURSES
104 Xinitscr(argc, argv);
105 #else
106 initscr();
107 #endif
108 backfill();
110 for (y = 0; y < 5; y++)
112 p1 = mkpanel(10, 10, 0, 0);
113 set_panel_userptr(p1, "p1");
115 p2 = mkpanel(14, 14, 5, 5);
116 set_panel_userptr(p2, "p2");
118 p3 = mkpanel(6, 8, 12, 12);
119 set_panel_userptr(p3, "p3");
121 p4 = mkpanel(10, 10, 10, 30);
122 w4 = panel_window(p4);
123 set_panel_userptr(p4, "p4");
125 p5 = mkpanel(10, 10, 13, 37);
126 w5 = panel_window(p5);
127 set_panel_userptr(p5, "p5");
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);
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);
149 saywhat("s1;");
150 show_panel(p1);
151 pflush();
152 wait_a_while(nap_msec);
154 saywhat("s2;");
155 show_panel(p2);
156 pflush();
157 wait_a_while(nap_msec);
159 saywhat("m2;");
160 move_panel(p2, 10, 10);
161 pflush();
162 wait_a_while(nap_msec);
164 saywhat("s3;");
165 show_panel(p3);
166 pflush();
167 wait_a_while(nap_msec);
169 saywhat("m3;");
170 move_panel(p3, 5, 5);
171 pflush();
172 wait_a_while(nap_msec);
174 saywhat("b3;");
175 bottom_panel(p3);
176 pflush();
177 wait_a_while(nap_msec);
179 saywhat("s4;");
180 show_panel(p4);
181 pflush();
182 wait_a_while(nap_msec);
184 saywhat("s5;");
185 show_panel(p5);
186 pflush();
187 wait_a_while(nap_msec);
189 saywhat("t3;");
190 top_panel(p3);
191 pflush();
192 wait_a_while(nap_msec);
194 saywhat("t1;");
195 top_panel(p1);
196 pflush();
197 wait_a_while(nap_msec);
199 saywhat("t2;");
200 top_panel(p2);
201 pflush();
202 wait_a_while(nap_msec);
204 saywhat("t3;");
205 top_panel(p3);
206 pflush();
207 wait_a_while(nap_msec);
209 saywhat("t4;");
210 top_panel(p4);
211 pflush();
212 wait_a_while(nap_msec);
214 for (itmp = 0; itmp < 6; itmp++)
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);
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);
231 saywhat("m4;");
232 move_panel(p4, 4, itmp * 10);
233 pflush();
234 wait_a_while(nap_msec);
236 saywhat("t5;");
237 top_panel(p5);
238 pflush();
239 wait_a_while(nap_msec);
241 saywhat("t2;");
242 top_panel(p2);
243 pflush();
244 wait_a_while(nap_msec);
246 saywhat("t1;");
247 top_panel(p1);
248 pflush();
249 wait_a_while(nap_msec);
251 saywhat("d2;");
252 rmpanel(p2);
253 pflush();
254 wait_a_while(nap_msec);
256 saywhat("h3;");
257 hide_panel(p3);
258 pflush();
259 wait_a_while(nap_msec);
261 saywhat("d1;");
262 rmpanel(p1);
263 pflush();
264 wait_a_while(nap_msec);
266 saywhat("d4; ");
267 rmpanel(p4);
268 pflush();
269 wait_a_while(nap_msec);
271 saywhat("d5; ");
272 rmpanel(p5);
273 pflush();
274 wait_a_while(nap_msec);
276 if (nap_msec == 1)
277 break;
279 nap_msec = 100L;
282 endwin();
284 return 0;
285 } /* end of main */