From b99518d1cebc450832df016948ed8290adfae538 Mon Sep 17 00:00:00 2001 From: carles Date: Sat, 19 Dec 2009 23:00:30 +0000 Subject: [PATCH] 2009-12-19 Carles Pina i Estany * include/grub/normal.h (grub_utf8_to_ucs4): New declaration. (grub_print_ucs4_alloc): Likewise. (grub_getstringwidth): Likewise. * normal/main.c (grub_normal_init_page): Gettextize version string. * normal/menu_text.c (grub_utf8_to_ucs4_alloc): New definition. (getstringwidth): Renamed to ... (grub_getstringwidth): ... this. Remove `static' qualifier (now used in normal/main.c). Use `grub_utf8_to_ucs4_alloc'. (grub_print_ucs4): Remove `static' qualifer (now used in normal/main.c). * po/POTFILES: Add normal/main.c. --- ChangeLog | 14 ++++++++++++ include/grub/normal.h | 6 +++++ normal/main.c | 35 +++++++++++++++++++--------- normal/menu_text.c | 53 +++++++++++++++++++++++++++---------------- po/POTFILES | 1 + 5 files changed, 79 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc616c078..077d0e438 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-12-19 Carles Pina i Estany + + * include/grub/normal.h (grub_utf8_to_ucs4): New declaration. + (grub_print_ucs4_alloc): Likewise. + (grub_getstringwidth): Likewise. + * normal/main.c (grub_normal_init_page): Gettextize version string. + * normal/menu_text.c (grub_utf8_to_ucs4_alloc): New definition. + (getstringwidth): Renamed to ... + (grub_getstringwidth): ... this. Remove `static' qualifier (now used + in normal/main.c). Use `grub_utf8_to_ucs4_alloc'. + (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. diff --git a/include/grub/normal.h b/include/grub/normal.h index feebc85b1..ae520c3f9 100644 --- a/include/grub/normal.h +++ b/include/grub/normal.h @@ -73,6 +73,12 @@ void grub_parse_color_name_pair (grub_uint8_t *ret, const char *name); /* Defined in `menu_text.c'. */ void grub_wait_after_message (void); +int grub_utf8_to_ucs4_alloc (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 grub_getstringwidth (grub_uint32_t * str, + const grub_uint32_t * last_position); /* Defined in `handler.c'. */ void read_handler_list (void); diff --git a/normal/main.c b/normal/main.c index f080a6971..6a238a082 100644 --- a/normal/main.c +++ b/normal/main.c @@ -385,22 +385,35 @@ read_config_file (const char *config) void grub_normal_init_page (void) { - grub_uint8_t width, margin; - -#define TITLE ("GNU GRUB version " PACKAGE_VERSION) - - width = grub_getwh () >> 8; - margin = (width - (sizeof(TITLE) + 7)) / 2; + int msg_len; + int posx; + const char *msg = _("GNU GRUB version %s"); + char *msg_formatted = grub_malloc (grub_strlen(msg) + + grub_strlen(PACKAGE_VERSION)); + grub_cls (); - grub_putchar ('\n'); - while (margin--) - grub_putchar (' '); + grub_sprintf (msg_formatted, msg, PACKAGE_VERSION); - grub_printf ("%s\n\n", TITLE); + grub_uint32_t *unicode_msg; + grub_uint32_t *last_position; + + msg_len = grub_utf8_to_ucs4_alloc (msg_formatted, + &unicode_msg, &last_position); + + if (msg_len < 0) + { + return; + } -#undef TITLE + posx = grub_getstringwidth (unicode_msg, last_position); + posx = (GRUB_TERM_WIDTH - posx) / 2; + grub_gotoxy (posx, 1); + + grub_print_ucs4 (unicode_msg, last_position); + grub_printf("\n\n"); + grub_free (unicode_msg); } static int reader_nested; diff --git a/normal/menu_text.c b/normal/menu_text.c index b9529b38b..f1ac76d35 100644 --- a/normal/menu_text.c +++ b/normal/menu_text.c @@ -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,8 +66,35 @@ grub_print_ucs4 (const grub_uint32_t * str, } } -static grub_ssize_t -getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position) +int +grub_utf8_to_ucs4_alloc (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 +grub_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, int margin_left, int margin_right) (margin_left + margin_right); grub_uint32_t *unicode_msg; + grub_uint32_t *last_position; - grub_ssize_t msg_len = grub_strlen (msg); + int msg_len; - unicode_msg = grub_malloc (msg_len * sizeof (*unicode_msg)); - - 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 = grub_utf8_to_ucs4_alloc (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; @@ -123,7 +138,7 @@ print_message_indented (const char *msg, int margin_left, int margin_right) next_new_line = (grub_uint32_t *) last_position; - while (getstringwidth (current_position, next_new_line) > line_len + while (grub_getstringwidth (current_position, next_new_line) > line_len || (*next_new_line != ' ' && next_new_line > current_position && next_new_line != last_position)) { diff --git a/po/POTFILES b/po/POTFILES index 7d213c357..a7969a15c 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -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