Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NLoKI-0000n2-Jm for mharc-grub-devel@gnu.org; Fri, 18 Dec 2009 20:41:46 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLoKG-0000mL-72 for grub-devel@gnu.org; Fri, 18 Dec 2009 20:41:44 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLoKA-0000jC-Sk for grub-devel@gnu.org; Fri, 18 Dec 2009 20:41:43 -0500 Received: from [199.232.76.173] (port=39872 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLoKA-0000j9-ME for grub-devel@gnu.org; Fri, 18 Dec 2009 20:41:38 -0500 Received: from 197.red-80-32-81.staticip.rima-tde.net ([80.32.81.197]:38756 helo=mail.pina.cat) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NLoK9-0001Jg-Ci for grub-devel@gnu.org; Fri, 18 Dec 2009 20:41:38 -0500 Received: from pinux (82-45-164-87.cable.ubr06.hari.blueyonder.co.uk [82.45.164.87]) by mail.pina.cat (Postfix) with ESMTP id E311F28415537 for ; Sat, 19 Dec 2009 02:41:35 +0100 (CET) Received: by pinux (Postfix, from userid 1000) id 3C1BD9621; Sat, 19 Dec 2009 01:41:54 +0000 (GMT) Date: Sat, 19 Dec 2009 01:41:54 +0000 From: Carles Pina i Estany To: grub-devel@gnu.org Message-ID: <20091219014154.GA15826@pina.cat> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="IS0zKkzwUGydFO0o" 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: gettext: version string in normal/main.c 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: Sat, 19 Dec 2009 01:41:44 -0000 --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, I've gettextitzzed the version string. Something to improve before committing? It's all right? Thanks, -- Carles Pina i Estany http://pinux.info --IS0zKkzwUGydFO0o Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="version_gettext.patch" === modified file 'ChangeLog' --- ChangeLog 2009-12-19 00:05:41 +0000 +++ ChangeLog 2009-12-19 01:27:34 +0000 @@ -1,5 +1,18 @@ 2009-12-19 Carles Pina i Estany + * include/grub/normal.h (utf8_to_ucs4): New declaration. + (grub_print_ucs4): Likewise. + (getstringwidth): Likewise. + * normal/main.c (grub_normal_init_page): Gettextize version string. + * normal/menu_text.c (utf8_to_ucs4): New declaration. + (getstringwidth): Remove `static' qualifier (now used in + normal/main.c). Use `utf8_to_ucs4'. + (grub_print_ucs4): Remove `static' qualifer (now used in + normal/main.c). + * po/POTFILES: Add normal/main.c. + +2009-12-19 Carles Pina i Estany + * normal/menu_text.c (STANDARD_MARGIN): New macro. (print_message_indented): Add `margin_left' and `margin_right' parameters. === modified file 'include/grub/normal.h' --- include/grub/normal.h 2009-08-24 23:55:06 +0000 +++ include/grub/normal.h 2009-12-19 01:21:13 +0000 @@ -73,6 +73,12 @@ void grub_parse_color_name_pair (grub_ui /* Defined in `menu_text.c'. */ void grub_wait_after_message (void); +int utf8_to_ucs4 (const char *msg, grub_uint32_t **unicode_msg, + grub_uint32_t **last_position); +void grub_print_ucs4 (const grub_uint32_t * str, + const grub_uint32_t * last_position); +grub_ssize_t getstringwidth (grub_uint32_t * str, + const grub_uint32_t * last_position); /* Defined in `handler.c'. */ void read_handler_list (void); === modified file 'normal/main.c' --- normal/main.c 2009-12-08 00:08:52 +0000 +++ normal/main.c 2009-12-19 01:36:39 +0000 @@ -385,22 +385,31 @@ read_config_file (const char *config) void grub_normal_init_page (void) { - grub_uint8_t width, margin; + grub_cls (); + const char *msg = _("GNU GRUB version %s"); -#define TITLE ("GNU GRUB version " PACKAGE_VERSION) + char *msg_formatted = grub_malloc (grub_strlen(msg) + grub_strlen(PACKAGE_VERSION)); - width = grub_getwh () >> 8; - margin = (width - (sizeof(TITLE) + 7)) / 2; + grub_sprintf (msg_formatted, msg, PACKAGE_VERSION); - grub_cls (); - grub_putchar ('\n'); + grub_uint32_t *unicode_msg; + grub_uint32_t *last_position; + + int msg_len; - while (margin--) - grub_putchar (' '); + msg_len = utf8_to_ucs4 (msg_formatted, &unicode_msg, &last_position); + + if (msg_len < 0) + { + return; + } - grub_printf ("%s\n\n", TITLE); + int posx = getstringwidth (unicode_msg, last_position); + posx = (GRUB_TERM_WIDTH - posx) / 2; + grub_gotoxy (posx, 1); -#undef TITLE + grub_print_ucs4 (unicode_msg, last_position); + grub_printf("\n\n"); } static int reader_nested; === modified file 'normal/menu_text.c' --- normal/menu_text.c 2009-12-19 00:05:41 +0000 +++ normal/menu_text.c 2009-12-19 01:20:58 +0000 @@ -55,7 +55,7 @@ print_spaces (int number_spaces) grub_putchar (' '); } -static void +void grub_print_ucs4 (const grub_uint32_t * str, const grub_uint32_t * last_position) { @@ -66,7 +66,34 @@ grub_print_ucs4 (const grub_uint32_t * s } } -static grub_ssize_t +int +utf8_to_ucs4 (const char *msg, grub_uint32_t **unicode_msg, + grub_uint32_t **last_position) +{ + grub_ssize_t msg_len = grub_strlen (msg); + + *unicode_msg = grub_malloc (grub_strlen (msg) * sizeof (grub_uint32_t)); + + if (!*unicode_msg) + { + grub_printf ("utf8_to_ucs4 ERROR1: %s", msg); + return -1; + } + + msg_len = grub_utf8_to_ucs4 (*unicode_msg, msg_len, + (grub_uint8_t *) msg, -1, 0); + + *last_position = *unicode_msg + msg_len; + + if (msg_len < 0) + { + grub_printf ("utf8_to_ucs4 ERROR2: %s", msg); + grub_free (*unicode_msg); + } + return msg_len; +} + +grub_ssize_t getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position) { grub_ssize_t width = 0; @@ -87,29 +114,17 @@ print_message_indented (const char *msg, (margin_left + margin_right); grub_uint32_t *unicode_msg; + grub_uint32_t *last_position; - grub_ssize_t msg_len = grub_strlen (msg); - - unicode_msg = grub_malloc (msg_len * sizeof (*unicode_msg)); + int msg_len; - msg_len = grub_utf8_to_ucs4 (unicode_msg, msg_len, - (grub_uint8_t *) msg, -1, 0); - - if (!unicode_msg) - { - grub_printf ("print_message_indented ERROR1: %s", msg); - return; - } + msg_len = utf8_to_ucs4 (msg, &unicode_msg, &last_position); if (msg_len < 0) { - grub_printf ("print_message_indented ERROR2: %s", msg); - grub_free (unicode_msg); return; } - const grub_uint32_t *last_position = unicode_msg + msg_len; - grub_uint32_t *current_position = unicode_msg; grub_uint32_t *next_new_line = unicode_msg; === modified file 'po/POTFILES' --- po/POTFILES 2009-12-05 11:25:07 +0000 +++ po/POTFILES 2009-12-19 00:32:03 +0000 @@ -11,5 +11,6 @@ util/mkisofs/rock.c util/mkisofs/tree.c util/mkisofs/write.c +normal/main.c normal/menu_entry.c normal/menu_text.c --IS0zKkzwUGydFO0o--