Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NOgp8-0008Ti-4G for mharc-grub-devel@gnu.org; Sat, 26 Dec 2009 19:17:30 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NOgp6-0008T2-Ty for grub-devel@gnu.org; Sat, 26 Dec 2009 19:17:28 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NOgp2-0008QR-7O for grub-devel@gnu.org; Sat, 26 Dec 2009 19:17:28 -0500 Received: from [199.232.76.173] (port=58898 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NOgp2-0008QO-1S for grub-devel@gnu.org; Sat, 26 Dec 2009 19:17:24 -0500 Received: from 197.red-80-32-81.staticip.rima-tde.net ([80.32.81.197]:46655 helo=mail.pina.cat) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NOgp0-0001Aj-N5 for grub-devel@gnu.org; Sat, 26 Dec 2009 19:17:23 -0500 Received: from pinux (unknown [192.168.0.108]) by mail.pina.cat (Postfix) with ESMTPA id 647AA2894B244 for ; Sun, 27 Dec 2009 01:17:21 +0100 (CET) Received: by pinux (Postfix, from userid 1000) id 879529147; Sun, 27 Dec 2009 00:17:42 +0000 (GMT) Date: Sun, 27 Dec 2009 01:17:42 +0100 From: Carles Pina i Estany To: grub-devel@gnu.org Message-ID: <20091227001742.GA22136@pina.cat> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="+HP7ph2BbKc20aGI" Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: lib/arg.c: dynamic newline in help X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Dec 2009 00:17:29 -0000 --+HP7ph2BbKc20aGI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, Until now the options for the commands has been splitted (using a \n) by the developer. For example, commands/hdparm.c: static const struct grub_arg_option options[] = { {"apm", 'B', 0, "Set Advanced Power Management\n" "(1=low, ..., 254=high, 255=off).", 0, ARG_TYPE_INT}, This is a problem for the translations: translators should be aware that they need to cut the string after some number of characters, or will not appear correctly formatted. Attached patch splits it dynamically. Note: the attached patch goes forward and then backward because some strings, like above one, must have a \n to split some lines. But other strings could be just be too long and could not have the \n line. The number of characters per line is fixed as a constant because lib/argc.c doesn't know anything about consoles. If I remember correctly is used in two places: form help command and fstest. I think that the attached solution is good enough for the current status. I implemented it using another approach and changed to the current one, so feel free to tell me any problem or things that you would improve. My limited tests has been fine. I think that after comitting it I will be able to gettext all options strings. Thanks, -- Carles Pina i Estany http://pinux.info --+HP7ph2BbKc20aGI Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="dynamic_split02.patch" === modified file 'ChangeLog' --- ChangeLog 2009-12-26 23:43:21 +0000 +++ ChangeLog 2009-12-27 00:08:20 +0000 @@ -1,5 +1,10 @@ 2009-12-27 Carles Pina i Estany + * lib/arg.c (AVAILABLE_CHARS_LINE): New macro. + (grub_arg_show_help): Cut the help string dynamically. + +2009-12-27 Carles Pina i Estany + * 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 00:08:27 +0000 @@ -28,6 +28,8 @@ #define SHORT_ARG_HELP -100 #define SHORT_ARG_USAGE -101 +#define AVAILABLE_CHARS_LINE (80 - 25) + static const struct grub_arg_option help_options[] = { {"help", SHORT_ARG_HELP, 0, @@ -144,7 +146,41 @@ 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); + + while (next_newline + AVAILABLE_CHARS_LINE < doc_last) + { + line = next_newline; + + /* Move forward. */ + while (*next_newline != '\n' && + next_newline - line < AVAILABLE_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 +195,8 @@ grub_arg_show_help (grub_extcmd_t cmd) doc++; spacing = 4 + 20; } + + grub_free (doc_orig); switch (opt->shortarg) { --+HP7ph2BbKc20aGI--