瀏覽代碼

This is based on a patch posted to lkml by Petr Baudis on 23 Nov, which was
then considerably hacked up by me. This eliminates the separate lxdialog and
instead directly uses the lxdialog internals. This allows 'make menuconfig'
to be much faster.
-Erik

Eric Andersen 22 年之前
父節點
當前提交
64eb982edd

+ 37 - 5
extra/config/Makefile

@@ -20,21 +20,37 @@ TOPDIR=../../
 include $(TOPDIR)Rules.mak
 include $(TOPDIR)Rules.mak
 
 
 
 
-all: conf mconf
+all: ncurses conf mconf
 
 
-NATIVE_CFLAGS=-Wall -g -O0
+#NATIVE_CFLAGS=-Wall -g -O0
+LIBS = -lncurses
+ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h))
+	NATIVE_CFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"
+else
+ifeq (/usr/include/ncurses/curses.h, $(wildcard /usr/include/ncurses/curses.h))
+	NATIVE_CFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"
+else
+ifeq (/usr/include/ncurses.h, $(wildcard /usr/include/ncurses.h))
+	NATIVE_CFLAGS += -DCURSES_LOC="<ncurses.h>"
+else
+	NATIVE_CFLAGS += -DCURSES_LOC="<curses.h>"
+endif
+endif
+endif
 
 
 
 
 CONF_SRC  =conf.c zconf.tab.c
 CONF_SRC  =conf.c zconf.tab.c
 MCONF_SRC =mconf.c zconf.tab.c
 MCONF_SRC =mconf.c zconf.tab.c
+LXDLG_SRC =checklist.c menubox.c textbox.c yesno.c inputbox.c util.c msgbox.c
 CONF_OBJS =$(patsubst %.c,%.o, $(CONF_SRC))
 CONF_OBJS =$(patsubst %.c,%.o, $(CONF_SRC))
 MCONF_OBJS=$(patsubst %.c,%.o, $(MCONF_SRC))
 MCONF_OBJS=$(patsubst %.c,%.o, $(MCONF_SRC))
+LXDLG_OBJS=$(patsubst %.c,%.o, $(LXDLG_SRC))
 
 
 conf: $(CONF_OBJS) 
 conf: $(CONF_OBJS) 
 	$(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) $^ -o $@
 	$(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) $^ -o $@
 
 
-mconf: $(MCONF_OBJS)
+mconf: $(MCONF_OBJS) $(LXDLG_OBJS)
-	$(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) $^ -o $@
+	$(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) $^ -o $@ $(LIBS)
 
 
 lkc_deps:=lkc.h lkc_proto.h lkc_defs.h expr.h zconf.tab.h
 lkc_deps:=lkc.h lkc_proto.h lkc_defs.h expr.h zconf.tab.h
 
 
@@ -77,8 +93,24 @@ zconf.tab.h: zconf.tab.h_shipped
 	cp zconf.tab.h_shipped zconf.tab.h
 	cp zconf.tab.h_shipped zconf.tab.h
 endif
 endif
 
 
+.PHONY: ncurses
+
+ncurses:
+	@echo "main() {}" > lxtemp.c
+	@if $(NATIVE_CC) lxtemp.c $(LIBS) ; then \
+		rm -f lxtemp.c a.out; \
+	else \
+		rm -f lxtemp.c; \
+		echo -e "\007" ;\
+		echo ">> Unable to find the Ncurses libraries." ;\
+		echo ">>" ;\
+		echo ">> You must have Ncurses installed in order" ;\
+		echo ">> to use 'make menuconfig'" ;\
+		echo ;\
+		exit 1 ;\
+	fi
+
 clean:
 clean:
 	rm -f *.o *~ core $(TARGETS) $(MCONF_OBJS) $(CONF_OBJS) \
 	rm -f *.o *~ core $(TARGETS) $(MCONF_OBJS) $(CONF_OBJS) \
 		conf mconf zconf.tab.c zconf.tab.h lex.zconf.c lkc_defs.h
 		conf mconf zconf.tab.c zconf.tab.h lex.zconf.c lkc_defs.h
-	$(MAKE) -C lxdialog clean
 
 

+ 14 - 20
extra/config/lxdialog/checklist.c → extra/config/checklist.c

@@ -118,7 +118,8 @@ print_buttons( WINDOW *dialog, int height, int width, int selected)
  */
  */
 int
 int
 dialog_checklist (const char *title, const char *prompt, int height, int width,
 dialog_checklist (const char *title, const char *prompt, int height, int width,
-	int list_height, int item_no, const char * const * items, int flag)
+	int list_height, int item_no, struct dialog_list_item ** items,
+	int flag)
 	
 	
 {
 {
     int i, x, y, box_x, box_y;
     int i, x, y, box_x, box_y;
@@ -137,7 +138,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 
 
     /* Initializes status */
     /* Initializes status */
     for (i = 0; i < item_no; i++) {
     for (i = 0; i < item_no; i++) {
-	status[i] = !strcasecmp (items[i * 3 + 2], "on");
+	status[i] = items[i]->selected;
 	if (!choice && status[i])
 	if (!choice && status[i])
             choice = i;
             choice = i;
     }
     }
@@ -195,7 +196,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
     /* Find length of longest item in order to center checklist */
     /* Find length of longest item in order to center checklist */
     check_x = 0;
     check_x = 0;
     for (i = 0; i < item_no; i++) 
     for (i = 0; i < item_no; i++) 
-	check_x = MAX (check_x, + strlen (items[i * 3 + 1]) + 4);
+	check_x = MAX (check_x, + strlen (items[i]->name) + 4);
 
 
     check_x = (list_width - check_x) / 2;
     check_x = (list_width - check_x) / 2;
     item_x = check_x + 4;
     item_x = check_x + 4;
@@ -207,7 +208,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 
 
     /* Print the list */
     /* Print the list */
     for (i = 0; i < max_choice; i++) {
     for (i = 0; i < max_choice; i++) {
-	print_item (list, items[(scroll+i) * 3 + 1],
+	print_item (list, items[scroll + i]->name,
 		    status[i+scroll], i, i == choice);
 		    status[i+scroll], i, i == choice);
     }
     }
 
 
@@ -224,7 +225,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 	key = wgetch (dialog);
 	key = wgetch (dialog);
 
 
     	for (i = 0; i < max_choice; i++)
     	for (i = 0; i < max_choice; i++)
-            if (toupper(key) == toupper(items[(scroll+i)*3+1][0]))
+            if (toupper(key) == toupper(items[scroll + i]->name[0]))
                 break;
                 break;
 
 
 
 
@@ -237,14 +238,14 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 		    /* Scroll list down */
 		    /* Scroll list down */
 		    if (list_height > 1) {
 		    if (list_height > 1) {
 			/* De-highlight current first item */
 			/* De-highlight current first item */
-			print_item (list, items[scroll * 3 + 1],
+			print_item (list, items[scroll]->name,
 					status[scroll], 0, FALSE);
 					status[scroll], 0, FALSE);
 			scrollok (list, TRUE);
 			scrollok (list, TRUE);
 			wscrl (list, -1);
 			wscrl (list, -1);
 			scrollok (list, FALSE);
 			scrollok (list, FALSE);
 		    }
 		    }
 		    scroll--;
 		    scroll--;
-		    print_item (list, items[scroll * 3 + 1],
+		    print_item (list, items[scroll]->name,
 				status[scroll], 0, TRUE);
 				status[scroll], 0, TRUE);
 		    wnoutrefresh (list);
 		    wnoutrefresh (list);
 
 
@@ -263,7 +264,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 		    /* Scroll list up */
 		    /* Scroll list up */
 		    if (list_height > 1) {
 		    if (list_height > 1) {
 			/* De-highlight current last item before scrolling up */
 			/* De-highlight current last item before scrolling up */
-			print_item (list, items[(scroll + max_choice - 1) * 3 + 1],
+			print_item (list, items[scroll + max_choice - 1]->name,
 				    status[scroll + max_choice - 1],
 				    status[scroll + max_choice - 1],
 				    max_choice - 1, FALSE);
 				    max_choice - 1, FALSE);
 			scrollok (list, TRUE);
 			scrollok (list, TRUE);
@@ -271,7 +272,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 			scrollok (list, FALSE);
 			scrollok (list, FALSE);
 		    }
 		    }
 		    scroll++;
 		    scroll++;
-		    print_item (list, items[(scroll + max_choice - 1) * 3 + 1],
+		    print_item (list, items[scroll + max_choice - 1]->name,
 				status[scroll + max_choice - 1],
 				status[scroll + max_choice - 1],
 				max_choice - 1, TRUE);
 				max_choice - 1, TRUE);
 		    wnoutrefresh (list);
 		    wnoutrefresh (list);
@@ -287,11 +288,11 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 	    }
 	    }
 	    if (i != choice) {
 	    if (i != choice) {
 		/* De-highlight current item */
 		/* De-highlight current item */
-		print_item (list, items[(scroll + choice) * 3 + 1],
+		print_item (list, items[scroll + choice]->name,
 			    status[scroll + choice], choice, FALSE);
 			    status[scroll + choice], choice, FALSE);
 		/* Highlight new item */
 		/* Highlight new item */
 		choice = i;
 		choice = i;
-		print_item (list, items[(scroll + choice) * 3 + 1],
+		print_item (list, items[scroll + choice]->name,
 			    status[scroll + choice], choice, TRUE);
 			    status[scroll + choice], choice, TRUE);
 		wnoutrefresh (list);
 		wnoutrefresh (list);
 		wrefresh (dialog);
 		wrefresh (dialog);
@@ -330,7 +331,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 			    status[i] = 0;
 			    status[i] = 0;
 			status[scroll + choice] = 1;
 			status[scroll + choice] = 1;
 			for (i = 0; i < max_choice; i++)
 			for (i = 0; i < max_choice; i++)
-			    print_item (list, items[(scroll + i) * 3 + 1],
+			    print_item (list, items[scroll + i]->name,
 					status[scroll + i], i, i == choice);
 					status[scroll + i], i, i == choice);
 		    }
 		    }
 		}
 		}
@@ -338,14 +339,7 @@ dialog_checklist (const char *title, const char *prompt, int height, int width,
 		wrefresh (dialog);
 		wrefresh (dialog);
             
             
 		for (i = 0; i < item_no; i++) {
 		for (i = 0; i < item_no; i++) {
-		    if (status[i]) {
+			items[i]->selected = status[i];
-			if (flag == FLAG_CHECK) {
-			    fprintf (stderr, "\"%s\" ", items[i * 3]);
-			} else {
-			    fprintf (stderr, "%s", items[i * 3]);
-			}
-
-		    }
 		}
 		}
             }
             }
 	    delwin (dialog);
 	    delwin (dialog);

+ 0 - 0
extra/config/lxdialog/colors.h → extra/config/colors.h


+ 20 - 8
extra/config/lxdialog/dialog.h → extra/config/dialog.h

@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 
 
+#ifdef CURSES_LOC
 #include CURSES_LOC
 #include CURSES_LOC
 
 
 /*
 /*
@@ -125,29 +126,35 @@
  * Global variables
  * Global variables
  */
  */
 extern bool use_colors;
 extern bool use_colors;
-extern bool use_shadow;
 
 
 extern chtype attributes[];
 extern chtype attributes[];
+#endif
+
+extern char *backtitle;
 
 
-extern const char *backtitle;
+struct dialog_list_item {
+	char *name;
+	int namelen;
+	char *tag;
+	int selected; /* Set to 1 by dialog_*() function. */
+};
 
 
 /*
 /*
  * Function prototypes
  * Function prototypes
  */
  */
-extern void create_rc (const char *filename);
-extern int parse_rc (void);
-
 
 
 void init_dialog (void);
 void init_dialog (void);
 void end_dialog (void);
 void end_dialog (void);
-void attr_clear (WINDOW * win, int height, int width, chtype attr);
 void dialog_clear (void);
 void dialog_clear (void);
+#ifdef CURSES_LOC
+void attr_clear (WINDOW * win, int height, int width, chtype attr);
 void color_setup (void);
 void color_setup (void);
 void print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x);
 void print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x);
 void print_button (WINDOW * win, const char *label, int y, int x, int selected);
 void print_button (WINDOW * win, const char *label, int y, int x, int selected);
 void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
 void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
 		chtype border);
 		chtype border);
 void draw_shadow (WINDOW * win, int y, int x, int height, int width);
 void draw_shadow (WINDOW * win, int y, int x, int height, int width);
+#endif
 
 
 int first_alpha (const char *string, const char *exempt);
 int first_alpha (const char *string, const char *exempt);
 int dialog_yesno (const char *title, const char *prompt, int height, int width);
 int dialog_yesno (const char *title, const char *prompt, int height, int width);
@@ -156,14 +163,17 @@ int dialog_msgbox (const char *title, const char *prompt, int height,
 int dialog_textbox (const char *title, const char *file, int height, int width);
 int dialog_textbox (const char *title, const char *file, int height, int width);
 int dialog_menu (const char *title, const char *prompt, int height, int width,
 int dialog_menu (const char *title, const char *prompt, int height, int width,
 		int menu_height, const char *choice, int item_no, 
 		int menu_height, const char *choice, int item_no, 
-		const char * const * items);
+		struct dialog_list_item ** items);
 int dialog_checklist (const char *title, const char *prompt, int height,
 int dialog_checklist (const char *title, const char *prompt, int height,
 		int width, int list_height, int item_no,
 		int width, int list_height, int item_no,
-		const char * const * items, int flag);
+		struct dialog_list_item ** items, int flag);
 extern unsigned char dialog_input_result[];
 extern unsigned char dialog_input_result[];
 int dialog_inputbox (const char *title, const char *prompt, int height,
 int dialog_inputbox (const char *title, const char *prompt, int height,
 		int width, const char *init);
 		int width, const char *init);
 
 
+struct dialog_list_item *first_sel_item(int item_no,
+		struct dialog_list_item ** items);
+
 /*
 /*
  * This is the base for fictitious keys, which activate
  * This is the base for fictitious keys, which activate
  * the buttons.
  * the buttons.
@@ -173,7 +183,9 @@ int dialog_inputbox (const char *title, const char *prompt, int height,
  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  */
  */
+#ifdef CURSES_LOC
 #define M_EVENT (KEY_MAX+1)
 #define M_EVENT (KEY_MAX+1)
+#endif
 
 
 
 
 /*
 /*

+ 0 - 0
extra/config/lxdialog/inputbox.c → extra/config/inputbox.c


+ 0 - 4
extra/config/lxdialog/BIG.FAT.WARNING

@@ -1,4 +0,0 @@
-This is NOT the official version of dialog.  This version has been
-significantly modified from the original.  It is for use by the Linux
-kernel configuration script.  Please do not bother Savio Lam with 
-questions about this program.

+ 0 - 51
extra/config/lxdialog/Makefile

@@ -1,51 +0,0 @@
-TOPDIR=../../../
-include $(TOPDIR)Rules.mak
-
-HOSTCFLAGS += -DLOCALE 
-LIBS = -lncurses
-
-ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h))
-	NATIVE_CFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"
-else
-ifeq (/usr/include/ncurses/curses.h, $(wildcard /usr/include/ncurses/curses.h))
-	NATIVE_CFLAGS += -I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"
-else
-ifeq (/usr/include/ncurses.h, $(wildcard /usr/include/ncurses.h))
-	NATIVE_CFLAGS += -DCURSES_LOC="<ncurses.h>"
-else
-	NATIVE_CFLAGS += -DCURSES_LOC="<curses.h>"
-endif
-endif
-endif
-
-
-OBJS = checklist.o menubox.o textbox.o yesno.o inputbox.o \
-       util.o lxdialog.o msgbox.o
-
-%.o: %.c
-	$(NATIVE_CC) $(NATIVE_CFLAGS) -c -o $@ $<
-
-all: ncurses lxdialog
-
-lxdialog: $(OBJS)
-	$(NATIVE_CC) -o lxdialog $(OBJS) $(LIBS)
-
-.PHONY: ncurses
-
-ncurses:
-	@echo "main() {}" > lxtemp.c
-	@if $(NATIVE_CC) lxtemp.c $(LIBS) ; then \
-		rm -f lxtemp.c a.out; \
-	else \
-		rm -f lxtemp.c; \
-		echo -e "\007" ;\
-		echo ">> Unable to find the Ncurses libraries." ;\
-		echo ">>" ;\
-		echo ">> You must have Ncurses installed in order" ;\
-		echo ">> to use 'make menuconfig'" ;\
-		echo ;\
-		exit 1 ;\
-	fi
-
-clean:
-	rm -f core *.o *~ lxdialog

+ 158 - 254
extra/config/mconf.c

@@ -4,6 +4,9 @@
  *
  *
  * Introduced single menu mode (show all sub-menus in one large tree).
  * Introduced single menu mode (show all sub-menus in one large tree).
  * 2002-11-06 Petr Baudis <pasky@ucw.cz>
  * 2002-11-06 Petr Baudis <pasky@ucw.cz>
+ *
+ * Directly use liblxdialog library routines.
+ * 2002-11-14 Petr Baudis <pasky@ucw.cz>
  */
  */
 
 
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
@@ -20,10 +23,11 @@
 #include <termios.h>
 #include <termios.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
+#include "dialog.h"
+
 #define LKC_DIRECT_LINK
 #define LKC_DIRECT_LINK
 #include "lkc.h"
 #include "lkc.h"
 
 
-static char menu_backtitle[128];
 static const char menu_instructions[] =
 static const char menu_instructions[] =
 	"Arrow keys navigate the menu.  "
 	"Arrow keys navigate the menu.  "
 	"<Enter> selects submenus --->.  "
 	"<Enter> selects submenus --->.  "
@@ -82,18 +86,17 @@ save_config_help[] =
 	"leave this blank.\n"
 	"leave this blank.\n"
 ;
 ;
 
 
-static char buf[4096], *bufptr = buf;
-static char input_buf[4096];
 static char filename[PATH_MAX+1] = ".config";
 static char filename[PATH_MAX+1] = ".config";
-static char *args[1024], **argptr = args;
 static int indent = 0;
 static int indent = 0;
 static struct termios ios_org;
 static struct termios ios_org;
 static int rows, cols;
 static int rows, cols;
 static struct menu *current_menu;
 static struct menu *current_menu;
 static int child_count;
 static int child_count;
-static int do_resize;
 static int single_menu_mode;
 static int single_menu_mode;
 
 
+static struct dialog_list_item *items[16384]; /* FIXME: This ought to be dynamic. */
+static int item_no;
+
 static void conf(struct menu *menu);
 static void conf(struct menu *menu);
 static void conf_choice(struct menu *menu);
 static void conf_choice(struct menu *menu);
 static void conf_string(struct menu *menu);
 static void conf_string(struct menu *menu);
@@ -104,11 +107,6 @@ static void show_helptext(const char *title, const char *text);
 static void show_help(struct menu *menu);
 static void show_help(struct menu *menu);
 static void show_readme(void);
 static void show_readme(void);
 
 
-static void cprint_init(void);
-static int cprint1(const char *fmt, ...);
-static void cprint_done(void);
-static int cprint(const char *fmt, ...);
-
 static void init_wsize(void)
 static void init_wsize(void)
 {
 {
 	struct winsize ws;
 	struct winsize ws;
@@ -131,135 +129,63 @@ static void init_wsize(void)
 	cols -= 5;
 	cols -= 5;
 }
 }
 
 
-static void cprint_init(void)
+static void cinit(void)
 {
 {
-	bufptr = buf;
+	item_no = 0;
-	argptr = args;
-	memset(args, 0, sizeof(args));
-	indent = 0;
-	child_count = 0;
-	cprint("./extra/config/lxdialog/lxdialog");
-	cprint("--backtitle");
-	cprint(menu_backtitle);
 }
 }
 
 
-static int cprint1(const char *fmt, ...)
+static void cmake(void)
+{
+	items[item_no] = malloc(sizeof(struct dialog_list_item));
+	memset(items[item_no], 0, sizeof(struct dialog_list_item));
+	items[item_no]->tag = malloc(32); items[item_no]->tag[0] = 0;
+	items[item_no]->name = malloc(512); items[item_no]->name[0] = 0;
+	items[item_no]->namelen = 0;
+	item_no++;
+}
+  
+static int cprint_name(const char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 	int res;
 	int res;
 
 
-	if (!*argptr)
+	if (!item_no)
-		*argptr = bufptr;
+		cmake();
 	va_start(ap, fmt);
 	va_start(ap, fmt);
-	res = vsprintf(bufptr, fmt, ap);
+	res = vsnprintf(items[item_no - 1]->name + items[item_no - 1]->namelen,
+			512 - items[item_no - 1]->namelen, fmt, ap);
+	if (res > 0)
+		items[item_no - 1]->namelen += res;
 	va_end(ap);
 	va_end(ap);
-	bufptr += res;
 
 
 	return res;
 	return res;
 }
 }
-
+  
-static void cprint_done(void)
+static int cprint_tag(const char *fmt, ...)
-{
-	*bufptr++ = 0;
-	argptr++;
-}
-
-static int cprint(const char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;
 	int res;
 	int res;
 
 
-	*argptr++ = bufptr;
+	if (!item_no)
+		cmake();
 	va_start(ap, fmt);
 	va_start(ap, fmt);
-	res = vsprintf(bufptr, fmt, ap);
+	res = vsnprintf(items[item_no - 1]->tag, 32, fmt, ap);
 	va_end(ap);
 	va_end(ap);
-	bufptr += res;
-	*bufptr++ = 0;
 
 
 	return res;
 	return res;
 }
 }
-
+  
-pid_t pid;
+static void cdone(void)
-
-static void winch_handler(int sig)
 {
 {
-	if (!do_resize) {
+	int i;
-		kill(pid, SIGINT);
-		do_resize = 1;
-	}
-}
 
 
-static int exec_conf(void)
+	for (i = 0; i < item_no; i++) {
-{
+		free(items[i]->tag);
-	int pipefd[2], stat, size;
+		free(items[i]->name);
-	struct sigaction sa;
+		free(items[i]);
-	sigset_t sset, osset;
-
-	sigemptyset(&sset);
-	sigaddset(&sset, SIGINT);
-	sigprocmask(SIG_BLOCK, &sset, &osset);
-
-	signal(SIGINT, SIG_DFL);
-
-	sa.sa_handler = winch_handler;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags = SA_RESTART;
-	sigaction(SIGWINCH, &sa, NULL);
-
-	*argptr++ = NULL;
-
-	pipe(pipefd);
-	pid = fork();
-	if (pid == 0) {
-		sigprocmask(SIG_SETMASK, &osset, NULL);
-		dup2(pipefd[1], 2);
-		close(pipefd[0]);
-		close(pipefd[1]);
-		execv(args[0], args);
-		_exit(EXIT_FAILURE);
 	}
 	}
 
 
-	close(pipefd[1]);
+	item_no = 0;
-	bufptr = input_buf;
-	while (1) {
-		size = input_buf + sizeof(input_buf) - bufptr;
-		size = read(pipefd[0], bufptr, size);
-		if (size <= 0) {
-			if (size < 0) {
-				if (errno == EINTR || errno == EAGAIN)
-					continue;
-				perror("read");
-			}
-			break;
-		}
-		bufptr += size;
-	}
-	*bufptr++ = 0;
-	close(pipefd[0]);
-	waitpid(pid, &stat, 0);
-
-	if (do_resize) {
-		init_wsize();
-		do_resize = 0;
-		sigprocmask(SIG_SETMASK, &osset, NULL);
-		return -1;
-	}
-	if (WIFSIGNALED(stat)) {
-		printf("\finterrupted(%d)\n", WTERMSIG(stat));
-		exit(1);
-	}
-#if 0
-	printf("\fexit state: %d\nexit data: '%s'\n", WEXITSTATUS(stat), input_buf);
-	sleep(1);
-#endif
-	sigpending(&sset);
-	if (sigismember(&sset, SIGINT)) {
-		printf("\finterrupted\n");
-		exit(1);
-	}
-	sigprocmask(SIG_SETMASK, &osset, NULL);
-
-	return WEXITSTATUS(stat);
 }
 }
 
 
 static void build_conf(struct menu *menu)
 static void build_conf(struct menu *menu)
@@ -282,27 +208,28 @@ static void build_conf(struct menu *menu)
 			switch (prop->type) {
 			switch (prop->type) {
 			case P_MENU:
 			case P_MENU:
 				child_count++;
 				child_count++;
-				cprint("m%p", menu);
+				cmake();
+				cprint_tag("m%p", menu);
 
 
 				if (single_menu_mode) {
 				if (single_menu_mode) {
-					cprint1("%s%*c%s",
+					cprint_name("%s%*c%s",
 						menu->data ? "-->" : "++>",
 						menu->data ? "-->" : "++>",
 						indent + 1, ' ', prompt);
 						indent + 1, ' ', prompt);
 				} else {
 				} else {
 					if (menu->parent != &rootmenu)
 					if (menu->parent != &rootmenu)
-						cprint1("   %*c", indent + 1, ' ');
+						cprint_name("   %*c", indent + 1, ' ');
-					cprint1("%s  --->", prompt);
+					cprint_name("%s  --->", prompt);
 				}
 				}
 
 
-				cprint_done();
 				if (single_menu_mode && menu->data)
 				if (single_menu_mode && menu->data)
 					goto conf_childs;
 					goto conf_childs;
 				return;
 				return;
 			default:
 			default:
 				if (prompt) {
 				if (prompt) {
 					child_count++;
 					child_count++;
-					cprint(":%p", menu);
+					cmake();
-					cprint("---%*c%s", indent + 1, ' ', prompt);
+					cprint_tag(":%p", menu);
+					cprint_name("---%*c%s", indent + 1, ' ', prompt);
 				}
 				}
 			}
 			}
 		} else
 		} else
@@ -310,6 +237,7 @@ static void build_conf(struct menu *menu)
 		goto conf_childs;
 		goto conf_childs;
 	}
 	}
 
 
+	cmake();
 	type = sym_get_type(sym);
 	type = sym_get_type(sym);
 	if (sym_is_choice(sym)) {
 	if (sym_is_choice(sym)) {
 		struct symbol *def_sym = sym_get_choice_value(sym);
 		struct symbol *def_sym = sym_get_choice_value(sym);
@@ -323,10 +251,10 @@ static void build_conf(struct menu *menu)
 
 
 		val = sym_get_tristate_value(sym);
 		val = sym_get_tristate_value(sym);
 		if (sym_is_changable(sym)) {
 		if (sym_is_changable(sym)) {
-			cprint("t%p", menu);
+			cprint_tag("t%p", menu);
 			switch (type) {
 			switch (type) {
 			case S_BOOLEAN:
 			case S_BOOLEAN:
-				cprint1("[%c]", val == no ? ' ' : '*');
+				cprint_name("[%c]", val == no ? ' ' : '*');
 				break;
 				break;
 			case S_TRISTATE:
 			case S_TRISTATE:
 				switch (val) {
 				switch (val) {
@@ -334,66 +262,61 @@ static void build_conf(struct menu *menu)
 				case mod: ch = 'M'; break;
 				case mod: ch = 'M'; break;
 				default:  ch = ' '; break;
 				default:  ch = ' '; break;
 				}
 				}
-				cprint1("<%c>", ch);
+				cprint_name("<%c>", ch);
 				break;
 				break;
 			}
 			}
 		} else {
 		} else {
-			cprint("%c%p", def_menu ? 't' : ':', menu);
+			cprint_tag("%c%p", def_menu ? 't' : ':', menu);
-			cprint1("   ");
+			cprint_name("   ");
 		}
 		}
 
 
-		cprint1("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
+		cprint_name("%*c%s", indent + 1, ' ', menu_get_prompt(menu));
 		if (val == yes) {
 		if (val == yes) {
 			if (def_menu) {
 			if (def_menu) {
-				cprint1(" (%s)", menu_get_prompt(def_menu));
+				cprint_name(" (%s)", menu_get_prompt(def_menu));
-				cprint1("  --->");
+				cprint_name("  --->");
-				cprint_done();
 				if (def_menu->list) {
 				if (def_menu->list) {
 					indent += 2;
 					indent += 2;
 					build_conf(def_menu);
 					build_conf(def_menu);
 					indent -= 2;
 					indent -= 2;
 				}
 				}
-			} else
+			}
-				cprint_done();
 			return;
 			return;
 		}
 		}
-		cprint_done();
 	} else {
 	} else {
 		child_count++;
 		child_count++;
 		val = sym_get_tristate_value(sym);
 		val = sym_get_tristate_value(sym);
 		if (sym_is_choice_value(sym) && val == yes) {
 		if (sym_is_choice_value(sym) && val == yes) {
-			cprint(":%p", menu);
+			cprint_tag(":%p", menu);
-			cprint1("   ");
+			cprint_name("   ");
 		} else {
 		} else {
 			switch (type) {
 			switch (type) {
 			case S_BOOLEAN:
 			case S_BOOLEAN:
-				cprint("t%p", menu);
+				cprint_tag("t%p", menu);
-				cprint1("[%c]", val == no ? ' ' : '*');
+				cprint_name("[%c]", val == no ? ' ' : '*');
 				break;
 				break;
 			case S_TRISTATE:
 			case S_TRISTATE:
-				cprint("t%p", menu);
+				cprint_tag("t%p", menu);
 				switch (val) {
 				switch (val) {
 				case yes: ch = '*'; break;
 				case yes: ch = '*'; break;
 				case mod: ch = 'M'; break;
 				case mod: ch = 'M'; break;
 				default:  ch = ' '; break;
 				default:  ch = ' '; break;
 				}
 				}
-				cprint1("<%c>", ch);
+				cprint_name("<%c>", ch);
 				break;
 				break;
 			default:
 			default:
-				cprint("s%p", menu);
+				cprint_tag("s%p", menu);
-				tmp = cprint1("(%s)", sym_get_string_value(sym));
+				tmp = cprint_name("(%s)", sym_get_string_value(sym));
 				tmp = indent - tmp + 4;
 				tmp = indent - tmp + 4;
 				if (tmp < 0)
 				if (tmp < 0)
 					tmp = 0;
 					tmp = 0;
-				cprint1("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
+				cprint_name("%*c%s%s", tmp, ' ', menu_get_prompt(menu),
 					sym_has_value(sym) ? "" : " (NEW)");
 					sym_has_value(sym) ? "" : " (NEW)");
-				cprint_done();
 				goto conf_childs;
 				goto conf_childs;
 			}
 			}
 		}
 		}
-		cprint1("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
+		cprint_name("%*c%s%s", indent + 1, ' ', menu_get_prompt(menu),
 			sym_has_value(sym) ? "" : " (NEW)");
 			sym_has_value(sym) ? "" : " (NEW)");
-		cprint_done();
 	}
 	}
 
 
 conf_childs:
 conf_childs:
@@ -405,57 +328,51 @@ conf_childs:
 
 
 static void conf(struct menu *menu)
 static void conf(struct menu *menu)
 {
 {
+	struct dialog_list_item *active_item = NULL;
 	struct menu *submenu;
 	struct menu *submenu;
 	const char *prompt = menu_get_prompt(menu);
 	const char *prompt = menu_get_prompt(menu);
 	struct symbol *sym;
 	struct symbol *sym;
 	char active_entry[40];
 	char active_entry[40];
-	int stat, type, i;
+	int stat, type;
 
 
 	unlink("lxdialog.scrltmp");
 	unlink("lxdialog.scrltmp");
 	active_entry[0] = 0;
 	active_entry[0] = 0;
 	while (1) {
 	while (1) {
-		cprint_init();
+		indent = 0;
-		cprint("--title");
+		child_count = 0;
-		cprint("%s", prompt ? prompt : "Main Menu");
+  		current_menu = menu;
-		cprint("--menu");
+		cdone(); cinit();
-		cprint(menu_instructions);
-		cprint("%d", rows);
-		cprint("%d", cols);
-		cprint("%d", rows - 10);
-		cprint("%s", active_entry);
-		current_menu = menu;
 		build_conf(menu);
 		build_conf(menu);
 		if (!child_count)
 		if (!child_count)
 			break;
 			break;
 		if (menu == &rootmenu) {
 		if (menu == &rootmenu) {
-			cprint(":");
+			cmake(); cprint_tag(":"); cprint_name("--- ");
-			cprint("--- ");
+			cmake(); cprint_tag("L"); cprint_name("Load an Alternate Configuration File");
-			cprint("L");
+			cmake(); cprint_tag("S"); cprint_name("Save Configuration to an Alternate File");
-			cprint("Load an Alternate Configuration File");
-			cprint("S");
-			cprint("Save Configuration to an Alternate File");
 		}
 		}
-		stat = exec_conf();
+		dialog_clear();
+		stat = dialog_menu(prompt ? prompt : "Main Menu",
+				menu_instructions, rows, cols, rows - 10,
+				active_entry, item_no, items);
 		if (stat < 0)
 		if (stat < 0)
-			continue;
+			return;
 
 
 		if (stat == 1 || stat == 255)
 		if (stat == 1 || stat == 255)
 			break;
 			break;
 
 
-		type = input_buf[0];
+		active_item = first_sel_item(item_no, items);
+		if (!active_item)
+			continue;
+		active_item->selected = 0;
+		strncpy(active_entry, active_item->tag, sizeof(active_entry));
+		active_entry[sizeof(active_entry)-1] = 0;
+		type = active_entry[0];
 		if (!type)
 		if (!type)
 			continue;
 			continue;
 
 
-		for (i = 0; input_buf[i] && !isspace((int)input_buf[i]); i++)
-			;
-		if (i >= sizeof(active_entry))
-			i = sizeof(active_entry) - 1;
-		input_buf[i] = 0;
-		strcpy(active_entry, input_buf);
-
 		sym = NULL;
 		sym = NULL;
 		submenu = NULL;
 		submenu = NULL;
-		if (sscanf(input_buf + 1, "%p", &submenu) == 1)
+		if (sscanf(active_entry + 1, "%p", &submenu) == 1)
 			sym = submenu->sym;
 			sym = submenu->sym;
 
 
 		switch (stat) {
 		switch (stat) {
@@ -521,17 +438,8 @@ static void show_textbox(const char *title, const char *text, int r, int c)
 	fd = creat(".help.tmp", 0777);
 	fd = creat(".help.tmp", 0777);
 	write(fd, text, strlen(text));
 	write(fd, text, strlen(text));
 	close(fd);
 	close(fd);
-	do {
+	while (dialog_textbox(title, ".help.tmp", r, c) < 0)
-		cprint_init();
+		;
-		if (title) {
-			cprint("--title");
-			cprint("%s", title);
-		}
-		cprint("--textbox");
-		cprint(".help.tmp");
-		cprint("%d", r);
-		cprint("%d", c);
-	} while (exec_conf() < 0);
 	unlink(".help.tmp");
 	unlink(".help.tmp");
 }
 }
 
 
@@ -560,13 +468,8 @@ static void show_help(struct menu *menu)
 
 
 static void show_readme(void)
 static void show_readme(void)
 {
 {
-	do {
+	while (dialog_textbox(NULL, "scripts/README.Menuconfig", rows, cols) < 0)
-		cprint_init();
+		;
-		cprint("--textbox");
-		cprint("scripts/README.Menuconfig");
-		cprint("%d", rows);
-		cprint("%d", cols);
-	} while (exec_conf() == -1);
 }
 }
 
 
 static void conf_choice(struct menu *menu)
 static void conf_choice(struct menu *menu)
@@ -574,32 +477,25 @@ static void conf_choice(struct menu *menu)
 	const char *prompt = menu_get_prompt(menu);
 	const char *prompt = menu_get_prompt(menu);
 	struct menu *child;
 	struct menu *child;
 	struct symbol *active;
 	struct symbol *active;
-	int stat;
 
 
 	while (1) {
 	while (1) {
-		cprint_init();
-		cprint("--title");
-		cprint("%s", prompt ? prompt : "Main Menu");
-		cprint("--radiolist");
-		cprint(radiolist_instructions);
-		cprint("15");
-		cprint("70");
-		cprint("6");
-
 		current_menu = menu;
 		current_menu = menu;
 		active = sym_get_choice_value(menu->sym);
 		active = sym_get_choice_value(menu->sym);
+		cdone(); cinit();
 		for (child = menu->list; child; child = child->next) {
 		for (child = menu->list; child; child = child->next) {
 			if (!menu_is_visible(child))
 			if (!menu_is_visible(child))
 				continue;
 				continue;
-			cprint("%p", child);
+			cmake();
-			cprint("%s", menu_get_prompt(child));
+			cprint_tag("%p", child);
-			cprint(child->sym == active ? "ON" : "OFF");
+			cprint_name("%s", menu_get_prompt(child));
+			items[item_no - 1]->selected = (child->sym == active);
 		}
 		}
 
 
-		stat = exec_conf();
+		switch (dialog_checklist(prompt ? prompt : "Main Menu",
-		switch (stat) {
+					radiolist_instructions, 15, 70, 6,
+					item_no, items, FLAG_RADIO)) {
 		case 0:
 		case 0:
-			if (sscanf(input_buf, "%p", &menu) != 1)
+			if (sscanf(first_sel_item(item_no, items)->tag, "%p", &menu) != 1)
 				break;
 				break;
 			sym_set_tristate_value(menu->sym, yes);
 			sym_set_tristate_value(menu->sym, yes);
 			return;
 			return;
@@ -615,33 +511,30 @@ static void conf_choice(struct menu *menu)
 static void conf_string(struct menu *menu)
 static void conf_string(struct menu *menu)
 {
 {
 	const char *prompt = menu_get_prompt(menu);
 	const char *prompt = menu_get_prompt(menu);
-	int stat;
 
 
 	while (1) {
 	while (1) {
-		cprint_init();
+		char *heading;
-		cprint("--title");
+
-		cprint("%s", prompt ? prompt : "Main Menu");
-		cprint("--inputbox");
 		switch (sym_get_type(menu->sym)) {
 		switch (sym_get_type(menu->sym)) {
 		case S_INT:
 		case S_INT:
-			cprint(inputbox_instructions_int);
+			heading = (char *) inputbox_instructions_int;
 			break;
 			break;
 		case S_HEX:
 		case S_HEX:
-			cprint(inputbox_instructions_hex);
+			heading = (char *) inputbox_instructions_hex;
 			break;
 			break;
 		case S_STRING:
 		case S_STRING:
-			cprint(inputbox_instructions_string);
+			heading = (char *) inputbox_instructions_string;
 			break;
 			break;
 		default:
 		default:
+			heading = "Internal mconf error!";
 			/* panic? */;
 			/* panic? */;
 		}
 		}
-		cprint("10");
+
-		cprint("75");
+		switch (dialog_inputbox(prompt ? prompt : "Main Menu",
-		cprint("%s", sym_get_string_value(menu->sym));
+					heading, 10, 75,
-		stat = exec_conf();
+					sym_get_string_value(menu->sym))) {
-		switch (stat) {
 		case 0:
 		case 0:
-			if (sym_set_string_value(menu->sym, input_buf))
+			if (sym_set_string_value(menu->sym, dialog_input_result))
 				return;
 				return;
 			show_textbox(NULL, "You have made an invalid entry.", 5, 43);
 			show_textbox(NULL, "You have made an invalid entry.", 5, 43);
 			break;
 			break;
@@ -656,21 +549,13 @@ static void conf_string(struct menu *menu)
 
 
 static void conf_load(void)
 static void conf_load(void)
 {
 {
-	int stat;
-
 	while (1) {
 	while (1) {
-		cprint_init();
+		switch (dialog_inputbox(NULL, load_config_text, 11, 55,
-		cprint("--inputbox");
+					filename)) {
-		cprint(load_config_text);
-		cprint("11");
-		cprint("55");
-		cprint("%s", filename);
-		stat = exec_conf();
-		switch(stat) {
 		case 0:
 		case 0:
-			if (!input_buf[0])
+			if (!dialog_input_result[0])
 				return;
 				return;
-			if (!conf_read(input_buf))
+			if (!conf_read(dialog_input_result))
 				return;
 				return;
 			show_textbox(NULL, "File does not exist!", 5, 38);
 			show_textbox(NULL, "File does not exist!", 5, 38);
 			break;
 			break;
@@ -685,21 +570,13 @@ static void conf_load(void)
 
 
 static void conf_save(void)
 static void conf_save(void)
 {
 {
-	int stat;
-
 	while (1) {
 	while (1) {
-		cprint_init();
+		switch (dialog_inputbox(NULL, save_config_text, 11, 55,
-		cprint("--inputbox");
+					filename)) {
-		cprint(save_config_text);
-		cprint("11");
-		cprint("55");
-		cprint("%s", filename);
-		stat = exec_conf();
-		switch(stat) {
 		case 0:
 		case 0:
-			if (!input_buf[0])
+			if (!dialog_input_result[0])
 				return;
 				return;
-			if (!conf_write(input_buf))
+			if (!conf_write(dialog_input_result))
 				return;
 				return;
 			show_textbox(NULL, "Can't create file!  Probably a nonexistent directory.", 5, 60);
 			show_textbox(NULL, "Can't create file!  Probably a nonexistent directory.", 5, 60);
 			break;
 			break;
@@ -719,18 +596,43 @@ static void conf_cleanup(void)
 	unlink("lxdialog.scrltmp");
 	unlink("lxdialog.scrltmp");
 }
 }
 
 
+static void winch_handler(int sig)
+{
+	struct winsize ws;
+
+	if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
+		rows = 24;
+		cols = 80;
+	} else {
+		rows = ws.ws_row;
+		cols = ws.ws_col;
+	}
+
+	if (rows < 19 || cols < 80) {
+		end_dialog();
+		fprintf(stderr, "Your display is too small to run Menuconfig!\n");
+		fprintf(stderr, "It must be at least 19 lines by 80 columns.\n");
+		exit(1);
+	}
+
+	rows -= 4;
+	cols -= 5;
+
+}
+
 int main(int ac, char **av)
 int main(int ac, char **av)
 {
 {
-	struct symbol *sym;
-	char *mode;
 	int stat;
 	int stat;
+	char *mode;
+	struct symbol *sym;
 
 
 	conf_parse(av[1]);
 	conf_parse(av[1]);
 	conf_read(NULL);
 	conf_read(NULL);
 
 
+	backtitle = malloc(128);
 	sym = sym_lookup("VERSION", 0);
 	sym = sym_lookup("VERSION", 0);
 	sym_calc_value(sym);
 	sym_calc_value(sym);
-	sprintf(menu_backtitle, "uClibc v%s Configuration",
+	snprintf(backtitle, 128, "uClibc v%s Configuration",
 		sym_get_string_value(sym));
 		sym_get_string_value(sym));
 
 
 	mode = getenv("MENUCONFIG_MODE");
 	mode = getenv("MENUCONFIG_MODE");
@@ -742,16 +644,18 @@ int main(int ac, char **av)
 	tcgetattr(1, &ios_org);
 	tcgetattr(1, &ios_org);
 	atexit(conf_cleanup);
 	atexit(conf_cleanup);
 	init_wsize();
 	init_wsize();
+	init_dialog();
+	signal(SIGWINCH, winch_handler); 
 	conf(&rootmenu);
 	conf(&rootmenu);
+	end_dialog();
 
 
+	/* Restart dialog to act more like when lxdialog was still separate */
+	init_dialog();
 	do {
 	do {
-		cprint_init();
+		stat = dialog_yesno(NULL, 
-		cprint("--yesno");
+				"Do you wish to save your new uClibc configuration?", 5, 60);
-		cprint("Do you wish to save your new uClibc configuration?");
-		cprint("5");
-		cprint("60");
-		stat = exec_conf();
 	} while (stat < 0);
 	} while (stat < 0);
+	end_dialog();
 
 
 	if (stat == 0) {
 	if (stat == 0) {
 		conf_write(NULL);
 		conf_write(NULL);

+ 26 - 33
extra/config/lxdialog/menubox.c → extra/config/menubox.c

@@ -93,7 +93,7 @@ print_item (WINDOW * win, const char *item, int choice, int selected, int hotkey
     }
     }
     if (selected) {
     if (selected) {
 	wmove (win, choice, item_x+1);
 	wmove (win, choice, item_x+1);
-	wrefresh (win);
+	wnoutrefresh (win);
     }
     }
 }
 }
 
 
@@ -165,8 +165,7 @@ print_buttons (WINDOW *win, int height, int width, int selected)
 int
 int
 dialog_menu (const char *title, const char *prompt, int height, int width,
 dialog_menu (const char *title, const char *prompt, int height, int width,
 		int menu_height, const char *current, int item_no,
 		int menu_height, const char *current, int item_no,
-		const char * const * items)
+		struct dialog_list_item ** items)
-
 {
 {
     int i, j, x, y, box_x, box_y;
     int i, j, x, y, box_x, box_y;
     int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice;
     int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice;
@@ -230,8 +229,8 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
      */
      */
     item_x = 0;
     item_x = 0;
     for (i = 0; i < item_no; i++) {
     for (i = 0; i < item_no; i++) {
-	item_x = MAX (item_x, MIN(menu_width, strlen (items[i * 2 + 1]) + 2));
+	item_x = MAX (item_x, MIN(menu_width, strlen (items[i]->name) + 2));
-	if (strcmp(current, items[i*2]) == 0) choice = i;
+	if (strcmp(current, items[i]->tag) == 0) choice = i;
     }
     }
 
 
     item_x = (menu_width - item_x) / 2;
     item_x = (menu_width - item_x) / 2;
@@ -261,8 +260,8 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
 
 
     /* Print the menu */
     /* Print the menu */
     for (i=0; i < max_choice; i++) {
     for (i=0; i < max_choice; i++) {
-	print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice,
+	print_item (menu, items[first_item + i]->name, i, i == choice,
-                    (items[(first_item + i)*2][0] != ':'));
+                    (items[first_item + i]->tag[0] != ':'));
     }
     }
 
 
     wnoutrefresh (menu);
     wnoutrefresh (menu);
@@ -283,14 +282,14 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
 		i = max_choice;
 		i = max_choice;
 	else {
 	else {
         for (i = choice+1; i < max_choice; i++) {
         for (i = choice+1; i < max_choice; i++) {
-		j = first_alpha(items[(scroll+i)*2+1], "YyNnMm");
+		j = first_alpha(items[scroll + i]->name, "YyNnMm>");
-		if (key == tolower(items[(scroll+i)*2+1][j]))
+		if (key == tolower(items[scroll + i]->name[j]))
                 	break;
                 	break;
 	}
 	}
 	if (i == max_choice)
 	if (i == max_choice)
        		for (i = 0; i < max_choice; i++) {
        		for (i = 0; i < max_choice; i++) {
-			j = first_alpha(items[(scroll+i)*2+1], "YyNnMm");
+			j = first_alpha(items[scroll + i]->name, "YyNnMm>");
-			if (key == tolower(items[(scroll+i)*2+1][j]))
+			if (key == tolower(items[scroll + i]->name[j]))
                 		break;
                 		break;
 		}
 		}
 	}
 	}
@@ -300,8 +299,8 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
             key == '-' || key == '+' ||
             key == '-' || key == '+' ||
             key == KEY_PPAGE || key == KEY_NPAGE) {
             key == KEY_PPAGE || key == KEY_NPAGE) {
 
 
-            print_item (menu, items[(scroll+choice)*2+1], choice, FALSE,
+            print_item (menu, items[scroll + choice]->name, choice, FALSE,
-                       (items[(scroll+choice)*2][0] != ':'));
+                       (items[scroll + choice]->tag[0] != ':'));
 
 
 	    if (key == KEY_UP || key == '-') {
 	    if (key == KEY_UP || key == '-') {
                 if (choice < 2 && scroll) {
                 if (choice < 2 && scroll) {
@@ -312,15 +311,15 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
 
 
                     scroll--;
                     scroll--;
 
 
-                    print_item (menu, items[scroll * 2 + 1], 0, FALSE,
+                    print_item (menu, items[scroll * 2]->name, 0, FALSE,
-                               (items[scroll*2][0] != ':'));
+                               (items[scroll * 2]->tag[0] != ':'));
 		} else
 		} else
 		    choice = MAX(choice - 1, 0);
 		    choice = MAX(choice - 1, 0);
 
 
 	    } else if (key == KEY_DOWN || key == '+')  {
 	    } else if (key == KEY_DOWN || key == '+')  {
 
 
-		print_item (menu, items[(scroll+choice)*2+1], choice, FALSE,
+		print_item (menu, items[scroll + choice]->name, choice, FALSE,
-                                (items[(scroll+choice)*2][0] != ':'));
+                                (items[scroll + choice]->tag[0] != ':'));
 
 
                 if ((choice > max_choice-3) &&
                 if ((choice > max_choice-3) &&
                     (scroll + max_choice < item_no)
                     (scroll + max_choice < item_no)
@@ -332,9 +331,9 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
 
 
                     scroll++;
                     scroll++;
 
 
-                    print_item (menu, items[(scroll+max_choice-1)*2+1],
+                    print_item (menu, items[scroll + max_choice - 1]->name,
                                max_choice-1, FALSE,
                                max_choice-1, FALSE,
-                               (items[(scroll+max_choice-1)*2][0] != ':'));
+                               (items[scroll + max_choice - 1]->tag[0] != ':'));
                 } else
                 } else
                     choice = MIN(choice+1, max_choice-1);
                     choice = MIN(choice+1, max_choice-1);
 
 
@@ -344,8 +343,8 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
                     if (scroll > 0) {
                     if (scroll > 0) {
                 	wscrl (menu, -1);
                 	wscrl (menu, -1);
                 	scroll--;
                 	scroll--;
-                	print_item (menu, items[scroll * 2 + 1], 0, FALSE,
+                	print_item (menu, items[scroll * 2]->name, 0, FALSE,
-                	(items[scroll*2][0] != ':'));
+                	(items[scroll * 2]->tag[0] != ':'));
                     } else {
                     } else {
                         if (choice > 0)
                         if (choice > 0)
                             choice--;
                             choice--;
@@ -360,9 +359,9 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
 			scroll(menu);
 			scroll(menu);
 			scrollok (menu, FALSE);
 			scrollok (menu, FALSE);
                 	scroll++;
                 	scroll++;
-                	print_item (menu, items[(scroll+max_choice-1)*2+1],
+                	print_item (menu, items[scroll + max_choice - 1]->name,
 			            max_choice-1, FALSE,
 			            max_choice-1, FALSE,
-			            (items[(scroll+max_choice-1)*2][0] != ':'));
+			            (items[scroll + max_choice - 1]->tag[0] != ':'));
 		    } else {
 		    } else {
 			if (choice+1 < max_choice)
 			if (choice+1 < max_choice)
 			    choice++;
 			    choice++;
@@ -372,8 +371,8 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
             } else
             } else
                 choice = i;
                 choice = i;
 
 
-            print_item (menu, items[(scroll+choice)*2+1], choice, TRUE,
+            print_item (menu, items[scroll + choice]->name, choice, TRUE,
-                       (items[(scroll+choice)*2][0] != ':'));
+                       (items[scroll + choice]->tag[0] != ':'));
 
 
             print_arrows(dialog, item_no, scroll,
             print_arrows(dialog, item_no, scroll,
                          box_y, box_x+item_x+1, menu_height);
                          box_y, box_x+item_x+1, menu_height);
@@ -405,7 +404,7 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
 		fclose(f);
 		fclose(f);
 	    }
 	    }
 	    delwin (dialog);
 	    delwin (dialog);
-            fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);
+            items[scroll + choice]->selected = 1;
             switch (key) {
             switch (key) {
             case 's': return 3;
             case 's': return 3;
             case 'y': return 3;
             case 'y': return 3;
@@ -419,13 +418,7 @@ dialog_menu (const char *title, const char *prompt, int height, int width,
 	    button = 2;
 	    button = 2;
 	case '\n':
 	case '\n':
 	    delwin (dialog);
 	    delwin (dialog);
-	    if (button == 2) 
+	    items[scroll + choice]->selected = 1;
-            	fprintf(stderr, "%s \"%s\"\n", 
-			items[(scroll + choice) * 2],
-			items[(scroll + choice) * 2 + 1] +
-			first_alpha(items[(scroll + choice) * 2 + 1],""));
-	    else
-            	fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);
 
 
 	    remove("lxdialog.scrltmp");
 	    remove("lxdialog.scrltmp");
 	    return button;
 	    return button;

+ 0 - 0
extra/config/lxdialog/msgbox.c → extra/config/msgbox.c


+ 1 - 1
extra/config/lxdialog/textbox.c → extra/config/textbox.c

@@ -317,7 +317,7 @@ dialog_textbox (const char *title, const char *file, int height, int width)
     delwin (dialog);
     delwin (dialog);
     free (buf);
     free (buf);
     close (fd);
     close (fd);
-    return -1;			/* ESC pressed */
+    return 1;			/* ESC pressed */
 }
 }
 
 
 /*
 /*

+ 17 - 1
extra/config/lxdialog/util.c → extra/config/util.c

@@ -25,7 +25,7 @@
 /* use colors by default? */
 /* use colors by default? */
 bool use_colors = 1;
 bool use_colors = 1;
 
 
-const char *backtitle = NULL;
+char *backtitle = NULL;
 
 
 const char *dialog_result;
 const char *dialog_result;
 
 
@@ -357,3 +357,19 @@ first_alpha(const char *string, const char *exempt)
 
 
 	return 0;
 	return 0;
 }
 }
+
+/*
+ * Get the first selected item in the dialog_list_item list.
+ */
+struct dialog_list_item *
+first_sel_item(int item_no, struct dialog_list_item ** items)
+{
+	int i;
+
+	for (i = 0; i < item_no; i++) {
+		if (items[i]->selected)
+			return items[i];
+	}
+
+	return NULL;
+}

+ 0 - 0
extra/config/lxdialog/yesno.c → extra/config/yesno.c