aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-10-03 11:51:38 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-03 11:51:38 -0400
commitb4a9071af62f95dc6d22040a0b37ac7225ce4d54 (patch)
treeb40a3ec798f42674f0ff62a071ff4c29348c8605 /scripts
parent8b2a1fd1b394c60eaa2587716102dd5e9b4e5990 (diff)
parent99c8b9477f2b8c4f625545c41f0318570fa38894 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild
* git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild: kbuild: trivial documentation fixes kconfig: fix saving alternate kconfig file in parent dir kbuild: make modpost processing configurable kconfig/menuconfig: do not let ncurses clutter screen on exit kconfig/lxdialog: clear long menu lines kbuild: do not build mconf & lxdialog unless needed kconfig/lxdialog: fix make mrproper kconfig/lxdialog: support resize kconfig/lxdialog: let <ESC><ESC> behave as expected kconfig/menuconfig: lxdialog is now built-in kconfig/lxdialog: add a new theme bluetitle which is now default kconfig/lxdialog: add support for color themes and add blackbg theme kconfig/lxdialog: refactor color support
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.modpost11
-rw-r--r--scripts/kconfig/Makefile31
-rw-r--r--scripts/kconfig/confdata.c2
-rw-r--r--scripts/kconfig/lxdialog/Makefile21
-rw-r--r--scripts/kconfig/lxdialog/checklist.c183
-rw-r--r--scripts/kconfig/lxdialog/colors.h154
-rw-r--r--scripts/kconfig/lxdialog/dialog.h144
-rw-r--r--scripts/kconfig/lxdialog/inputbox.c48
-rw-r--r--scripts/kconfig/lxdialog/lxdialog.c204
-rw-r--r--scripts/kconfig/lxdialog/menubox.c166
-rw-r--r--scripts/kconfig/lxdialog/msgbox.c71
-rw-r--r--scripts/kconfig/lxdialog/textbox.c416
-rw-r--r--scripts/kconfig/lxdialog/util.c502
-rw-r--r--scripts/kconfig/lxdialog/yesno.c26
-rw-r--r--scripts/kconfig/mconf.c511
15 files changed, 1048 insertions, 1442 deletions
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 4b2721ca97da..6c5469b1473b 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -32,6 +32,10 @@
32# Step 4 is solely used to allow module versioning in external modules, 32# Step 4 is solely used to allow module versioning in external modules,
33# where the CRC of each module is retrieved from the Module.symers file. 33# where the CRC of each module is retrieved from the Module.symers file.
34 34
35# KBUILD_MODPOST_WARN can be set to avoid error out in case of undefined
36# symbols in the final module linking stage
37# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
38# This is solely usefull to speed up test compiles
35PHONY := _modpost 39PHONY := _modpost
36_modpost: __modpost 40_modpost: __modpost
37 41
@@ -46,7 +50,8 @@ modulesymfile := $(KBUILD_EXTMOD)/Module.symvers
46__modules := $(sort $(shell grep -h '\.ko' /dev/null $(wildcard $(MODVERDIR)/*.mod))) 50__modules := $(sort $(shell grep -h '\.ko' /dev/null $(wildcard $(MODVERDIR)/*.mod)))
47modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o))) 51modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o)))
48 52
49_modpost: $(modules) 53# Stop after building .o files if NOFINAL is set. Makes compile tests quicker
54_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
50 55
51 56
52# Step 2), invoke modpost 57# Step 2), invoke modpost
@@ -58,7 +63,7 @@ quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules
58 $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \ 63 $(if $(KBUILD_EXTMOD),-i,-o) $(kernelsymfile) \
59 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \ 64 $(if $(KBUILD_EXTMOD),-I $(modulesymfile)) \
60 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \ 65 $(if $(KBUILD_EXTMOD),-o $(modulesymfile)) \
61 $(if $(KBUILD_EXTMOD),-w) \ 66 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \
62 $(wildcard vmlinux) $(filter-out FORCE,$^) 67 $(wildcard vmlinux) $(filter-out FORCE,$^)
63 68
64PHONY += __modpost 69PHONY += __modpost
@@ -92,7 +97,7 @@ targets += $(modules:.ko=.mod.o)
92 97
93# Step 6), final link of the modules 98# Step 6), final link of the modules
94quiet_cmd_ld_ko_o = LD [M] $@ 99quiet_cmd_ld_ko_o = LD [M] $@
95 cmd_ld_ko_o = $(LD) $(LDFLAGS) $(LDFLAGS_MODULE) -o $@ \ 100 cmd_ld_ko_o = $(LD) $(LDFLAGS) $(LDFLAGS_MODULE) -o $@ \
96 $(filter-out FORCE,$^) 101 $(filter-out FORCE,$^)
97 102
98$(modules): %.ko :%.o %.mod.o FORCE 103$(modules): %.ko :%.o %.mod.o FORCE
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index a90d3cc76bfa..7e7e147875bf 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -11,7 +11,6 @@ gconfig: $(obj)/gconf
11 $< arch/$(ARCH)/Kconfig 11 $< arch/$(ARCH)/Kconfig
12 12
13menuconfig: $(obj)/mconf 13menuconfig: $(obj)/mconf
14 $(Q)$(MAKE) $(build)=scripts/kconfig/lxdialog
15 $< arch/$(ARCH)/Kconfig 14 $< arch/$(ARCH)/Kconfig
16 15
17config: $(obj)/conf 16config: $(obj)/conf
@@ -81,6 +80,23 @@ help:
81 @echo ' allyesconfig - New config where all options are accepted with yes' 80 @echo ' allyesconfig - New config where all options are accepted with yes'
82 @echo ' allnoconfig - New config where all options are answered with no' 81 @echo ' allnoconfig - New config where all options are answered with no'
83 82
83# lxdialog stuff
84check-lxdialog := $(srctree)/$(src)/lxdialog/check-lxdialog.sh
85
86# Use reursively expanded variables so we do not call gcc unless
87# we really need to do so. (Do not call gcc as part of make mrproper)
88HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags)
89HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC))
90
91HOST_EXTRACFLAGS += -DLOCALE
92
93PHONY += $(obj)/dochecklxdialog
94$(obj)/dochecklxdialog:
95 $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES)
96
97always := dochecklxdialog
98
99
84# =========================================================================== 100# ===========================================================================
85# Shared Makefile for the various kconfig executables: 101# Shared Makefile for the various kconfig executables:
86# conf: Used for defconfig, oldconfig and related targets 102# conf: Used for defconfig, oldconfig and related targets
@@ -92,11 +108,19 @@ help:
92# Based on GTK which needs to be installed to compile it 108# Based on GTK which needs to be installed to compile it
93# object files used by all kconfig flavours 109# object files used by all kconfig flavours
94 110
95hostprogs-y := conf mconf qconf gconf kxgettext 111lxdialog := lxdialog/checklist.o lxdialog/util.o lxdialog/inputbox.o
112lxdialog += lxdialog/textbox.o lxdialog/yesno.o lxdialog/menubox.o
113
96conf-objs := conf.o zconf.tab.o 114conf-objs := conf.o zconf.tab.o
97mconf-objs := mconf.o zconf.tab.o 115mconf-objs := mconf.o zconf.tab.o $(lxdialog)
98kxgettext-objs := kxgettext.o zconf.tab.o 116kxgettext-objs := kxgettext.o zconf.tab.o
99 117
118hostprogs-y := conf qconf gconf kxgettext
119
120ifeq ($(MAKECMDGOALS),menuconfig)
121 hostprogs-y += mconf
122endif
123
100ifeq ($(MAKECMDGOALS),xconfig) 124ifeq ($(MAKECMDGOALS),xconfig)
101 qconf-target := 1 125 qconf-target := 1
102endif 126endif
@@ -116,7 +140,6 @@ endif
116 140
117clean-files := lkc_defs.h qconf.moc .tmp_qtcheck \ 141clean-files := lkc_defs.h qconf.moc .tmp_qtcheck \
118 .tmp_gtkcheck zconf.tab.c lex.zconf.c zconf.hash.c 142 .tmp_gtkcheck zconf.tab.c lex.zconf.c zconf.hash.c
119subdir- += lxdialog
120 143
121# Needed for systems without gettext 144# Needed for systems without gettext
122KBUILD_HAVE_NLS := $(shell \ 145KBUILD_HAVE_NLS := $(shell \
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 69f96b398c22..66b15ef02931 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -517,7 +517,7 @@ int conf_write(const char *name)
517 fclose(out); 517 fclose(out);
518 518
519 if (*tmpname) { 519 if (*tmpname) {
520 strcat(dirname, name ? name : conf_get_configname()); 520 strcat(dirname, basename);
521 strcat(dirname, ".old"); 521 strcat(dirname, ".old");
522 rename(newname, dirname); 522 rename(newname, dirname);
523 if (rename(tmpname, newname)) 523 if (rename(tmpname, newname))
diff --git a/scripts/kconfig/lxdialog/Makefile b/scripts/kconfig/lxdialog/Makefile
deleted file mode 100644
index a8b026326247..000000000000
--- a/scripts/kconfig/lxdialog/Makefile
+++ /dev/null
@@ -1,21 +0,0 @@
1# Makefile to build lxdialog package
2#
3
4check-lxdialog := $(srctree)/$(src)/check-lxdialog.sh
5
6# Use reursively expanded variables so we do not call gcc unless
7# we really need to do so. (Do not call gcc as part of make mrproper)
8HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags)
9HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC))
10
11HOST_EXTRACFLAGS += -DLOCALE
12
13PHONY += dochecklxdialog
14$(obj)/dochecklxdialog:
15 $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES)
16
17hostprogs-y := lxdialog
18always := $(hostprogs-y) dochecklxdialog
19
20lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \
21 util.o lxdialog.o msgbox.o
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index 79886413b6d5..cf697080dddd 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -28,25 +28,25 @@ static int list_width, check_x, item_x;
28/* 28/*
29 * Print list item 29 * Print list item
30 */ 30 */
31static void print_item(WINDOW * win, const char *item, int status, int choice, 31static void print_item(WINDOW * win, int choice, int selected)
32 int selected)
33{ 32{
34 int i; 33 int i;
35 34
36 /* Clear 'residue' of last item */ 35 /* Clear 'residue' of last item */
37 wattrset(win, menubox_attr); 36 wattrset(win, dlg.menubox.atr);
38 wmove(win, choice, 0); 37 wmove(win, choice, 0);
39 for (i = 0; i < list_width; i++) 38 for (i = 0; i < list_width; i++)
40 waddch(win, ' '); 39 waddch(win, ' ');
41 40
42 wmove(win, choice, check_x); 41 wmove(win, choice, check_x);
43 wattrset(win, selected ? check_selected_attr : check_attr); 42 wattrset(win, selected ? dlg.check_selected.atr
44 wprintw(win, "(%c)", status ? 'X' : ' '); 43 : dlg.check.atr);
45 44 wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' ');
46 wattrset(win, selected ? tag_selected_attr : tag_attr); 45
47 mvwaddch(win, choice, item_x, item[0]); 46 wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr);
48 wattrset(win, selected ? item_selected_attr : item_attr); 47 mvwaddch(win, choice, item_x, item_str()[0]);
49 waddstr(win, (char *)item + 1); 48 wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
49 waddstr(win, (char *)item_str() + 1);
50 if (selected) { 50 if (selected) {
51 wmove(win, choice, check_x + 1); 51 wmove(win, choice, check_x + 1);
52 wrefresh(win); 52 wrefresh(win);
@@ -62,11 +62,11 @@ static void print_arrows(WINDOW * win, int choice, int item_no, int scroll,
62 wmove(win, y, x); 62 wmove(win, y, x);
63 63
64 if (scroll > 0) { 64 if (scroll > 0) {
65 wattrset(win, uarrow_attr); 65 wattrset(win, dlg.uarrow.atr);
66 waddch(win, ACS_UARROW); 66 waddch(win, ACS_UARROW);
67 waddstr(win, "(-)"); 67 waddstr(win, "(-)");
68 } else { 68 } else {
69 wattrset(win, menubox_attr); 69 wattrset(win, dlg.menubox.atr);
70 waddch(win, ACS_HLINE); 70 waddch(win, ACS_HLINE);
71 waddch(win, ACS_HLINE); 71 waddch(win, ACS_HLINE);
72 waddch(win, ACS_HLINE); 72 waddch(win, ACS_HLINE);
@@ -77,11 +77,11 @@ static void print_arrows(WINDOW * win, int choice, int item_no, int scroll,
77 wmove(win, y, x); 77 wmove(win, y, x);
78 78
79 if ((height < item_no) && (scroll + choice < item_no - 1)) { 79 if ((height < item_no) && (scroll + choice < item_no - 1)) {
80 wattrset(win, darrow_attr); 80 wattrset(win, dlg.darrow.atr);
81 waddch(win, ACS_DARROW); 81 waddch(win, ACS_DARROW);
82 waddstr(win, "(+)"); 82 waddstr(win, "(+)");
83 } else { 83 } else {
84 wattrset(win, menubox_border_attr); 84 wattrset(win, dlg.menubox_border.atr);
85 waddch(win, ACS_HLINE); 85 waddch(win, ACS_HLINE);
86 waddch(win, ACS_HLINE); 86 waddch(win, ACS_HLINE);
87 waddch(win, ACS_HLINE); 87 waddch(win, ACS_HLINE);
@@ -109,32 +109,29 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)
109 * in the style of radiolist (only one option turned on at a time). 109 * in the style of radiolist (only one option turned on at a time).
110 */ 110 */
111int dialog_checklist(const char *title, const char *prompt, int height, 111int dialog_checklist(const char *title, const char *prompt, int height,
112 int width, int list_height, int item_no, 112 int width, int list_height)
113 const char *const *items)
114{ 113{
115 int i, x, y, box_x, box_y; 114 int i, x, y, box_x, box_y;
116 int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; 115 int key = 0, button = 0, choice = 0, scroll = 0, max_choice;
117 WINDOW *dialog, *list; 116 WINDOW *dialog, *list;
118 117
119 /* Allocate space for storing item on/off status */ 118 /* which item to highlight */
120 if ((status = malloc(sizeof(int) * item_no)) == NULL) { 119 item_foreach() {
121 endwin(); 120 if (item_is_tag('X'))
122 fprintf(stderr, 121 choice = item_n();
123 "\nCan't allocate memory in dialog_checklist().\n"); 122 if (item_is_selected()) {
124 exit(-1); 123 choice = item_n();
124 break;
125 }
125 } 126 }
126 127
127 /* Initializes status */ 128do_resize:
128 for (i = 0; i < item_no; i++) { 129 if (getmaxy(stdscr) < (height + 6))
129 status[i] = !strcasecmp(items[i * 3 + 2], "on"); 130 return -ERRDISPLAYTOOSMALL;
130 if ((!choice && status[i]) 131 if (getmaxx(stdscr) < (width + 6))
131 || !strcasecmp(items[i * 3 + 2], "selected")) 132 return -ERRDISPLAYTOOSMALL;
132 choice = i + 1;
133 }
134 if (choice)
135 choice--;
136 133
137 max_choice = MIN(list_height, item_no); 134 max_choice = MIN(list_height, item_count());
138 135
139 /* center dialog box on screen */ 136 /* center dialog box on screen */
140 x = (COLS - width) / 2; 137 x = (COLS - width) / 2;
@@ -145,17 +142,18 @@ int dialog_checklist(const char *title, const char *prompt, int height,
145 dialog = newwin(height, width, y, x); 142 dialog = newwin(height, width, y, x);
146 keypad(dialog, TRUE); 143 keypad(dialog, TRUE);
147 144
148 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 145 draw_box(dialog, 0, 0, height, width,
149 wattrset(dialog, border_attr); 146 dlg.dialog.atr, dlg.border.atr);
147 wattrset(dialog, dlg.border.atr);
150 mvwaddch(dialog, height - 3, 0, ACS_LTEE); 148 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
151 for (i = 0; i < width - 2; i++) 149 for (i = 0; i < width - 2; i++)
152 waddch(dialog, ACS_HLINE); 150 waddch(dialog, ACS_HLINE);
153 wattrset(dialog, dialog_attr); 151 wattrset(dialog, dlg.dialog.atr);
154 waddch(dialog, ACS_RTEE); 152 waddch(dialog, ACS_RTEE);
155 153
156 print_title(dialog, title, width); 154 print_title(dialog, title, width);
157 155
158 wattrset(dialog, dialog_attr); 156 wattrset(dialog, dlg.dialog.atr);
159 print_autowrap(dialog, prompt, width - 2, 1, 3); 157 print_autowrap(dialog, prompt, width - 2, 1, 3);
160 158
161 list_width = width - 6; 159 list_width = width - 6;
@@ -170,12 +168,12 @@ int dialog_checklist(const char *title, const char *prompt, int height,
170 168
171 /* draw a box around the list items */ 169 /* draw a box around the list items */
172 draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, 170 draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
173 menubox_border_attr, menubox_attr); 171 dlg.menubox_border.atr, dlg.menubox.atr);
174 172
175 /* Find length of longest item in order to center checklist */ 173 /* Find length of longest item in order to center checklist */
176 check_x = 0; 174 check_x = 0;
177 for (i = 0; i < item_no; i++) 175 item_foreach()
178 check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); 176 check_x = MAX(check_x, strlen(item_str()) + 4);
179 177
180 check_x = (list_width - check_x) / 2; 178 check_x = (list_width - check_x) / 2;
181 item_x = check_x + 4; 179 item_x = check_x + 4;
@@ -187,14 +185,11 @@ int dialog_checklist(const char *title, const char *prompt, int height,
187 185
188 /* Print the list */ 186 /* Print the list */
189 for (i = 0; i < max_choice; i++) { 187 for (i = 0; i < max_choice; i++) {
190 if (i != choice) 188 item_set(scroll + i);
191 print_item(list, items[(scroll + i) * 3 + 1], 189 print_item(list, i, i == choice);
192 status[i + scroll], i, 0);
193 } 190 }
194 print_item(list, items[(scroll + choice) * 3 + 1],
195 status[choice + scroll], choice, 1);
196 191
197 print_arrows(dialog, choice, item_no, scroll, 192 print_arrows(dialog, choice, item_count(), scroll,
198 box_y, box_x + check_x + 5, list_height); 193 box_y, box_x + check_x + 5, list_height);
199 194
200 print_buttons(dialog, height, width, 0); 195 print_buttons(dialog, height, width, 0);
@@ -203,13 +198,14 @@ int dialog_checklist(const char *title, const char *prompt, int height,
203 wnoutrefresh(list); 198 wnoutrefresh(list);
204 doupdate(); 199 doupdate();
205 200
206 while (key != ESC) { 201 while (key != KEY_ESC) {
207 key = wgetch(dialog); 202 key = wgetch(dialog);
208 203
209 for (i = 0; i < max_choice; i++) 204 for (i = 0; i < max_choice; i++) {
210 if (toupper(key) == 205 item_set(i + scroll);
211 toupper(items[(scroll + i) * 3 + 1][0])) 206 if (toupper(key) == toupper(item_str()[0]))
212 break; 207 break;
208 }
213 209
214 if (i < max_choice || key == KEY_UP || key == KEY_DOWN || 210 if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
215 key == '+' || key == '-') { 211 key == '+' || key == '-') {
@@ -220,15 +216,16 @@ int dialog_checklist(const char *title, const char *prompt, int height,
220 /* Scroll list down */ 216 /* Scroll list down */
221 if (list_height > 1) { 217 if (list_height > 1) {
222 /* De-highlight current first item */ 218 /* De-highlight current first item */
223 print_item(list, items[scroll * 3 + 1], 219 item_set(scroll);
224 status[scroll], 0, FALSE); 220 print_item(list, 0, FALSE);
225 scrollok(list, TRUE); 221 scrollok(list, TRUE);
226 wscrl(list, -1); 222 wscrl(list, -1);
227 scrollok(list, FALSE); 223 scrollok(list, FALSE);
228 } 224 }
229 scroll--; 225 scroll--;
230 print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); 226 item_set(scroll);
231 print_arrows(dialog, choice, item_no, 227 print_item(list, 0, TRUE);
228 print_arrows(dialog, choice, item_count(),
232 scroll, box_y, box_x + check_x + 5, list_height); 229 scroll, box_y, box_x + check_x + 5, list_height);
233 230
234 wnoutrefresh(dialog); 231 wnoutrefresh(dialog);
@@ -239,23 +236,24 @@ int dialog_checklist(const char *title, const char *prompt, int height,
239 i = choice - 1; 236 i = choice - 1;
240 } else if (key == KEY_DOWN || key == '+') { 237 } else if (key == KEY_DOWN || key == '+') {
241 if (choice == max_choice - 1) { 238 if (choice == max_choice - 1) {
242 if (scroll + choice >= item_no - 1) 239 if (scroll + choice >= item_count() - 1)
243 continue; 240 continue;
244 /* Scroll list up */ 241 /* Scroll list up */
245 if (list_height > 1) { 242 if (list_height > 1) {
246 /* De-highlight current last item before scrolling up */ 243 /* De-highlight current last item before scrolling up */
247 print_item(list, items[(scroll + max_choice - 1) * 3 + 1], 244 item_set(scroll + max_choice - 1);
248 status[scroll + max_choice - 1], 245 print_item(list,
249 max_choice - 1, FALSE); 246 max_choice - 1,
247 FALSE);
250 scrollok(list, TRUE); 248 scrollok(list, TRUE);
251 wscrl(list, 1); 249 wscrl(list, 1);
252 scrollok(list, FALSE); 250 scrollok(list, FALSE);
253 } 251 }
254 scroll++; 252 scroll++;
255 print_item(list, items[(scroll + max_choice - 1) * 3 + 1], 253 item_set(scroll + max_choice - 1);
256 status[scroll + max_choice - 1], max_choice - 1, TRUE); 254 print_item(list, max_choice - 1, TRUE);
257 255
258 print_arrows(dialog, choice, item_no, 256 print_arrows(dialog, choice, item_count(),
259 scroll, box_y, box_x + check_x + 5, list_height); 257 scroll, box_y, box_x + check_x + 5, list_height);
260 258
261 wnoutrefresh(dialog); 259 wnoutrefresh(dialog);
@@ -267,12 +265,12 @@ int dialog_checklist(const char *title, const char *prompt, int height,
267 } 265 }
268 if (i != choice) { 266 if (i != choice) {
269 /* De-highlight current item */ 267 /* De-highlight current item */
270 print_item(list, items[(scroll + choice) * 3 + 1], 268 item_set(scroll + choice);
271 status[scroll + choice], choice, FALSE); 269 print_item(list, choice, FALSE);
272 /* Highlight new item */ 270 /* Highlight new item */
273 choice = i; 271 choice = i;
274 print_item(list, items[(scroll + choice) * 3 + 1], 272 item_set(scroll + choice);
275 status[scroll + choice], choice, TRUE); 273 print_item(list, choice, TRUE);
276 wnoutrefresh(dialog); 274 wnoutrefresh(dialog);
277 wrefresh(list); 275 wrefresh(list);
278 } 276 }
@@ -282,10 +280,19 @@ int dialog_checklist(const char *title, const char *prompt, int height,
282 case 'H': 280 case 'H':
283 case 'h': 281 case 'h':
284 case '?': 282 case '?':
285 fprintf(stderr, "%s", items[(scroll + choice) * 3]); 283 button = 1;
284 /* fall-through */
285 case 'S':
286 case 's':
287 case ' ':
288 case '\n':
289 item_foreach()
290 item_set_selected(0);
291 item_set(scroll + choice);
292 item_set_selected(1);
293 delwin(list);
286 delwin(dialog); 294 delwin(dialog);
287 free(status); 295 return button;
288 return 1;
289 case TAB: 296 case TAB:
290 case KEY_LEFT: 297 case KEY_LEFT:
291 case KEY_RIGHT: 298 case KEY_RIGHT:
@@ -295,42 +302,24 @@ int dialog_checklist(const char *title, const char *prompt, int height,
295 print_buttons(dialog, height, width, button); 302 print_buttons(dialog, height, width, button);
296 wrefresh(dialog); 303 wrefresh(dialog);
297 break; 304 break;
298 case 'S':
299 case 's':
300 case ' ':
301 case '\n':
302 if (!button) {
303 if (!status[scroll + choice]) {
304 for (i = 0; i < item_no; i++)
305 status[i] = 0;
306 status[scroll + choice] = 1;
307 for (i = 0; i < max_choice; i++)
308 print_item(list, items[(scroll + i) * 3 + 1],
309 status[scroll + i], i, i == choice);
310 }
311 wnoutrefresh(dialog);
312 wrefresh(list);
313
314 for (i = 0; i < item_no; i++)
315 if (status[i])
316 fprintf(stderr, "%s", items[i * 3]);
317 } else
318 fprintf(stderr, "%s", items[(scroll + choice) * 3]);
319 delwin(dialog);
320 free(status);
321 return button;
322 case 'X': 305 case 'X':
323 case 'x': 306 case 'x':
324 key = ESC; 307 key = KEY_ESC;
325 case ESC: 308 break;
309 case KEY_ESC:
310 key = on_key_esc(dialog);
326 break; 311 break;
312 case KEY_RESIZE:
313 delwin(list);
314 delwin(dialog);
315 on_key_resize();
316 goto do_resize;
327 } 317 }
328 318
329 /* Now, update everything... */ 319 /* Now, update everything... */
330 doupdate(); 320 doupdate();
331 } 321 }
332 322 delwin(list);
333 delwin(dialog); 323 delwin(dialog);
334 free(status); 324 return key; /* ESC pressed */
335 return -1; /* ESC pressed */
336} 325}
diff --git a/scripts/kconfig/lxdialog/colors.h b/scripts/kconfig/lxdialog/colors.h
deleted file mode 100644
index db071df12bbb..000000000000
--- a/scripts/kconfig/lxdialog/colors.h
+++ /dev/null
@@ -1,154 +0,0 @@
1/*
2 * colors.h -- color attribute definitions
3 *
4 * AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21/*
22 * Default color definitions
23 *
24 * *_FG = foreground
25 * *_BG = background
26 * *_HL = highlight?
27 */
28#define SCREEN_FG COLOR_CYAN
29#define SCREEN_BG COLOR_BLUE
30#define SCREEN_HL TRUE
31
32#define SHADOW_FG COLOR_BLACK
33#define SHADOW_BG COLOR_BLACK
34#define SHADOW_HL TRUE
35
36#define DIALOG_FG COLOR_BLACK
37#define DIALOG_BG COLOR_WHITE
38#define DIALOG_HL FALSE
39
40#define TITLE_FG COLOR_YELLOW
41#define TITLE_BG COLOR_WHITE
42#define TITLE_HL TRUE
43
44#define BORDER_FG COLOR_WHITE
45#define BORDER_BG COLOR_WHITE
46#define BORDER_HL TRUE
47
48#define BUTTON_ACTIVE_FG COLOR_WHITE
49#define BUTTON_ACTIVE_BG COLOR_BLUE
50#define BUTTON_ACTIVE_HL TRUE
51
52#define BUTTON_INACTIVE_FG COLOR_BLACK
53#define BUTTON_INACTIVE_BG COLOR_WHITE
54#define BUTTON_INACTIVE_HL FALSE
55
56#define BUTTON_KEY_ACTIVE_FG COLOR_WHITE
57#define BUTTON_KEY_ACTIVE_BG COLOR_BLUE
58#define BUTTON_KEY_ACTIVE_HL TRUE
59
60#define BUTTON_KEY_INACTIVE_FG COLOR_RED
61#define BUTTON_KEY_INACTIVE_BG COLOR_WHITE
62#define BUTTON_KEY_INACTIVE_HL FALSE
63
64#define BUTTON_LABEL_ACTIVE_FG COLOR_YELLOW
65#define BUTTON_LABEL_ACTIVE_BG COLOR_BLUE
66#define BUTTON_LABEL_ACTIVE_HL TRUE
67
68#define BUTTON_LABEL_INACTIVE_FG COLOR_BLACK
69#define BUTTON_LABEL_INACTIVE_BG COLOR_WHITE
70#define BUTTON_LABEL_INACTIVE_HL TRUE
71
72#define INPUTBOX_FG COLOR_BLACK
73#define INPUTBOX_BG COLOR_WHITE
74#define INPUTBOX_HL FALSE
75
76#define INPUTBOX_BORDER_FG COLOR_BLACK
77#define INPUTBOX_BORDER_BG COLOR_WHITE
78#define INPUTBOX_BORDER_HL FALSE
79
80#define SEARCHBOX_FG COLOR_BLACK
81#define SEARCHBOX_BG COLOR_WHITE
82#define SEARCHBOX_HL FALSE
83
84#define SEARCHBOX_TITLE_FG COLOR_YELLOW
85#define SEARCHBOX_TITLE_BG COLOR_WHITE
86#define SEARCHBOX_TITLE_HL TRUE
87
88#define SEARCHBOX_BORDER_FG COLOR_WHITE
89#define SEARCHBOX_BORDER_BG COLOR_WHITE
90#define SEARCHBOX_BORDER_HL TRUE
91
92#define POSITION_INDICATOR_FG COLOR_YELLOW
93#define POSITION_INDICATOR_BG COLOR_WHITE
94#define POSITION_INDICATOR_HL TRUE
95
96#define MENUBOX_FG COLOR_BLACK
97#define MENUBOX_BG COLOR_WHITE
98#define MENUBOX_HL FALSE
99
100#define MENUBOX_BORDER_FG COLOR_WHITE
101#define MENUBOX_BORDER_BG COLOR_WHITE
102#define MENUBOX_BORDER_HL TRUE
103
104#define ITEM_FG COLOR_BLACK
105#define ITEM_BG COLOR_WHITE
106#define ITEM_HL FALSE
107
108#define ITEM_SELECTED_FG COLOR_WHITE
109#define ITEM_SELECTED_BG COLOR_BLUE
110#define ITEM_SELECTED_HL TRUE
111
112#define TAG_FG COLOR_YELLOW
113#define TAG_BG COLOR_WHITE
114#define TAG_HL TRUE
115
116#define TAG_SELECTED_FG COLOR_YELLOW
117#define TAG_SELECTED_BG COLOR_BLUE
118#define TAG_SELECTED_HL TRUE
119
120#define TAG_KEY_FG COLOR_YELLOW
121#define TAG_KEY_BG COLOR_WHITE
122#define TAG_KEY_HL TRUE
123
124#define TAG_KEY_SELECTED_FG COLOR_YELLOW
125#define TAG_KEY_SELECTED_BG COLOR_BLUE
126#define TAG_KEY_SELECTED_HL TRUE
127
128#define CHECK_FG COLOR_BLACK
129#define CHECK_BG COLOR_WHITE
130#define CHECK_HL FALSE
131
132#define CHECK_SELECTED_FG COLOR_WHITE
133#define CHECK_SELECTED_BG COLOR_BLUE
134#define CHECK_SELECTED_HL TRUE
135
136#define UARROW_FG COLOR_GREEN
137#define UARROW_BG COLOR_WHITE
138#define UARROW_HL TRUE
139
140#define DARROW_FG COLOR_GREEN
141#define DARROW_BG COLOR_WHITE
142#define DARROW_HL TRUE
143
144/* End of default color definitions */
145
146#define C_ATTR(x,y) ((x ? A_BOLD : 0) | COLOR_PAIR((y)))
147#define COLOR_NAME_LEN 10
148#define COLOR_COUNT 8
149
150/*
151 * Global variables
152 */
153
154extern int color_table[][3];
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index af3cf716e215..8dea47f9d3e4 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -48,7 +48,7 @@
48 48
49#define TR(params) _tracef params 49#define TR(params) _tracef params
50 50
51#define ESC 27 51#define KEY_ESC 27
52#define TAB 9 52#define TAB 9
53#define MAX_LEN 2048 53#define MAX_LEN 2048
54#define BUF_SIZE (10*1024) 54#define BUF_SIZE (10*1024)
@@ -86,63 +86,111 @@
86#define ACS_DARROW 'v' 86#define ACS_DARROW 'v'
87#endif 87#endif
88 88
89/* error return codes */
90#define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
91
89/* 92/*
90 * Attribute names 93 * Color definitions
91 */ 94 */
92#define screen_attr attributes[0] 95struct dialog_color {
93#define shadow_attr attributes[1] 96 chtype atr; /* Color attribute */
94#define dialog_attr attributes[2] 97 int fg; /* foreground */
95#define title_attr attributes[3] 98 int bg; /* background */
96#define border_attr attributes[4] 99 int hl; /* highlight this item */
97#define button_active_attr attributes[5] 100};
98#define button_inactive_attr attributes[6] 101
99#define button_key_active_attr attributes[7] 102struct dialog_info {
100#define button_key_inactive_attr attributes[8] 103 const char *backtitle;
101#define button_label_active_attr attributes[9] 104 struct dialog_color screen;
102#define button_label_inactive_attr attributes[10] 105 struct dialog_color shadow;
103#define inputbox_attr attributes[11] 106 struct dialog_color dialog;
104#define inputbox_border_attr attributes[12] 107 struct dialog_color title;
105#define searchbox_attr attributes[13] 108 struct dialog_color border;
106#define searchbox_title_attr attributes[14] 109 struct dialog_color button_active;
107#define searchbox_border_attr attributes[15] 110 struct dialog_color button_inactive;
108#define position_indicator_attr attributes[16] 111 struct dialog_color button_key_active;
109#define menubox_attr attributes[17] 112 struct dialog_color button_key_inactive;
110#define menubox_border_attr attributes[18] 113 struct dialog_color button_label_active;
111#define item_attr attributes[19] 114 struct dialog_color button_label_inactive;
112#define item_selected_attr attributes[20] 115 struct dialog_color inputbox;
113#define tag_attr attributes[21] 116 struct dialog_color inputbox_border;
114#define tag_selected_attr attributes[22] 117 struct dialog_color searchbox;
115#define tag_key_attr attributes[23] 118 struct dialog_color searchbox_title;
116#define tag_key_selected_attr attributes[24] 119 struct dialog_color searchbox_border;
117#define check_attr attributes[25] 120 struct dialog_color position_indicator;
118#define check_selected_attr attributes[26] 121 struct dialog_color menubox;
119#define uarrow_attr attributes[27] 122 struct dialog_color menubox_border;
120#define darrow_attr attributes[28] 123 struct dialog_color item;
121 124 struct dialog_color item_selected;
122/* number of attributes */ 125 struct dialog_color tag;
123#define ATTRIBUTE_COUNT 29 126 struct dialog_color tag_selected;
127 struct dialog_color tag_key;
128 struct dialog_color tag_key_selected;
129 struct dialog_color check;
130 struct dialog_color check_selected;
131 struct dialog_color uarrow;
132 struct dialog_color darrow;
133};
124 134
125/* 135/*
126 * Global variables 136 * Global variables
127 */ 137 */
128extern bool use_colors; 138extern struct dialog_info dlg;
129extern bool use_shadow; 139extern char dialog_input_result[];
130
131extern chtype attributes[];
132
133extern const char *backtitle;
134 140
135/* 141/*
136 * Function prototypes 142 * Function prototypes
137 */ 143 */
138extern void create_rc(const char *filename);
139extern int parse_rc(void);
140 144
141void init_dialog(void); 145/* item list as used by checklist and menubox */
146void item_reset(void);
147void item_make(const char *fmt, ...);
148void item_add_str(const char *fmt, ...);
149void item_set_tag(char tag);
150void item_set_data(void *p);
151void item_set_selected(int val);
152int item_activate_selected(void);
153void *item_data(void);
154char item_tag(void);
155
156/* item list manipulation for lxdialog use */
157#define MAXITEMSTR 200
158struct dialog_item {
159 char str[MAXITEMSTR]; /* promtp displayed */
160 char tag;
161 void *data; /* pointer to menu item - used by menubox+checklist */
162 int selected; /* Set to 1 by dialog_*() function if selected. */
163};
164
165/* list of lialog_items */
166struct dialog_list {
167 struct dialog_item node;
168 struct dialog_list *next;
169};
170
171extern struct dialog_list *item_cur;
172extern struct dialog_list item_nil;
173extern struct dialog_list *item_head;
174
175int item_count(void);
176void item_set(int n);
177int item_n(void);
178const char *item_str(void);
179int item_is_selected(void);
180int item_is_tag(char tag);
181#define item_foreach() \
182 for (item_cur = item_head ? item_head: item_cur; \
183 item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
184
185/* generic key handlers */
186int on_key_esc(WINDOW *win);
187int on_key_resize(void);
188
189void init_dialog(const char *backtitle);
190void reset_dialog(void);
142void end_dialog(void); 191void end_dialog(void);
143void attr_clear(WINDOW * win, int height, int width, chtype attr); 192void attr_clear(WINDOW * win, int height, int width, chtype attr);
144void dialog_clear(void); 193void dialog_clear(void);
145void color_setup(void);
146void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x); 194void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
147void print_button(WINDOW * win, const char *label, int y, int x, int selected); 195void print_button(WINDOW * win, const char *label, int y, int x, int selected);
148void print_title(WINDOW *dialog, const char *title, int width); 196void print_title(WINDOW *dialog, const char *title, int width);
@@ -155,12 +203,10 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width);
155int dialog_msgbox(const char *title, const char *prompt, int height, 203int dialog_msgbox(const char *title, const char *prompt, int height,
156 int width, int pause); 204 int width, int pause);
157int dialog_textbox(const char *title, const char *file, int height, int width); 205int dialog_textbox(const char *title, const char *file, int height, int width);
158int dialog_menu(const char *title, const char *prompt, int height, int width, 206int dialog_menu(const char *title, const char *prompt,
159 int menu_height, const char *choice, int item_no, 207 const void *selected, int *s_scroll);
160 const char *const *items);
161int dialog_checklist(const char *title, const char *prompt, int height, 208int dialog_checklist(const char *title, const char *prompt, int height,
162 int width, int list_height, int item_no, 209 int width, int list_height);
163 const char *const *items);
164extern char dialog_input_result[]; 210extern char dialog_input_result[];
165int dialog_inputbox(const char *title, const char *prompt, int height, 211int dialog_inputbox(const char *title, const char *prompt, int height,
166 int width, const char *init); 212 int width, const char *init);
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 779503726b0a..05e72066b359 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -49,6 +49,17 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
49 char *instr = dialog_input_result; 49 char *instr = dialog_input_result;
50 WINDOW *dialog; 50 WINDOW *dialog;
51 51
52 if (!init)
53 instr[0] = '\0';
54 else
55 strcpy(instr, init);
56
57do_resize:
58 if (getmaxy(stdscr) <= (height - 2))
59 return -ERRDISPLAYTOOSMALL;
60 if (getmaxx(stdscr) <= (width - 2))
61 return -ERRDISPLAYTOOSMALL;
62
52 /* center dialog box on screen */ 63 /* center dialog box on screen */
53 x = (COLS - width) / 2; 64 x = (COLS - width) / 2;
54 y = (LINES - height) / 2; 65 y = (LINES - height) / 2;
@@ -58,17 +69,18 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
58 dialog = newwin(height, width, y, x); 69 dialog = newwin(height, width, y, x);
59 keypad(dialog, TRUE); 70 keypad(dialog, TRUE);
60 71
61 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 72 draw_box(dialog, 0, 0, height, width,
62 wattrset(dialog, border_attr); 73 dlg.dialog.atr, dlg.border.atr);
74 wattrset(dialog, dlg.border.atr);
63 mvwaddch(dialog, height - 3, 0, ACS_LTEE); 75 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
64 for (i = 0; i < width - 2; i++) 76 for (i = 0; i < width - 2; i++)
65 waddch(dialog, ACS_HLINE); 77 waddch(dialog, ACS_HLINE);
66 wattrset(dialog, dialog_attr); 78 wattrset(dialog, dlg.dialog.atr);
67 waddch(dialog, ACS_RTEE); 79 waddch(dialog, ACS_RTEE);
68 80
69 print_title(dialog, title, width); 81 print_title(dialog, title, width);
70 82
71 wattrset(dialog, dialog_attr); 83 wattrset(dialog, dlg.dialog.atr);
72 print_autowrap(dialog, prompt, width - 2, 1, 3); 84 print_autowrap(dialog, prompt, width - 2, 1, 3);
73 85
74 /* Draw the input field box */ 86 /* Draw the input field box */
@@ -76,18 +88,14 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
76 getyx(dialog, y, x); 88 getyx(dialog, y, x);
77 box_y = y + 2; 89 box_y = y + 2;
78 box_x = (width - box_width) / 2; 90 box_x = (width - box_width) / 2;
79 draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, border_attr, dialog_attr); 91 draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
92 dlg.border.atr, dlg.dialog.atr);
80 93
81 print_buttons(dialog, height, width, 0); 94 print_buttons(dialog, height, width, 0);
82 95
83 /* Set up the initial value */ 96 /* Set up the initial value */
84 wmove(dialog, box_y, box_x); 97 wmove(dialog, box_y, box_x);
85 wattrset(dialog, inputbox_attr); 98 wattrset(dialog, dlg.inputbox.atr);
86
87 if (!init)
88 instr[0] = '\0';
89 else
90 strcpy(instr, init);
91 99
92 input_x = strlen(instr); 100 input_x = strlen(instr);
93 101
@@ -104,7 +112,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
104 112
105 wrefresh(dialog); 113 wrefresh(dialog);
106 114
107 while (key != ESC) { 115 while (key != KEY_ESC) {
108 key = wgetch(dialog); 116 key = wgetch(dialog);
109 117
110 if (button == -1) { /* Input box selected */ 118 if (button == -1) { /* Input box selected */
@@ -120,7 +128,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
120 case KEY_BACKSPACE: 128 case KEY_BACKSPACE:
121 case 127: 129 case 127:
122 if (input_x || scroll) { 130 if (input_x || scroll) {
123 wattrset(dialog, inputbox_attr); 131 wattrset(dialog, dlg.inputbox.atr);
124 if (!input_x) { 132 if (!input_x) {
125 scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1); 133 scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
126 wmove(dialog, box_y, box_x); 134 wmove(dialog, box_y, box_x);
@@ -140,7 +148,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
140 default: 148 default:
141 if (key < 0x100 && isprint(key)) { 149 if (key < 0x100 && isprint(key)) {
142 if (scroll + input_x < MAX_LEN) { 150 if (scroll + input_x < MAX_LEN) {
143 wattrset(dialog, inputbox_attr); 151 wattrset(dialog, dlg.inputbox.atr);
144 instr[scroll + input_x] = key; 152 instr[scroll + input_x] = key;
145 instr[scroll + input_x + 1] = '\0'; 153 instr[scroll + input_x + 1] = '\0';
146 if (input_x == box_width - 1) { 154 if (input_x == box_width - 1) {
@@ -213,12 +221,18 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
213 return (button == -1 ? 0 : button); 221 return (button == -1 ? 0 : button);
214 case 'X': 222 case 'X':
215 case 'x': 223 case 'x':
216 key = ESC; 224 key = KEY_ESC;
217 case ESC: 225 break;
226 case KEY_ESC:
227 key = on_key_esc(dialog);
218 break; 228 break;
229 case KEY_RESIZE:
230 delwin(dialog);
231 on_key_resize();
232 goto do_resize;
219 } 233 }
220 } 234 }
221 235
222 delwin(dialog); 236 delwin(dialog);
223 return -1; /* ESC pressed */ 237 return KEY_ESC; /* ESC pressed */
224} 238}
diff --git a/scripts/kconfig/lxdialog/lxdialog.c b/scripts/kconfig/lxdialog/lxdialog.c
deleted file mode 100644
index 79f6c5fb5cef..000000000000
--- a/scripts/kconfig/lxdialog/lxdialog.c
+++ /dev/null
@@ -1,204 +0,0 @@
1/*
2 * dialog - Display simple dialog boxes from shell scripts
3 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include "dialog.h"
23
24static void Usage(const char *name);
25
26typedef int (jumperFn) (const char *title, int argc, const char *const *argv);
27
28struct Mode {
29 char *name;
30 int argmin, argmax, argmod;
31 jumperFn *jumper;
32};
33
34jumperFn j_menu, j_radiolist, j_yesno, j_textbox, j_inputbox;
35jumperFn j_msgbox, j_infobox;
36
37static struct Mode modes[] = {
38 {"--menu", 9, 0, 3, j_menu},
39 {"--radiolist", 9, 0, 3, j_radiolist},
40 {"--yesno", 5, 5, 1, j_yesno},
41 {"--textbox", 5, 5, 1, j_textbox},
42 {"--inputbox", 5, 6, 1, j_inputbox},
43 {"--msgbox", 5, 5, 1, j_msgbox},
44 {"--infobox", 5, 5, 1, j_infobox},
45 {NULL, 0, 0, 0, NULL}
46};
47
48static struct Mode *modePtr;
49
50#ifdef LOCALE
51#include <locale.h>
52#endif
53
54int main(int argc, const char *const *argv)
55{
56 int offset = 0, opt_clear = 0, end_common_opts = 0, retval;
57 const char *title = NULL;
58
59#ifdef LOCALE
60 (void)setlocale(LC_ALL, "");
61#endif
62
63#ifdef TRACE
64 trace(TRACE_CALLS | TRACE_UPDATE);
65#endif
66 if (argc < 2) {
67 Usage(argv[0]);
68 exit(-1);
69 }
70
71 while (offset < argc - 1 && !end_common_opts) { /* Common options */
72 if (!strcmp(argv[offset + 1], "--title")) {
73 if (argc - offset < 3 || title != NULL) {
74 Usage(argv[0]);
75 exit(-1);
76 } else {
77 title = argv[offset + 2];
78 offset += 2;
79 }
80 } else if (!strcmp(argv[offset + 1], "--backtitle")) {
81 if (backtitle != NULL) {
82 Usage(argv[0]);
83 exit(-1);
84 } else {
85 backtitle = argv[offset + 2];
86 offset += 2;
87 }
88 } else if (!strcmp(argv[offset + 1], "--clear")) {
89 if (opt_clear) { /* Hey, "--clear" can't appear twice! */
90 Usage(argv[0]);
91 exit(-1);
92 } else if (argc == 2) { /* we only want to clear the screen */
93 init_dialog();
94 refresh(); /* init_dialog() will clear the screen for us */
95 end_dialog();
96 return 0;
97 } else {
98 opt_clear = 1;
99 offset++;
100 }
101 } else /* no more common options */
102 end_common_opts = 1;
103 }
104
105 if (argc - 1 == offset) { /* no more options */
106 Usage(argv[0]);
107 exit(-1);
108 }
109 /* use a table to look for the requested mode, to avoid code duplication */
110
111 for (modePtr = modes; modePtr->name; modePtr++) /* look for the mode */
112 if (!strcmp(argv[offset + 1], modePtr->name))
113 break;
114
115 if (!modePtr->name)
116 Usage(argv[0]);
117 if (argc - offset < modePtr->argmin)
118 Usage(argv[0]);
119 if (modePtr->argmax && argc - offset > modePtr->argmax)
120 Usage(argv[0]);
121
122 init_dialog();
123 retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
124
125 if (opt_clear) { /* clear screen before exit */
126 attr_clear(stdscr, LINES, COLS, screen_attr);
127 refresh();
128 }
129 end_dialog();
130
131 exit(retval);
132}
133
134/*
135 * Print program usage
136 */
137static void Usage(const char *name)
138{
139 fprintf(stderr, "\
140\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
141\n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\
142\n modified/gutted for use as a Linux kernel config tool by \
143\n William Roadcap (roadcapw@cfw.com)\
144\n\
145\n* Display dialog boxes from shell scripts *\
146\n\
147\nUsage: %s --clear\
148\n %s [--title <title>] [--backtitle <backtitle>] --clear <Box options>\
149\n\
150\nBox options:\
151\n\
152\n --menu <text> <height> <width> <menu height> <tag1> <item1>...\
153\n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\
154\n --textbox <file> <height> <width>\
155\n --inputbox <text> <height> <width> [<init>]\
156\n --yesno <text> <height> <width>\
157\n", name, name);
158 exit(-1);
159}
160
161/*
162 * These are the program jumpers
163 */
164
165int j_menu(const char *t, int ac, const char *const *av)
166{
167 return dialog_menu(t, av[2], atoi(av[3]), atoi(av[4]),
168 atoi(av[5]), av[6], (ac - 6) / 2, av + 7);
169}
170
171int j_radiolist(const char *t, int ac, const char *const *av)
172{
173 return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
174 atoi(av[5]), (ac - 6) / 3, av + 6);
175}
176
177int j_textbox(const char *t, int ac, const char *const *av)
178{
179 return dialog_textbox(t, av[2], atoi(av[3]), atoi(av[4]));
180}
181
182int j_yesno(const char *t, int ac, const char *const *av)
183{
184 return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4]));
185}
186
187int j_inputbox(const char *t, int ac, const char *const *av)
188{
189 int ret = dialog_inputbox(t, av[2], atoi(av[3]), atoi(av[4]),
190 ac == 6 ? av[5] : (char *)NULL);
191 if (ret == 0)
192 fprintf(stderr, dialog_input_result);
193 return ret;
194}
195
196int j_msgbox(const char *t, int ac, const char *const *av)
197{
198 return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 1);
199}
200
201int j_infobox(const char *t, int ac, const char *const *av)
202{
203 return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 0);
204}
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index bf8052f4fd4a..0d83159d9012 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -63,19 +63,19 @@ static int menu_width, item_x;
63/* 63/*
64 * Print menu item 64 * Print menu item
65 */ 65 */
66static void do_print_item(WINDOW * win, const char *item, int choice, 66static void do_print_item(WINDOW * win, const char *item, int line_y,
67 int selected, int hotkey) 67 int selected, int hotkey)
68{ 68{
69 int j; 69 int j;
70 char *menu_item = malloc(menu_width + 1); 70 char *menu_item = malloc(menu_width + 1);
71 71
72 strncpy(menu_item, item, menu_width - item_x); 72 strncpy(menu_item, item, menu_width - item_x);
73 menu_item[menu_width] = 0; 73 menu_item[menu_width - item_x] = '\0';
74 j = first_alpha(menu_item, "YyNnMmHh"); 74 j = first_alpha(menu_item, "YyNnMmHh");
75 75
76 /* Clear 'residue' of last item */ 76 /* Clear 'residue' of last item */
77 wattrset(win, menubox_attr); 77 wattrset(win, dlg.menubox.atr);
78 wmove(win, choice, 0); 78 wmove(win, line_y, 0);
79#if OLD_NCURSES 79#if OLD_NCURSES
80 { 80 {
81 int i; 81 int i;
@@ -85,23 +85,24 @@ static void do_print_item(WINDOW * win, const char *item, int choice,
85#else 85#else
86 wclrtoeol(win); 86 wclrtoeol(win);
87#endif 87#endif
88 wattrset(win, selected ? item_selected_attr : item_attr); 88 wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr);
89 mvwaddstr(win, choice, item_x, menu_item); 89 mvwaddstr(win, line_y, item_x, menu_item);
90 if (hotkey) { 90 if (hotkey) {
91 wattrset(win, selected ? tag_key_selected_attr : tag_key_attr); 91 wattrset(win, selected ? dlg.tag_key_selected.atr
92 mvwaddch(win, choice, item_x + j, menu_item[j]); 92 : dlg.tag_key.atr);
93 mvwaddch(win, line_y, item_x + j, menu_item[j]);
93 } 94 }
94 if (selected) { 95 if (selected) {
95 wmove(win, choice, item_x + 1); 96 wmove(win, line_y, item_x + 1);
96 } 97 }
97 free(menu_item); 98 free(menu_item);
98 wrefresh(win); 99 wrefresh(win);
99} 100}
100 101
101#define print_item(index, choice, selected) \ 102#define print_item(index, choice, selected) \
102do {\ 103do { \
103 int hotkey = (items[(index) * 2][0] != ':'); \ 104 item_set(index); \
104 do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \ 105 do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \
105} while (0) 106} while (0)
106 107
107/* 108/*
@@ -117,11 +118,11 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
117 wmove(win, y, x); 118 wmove(win, y, x);
118 119
119 if (scroll > 0) { 120 if (scroll > 0) {
120 wattrset(win, uarrow_attr); 121 wattrset(win, dlg.uarrow.atr);
121 waddch(win, ACS_UARROW); 122 waddch(win, ACS_UARROW);
122 waddstr(win, "(-)"); 123 waddstr(win, "(-)");
123 } else { 124 } else {
124 wattrset(win, menubox_attr); 125 wattrset(win, dlg.menubox.atr);
125 waddch(win, ACS_HLINE); 126 waddch(win, ACS_HLINE);
126 waddch(win, ACS_HLINE); 127 waddch(win, ACS_HLINE);
127 waddch(win, ACS_HLINE); 128 waddch(win, ACS_HLINE);
@@ -133,11 +134,11 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
133 wrefresh(win); 134 wrefresh(win);
134 135
135 if ((height < item_no) && (scroll + height < item_no)) { 136 if ((height < item_no) && (scroll + height < item_no)) {
136 wattrset(win, darrow_attr); 137 wattrset(win, dlg.darrow.atr);
137 waddch(win, ACS_DARROW); 138 waddch(win, ACS_DARROW);
138 waddstr(win, "(+)"); 139 waddstr(win, "(+)");
139 } else { 140 } else {
140 wattrset(win, menubox_border_attr); 141 wattrset(win, dlg.menubox_border.atr);
141 waddch(win, ACS_HLINE); 142 waddch(win, ACS_HLINE);
142 waddch(win, ACS_HLINE); 143 waddch(win, ACS_HLINE);
143 waddch(win, ACS_HLINE); 144 waddch(win, ACS_HLINE);
@@ -178,17 +179,26 @@ static void do_scroll(WINDOW *win, int *scroll, int n)
178/* 179/*
179 * Display a menu for choosing among a number of options 180 * Display a menu for choosing among a number of options
180 */ 181 */
181int dialog_menu(const char *title, const char *prompt, int height, int width, 182int dialog_menu(const char *title, const char *prompt,
182 int menu_height, const char *current, int item_no, 183 const void *selected, int *s_scroll)
183 const char *const *items)
184{ 184{
185 int i, j, x, y, box_x, box_y; 185 int i, j, x, y, box_x, box_y;
186 int height, width, menu_height;
186 int key = 0, button = 0, scroll = 0, choice = 0; 187 int key = 0, button = 0, scroll = 0, choice = 0;
187 int first_item = 0, max_choice; 188 int first_item = 0, max_choice;
188 WINDOW *dialog, *menu; 189 WINDOW *dialog, *menu;
189 FILE *f;
190 190
191 max_choice = MIN(menu_height, item_no); 191do_resize:
192 height = getmaxy(stdscr);
193 width = getmaxx(stdscr);
194 if (height < 15 || width < 65)
195 return -ERRDISPLAYTOOSMALL;
196
197 height -= 4;
198 width -= 5;
199 menu_height = height - 10;
200
201 max_choice = MIN(menu_height, item_count());
192 202
193 /* center dialog box on screen */ 203 /* center dialog box on screen */
194 x = (COLS - width) / 2; 204 x = (COLS - width) / 2;
@@ -199,18 +209,19 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
199 dialog = newwin(height, width, y, x); 209 dialog = newwin(height, width, y, x);
200 keypad(dialog, TRUE); 210 keypad(dialog, TRUE);
201 211
202 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 212 draw_box(dialog, 0, 0, height, width,
203 wattrset(dialog, border_attr); 213 dlg.dialog.atr, dlg.border.atr);
214 wattrset(dialog, dlg.border.atr);
204 mvwaddch(dialog, height - 3, 0, ACS_LTEE); 215 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
205 for (i = 0; i < width - 2; i++) 216 for (i = 0; i < width - 2; i++)
206 waddch(dialog, ACS_HLINE); 217 waddch(dialog, ACS_HLINE);
207 wattrset(dialog, dialog_attr); 218 wattrset(dialog, dlg.dialog.atr);
208 wbkgdset(dialog, dialog_attr & A_COLOR); 219 wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
209 waddch(dialog, ACS_RTEE); 220 waddch(dialog, ACS_RTEE);
210 221
211 print_title(dialog, title, width); 222 print_title(dialog, title, width);
212 223
213 wattrset(dialog, dialog_attr); 224 wattrset(dialog, dlg.dialog.atr);
214 print_autowrap(dialog, prompt, width - 2, 1, 3); 225 print_autowrap(dialog, prompt, width - 2, 1, 3);
215 226
216 menu_width = width - 6; 227 menu_width = width - 6;
@@ -224,33 +235,29 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
224 235
225 /* draw a box around the menu items */ 236 /* draw a box around the menu items */
226 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, 237 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
227 menubox_border_attr, menubox_attr); 238 dlg.menubox_border.atr, dlg.menubox.atr);
228 239
229 item_x = (menu_width - 70) / 2; 240 if (menu_width >= 80)
241 item_x = (menu_width - 70) / 2;
242 else
243 item_x = 4;
230 244
231 /* Set choice to default item */ 245 /* Set choice to default item */
232 for (i = 0; i < item_no; i++) 246 item_foreach()
233 if (strcmp(current, items[i * 2]) == 0) 247 if (selected && (selected == item_data()))
234 choice = i; 248 choice = item_n();
235 249 /* get the saved scroll info */
236 /* get the scroll info from the temp file */ 250 scroll = *s_scroll;
237 if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { 251 if ((scroll <= choice) && (scroll + max_choice > choice) &&
238 if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && 252 (scroll >= 0) && (scroll + max_choice <= item_count())) {
239 (scroll + max_choice > choice) && (scroll >= 0) && 253 first_item = scroll;
240 (scroll + max_choice <= item_no)) { 254 choice = choice - scroll;
241 first_item = scroll; 255 } else {
242 choice = choice - scroll; 256 scroll = 0;
243 fclose(f);
244 } else {
245 scroll = 0;
246 remove("lxdialog.scrltmp");
247 fclose(f);
248 f = NULL;
249 }
250 } 257 }
251 if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { 258 if ((choice >= max_choice)) {
252 if (choice >= item_no - max_choice / 2) 259 if (choice >= item_count() - max_choice / 2)
253 scroll = first_item = item_no - max_choice; 260 scroll = first_item = item_count() - max_choice;
254 else 261 else
255 scroll = first_item = choice - max_choice / 2; 262 scroll = first_item = choice - max_choice / 2;
256 choice = choice - scroll; 263 choice = choice - scroll;
@@ -263,14 +270,14 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
263 270
264 wnoutrefresh(menu); 271 wnoutrefresh(menu);
265 272
266 print_arrows(dialog, item_no, scroll, 273 print_arrows(dialog, item_count(), scroll,
267 box_y, box_x + item_x + 1, menu_height); 274 box_y, box_x + item_x + 1, menu_height);
268 275
269 print_buttons(dialog, height, width, 0); 276 print_buttons(dialog, height, width, 0);
270 wmove(menu, choice, item_x + 1); 277 wmove(menu, choice, item_x + 1);
271 wrefresh(menu); 278 wrefresh(menu);
272 279
273 while (key != ESC) { 280 while (key != KEY_ESC) {
274 key = wgetch(menu); 281 key = wgetch(menu);
275 282
276 if (key < 256 && isalpha(key)) 283 if (key < 256 && isalpha(key))
@@ -280,14 +287,16 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
280 i = max_choice; 287 i = max_choice;
281 else { 288 else {
282 for (i = choice + 1; i < max_choice; i++) { 289 for (i = choice + 1; i < max_choice; i++) {
283 j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); 290 item_set(scroll + i);
284 if (key == tolower(items[(scroll + i) * 2 + 1][j])) 291 j = first_alpha(item_str(), "YyNnMmHh");
292 if (key == tolower(item_str()[j]))
285 break; 293 break;
286 } 294 }
287 if (i == max_choice) 295 if (i == max_choice)
288 for (i = 0; i < max_choice; i++) { 296 for (i = 0; i < max_choice; i++) {
289 j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); 297 item_set(scroll + i);
290 if (key == tolower(items[(scroll + i) * 2 + 1][j])) 298 j = first_alpha(item_str(), "YyNnMmHh");
299 if (key == tolower(item_str()[j]))
291 break; 300 break;
292 } 301 }
293 } 302 }
@@ -312,7 +321,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
312 print_item(scroll+choice, choice, FALSE); 321 print_item(scroll+choice, choice, FALSE);
313 322
314 if ((choice > max_choice - 3) && 323 if ((choice > max_choice - 3) &&
315 (scroll + max_choice < item_no)) { 324 (scroll + max_choice < item_count())) {
316 /* Scroll menu up */ 325 /* Scroll menu up */
317 do_scroll(menu, &scroll, 1); 326 do_scroll(menu, &scroll, 1);
318 327
@@ -335,7 +344,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
335 344
336 } else if (key == KEY_NPAGE) { 345 } else if (key == KEY_NPAGE) {
337 for (i = 0; (i < max_choice); i++) { 346 for (i = 0; (i < max_choice); i++) {
338 if (scroll + max_choice < item_no) { 347 if (scroll + max_choice < item_count()) {
339 do_scroll(menu, &scroll, 1); 348 do_scroll(menu, &scroll, 1);
340 print_item(scroll+max_choice-1, 349 print_item(scroll+max_choice-1,
341 max_choice - 1, FALSE); 350 max_choice - 1, FALSE);
@@ -349,7 +358,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
349 358
350 print_item(scroll + choice, choice, TRUE); 359 print_item(scroll + choice, choice, TRUE);
351 360
352 print_arrows(dialog, item_no, scroll, 361 print_arrows(dialog, item_count(), scroll,
353 box_y, box_x + item_x + 1, menu_height); 362 box_y, box_x + item_x + 1, menu_height);
354 363
355 wnoutrefresh(dialog); 364 wnoutrefresh(dialog);
@@ -375,12 +384,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
375 case 'm': 384 case 'm':
376 case '/': 385 case '/':
377 /* save scroll info */ 386 /* save scroll info */
378 if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { 387 *s_scroll = scroll;
379 fprintf(f, "%d\n", scroll); 388 delwin(menu);
380 fclose(f);
381 }
382 delwin(dialog); 389 delwin(dialog);
383 fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 390 item_set(scroll + choice);
391 item_set_selected(1);
384 switch (key) { 392 switch (key) {
385 case 's': 393 case 's':
386 return 3; 394 return 3;
@@ -400,27 +408,27 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
400 case '?': 408 case '?':
401 button = 2; 409 button = 2;
402 case '\n': 410 case '\n':
411 *s_scroll = scroll;
412 delwin(menu);
403 delwin(dialog); 413 delwin(dialog);
404 if (button == 2) 414 item_set(scroll + choice);
405 fprintf(stderr, "%s \"%s\"\n", 415 item_set_selected(1);
406 items[(scroll + choice) * 2],
407 items[(scroll + choice) * 2 + 1] +
408 first_alpha(items [(scroll + choice) * 2 + 1], ""));
409 else
410 fprintf(stderr, "%s\n",
411 items[(scroll + choice) * 2]);
412
413 remove("lxdialog.scrltmp");
414 return button; 416 return button;
415 case 'e': 417 case 'e':
416 case 'x': 418 case 'x':
417 key = ESC; 419 key = KEY_ESC;
418 case ESC: 420 break;
421 case KEY_ESC:
422 key = on_key_esc(menu);
419 break; 423 break;
424 case KEY_RESIZE:
425 on_key_resize();
426 delwin(menu);
427 delwin(dialog);
428 goto do_resize;
420 } 429 }
421 } 430 }
422 431 delwin(menu);
423 delwin(dialog); 432 delwin(dialog);
424 remove("lxdialog.scrltmp"); 433 return key; /* ESC pressed */
425 return -1; /* ESC pressed */
426} 434}
diff --git a/scripts/kconfig/lxdialog/msgbox.c b/scripts/kconfig/lxdialog/msgbox.c
deleted file mode 100644
index 7323f5471f69..000000000000
--- a/scripts/kconfig/lxdialog/msgbox.c
+++ /dev/null
@@ -1,71 +0,0 @@
1/*
2 * msgbox.c -- implements the message box and info box
3 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include "dialog.h"
23
24/*
25 * Display a message box. Program will pause and display an "OK" button
26 * if the parameter 'pause' is non-zero.
27 */
28int dialog_msgbox(const char *title, const char *prompt, int height, int width,
29 int pause)
30{
31 int i, x, y, key = 0;
32 WINDOW *dialog;
33
34 /* center dialog box on screen */
35 x = (COLS - width) / 2;
36 y = (LINES - height) / 2;
37
38 draw_shadow(stdscr, y, x, height, width);
39
40 dialog = newwin(height, width, y, x);
41 keypad(dialog, TRUE);
42
43 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
44
45 print_title(dialog, title, width);
46
47 wattrset(dialog, dialog_attr);
48 print_autowrap(dialog, prompt, width - 2, 1, 2);
49
50 if (pause) {
51 wattrset(dialog, border_attr);
52 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
53 for (i = 0; i < width - 2; i++)
54 waddch(dialog, ACS_HLINE);
55 wattrset(dialog, dialog_attr);
56 waddch(dialog, ACS_RTEE);
57
58 print_button(dialog, " Ok ", height - 2, width / 2 - 4, TRUE);
59
60 wrefresh(dialog);
61 while (key != ESC && key != '\n' && key != ' ' &&
62 key != 'O' && key != 'o' && key != 'X' && key != 'x')
63 key = wgetch(dialog);
64 } else {
65 key = '\n';
66 wrefresh(dialog);
67 }
68
69 delwin(dialog);
70 return key == ESC ? -1 : 0;
71}
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index 77848bb8e07f..fabfc1ad789d 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -25,56 +25,62 @@ static void back_lines(int n);
25static void print_page(WINDOW * win, int height, int width); 25static void print_page(WINDOW * win, int height, int width);
26static void print_line(WINDOW * win, int row, int width); 26static void print_line(WINDOW * win, int row, int width);
27static char *get_line(void); 27static char *get_line(void);
28static void print_position(WINDOW * win, int height, int width); 28static void print_position(WINDOW * win);
29
30static int hscroll;
31static int begin_reached, end_reached, page_length;
32static const char *buf;
33static const char *page;
34
35/*
36 * refresh window content
37 */
38static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
39 int cur_y, int cur_x)
40{
41 print_page(box, boxh, boxw);
42 print_position(dialog);
43 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
44 wrefresh(dialog);
45}
29 46
30static int hscroll, fd, file_size, bytes_read;
31static int begin_reached = 1, end_reached, page_length;
32static char *buf, *page;
33 47
34/* 48/*
35 * Display text from a file in a dialog box. 49 * Display text from a file in a dialog box.
36 */ 50 */
37int dialog_textbox(const char *title, const char *file, int height, int width) 51int dialog_textbox(const char *title, const char *tbuf,
52 int initial_height, int initial_width)
38{ 53{
39 int i, x, y, cur_x, cur_y, fpos, key = 0; 54 int i, x, y, cur_x, cur_y, key = 0;
55 int height, width, boxh, boxw;
40 int passed_end; 56 int passed_end;
41 char search_term[MAX_LEN + 1]; 57 WINDOW *dialog, *box;
42 WINDOW *dialog, *text;
43
44 search_term[0] = '\0'; /* no search term entered yet */
45 58
46 /* Open input file for reading */ 59 begin_reached = 1;
47 if ((fd = open(file, O_RDONLY)) == -1) { 60 end_reached = 0;
48 endwin(); 61 page_length = 0;
49 fprintf(stderr, "\nCan't open input file in dialog_textbox().\n"); 62 hscroll = 0;
50 exit(-1); 63 buf = tbuf;
51 } 64 page = buf; /* page is pointer to start of page to be displayed */
52 /* Get file size. Actually, 'file_size' is the real file size - 1, 65
53 since it's only the last byte offset from the beginning */ 66do_resize:
54 if ((file_size = lseek(fd, 0, SEEK_END)) == -1) { 67 getmaxyx(stdscr, height, width);
55 endwin(); 68 if (height < 8 || width < 8)
56 fprintf(stderr, "\nError getting file size in dialog_textbox().\n"); 69 return -ERRDISPLAYTOOSMALL;
57 exit(-1); 70 if (initial_height != 0)
58 } 71 height = initial_height;
59 /* Restore file pointer to beginning of file after getting file size */ 72 else
60 if (lseek(fd, 0, SEEK_SET) == -1) { 73 if (height > 4)
61 endwin(); 74 height -= 4;
62 fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); 75 else
63 exit(-1); 76 height = 0;
64 } 77 if (initial_width != 0)
65 /* Allocate space for read buffer */ 78 width = initial_width;
66 if ((buf = malloc(BUF_SIZE + 1)) == NULL) { 79 else
67 endwin(); 80 if (width > 5)
68 fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n"); 81 width -= 5;
69 exit(-1); 82 else
70 } 83 width = 0;
71 if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
72 endwin();
73 fprintf(stderr, "\nError reading file in dialog_textbox().\n");
74 exit(-1);
75 }
76 buf[bytes_read] = '\0'; /* mark end of valid data */
77 page = buf; /* page is pointer to start of page to be displayed */
78 84
79 /* center dialog box on screen */ 85 /* center dialog box on screen */
80 x = (COLS - width) / 2; 86 x = (COLS - width) / 2;
@@ -85,22 +91,25 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
85 dialog = newwin(height, width, y, x); 91 dialog = newwin(height, width, y, x);
86 keypad(dialog, TRUE); 92 keypad(dialog, TRUE);
87 93
88 /* Create window for text region, used for scrolling text */ 94 /* Create window for box region, used for scrolling text */
89 text = subwin(dialog, height - 4, width - 2, y + 1, x + 1); 95 boxh = height - 4;
90 wattrset(text, dialog_attr); 96 boxw = width - 2;
91 wbkgdset(text, dialog_attr & A_COLOR); 97 box = subwin(dialog, boxh, boxw, y + 1, x + 1);
98 wattrset(box, dlg.dialog.atr);
99 wbkgdset(box, dlg.dialog.atr & A_COLOR);
92 100
93 keypad(text, TRUE); 101 keypad(box, TRUE);
94 102
95 /* register the new window, along with its borders */ 103 /* register the new window, along with its borders */
96 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 104 draw_box(dialog, 0, 0, height, width,
105 dlg.dialog.atr, dlg.border.atr);
97 106
98 wattrset(dialog, border_attr); 107 wattrset(dialog, dlg.border.atr);
99 mvwaddch(dialog, height - 3, 0, ACS_LTEE); 108 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
100 for (i = 0; i < width - 2; i++) 109 for (i = 0; i < width - 2; i++)
101 waddch(dialog, ACS_HLINE); 110 waddch(dialog, ACS_HLINE);
102 wattrset(dialog, dialog_attr); 111 wattrset(dialog, dlg.dialog.atr);
103 wbkgdset(dialog, dialog_attr & A_COLOR); 112 wbkgdset(dialog, dlg.dialog.atr & A_COLOR);
104 waddch(dialog, ACS_RTEE); 113 waddch(dialog, ACS_RTEE);
105 114
106 print_title(dialog, title, width); 115 print_title(dialog, title, width);
@@ -110,85 +119,37 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
110 getyx(dialog, cur_y, cur_x); /* Save cursor position */ 119 getyx(dialog, cur_y, cur_x); /* Save cursor position */
111 120
112 /* Print first page of text */ 121 /* Print first page of text */
113 attr_clear(text, height - 4, width - 2, dialog_attr); 122 attr_clear(box, boxh, boxw, dlg.dialog.atr);
114 print_page(text, height - 4, width - 2); 123 refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
115 print_position(dialog, height, width);
116 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
117 wrefresh(dialog);
118 124
119 while ((key != ESC) && (key != '\n')) { 125 while ((key != KEY_ESC) && (key != '\n')) {
120 key = wgetch(dialog); 126 key = wgetch(dialog);
121 switch (key) { 127 switch (key) {
122 case 'E': /* Exit */ 128 case 'E': /* Exit */
123 case 'e': 129 case 'e':
124 case 'X': 130 case 'X':
125 case 'x': 131 case 'x':
132 delwin(box);
126 delwin(dialog); 133 delwin(dialog);
127 free(buf);
128 close(fd);
129 return 0; 134 return 0;
130 case 'g': /* First page */ 135 case 'g': /* First page */
131 case KEY_HOME: 136 case KEY_HOME:
132 if (!begin_reached) { 137 if (!begin_reached) {
133 begin_reached = 1; 138 begin_reached = 1;
134 /* First page not in buffer? */
135 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
136 endwin();
137 fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
138 exit(-1);
139 }
140 if (fpos > bytes_read) { /* Yes, we have to read it in */
141 if (lseek(fd, 0, SEEK_SET) == -1) {
142 endwin();
143 fprintf(stderr, "\nError moving file pointer in "
144 "dialog_textbox().\n");
145 exit(-1);
146 }
147 if ((bytes_read =
148 read(fd, buf, BUF_SIZE)) == -1) {
149 endwin();
150 fprintf(stderr, "\nError reading file in dialog_textbox().\n");
151 exit(-1);
152 }
153 buf[bytes_read] = '\0';
154 }
155 page = buf; 139 page = buf;
156 print_page(text, height - 4, width - 2); 140 refresh_text_box(dialog, box, boxh, boxw,
157 print_position(dialog, height, width); 141 cur_y, cur_x);
158 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
159 wrefresh(dialog);
160 } 142 }
161 break; 143 break;
162 case 'G': /* Last page */ 144 case 'G': /* Last page */
163 case KEY_END: 145 case KEY_END:
164 146
165 end_reached = 1; 147 end_reached = 1;
166 /* Last page not in buffer? */ 148 /* point to last char in buf */
167 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { 149 page = buf + strlen(buf);
168 endwin(); 150 back_lines(boxh);
169 fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); 151 refresh_text_box(dialog, box, boxh, boxw,
170 exit(-1); 152 cur_y, cur_x);
171 }
172 if (fpos < file_size) { /* Yes, we have to read it in */
173 if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) {
174 endwin();
175 fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
176 exit(-1);
177 }
178 if ((bytes_read =
179 read(fd, buf, BUF_SIZE)) == -1) {
180 endwin();
181 fprintf(stderr, "\nError reading file in dialog_textbox().\n");
182 exit(-1);
183 }
184 buf[bytes_read] = '\0';
185 }
186 page = buf + bytes_read;
187 back_lines(height - 4);
188 print_page(text, height - 4, width - 2);
189 print_position(dialog, height, width);
190 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
191 wrefresh(dialog);
192 break; 153 break;
193 case 'K': /* Previous line */ 154 case 'K': /* Previous line */
194 case 'k': 155 case 'k':
@@ -196,21 +157,23 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
196 if (!begin_reached) { 157 if (!begin_reached) {
197 back_lines(page_length + 1); 158 back_lines(page_length + 1);
198 159
199 /* We don't call print_page() here but use scrolling to ensure 160 /* We don't call print_page() here but use
200 faster screen update. However, 'end_reached' and 161 * scrolling to ensure faster screen update.
201 'page_length' should still be updated, and 'page' should 162 * However, 'end_reached' and 'page_length'
202 point to start of next page. This is done by calling 163 * should still be updated, and 'page' should
203 get_line() in the following 'for' loop. */ 164 * point to start of next page. This is done
204 scrollok(text, TRUE); 165 * by calling get_line() in the following
205 wscrl(text, -1); /* Scroll text region down one line */ 166 * 'for' loop. */
206 scrollok(text, FALSE); 167 scrollok(box, TRUE);
168 wscrl(box, -1); /* Scroll box region down one line */
169 scrollok(box, FALSE);
207 page_length = 0; 170 page_length = 0;
208 passed_end = 0; 171 passed_end = 0;
209 for (i = 0; i < height - 4; i++) { 172 for (i = 0; i < boxh; i++) {
210 if (!i) { 173 if (!i) {
211 /* print first line of page */ 174 /* print first line of page */
212 print_line(text, 0, width - 2); 175 print_line(box, 0, boxw);
213 wnoutrefresh(text); 176 wnoutrefresh(box);
214 } else 177 } else
215 /* Called to update 'end_reached' and 'page' */ 178 /* Called to update 'end_reached' and 'page' */
216 get_line(); 179 get_line();
@@ -220,7 +183,7 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
220 passed_end = 1; 183 passed_end = 1;
221 } 184 }
222 185
223 print_position(dialog, height, width); 186 print_position(dialog);
224 wmove(dialog, cur_y, cur_x); /* Restore cursor position */ 187 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
225 wrefresh(dialog); 188 wrefresh(dialog);
226 } 189 }
@@ -230,23 +193,21 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
230 case KEY_PPAGE: 193 case KEY_PPAGE:
231 if (begin_reached) 194 if (begin_reached)
232 break; 195 break;
233 back_lines(page_length + height - 4); 196 back_lines(page_length + boxh);
234 print_page(text, height - 4, width - 2); 197 refresh_text_box(dialog, box, boxh, boxw,
235 print_position(dialog, height, width); 198 cur_y, cur_x);
236 wmove(dialog, cur_y, cur_x);
237 wrefresh(dialog);
238 break; 199 break;
239 case 'J': /* Next line */ 200 case 'J': /* Next line */
240 case 'j': 201 case 'j':
241 case KEY_DOWN: 202 case KEY_DOWN:
242 if (!end_reached) { 203 if (!end_reached) {
243 begin_reached = 0; 204 begin_reached = 0;
244 scrollok(text, TRUE); 205 scrollok(box, TRUE);
245 scroll(text); /* Scroll text region up one line */ 206 scroll(box); /* Scroll box region up one line */
246 scrollok(text, FALSE); 207 scrollok(box, FALSE);
247 print_line(text, height - 5, width - 2); 208 print_line(box, boxh - 1, boxw);
248 wnoutrefresh(text); 209 wnoutrefresh(box);
249 print_position(dialog, height, width); 210 print_position(dialog);
250 wmove(dialog, cur_y, cur_x); /* Restore cursor position */ 211 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
251 wrefresh(dialog); 212 wrefresh(dialog);
252 } 213 }
@@ -257,10 +218,8 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
257 break; 218 break;
258 219
259 begin_reached = 0; 220 begin_reached = 0;
260 print_page(text, height - 4, width - 2); 221 refresh_text_box(dialog, box, boxh, boxw,
261 print_position(dialog, height, width); 222 cur_y, cur_x);
262 wmove(dialog, cur_y, cur_x);
263 wrefresh(dialog);
264 break; 223 break;
265 case '0': /* Beginning of line */ 224 case '0': /* Beginning of line */
266 case 'H': /* Scroll left */ 225 case 'H': /* Scroll left */
@@ -275,9 +234,8 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
275 hscroll--; 234 hscroll--;
276 /* Reprint current page to scroll horizontally */ 235 /* Reprint current page to scroll horizontally */
277 back_lines(page_length); 236 back_lines(page_length);
278 print_page(text, height - 4, width - 2); 237 refresh_text_box(dialog, box, boxh, boxw,
279 wmove(dialog, cur_y, cur_x); 238 cur_y, cur_x);
280 wrefresh(dialog);
281 break; 239 break;
282 case 'L': /* Scroll right */ 240 case 'L': /* Scroll right */
283 case 'l': 241 case 'l':
@@ -287,131 +245,56 @@ int dialog_textbox(const char *title, const char *file, int height, int width)
287 hscroll++; 245 hscroll++;
288 /* Reprint current page to scroll horizontally */ 246 /* Reprint current page to scroll horizontally */
289 back_lines(page_length); 247 back_lines(page_length);
290 print_page(text, height - 4, width - 2); 248 refresh_text_box(dialog, box, boxh, boxw,
291 wmove(dialog, cur_y, cur_x); 249 cur_y, cur_x);
292 wrefresh(dialog);
293 break; 250 break;
294 case ESC: 251 case KEY_ESC:
252 key = on_key_esc(dialog);
295 break; 253 break;
254 case KEY_RESIZE:
255 back_lines(height);
256 delwin(box);
257 delwin(dialog);
258 on_key_resize();
259 goto do_resize;
296 } 260 }
297 } 261 }
298 262 delwin(box);
299 delwin(dialog); 263 delwin(dialog);
300 free(buf); 264 return key; /* ESC pressed */
301 close(fd);
302 return -1; /* ESC pressed */
303} 265}
304 266
305/* 267/*
306 * Go back 'n' lines in text file. Called by dialog_textbox(). 268 * Go back 'n' lines in text. Called by dialog_textbox().
307 * 'page' will be updated to point to the desired line in 'buf'. 269 * 'page' will be updated to point to the desired line in 'buf'.
308 */ 270 */
309static void back_lines(int n) 271static void back_lines(int n)
310{ 272{
311 int i, fpos; 273 int i;
312 274
313 begin_reached = 0; 275 begin_reached = 0;
314 /* We have to distinguish between end_reached and !end_reached 276 /* Go back 'n' lines */
315 since at end of file, the line is not ended by a '\n'. 277 for (i = 0; i < n; i++) {
316 The code inside 'if' basically does a '--page' to move one 278 if (*page == '\0') {
317 character backward so as to skip '\n' of the previous line */ 279 if (end_reached) {
318 if (!end_reached) { 280 end_reached = 0;
319 /* Either beginning of buffer or beginning of file reached? */ 281 continue;
320 if (page == buf) {
321 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
322 endwin();
323 fprintf(stderr, "\nError moving file pointer in "
324 "back_lines().\n");
325 exit(-1);
326 }
327 if (fpos > bytes_read) { /* Not beginning of file yet */
328 /* We've reached beginning of buffer, but not beginning of
329 file yet, so read previous part of file into buffer.
330 Note that we only move backward for BUF_SIZE/2 bytes,
331 but not BUF_SIZE bytes to avoid re-reading again in
332 print_page() later */
333 /* Really possible to move backward BUF_SIZE/2 bytes? */
334 if (fpos < BUF_SIZE / 2 + bytes_read) {
335 /* No, move less then */
336 if (lseek(fd, 0, SEEK_SET) == -1) {
337 endwin();
338 fprintf(stderr, "\nError moving file pointer in "
339 "back_lines().\n");
340 exit(-1);
341 }
342 page = buf + fpos - bytes_read;
343 } else { /* Move backward BUF_SIZE/2 bytes */
344 if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) {
345 endwin();
346 fprintf(stderr, "\nError moving file pointer "
347 "in back_lines().\n");
348 exit(-1);
349 }
350 page = buf + BUF_SIZE / 2;
351 }
352 if ((bytes_read =
353 read(fd, buf, BUF_SIZE)) == -1) {
354 endwin();
355 fprintf(stderr, "\nError reading file in back_lines().\n");
356 exit(-1);
357 }
358 buf[bytes_read] = '\0';
359 } else { /* Beginning of file reached */
360 begin_reached = 1;
361 return;
362 } 282 }
363 } 283 }
364 if (*(--page) != '\n') { /* '--page' here */ 284 if (page == buf) {
365 /* Something's wrong... */ 285 begin_reached = 1;
366 endwin(); 286 return;
367 fprintf(stderr, "\nInternal error in back_lines().\n");
368 exit(-1);
369 } 287 }
370 } 288 page--;
371 /* Go back 'n' lines */
372 for (i = 0; i < n; i++)
373 do { 289 do {
374 if (page == buf) { 290 if (page == buf) {
375 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { 291 begin_reached = 1;
376 endwin(); 292 return;
377 fprintf(stderr, "\nError moving file pointer in back_lines().\n");
378 exit(-1);
379 }
380 if (fpos > bytes_read) {
381 /* Really possible to move backward BUF_SIZE/2 bytes? */
382 if (fpos < BUF_SIZE / 2 + bytes_read) {
383 /* No, move less then */
384 if (lseek(fd, 0, SEEK_SET) == -1) {
385 endwin();
386 fprintf(stderr, "\nError moving file pointer "
387 "in back_lines().\n");
388 exit(-1);
389 }
390 page = buf + fpos - bytes_read;
391 } else { /* Move backward BUF_SIZE/2 bytes */
392 if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) {
393 endwin();
394 fprintf(stderr, "\nError moving file pointer"
395 " in back_lines().\n");
396 exit(-1);
397 }
398 page = buf + BUF_SIZE / 2;
399 }
400 if ((bytes_read =
401 read(fd, buf, BUF_SIZE)) == -1) {
402 endwin();
403 fprintf(stderr, "\nError reading file in "
404 "back_lines().\n");
405 exit(-1);
406 }
407 buf[bytes_read] = '\0';
408 } else { /* Beginning of file reached */
409 begin_reached = 1;
410 return;
411 }
412 } 293 }
413 } while (*(--page) != '\n'); 294 page--;
414 page++; 295 } while (*page != '\n');
296 page++;
297 }
415} 298}
416 299
417/* 300/*
@@ -466,33 +349,14 @@ static void print_line(WINDOW * win, int row, int width)
466 */ 349 */
467static char *get_line(void) 350static char *get_line(void)
468{ 351{
469 int i = 0, fpos; 352 int i = 0;
470 static char line[MAX_LEN + 1]; 353 static char line[MAX_LEN + 1];
471 354
472 end_reached = 0; 355 end_reached = 0;
473 while (*page != '\n') { 356 while (*page != '\n') {
474 if (*page == '\0') { 357 if (*page == '\0') {
475 /* Either end of file or end of buffer reached */ 358 if (!end_reached) {
476 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { 359 end_reached = 1;
477 endwin();
478 fprintf(stderr, "\nError moving file pointer in "
479 "get_line().\n");
480 exit(-1);
481 }
482 if (fpos < file_size) { /* Not end of file yet */
483 /* We've reached end of buffer, but not end of file yet,
484 so read next part of file into buffer */
485 if ((bytes_read =
486 read(fd, buf, BUF_SIZE)) == -1) {
487 endwin();
488 fprintf(stderr, "\nError reading file in get_line().\n");
489 exit(-1);
490 }
491 buf[bytes_read] = '\0';
492 page = buf;
493 } else {
494 if (!end_reached)
495 end_reached = 1;
496 break; 360 break;
497 } 361 }
498 } else if (i < MAX_LEN) 362 } else if (i < MAX_LEN)
@@ -515,19 +379,13 @@ static char *get_line(void)
515/* 379/*
516 * Print current position 380 * Print current position
517 */ 381 */
518static void print_position(WINDOW * win, int height, int width) 382static void print_position(WINDOW * win)
519{ 383{
520 int fpos, percent; 384 int percent;
521 385
522 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { 386 wattrset(win, dlg.position_indicator.atr);
523 endwin(); 387 wbkgdset(win, dlg.position_indicator.atr & A_COLOR);
524 fprintf(stderr, "\nError moving file pointer in print_position().\n"); 388 percent = (page - buf) * 100 / strlen(buf);
525 exit(-1); 389 wmove(win, getmaxy(win) - 3, getmaxx(win) - 9);
526 }
527 wattrset(win, position_indicator_attr);
528 wbkgdset(win, position_indicator_attr & A_COLOR);
529 percent = !file_size ?
530 100 : ((fpos - bytes_read + page - buf) * 100) / file_size;
531 wmove(win, height - 3, width - 9);
532 wprintw(win, "(%3d%%)", percent); 390 wprintw(win, "(%3d%%)", percent);
533} 391}
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index f82cebb9ff06..ebc781b493d7 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -21,85 +21,217 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24/* use colors by default? */ 24struct dialog_info dlg;
25bool use_colors = 1;
26 25
27const char *backtitle = NULL; 26static void set_mono_theme(void)
27{
28 dlg.screen.atr = A_NORMAL;
29 dlg.shadow.atr = A_NORMAL;
30 dlg.dialog.atr = A_NORMAL;
31 dlg.title.atr = A_BOLD;
32 dlg.border.atr = A_NORMAL;
33 dlg.button_active.atr = A_REVERSE;
34 dlg.button_inactive.atr = A_DIM;
35 dlg.button_key_active.atr = A_REVERSE;
36 dlg.button_key_inactive.atr = A_BOLD;
37 dlg.button_label_active.atr = A_REVERSE;
38 dlg.button_label_inactive.atr = A_NORMAL;
39 dlg.inputbox.atr = A_NORMAL;
40 dlg.inputbox_border.atr = A_NORMAL;
41 dlg.searchbox.atr = A_NORMAL;
42 dlg.searchbox_title.atr = A_BOLD;
43 dlg.searchbox_border.atr = A_NORMAL;
44 dlg.position_indicator.atr = A_BOLD;
45 dlg.menubox.atr = A_NORMAL;
46 dlg.menubox_border.atr = A_NORMAL;
47 dlg.item.atr = A_NORMAL;
48 dlg.item_selected.atr = A_REVERSE;
49 dlg.tag.atr = A_BOLD;
50 dlg.tag_selected.atr = A_REVERSE;
51 dlg.tag_key.atr = A_BOLD;
52 dlg.tag_key_selected.atr = A_REVERSE;
53 dlg.check.atr = A_BOLD;
54 dlg.check_selected.atr = A_REVERSE;
55 dlg.uarrow.atr = A_BOLD;
56 dlg.darrow.atr = A_BOLD;
57}
58
59#define DLG_COLOR(dialog, f, b, h) \
60do { \
61 dlg.dialog.fg = (f); \
62 dlg.dialog.bg = (b); \
63 dlg.dialog.hl = (h); \
64} while (0)
65
66static void set_classic_theme(void)
67{
68 DLG_COLOR(screen, COLOR_CYAN, COLOR_BLUE, true);
69 DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, true);
70 DLG_COLOR(dialog, COLOR_BLACK, COLOR_WHITE, false);
71 DLG_COLOR(title, COLOR_YELLOW, COLOR_WHITE, true);
72 DLG_COLOR(border, COLOR_WHITE, COLOR_WHITE, true);
73 DLG_COLOR(button_active, COLOR_WHITE, COLOR_BLUE, true);
74 DLG_COLOR(button_inactive, COLOR_BLACK, COLOR_WHITE, false);
75 DLG_COLOR(button_key_active, COLOR_WHITE, COLOR_BLUE, true);
76 DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_WHITE, false);
77 DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true);
78 DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true);
79 DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false);
80 DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false);
81 DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false);
82 DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true);
83 DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true);
84 DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true);
85 DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false);
86 DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true);
87 DLG_COLOR(item, COLOR_BLACK, COLOR_WHITE, false);
88 DLG_COLOR(item_selected, COLOR_WHITE, COLOR_BLUE, true);
89 DLG_COLOR(tag, COLOR_YELLOW, COLOR_WHITE, true);
90 DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_BLUE, true);
91 DLG_COLOR(tag_key, COLOR_YELLOW, COLOR_WHITE, true);
92 DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_BLUE, true);
93 DLG_COLOR(check, COLOR_BLACK, COLOR_WHITE, false);
94 DLG_COLOR(check_selected, COLOR_WHITE, COLOR_BLUE, true);
95 DLG_COLOR(uarrow, COLOR_GREEN, COLOR_WHITE, true);
96 DLG_COLOR(darrow, COLOR_GREEN, COLOR_WHITE, true);
97}
98
99static void set_blackbg_theme(void)
100{
101 DLG_COLOR(screen, COLOR_RED, COLOR_BLACK, true);
102 DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, false);
103 DLG_COLOR(dialog, COLOR_WHITE, COLOR_BLACK, false);
104 DLG_COLOR(title, COLOR_RED, COLOR_BLACK, false);
105 DLG_COLOR(border, COLOR_BLACK, COLOR_BLACK, true);
106
107 DLG_COLOR(button_active, COLOR_YELLOW, COLOR_RED, false);
108 DLG_COLOR(button_inactive, COLOR_YELLOW, COLOR_BLACK, false);
109 DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_RED, true);
110 DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_BLACK, false);
111 DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_RED, false);
112 DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_BLACK, true);
113
114 DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false);
115 DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false);
116
117 DLG_COLOR(searchbox, COLOR_YELLOW, COLOR_BLACK, false);
118 DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_BLACK, true);
119 DLG_COLOR(searchbox_border, COLOR_BLACK, COLOR_BLACK, true);
120
121 DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK, false);
122
123 DLG_COLOR(menubox, COLOR_YELLOW, COLOR_BLACK, false);
124 DLG_COLOR(menubox_border, COLOR_BLACK, COLOR_BLACK, true);
125
126 DLG_COLOR(item, COLOR_WHITE, COLOR_BLACK, false);
127 DLG_COLOR(item_selected, COLOR_WHITE, COLOR_RED, false);
128
129 DLG_COLOR(tag, COLOR_RED, COLOR_BLACK, false);
130 DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_RED, true);
131 DLG_COLOR(tag_key, COLOR_RED, COLOR_BLACK, false);
132 DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_RED, true);
133
134 DLG_COLOR(check, COLOR_YELLOW, COLOR_BLACK, false);
135 DLG_COLOR(check_selected, COLOR_YELLOW, COLOR_RED, true);
136
137 DLG_COLOR(uarrow, COLOR_RED, COLOR_BLACK, false);
138 DLG_COLOR(darrow, COLOR_RED, COLOR_BLACK, false);
139}
140
141static void set_bluetitle_theme(void)
142{
143 set_classic_theme();
144 DLG_COLOR(title, COLOR_BLUE, COLOR_WHITE, true);
145 DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_BLUE, true);
146 DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_BLUE, true);
147 DLG_COLOR(searchbox_title, COLOR_BLUE, COLOR_WHITE, true);
148 DLG_COLOR(position_indicator, COLOR_BLUE, COLOR_WHITE, true);
149 DLG_COLOR(tag, COLOR_BLUE, COLOR_WHITE, true);
150 DLG_COLOR(tag_key, COLOR_BLUE, COLOR_WHITE, true);
151
152}
28 153
29/* 154/*
30 * Attribute values, default is for mono display 155 * Select color theme
31 */ 156 */
32chtype attributes[] = { 157static int set_theme(const char *theme)
33 A_NORMAL, /* screen_attr */ 158{
34 A_NORMAL, /* shadow_attr */ 159 int use_color = 1;
35 A_NORMAL, /* dialog_attr */ 160 if (!theme)
36 A_BOLD, /* title_attr */ 161 set_bluetitle_theme();
37 A_NORMAL, /* border_attr */ 162 else if (strcmp(theme, "classic") == 0)
38 A_REVERSE, /* button_active_attr */ 163 set_classic_theme();
39 A_DIM, /* button_inactive_attr */ 164 else if (strcmp(theme, "bluetitle") == 0)
40 A_REVERSE, /* button_key_active_attr */ 165 set_bluetitle_theme();
41 A_BOLD, /* button_key_inactive_attr */ 166 else if (strcmp(theme, "blackbg") == 0)
42 A_REVERSE, /* button_label_active_attr */ 167 set_blackbg_theme();
43 A_NORMAL, /* button_label_inactive_attr */ 168 else if (strcmp(theme, "mono") == 0)
44 A_NORMAL, /* inputbox_attr */ 169 use_color = 0;
45 A_NORMAL, /* inputbox_border_attr */ 170
46 A_NORMAL, /* searchbox_attr */ 171 return use_color;
47 A_BOLD, /* searchbox_title_attr */ 172}
48 A_NORMAL, /* searchbox_border_attr */ 173
49 A_BOLD, /* position_indicator_attr */ 174static void init_one_color(struct dialog_color *color)
50 A_NORMAL, /* menubox_attr */ 175{
51 A_NORMAL, /* menubox_border_attr */ 176 static int pair = 0;
52 A_NORMAL, /* item_attr */ 177
53 A_REVERSE, /* item_selected_attr */ 178 pair++;
54 A_BOLD, /* tag_attr */ 179 init_pair(pair, color->fg, color->bg);
55 A_REVERSE, /* tag_selected_attr */ 180 if (color->hl)
56 A_BOLD, /* tag_key_attr */ 181 color->atr = A_BOLD | COLOR_PAIR(pair);
57 A_REVERSE, /* tag_key_selected_attr */ 182 else
58 A_BOLD, /* check_attr */ 183 color->atr = COLOR_PAIR(pair);
59 A_REVERSE, /* check_selected_attr */ 184}
60 A_BOLD, /* uarrow_attr */ 185
61 A_BOLD /* darrow_attr */ 186static void init_dialog_colors(void)
62}; 187{
63 188 init_one_color(&dlg.screen);
64#include "colors.h" 189 init_one_color(&dlg.shadow);
190 init_one_color(&dlg.dialog);
191 init_one_color(&dlg.title);
192 init_one_color(&dlg.border);
193 init_one_color(&dlg.button_active);
194 init_one_color(&dlg.button_inactive);
195 init_one_color(&dlg.button_key_active);
196 init_one_color(&dlg.button_key_inactive);
197 init_one_color(&dlg.button_label_active);
198 init_one_color(&dlg.button_label_inactive);
199 init_one_color(&dlg.inputbox);
200 init_one_color(&dlg.inputbox_border);
201 init_one_color(&dlg.searchbox);
202 init_one_color(&dlg.searchbox_title);
203 init_one_color(&dlg.searchbox_border);
204 init_one_color(&dlg.position_indicator);
205 init_one_color(&dlg.menubox);
206 init_one_color(&dlg.menubox_border);
207 init_one_color(&dlg.item);
208 init_one_color(&dlg.item_selected);
209 init_one_color(&dlg.tag);
210 init_one_color(&dlg.tag_selected);
211 init_one_color(&dlg.tag_key);
212 init_one_color(&dlg.tag_key_selected);
213 init_one_color(&dlg.check);
214 init_one_color(&dlg.check_selected);
215 init_one_color(&dlg.uarrow);
216 init_one_color(&dlg.darrow);
217}
65 218
66/* 219/*
67 * Table of color values 220 * Setup for color display
68 */ 221 */
69int color_table[][3] = { 222static void color_setup(const char *theme)
70 {SCREEN_FG, SCREEN_BG, SCREEN_HL}, 223{
71 {SHADOW_FG, SHADOW_BG, SHADOW_HL}, 224 if (set_theme(theme)) {
72 {DIALOG_FG, DIALOG_BG, DIALOG_HL}, 225 if (has_colors()) { /* Terminal supports color? */
73 {TITLE_FG, TITLE_BG, TITLE_HL}, 226 start_color();
74 {BORDER_FG, BORDER_BG, BORDER_HL}, 227 init_dialog_colors();
75 {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, 228 }
76 {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, 229 }
77 {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, 230 else
78 {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, 231 {
79 BUTTON_KEY_INACTIVE_HL}, 232 set_mono_theme();
80 {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, 233 }
81 BUTTON_LABEL_ACTIVE_HL}, 234}
82 {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG,
83 BUTTON_LABEL_INACTIVE_HL},
84 {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL},
85 {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL},
86 {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL},
87 {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL},
88 {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL},
89 {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL},
90 {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL},
91 {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL},
92 {ITEM_FG, ITEM_BG, ITEM_HL},
93 {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL},
94 {TAG_FG, TAG_BG, TAG_HL},
95 {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL},
96 {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL},
97 {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL},
98 {CHECK_FG, CHECK_BG, CHECK_HL},
99 {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL},
100 {UARROW_FG, UARROW_BG, UARROW_HL},
101 {DARROW_FG, DARROW_BG, DARROW_HL},
102}; /* color_table */
103 235
104/* 236/*
105 * Set window to attribute 'attr' 237 * Set window to attribute 'attr'
@@ -119,13 +251,13 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr)
119 251
120void dialog_clear(void) 252void dialog_clear(void)
121{ 253{
122 attr_clear(stdscr, LINES, COLS, screen_attr); 254 attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
123 /* Display background title if it exists ... - SLH */ 255 /* Display background title if it exists ... - SLH */
124 if (backtitle != NULL) { 256 if (dlg.backtitle != NULL) {
125 int i; 257 int i;
126 258
127 wattrset(stdscr, screen_attr); 259 wattrset(stdscr, dlg.screen.atr);
128 mvwaddstr(stdscr, 0, 1, (char *)backtitle); 260 mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle);
129 wmove(stdscr, 1, 1); 261 wmove(stdscr, 1, 1);
130 for (i = 1; i < COLS - 1; i++) 262 for (i = 1; i < COLS - 1; i++)
131 waddch(stdscr, ACS_HLINE); 263 waddch(stdscr, ACS_HLINE);
@@ -136,40 +268,22 @@ void dialog_clear(void)
136/* 268/*
137 * Do some initialization for dialog 269 * Do some initialization for dialog
138 */ 270 */
139void init_dialog(void) 271void init_dialog(const char *backtitle)
272{
273 dlg.backtitle = backtitle;
274 color_setup(getenv("MENUCONFIG_COLOR"));
275}
276
277void reset_dialog(void)
140{ 278{
141 initscr(); /* Init curses */ 279 initscr(); /* Init curses */
142 keypad(stdscr, TRUE); 280 keypad(stdscr, TRUE);
143 cbreak(); 281 cbreak();
144 noecho(); 282 noecho();
145
146 if (use_colors) /* Set up colors */
147 color_setup();
148
149 dialog_clear(); 283 dialog_clear();
150} 284}
151 285
152/* 286/*
153 * Setup for color display
154 */
155void color_setup(void)
156{
157 int i;
158
159 if (has_colors()) { /* Terminal supports color? */
160 start_color();
161
162 /* Initialize color pairs */
163 for (i = 0; i < ATTRIBUTE_COUNT; i++)
164 init_pair(i + 1, color_table[i][0], color_table[i][1]);
165
166 /* Setup color attributes */
167 for (i = 0; i < ATTRIBUTE_COUNT; i++)
168 attributes[i] = C_ATTR(color_table[i][2], i + 1);
169 }
170}
171
172/*
173 * End using dialog functions. 287 * End using dialog functions.
174 */ 288 */
175void end_dialog(void) 289void end_dialog(void)
@@ -184,7 +298,7 @@ void print_title(WINDOW *dialog, const char *title, int width)
184{ 298{
185 if (title) { 299 if (title) {
186 int tlen = MIN(width - 2, strlen(title)); 300 int tlen = MIN(width - 2, strlen(title));
187 wattrset(dialog, title_attr); 301 wattrset(dialog, dlg.title.atr);
188 mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' '); 302 mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' ');
189 mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen); 303 mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen);
190 waddch(dialog, ' '); 304 waddch(dialog, ' ');
@@ -264,21 +378,23 @@ void print_button(WINDOW * win, const char *label, int y, int x, int selected)
264 int i, temp; 378 int i, temp;
265 379
266 wmove(win, y, x); 380 wmove(win, y, x);
267 wattrset(win, selected ? button_active_attr : button_inactive_attr); 381 wattrset(win, selected ? dlg.button_active.atr
382 : dlg.button_inactive.atr);
268 waddstr(win, "<"); 383 waddstr(win, "<");
269 temp = strspn(label, " "); 384 temp = strspn(label, " ");
270 label += temp; 385 label += temp;
271 wattrset(win, selected ? button_label_active_attr 386 wattrset(win, selected ? dlg.button_label_active.atr
272 : button_label_inactive_attr); 387 : dlg.button_label_inactive.atr);
273 for (i = 0; i < temp; i++) 388 for (i = 0; i < temp; i++)
274 waddch(win, ' '); 389 waddch(win, ' ');
275 wattrset(win, selected ? button_key_active_attr 390 wattrset(win, selected ? dlg.button_key_active.atr
276 : button_key_inactive_attr); 391 : dlg.button_key_inactive.atr);
277 waddch(win, label[0]); 392 waddch(win, label[0]);
278 wattrset(win, selected ? button_label_active_attr 393 wattrset(win, selected ? dlg.button_label_active.atr
279 : button_label_inactive_attr); 394 : dlg.button_label_inactive.atr);
280 waddstr(win, (char *)label + 1); 395 waddstr(win, (char *)label + 1);
281 wattrset(win, selected ? button_active_attr : button_inactive_attr); 396 wattrset(win, selected ? dlg.button_active.atr
397 : dlg.button_inactive.atr);
282 waddstr(win, ">"); 398 waddstr(win, ">");
283 wmove(win, y, x + temp + 1); 399 wmove(win, y, x + temp + 1);
284} 400}
@@ -326,7 +442,7 @@ void draw_shadow(WINDOW * win, int y, int x, int height, int width)
326 int i; 442 int i;
327 443
328 if (has_colors()) { /* Whether terminal supports color? */ 444 if (has_colors()) { /* Whether terminal supports color? */
329 wattrset(win, shadow_attr); 445 wattrset(win, dlg.shadow.atr);
330 wmove(win, y + height, x + 2); 446 wmove(win, y + height, x + 2);
331 for (i = 0; i < width; i++) 447 for (i = 0; i < width; i++)
332 waddch(win, winch(win) & A_CHARTEXT); 448 waddch(win, winch(win) & A_CHARTEXT);
@@ -360,3 +476,167 @@ int first_alpha(const char *string, const char *exempt)
360 476
361 return 0; 477 return 0;
362} 478}
479
480/*
481 * ncurses uses ESC to detect escaped char sequences. This resutl in
482 * a small timeout before ESC is actually delivered to the application.
483 * lxdialog suggest <ESC> <ESC> which is correctly translated to two
484 * times esc. But then we need to ignore the second esc to avoid stepping
485 * out one menu too much. Filter away all escaped key sequences since
486 * keypad(FALSE) turn off ncurses support for escape sequences - and thats
487 * needed to make notimeout() do as expected.
488 */
489int on_key_esc(WINDOW *win)
490{
491 int key;
492 int key2;
493 int key3;
494
495 nodelay(win, TRUE);
496 keypad(win, FALSE);
497 key = wgetch(win);
498 key2 = wgetch(win);
499 do {
500 key3 = wgetch(win);
501 } while (key3 != ERR);
502 nodelay(win, FALSE);
503 keypad(win, TRUE);
504 if (key == KEY_ESC && key2 == ERR)
505 return KEY_ESC;
506 else if (key != ERR && key != KEY_ESC && key2 == ERR)
507 ungetch(key);
508
509 return -1;
510}
511
512/* redraw screen in new size */
513int on_key_resize(void)
514{
515 dialog_clear();
516 return KEY_RESIZE;
517}
518
519struct dialog_list *item_cur;
520struct dialog_list item_nil;
521struct dialog_list *item_head;
522
523void item_reset(void)
524{
525 struct dialog_list *p, *next;
526
527 for (p = item_head; p; p = next) {
528 next = p->next;
529 free(p);
530 }
531 item_head = NULL;
532 item_cur = &item_nil;
533}
534
535void item_make(const char *fmt, ...)
536{
537 va_list ap;
538 struct dialog_list *p = malloc(sizeof(*p));
539
540 if (item_head)
541 item_cur->next = p;
542 else
543 item_head = p;
544 item_cur = p;
545 memset(p, 0, sizeof(*p));
546
547 va_start(ap, fmt);
548 vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap);
549 va_end(ap);
550}
551
552void item_add_str(const char *fmt, ...)
553{
554 va_list ap;
555 size_t avail;
556
557 avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str);
558
559 va_start(ap, fmt);
560 vsnprintf(item_cur->node.str + strlen(item_cur->node.str),
561 avail, fmt, ap);
562 item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0';
563 va_end(ap);
564}
565
566void item_set_tag(char tag)
567{
568 item_cur->node.tag = tag;
569}
570void item_set_data(void *ptr)
571{
572 item_cur->node.data = ptr;
573}
574
575void item_set_selected(int val)
576{
577 item_cur->node.selected = val;
578}
579
580int item_activate_selected(void)
581{
582 item_foreach()
583 if (item_is_selected())
584 return 1;
585 return 0;
586}
587
588void *item_data(void)
589{
590 return item_cur->node.data;
591}
592
593char item_tag(void)
594{
595 return item_cur->node.tag;
596}
597
598int item_count(void)
599{
600 int n = 0;
601 struct dialog_list *p;
602
603 for (p = item_head; p; p = p->next)
604 n++;
605 return n;
606}
607
608void item_set(int n)
609{
610 int i = 0;
611 item_foreach()
612 if (i++ == n)
613 return;
614}
615
616int item_n(void)
617{
618 int n = 0;
619 struct dialog_list *p;
620
621 for (p = item_head; p; p = p->next) {
622 if (p == item_cur)
623 return n;
624 n++;
625 }
626 return 0;
627}
628
629const char *item_str(void)
630{
631 return item_cur->node.str;
632}
633
634int item_is_selected(void)
635{
636 return (item_cur->node.selected != 0);
637}
638
639int item_is_tag(char tag)
640{
641 return (item_cur->node.tag == tag);
642}
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c
index cb2568aae3ed..ee0a04e3e012 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -44,6 +44,12 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
44 int i, x, y, key = 0, button = 0; 44 int i, x, y, key = 0, button = 0;
45 WINDOW *dialog; 45 WINDOW *dialog;
46 46
47do_resize:
48 if (getmaxy(stdscr) < (height + 4))
49 return -ERRDISPLAYTOOSMALL;
50 if (getmaxx(stdscr) < (width + 4))
51 return -ERRDISPLAYTOOSMALL;
52
47 /* center dialog box on screen */ 53 /* center dialog box on screen */
48 x = (COLS - width) / 2; 54 x = (COLS - width) / 2;
49 y = (LINES - height) / 2; 55 y = (LINES - height) / 2;
@@ -53,22 +59,23 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
53 dialog = newwin(height, width, y, x); 59 dialog = newwin(height, width, y, x);
54 keypad(dialog, TRUE); 60 keypad(dialog, TRUE);
55 61
56 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 62 draw_box(dialog, 0, 0, height, width,
57 wattrset(dialog, border_attr); 63 dlg.dialog.atr, dlg.border.atr);
64 wattrset(dialog, dlg.border.atr);
58 mvwaddch(dialog, height - 3, 0, ACS_LTEE); 65 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
59 for (i = 0; i < width - 2; i++) 66 for (i = 0; i < width - 2; i++)
60 waddch(dialog, ACS_HLINE); 67 waddch(dialog, ACS_HLINE);
61 wattrset(dialog, dialog_attr); 68 wattrset(dialog, dlg.dialog.atr);
62 waddch(dialog, ACS_RTEE); 69 waddch(dialog, ACS_RTEE);
63 70
64 print_title(dialog, title, width); 71 print_title(dialog, title, width);
65 72
66 wattrset(dialog, dialog_attr); 73 wattrset(dialog, dlg.dialog.atr);
67 print_autowrap(dialog, prompt, width - 2, 1, 3); 74 print_autowrap(dialog, prompt, width - 2, 1, 3);
68 75
69 print_buttons(dialog, height, width, 0); 76 print_buttons(dialog, height, width, 0);
70 77
71 while (key != ESC) { 78 while (key != KEY_ESC) {
72 key = wgetch(dialog); 79 key = wgetch(dialog);
73 switch (key) { 80 switch (key) {
74 case 'Y': 81 case 'Y':
@@ -92,11 +99,16 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
92 case '\n': 99 case '\n':
93 delwin(dialog); 100 delwin(dialog);
94 return button; 101 return button;
95 case ESC: 102 case KEY_ESC:
103 key = on_key_esc(dialog);
96 break; 104 break;
105 case KEY_RESIZE:
106 delwin(dialog);
107 on_key_resize();
108 goto do_resize;
97 } 109 }
98 } 110 }
99 111
100 delwin(dialog); 112 delwin(dialog);
101 return -1; /* ESC pressed */ 113 return key; /* ESC pressed */
102} 114}
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 7f973195e79a..08a4c7af93ea 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -24,6 +24,7 @@
24 24
25#define LKC_DIRECT_LINK 25#define LKC_DIRECT_LINK
26#include "lkc.h" 26#include "lkc.h"
27#include "lxdialog/dialog.h"
27 28
28static char menu_backtitle[128]; 29static char menu_backtitle[128];
29static const char mconf_readme[] = N_( 30static const char mconf_readme[] = N_(
@@ -159,7 +160,21 @@ static const char mconf_readme[] = N_(
159"\n" 160"\n"
160"Note that this mode can eventually be a little more CPU expensive\n" 161"Note that this mode can eventually be a little more CPU expensive\n"
161"(especially with a larger number of unrolled categories) than the\n" 162"(especially with a larger number of unrolled categories) than the\n"
162"default mode.\n"), 163"default mode.\n"
164"\n"
165"Different color themes available\n"
166"--------------------------------\n"
167"It is possible to select different color themes using the variable\n"
168"MENUCONFIG_COLOR. To select a theme use:\n"
169"\n"
170"make MENUCONFIG_COLOR=<theme> menuconfig\n"
171"\n"
172"Available themes are\n"
173" mono => selects colors suitable for monochrome displays\n"
174" blackbg => selects a color scheme with black background\n"
175" classic => theme with blue background. The classic look\n"
176" bluetitle => a LCD friendly version of classic. (default)\n"
177"\n"),
163menu_instructions[] = N_( 178menu_instructions[] = N_(
164 "Arrow keys navigate the menu. " 179 "Arrow keys navigate the menu. "
165 "<Enter> selects submenus --->. " 180 "<Enter> selects submenus --->. "
@@ -256,16 +271,12 @@ search_help[] = N_(
256 " USB$ => find all CONFIG_ symbols ending with USB\n" 271 " USB$ => find all CONFIG_ symbols ending with USB\n"
257 "\n"); 272 "\n");
258 273
259static char buf[4096], *bufptr = buf;
260static char input_buf[4096];
261static char filename[PATH_MAX+1] = ".config"; 274static char filename[PATH_MAX+1] = ".config";
262static char *args[1024], **argptr = args;
263static int indent; 275static int indent;
264static struct termios ios_org; 276static struct termios ios_org;
265static int rows = 0, cols = 0; 277static int rows = 0, cols = 0;
266static struct menu *current_menu; 278static struct menu *current_menu;
267static int child_count; 279static int child_count;
268static int do_resize;
269static int single_menu_mode; 280static int single_menu_mode;
270 281
271static void conf(struct menu *menu); 282static void conf(struct menu *menu);
@@ -276,12 +287,6 @@ static void conf_save(void);
276static void show_textbox(const char *title, const char *text, int r, int c); 287static void show_textbox(const char *title, const char *text, int r, int c);
277static void show_helptext(const char *title, const char *text); 288static void show_helptext(const char *title, const char *text);
278static void show_help(struct menu *menu); 289static void show_help(struct menu *menu);
279static void show_file(const char *filename, const char *title, int r, int c);
280
281static void cprint_init(void);
282static int cprint1(const char *fmt, ...);
283static void cprint_done(void);
284static int cprint(const char *fmt, ...);
285 290
286static void init_wsize(void) 291static void init_wsize(void)
287{ 292{
@@ -318,54 +323,6 @@ static void init_wsize(void)
318 cols -= 5; 323 cols -= 5;
319} 324}
320 325
321static void cprint_init(void)
322{
323 bufptr = buf;
324 argptr = args;
325 memset(args, 0, sizeof(args));
326 indent = 0;
327 child_count = 0;
328 cprint("./scripts/kconfig/lxdialog/lxdialog");
329 cprint("--backtitle");
330 cprint(menu_backtitle);
331}
332
333static int cprint1(const char *fmt, ...)
334{
335 va_list ap;
336 int res;
337
338 if (!*argptr)
339 *argptr = bufptr;
340 va_start(ap, fmt);
341 res = vsprintf(bufptr, fmt, ap);
342 va_end(ap);
343 bufptr += res;
344
345 return res;
346}
347
348static void cprint_done(void)
349{
350 *bufptr++ = 0;
351 argptr++;
352}
353
354static int cprint(const char *fmt, ...)
355{
356 va_list ap;
357 int res;
358
359 *argptr++ = bufptr;
360 va_start(ap, fmt);
361 res = vsprintf(bufptr, fmt, ap);
362 va_end(ap);
363 bufptr += res;
364 *bufptr++ = 0;
365
366 return res;
367}
368
369static void get_prompt_str(struct gstr *r, struct property *prop) 326static void get_prompt_str(struct gstr *r, struct property *prop)
370{ 327{
371 int i, j; 328 int i, j;
@@ -438,108 +395,17 @@ static struct gstr get_relations_str(struct symbol **sym_arr)
438 return res; 395 return res;
439} 396}
440 397
441pid_t pid;
442
443static void winch_handler(int sig)
444{
445 if (!do_resize) {
446 kill(pid, SIGINT);
447 do_resize = 1;
448 }
449}
450
451static int exec_conf(void)
452{
453 int pipefd[2], stat, size;
454 struct sigaction sa;
455 sigset_t sset, osset;
456
457 sigemptyset(&sset);
458 sigaddset(&sset, SIGINT);
459 sigprocmask(SIG_BLOCK, &sset, &osset);
460
461 signal(SIGINT, SIG_DFL);
462
463 sa.sa_handler = winch_handler;
464 sigemptyset(&sa.sa_mask);
465 sa.sa_flags = SA_RESTART;
466 sigaction(SIGWINCH, &sa, NULL);
467
468 *argptr++ = NULL;
469
470 pipe(pipefd);
471 pid = fork();
472 if (pid == 0) {
473 sigprocmask(SIG_SETMASK, &osset, NULL);
474 dup2(pipefd[1], 2);
475 close(pipefd[0]);
476 close(pipefd[1]);
477 execv(args[0], args);
478 _exit(EXIT_FAILURE);
479 }
480
481 close(pipefd[1]);
482 bufptr = input_buf;
483 while (1) {
484 size = input_buf + sizeof(input_buf) - bufptr;
485 size = read(pipefd[0], bufptr, size);
486 if (size <= 0) {
487 if (size < 0) {
488 if (errno == EINTR || errno == EAGAIN)
489 continue;
490 perror("read");
491 }
492 break;
493 }
494 bufptr += size;
495 }
496 *bufptr++ = 0;
497 close(pipefd[0]);
498 waitpid(pid, &stat, 0);
499
500 if (do_resize) {
501 init_wsize();
502 do_resize = 0;
503 sigprocmask(SIG_SETMASK, &osset, NULL);
504 return -1;
505 }
506 if (WIFSIGNALED(stat)) {
507 printf("\finterrupted(%d)\n", WTERMSIG(stat));
508 exit(1);
509 }
510#if 0
511 printf("\fexit state: %d\nexit data: '%s'\n", WEXITSTATUS(stat), input_buf);
512 sleep(1);
513#endif
514 sigpending(&sset);
515 if (sigismember(&sset, SIGINT)) {
516 printf("\finterrupted\n");
517 exit(1);
518 }
519 sigprocmask(SIG_SETMASK, &osset, NULL);
520
521 return WEXITSTATUS(stat);
522}
523
524static void search_conf(void) 398static void search_conf(void)
525{ 399{
526 struct symbol **sym_arr; 400 struct symbol **sym_arr;
527 int stat;
528 struct gstr res; 401 struct gstr res;
529 402 int dres;
530again: 403again:
531 cprint_init(); 404 dialog_clear();
532 cprint("--title"); 405 dres = dialog_inputbox(_("Search Configuration Parameter"),
533 cprint(_("Search Configuration Parameter")); 406 _("Enter CONFIG_ (sub)string to search for (omit CONFIG_)"),
534 cprint("--inputbox"); 407 10, 75, "");
535 cprint(_("Enter CONFIG_ (sub)string to search for (omit CONFIG_)")); 408 switch (dres) {
536 cprint("10");
537 cprint("75");
538 cprint("");
539 stat = exec_conf();
540 if (stat < 0)
541 goto again;
542 switch (stat) {
543 case 0: 409 case 0:
544 break; 410 break;
545 case 1: 411 case 1:
@@ -549,7 +415,7 @@ again:
549 return; 415 return;
550 } 416 }
551 417
552 sym_arr = sym_re_search(input_buf); 418 sym_arr = sym_re_search(dialog_input_result);
553 res = get_relations_str(sym_arr); 419 res = get_relations_str(sym_arr);
554 free(sym_arr); 420 free(sym_arr);
555 show_textbox(_("Search Results"), str_get(&res), 0, 0); 421 show_textbox(_("Search Results"), str_get(&res), 0, 0);
@@ -576,24 +442,24 @@ static void build_conf(struct menu *menu)
576 switch (prop->type) { 442 switch (prop->type) {
577 case P_MENU: 443 case P_MENU:
578 child_count++; 444 child_count++;
579 cprint("m%p", menu);
580
581 if (single_menu_mode) { 445 if (single_menu_mode) {
582 cprint1("%s%*c%s", 446 item_make("%s%*c%s",
583 menu->data ? "-->" : "++>", 447 menu->data ? "-->" : "++>",
584 indent + 1, ' ', prompt); 448 indent + 1, ' ', prompt);
585 } else 449 } else
586 cprint1(" %*c%s --->", indent + 1, ' ', prompt); 450 item_make(" %*c%s --->", indent + 1, ' ', prompt);
587 451
588 cprint_done(); 452 item_set_tag('m');
453 item_set_data(menu);
589 if (single_menu_mode && menu->data) 454 if (single_menu_mode && menu->data)
590 goto conf_childs; 455 goto conf_childs;
591 return; 456 return;
592 default: 457 default:
593 if (prompt) { 458 if (prompt) {
594 child_count++; 459 child_count++;
595 cprint(":%p", menu); 460 item_make("---%*c%s", indent + 1, ' ', prompt);
596 cprint("---%*c%s", indent + 1, ' ', prompt); 461 item_set_tag(':');
462 item_set_data(menu);
597 } 463 }
598 } 464 }
599 } else 465 } else
@@ -614,10 +480,9 @@ static void build_conf(struct menu *menu)
614 480
615 val = sym_get_tristate_value(sym); 481 val = sym_get_tristate_value(sym);
616 if (sym_is_changable(sym)) { 482 if (sym_is_changable(sym)) {
617 cprint("t%p", menu);
618 switch (type) { 483 switch (type) {
619 case S_BOOLEAN: 484 case S_BOOLEAN:
620 cprint1("[%c]", val == no ? ' ' : '*'); 485 item_make("[%c]", val == no ? ' ' : '*');
621 break; 486 break;
622 case S_TRISTATE: 487 case S_TRISTATE:
623 switch (val) { 488 switch (val) {
@@ -625,84 +490,87 @@ static void build_conf(struct menu *menu)
625 case mod: ch = 'M'; break; 490 case mod: ch = 'M'; break;
626 default: ch = ' '; break; 491 default: ch = ' '; break;
627 } 492 }
628 cprint1("<%c>", ch); 493 item_make("<%c>", ch);
629 break; 494 break;
630 } 495 }
496 item_set_tag('t');
497 item_set_data(menu);
631 } else { 498 } else {
632 cprint("%c%p", def_menu ? 't' : ':', menu); 499 item_make(" ");
633 cprint1(" "); 500 item_set_tag(def_menu ? 't' : ':');
501 item_set_data(menu);
634 } 502 }
635 503
636 cprint1("%*c%s", indent + 1, ' ', menu_get_prompt(menu)); 504 item_add_str("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
637 if (val == yes) { 505 if (val == yes) {
638 if (def_menu) { 506 if (def_menu) {
639 cprint1(" (%s)", menu_get_prompt(def_menu)); 507 item_add_str(" (%s)", menu_get_prompt(def_menu));
640 cprint1(" --->"); 508 item_add_str(" --->");
641 cprint_done();
642 if (def_menu->list) { 509 if (def_menu->list) {
643 indent += 2; 510 indent += 2;
644 build_conf(def_menu); 511 build_conf(def_menu);
645 indent -= 2; 512 indent -= 2;
646 } 513 }
647 } else 514 }
648 cprint_done();
649 return; 515 return;
650 } 516 }
651 cprint_done();
652 } else { 517 } else {
653 if (menu == current_menu) { 518 if (menu == current_menu) {
654 cprint(":%p", menu); 519 item_make("---%*c%s", indent + 1, ' ', menu_get_prompt(menu));
655 cprint("---%*c%s", indent + 1, ' ', menu_get_prompt(menu)); 520 item_set_tag(':');
521 item_set_data(menu);
656 goto conf_childs; 522 goto conf_childs;
657 } 523 }
658 child_count++; 524 child_count++;
659 val = sym_get_tristate_value(sym); 525 val = sym_get_tristate_value(sym);
660 if (sym_is_choice_value(sym) && val == yes) { 526 if (sym_is_choice_value(sym) && val == yes) {
661 cprint(":%p", menu); 527 item_make(" ");
662 cprint1(" "); 528 item_set_tag(':');
529 item_set_data(menu);
663 } else { 530 } else {
664 switch (type) { 531 switch (type) {
665 case S_BOOLEAN: 532 case S_BOOLEAN:
666 cprint("t%p", menu);
667 if (sym_is_changable(sym)) 533 if (sym_is_changable(sym))
668 cprint1("[%c]", val == no ? ' ' : '*'); 534 item_make("[%c]", val == no ? ' ' : '*');
669 else 535 else
670 cprint1("---"); 536 item_make("---");
537 item_set_tag('t');
538 item_set_data(menu);
671 break; 539 break;
672 case S_TRISTATE: 540 case S_TRISTATE:
673 cprint("t%p", menu);
674 switch (val) { 541 switch (val) {
675 case yes: ch = '*'; break; 542 case yes: ch = '*'; break;
676 case mod: ch = 'M'; break; 543 case mod: ch = 'M'; break;
677 default: ch = ' '; break; 544 default: ch = ' '; break;
678 } 545 }
679 if (sym_is_changable(sym)) 546 if (sym_is_changable(sym))
680 cprint1("<%c>", ch); 547 item_make("<%c>", ch);
681 else 548 else
682 cprint1("---"); 549 item_make("---");
550 item_set_tag('t');
551 item_set_data(menu);
683 break; 552 break;
684 default: 553 default:
685 cprint("s%p", menu); 554 tmp = 2 + strlen(sym_get_string_value(sym)); /* () = 2 */
686 tmp = cprint1("(%s)", sym_get_string_value(sym)); 555 item_make("(%s)", sym_get_string_value(sym));
687 tmp = indent - tmp + 4; 556 tmp = indent - tmp + 4;
688 if (tmp < 0) 557 if (tmp < 0)
689 tmp = 0; 558 tmp = 0;
690 cprint1("%*c%s%s", tmp, ' ', menu_get_prompt(menu), 559 item_add_str("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
691 (sym_has_value(sym) || !sym_is_changable(sym)) ? 560 (sym_has_value(sym) || !sym_is_changable(sym)) ?
692 "" : " (NEW)"); 561 "" : " (NEW)");
693 cprint_done(); 562 item_set_tag('s');
563 item_set_data(menu);
694 goto conf_childs; 564 goto conf_childs;
695 } 565 }
696 } 566 }
697 cprint1("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu), 567 item_add_str("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
698 (sym_has_value(sym) || !sym_is_changable(sym)) ? 568 (sym_has_value(sym) || !sym_is_changable(sym)) ?
699 "" : " (NEW)"); 569 "" : " (NEW)");
700 if (menu->prompt->type == P_MENU) { 570 if (menu->prompt->type == P_MENU) {
701 cprint1(" --->"); 571 item_add_str(" --->");
702 cprint_done();
703 return; 572 return;
704 } 573 }
705 cprint_done();
706 } 574 }
707 575
708conf_childs: 576conf_childs:
@@ -717,59 +585,45 @@ static void conf(struct menu *menu)
717 struct menu *submenu; 585 struct menu *submenu;
718 const char *prompt = menu_get_prompt(menu); 586 const char *prompt = menu_get_prompt(menu);
719 struct symbol *sym; 587 struct symbol *sym;
720 char active_entry[40]; 588 struct menu *active_menu = NULL;
721 int stat, type, i; 589 int res;
590 int s_scroll = 0;
722 591
723 unlink("lxdialog.scrltmp");
724 active_entry[0] = 0;
725 while (1) { 592 while (1) {
726 cprint_init(); 593 item_reset();
727 cprint("--title");
728 cprint("%s", prompt ? prompt : _("Main Menu"));
729 cprint("--menu");
730 cprint(_(menu_instructions));
731 cprint("%d", rows);
732 cprint("%d", cols);
733 cprint("%d", rows - 10);
734 cprint("%s", active_entry);
735 current_menu = menu; 594 current_menu = menu;
736 build_conf(menu); 595 build_conf(menu);
737 if (!child_count) 596 if (!child_count)
738 break; 597 break;
739 if (menu == &rootmenu) { 598 if (menu == &rootmenu) {
740 cprint(":"); 599 item_make("--- ");
741 cprint("--- "); 600 item_set_tag(':');
742 cprint("L"); 601 item_make(_(" Load an Alternate Configuration File"));
743 cprint(_(" Load an Alternate Configuration File")); 602 item_set_tag('L');
744 cprint("S"); 603 item_make(_(" Save an Alternate Configuration File"));
745 cprint(_(" Save Configuration to an Alternate File")); 604 item_set_tag('S');
746 } 605 }
747 stat = exec_conf(); 606 dialog_clear();
748 if (stat < 0) 607 res = dialog_menu(prompt ? prompt : _("Main Menu"),
749 continue; 608 _(menu_instructions),
750 609 active_menu, &s_scroll);
751 if (stat == 1 || stat == 255) 610 if (res == 1 || res == KEY_ESC || res == -ERRDISPLAYTOOSMALL)
752 break; 611 break;
753 612 if (!item_activate_selected())
754 type = input_buf[0]; 613 continue;
755 if (!type) 614 if (!item_tag())
756 continue; 615 continue;
757 616
758 for (i = 0; input_buf[i] && !isspace(input_buf[i]); i++) 617 submenu = item_data();
759 ; 618 active_menu = item_data();
760 if (i >= sizeof(active_entry)) 619 if (submenu)
761 i = sizeof(active_entry) - 1;
762 input_buf[i] = 0;
763 strcpy(active_entry, input_buf);
764
765 sym = NULL;
766 submenu = NULL;
767 if (sscanf(input_buf + 1, "%p", &submenu) == 1)
768 sym = submenu->sym; 620 sym = submenu->sym;
621 else
622 sym = NULL;
769 623
770 switch (stat) { 624 switch (res) {
771 case 0: 625 case 0:
772 switch (type) { 626 switch (item_tag()) {
773 case 'm': 627 case 'm':
774 if (single_menu_mode) 628 if (single_menu_mode)
775 submenu->data = (void *) (long) !submenu->data; 629 submenu->data = (void *) (long) !submenu->data;
@@ -800,7 +654,7 @@ static void conf(struct menu *menu)
800 show_helptext("README", _(mconf_readme)); 654 show_helptext("README", _(mconf_readme));
801 break; 655 break;
802 case 3: 656 case 3:
803 if (type == 't') { 657 if (item_is_tag('t')) {
804 if (sym_set_tristate_value(sym, yes)) 658 if (sym_set_tristate_value(sym, yes))
805 break; 659 break;
806 if (sym_set_tristate_value(sym, mod)) 660 if (sym_set_tristate_value(sym, mod))
@@ -808,17 +662,17 @@ static void conf(struct menu *menu)
808 } 662 }
809 break; 663 break;
810 case 4: 664 case 4:
811 if (type == 't') 665 if (item_is_tag('t'))
812 sym_set_tristate_value(sym, no); 666 sym_set_tristate_value(sym, no);
813 break; 667 break;
814 case 5: 668 case 5:
815 if (type == 't') 669 if (item_is_tag('t'))
816 sym_set_tristate_value(sym, mod); 670 sym_set_tristate_value(sym, mod);
817 break; 671 break;
818 case 6: 672 case 6:
819 if (type == 't') 673 if (item_is_tag('t'))
820 sym_toggle_tristate_value(sym); 674 sym_toggle_tristate_value(sym);
821 else if (type == 'm') 675 else if (item_is_tag('m'))
822 conf(submenu); 676 conf(submenu);
823 break; 677 break;
824 case 7: 678 case 7:
@@ -830,13 +684,8 @@ static void conf(struct menu *menu)
830 684
831static void show_textbox(const char *title, const char *text, int r, int c) 685static void show_textbox(const char *title, const char *text, int r, int c)
832{ 686{
833 int fd; 687 dialog_clear();
834 688 dialog_textbox(title, text, r, c);
835 fd = creat(".help.tmp", 0777);
836 write(fd, text, strlen(text));
837 close(fd);
838 show_file(".help.tmp", title, r, c);
839 unlink(".help.tmp");
840} 689}
841 690
842static void show_helptext(const char *title, const char *text) 691static void show_helptext(const char *title, const char *text)
@@ -864,68 +713,52 @@ static void show_help(struct menu *menu)
864 str_free(&help); 713 str_free(&help);
865} 714}
866 715
867static void show_file(const char *filename, const char *title, int r, int c)
868{
869 do {
870 cprint_init();
871 if (title) {
872 cprint("--title");
873 cprint("%s", title);
874 }
875 cprint("--textbox");
876 cprint("%s", filename);
877 cprint("%d", r ? r : rows);
878 cprint("%d", c ? c : cols);
879 } while (exec_conf() < 0);
880}
881
882static void conf_choice(struct menu *menu) 716static void conf_choice(struct menu *menu)
883{ 717{
884 const char *prompt = menu_get_prompt(menu); 718 const char *prompt = menu_get_prompt(menu);
885 struct menu *child; 719 struct menu *child;
886 struct symbol *active; 720 struct symbol *active;
887 int stat;
888 721
889 active = sym_get_choice_value(menu->sym); 722 active = sym_get_choice_value(menu->sym);
890 while (1) { 723 while (1) {
891 cprint_init(); 724 int res;
892 cprint("--title"); 725 int selected;
893 cprint("%s", prompt ? prompt : _("Main Menu")); 726 item_reset();
894 cprint("--radiolist");
895 cprint(_(radiolist_instructions));
896 cprint("15");
897 cprint("70");
898 cprint("6");
899 727
900 current_menu = menu; 728 current_menu = menu;
901 for (child = menu->list; child; child = child->next) { 729 for (child = menu->list; child; child = child->next) {
902 if (!menu_is_visible(child)) 730 if (!menu_is_visible(child))
903 continue; 731 continue;
904 cprint("%p", child); 732 item_make("%s", menu_get_prompt(child));
905 cprint("%s", menu_get_prompt(child)); 733 item_set_data(child);
734 if (child->sym == active)
735 item_set_selected(1);
906 if (child->sym == sym_get_choice_value(menu->sym)) 736 if (child->sym == sym_get_choice_value(menu->sym))
907 cprint("ON"); 737 item_set_tag('X');
908 else if (child->sym == active)
909 cprint("SELECTED");
910 else
911 cprint("OFF");
912 } 738 }
913 739 dialog_clear();
914 stat = exec_conf(); 740 res = dialog_checklist(prompt ? prompt : _("Main Menu"),
915 switch (stat) { 741 _(radiolist_instructions),
742 15, 70, 6);
743 selected = item_activate_selected();
744 switch (res) {
916 case 0: 745 case 0:
917 if (sscanf(input_buf, "%p", &child) != 1) 746 if (selected) {
918 break; 747 child = item_data();
919 sym_set_tristate_value(child->sym, yes); 748 sym_set_tristate_value(child->sym, yes);
749 }
920 return; 750 return;
921 case 1: 751 case 1:
922 if (sscanf(input_buf, "%p", &child) == 1) { 752 if (selected) {
753 child = item_data();
923 show_help(child); 754 show_help(child);
924 active = child->sym; 755 active = child->sym;
925 } else 756 } else
926 show_help(menu); 757 show_help(menu);
927 break; 758 break;
928 case 255: 759 case KEY_ESC:
760 return;
761 case -ERRDISPLAYTOOSMALL:
929 return; 762 return;
930 } 763 }
931 } 764 }
@@ -934,40 +767,38 @@ static void conf_choice(struct menu *menu)
934static void conf_string(struct menu *menu) 767static void conf_string(struct menu *menu)
935{ 768{
936 const char *prompt = menu_get_prompt(menu); 769 const char *prompt = menu_get_prompt(menu);
937 int stat;
938 770
939 while (1) { 771 while (1) {
940 cprint_init(); 772 int res;
941 cprint("--title"); 773 char *heading;
942 cprint("%s", prompt ? prompt : _("Main Menu")); 774
943 cprint("--inputbox");
944 switch (sym_get_type(menu->sym)) { 775 switch (sym_get_type(menu->sym)) {
945 case S_INT: 776 case S_INT:
946 cprint(_(inputbox_instructions_int)); 777 heading = _(inputbox_instructions_int);
947 break; 778 break;
948 case S_HEX: 779 case S_HEX:
949 cprint(_(inputbox_instructions_hex)); 780 heading = _(inputbox_instructions_hex);
950 break; 781 break;
951 case S_STRING: 782 case S_STRING:
952 cprint(_(inputbox_instructions_string)); 783 heading = _(inputbox_instructions_string);
953 break; 784 break;
954 default: 785 default:
955 /* panic? */; 786 heading = "Internal mconf error!";
956 } 787 }
957 cprint("10"); 788 dialog_clear();
958 cprint("75"); 789 res = dialog_inputbox(prompt ? prompt : _("Main Menu"),
959 cprint("%s", sym_get_string_value(menu->sym)); 790 heading, 10, 75,
960 stat = exec_conf(); 791 sym_get_string_value(menu->sym));
961 switch (stat) { 792 switch (res) {
962 case 0: 793 case 0:
963 if (sym_set_string_value(menu->sym, input_buf)) 794 if (sym_set_string_value(menu->sym, dialog_input_result))
964 return; 795 return;
965 show_textbox(NULL, _("You have made an invalid entry."), 5, 43); 796 show_textbox(NULL, _("You have made an invalid entry."), 5, 43);
966 break; 797 break;
967 case 1: 798 case 1:
968 show_help(menu); 799 show_help(menu);
969 break; 800 break;
970 case 255: 801 case KEY_ESC:
971 return; 802 return;
972 } 803 }
973 } 804 }
@@ -975,28 +806,24 @@ static void conf_string(struct menu *menu)
975 806
976static void conf_load(void) 807static void conf_load(void)
977{ 808{
978 int stat;
979 809
980 while (1) { 810 while (1) {
981 cprint_init(); 811 int res;
982 cprint("--inputbox"); 812 dialog_clear();
983 cprint(load_config_text); 813 res = dialog_inputbox(NULL, load_config_text,
984 cprint("11"); 814 11, 55, filename);
985 cprint("55"); 815 switch(res) {
986 cprint("%s", filename);
987 stat = exec_conf();
988 switch(stat) {
989 case 0: 816 case 0:
990 if (!input_buf[0]) 817 if (!dialog_input_result[0])
991 return; 818 return;
992 if (!conf_read(input_buf)) 819 if (!conf_read(dialog_input_result))
993 return; 820 return;
994 show_textbox(NULL, _("File does not exist!"), 5, 38); 821 show_textbox(NULL, _("File does not exist!"), 5, 38);
995 break; 822 break;
996 case 1: 823 case 1:
997 show_helptext(_("Load Alternate Configuration"), load_config_help); 824 show_helptext(_("Load Alternate Configuration"), load_config_help);
998 break; 825 break;
999 case 255: 826 case KEY_ESC:
1000 return; 827 return;
1001 } 828 }
1002 } 829 }
@@ -1004,28 +831,23 @@ static void conf_load(void)
1004 831
1005static void conf_save(void) 832static void conf_save(void)
1006{ 833{
1007 int stat;
1008
1009 while (1) { 834 while (1) {
1010 cprint_init(); 835 int res;
1011 cprint("--inputbox"); 836 dialog_clear();
1012 cprint(save_config_text); 837 res = dialog_inputbox(NULL, save_config_text,
1013 cprint("11"); 838 11, 55, filename);
1014 cprint("55"); 839 switch(res) {
1015 cprint("%s", filename);
1016 stat = exec_conf();
1017 switch(stat) {
1018 case 0: 840 case 0:
1019 if (!input_buf[0]) 841 if (!dialog_input_result[0])
1020 return; 842 return;
1021 if (!conf_write(input_buf)) 843 if (!conf_write(dialog_input_result))
1022 return; 844 return;
1023 show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60); 845 show_textbox(NULL, _("Can't create file! Probably a nonexistent directory."), 5, 60);
1024 break; 846 break;
1025 case 1: 847 case 1:
1026 show_helptext(_("Save Alternate Configuration"), save_config_help); 848 show_helptext(_("Save Alternate Configuration"), save_config_help);
1027 break; 849 break;
1028 case 255: 850 case KEY_ESC:
1029 return; 851 return;
1030 } 852 }
1031 } 853 }
@@ -1034,15 +856,13 @@ static void conf_save(void)
1034static void conf_cleanup(void) 856static void conf_cleanup(void)
1035{ 857{
1036 tcsetattr(1, TCSAFLUSH, &ios_org); 858 tcsetattr(1, TCSAFLUSH, &ios_org);
1037 unlink(".help.tmp");
1038 unlink("lxdialog.scrltmp");
1039} 859}
1040 860
1041int main(int ac, char **av) 861int main(int ac, char **av)
1042{ 862{
1043 struct symbol *sym; 863 struct symbol *sym;
1044 char *mode; 864 char *mode;
1045 int stat; 865 int res;
1046 866
1047 setlocale(LC_ALL, ""); 867 setlocale(LC_ALL, "");
1048 bindtextdomain(PACKAGE, LOCALEDIR); 868 bindtextdomain(PACKAGE, LOCALEDIR);
@@ -1065,18 +885,19 @@ int main(int ac, char **av)
1065 tcgetattr(1, &ios_org); 885 tcgetattr(1, &ios_org);
1066 atexit(conf_cleanup); 886 atexit(conf_cleanup);
1067 init_wsize(); 887 init_wsize();
1068 conf(&rootmenu); 888 reset_dialog();
1069 889 init_dialog(menu_backtitle);
1070 do { 890 do {
1071 cprint_init(); 891 conf(&rootmenu);
1072 cprint("--yesno"); 892 dialog_clear();
1073 cprint(_("Do you wish to save your new kernel configuration?")); 893 res = dialog_yesno(NULL,
1074 cprint("5"); 894 _("Do you wish to save your "
1075 cprint("60"); 895 "new kernel configuration?\n"
1076 stat = exec_conf(); 896 "<ESC><ESC> to continue."),
1077 } while (stat < 0); 897 6, 60);
1078 898 } while (res == KEY_ESC);
1079 if (stat == 0) { 899 end_dialog();
900 if (res == 0) {
1080 if (conf_write(NULL)) { 901 if (conf_write(NULL)) {
1081 fprintf(stderr, _("\n\n" 902 fprintf(stderr, _("\n\n"
1082 "Error during writing of the kernel configuration.\n" 903 "Error during writing of the kernel configuration.\n"