Skip to contentSkip to conversation

Direct use of lxdialog routines by menuconfig (resent,v2)

PATCH In review Petr Baudis 3 participants 5 messages Nov 23, 2002 – Feb 9, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Direct use of lxdialog routines by menuconfig (resent,v2)

Hello,

this patch (against 2.5.49) cleans up interaction between kconfig's mconf
(menuconfig frontend) and lxdialog. Its commandline interface (called imaginatively lxdialog) no longer exists, instead a huge .o is packed from the lxdialog objects and the relevant functions are called directly from mconf.

In practice, this means that drawing on the screen is done with _MUCH_ less
overhead now (we can still do better, maybe I will make few more patches in future; the difference won't be very big anymore though, I suppose), the screen updates are better optimalized as ncurses aren't reset everytime you display something, that also implies that the ugly screen flickering is done. As a cute side-effect, the dialogs are now rendered on the top of the menu or help panel.

It appears to work fine for me, and the change should cause overall
improvement of the configuration process. Please apply.

 Makefile                     |    7
 scripts/kconfig/Makefile     |    3
 scripts/kconfig/mconf.c      |  376 ++++++++++++++-----------------------------
 scripts/lxdialog/Makefile    |   23 ++
 scripts/lxdialog/checklist.c |   34 +--
 scripts/lxdialog/dialog.h    |   28 ++-
 scripts/lxdialog/lxdialog.c  |  226 -------------------------
 scripts/lxdialog/menubox.c   |   59 ++----
 scripts/lxdialog/textbox.c   |    2
 scripts/lxdialog/util.c      |   18 +-
 10 files changed, 232 insertions(+), 544 deletions(-)

Note that this is a progeny of the previous (already ancient)
kconfig_lxso_mconf.patch - this one actually creates an .o, not a .so, thus it doesn't need any kbuild modifications (altough I'm a little anxious from the hacks I had to do).

Note also that this is the third resubmission of the patch. There are no
changes between 2.5.48 and 2.5.49 in this part of kernel, thus there are no changes in this patch as well.

Kind regards,
Petr Baudis

Makefile +5 -2
@@ -641,8 +641,7 @@
 xconfig: scripts/kconfig/qconf
 	./scripts/kconfig/qconf arch/$(ARCH)/Kconfig
 
-menuconfig: scripts/kconfig/mconf
-	$(Q)$(MAKE) -f scripts/Makefile.build obj=scripts lxdialog
+menuconfig: scripts/lxdialog/built-in.o scripts/kconfig/mconf
 	./scripts/kconfig/mconf arch/$(ARCH)/Kconfig
 
 config: scripts/kconfig/conf
@@ -665,6 +664,10 @@
 
 defconfig: scripts/kconfig/conf
 	./scripts/kconfig/conf -d arch/$(ARCH)/Kconfig
+
+scripts/lxdialog/built-in.o: FORCE
+	$(Q)$(MAKE) -f scripts/Makefile.build obj=scripts lxdialog
+
 
 ###
 # Cleaning is done on three levels.
scripts/kconfig/Makefile +3 -0
diff -ru linux/scripts/kconfig/Makefile linux+pasky/scripts/kconfig/Makefile
@@ -27,6 +27,9 @@
 HOSTCFLAGS_lex.zconf.o	:= -I$(src)
 HOSTCFLAGS_zconf.tab.o	:= -I$(src)
 
+# See scripts/lxdialog/Makefile header for reason of this:
+HOSTLOADLIBES_mconf	= $(obj)/../lxdialog/built-in.o -lncurses
+
 HOSTLOADLIBES_qconf	= -L$(QTDIR)/lib -Wl,-rpath,$(QTDIR)/lib -l$(QTLIB) -ldl
 HOSTCXXFLAGS_qconf.o	= -I$(QTDIR)/include 
 
scripts/kconfig/mconf.c +127 -249

635 lines not on this page · raw message

scripts/lxdialog/Makefile +19 -4
diff -ru linux/scripts/lxdialog/Makefile linux+pasky/scripts/lxdialog/Makefile
@@ -1,3 +1,17 @@
+# A little excursion to the grand scheme of the things:
+#
+# Unlike how it used to be in the past, now we don't use the external lxdialog
+# utility in make menuconfig, but we link the lxdialog suite against mconf
+# directly. This is a little hackish, though - we want to make up a variation
+# to the "static library" theme for lxdialog, and we have to use standart
+# kbuild tools for that; these are tuned for in-kernel use, though, thus we
+# need to do some flags swaps etc. The resulting object, built-in.o, is then
+# linked against mconf.o inside of scripts/kconfig/Makefile. Also, mconf is
+# linked against ncurses _THERE_, regardless to what you see here in
+# HOST_LOADLIBES; here we merely check for ncurses presence.
+#
+# 2002-11-14 Petr Baudis <[email protected]>
+
 HOST_EXTRACFLAGS := -DLOCALE 
 HOST_LOADLIBES   := -lncurses
 
@@ -15,12 +29,13 @@
 endif
 endif
 
-host-progs := lxdialog
 
-lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \
-		 util.o lxdialog.o msgbox.o
+# Replace kernel CFLAGS with host CFLAGS, which is what we want in fact.
+CFLAGS := $(HOSTCFLAGS) $(HOST_EXTRACFLAGS)
+NOSTDINC_FLAGS :=
+
+obj-y := checklist.o menubox.o textbox.o yesno.o inputbox.o util.o msgbox.o
 
-EXTRA_TARGETS := lxdialog
 
 first_rule: ncurses
 
scripts/lxdialog/checklist.c +14 -20
diff -ru linux/scripts/lxdialog/checklist.c linux+pasky/scripts/lxdialog/checklist.c
@@ -118,7 +118,8 @@
  */
 int
 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;
@@ -137,7 +138,7 @@
 
     /* Initializes status */
     for (i = 0; i < item_no; i++) {
-	status[i] = !strcasecmp (items[i * 3 + 2], "on");
+	status[i] = items[i]->selected;
 	if (!choice && status[i])
             choice = i;
     }
@@ -195,7 +196,7 @@
     /* Find length of longest item in order to center checklist */
     check_x = 0;
     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;
     item_x = check_x + 4;
@@ -207,7 +208,7 @@
 
     /* Print the list */
     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);
     }
 
@@ -224,7 +225,7 @@
 	key = wgetch (dialog);
 
     	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;
 
 
@@ -237,14 +238,14 @@
 		    /* Scroll list down */
 		    if (list_height > 1) {
 			/* De-highlight current first item */
-			print_item (list, items[scroll * 3 + 1],
+			print_item (list, items[scroll]->name,
 					status[scroll], 0, FALSE);
 			scrollok (list, TRUE);
 			wscrl (list, -1);
 			scrollok (list, FALSE);
 		    }
 		    scroll--;
-		    print_item (list, items[scroll * 3 + 1],
+		    print_item (list, items[scroll]->name,
 				status[scroll], 0, TRUE);
 		    wnoutrefresh (list);
 
@@ -263,7 +264,7 @@
 		    /* Scroll list up */
 		    if (list_height > 1) {
 			/* 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],
 				    max_choice - 1, FALSE);
 			scrollok (list, TRUE);
@@ -271,7 +272,7 @@
 			scrollok (list, FALSE);
 		    }
 		    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],
 				max_choice - 1, TRUE);
 		    wnoutrefresh (list);
@@ -287,11 +288,11 @@
 	    }
 	    if (i != choice) {
 		/* De-highlight current item */
-		print_item (list, items[(scroll + choice) * 3 + 1],
+		print_item (list, items[scroll + choice]->name,
 			    status[scroll + choice], choice, FALSE);
 		/* Highlight new item */
 		choice = i;
-		print_item (list, items[(scroll + choice) * 3 + 1],
+		print_item (list, items[scroll + choice]->name,
 			    status[scroll + choice], choice, TRUE);
 		wnoutrefresh (list);
 		wrefresh (dialog);
@@ -330,7 +331,7 @@
 			    status[i] = 0;
 			status[scroll + choice] = 1;
 			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);
 		    }
 		}
@@ -338,14 +339,7 @@
 		wrefresh (dialog);
             
 		for (i = 0; i < item_no; i++) {
-		    if (status[i]) {
-			if (flag == FLAG_CHECK) {
-			    fprintf (stderr, "\"%s\" ", items[i * 3]);
-			} else {
-			    fprintf (stderr, "%s", items[i * 3]);
-			}
-
-		    }
+			items[i]->selected = status[i];
 		}
             }
 	    delwin (dialog);
scripts/lxdialog/dialog.h +20 -8
diff -ru linux/scripts/lxdialog/dialog.h linux+pasky/scripts/lxdialog/dialog.h
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef CURSES_LOC
 #include CURSES_LOC
 
 /*
@@ -125,29 +126,35 @@
  * Global variables
  */
 extern bool use_colors;
-extern bool use_shadow;
 
 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
  */
-extern void create_rc (const char *filename);
-extern int parse_rc (void);
-
 
 void init_dialog (void);
 void end_dialog (void);
-void attr_clear (WINDOW * win, int height, int width, chtype attr);
 void dialog_clear (void);
+#ifdef CURSES_LOC
+void attr_clear (WINDOW * win, int height, int width, chtype attr);
 void color_setup (void);
 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 draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
 		chtype border);
 void draw_shadow (WINDOW * win, int y, int x, int height, int width);
+#endif
 
 int first_alpha (const char *string, const char *exempt);
 int dialog_yesno (const char *title, const char *prompt, int height, int width);
@@ -156,14 +163,17 @@
 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 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 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[];
 int dialog_inputbox (const char *title, const char *prompt, int height,
 		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
  * the buttons.
@@ -173,7 +183,9 @@
  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  */
+#ifdef CURSES_LOC
 #define M_EVENT (KEY_MAX+1)
+#endif
 
 
 /*
scripts/lxdialog/menubox.c +26 -33

148 lines not on this page · raw message

scripts/lxdialog/textbox.c +1 -1
diff -ru linux/scripts/lxdialog/textbox.c linux+pasky/scripts/lxdialog/textbox.c
@@ -317,7 +317,7 @@
     delwin (dialog);
     free (buf);
     close (fd);
-    return -1;			/* ESC pressed */
+    return 1;			/* ESC pressed */
 }
 
 /*
scripts/lxdialog/util.c +17 -1
diff -ru linux/scripts/lxdialog/util.c linux+pasky/scripts/lxdialog/util.c
@@ -25,7 +25,7 @@
 /* use colors by default? */
 bool use_colors = 1;
 
-const char *backtitle = NULL;
+char *backtitle = NULL;
 
 const char *dialog_result;
 
@@ -356,4 +356,20 @@
 	}
 
 	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;
 }
scripts/lxdialog/lxdialog.c +0 -226

226 lines not on this page · raw message

#1 lore raw

Hi,

Quoted 4 lines · Petr Baudis

this patch (against 2.5.49) cleans up interaction between kconfig's mconf
(menuconfig frontend) and lxdialog. Its commandline interface (called imaginatively lxdialog) no longer exists, instead a huge .o is packed from the lxdialog objects and the relevant functions are called directly from mconf.

It didn't apply cleanly, I had one reject from menubox.c, which I had to apply manually.
Anyway, some minor comments about the code:

scripts/kconfig/mconf.c line 98

Quoted 3 lines
scripts/kconfig/mconf.c +3 -0
+struct dialog_list_item *items[16384]; /* FIXME: This ought to be dynamic. */
+int item_no;
+

These should be static.

scripts/kconfig/mconf.c line 131

Quoted 2 lines
scripts/kconfig/mconf.c +1 -1
-static void cprint_init(void)
+static void cinit(void)

You can join this with cdone(), they are always called together.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!item_no)
+		cmake();

This could be "if (!items[item_no]) cmake()" to allocate the data as needed. Increment item_no after you done, this avoids also all the "item_no - 1" as index.

Quoted 8 lines
scripts/kconfig/mconf.c +2 -2
-static int cprint(const char *fmt, ...)
+static int cprint_tag(const char *fmt, ...)
 {
 	va_list ap;
 	int res;
 
-	*argptr++ = bufptr;
+	if (!item_no)

scripts/kconfig/mconf.c line 175

Quoted 10 lines
scripts/kconfig/mconf.c +2 -3
+		cmake();
 	va_start(ap, fmt);
-	res = vsprintf(bufptr, fmt, ap);
+	res = vsnprintf(items[item_no - 1]->tag, 32, fmt, ap);
 	va_end(ap);
-	bufptr += res;
-	*bufptr++ = 0;
 
 	return res;
 }

Could you change the tag field of dialog_list_item into a "char type" and a void pointer? I don't really see a reason to convert them from/into strings anymore.

scripts/kconfig/mconf.c line 206

Quoted 4 lines
scripts/kconfig/mconf.c +0 -4
-	sa.sa_handler = winch_handler;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags = SA_RESTART;
-	sigaction(SIGWINCH, &sa, NULL);

Could you please add this one back and just reinitialize curses? (I actually liked the new resize feature. :) )

BTW just add the other patch to this one, it's not that important to keep it separate.

bye, Roman

#2 lore raw

Re: [PATCH] [kconfig] Direct use of lxdialog routines by menuconfig (v3)

Dear diary, on Sun, Nov 24, 2002 at 02:48:23AM CET, I got a letter, where Roman Zippel <[email protected]> told me, that...

Quoted 1 line

Hi,

Hello,

first I apologize for a slight delay.

Quoted 9 lines · Petr Baudis
Quoted 5 lines

this patch (against 2.5.49) cleans up interaction between kconfig's mconf
(menuconfig frontend) and lxdialog. Its commandline interface (called imaginatively lxdialog) no longer exists, instead a huge .o is packed from the lxdialog objects and the relevant functions are called directly from mconf.

It didn't apply cleanly, I had one reject from menubox.c, which I had to apply manually.

Huh.. unreproducible here :-(. It applies cleanly to my clean 2.5.49 tree.

Late note: so does it to 2.5.59.

Quoted 7 lines

Anyway, some minor comments about the code:

Review

Quoted 3 lines
(quoted diff) +3 -0
+struct dialog_list_item *items[16384]; /* FIXME: This ought to be dynamic. */
+int item_no;
+

These should be static.

Oops, fixed.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-static void cprint_init(void)
+static void cinit(void)

You can join this with cdone(), they are always called together.

Hmm.. I thought I could use it separately sometimes, but changed my mind then ;-). Merged (well, rather cinit() annihilated) and renamed to creset().

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (!item_no)
+		cmake();

This could be "if (!items[item_no]) cmake()" to allocate the data as needed. Increment item_no after you done, this avoids also all the "item_no - 1" as index.

We don't clean the items array in cdone^H^H^H^Hreset(). Thus, this won't work after first pass, IMHO. I think this is probably more straightforward anyway. *shrug*

Quoted 16 lines
Quoted 16 lines
(quoted diff) +4 -5
-static int cprint(const char *fmt, ...)
+static int cprint_tag(const char *fmt, ...)
 {
 	va_list ap;
 	int res;
 
-	*argptr++ = bufptr;
+	if (!item_no)
+		cmake();
 	va_start(ap, fmt);
-	res = vsprintf(bufptr, fmt, ap);
+	res = vsnprintf(items[item_no - 1]->tag, 32, fmt, ap);
 	va_end(ap);
-	bufptr += res;
-	*bufptr++ = 0;
Quoted 6 lines
Quoted 2 lines

return res;
}

Could you change the tag field of dialog_list_item into a "char type" and a void pointer? I don't really see a reason to convert them from/into strings anymore.

Bigger diff ;-). Ok, you asked for it. Done.

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +0 -4
-	sa.sa_handler = winch_handler;
-	sigemptyset(&sa.sa_mask);
-	sa.sa_flags = SA_RESTART;
-	sigaction(SIGWINCH, &sa, NULL);

Could you please add this one back and just reinitialize curses? (I actually liked the new resize feature. :) )

Well I tried to do something, but it is relatively complex, since we can't do almost anything useful in the signal handler itself. The problem is that for a reason which I'm unable to hunt down now (after approx. 4 hours of mainly trying to accomplish that) in some percentage of cases when the window is resized, something terribly pollutes the stack and we're screwed. Thus I temporarily disabled the functional part of the winch handler for now, the rest of code is in place and ready to be used by anyone brave enough to s/#if 0/#if 1/ in the winch handler.

Otherwise (with the resizing disabled) it's quite stable about my personal stresstesting through, and the crash always happens inside of ncurses, so I don't really know... thus I believe it's ready for inclusion, we can fix the resizing issue later as it's not anything critical, is it? *hopeful smile*

Quoted 2 lines

BTW just add the other patch to this one, it's not that important to keep it separate.

Well it looks as it's included already...?

 Makefile                     |    7
 scripts/kconfig/Makefile     |    7
 scripts/kconfig/mconf.c      |  428 ++++++++++++++++---------------------------
 scripts/lxdialog/Makefile    |   26 ++
 scripts/lxdialog/checklist.c |   39 +--
 scripts/lxdialog/dialog.h    |   34 ++-
 scripts/lxdialog/inputbox.c  |    5
 scripts/lxdialog/lxdialog.c  |  226 ----------------------
 scripts/lxdialog/menubox.c   |   70 +++----
 scripts/lxdialog/msgbox.c    |    6
 scripts/lxdialog/textbox.c   |    9
 scripts/lxdialog/util.c      |   50 ++++-
 scripts/lxdialog/yesno.c     |    6
 13 files changed, 346 insertions(+), 567 deletions(-)

Note also that this is the fifth resubmission of the patch. The changes are
mostly based on Roman's suggestions and also some mine minor enhancements. Also one bug catched by Erik Andersen is fixed.

Kind regards,
Petr Baudis

Makefile +5 -2
@@ -675,8 +675,7 @@
 xconfig: scripts/kconfig/qconf
 	./scripts/kconfig/qconf arch/$(ARCH)/Kconfig
 
-menuconfig: scripts/kconfig/mconf
-	$(Q)$(MAKE) $(build)=scripts/lxdialog
+menuconfig: scripts/lxdialog/built-in.o scripts/kconfig/mconf
 	./scripts/kconfig/mconf arch/$(ARCH)/Kconfig
 
 config: scripts/kconfig/conf
@@ -699,6 +698,10 @@
 
 defconfig: scripts/kconfig/conf
 	./scripts/kconfig/conf -d arch/$(ARCH)/Kconfig
+
+scripts/lxdialog/built-in.o: FORCE
+	$(Q)$(MAKE) $(build)=scripts/lxdialog
+
 
 ###
 # Cleaning is done on three levels.
scripts/kconfig/Makefile +6 -1
diff -ruN linux/scripts/kconfig/Makefile linux+pasky/scripts/kconfig/Makefile
@@ -2,7 +2,7 @@
 #
 # Shared Makefile for the various lkc executables:
 # conf:	  Used for defconfig, oldconfig and related targets
-# mconf:  Used for the mconfig target.
+# mconf:  Used for the mconfig target
 #         Utilizes the lxdialog package
 # qconf:  Used for the xconfig target
 #         Based on QT which needs to be installed to compile it
@@ -24,6 +24,11 @@
 # generated files seem to need this to find local include files
 HOSTCFLAGS_lex.zconf.o	:= -I$(src)
 HOSTCFLAGS_zconf.tab.o	:= -I$(src)
+
+# See scripts/lxdialog/Makefile header for reason of this:
+$(obj)/mconf.o: $(obj)/../lxdialog/built-in.o
+HOSTLOADLIBES_mconf	= $(obj)/../lxdialog/built-in.o -lncurses
+
 
 HOSTLOADLIBES_qconf	= -L$(QTDIR)/lib -Wl,-rpath,$(QTDIR)/lib -l$(QTLIB) -ldl
 HOSTCXXFLAGS_qconf.o	= -I$(QTDIR)/include 
scripts/kconfig/mconf.c +164 -264

711 lines not on this page · raw message

scripts/lxdialog/Makefile +21 -5
diff -ruN linux/scripts/lxdialog/Makefile linux+pasky/scripts/lxdialog/Makefile
@@ -1,4 +1,18 @@
-HOST_EXTRACFLAGS := -DLOCALE 
+# A little excursion to the grand scheme of things:
+#
+# Unlike how it used to be in the past, now we don't use the external lxdialog
+# utility in make menuconfig, but we link the lxdialog suite directly against
+# mconf. This is a little hackish, though - we want to make up a variation
+# to the "static library" theme for lxdialog, and we have to use standart
+# kbuild tools for that; these are tuned for in-kernel use, though, thus we
+# need to do some flags swaps etc. The resulting object, built-in.o, is then
+# linked against mconf.o inside of scripts/kconfig/Makefile. Also, mconf is
+# linked against ncurses _THERE_, regardless to what you see here in
+# HOST_LOADLIBES; here we merely check for ncurses presence.
+#
+# 2003-02-04 Petr Baudis <[email protected]>
+
+HOST_EXTRACFLAGS := -DLOCALE
 HOST_LOADLIBES   := -lncurses
 
 ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h))
@@ -15,11 +29,13 @@
 endif
 endif
 
-host-progs    := lxdialog
-build-targets := $(host-progs)
 
-lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \
-		 util.o lxdialog.o msgbox.o
+# Replace kernel CFLAGS with host CFLAGS, which is what we want in fact.
+CFLAGS := $(HOSTCFLAGS) $(HOST_EXTRACFLAGS)
+NOSTDINC_FLAGS :=
+
+obj-y := checklist.o menubox.o textbox.o yesno.o inputbox.o util.o msgbox.o
+
 
 first_rule: ncurses
 
scripts/lxdialog/checklist.c +19 -20
diff -ruN linux/scripts/lxdialog/checklist.c linux+pasky/scripts/lxdialog/checklist.c
@@ -118,7 +118,8 @@
  */
 int
 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;
@@ -137,7 +138,7 @@
 
     /* Initializes status */
     for (i = 0; i < item_no; i++) {
-	status[i] = !strcasecmp (items[i * 3 + 2], "on");
+	status[i] = items[i]->selected;
 	if (!choice && status[i])
             choice = i;
     }
@@ -195,7 +196,7 @@
     /* Find length of longest item in order to center checklist */
     check_x = 0;
     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;
     item_x = check_x + 4;
@@ -207,7 +208,7 @@
 
     /* Print the list */
     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);
     }
 
@@ -223,8 +224,11 @@
     while (key != ESC) {
 	key = wgetch (dialog);
 
+	if (should_resize)
+	    do_resize_dialog();
+
     	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;
 
 
@@ -237,14 +241,14 @@
 		    /* Scroll list down */
 		    if (list_height > 1) {
 			/* De-highlight current first item */
-			print_item (list, items[scroll * 3 + 1],
+			print_item (list, items[scroll]->name,
 					status[scroll], 0, FALSE);
 			scrollok (list, TRUE);
 			wscrl (list, -1);
 			scrollok (list, FALSE);
 		    }
 		    scroll--;
-		    print_item (list, items[scroll * 3 + 1],
+		    print_item (list, items[scroll]->name,
 				status[scroll], 0, TRUE);
 		    wnoutrefresh (list);
 
@@ -263,7 +267,7 @@
 		    /* Scroll list up */
 		    if (list_height > 1) {
 			/* 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],
 				    max_choice - 1, FALSE);
 			scrollok (list, TRUE);
@@ -271,7 +275,7 @@
 			scrollok (list, FALSE);
 		    }
 		    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],
 				max_choice - 1, TRUE);
 		    wnoutrefresh (list);
@@ -287,11 +291,11 @@
 	    }
 	    if (i != choice) {
 		/* De-highlight current item */
-		print_item (list, items[(scroll + choice) * 3 + 1],
+		print_item (list, items[scroll + choice]->name,
 			    status[scroll + choice], choice, FALSE);
 		/* Highlight new item */
 		choice = i;
-		print_item (list, items[(scroll + choice) * 3 + 1],
+		print_item (list, items[scroll + choice]->name,
 			    status[scroll + choice], choice, TRUE);
 		wnoutrefresh (list);
 		wrefresh (dialog);
@@ -314,6 +318,8 @@
 	    print_buttons(dialog, height, width, button);
 	    wrefresh (dialog);
 	    break;
+	case KEY_RESIZE:
+	    button = -2;
 	case 'S':
 	case 's':
 	case ' ':
@@ -330,7 +336,7 @@
 			    status[i] = 0;
 			status[scroll + choice] = 1;
 			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);
 		    }
 		}
@@ -338,14 +344,7 @@
 		wrefresh (dialog);
             
 		for (i = 0; i < item_no; i++) {
-		    if (status[i]) {
-			if (flag == FLAG_CHECK) {
-			    fprintf (stderr, "\"%s\" ", items[i * 3]);
-			} else {
-			    fprintf (stderr, "%s", items[i * 3]);
-			}
-
-		    }
+			items[i]->selected = status[i];
 		}
             }
 	    delwin (dialog);
scripts/lxdialog/dialog.h +25 -9
diff -ruN linux/scripts/lxdialog/dialog.h linux+pasky/scripts/lxdialog/dialog.h
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef CURSES_LOC
 #include CURSES_LOC
 
 /*
@@ -125,29 +126,39 @@
  * Global variables
  */
 extern bool use_colors;
-extern bool use_shadow;
+extern bool should_resize;
 
 extern chtype attributes[];
+#endif
+
+extern char *backtitle;
 
-extern const char *backtitle;
+struct dialog_list_item {
+	char *name;
+	int namelen;
+	char type;
+	void *data;
+	int selected; /* Set to 1 by dialog_*() function. */
+};
 
 /*
  * Function prototypes
  */
-extern void create_rc (const char *filename);
-extern int parse_rc (void);
-
 
 void init_dialog (void);
 void end_dialog (void);
-void attr_clear (WINDOW * win, int height, int width, chtype attr);
+void resize_dialog (int rows, int cols);
+void do_resize_dialog (void);
 void dialog_clear (void);
+#ifdef CURSES_LOC
+void attr_clear (WINDOW * win, int height, int width, chtype attr);
 void color_setup (void);
 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 draw_box (WINDOW * win, int y, int x, int height, int width, chtype box,
 		chtype border);
 void draw_shadow (WINDOW * win, int y, int x, int height, int width);
+#endif
 
 int first_alpha (const char *string, const char *exempt);
 int dialog_yesno (const char *title, const char *prompt, int height, int width);
@@ -155,15 +166,18 @@
 		int width, int pause);
 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 menu_height, const char *choice, int item_no, 
-		const char * const * items);
+		int menu_height, const char choice_type, const void *choice_ptr,
+		int item_no, struct dialog_list_item ** items);
 int dialog_checklist (const char *title, const char *prompt, int height,
 		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[];
 int dialog_inputbox (const char *title, const char *prompt, int height,
 		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
  * the buttons.
@@ -173,7 +187,9 @@
  *   -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
  *   -- uppercase chars are used to invoke the button (M_EVENT + 'O')
  */
+#ifdef CURSES_LOC
 #define M_EVENT (KEY_MAX+1)
+#endif
 
 
 /*
scripts/lxdialog/inputbox.c +5 -0
diff -ruN linux/scripts/lxdialog/inputbox.c linux+pasky/scripts/lxdialog/inputbox.c
@@ -123,6 +123,9 @@
     while (key != ESC) {
 	key = wgetch (dialog);
 
+	if (should_resize)
+	    do_resize_dialog();
+
 	if (button == -1) {	/* Input box selected */
 	    switch (key) {
 	    case TAB:
@@ -223,6 +226,8 @@
 		break;
 	    }
 	    break;
+	case KEY_RESIZE:
+	    button = -2;
 	case ' ':
 	case '\n':
 	    delwin (dialog);
scripts/lxdialog/lxdialog.c +0 -226

226 lines not on this page · raw message

scripts/lxdialog/menubox.c +34 -36

180 lines not on this page · raw message

scripts/lxdialog/msgbox.c +5 -1
diff -ruN linux/scripts/lxdialog/msgbox.c linux+pasky/scripts/lxdialog/msgbox.c
@@ -73,8 +73,12 @@
 
 	wrefresh (dialog);
 	while (key != ESC && key != '\n' && key != ' ' &&
-               key != 'O' && key != 'o' && key != 'X' && key != 'x')
+               key != 'O' && key != 'o' && key != 'X' && key != 'x' &&
+	       key != KEY_RESIZE) {
 	    key = wgetch (dialog);
+	    if (should_resize)
+		do_resize_dialog ();
+	}
     } else {
 	key = '\n';
 	wrefresh (dialog);
scripts/lxdialog/textbox.c +7 -2
diff -ruN linux/scripts/lxdialog/textbox.c linux+pasky/scripts/lxdialog/textbox.c
@@ -133,7 +133,12 @@
 
     while ((key != ESC) && (key != '\n')) {
 	key = wgetch (dialog);
+
+	if (should_resize)
+	    do_resize_dialog();
+
 	switch (key) {
+	case KEY_RESIZE:
 	case 'E':		/* Exit */
 	case 'e':
 	case 'X':
@@ -141,7 +146,7 @@
 	    delwin (dialog);
 	    free (buf);
 	    close (fd);
-	    return 0;
+	    return key == KEY_RESIZE ? -2 : 0;
 	case 'g':		/* First page */
 	case KEY_HOME:
 	    if (!begin_reached) {
@@ -317,7 +322,7 @@
     delwin (dialog);
     free (buf);
     close (fd);
-    return -1;			/* ESC pressed */
+    return 1;			/* ESC pressed */
 }
 
 /*
scripts/lxdialog/util.c +49 -1

66 lines not on this page · raw message

scripts/lxdialog/yesno.c +6 -0
diff -ruN linux/scripts/lxdialog/yesno.c linux+pasky/scripts/lxdialog/yesno.c
@@ -85,6 +85,10 @@
 
     while (key != ESC) {
 	key = wgetch (dialog);
+
+	if (should_resize)
+	    do_resize_dialog();
+
 	switch (key) {
 	case 'Y':
 	case 'y':
@@ -104,6 +108,8 @@
 	    print_buttons(dialog, height, width, button);
 	    wrefresh (dialog);
 	    break;
+	case KEY_RESIZE:
+	    button = -2;
 	case ' ':
 	case '\n':
 	    delwin (dialog);
#3 lore raw

Re: [PATCH] [kconfig] Direct use of lxdialog routines by menuconfig (v3)

Hi,

Quoted 6 lines · Petr Baudis
Quoted 2 lines

It didn't apply cleanly, I had one reject from menubox.c, which I had to apply manually.

Huh.. unreproducible here :-(. It applies cleanly to my clean 2.5.49 tree.

Late note: so does it to 2.5.59.

There must be a problem with your kernel tree, I fetched a new 2.5.59 archive and I still get a reject.

Quoted 11 lines
Quoted 2 lines

Could you please add this one back and just reinitialize curses? (I actually liked the new resize feature. :) )

Well I tried to do something, but it is relatively complex, since we can't do almost anything useful in the signal handler itself. The problem is that for a reason which I'm unable to hunt down now (after approx. 4 hours of mainly trying to accomplish that) in some percentage of cases when the window is resized, something terribly pollutes the stack and we're screwed. Thus I temporarily disabled the functional part of the winch handler for now, the rest of code is in place and ready to be used by anyone brave enough to s/#if 0/#if 1/ in the winch handler.

I played a bit with this, try this:

static sigjmp_buf jmp_env;
static int do_jmp, need_resize;

static void winch_handler(int sig)

{       
	if (do_jmp)
		siglongjmp(jmp_env, 1);
	need_resize = 1;
}       

before calling into dialog add this (maybe as macro):

	if (need_resize || sigsetjmp(jmp_env, 1)) {
		init_wsize();
		resizeterm(rows + 4, cols + 5);
		/* rebuild menu */
	}
	do_jmp = 1;

After the call reset do_jmp. It seems to work mostly, but the e.g. menu_instructions are not correctly redrawn, any ideas?

Quoted 4 lines

Otherwise (with the resizing disabled) it's quite stable about my personal stresstesting through, and the crash always happens inside of ncurses, so I don't really know... thus I believe it's ready for inclusion, we can fix the resizing issue later as it's not anything critical, is it? *hopeful smile*

I found some other issues. :)
The Esc key doesn't seem to work correctly, in some dialogs (choice, string) it doesn't work at all, in menu dialogs <Esc><Esc> doesn't work as it did.
After selecting help in choice or string dialog, the help text stays in the background, what I find a bit confusing. Is it possible to save/restore the old background?

Quoted 4 lines
Quoted 2 lines

BTW just add the other patch to this one, it's not that important to keep it separate.

Well it looks as it's included already...?

You can thank Alan. :)

bye, Roman

#4 lore raw
In reply to Petr Baudis
Quoted 9 lines · Petr Baudis
scripts/kconfig/mconf.c +0 -8
 		if (menu == &rootmenu) {
-			cprint(":");
-			cprint("--- ");
-			cprint("L");
-			cprint("Load an Alternate Configuration File");
-			cprint("S");
-			cprint("Save Configuration to an Alternate File");
-		}
-		stat = exec_conf();

scripts/kconfig/mconf.c line 358

Quoted 10 lines
scripts/kconfig/mconf.c +8 -0
+			cmake(); cprint_tag(":"); cprint_name("--- ");
+			cmake(); cprint_tag("L"); cprint_name("Load an Alternate Configuration File");
+			cmake(); cprint_tag("S"); cprint_name("Save Configuration to an Alternate File");
+		}
+		dialog_clear();
+		stat = dialog_menu(prompt ? prompt : "Main Menu",
+				menu_instructions, rows, cols, rows - 10,
+				active_entry, item_no, items);
 		if (stat < 0)
 			continue;

You never return from sub-menus. This last bit should be:

if (stat < 0)
- continue;
+ return;

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--