[prev in list] [next in list] [prev in thread] [next in thread]
List: grub-devel
Subject: Re: lib/arg.c: dynamic newline in help
From: Carles Pina i Estany <carles () pina ! cat>
Date: 2009-12-27 18:38:51
Message-ID: 20091227183851.GA4879 () pina ! cat
[Download RAW message or body]
Hi,
Following a suggestion of Vladimir, now it uses GRUB_TERMINAL_WIDTH if
it's not compiling in util way.
--
Carles Pina i Estany
http://pinux.info
["dynamic_split03.patch" (text/x-diff)]
=== modified file 'ChangeLog'
--- ChangeLog 2009-12-26 23:43:21 +0000
+++ ChangeLog 2009-12-27 17:06:29 +0000
@@ -1,5 +1,10 @@
2009-12-27 Carles Pina i Estany <carles@pina.cat>
+ * lib/arg.c (AVAILABLE_CHARS_LINE): New macro.
+ (grub_arg_show_help): Cut the help string dynamically.
+
+2009-12-27 Carles Pina i Estany <carles@pina.cat>
+
* normal/cmdline.c (grub_cmdline_get): Print a space after prompt.
* normal/main.c (grub_normal_read_line): Remove a space from the
default prompt.
=== modified file 'lib/arg.c'
--- lib/arg.c 2009-12-25 23:50:59 +0000
+++ lib/arg.c 2009-12-27 18:36:58 +0000
@@ -144,7 +144,48 @@ grub_arg_show_help (grub_extcmd_t cmd)
}
}
- const char *doc = _(opt->doc);
+ char *doc_orig = grub_strdup (_(opt->doc));
+ char *doc = doc_orig;
+
+ char* next_newline = doc;
+ char* line;
+ char* doc_last = doc + grub_strlen (doc);
+ #ifndef GRUB_UTIL
+ const int terminal_width = GRUB_TERM_WIDTH;
+ #else
+ const int terminal_width = 80;
+ #endif
+
+ const int chars_line = terminal_width - 25;
+
+ while (next_newline + chars_line < doc_last)
+ {
+ line = next_newline;
+
+ /* Move forward. */
+ while (*next_newline != '\n' &&
+ next_newline - line < chars_line &&
+ *next_newline != '\0')
+ {
+ next_newline++;
+ }
+
+ /* Move backward. */
+ while (*next_newline != '\n' &&
+ *next_newline != ' ' && next_newline != line &&
+ *next_newline != '\0')
+ {
+ next_newline--;
+ }
+
+ *next_newline = '\n';
+ if (next_newline == line)
+ {
+ break;
+ }
+ next_newline++;
+ }
+
for (;;)
{
while (spacing-- > 0)
@@ -159,6 +200,8 @@ grub_arg_show_help (grub_extcmd_t cmd)
doc++;
spacing = 4 + 20;
}
+
+ grub_free (doc_orig);
switch (opt->shortarg)
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic