All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] mconf: make extensive use of ncurses' variables LINES and COLS.
@ 2013-05-10 12:59 Dirk Gouders
  2013-05-11  9:48 ` Yann E. MORIN
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Gouders @ 2013-05-10 12:59 UTC (permalink / raw)
  To: linux-kbuild

[-- Attachment #1: Type: text/plain, Size: 181 bytes --]

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


[-- Attachment #2: Patch --]
[-- Type: text/plain, Size: 4803 bytes --]

From 882aa6595cbb2683a43bf24f1b9741263641ec9b Mon Sep 17 00:00:00 2001
From: Dirk Gouders <dirk@gouders.net>
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@gouders.net>
---
 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


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

* Re: [RFC] mconf: make extensive use of ncurses' variables LINES and COLS.
  2013-05-10 12:59 [RFC] mconf: make extensive use of ncurses' variables LINES and COLS Dirk Gouders
@ 2013-05-11  9:48 ` Yann E. MORIN
  2013-05-11 11:20   ` Dirk Gouders
  0 siblings, 1 reply; 11+ messages in thread
From: Yann E. MORIN @ 2013-05-11  9:48 UTC (permalink / raw)
  To: Dirk Gouders; +Cc: linux-kbuild

Dirk, All,

On 2013-05-10 14:59 +0200, Dirk Gouders spake thusly:
> From 882aa6595cbb2683a43bf24f1b9741263641ec9b Mon Sep 17 00:00:00 2001
> From: Dirk Gouders <dirk@gouders.net>
> 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.

If we read the manpage strictly, the LINES and COLS are set by initsrc,
and nothing else updates them. So the manpage does not state what
happens when the terminal is resized. The only mention of 'COLS' in the
man page is this paragraph:

    ---8<---
    The integer variables LINES and COLS are defined in <curses.h>
    and will be filled in by initscr with the size of the screen.
    ---8<---

After looking at the code of ncurses, the LINES and COLS are also
updated upon a resize. But as this is not documented, I think we should
*not* rely on that behaviour.

I believe we should use the functions, not the variables.

Also note that the getmaxyx() familly are not functions, they are macros.

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

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

* Re: [RFC] mconf: make extensive use of ncurses' variables LINES and COLS.
  2013-05-11  9:48 ` Yann E. MORIN
@ 2013-05-11 11:20   ` Dirk Gouders
  2013-05-11 11:27     ` Dirk Gouders
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Gouders @ 2013-05-11 11:20 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: linux-kbuild

[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]

"Yann E. MORIN" <yann.morin.1998@free.fr> writes:

> If we read the manpage strictly, the LINES and COLS are set by initsrc,
> and nothing else updates them. So the manpage does not state what
> happens when the terminal is resized. The only mention of 'COLS' in the
> man page is this paragraph:
>
>     ---8<---
>     The integer variables LINES and COLS are defined in <curses.h>
>     and will be filled in by initscr with the size of the screen.
>     ---8<---
>
> After looking at the code of ncurses, the LINES and COLS are also
> updated upon a resize. But as this is not documented, I think we should
> *not* rely on that behaviour.
>
> I believe we should use the functions, not the variables.
>
> Also note that the getmaxyx() familly are not functions, they are macros.

Thank you for your review and comments.

I changed the patch so that the variables are used (or not used)
strictly according to the documentation.  Of course, the change of
init_dialog() is not really necessary to comply with the documentation;
I will send a v3 if it shold remain unchanged.

Dirk


[-- Attachment #2: Patchv2 --]
[-- Type: text/plain, Size: 3956 bytes --]

From 178b894e8129ae7b199c5495091dafc89c203b00 Mon Sep 17 00:00:00 2001
From: Dirk Gouders <dirk@gouders.net>
Date: Sat, 11 May 2013 12:46:12 +0200
Subject: [PATCH v2] mconf: Use ncurses' variables LINES and COLS according to the
 documentation.

According to the documentation [1], LINES and COLS are initialized by
initscr().  So, use these variables in init_dialog().

The documentation does not say anything about the behavior when
windows are resized.  Do not rely on the current implementation
of ncurses that updates these variables on resize, but use the propper
function calls to get window dimensions.

[1] ncurses(3X)
---
 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 ++--
 6 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index a2eb80f..af8e8a6 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -140,8 +140,8 @@ do_resize:
 	max_choice = MIN(list_height, item_count());
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 21404a0..7a8c6b3e 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -62,8 +62,8 @@ do_resize:
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index 48d382e..e068251 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -203,8 +203,8 @@ do_resize:
 	max_choice = MIN(menu_height, item_count());
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index a48bb93..ad6e199 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -98,8 +98,8 @@ do_resize:
 			width = 0;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index a0e97c2..9b528a2 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..67b7203 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -51,8 +51,8 @@ do_resize:
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
-- 
1.8.2.1


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

* Re: [RFC] mconf: make extensive use of ncurses' variables LINES and COLS.
  2013-05-11 11:20   ` Dirk Gouders
@ 2013-05-11 11:27     ` Dirk Gouders
  2013-05-11 20:58       ` Yann E. MORIN
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Gouders @ 2013-05-11 11:27 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: linux-kbuild

[-- Attachment #1: Type: text/plain, Size: 1215 bytes --]

Dirk Gouders <dirk@gouders.net> writes:

> "Yann E. MORIN" <yann.morin.1998@free.fr> writes:
>
>> If we read the manpage strictly, the LINES and COLS are set by initsrc,
>> and nothing else updates them. So the manpage does not state what
>> happens when the terminal is resized. The only mention of 'COLS' in the
>> man page is this paragraph:
>>
>>     ---8<---
>>     The integer variables LINES and COLS are defined in <curses.h>
>>     and will be filled in by initscr with the size of the screen.
>>     ---8<---
>>
>> After looking at the code of ncurses, the LINES and COLS are also
>> updated upon a resize. But as this is not documented, I think we should
>> *not* rely on that behaviour.
>>
>> I believe we should use the functions, not the variables.
>>
>> Also note that the getmaxyx() familly are not functions, they are macros.
>
> Thank you for your review and comments.
>
> I changed the patch so that the variables are used (or not used)
> strictly according to the documentation.  Of course, the change of
> init_dialog() is not really necessary to comply with the documentation;
> I will send a v3 if it shold remain unchanged.

I'm sorry, I forgot to insert a Signed-off-by line, again.

Dirk


[-- Attachment #2: Patchv3 --]
[-- Type: text/plain, Size: 4004 bytes --]

From a8f5ff2e666d467c84ece16e1fe783ac89ceaa60 Mon Sep 17 00:00:00 2001
From: Dirk Gouders <dirk@gouders.net>
Date: Sat, 11 May 2013 12:46:12 +0200
Subject: [PATCH v3] mconf: Use ncurses' variables LINES and COLS according to the
 documentation.

According to the documentation [1], LINES and COLS are initialized by
initscr().  So, use these variables in init_dialog().

The documentation does not say anything about the behavior when
windows are resized.  Do not rely on the current implementation
of ncurses that updates these variables on resize, but use the propper
function calls to get window dimensions.

[1] ncurses(3X)

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 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 ++--
 6 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index a2eb80f..af8e8a6 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -140,8 +140,8 @@ do_resize:
 	max_choice = MIN(list_height, item_count());
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 21404a0..7a8c6b3e 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -62,8 +62,8 @@ do_resize:
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index 48d382e..e068251 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -203,8 +203,8 @@ do_resize:
 	max_choice = MIN(menu_height, item_count());
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index a48bb93..ad6e199 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -98,8 +98,8 @@ do_resize:
 			width = 0;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index a0e97c2..9b528a2 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..67b7203 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -51,8 +51,8 @@ do_resize:
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
-- 
1.8.2.1


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

* Re: [RFC] mconf: make extensive use of ncurses' variables LINES and COLS.
  2013-05-11 11:27     ` Dirk Gouders
@ 2013-05-11 20:58       ` Yann E. MORIN
  2013-05-12 10:30         ` [PATCH v4] mconf: use function calls instead " Dirk Gouders
  0 siblings, 1 reply; 11+ messages in thread
From: Yann E. MORIN @ 2013-05-11 20:58 UTC (permalink / raw)
  To: Dirk Gouders; +Cc: linux-kbuild

Dirk, All,

On 2013-05-11 13:27 +0200, Dirk Gouders spake thusly:
> Dirk Gouders <dirk@gouders.net> writes:
[--SNIP--]
> From a8f5ff2e666d467c84ece16e1fe783ac89ceaa60 Mon Sep 17 00:00:00 2001
> From: Dirk Gouders <dirk@gouders.net>
> Date: Sat, 11 May 2013 12:46:12 +0200
> Subject: [PATCH v3] mconf: Use ncurses' variables LINES and COLS according to the
>  documentation.
> 
> According to the documentation [1], LINES and COLS are initialized by
> initscr().  So, use these variables in init_dialog().
> 
> The documentation does not say anything about the behavior when
> windows are resized.  Do not rely on the current implementation
> of ncurses that updates these variables on resize, but use the propper
> function calls to get window dimensions.

You missed three occurences of COLS in:
    scripts/kconfig/lxdialog/util.c:dialog_clear


> diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
> index a0e97c2..9b528a2 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) {

I know that COLS and LINES are correct right here since we just called
initscr, but for the sake of consistency, I think we'd better use the
functions here, too.

Also, it's a pain to apply your patches, since 'git am' will use the
entire body of the mail as the commit message.

I know you have issues using 'git send-email', but could you please at
least add a scissor-line as the last line of your email body, which will
make 'git am' ignore whatever is above that line (and that line itself):
    ---8<---        <- This is a scissor-line

And please do not attach the patch, add it in the body of the mail.
Use 'git format-patch' to prepare your patch(es), and just send the
resulting file(s) as the mail (hopefully, gnus is able to use an
existing file as the mail to send).

Otherwise, LGTM.

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

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

* [PATCH v4] mconf: use function calls instead of ncurses' variables LINES and COLS
  2013-05-11 20:58       ` Yann E. MORIN
@ 2013-05-12 10:30         ` Dirk Gouders
  2013-05-12 12:55           ` Yann E. MORIN
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Gouders @ 2013-05-12 10:30 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: linux-kbuild, Dirk Gouders

According to the documentation [1], LINES and COLS are initialized by
initscr(); it does not say anything about the behavior when windows are
resized.

Do not rely on the current implementation of ncurses that updates
these variables on resize, but use the propper function calls to get
window dimensions.

init_dialog() could make use of the variables, but for the sake of
consistency we do not change it's current use of the macro getmaxyx().

[1] ncurses(3X)

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 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      | 13 +++++++++----
 scripts/kconfig/lxdialog/yesno.c     |  4 ++--
 6 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index a2eb80f..af8e8a6 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -140,8 +140,8 @@ do_resize:
 	max_choice = MIN(list_height, item_count());
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 21404a0..7a8c6b3e 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -62,8 +62,8 @@ do_resize:
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index 48d382e..e068251 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -203,8 +203,8 @@ do_resize:
 	max_choice = MIN(menu_height, item_count());
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index a48bb93..ad6e199 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -98,8 +98,8 @@ do_resize:
 			width = 0;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index a0e97c2..25329c1 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -254,7 +254,12 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr)
 
 void dialog_clear(void)
 {
-	attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
+	int lines, columns;
+
+	lines = getmaxy(stdscr);
+	columns = getmaxx(stdscr);
+
+	attr_clear(stdscr, lines, columns, dlg.screen.atr);
 	/* Display background title if it exists ... - SLH */
 	if (dlg.backtitle != NULL) {
 		int i, len = 0, skip = 0;
@@ -269,10 +274,10 @@ void dialog_clear(void)
 		}
 
 		wmove(stdscr, 1, 1);
-		if (len > COLS - 2) {
+		if (len > columns - 2) {
 			const char *ellipsis = "[...] ";
 			waddstr(stdscr, ellipsis);
-			skip = len - (COLS - 2 - strlen(ellipsis));
+			skip = len - (columns - 2 - strlen(ellipsis));
 		}
 
 		for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
@@ -298,7 +303,7 @@ void dialog_clear(void)
 				skip--;
 		}
 
-		for (i = len + 1; i < COLS - 1; i++)
+		for (i = len + 1; i < columns - 1; i++)
 			waddch(stdscr, ACS_HLINE);
 	}
 	wnoutrefresh(stdscr);
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c
index 4e6e809..67b7203 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -51,8 +51,8 @@ do_resize:
 		return -ERRDISPLAYTOOSMALL;
 
 	/* center dialog box on screen */
-	x = (COLS - width) / 2;
-	y = (LINES - height) / 2;
+	x = (getmaxx(stdscr) - width) / 2;
+	y = (getmaxy(stdscr) - height) / 2;
 
 	draw_shadow(stdscr, y, x, height, width);
 
-- 
1.8.2.1


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

* Re: [PATCH v4] mconf: use function calls instead of ncurses' variables LINES and COLS
  2013-05-12 10:30         ` [PATCH v4] mconf: use function calls instead " Dirk Gouders
@ 2013-05-12 12:55           ` Yann E. MORIN
  2013-05-12 13:41             ` Dirk Gouders
  0 siblings, 1 reply; 11+ messages in thread
From: Yann E. MORIN @ 2013-05-12 12:55 UTC (permalink / raw)
  To: Dirk Gouders; +Cc: linux-kbuild

Dirk, All,

On 2013-05-12 12:30 +0200, Dirk Gouders spake thusly:
> According to the documentation [1], LINES and COLS are initialized by
> initscr(); it does not say anything about the behavior when windows are
> resized.
> 
> Do not rely on the current implementation of ncurses that updates
> these variables on resize, but use the propper function calls to get
> window dimensions.
> 
> init_dialog() could make use of the variables, but for the sake of
> consistency we do not change it's current use of the macro getmaxyx().
> 
> [1] ncurses(3X)
> 
> Signed-off-by: Dirk Gouders <dirk@gouders.net>

I've queued it now. Thank you!

Regards,
Yann E. MORIN.

PS. That new mail was correctly formatted, now! Thanks!
YEM.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

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

* Re: [PATCH v4] mconf: use function calls instead of ncurses' variables LINES and COLS
  2013-05-12 12:55           ` Yann E. MORIN
@ 2013-05-12 13:41             ` Dirk Gouders
  2013-05-12 14:22               ` Yann E. MORIN
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Gouders @ 2013-05-12 13:41 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: linux-kbuild

"Yann E. MORIN" <yann.morin.1998@free.fr> writes:

> I've queued it now. Thank you!
>
> Regards,
> Yann E. MORIN.
>
> PS. That new mail was correctly formatted, now! Thanks!
> YEM.

Thank you, Yann.  Especially for your patience with me, wasting your
time with sending misformatted patches and getting rather simple changes
right.

Dirk

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

* Re: [PATCH v4] mconf: use function calls instead of ncurses' variables LINES and COLS
  2013-05-12 13:41             ` Dirk Gouders
@ 2013-05-12 14:22               ` Yann E. MORIN
  2013-05-13  9:23                 ` [PATCH] nconf: " Dirk Gouders
  0 siblings, 1 reply; 11+ messages in thread
From: Yann E. MORIN @ 2013-05-12 14:22 UTC (permalink / raw)
  To: Dirk Gouders; +Cc: linux-kbuild

Dirk, All,

On 2013-05-12 15:41 +0200, Dirk Gouders spake thusly:
> "Yann E. MORIN" <yann.morin.1998@free.fr> writes:
> 
> > I've queued it now. Thank you!
> >
> > Regards,
> > Yann E. MORIN.
> >
> > PS. That new mail was correctly formatted, now! Thanks!
> > YEM.
> 
> Thank you, Yann.  Especially for your patience with me, wasting your
> time with sending misformatted patches and getting rather simple changes
> right.

No problem! Thanks for staying with us during the iterations.

Now, since you seem to be interested in some cleanup and polishing, I've
noticed that the nconf frontend also uses COLS and LINES, so if you've
got some spare time... ;-)

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

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

* [PATCH] nconf: use function calls instead of ncurses' variables LINES and COLS
  2013-05-12 14:22               ` Yann E. MORIN
@ 2013-05-13  9:23                 ` Dirk Gouders
  2013-05-13 16:39                   ` Yann E. MORIN
  0 siblings, 1 reply; 11+ messages in thread
From: Dirk Gouders @ 2013-05-13  9:23 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: linux-kbuild

According to the documentation [1], LINES and COLS are initialized by
initscr(); it does not say anything about the behavior when windows are
resized.

Do not rely on the current implementation of ncurses that updates
these variables on resize, but use the propper function calls or macros
to get window dimensions.

The use of the variables in main() was OK, but for the sake of
consistency it was modified to use the macro getmaxyx().

[1] ncurses(3X)

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 scripts/kconfig/nconf.c     | 23 ++++++++++++++++-------
 scripts/kconfig/nconf.gui.c | 20 +++++++++++---------
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index dbf31ed..55fe5a6 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -365,15 +365,16 @@ static void print_function_line(void)
 	int i;
 	int offset = 1;
 	const int skip = 1;
+	int lines = getmaxy(stdscr);
 
 	for (i = 0; i < function_keys_num; i++) {
 		(void) wattrset(main_window, attributes[FUNCTION_HIGHLIGHT]);
-		mvwprintw(main_window, LINES-3, offset,
+		mvwprintw(main_window, lines-3, offset,
 				"%s",
 				function_keys[i].key_str);
 		(void) wattrset(main_window, attributes[FUNCTION_TEXT]);
 		offset += strlen(function_keys[i].key_str);
-		mvwprintw(main_window, LINES-3,
+		mvwprintw(main_window, lines-3,
 				offset, "%s",
 				function_keys[i].func);
 		offset += strlen(function_keys[i].func) + skip;
@@ -954,7 +955,7 @@ static void show_menu(const char *prompt, const char *instructions,
 
 	clear();
 	(void) wattrset(main_window, attributes[NORMAL]);
-	print_in_middle(stdscr, 1, 0, COLS,
+	print_in_middle(stdscr, 1, 0, getmaxx(stdscr),
 			menu_backtitle,
 			attributes[MAIN_HEADING]);
 
@@ -1455,14 +1456,19 @@ static void conf_save(void)
 
 void setup_windows(void)
 {
+	int lines;
+	int columns;
+
+	getmaxyx(stdscr, lines, columns);
+
 	if (main_window != NULL)
 		delwin(main_window);
 
 	/* set up the menu and menu window */
-	main_window = newwin(LINES-2, COLS-2, 2, 1);
+	main_window = newwin(lines-2, columns-2, 2, 1);
 	keypad(main_window, TRUE);
-	mwin_max_lines = LINES-7;
-	mwin_max_cols = COLS-6;
+	mwin_max_lines = lines-7;
+	mwin_max_cols = columns-6;
 
 	/* panels order is from bottom to top */
 	new_panel(main_window);
@@ -1470,6 +1476,8 @@ void setup_windows(void)
 
 int main(int ac, char **av)
 {
+	int lines;
+	int columns;
 	char *mode;
 
 	setlocale(LC_ALL, "");
@@ -1495,7 +1503,8 @@ int main(int ac, char **av)
 	keypad(stdscr, TRUE);
 	curs_set(0);
 
-	if (COLS < 75 || LINES < 20) {
+	getmaxyx(stdscr, lines, columns);
+	if (columns < 75 || lines < 20) {
 		endwin();
 		printf("Your terminal should have at "
 			"least 20 lines and 75 columns\n");
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index 9f8c44e..8275f0e5 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -276,8 +276,8 @@ int btn_dialog(WINDOW *main_window, const char *msg, int btn_num, ...)
 
 	total_width = max(msg_width, btns_width);
 	/* place dialog in middle of screen */
-	y = (LINES-(msg_lines+4))/2;
-	x = (COLS-(total_width+4))/2;
+	y = (getmaxy(stdscr)-(msg_lines+4))/2;
+	x = (getmaxx(stdscr)-(total_width+4))/2;
 
 
 	/* create the windows */
@@ -387,8 +387,8 @@ int dialog_inputbox(WINDOW *main_window,
 		prompt_width = max(prompt_width, strlen(title));
 
 	/* place dialog in middle of screen */
-	y = (LINES-(prompt_lines+4))/2;
-	x = (COLS-(prompt_width+4))/2;
+	y = (getmaxy(stdscr)-(prompt_lines+4))/2;
+	x = (getmaxx(stdscr)-(prompt_width+4))/2;
 
 	strncpy(result, init, *result_len);
 
@@ -545,7 +545,7 @@ void show_scroll_win(WINDOW *main_window,
 {
 	int res;
 	int total_lines = get_line_no(text);
-	int x, y;
+	int x, y, lines, columns;
 	int start_x = 0, start_y = 0;
 	int text_lines = 0, text_cols = 0;
 	int total_cols = 0;
@@ -556,6 +556,8 @@ void show_scroll_win(WINDOW *main_window,
 	WINDOW *pad;
 	PANEL *panel;
 
+	getmaxyx(stdscr, lines, columns);
+
 	/* find the widest line of msg: */
 	total_lines = get_line_no(text);
 	for (i = 0; i < total_lines; i++) {
@@ -569,14 +571,14 @@ void show_scroll_win(WINDOW *main_window,
 	(void) wattrset(pad, attributes[SCROLLWIN_TEXT]);
 	fill_window(pad, text);
 
-	win_lines = min(total_lines+4, LINES-2);
-	win_cols = min(total_cols+2, COLS-2);
+	win_lines = min(total_lines+4, lines-2);
+	win_cols = min(total_cols+2, columns-2);
 	text_lines = max(win_lines-4, 0);
 	text_cols = max(win_cols-2, 0);
 
 	/* place window in middle of screen */
-	y = (LINES-win_lines)/2;
-	x = (COLS-win_cols)/2;
+	y = (lines-win_lines)/2;
+	x = (columns-win_cols)/2;
 
 	win = newwin(win_lines, win_cols, y, x);
 	keypad(win, TRUE);
-- 
1.8.2.1


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

* Re: [PATCH] nconf: use function calls instead of ncurses' variables LINES and COLS
  2013-05-13  9:23                 ` [PATCH] nconf: " Dirk Gouders
@ 2013-05-13 16:39                   ` Yann E. MORIN
  0 siblings, 0 replies; 11+ messages in thread
From: Yann E. MORIN @ 2013-05-13 16:39 UTC (permalink / raw)
  To: Dirk Gouders; +Cc: linux-kbuild

Dirk, All,

On 2013-05-13 11:23 +0200, Dirk Gouders spake thusly:
> According to the documentation [1], LINES and COLS are initialized by
> initscr(); it does not say anything about the behavior when windows are
> resized.
> 
> Do not rely on the current implementation of ncurses that updates
> these variables on resize, but use the propper function calls or macros
> to get window dimensions.
> 
> The use of the variables in main() was OK, but for the sake of
> consistency it was modified to use the macro getmaxyx().
> 
> [1] ncurses(3X)
> 
> Signed-off-by: Dirk Gouders <dirk@gouders.net>

Queued in my tree, with two very, very light changes:

> diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
> index dbf31ed..55fe5a6 100644
> --- a/scripts/kconfig/nconf.c
> +++ b/scripts/kconfig/nconf.c
[--SMIP--]
> @@ -1455,14 +1456,19 @@ static void conf_save(void)
>  
>  void setup_windows(void)
>  {
> +	int lines;
> +	int columns;

I've chamged this to be a single line:
    int lines, columns;

[--SNIP--]
> @@ -1470,6 +1476,8 @@ void setup_windows(void)
>  
>  int main(int ac, char **av)
>  {
> +	int lines;
> +	int columns;

Ditto.

Thank you!

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

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

end of thread, other threads:[~2013-05-13 16:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-10 12:59 [RFC] mconf: make extensive use of ncurses' variables LINES and COLS Dirk Gouders
2013-05-11  9:48 ` Yann E. MORIN
2013-05-11 11:20   ` Dirk Gouders
2013-05-11 11:27     ` Dirk Gouders
2013-05-11 20:58       ` Yann E. MORIN
2013-05-12 10:30         ` [PATCH v4] mconf: use function calls instead " Dirk Gouders
2013-05-12 12:55           ` Yann E. MORIN
2013-05-12 13:41             ` Dirk Gouders
2013-05-12 14:22               ` Yann E. MORIN
2013-05-13  9:23                 ` [PATCH] nconf: " Dirk Gouders
2013-05-13 16:39                   ` Yann E. MORIN

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.