Skip to contentSkip to conversation

Direct use of lxdialog routines by menuconfig (v2)

PATCH New Petr Baudis 1 participant 1 message Nov 14, 2002

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

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

Hello,

this patch (against 2.5.47) 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 test, comment, 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 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). It is also updated to 2.5.47 and several minor problems were fixed (mainly the prev. patch was missing a part ;-).

Kind regards,
Petr Baudis

Makefile +5 -2
@@ -643,8 +643,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
@@ -667,6 +666,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