[RFC] mconf: make extensive use of ncurses' variables LINES and COLS.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This (again) is a rather cosmetic change that I could not resist,
while checking how to make print_autowrap() handle height-conflicts
and also reading ncurses documentation.

Dirk

>From 882aa6595cbb2683a43bf24f1b9741263641ec9b Mon Sep 17 00:00:00 2001
From: Dirk Gouders <dirk@xxxxxxxxxxx>
Date: Fri, 10 May 2013 12:26:23 +0200
Subject: [PATCH] mconf: make extensive use of ncurses' variables LINES and
 COLS.

The manual page of ncurses states that the variables LINES and COLS
are initialized by initscr().  So, in init_dialog() there is no need
to use local variables `height' and `width' and initialize them using
function calls.

Further, in other functions' `do_resize' cases getmaxx(stdscr)/COLS and
getmaxy(stdscr)/LINES were used in mixture; the function calls were
replaced with the respective variables.

Finally, to be consequent, show_help() used getmaxx(stdscr) which has
been replaced by COLS.

Signed-off-by: Dirk Gouders <dirk@xxxxxxxxxxx>
---
 scripts/kconfig/lxdialog/checklist.c | 4 ++--
 scripts/kconfig/lxdialog/inputbox.c  | 4 ++--
 scripts/kconfig/lxdialog/menubox.c   | 4 ++--
 scripts/kconfig/lxdialog/textbox.c   | 4 +++-
 scripts/kconfig/lxdialog/util.c      | 5 +----
 scripts/kconfig/lxdialog/yesno.c     | 4 ++--
 scripts/kconfig/mconf.c              | 2 +-
 7 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index a2eb80f..fd3f5c5 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -132,9 +132,9 @@ int dialog_checklist(const char *title, const char *prompt, int height,
 	}
 
 do_resize:
-	if (getmaxy(stdscr) < (height + 6))
+	if (LINES < (height + 6))
 		return -ERRDISPLAYTOOSMALL;
-	if (getmaxx(stdscr) < (width + 6))
+	if (COLS < (width + 6))
 		return -ERRDISPLAYTOOSMALL;
 
 	max_choice = MIN(list_height, item_count());
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 21404a0..bc5d17d 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -56,9 +56,9 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
 		strcpy(instr, init);
 
 do_resize:
-	if (getmaxy(stdscr) <= (height - 2))
+	if (LINES <= (height - 2))
 		return -ERRDISPLAYTOOSMALL;
-	if (getmaxx(stdscr) <= (width - 2))
+	if (COLS <= (width - 2))
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index 48d382e..a3ad1b5 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -191,8 +191,8 @@ int dialog_menu(const char *title, const char *prompt,
 	WINDOW *dialog, *menu;
 
 do_resize:
-	height = getmaxy(stdscr);
-	width = getmaxx(stdscr);
+	height = LINES;
+	width = COLS;
 	if (height < 15 || width < 65)
 		return -ERRDISPLAYTOOSMALL;
 
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index a48bb93..b6a004d 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -79,7 +79,9 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,
 		hscroll = *_hscroll;
 
 do_resize:
-	getmaxyx(stdscr, height, width);
+	height = LINES;
+	width = COLS;
+
 	if (height < 8 || width < 8)
 		return -ERRDISPLAYTOOSMALL;
 	if (initial_height != 0)
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index cfee00c..8ea7ef2 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -309,15 +309,12 @@ void dialog_clear(void)
  */
 int init_dialog(const char *backtitle)
 {
-	int height, width;
-
 	initscr();		/* Init curses */
 
 	/* Get current cursor position for signal handler in mconf.c */
 	getyx(stdscr, saved_y, saved_x);
 
-	getmaxyx(stdscr, height, width);
-	if (height < 19 || width < 80) {
+	if (LINES < 19 || COLS < 80) {
 		endwin();
 		return -ERRDISPLAYTOOSMALL;
 	}
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c
index 4e6e809..e3e9be8 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -45,9 +45,9 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
 	WINDOW *dialog;
 
 do_resize:
-	if (getmaxy(stdscr) < (height + 4))
+	if (LINES < (height + 4))
 		return -ERRDISPLAYTOOSMALL;
-	if (getmaxx(stdscr) < (width + 4))
+	if (COLS < (width + 4))
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index a258b8c..9a30a85 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -787,7 +787,7 @@ static void show_help(struct menu *menu)
 {
 	struct gstr help = str_new();
 
-	help.max_width = getmaxx(stdscr) - 10;
+	help.max_width = COLS - 10;
 	menu_get_ext_help(menu, &help);
 
 	show_helptext(_(menu_get_prompt(menu)), str_get(&help));
-- 
1.8.2.1


[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux