Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NOy1A-0001sv-61 for mharc-grub-devel@gnu.org; Sun, 27 Dec 2009 13:39:04 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NOy17-0001rs-FW for grub-devel@gnu.org; Sun, 27 Dec 2009 13:39:01 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NOy13-0001qU-OE for grub-devel@gnu.org; Sun, 27 Dec 2009 13:39:01 -0500 Received: from [199.232.76.173] (port=37823 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NOy13-0001qR-Hk for grub-devel@gnu.org; Sun, 27 Dec 2009 13:38:57 -0500 Received: from 197.red-80-32-81.staticip.rima-tde.net ([80.32.81.197]:59143 helo=mail.pina.cat) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NOy12-0001Dx-DK for grub-devel@gnu.org; Sun, 27 Dec 2009 13:38:57 -0500 Received: from pinux (unknown [192.168.0.78]) by mail.pina.cat (Postfix) with ESMTPA id 478422894B244 for ; Sun, 27 Dec 2009 19:38:53 +0100 (CET) Received: by pinux (Postfix, from userid 1000) id C5A0CDB97; Sun, 27 Dec 2009 19:38:51 +0100 (CET) Date: Sun, 27 Dec 2009 19:38:51 +0100 From: Carles Pina i Estany To: grub-devel@gnu.org Message-ID: <20091227183851.GA4879@pina.cat> References: <20091227001742.GA22136@pina.cat> <20091227104937.GA25228@pina.cat> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IJpNTDwzlM2Ie8A6" Content-Disposition: inline In-Reply-To: <20091227104937.GA25228@pina.cat> 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: Re: 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 18:39:01 -0000 --IJpNTDwzlM2Ie8A6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --IJpNTDwzlM2Ie8A6 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="dynamic_split03.patch" === 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 + * 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 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) { --IJpNTDwzlM2Ie8A6--