annotate kconfig/lxdialog/yesno.c @ 10:4d21d59f3206

Add menuconfig, plus some basic Config info, lots of which is just future plans for toysh. Nothing's currently _using_ this config info, but at least it's being generated now.
author landley@driftwood
date Tue, 31 Oct 2006 23:30:06 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
1 /*
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
2 * yesno.c -- implements the yes/no box
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
3 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
6 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
9 * as published by the Free Software Foundation; either version 2
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
10 * of the License, or (at your option) any later version.
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
11 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
15 * GNU General Public License for more details.
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
16 *
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
20 */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
21
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
22 #include "dialog.h"
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
23
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
24 /*
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
25 * Display termination buttons
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
26 */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
27 static void print_buttons(WINDOW * dialog, int height, int width, int selected)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
28 {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
29 int x = width / 2 - 10;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
30 int y = height - 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
31
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
32 print_button(dialog, " Yes ", y, x, selected == 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
33 print_button(dialog, " No ", y, x + 13, selected == 1);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
34
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
35 wmove(dialog, y, x + 1 + 13 * selected);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
36 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
37 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
38
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
39 /*
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
40 * Display a dialog box with two buttons - Yes and No
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
41 */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
42 int dialog_yesno(const char *title, const char *prompt, int height, int width)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
43 {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
44 int i, x, y, key = 0, button = 0;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
45 WINDOW *dialog;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
46
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
47 do_resize:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
48 if (getmaxy(stdscr) < (height + 4))
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
49 return -ERRDISPLAYTOOSMALL;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
50 if (getmaxx(stdscr) < (width + 4))
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
51 return -ERRDISPLAYTOOSMALL;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
52
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
53 /* center dialog box on screen */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
54 x = (COLS - width) / 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
55 y = (LINES - height) / 2;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
56
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
57 draw_shadow(stdscr, y, x, height, width);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
58
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
59 dialog = newwin(height, width, y, x);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
60 keypad(dialog, TRUE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
61
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
62 draw_box(dialog, 0, 0, height, width,
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
63 dlg.dialog.atr, dlg.border.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
64 wattrset(dialog, dlg.border.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
65 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
66 for (i = 0; i < width - 2; i++)
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
67 waddch(dialog, ACS_HLINE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
68 wattrset(dialog, dlg.dialog.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
69 waddch(dialog, ACS_RTEE);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
70
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
71 print_title(dialog, title, width);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
72
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
73 wattrset(dialog, dlg.dialog.atr);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
74 print_autowrap(dialog, prompt, width - 2, 1, 3);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
75
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
76 print_buttons(dialog, height, width, 0);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
77
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
78 while (key != KEY_ESC) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
79 key = wgetch(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
80 switch (key) {
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
81 case 'Y':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
82 case 'y':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
83 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
84 return 0;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
85 case 'N':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
86 case 'n':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
87 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
88 return 1;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
89
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
90 case TAB:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
91 case KEY_LEFT:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
92 case KEY_RIGHT:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
93 button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
94
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
95 print_buttons(dialog, height, width, button);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
96 wrefresh(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
97 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
98 case ' ':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
99 case '\n':
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
100 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
101 return button;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
102 case KEY_ESC:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
103 key = on_key_esc(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
104 break;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
105 case KEY_RESIZE:
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
106 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
107 on_key_resize();
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
108 goto do_resize;
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
109 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
110 }
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
111
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
112 delwin(dialog);
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
113 return key; /* ESC pressed */
4d21d59f3206 Add menuconfig, plus some basic Config info, lots of which is just future
landley@driftwood
parents:
diff changeset
114 }