From 132e06f1369214db3e5e7996ab5d10c9bc17f004 Mon Sep 17 00:00:00 2001 From: Laurent MONIN Date: Thu, 26 Apr 2007 15:00:04 +0200 Subject: [PATCH] Enhance version and features display. Wrap on spaces when features are sent to console using -version, and let Info dialog do the job in interactive mode. --- src/main/version.c | 65 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/src/main/version.c b/src/main/version.c index c4b33ebf..6c3d6e1f 100644 --- a/src/main/version.c +++ b/src/main/version.c @@ -48,22 +48,42 @@ static void add_modules_to_string(struct string *string, struct terminal *term) { struct module *module; - int i, last_split = 0; - unsigned char *last_newline = strrchr(string->source, '\n'); - - if (last_newline) - last_split = last_newline - string->source; + int i; foreach_module (module, builtin_modules, i) { if (i > 0) add_to_string(string, ", "); - if (string->length - last_split > 70) { - add_char_to_string(string, '\n'); - last_split = string->length; - } add_module_to_string(string, module, term); } } +/* Wrap string on spaces starting at position @start_at, trying + * to keep lines undex @maxlen length */ +static void +wrap_string(struct string *string, int start_at, int maxlen) +{ + unsigned char *pos, *start_pos; + unsigned char *last_pos = NULL; + + assert(string && string->source && start_at < string->length); + if_assert_failed return; + + if (maxlen <= 0) return; + + pos = start_pos = &string->source[start_at]; + while ((pos = strchr(pos, ' '))) { + int len = pos - start_pos; + + if (len < maxlen) { + last_pos = pos; + pos++; + } else { + if (last_pos) *last_pos = '\n'; + pos = start_pos = last_pos + 1; + } + if (!*pos) break; + } +} + /* @more will add more information especially for info box. */ unsigned char * get_dyn_full_version(struct terminal *term, int more) @@ -74,17 +94,19 @@ get_dyn_full_version(struct terminal *term, int more) if (!init_string(&string)) return NULL; add_format_to_string(&string, "ELinks %s", VERSION_STRING); - if (*build_id) + if (*build_id) { + if (more) add_to_string(&string, "\n"); add_format_to_string(&string, " (%s)", build_id); + } + + if (more) add_to_string(&string, "\n"); + + add_format_to_string(&string, _(" (built on %s %s)", term), + build_date, build_time); + if (more) { - add_to_string(&string, "\n"); - add_format_to_string(&string, _("Built on %s %s", term), - build_date, build_time); add_to_string(&string, "\n\n"); add_to_string(&string, _("Text WWW browser", term)); - } else { - add_format_to_string(&string, _(" (built on %s %s)", term), - build_date, build_time); } string_concat(&string, @@ -128,6 +150,17 @@ get_dyn_full_version(struct terminal *term, int more) add_modules_to_string(&string, term); + if (!more) { + int start_at = 0; + unsigned char *last_newline = strrchr(string.source, '\n'); + + if (last_newline) { + start_at = last_newline - string.source + 1; + } + + wrap_string(&string, start_at, 72); + } + return string.source; }