public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] kconfig/menuconfig
@ 2005-11-21 22:37 Sam Ravnborg
  2005-11-21 22:38 ` [1/7] kconfig: fixup after Lindent Sam Ravnborg
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:37 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel; +Cc: Sam Ravnborg

Hi Roman & lkml.

I have digged up a serie of patches I had for scripts/lxdialog.
The net result of the patches are much nicer look in a text-only console
(that is with no X running). Also the code becomes in some places
almost readable, using Lindent is just one part of the cure.

Description of the individual patches:

[xxx] Lindent of scripts/lxdialog (patch not posted)
[1/7] fixup after Lindent
[2/7] make lxdialog sparse clean
[3/7] introduce a common helper to simplify printing the title
[4/7] left align the menu lines
[5/7] fix indention on text-only consoles
[6/7] make menubox.c more readable using a single macro
[7/7] truncate long menu lines

All patches are pushed to the kbuild repository at kernel.org:
http://www.kernel.org/pub/scm/linux/kernel/git/sam/kbuild.git

Patched will follow as reply to this mail

This is not strictly kbuild stuff but using this repository the patches will
hit -mm for wider testing.


	Sam

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [1/7] kconfig: fixup after Lindent
  2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
@ 2005-11-21 22:38 ` Sam Ravnborg
  2005-11-21 22:38 ` [2/7] kconfig: lxdialog is now sparse clean Sam Ravnborg
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:38 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel

    kconfig: fixup after Lindent
    
    Readability are more important then the 80 coloumn limit, so fold
    several lines to greatly improve readability.
    Also keep return type on same line as function definition.
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/scripts/lxdialog/checklist.c b/scripts/lxdialog/checklist.c
index 1857c53..ae40a2b 100644
--- a/scripts/lxdialog/checklist.c
+++ b/scripts/lxdialog/checklist.c
@@ -26,12 +26,12 @@
 static int list_width, check_x, item_x, checkflag;
 
 /*
  * Print list item
  */
-static void
-print_item(WINDOW * win, const char *item, int status, int choice, int selected)
+static void print_item(WINDOW * win, const char *item, int status, int choice,
+		       int selected)
 {
 	int i;
 
 	/* Clear 'residue' of last item */
 	wattrset(win, menubox_attr);
@@ -57,12 +57,11 @@ print_item(WINDOW * win, const char *ite
 }
 
 /*
  * Print the scroll indicators.
  */
-static void
-print_arrows(WINDOW * win, int choice, int item_no, int scroll,
+static void print_arrows(WINDOW * win, int choice, int item_no, int scroll,
 	     int y, int x, int height)
 {
 	wmove(win, y, x);
 
 	if (scroll > 0) {
@@ -110,14 +109,13 @@ static void print_buttons(WINDOW * dialo
 
 /*
  * Display a dialog box with a list of options that can be turned on or off
  * The `flag' parameter is used to select between radiolist and checklist.
  */
-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 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 i, x, y, box_x, box_y;
 	int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status;
 	WINDOW *dialog, *list;
 
@@ -181,19 +179,18 @@ dialog_checklist(const char *title, cons
 	list_width = width - 6;
 	box_y = height - list_height - 5;
 	box_x = (width - list_width) / 2 - 1;
 
 	/* create new window for the list */
-	list =
-	    subwin(dialog, list_height, list_width, y + box_y + 1,
-		   x + box_x + 1);
+	list = subwin(dialog, list_height, list_width, y + box_y + 1,
+	              x + box_x + 1);
 
 	keypad(list, TRUE);
 
 	/* draw a box around the list items */
 	draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
-		 menubox_border_attr, menubox_attr);
+	         menubox_border_attr, menubox_attr);
 
 	/* 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);
@@ -236,28 +233,22 @@ dialog_checklist(const char *title, cons
 					if (!scroll)
 						continue;
 					/* Scroll list down */
 					if (list_height > 1) {
 						/* De-highlight current first item */
-						print_item(list,
-							   items[scroll * 3 +
-								 1],
-							   status[scroll], 0,
-							   FALSE);
+						print_item(list, items[scroll * 3 + 1],
+							   status[scroll], 0, FALSE);
 						scrollok(list, TRUE);
 						wscrl(list, -1);
 						scrollok(list, FALSE);
 					}
 					scroll--;
-					print_item(list, items[scroll * 3 + 1],
-						   status[scroll], 0, TRUE);
+					print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE);
 					wnoutrefresh(list);
 
 					print_arrows(dialog, choice, item_no,
-						     scroll, box_y,
-						     box_x + check_x + 5,
-						     list_height);
+						     scroll, box_y, box_x + check_x + 5, list_height);
 
 					wrefresh(dialog);
 
 					continue;	/* wait for another key press */
 				} else
@@ -267,55 +258,39 @@ dialog_checklist(const char *title, cons
 					if (scroll + choice >= item_no - 1)
 						continue;
 					/* 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],
-							   status[scroll +
-								  max_choice -
-								  1],
-							   max_choice - 1,
-							   FALSE);
+						print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
+							   status[scroll + max_choice - 1],
+							   max_choice - 1, FALSE);
 						scrollok(list, TRUE);
 						wscrl(list, 1);
 						scrollok(list, FALSE);
 					}
 					scroll++;
-					print_item(list,
-						   items[(scroll + max_choice -
-							  1) * 3 + 1],
-						   status[scroll + max_choice -
-							  1], max_choice - 1,
-						   TRUE);
+					print_item(list, items[(scroll + max_choice - 1) * 3 + 1],
+						   status[scroll + max_choice - 1], max_choice - 1, TRUE);
 					wnoutrefresh(list);
 
 					print_arrows(dialog, choice, item_no,
-						     scroll, box_y,
-						     box_x + check_x + 5,
-						     list_height);
+						     scroll, box_y, box_x + check_x + 5, list_height);
 
 					wrefresh(dialog);
 
 					continue;	/* wait for another key press */
 				} else
 					i = choice + 1;
 			}
 			if (i != choice) {
 				/* De-highlight current item */
-				print_item(list,
-					   items[(scroll + choice) * 3 + 1],
-					   status[scroll + choice], choice,
-					   FALSE);
+				print_item(list, items[(scroll + choice) * 3 + 1],
+					   status[scroll + choice], choice, FALSE);
 				/* Highlight new item */
 				choice = i;
-				print_item(list,
-					   items[(scroll + choice) * 3 + 1],
-					   status[scroll + choice], choice,
-					   TRUE);
+				print_item(list, items[(scroll + choice) * 3 + 1],
+					   status[scroll + choice], choice, TRUE);
 				wnoutrefresh(list);
 				wrefresh(dialog);
 			}
 			continue;	/* wait for another key press */
 		}
@@ -340,53 +315,39 @@ dialog_checklist(const char *title, cons
 		case 's':
 		case ' ':
 		case '\n':
 			if (!button) {
 				if (flag == FLAG_CHECK) {
-					status[scroll + choice] =
-					    !status[scroll + choice];
+					status[scroll + choice] = !status[scroll + choice];
 					wmove(list, choice, check_x);
 					wattrset(list, check_selected_attr);
-					wprintw(list, "[%c]",
-						status[scroll +
-						       choice] ? 'X' : ' ');
+					wprintw(list, "[%c]", status[scroll + choice] ? 'X' : ' ');
 				} else {
 					if (!status[scroll + choice]) {
 						for (i = 0; i < item_no; i++)
 							status[i] = 0;
 						status[scroll + choice] = 1;
 						for (i = 0; i < max_choice; i++)
-							print_item(list,
-								   items[(scroll
-									  +
-									  i) *
-									 3 + 1],
-								   status[scroll
-									  + i],
-								   i,
-								   i == choice);
+							print_item(list, items[(scroll + i) * 3 + 1],
+								   status[scroll + i], i, i == choice);
 					}
 				}
 				wnoutrefresh(list);
 				wrefresh(dialog);
 
 				for (i = 0; i < item_no; i++) {
 					if (status[i]) {
 						if (flag == FLAG_CHECK) {
-							fprintf(stderr,
-								"\"%s\" ",
-								items[i * 3]);
+							fprintf(stderr, "\"%s\" ", items[i * 3]);
 						} else {
-							fprintf(stderr, "%s",
-								items[i * 3]);
+							fprintf(stderr, "%s", items[i * 3]);
 						}
 
 					}
 				}
 			} else
-				fprintf(stderr, "%s",
-					items[(scroll + choice) * 3]);
+				fprintf(stderr, "%s", items[(scroll + choice) * 3]);
 			delwin(dialog);
 			free(status);
 			return button;
 		case 'X':
 		case 'x':
diff --git a/scripts/lxdialog/dialog.h b/scripts/lxdialog/dialog.h
index c86801f..3cf3d35 100644
--- a/scripts/lxdialog/dialog.h
+++ b/scripts/lxdialog/dialog.h
@@ -1,6 +1,5 @@
-
 /*
  *  dialog.h -- common declarations for all dialog modules
  *
  *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
  *
@@ -85,11 +84,11 @@
 #endif
 #ifndef ACS_DARROW
 #define ACS_DARROW 'v'
 #endif
 
-/* 
+/*
  * Attribute names
  */
 #define screen_attr                   attributes[0]
 #define shadow_attr                   attributes[1]
 #define dialog_attr                   attributes[2]
diff --git a/scripts/lxdialog/inputbox.c b/scripts/lxdialog/inputbox.c
index 9e96915..bc135c7 100644
--- a/scripts/lxdialog/inputbox.c
+++ b/scripts/lxdialog/inputbox.c
@@ -39,13 +39,12 @@ static void print_buttons(WINDOW * dialo
 }
 
 /*
  * Display a dialog box for inputing a string
  */
-int
-dialog_inputbox(const char *title, const char *prompt, int height, int width,
-		const char *init)
+int dialog_inputbox(const char *title, const char *prompt, int height, int width,
+                    const char *init)
 {
 	int i, x, y, box_y, box_x, box_width;
 	int input_x = 0, scroll = 0, key = 0, button = -1;
 	char *instr = dialog_input_result;
 	WINDOW *dialog;
@@ -88,12 +87,11 @@ dialog_inputbox(const char *title, const
 	/* Draw the input field box */
 	box_width = width - 6;
 	getyx(dialog, y, x);
 	box_y = y + 2;
 	box_x = (width - box_width) / 2;
-	draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
-		 border_attr, dialog_attr);
+	draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, border_attr, dialog_attr);
 
 	print_buttons(dialog, height, width, 0);
 
 	/* Set up the initial value */
 	wmove(dialog, box_y, box_x);
@@ -109,12 +107,13 @@ dialog_inputbox(const char *title, const
 	if (input_x >= box_width) {
 		scroll = input_x - box_width + 1;
 		input_x = box_width - 1;
 		for (i = 0; i < box_width - 1; i++)
 			waddch(dialog, instr[scroll + i]);
-	} else
+	} else {
 		waddstr(dialog, instr);
+	}
 
 	wmove(dialog, box_y, box_x + input_x);
 
 	wrefresh(dialog);
 
@@ -134,56 +133,38 @@ dialog_inputbox(const char *title, const
 			case KEY_BACKSPACE:
 			case 127:
 				if (input_x || scroll) {
 					wattrset(dialog, inputbox_attr);
 					if (!input_x) {
-						scroll =
-						    scroll <
-						    box_width - 1 ? 0 : scroll -
-						    (box_width - 1);
+						scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1);
 						wmove(dialog, box_y, box_x);
 						for (i = 0; i < box_width; i++)
 							waddch(dialog,
-							       instr[scroll +
-								     input_x +
-								     i] ?
-							       instr[scroll +
-								     input_x +
-								     i] : ' ');
-						input_x =
-						    strlen(instr) - scroll;
+							       instr[scroll + input_x + i] ?
+							       instr[scroll + input_x + i] : ' ');
+						input_x = strlen(instr) - scroll;
 					} else
 						input_x--;
 					instr[scroll + input_x] = '\0';
-					mvwaddch(dialog, box_y, input_x + box_x,
-						 ' ');
+					mvwaddch(dialog, box_y, input_x + box_x, ' ');
 					wmove(dialog, box_y, input_x + box_x);
 					wrefresh(dialog);
 				}
 				continue;
 			default:
 				if (key < 0x100 && isprint(key)) {
 					if (scroll + input_x < MAX_LEN) {
 						wattrset(dialog, inputbox_attr);
 						instr[scroll + input_x] = key;
-						instr[scroll + input_x + 1] =
-						    '\0';
+						instr[scroll + input_x + 1] = '\0';
 						if (input_x == box_width - 1) {
 							scroll++;
-							wmove(dialog, box_y,
-							      box_x);
-							for (i = 0;
-							     i < box_width - 1;
-							     i++)
-								waddch(dialog,
-								       instr
-								       [scroll +
-									i]);
+							wmove(dialog, box_y, box_x);
+							for (i = 0; i < box_width - 1; i++)
+								waddch(dialog, instr [scroll + i]);
 						} else {
-							wmove(dialog, box_y,
-							      input_x++ +
-							      box_x);
+							wmove(dialog, box_y, input_x++ + box_x);
 							waddch(dialog, key);
 						}
 						wrefresh(dialog);
 					} else
 						flash();	/* Alarm user about overflow */
diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index 083f13d..260cc4d 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -61,12 +61,12 @@
 static int menu_width, item_x;
 
 /*
  * Print menu item
  */
-static void
-print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey)
+static void print_item(WINDOW * win, const char *item, int choice,
+		       int selected, int hotkey)
 {
 	int j;
 	char menu_item[menu_width + 1];
 
 	strncpy(menu_item, item, menu_width);
@@ -98,12 +98,12 @@ print_item(WINDOW * win, const char *ite
 }
 
 /*
  * Print the scroll indicators.
  */
-static void
-print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, int height)
+static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
+			 int height)
 {
 	int cur_y, cur_x;
 
 	getyx(win, cur_y, cur_x);
 
@@ -156,14 +156,13 @@ static void print_buttons(WINDOW * win, 
 }
 
 /*
  * Display a menu for choosing among a number of options
  */
-int
-dialog_menu(const char *title, const char *prompt, int height, int width,
-	    int menu_height, const char *current, int item_no,
-	    const char *const *items)
+int dialog_menu(const char *title, const char *prompt, int height, int width,
+                int menu_height, const char *current, int item_no,
+                const char *const *items)
 {
 	int i, j, x, y, box_x, box_y;
 	int key = 0, button = 0, scroll = 0, choice = 0, first_item =
 	    0, max_choice;
 	WINDOW *dialog, *menu;
@@ -281,24 +280,18 @@ dialog_menu(const char *title, const cha
 
 		if (strchr("ynmh", key))
 			i = max_choice;
 		else {
 			for (i = choice + 1; i < max_choice; i++) {
-				j = first_alpha(items[(scroll + i) * 2 + 1],
-						"YyNnMmHh");
-				if (key ==
-				    tolower(items[(scroll + i) * 2 + 1][j]))
+				j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh");
+				if (key == tolower(items[(scroll + i) * 2 + 1][j]))
 					break;
 			}
 			if (i == max_choice)
 				for (i = 0; i < max_choice; i++) {
-					j = first_alpha(items
-							[(scroll + i) * 2 + 1],
-							"YyNnMmHh");
-					if (key ==
-					    tolower(items[(scroll + i) * 2 + 1]
-						    [j]))
+					j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh");
+					if (key == tolower(items[(scroll + i) * 2 + 1][j]))
 						break;
 				}
 		}
 
 		if (i < max_choice ||
@@ -317,57 +310,44 @@ dialog_menu(const char *title, const cha
 					wscrl(menu, -1);
 					scrollok(menu, FALSE);
 
 					scroll--;
 
-					print_item(menu, items[scroll * 2 + 1],
-						   0, FALSE,
-						   (items[scroll * 2][0] !=
-						    ':'));
+					print_item(menu, items[scroll * 2 + 1], 0, FALSE,
+						   (items[scroll * 2][0] != ':'));
 				} else
 					choice = MAX(choice - 1, 0);
 
 			} else if (key == KEY_DOWN || key == '+') {
 
 				print_item(menu,
-					   items[(scroll + choice) * 2 + 1],
-					   choice, FALSE,
-					   (items[(scroll + choice) * 2][0] !=
-					    ':'));
+					   items[(scroll + choice) * 2 + 1], choice, FALSE,
+					   (items[(scroll + choice) * 2][0] != ':'));
 
 				if ((choice > max_choice - 3) &&
-				    (scroll + max_choice < item_no)
-				    ) {
+				    (scroll + max_choice < item_no)) {
 					/* Scroll menu up */
 					scrollok(menu, TRUE);
 					wscrl(menu, 1);
 					scrollok(menu, FALSE);
 
 					scroll++;
 
-					print_item(menu,
-						   items[(scroll + max_choice -
-							  1) * 2 + 1],
+					print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
 						   max_choice - 1, FALSE,
-						   (items
-						    [(scroll + max_choice -
-						      1) * 2][0] != ':'));
+						   (items [(scroll + max_choice - 1) * 2][0] != ':'));
 				} else
-					choice =
-					    MIN(choice + 1, max_choice - 1);
+					choice = MIN(choice + 1, max_choice - 1);
 
 			} else if (key == KEY_PPAGE) {
 				scrollok(menu, TRUE);
 				for (i = 0; (i < max_choice); i++) {
 					if (scroll > 0) {
 						wscrl(menu, -1);
 						scroll--;
-						print_item(menu,
-							   items[scroll * 2 +
-								 1], 0, FALSE,
-							   (items[scroll * 2][0]
-							    != ':'));
+						print_item(menu, items[scroll * 2 + 1], 0, FALSE,
+							   (items[scroll * 2][0] != ':'));
 					} else {
 						if (choice > 0)
 							choice--;
 					}
 				}
@@ -378,33 +358,24 @@ dialog_menu(const char *title, const cha
 					if (scroll + max_choice < item_no) {
 						scrollok(menu, TRUE);
 						wscrl(menu, 1);
 						scrollok(menu, FALSE);
 						scroll++;
-						print_item(menu,
-							   items[(scroll +
-								  max_choice -
-								  1) * 2 + 1],
-							   max_choice - 1,
-							   FALSE,
-							   (items
-							    [(scroll +
-							      max_choice -
-							      1) * 2][0] !=
-							    ':'));
+						print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
+							   max_choice - 1, FALSE,
+							   (items [(scroll + max_choice - 1) * 2][0] != ':'));
 					} else {
 						if (choice + 1 < max_choice)
 							choice++;
 					}
 				}
 
 			} else
 				choice = i;
 
 			print_item(menu, items[(scroll + choice) * 2 + 1],
-				   choice, TRUE,
-				   (items[(scroll + choice) * 2][0] != ':'));
+				   choice, TRUE, (items[(scroll + choice) * 2][0] != ':'));
 
 			print_arrows(dialog, item_no, scroll,
 				     box_y, box_x + item_x + 1, menu_height);
 
 			wnoutrefresh(dialog);
@@ -458,13 +429,11 @@ dialog_menu(const char *title, const cha
 			delwin(dialog);
 			if (button == 2)
 				fprintf(stderr, "%s \"%s\"\n",
 					items[(scroll + choice) * 2],
 					items[(scroll + choice) * 2 + 1] +
-					first_alpha(items
-						    [(scroll + choice) * 2 + 1],
-						    ""));
+					first_alpha(items [(scroll + choice) * 2 + 1], ""));
 			else
 				fprintf(stderr, "%s\n",
 					items[(scroll + choice) * 2]);
 
 			remove("lxdialog.scrltmp");
diff --git a/scripts/lxdialog/msgbox.c b/scripts/lxdialog/msgbox.c
index 76f358c..b394057 100644
--- a/scripts/lxdialog/msgbox.c
+++ b/scripts/lxdialog/msgbox.c
@@ -23,13 +23,12 @@
 
 /*
  * Display a message box. Program will pause and display an "OK" button
  * if the parameter 'pause' is non-zero.
  */
-int
-dialog_msgbox(const char *title, const char *prompt, int height, int width,
-	      int pause)
+int dialog_msgbox(const char *title, const char *prompt, int height, int width,
+                  int pause)
 {
 	int i, x, y, key = 0;
 	WINDOW *dialog;
 
 	/* center dialog box on screen */
diff --git a/scripts/lxdialog/textbox.c b/scripts/lxdialog/textbox.c
index d6e7f2a..fa8d92e 100644
--- a/scripts/lxdialog/textbox.c
+++ b/scripts/lxdialog/textbox.c
@@ -44,34 +44,30 @@ int dialog_textbox(const char *title, co
 	search_term[0] = '\0';	/* no search term entered yet */
 
 	/* Open input file for reading */
 	if ((fd = open(file, O_RDONLY)) == -1) {
 		endwin();
-		fprintf(stderr,
-			"\nCan't open input file in dialog_textbox().\n");
+		fprintf(stderr, "\nCan't open input file in dialog_textbox().\n");
 		exit(-1);
 	}
 	/* Get file size. Actually, 'file_size' is the real file size - 1,
 	   since it's only the last byte offset from the beginning */
 	if ((file_size = lseek(fd, 0, SEEK_END)) == -1) {
 		endwin();
-		fprintf(stderr,
-			"\nError getting file size in dialog_textbox().\n");
+		fprintf(stderr, "\nError getting file size in dialog_textbox().\n");
 		exit(-1);
 	}
 	/* Restore file pointer to beginning of file after getting file size */
 	if (lseek(fd, 0, SEEK_SET) == -1) {
 		endwin();
-		fprintf(stderr,
-			"\nError moving file pointer in dialog_textbox().\n");
+		fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
 		exit(-1);
 	}
 	/* Allocate space for read buffer */
 	if ((buf = malloc(BUF_SIZE + 1)) == NULL) {
 		endwin();
-		fprintf(stderr,
-			"\nCan't allocate memory in dialog_textbox().\n");
+		fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n");
 		exit(-1);
 	}
 	if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
 		endwin();
 		fprintf(stderr, "\nError reading file in dialog_textbox().\n");
@@ -148,27 +144,24 @@ int dialog_textbox(const char *title, co
 			if (!begin_reached) {
 				begin_reached = 1;
 				/* First page not in buffer? */
 				if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
 					endwin();
-					fprintf(stderr,
-						"\nError moving file pointer in dialog_textbox().\n");
+					fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
 					exit(-1);
 				}
 				if (fpos > bytes_read) {	/* Yes, we have to read it in */
 					if (lseek(fd, 0, SEEK_SET) == -1) {
 						endwin();
-						fprintf(stderr,
-							"\nError moving file pointer in "
-							"dialog_textbox().\n");
+						fprintf(stderr, "\nError moving file pointer in "
+							        "dialog_textbox().\n");
 						exit(-1);
 					}
 					if ((bytes_read =
 					     read(fd, buf, BUF_SIZE)) == -1) {
 						endwin();
-						fprintf(stderr,
-							"\nError reading file in dialog_textbox().\n");
+						fprintf(stderr, "\nError reading file in dialog_textbox().\n");
 						exit(-1);
 					}
 					buf[bytes_read] = '\0';
 				}
 				page = buf;
@@ -183,26 +176,23 @@ int dialog_textbox(const char *title, co
 
 			end_reached = 1;
 			/* Last page not in buffer? */
 			if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
 				endwin();
-				fprintf(stderr,
-					"\nError moving file pointer in dialog_textbox().\n");
+				fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
 				exit(-1);
 			}
 			if (fpos < file_size) {	/* Yes, we have to read it in */
 				if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) {
 					endwin();
-					fprintf(stderr,
-						"\nError moving file pointer in dialog_textbox().\n");
+					fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n");
 					exit(-1);
 				}
 				if ((bytes_read =
 				     read(fd, buf, BUF_SIZE)) == -1) {
 					endwin();
-					fprintf(stderr,
-						"\nError reading file in dialog_textbox().\n");
+					fprintf(stderr, "\nError reading file in dialog_textbox().\n");
 					exit(-1);
 				}
 				buf[bytes_read] = '\0';
 			}
 			page = buf + bytes_read;
@@ -340,13 +330,12 @@ static void back_lines(int n)
 	if (!end_reached) {
 		/* Either beginning of buffer or beginning of file reached? */
 		if (page == buf) {
 			if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
 				endwin();
-				fprintf(stderr,
-					"\nError moving file pointer in "
-					"back_lines().\n");
+				fprintf(stderr, "\nError moving file pointer in "
+					        "back_lines().\n");
 				exit(-1);
 			}
 			if (fpos > bytes_read) {	/* Not beginning of file yet */
 				/* We've reached beginning of buffer, but not beginning of
 				   file yet, so read previous part of file into buffer.
@@ -356,34 +345,28 @@ static void back_lines(int n)
 				/* Really possible to move backward BUF_SIZE/2 bytes? */
 				if (fpos < BUF_SIZE / 2 + bytes_read) {
 					/* No, move less then */
 					if (lseek(fd, 0, SEEK_SET) == -1) {
 						endwin();
-						fprintf(stderr,
-							"\nError moving file pointer in "
-							"back_lines().\n");
+						fprintf(stderr, "\nError moving file pointer in "
+						                "back_lines().\n");
 						exit(-1);
 					}
 					page = buf + fpos - bytes_read;
 				} else {	/* Move backward BUF_SIZE/2 bytes */
-					if (lseek
-					    (fd, -(BUF_SIZE / 2 + bytes_read),
-					     SEEK_CUR)
-					    == -1) {
+					if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) {
 						endwin();
-						fprintf(stderr,
-							"\nError moving file pointer "
-							"in back_lines().\n");
+						fprintf(stderr, "\nError moving file pointer "
+						                "in back_lines().\n");
 						exit(-1);
 					}
 					page = buf + BUF_SIZE / 2;
 				}
 				if ((bytes_read =
 				     read(fd, buf, BUF_SIZE)) == -1) {
 					endwin();
-					fprintf(stderr,
-						"\nError reading file in back_lines().\n");
+					fprintf(stderr, "\nError reading file in back_lines().\n");
 					exit(-1);
 				}
 				buf[bytes_read] = '\0';
 			} else {	/* Beginning of file reached */
 				begin_reached = 1;
@@ -401,47 +384,38 @@ static void back_lines(int n)
 	for (i = 0; i < n; i++)
 		do {
 			if (page == buf) {
 				if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
 					endwin();
-					fprintf(stderr,
-						"\nError moving file pointer in back_lines().\n");
+					fprintf(stderr, "\nError moving file pointer in back_lines().\n");
 					exit(-1);
 				}
 				if (fpos > bytes_read) {
 					/* Really possible to move backward BUF_SIZE/2 bytes? */
 					if (fpos < BUF_SIZE / 2 + bytes_read) {
 						/* No, move less then */
-						if (lseek(fd, 0, SEEK_SET) ==
-						    -1) {
+						if (lseek(fd, 0, SEEK_SET) == -1) {
 							endwin();
-							fprintf(stderr,
-								"\nError moving file pointer "
-								"in back_lines().\n");
+							fprintf(stderr, "\nError moving file pointer "
+							                "in back_lines().\n");
 							exit(-1);
 						}
 						page = buf + fpos - bytes_read;
 					} else {	/* Move backward BUF_SIZE/2 bytes */
-						if (lseek
-						    (fd,
-						     -(BUF_SIZE / 2 +
-						       bytes_read),
-						     SEEK_CUR) == -1) {
+						if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) {
 							endwin();
-							fprintf(stderr,
-								"\nError moving file pointer"
-								" in back_lines().\n");
+							fprintf(stderr, "\nError moving file pointer"
+							                " in back_lines().\n");
 							exit(-1);
 						}
 						page = buf + BUF_SIZE / 2;
 					}
 					if ((bytes_read =
 					     read(fd, buf, BUF_SIZE)) == -1) {
 						endwin();
-						fprintf(stderr,
-							"\nError reading file in "
-							"back_lines().\n");
+						fprintf(stderr, "\nError reading file in "
+						                "back_lines().\n");
 						exit(-1);
 					}
 					buf[bytes_read] = '\0';
 				} else {	/* Beginning of file reached */
 					begin_reached = 1;
@@ -511,23 +485,21 @@ static char *get_line(void)
 	while (*page != '\n') {
 		if (*page == '\0') {
 			/* Either end of file or end of buffer reached */
 			if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
 				endwin();
-				fprintf(stderr,
-					"\nError moving file pointer in "
-					"get_line().\n");
+				fprintf(stderr, "\nError moving file pointer in "
+				                "get_line().\n");
 				exit(-1);
 			}
 			if (fpos < file_size) {	/* Not end of file yet */
 				/* We've reached end of buffer, but not end of file yet,
 				   so read next part of file into buffer */
 				if ((bytes_read =
 				     read(fd, buf, BUF_SIZE)) == -1) {
 					endwin();
-					fprintf(stderr,
-						"\nError reading file in get_line().\n");
+					fprintf(stderr, "\nError reading file in get_line().\n");
 					exit(-1);
 				}
 				buf[bytes_read] = '\0';
 				page = buf;
 			} else {
@@ -559,12 +531,11 @@ static void print_position(WINDOW * win,
 {
 	int fpos, percent;
 
 	if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
 		endwin();
-		fprintf(stderr,
-			"\nError moving file pointer in print_position().\n");
+		fprintf(stderr, "\nError moving file pointer in print_position().\n");
 		exit(-1);
 	}
 	wattrset(win, position_indicator_attr);
 	wbkgdset(win, position_indicator_attr & A_COLOR);
 	percent = !file_size ?
diff --git a/scripts/lxdialog/util.c b/scripts/lxdialog/util.c
index 232b32c..1f84809 100644
--- a/scripts/lxdialog/util.c
+++ b/scripts/lxdialog/util.c
@@ -26,11 +26,11 @@ bool use_colors = 1;
 
 const char *backtitle = NULL;
 
 const char *dialog_result;
 
-/* 
+/*
  * Attribute values, default is for mono display
  */
 chtype attributes[] = {
 	A_NORMAL,		/* screen_attr */
 	A_NORMAL,		/* shadow_attr */
diff --git a/scripts/lxdialog/yesno.c b/scripts/lxdialog/yesno.c
index dffd5af..84f3e8e 100644
--- a/scripts/lxdialog/yesno.c
+++ b/scripts/lxdialog/yesno.c
@@ -94,12 +94,11 @@ int dialog_yesno(const char *title, cons
 			return 1;
 
 		case TAB:
 		case KEY_LEFT:
 		case KEY_RIGHT:
-			button = ((key == KEY_LEFT ? --button : ++button) < 0)
-			    ? 1 : (button > 1 ? 0 : button);
+			button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
 
 			print_buttons(dialog, height, width, button);
 			wrefresh(dialog);
 			break;
 		case ' ':

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [2/7] kconfig: lxdialog is now sparse clean
  2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
  2005-11-21 22:38 ` [1/7] kconfig: fixup after Lindent Sam Ravnborg
@ 2005-11-21 22:38 ` Sam Ravnborg
  2005-11-21 23:44   ` Al Viro
  2005-11-21 22:39 ` [3/7] kconfig: Add print_title helper in lxdialog Sam Ravnborg
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:38 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel

    kconfig: lxdialog is now sparse clean
    
    Replacing a gcc idiom with malloc and deleting an unused global
    variable made lxdialog sparse clean.
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index 260cc4d..ff3a617 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -65,11 +65,11 @@ static int menu_width, item_x;
  */
 static void print_item(WINDOW * win, const char *item, int choice,
 		       int selected, int hotkey)
 {
 	int j;
-	char menu_item[menu_width + 1];
+	char *menu_item = malloc(menu_width + 1);
 
 	strncpy(menu_item, item, menu_width);
 	menu_item[menu_width] = 0;
 	j = first_alpha(menu_item, "YyNnMmHh");
 
@@ -93,10 +93,11 @@ static void print_item(WINDOW * win, con
 	}
 	if (selected) {
 		wmove(win, choice, item_x + 1);
 		wrefresh(win);
 	}
+	free(menu_item);
 }
 
 /*
  * Print the scroll indicators.
  */
@@ -219,11 +220,11 @@ int dialog_menu(const char *title, const
 	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
 		 menubox_border_attr, menubox_attr);
 
 	/*
 	 * Find length of longest item in order to center menu.
-	 * Set 'choice' to default item. 
+	 * Set 'choice' to default item.
 	 */
 	item_x = 0;
 	for (i = 0; i < item_no; i++) {
 		item_x =
 		    MAX(item_x, MIN(menu_width, strlen(items[i * 2 + 1]) + 2));
diff --git a/scripts/lxdialog/util.c b/scripts/lxdialog/util.c
index 1f84809..ce41147 100644
--- a/scripts/lxdialog/util.c
+++ b/scripts/lxdialog/util.c
@@ -24,12 +24,10 @@
 /* use colors by default? */
 bool use_colors = 1;
 
 const char *backtitle = NULL;
 
-const char *dialog_result;
-
 /*
  * Attribute values, default is for mono display
  */
 chtype attributes[] = {
 	A_NORMAL,		/* screen_attr */

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [3/7] kconfig: Add print_title helper in lxdialog
  2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
  2005-11-21 22:38 ` [1/7] kconfig: fixup after Lindent Sam Ravnborg
  2005-11-21 22:38 ` [2/7] kconfig: lxdialog is now sparse clean Sam Ravnborg
@ 2005-11-21 22:39 ` Sam Ravnborg
  2005-11-21 22:39 ` [4/7] kconfig: Left aling menu items in menuconfig Sam Ravnborg
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:39 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel

    kconfig: Add print_title helper in lxdialog
    
    Simplify check for long title and use a helper function in util.c
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/scripts/lxdialog/checklist.c b/scripts/lxdialog/checklist.c
index ae40a2b..3fb681f 100644
--- a/scripts/lxdialog/checklist.c
+++ b/scripts/lxdialog/checklist.c
@@ -156,24 +156,11 @@ int dialog_checklist(const char *title, 
 	for (i = 0; i < width - 2; i++)
 		waddch(dialog, ACS_HLINE);
 	wattrset(dialog, dialog_attr);
 	waddch(dialog, ACS_RTEE);
 
-	if (title != NULL && strlen(title) >= width - 2) {
-		/* truncate long title -- mec */
-		char *title2 = malloc(width - 2 + 1);
-		memcpy(title2, title, width - 2);
-		title2[width - 2] = '\0';
-		title = title2;
-	}
-
-	if (title != NULL) {
-		wattrset(dialog, title_attr);
-		mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
-		waddstr(dialog, (char *)title);
-		waddch(dialog, ' ');
-	}
+	print_title(dialog, title, width);
 
 	wattrset(dialog, dialog_attr);
 	print_autowrap(dialog, prompt, width - 2, 1, 3);
 
 	list_width = width - 6;
diff --git a/scripts/lxdialog/dialog.h b/scripts/lxdialog/dialog.h
index 3cf3d35..f882204 100644
--- a/scripts/lxdialog/dialog.h
+++ b/scripts/lxdialog/dialog.h
@@ -143,10 +143,11 @@ void end_dialog(void);
 void attr_clear(WINDOW * win, int height, int width, chtype attr);
 void dialog_clear(void);
 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 print_title(WINDOW *dialog, const char *title, int width);
 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);
 
 int first_alpha(const char *string, const char *exempt);
diff --git a/scripts/lxdialog/inputbox.c b/scripts/lxdialog/inputbox.c
index bc135c7..7795037 100644
--- a/scripts/lxdialog/inputbox.c
+++ b/scripts/lxdialog/inputbox.c
@@ -64,24 +64,11 @@ int dialog_inputbox(const char *title, c
 	for (i = 0; i < width - 2; i++)
 		waddch(dialog, ACS_HLINE);
 	wattrset(dialog, dialog_attr);
 	waddch(dialog, ACS_RTEE);
 
-	if (title != NULL && strlen(title) >= width - 2) {
-		/* truncate long title -- mec */
-		char *title2 = malloc(width - 2 + 1);
-		memcpy(title2, title, width - 2);
-		title2[width - 2] = '\0';
-		title = title2;
-	}
-
-	if (title != NULL) {
-		wattrset(dialog, title_attr);
-		mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
-		waddstr(dialog, (char *)title);
-		waddch(dialog, ' ');
-	}
+	print_title(dialog, title, width);
 
 	wattrset(dialog, dialog_attr);
 	print_autowrap(dialog, prompt, width - 2, 1, 3);
 
 	/* Draw the input field box */
diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index ff3a617..ebfe6a3 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -187,24 +187,11 @@ int dialog_menu(const char *title, const
 		waddch(dialog, ACS_HLINE);
 	wattrset(dialog, dialog_attr);
 	wbkgdset(dialog, dialog_attr & A_COLOR);
 	waddch(dialog, ACS_RTEE);
 
-	if (title != NULL && strlen(title) >= width - 2) {
-		/* truncate long title -- mec */
-		char *title2 = malloc(width - 2 + 1);
-		memcpy(title2, title, width - 2);
-		title2[width - 2] = '\0';
-		title = title2;
-	}
-
-	if (title != NULL) {
-		wattrset(dialog, title_attr);
-		mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
-		waddstr(dialog, (char *)title);
-		waddch(dialog, ' ');
-	}
+	print_title(dialog, title, width);
 
 	wattrset(dialog, dialog_attr);
 	print_autowrap(dialog, prompt, width - 2, 1, 3);
 
 	menu_width = width - 6;
diff --git a/scripts/lxdialog/msgbox.c b/scripts/lxdialog/msgbox.c
index b394057..7323f54 100644
--- a/scripts/lxdialog/msgbox.c
+++ b/scripts/lxdialog/msgbox.c
@@ -40,24 +40,12 @@ int dialog_msgbox(const char *title, con
 	dialog = newwin(height, width, y, x);
 	keypad(dialog, TRUE);
 
 	draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
 
-	if (title != NULL && strlen(title) >= width - 2) {
-		/* truncate long title -- mec */
-		char *title2 = malloc(width - 2 + 1);
-		memcpy(title2, title, width - 2);
-		title2[width - 2] = '\0';
-		title = title2;
-	}
+	print_title(dialog, title, width);
 
-	if (title != NULL) {
-		wattrset(dialog, title_attr);
-		mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
-		waddstr(dialog, (char *)title);
-		waddch(dialog, ' ');
-	}
 	wattrset(dialog, dialog_attr);
 	print_autowrap(dialog, prompt, width - 2, 1, 2);
 
 	if (pause) {
 		wattrset(dialog, border_attr);
diff --git a/scripts/lxdialog/textbox.c b/scripts/lxdialog/textbox.c
index fa8d92e..77848bb 100644
--- a/scripts/lxdialog/textbox.c
+++ b/scripts/lxdialog/textbox.c
@@ -101,24 +101,12 @@ int dialog_textbox(const char *title, co
 		waddch(dialog, ACS_HLINE);
 	wattrset(dialog, dialog_attr);
 	wbkgdset(dialog, dialog_attr & A_COLOR);
 	waddch(dialog, ACS_RTEE);
 
-	if (title != NULL && strlen(title) >= width - 2) {
-		/* truncate long title -- mec */
-		char *title2 = malloc(width - 2 + 1);
-		memcpy(title2, title, width - 2);
-		title2[width - 2] = '\0';
-		title = title2;
-	}
+	print_title(dialog, title, width);
 
-	if (title != NULL) {
-		wattrset(dialog, title_attr);
-		mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
-		waddstr(dialog, (char *)title);
-		waddch(dialog, ' ');
-	}
 	print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
 	wnoutrefresh(dialog);
 	getyx(dialog, cur_y, cur_x);	/* Save cursor position */
 
 	/* Print first page of text */
diff --git a/scripts/lxdialog/util.c b/scripts/lxdialog/util.c
index ce41147..f82cebb 100644
--- a/scripts/lxdialog/util.c
+++ b/scripts/lxdialog/util.c
@@ -175,10 +175,24 @@ void color_setup(void)
 void end_dialog(void)
 {
 	endwin();
 }
 
+/* Print the title of the dialog. Center the title and truncate
+ * tile if wider than dialog (- 2 chars).
+ **/
+void print_title(WINDOW *dialog, const char *title, int width)
+{
+	if (title) {
+		int tlen = MIN(width - 2, strlen(title));
+		wattrset(dialog, title_attr);
+		mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' ');
+		mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen);
+		waddch(dialog, ' ');
+	}
+}
+
 /*
  * Print a string of text in a window, automatically wrap around to the
  * next line if the string is too long to fit on one line. Newline
  * characters '\n' are replaced by spaces.  We start on a new line
  * if there is no room for at least 4 nonblanks following a double-space.
diff --git a/scripts/lxdialog/yesno.c b/scripts/lxdialog/yesno.c
index 84f3e8e..cb2568a 100644
--- a/scripts/lxdialog/yesno.c
+++ b/scripts/lxdialog/yesno.c
@@ -59,24 +59,11 @@ int dialog_yesno(const char *title, cons
 	for (i = 0; i < width - 2; i++)
 		waddch(dialog, ACS_HLINE);
 	wattrset(dialog, dialog_attr);
 	waddch(dialog, ACS_RTEE);
 
-	if (title != NULL && strlen(title) >= width - 2) {
-		/* truncate long title -- mec */
-		char *title2 = malloc(width - 2 + 1);
-		memcpy(title2, title, width - 2);
-		title2[width - 2] = '\0';
-		title = title2;
-	}
-
-	if (title != NULL) {
-		wattrset(dialog, title_attr);
-		mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
-		waddstr(dialog, (char *)title);
-		waddch(dialog, ' ');
-	}
+	print_title(dialog, title, width);
 
 	wattrset(dialog, dialog_attr);
 	print_autowrap(dialog, prompt, width - 2, 1, 3);
 
 	print_buttons(dialog, height, width, 0);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [4/7] kconfig: Left aling menu items in menuconfig
  2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
                   ` (2 preceding siblings ...)
  2005-11-21 22:39 ` [3/7] kconfig: Add print_title helper in lxdialog Sam Ravnborg
@ 2005-11-21 22:39 ` Sam Ravnborg
  2005-11-21 22:40 ` [5/7] kconfig: Fix indention when using menuconfig in text-onle consoles Sam Ravnborg
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:39 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel

    kconfig: Left aling menu items in menuconfig
    
    Keeping menu lines on a fixed position creates less visual
    noise when navigating the menus.
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index ebfe6a3..89fcf41 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -56,11 +56,12 @@
  * fscanf would read in 'scroll', and eventually that value would get used.
  */
 
 #include "dialog.h"
 
-static int menu_width, item_x;
+#define ITEM_IDENT 4   /* Indent of menu entries. Fixed for all menus */
+static int menu_width;
 
 /*
  * Print menu item
  */
 static void print_item(WINDOW * win, const char *item, int choice,
@@ -84,17 +85,17 @@ static void print_item(WINDOW * win, con
 	}
 #else
 	wclrtoeol(win);
 #endif
 	wattrset(win, selected ? item_selected_attr : item_attr);
-	mvwaddstr(win, choice, item_x, menu_item);
+	mvwaddstr(win, choice, ITEM_IDENT, menu_item);
 	if (hotkey) {
 		wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
-		mvwaddch(win, choice, item_x + j, menu_item[j]);
+		mvwaddch(win, choice, ITEM_IDENT + j, menu_item[j]);
 	}
 	if (selected) {
-		wmove(win, choice, item_x + 1);
+		wmove(win, choice, ITEM_IDENT + 1);
 		wrefresh(win);
 	}
 	free(menu_item);
 }
 
@@ -205,23 +206,14 @@ int dialog_menu(const char *title, const
 
 	/* draw a box around the menu items */
 	draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
 		 menubox_border_attr, menubox_attr);
 
-	/*
-	 * Find length of longest item in order to center menu.
-	 * Set 'choice' to default item.
-	 */
-	item_x = 0;
-	for (i = 0; i < item_no; i++) {
-		item_x =
-		    MAX(item_x, MIN(menu_width, strlen(items[i * 2 + 1]) + 2));
+	/* Set choice to default item */
+	for (i = 0; i < item_no; i++)
 		if (strcmp(current, items[i * 2]) == 0)
 			choice = i;
-	}
-
-	item_x = (menu_width - item_x) / 2;
 
 	/* get the scroll info from the temp file */
 	if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) {
 		if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) &&
 		    (scroll + max_choice > choice) && (scroll >= 0) &&
@@ -252,14 +244,14 @@ int dialog_menu(const char *title, const
 	}
 
 	wnoutrefresh(menu);
 
 	print_arrows(dialog, item_no, scroll,
-		     box_y, box_x + item_x + 1, menu_height);
+		     box_y, box_x + ITEM_IDENT + 1, menu_height);
 
 	print_buttons(dialog, height, width, 0);
-	wmove(menu, choice, item_x + 1);
+	wmove(menu, choice, ITEM_IDENT + 1);
 	wrefresh(menu);
 
 	while (key != ESC) {
 		key = wgetch(menu);
 
@@ -284,11 +276,11 @@ int dialog_menu(const char *title, const
 
 		if (i < max_choice ||
 		    key == KEY_UP || key == KEY_DOWN ||
 		    key == '-' || key == '+' ||
 		    key == KEY_PPAGE || key == KEY_NPAGE) {
-
+			/* Remove highligt of current item */
 			print_item(menu, items[(scroll + choice) * 2 + 1],
 				   choice, FALSE,
 				   (items[(scroll + choice) * 2][0] != ':'));
 
 			if (key == KEY_UP || key == '-') {
@@ -362,11 +354,11 @@ int dialog_menu(const char *title, const
 
 			print_item(menu, items[(scroll + choice) * 2 + 1],
 				   choice, TRUE, (items[(scroll + choice) * 2][0] != ':'));
 
 			print_arrows(dialog, item_no, scroll,
-				     box_y, box_x + item_x + 1, menu_height);
+				     box_y, box_x + ITEM_IDENT + 1, menu_height);
 
 			wnoutrefresh(dialog);
 			wrefresh(menu);
 
 			continue;	/* wait for another key press */

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [5/7] kconfig: Fix indention when using menuconfig in text-onle consoles
  2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
                   ` (3 preceding siblings ...)
  2005-11-21 22:39 ` [4/7] kconfig: Left aling menu items in menuconfig Sam Ravnborg
@ 2005-11-21 22:40 ` Sam Ravnborg
  2005-11-21 22:40 ` [6/7] kconfig: make lxdialog/menubox.c more readable Sam Ravnborg
  2005-11-21 22:41 ` [7/7] kconfig: truncate too long menu lines in menuconfig Sam Ravnborg
  6 siblings, 0 replies; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:40 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel

    kconfig: Fix indention when using menuconfig in text-onle consoles
    
    When using menuconfig in a text-only console (no X started)
    the indention was often two spaces wrong. This proved to be a ncurses
    issue which are worked around by calling wrefresh more often.
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index 89fcf41..461ee08 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -92,13 +92,13 @@ static void print_item(WINDOW * win, con
 		wattrset(win, selected ? tag_key_selected_attr : tag_key_attr);
 		mvwaddch(win, choice, ITEM_IDENT + j, menu_item[j]);
 	}
 	if (selected) {
 		wmove(win, choice, ITEM_IDENT + 1);
-		wrefresh(win);
 	}
 	free(menu_item);
+	wrefresh(win);
 }
 
 /*
  * Print the scroll indicators.
  */
@@ -123,10 +123,11 @@ static void print_arrows(WINDOW * win, i
 		waddch(win, ACS_HLINE);
 	}
 
 	y = y + height + 1;
 	wmove(win, y, x);
+	wrefresh(win);
 
 	if ((height < item_no) && (scroll + height < item_no)) {
 		wattrset(win, darrow_attr);
 		waddch(win, ACS_DARROW);
 		waddstr(win, "(+)");
@@ -137,10 +138,11 @@ static void print_arrows(WINDOW * win, i
 		waddch(win, ACS_HLINE);
 		waddch(win, ACS_HLINE);
 	}
 
 	wmove(win, cur_y, cur_x);
+	wrefresh(win);
 }
 
 /*
  * Display the termination buttons.
  */
@@ -155,10 +157,21 @@ static void print_buttons(WINDOW * win, 
 
 	wmove(win, y, x + 1 + 12 * selected);
 	wrefresh(win);
 }
 
+/* scroll up n lines (n may be negative) */
+static void do_scroll(WINDOW *win, int *scroll, int n)
+{
+	/* Scroll menu up */
+	scrollok(win, TRUE);
+	wscrl(win, n);
+	scrollok(win, FALSE);
+	*scroll = *scroll + n;
+	wrefresh(win);
+}
+
 /*
  * Display a menu for choosing among a number of options
  */
 int dialog_menu(const char *title, const char *prompt, int height, int width,
                 int menu_height, const char *current, int item_no,
@@ -284,15 +297,11 @@ int dialog_menu(const char *title, const
 				   (items[(scroll + choice) * 2][0] != ':'));
 
 			if (key == KEY_UP || key == '-') {
 				if (choice < 2 && scroll) {
 					/* Scroll menu down */
-					scrollok(menu, TRUE);
-					wscrl(menu, -1);
-					scrollok(menu, FALSE);
-
-					scroll--;
+					do_scroll(menu, &scroll, -1);
 
 					print_item(menu, items[scroll * 2 + 1], 0, FALSE,
 						   (items[scroll * 2][0] != ':'));
 				} else
 					choice = MAX(choice - 1, 0);
@@ -304,15 +313,11 @@ int dialog_menu(const char *title, const
 					   (items[(scroll + choice) * 2][0] != ':'));
 
 				if ((choice > max_choice - 3) &&
 				    (scroll + max_choice < item_no)) {
 					/* Scroll menu up */
-					scrollok(menu, TRUE);
-					wscrl(menu, 1);
-					scrollok(menu, FALSE);
-
-					scroll++;
+					do_scroll(menu, &scroll, 1);
 
 					print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
 						   max_choice - 1, FALSE,
 						   (items [(scroll + max_choice - 1) * 2][0] != ':'));
 				} else
@@ -320,37 +325,31 @@ int dialog_menu(const char *title, const
 
 			} else if (key == KEY_PPAGE) {
 				scrollok(menu, TRUE);
 				for (i = 0; (i < max_choice); i++) {
 					if (scroll > 0) {
-						wscrl(menu, -1);
-						scroll--;
+						do_scroll(menu, &scroll, -1);
 						print_item(menu, items[scroll * 2 + 1], 0, FALSE,
 							   (items[scroll * 2][0] != ':'));
 					} else {
 						if (choice > 0)
 							choice--;
 					}
 				}
-				scrollok(menu, FALSE);
 
 			} else if (key == KEY_NPAGE) {
 				for (i = 0; (i < max_choice); i++) {
 					if (scroll + max_choice < item_no) {
-						scrollok(menu, TRUE);
-						wscrl(menu, 1);
-						scrollok(menu, FALSE);
-						scroll++;
+						do_scroll(menu, &scroll, 1);
 						print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
 							   max_choice - 1, FALSE,
 							   (items [(scroll + max_choice - 1) * 2][0] != ':'));
 					} else {
 						if (choice + 1 < max_choice)
 							choice++;
 					}
 				}
-
 			} else
 				choice = i;
 
 			print_item(menu, items[(scroll + choice) * 2 + 1],
 				   choice, TRUE, (items[(scroll + choice) * 2][0] != ':'));

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [6/7] kconfig: make lxdialog/menubox.c more readable
  2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
                   ` (4 preceding siblings ...)
  2005-11-21 22:40 ` [5/7] kconfig: Fix indention when using menuconfig in text-onle consoles Sam Ravnborg
@ 2005-11-21 22:40 ` Sam Ravnborg
  2005-11-21 22:41 ` [7/7] kconfig: truncate too long menu lines in menuconfig Sam Ravnborg
  6 siblings, 0 replies; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:40 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel

    kconfig: make lxdialog/menubox.c more readable
    
    Utilising a small macro for print_item made wonders for readability
    for this file.
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index 461ee08..d0bf32b 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -62,12 +62,12 @@
 static int menu_width;
 
 /*
  * Print menu item
  */
-static void print_item(WINDOW * win, const char *item, int choice,
-		       int selected, int hotkey)
+static void do_print_item(WINDOW * win, const char *item, int choice,
+                          int selected, int hotkey)
 {
 	int j;
 	char *menu_item = malloc(menu_width + 1);
 
 	strncpy(menu_item, item, menu_width);
@@ -97,10 +97,16 @@ static void print_item(WINDOW * win, con
 	}
 	free(menu_item);
 	wrefresh(win);
 }
 
+#define print_item(index, choice, selected) \
+do {\
+	int hotkey = (items[(index) * 2][0] != ':'); \
+	do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \
+} while (0)
+
 /*
  * Print the scroll indicators.
  */
 static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x,
 			 int height)
@@ -249,13 +255,11 @@ int dialog_menu(const char *title, const
 		choice = choice - scroll;
 	}
 
 	/* Print the menu */
 	for (i = 0; i < max_choice; i++) {
-		print_item(menu, items[(first_item + i) * 2 + 1], i,
-			   i == choice,
-			   (items[(first_item + i) * 2][0] != ':'));
+		print_item(first_item + i, i, i == choice);
 	}
 
 	wnoutrefresh(menu);
 
 	print_arrows(dialog, item_no, scroll,
@@ -290,71 +294,61 @@ int dialog_menu(const char *title, const
 		if (i < max_choice ||
 		    key == KEY_UP || key == KEY_DOWN ||
 		    key == '-' || key == '+' ||
 		    key == KEY_PPAGE || key == KEY_NPAGE) {
 			/* Remove highligt of current item */
-			print_item(menu, items[(scroll + choice) * 2 + 1],
-				   choice, FALSE,
-				   (items[(scroll + choice) * 2][0] != ':'));
+			print_item(scroll + choice, choice, FALSE);
 
 			if (key == KEY_UP || key == '-') {
 				if (choice < 2 && scroll) {
 					/* Scroll menu down */
 					do_scroll(menu, &scroll, -1);
 
-					print_item(menu, items[scroll * 2 + 1], 0, FALSE,
-						   (items[scroll * 2][0] != ':'));
+					print_item(scroll, 0, FALSE);
 				} else
 					choice = MAX(choice - 1, 0);
 
 			} else if (key == KEY_DOWN || key == '+') {
-
-				print_item(menu,
-					   items[(scroll + choice) * 2 + 1], choice, FALSE,
-					   (items[(scroll + choice) * 2][0] != ':'));
+				print_item(scroll+choice, choice, FALSE);
 
 				if ((choice > max_choice - 3) &&
 				    (scroll + max_choice < item_no)) {
 					/* Scroll menu up */
 					do_scroll(menu, &scroll, 1);
 
-					print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
-						   max_choice - 1, FALSE,
-						   (items [(scroll + max_choice - 1) * 2][0] != ':'));
+					print_item(scroll+max_choice - 1,
+						   max_choice - 1, FALSE);
 				} else
 					choice = MIN(choice + 1, max_choice - 1);
 
 			} else if (key == KEY_PPAGE) {
 				scrollok(menu, TRUE);
 				for (i = 0; (i < max_choice); i++) {
 					if (scroll > 0) {
 						do_scroll(menu, &scroll, -1);
-						print_item(menu, items[scroll * 2 + 1], 0, FALSE,
-							   (items[scroll * 2][0] != ':'));
+						print_item(scroll, 0, FALSE);
 					} else {
 						if (choice > 0)
 							choice--;
 					}
 				}
 
 			} else if (key == KEY_NPAGE) {
 				for (i = 0; (i < max_choice); i++) {
 					if (scroll + max_choice < item_no) {
 						do_scroll(menu, &scroll, 1);
-						print_item(menu, items[(scroll + max_choice - 1) * 2 + 1],
-							   max_choice - 1, FALSE,
-							   (items [(scroll + max_choice - 1) * 2][0] != ':'));
+						print_item(scroll+max_choice-1,
+							   max_choice - 1, FALSE);
 					} else {
 						if (choice + 1 < max_choice)
 							choice++;
 					}
 				}
 			} else
 				choice = i;
 
-			print_item(menu, items[(scroll + choice) * 2 + 1],
-				   choice, TRUE, (items[(scroll + choice) * 2][0] != ':'));
+			print_item(scroll + choice, choice, TRUE);
 
 			print_arrows(dialog, item_no, scroll,
 				     box_y, box_x + ITEM_IDENT + 1, menu_height);
 
 			wnoutrefresh(dialog);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [7/7] kconfig: truncate too long menu lines in menuconfig
  2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
                   ` (5 preceding siblings ...)
  2005-11-21 22:40 ` [6/7] kconfig: make lxdialog/menubox.c more readable Sam Ravnborg
@ 2005-11-21 22:41 ` Sam Ravnborg
  6 siblings, 0 replies; 9+ messages in thread
From: Sam Ravnborg @ 2005-11-21 22:41 UTC (permalink / raw)
  To: Roman Zippel, linux-kernel

    kconfig: truncate too long menu lines in menuconfig
    
    menu lines wrapped over too lines when too long - truncate them.
    Also fixed a coding style issue
    
    Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index d0bf32b..2d91880 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -68,11 +68,11 @@ static void do_print_item(WINDOW * win, 
                           int selected, int hotkey)
 {
 	int j;
 	char *menu_item = malloc(menu_width + 1);
 
-	strncpy(menu_item, item, menu_width);
+	strncpy(menu_item, item, menu_width - ITEM_IDENT);
 	menu_item[menu_width] = 0;
 	j = first_alpha(menu_item, "YyNnMmHh");
 
 	/* Clear 'residue' of last item */
 	wattrset(win, menubox_attr);
@@ -182,12 +182,12 @@ static void do_scroll(WINDOW *win, int *
 int dialog_menu(const char *title, const char *prompt, int height, int width,
                 int menu_height, const char *current, int item_no,
                 const char *const *items)
 {
 	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;
+	int first_item =  0, max_choice;
 	WINDOW *dialog, *menu;
 	FILE *f;
 
 	max_choice = MIN(menu_height, item_no);
 

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [2/7] kconfig: lxdialog is now sparse clean
  2005-11-21 22:38 ` [2/7] kconfig: lxdialog is now sparse clean Sam Ravnborg
@ 2005-11-21 23:44   ` Al Viro
  0 siblings, 0 replies; 9+ messages in thread
From: Al Viro @ 2005-11-21 23:44 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Roman Zippel, linux-kernel

On Mon, Nov 21, 2005 at 11:38:53PM +0100, Sam Ravnborg wrote:
>     kconfig: lxdialog is now sparse clean
>     
>     Replacing a gcc idiom with malloc and deleting an unused global
>     variable made lxdialog sparse clean.

You do realize that this is not a gccism, right?

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-11-21 23:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-21 22:37 [PATCH 0/7] kconfig/menuconfig Sam Ravnborg
2005-11-21 22:38 ` [1/7] kconfig: fixup after Lindent Sam Ravnborg
2005-11-21 22:38 ` [2/7] kconfig: lxdialog is now sparse clean Sam Ravnborg
2005-11-21 23:44   ` Al Viro
2005-11-21 22:39 ` [3/7] kconfig: Add print_title helper in lxdialog Sam Ravnborg
2005-11-21 22:39 ` [4/7] kconfig: Left aling menu items in menuconfig Sam Ravnborg
2005-11-21 22:40 ` [5/7] kconfig: Fix indention when using menuconfig in text-onle consoles Sam Ravnborg
2005-11-21 22:40 ` [6/7] kconfig: make lxdialog/menubox.c more readable Sam Ravnborg
2005-11-21 22:41 ` [7/7] kconfig: truncate too long menu lines in menuconfig Sam Ravnborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox