Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Dec 2011 09:02:57 +0000 (UTC)
From:      Max Khon <fjoe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r228176 - head/usr.sbin/tzsetup
Message-ID:  <201112010902.pB192vNj036643@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: fjoe
Date: Thu Dec  1 09:02:57 2011
New Revision: 228176
URL: http://svn.freebsd.org/changeset/base/228176

Log:
  Sync xdialog_menu() implementation with sade.

Modified:
  head/usr.sbin/tzsetup/tzsetup.c

Modified: head/usr.sbin/tzsetup/tzsetup.c
==============================================================================
--- head/usr.sbin/tzsetup/tzsetup.c	Thu Dec  1 09:01:51 2011	(r228175)
+++ head/usr.sbin/tzsetup/tzsetup.c	Thu Dec  1 09:02:57 2011	(r228176)
@@ -73,6 +73,38 @@ typedef struct dialogMenuItem {
 } dialogMenuItem;
 
 static int
+xdialog_count_rows(const char *p)
+{
+	int rows = 0;
+
+	while ((p = strchr(p, '\n')) != NULL) {
+		p++;
+		if (*p == '\0')
+			break;
+		rows++;
+	}
+
+	return rows ? rows : 1;
+}
+
+static int
+xdialog_count_columns(const char *p)
+{
+	int len;
+	int max_len = 0;
+	const char *q;
+
+	for (; (q = strchr(p, '\n')) != NULL; p = q + 1) {
+		len = q - p;
+		max_len = MAX(max_len, len);
+	}
+
+	len = strlen(p);
+	max_len = MAX(max_len, len);
+	return max_len;
+}
+
+static int
 xdialog_menu(const char *title, const char *cprompt, int height, int width,
 	     int menu_height, int item_no, dialogMenuItem *ditems)
 {
@@ -90,6 +122,12 @@ xdialog_menu(const char *title, const ch
 		listitems[i].text = ditems[i].title;
 	}
 
+	/* calculate height */
+	if (height < 0)
+		height = xdialog_count_rows(cprompt) + menu_height + 4 + 2;
+	if (height > LINES)
+		height = LINES;
+
 	/* calculate width */
 	if (width < 0) {
 		int tag_x = 0;
@@ -103,7 +141,7 @@ xdialog_menu(const char *title, const ch
 				tag_x = MAX(tag_x, l + k + 2);
 			}
 		}
-		width = MAX(dlg_count_columns(cprompt), title != NULL ? dlg_count_columns(title) : 0);
+		width = MAX(xdialog_count_columns(cprompt), title != NULL ? xdialog_count_columns(title) : 0);
 		width = MAX(width, tag_x + 4) + 4;
 	}
 	width = MAX(width, 24);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201112010902.pB192vNj036643>