From 3a40734373e887c1577eb7be0ad9aff92be6dafe Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Sat, 5 Feb 2005 13:03:11 +0000 Subject: [PATCH] * util.h (msglen): Converted from a function to a procedure. * util.c (msglen): Changed variable names and did a speedup. * hotlist.c (add_new_entry_input): Using new msglen function. * hotlist.c (add_new_group_input): Likewise. * wtools.c (query_dialog): Likewise. * wtools.c (fg_input_dialog_help): Likewise. --- src/ChangeLog | 9 +++++++++ src/hotlist.c | 16 ++++++++++------ src/util.c | 29 ++++++++++++++++------------- src/util.h | 2 +- src/wtools.c | 8 +++++--- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6bf9d35f7..2a7aafd56 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2005-02-05 Roland Illig + + * util.h (msglen): Converted from a function to a procedure. + * util.c (msglen): Changed variable names and did a speedup. + * hotlist.c (add_new_entry_input): Using new msglen function. + * hotlist.c (add_new_group_input): Likewise. + * wtools.c (query_dialog): Likewise. + * wtools.c (fg_input_dialog_help): Likewise. + 2005-02-02 Andrew V. Samoilov * find.c: Implement non-recursive 'Find file' feature. diff --git a/src/hotlist.c b/src/hotlist.c index 5ce460631..ebff7496a 100644 --- a/src/hotlist.c +++ b/src/hotlist.c @@ -852,16 +852,19 @@ add_new_entry_input (const char *header, const char *text1, const char *text2, 0, 0, "label-lbl" }, NULL_QuickWidget }; - size_t len; + int len; int i; int lines1, lines2; + int cols1, cols2; #ifdef ENABLE_NLS static int i18n_flag = 0; #endif /* ENABLE_NLS */ - len = max (strlen (header), (size_t) msglen (text1, &lines1)); - len = max (len, (size_t) msglen (text2, &lines2)) + 4; + msglen(text1, &lines1, &cols1); + msglen(text2, &lines2, &cols2); + len = max ((int) strlen (header), cols1); + len = max (len, cols2) + 4; len = max (len, 64); #ifdef ENABLE_NLS @@ -949,13 +952,14 @@ add_new_group_input (const char *header, const char *label, char **result) quick_widgets variable above */ int len; int i; - int lines; + int lines, cols; #ifdef ENABLE_NLS static int i18n_flag = 0; #endif /* ENABLE_NLS */ - - len = max (strlen (header), (size_t) msglen (label, &lines)) + 4; + + msglen (label, &lines, &cols); + len = max ((int) strlen (header), cols) + 4; len = max (len, 64); #ifdef ENABLE_NLS diff --git a/src/util.c b/src/util.c index 53fbd5b60..884ab9877 100644 --- a/src/util.c +++ b/src/util.c @@ -97,23 +97,26 @@ is_printable (int c) #endif /* !HAVE_CHARSET */ } -/* Returns the message dimensions (lines and columns) */ -int msglen (const char *text, int *lines) +/* Calculates the message dimensions (lines and columns) */ +void msglen (const char *text, int *lines, int *columns) { - int max = 0; - int line_len = 0; - - for (*lines = 1;*text; text++){ - if (*text == '\n'){ - line_len = 0; - (*lines)++; + int nlines = 1; /* even the empty string takes one line */ + int ncolumns = 0; + int colindex = 0; + + for (; *text != '\0'; text++) { + if (*text == '\n') { + nlines++; + colindex = 0; } else { - line_len++; - if (line_len > max) - max = line_len; + colindex++; + if (colindex > ncolumns) + ncolumns = colindex; } } - return max; + + *lines = nlines; + *columns = ncolumns; } /* diff --git a/src/util.h b/src/util.h index 474169b61..5b91d97e0 100644 --- a/src/util.h +++ b/src/util.h @@ -9,7 +9,7 @@ extern const char *cstrcasestr (const char *haystack, const char *needle); void str_replace(char *s, char from, char to); int is_printable (int c); -int msglen (const char *text, int *lines); +void msglen (const char *text, /*@out@*/ int *lines, /*@out@*/ int *columns); /* Copy from s to d, and trim the beginning if necessary, and prepend * "..." in this case. The destination string can have at most len diff --git a/src/wtools.c b/src/wtools.c index ea56508e3..72aa6de41 100644 --- a/src/wtools.c +++ b/src/wtools.c @@ -131,7 +131,8 @@ query_dialog (const char *header, const char *text, int flags, int count, ...) } /* count coordinates */ - cols = 6 + max (win_len, max ((int) strlen (header), msglen (text, &lines))); + msglen (text, &lines, &cols); + cols = 6 + max (win_len, max ((int) strlen (header), cols)); lines += 4 + (count > 0 ? 2 : 0); xpos = COLS / 2 - cols / 2; ypos = LINES / 3 - (lines - 3) / 2; @@ -446,7 +447,7 @@ fg_input_dialog_help (const char *header, const char *text, const char *help, int len; int i; - int lines; + int lines, cols; int ret; char *my_str; char histname[64] = "inp|"; @@ -457,7 +458,8 @@ fg_input_dialog_help (const char *header, const char *text, const char *help, g_strlcpy (histname + 3, header, 61); quick_widgets[2].histname = histname; - len = max ((int) strlen (header), msglen (text, &lines)) + 4; + msglen (text, &lines, &cols); + len = max ((int) strlen (header), cols) + 4; len = max (len, 64); /* The special value of def_text is used to identify password boxes