* gettext: normal_menu.c
@ 2009-11-28 0:09 Carles Pina i Estany
2009-11-28 1:24 ` Carles Pina i Estany
0 siblings, 1 reply; 8+ messages in thread
From: Carles Pina i Estany @ 2009-11-28 0:09 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 421 bytes --]
Hi,
Find attached the patch and ChangeLog for normal_menu.c
Suggestions? What to change?
Notice that I used grub_printf to print the spaces/new lines of
formatting.
And print_message_indented receive a "long" string and prints it
splitting by the spaces and indented 6 spaces.
(15 and 6 in that method could be macrofied or const int spaces = 6,
would be in normal.h ?)
--
Carles Pina i Estany
http://pinux.info
[-- Attachment #2: ChangeLog.normal_menu --]
[-- Type: text/plain, Size: 508 bytes --]
2009-11-28 Carles Pina i Estany <carles@pina.cat>
* normal/menu_text.c (grub_color_menu_high): Gettexttize string.
(print_spaces): New function.
(grub_print_ucs4): New function.
(print_message_indented): New function.
(print_message): Gettexttize strings using print_message_indented.
(run_menu): Replaces grub_printf by dynamic terminal width
print_spaces.
(get_entry_number): Gettextize and uses dynamic terminal width.
(notify_booting, notify_fallback, notify_execution_failure):
Gettextize.
[-- Attachment #3: normal_menu_gettext.patch --]
[-- Type: text/x-diff, Size: 6203 bytes --]
=== modified file 'normal/menu_text.c'
--- normal/menu_text.c 2009-11-23 20:59:24 +0000
+++ normal/menu_text.c 2009-11-27 23:58:34 +0000
@@ -39,7 +39,8 @@ static grub_uint8_t grub_color_menu_high
void
grub_wait_after_message (void)
{
- grub_printf ("\nPress any key to continue...");
+ grub_putchar('\n');
+ grub_printf (_("Press any key to continue..."));
(void) grub_getkey ();
grub_putchar ('\n');
}
@@ -81,28 +82,107 @@ draw_border (void)
}
static void
+print_spaces (int number_spaces)
+{
+ int i;
+ for (i = 0; i < number_spaces; i++)
+ grub_putchar(' ');
+}
+
+static void
+grub_print_ucs4 (grub_uint32_t* str, const grub_uint32_t* last_position)
+{
+ while (str < last_position)
+ {
+ grub_putcode(*str);
+ str++;
+ }
+}
+
+print_message_indented(const char* msg)
+{
+ const int line_len = GRUB_TERM_WIDTH - 15;
+
+ grub_uint32_t *unicode_msg;
+
+ grub_ssize_t msg_len = grub_strlen(msg);
+
+ 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;
+ }
+
+ 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;
+
+ while (current_position < last_position)
+ {
+ next_new_line = (next_new_line + line_len > last_position) ?
+ (grub_uint32_t*)last_position :
+ next_new_line + line_len;
+
+ while (*next_new_line != ' ' && next_new_line >= unicode_msg &&
+ next_new_line != last_position)
+ {
+ next_new_line--;
+ }
+
+ print_spaces(6);
+ grub_print_ucs4(current_position,next_new_line);
+ grub_putchar('\n');
+
+ next_new_line++;
+ current_position = next_new_line;
+ }
+ grub_free(unicode_msg);
+}
+
+static void
print_message (int nested, int edit)
{
grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
-
+
+ grub_putchar ('\n');
if (edit)
{
- grub_printf ("\n\
- Minimum Emacs-like screen editing is supported. TAB lists\n\
- completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\
- or ESC to return menu.");
+ print_message_indented(_("Minimum Emacs-like screen editing is \
+supported. TAB lists completions. Press Ctrl-x to boot, Ctrl-c for a \
+command-line or ESC to return menu."));
}
else
{
- grub_printf (_("\n\
- Use the %C and %C keys to select which entry is highlighted.\n"),
- (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN);
- grub_printf ("\
- Press enter to boot the selected OS, \'e\' to edit the\n\
- commands before booting or \'c\' for a command-line.");
+ const char *msg = _("Use the %C and %C keys to select which \
+entry is highlighted.");
+ char* msg_translated = grub_malloc(sizeof(char) * grub_strlen(msg) + 1);
+
+ grub_sprintf(msg_translated, msg, (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN);
+ print_message_indented(msg_translated);
+
+ grub_free (msg_translated);
+
+ print_message_indented(_("Press enter to boot the selected OS, \
+\'e\' to edit the commands before booting or \'c\' for a command-line."));
if (nested)
- grub_printf ("\n\
- ESC to return previous menu.");
+ {
+ grub_printf ("\n ");
+ grub_printf(_("ESC to return previous menu."));
+ }
}
}
@@ -265,13 +345,16 @@ get_entry_number (const char *name)
static void
print_timeout (int timeout, int offset, int second_stage)
{
- /* NOTE: Do not remove the trailing space characters.
- They are required to clear the line. */
- char *msg = " The highlighted entry will be booted automatically in %ds. ";
+ const char *msg = _("The highlighted entry will be booted automatically in %ds.");
+ const int msg_localized_len = grub_strlen (msg);
+ const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len - 3;
+
char *msg_end = grub_strchr (msg, '%');
- grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3);
+ grub_gotoxy (second_stage ? (msg_end - msg + 3) : 3, GRUB_TERM_HEIGHT - 3);
grub_printf (second_stage ? msg_end : msg, timeout);
+ print_spaces (second_stage ? number_spaces : 0);
+
grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
grub_refresh ();
};
@@ -360,8 +443,7 @@ run_menu (grub_menu_t menu, int nested,
if (timeout >= 0)
{
grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
- grub_printf ("\
- ");
+ print_spaces (GRUB_TERM_WIDTH - 1);
grub_env_unset ("timeout");
grub_env_unset ("fallback");
grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
@@ -517,7 +599,9 @@ static void
notify_booting (grub_menu_entry_t entry,
void *userdata __attribute__((unused)))
{
- grub_printf (" Booting \'%s\'\n\n", entry->title);
+ grub_printf (" ");
+ grub_printf (_("Booting \'%s\'"), entry->title);
+ grub_printf ("\n\n");
}
/* Callback invoked when a default menu entry executed because of a timeout
@@ -527,7 +611,9 @@ static void
notify_fallback (grub_menu_entry_t entry,
void *userdata __attribute__((unused)))
{
- grub_printf ("\n Falling back to \'%s\'\n\n", entry->title);
+ grub_printf ("\n ");
+ grub_printf (_("Falling back to \'%s\'"), entry->title);
+ grub_printf ("\n\n");
grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS);
}
@@ -541,7 +627,9 @@ notify_execution_failure (void *userdata
grub_print_error ();
grub_errno = GRUB_ERR_NONE;
}
- grub_printf ("\n Failed to boot default entries.\n");
+ grub_printf ("\n ");
+ grub_printf (_("Failed to boot default entries."));
+ grub_putchar ('\n');
grub_wait_after_message ();
}
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: gettext: normal_menu.c 2009-11-28 0:09 gettext: normal_menu.c Carles Pina i Estany @ 2009-11-28 1:24 ` Carles Pina i Estany 2009-11-28 1:47 ` Carles Pina i Estany 0 siblings, 1 reply; 8+ messages in thread From: Carles Pina i Estany @ 2009-11-28 1:24 UTC (permalink / raw) To: grub-devel Hi, On Nov/28/2009, Carles Pina i Estany wrote: > Find attached the patch and ChangeLog for normal_menu.c new version with two improvements: a) uses grubcharwidth to calculate the width of the string (for the characters that doesn't have any width, etc.). This has to be consistent with GRUB_TERM_WIDTH. b) ensure that strings that doesn't fit in one line will be correctly handled and indented. This can happen in languages where the separator is not a space. I've checked if there is some unicode character to say "word separator" and I didn't find, so it adds the newline wherever is fine for the terminal width. Question: getstringwidth should be in normal/menu_text.c like it's now or in kern/term.c like grub_getchardwidth. Some suggestions before committing? Thanks, -- Carles Pina i Estany http://pinux.info ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: gettext: normal_menu.c 2009-11-28 1:24 ` Carles Pina i Estany @ 2009-11-28 1:47 ` Carles Pina i Estany 2009-11-28 12:21 ` Carles Pina i Estany 0 siblings, 1 reply; 8+ messages in thread From: Carles Pina i Estany @ 2009-11-28 1:47 UTC (permalink / raw) To: grub-devel [-- Attachment #1: Type: text/plain, Size: 332 bytes --] Hi, On Nov/28/2009, Carles Pina i Estany wrote: > > Hi, > > On Nov/28/2009, Carles Pina i Estany wrote: > > > Find attached the patch and ChangeLog for normal_menu.c > > new version with two improvements: really, I should not be sending mails on Friday too late. Now is attached. -- Carles Pina i Estany http://pinux.info [-- Attachment #2: normal_menu_gettext2.patch --] [-- Type: text/x-diff, Size: 6699 bytes --] === modified file 'normal/menu_text.c' --- normal/menu_text.c 2009-11-23 20:59:24 +0000 +++ normal/menu_text.c 2009-11-28 01:18:23 +0000 @@ -39,7 +39,8 @@ static grub_uint8_t grub_color_menu_high void grub_wait_after_message (void) { - grub_printf ("\nPress any key to continue..."); + grub_putchar('\n'); + grub_printf (_("Press any key to continue...")); (void) grub_getkey (); grub_putchar ('\n'); } @@ -81,28 +82,128 @@ draw_border (void) } static void +print_spaces (int number_spaces) +{ + int i; + for (i = 0; i < number_spaces; i++) + grub_putchar(' '); +} + +static void +grub_print_ucs4 (const grub_uint32_t* str, const grub_uint32_t* last_position) +{ + while (str < last_position) + { + grub_putcode(*str); + str++; + } +} + +static grub_ssize_t +getstringwidth(grub_uint32_t* str, const grub_uint32_t* last_position) +{ + grub_ssize_t width = 0; + + while (str < last_position) + { + width += grub_getcharwidth(*str); + str++; + } + return width; +} + +static void +print_message_indented(const char* msg) +{ + const int line_len = GRUB_TERM_WIDTH - grub_getcharwidth('m') * 15; + + grub_uint32_t *unicode_msg; + + grub_ssize_t msg_len = grub_strlen(msg); + + 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; + } + + 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; + + while (current_position < last_position) + { + next_new_line = (grub_uint32_t*)last_position; + + while (getstringwidth(current_position,next_new_line) > line_len + || (*next_new_line != ' ' && next_new_line > current_position && + next_new_line != last_position)) + { + next_new_line--; + } + + if (next_new_line == current_position) + { + next_new_line = (next_new_line + line_len > last_position) ? + (grub_uint32_t*)last_position : + next_new_line + line_len; + } + + print_spaces(6); + grub_print_ucs4(current_position,next_new_line); + grub_putchar('\n'); + + next_new_line++; + current_position = next_new_line; + } + grub_free(unicode_msg); +} + +static void print_message (int nested, int edit) { grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); - + + grub_putchar ('\n'); if (edit) { - grub_printf ("\n\ - Minimum Emacs-like screen editing is supported. TAB lists\n\ - completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\ - or ESC to return menu."); + print_message_indented(_("Minimum Emacs-like screen editing is \ +supported. TAB lists completions. Press Ctrl-x to boot, Ctrl-c for a \ +command-line or ESC to return menu.")); } else { - grub_printf (_("\n\ - Use the %C and %C keys to select which entry is highlighted.\n"), - (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); - grub_printf ("\ - Press enter to boot the selected OS, \'e\' to edit the\n\ - commands before booting or \'c\' for a command-line."); + const char *msg = _("Use the %C and %C keys to select which \ +entry is highlighted."); + char* msg_translated = grub_malloc(sizeof(char) * grub_strlen(msg) + 1); + + grub_sprintf(msg_translated, msg, (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); + print_message_indented(msg_translated); + + grub_free (msg_translated); + + print_message_indented(_("Press enter to boot the selected OS, \ +\'e\' to edit the commands before booting or \'c\' for a command-line.")); + if (nested) - grub_printf ("\n\ - ESC to return previous menu."); + { + grub_printf ("\n "); + grub_printf(_("ESC to return previous menu.")); + } } } @@ -265,13 +366,16 @@ get_entry_number (const char *name) static void print_timeout (int timeout, int offset, int second_stage) { - /* NOTE: Do not remove the trailing space characters. - They are required to clear the line. */ - char *msg = " The highlighted entry will be booted automatically in %ds. "; + const char *msg = _("The highlighted entry will be booted automatically in %ds."); + const int msg_localized_len = grub_strlen (msg); + const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len - 3; + char *msg_end = grub_strchr (msg, '%'); - grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3); + grub_gotoxy (second_stage ? (msg_end - msg + 3) : 3, GRUB_TERM_HEIGHT - 3); grub_printf (second_stage ? msg_end : msg, timeout); + print_spaces (second_stage ? number_spaces : 0); + grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); grub_refresh (); }; @@ -360,8 +464,7 @@ run_menu (grub_menu_t menu, int nested, if (timeout >= 0) { grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - grub_printf ("\ - "); + print_spaces (GRUB_TERM_WIDTH - 1); grub_env_unset ("timeout"); grub_env_unset ("fallback"); grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); @@ -517,7 +620,9 @@ static void notify_booting (grub_menu_entry_t entry, void *userdata __attribute__((unused))) { - grub_printf (" Booting \'%s\'\n\n", entry->title); + grub_printf (" "); + grub_printf (_("Booting \'%s\'"), entry->title); + grub_printf ("\n\n"); } /* Callback invoked when a default menu entry executed because of a timeout @@ -527,7 +632,9 @@ static void notify_fallback (grub_menu_entry_t entry, void *userdata __attribute__((unused))) { - grub_printf ("\n Falling back to \'%s\'\n\n", entry->title); + grub_printf ("\n "); + grub_printf (_("Falling back to \'%s\'"), entry->title); + grub_printf ("\n\n"); grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); } @@ -541,7 +648,9 @@ notify_execution_failure (void *userdata grub_print_error (); grub_errno = GRUB_ERR_NONE; } - grub_printf ("\n Failed to boot default entries.\n"); + grub_printf ("\n "); + grub_printf (_("Failed to boot default entries.")); + grub_putchar ('\n'); grub_wait_after_message (); } [-- Attachment #3: ChangeLog.normal_menu --] [-- Type: text/plain, Size: 541 bytes --] 2009-11-28 Carles Pina i Estany <carles@pina.cat> * normal/menu_text.c (grub_color_menu_high): Gettexttize string. (print_spaces): New function. (grub_print_ucs4): New function. (print_message_indented): New function. (getstringwidth): New function. (print_message): Gettexttize strings using print_message_indented. (run_menu): Replaces grub_printf by dynamic terminal width print_spaces. (get_entry_number): Gettextize and uses dynamic terminal width. (notify_booting, notify_fallback, notify_execution_failure): Gettextize. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: gettext: normal_menu.c 2009-11-28 1:47 ` Carles Pina i Estany @ 2009-11-28 12:21 ` Carles Pina i Estany 2009-11-28 19:09 ` Robert Millan 0 siblings, 1 reply; 8+ messages in thread From: Carles Pina i Estany @ 2009-11-28 12:21 UTC (permalink / raw) To: grub-devel [-- Attachment #1: Type: text/plain, Size: 143 bytes --] Hi, I've added some easy changes for normal/menu_entry.c So better review this patch. Thanks! -- Carles Pina i Estany http://pinux.info [-- Attachment #2: ChangeLog.normal --] [-- Type: text/plain, Size: 668 bytes --] 2009-11-28 Carles Pina i Estany <carles@pina.cat> * normal/menu_text.c (grub_color_menu_high): Gettexttize string. (print_spaces): New function. (grub_print_ucs4): New function. (print_message_indented): New function. (getstringwidth): New function. (print_message): Gettexttize strings using print_message_indented. (run_menu): Replaces grub_printf by dynamic terminal width print_spaces. (get_entry_number): Gettextize and uses dynamic terminal width. (notify_booting, notify_fallback, notify_execution_failure): Gettextize. * normal/menu_entry.c (store_completion): Cleanup the gettextized string (run): Likewise. (grub_menu_entry_run): Likewise. [-- Attachment #3: normal_menu_gettext3.patch --] [-- Type: text/x-diff, Size: 7751 bytes --] === modified file 'normal/menu_entry.c' --- normal/menu_entry.c 2009-11-23 20:31:57 +0000 +++ normal/menu_entry.c 2009-11-28 12:14:22 +0000 @@ -836,7 +836,9 @@ store_completion (const char *item, grub } grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - grub_printf (" Possible %s are:\n ", what); + grub_printf (" "); + grub_printf (_("Possible %s are:"), what); + grub_printf ("\n "); } /* Make sure that the completion buffer has enough room. */ @@ -997,7 +999,9 @@ run (struct screen *screen) } grub_cls (); - grub_printf (_(" Booting a command list\n\n")); + grub_printf (" "); + grub_printf (_("Booting a command list")); + grub_printf ("\n\n"); /* Execute the script, line for line. */ @@ -1177,6 +1181,7 @@ grub_menu_entry_run (grub_menu_entry_t e grub_cls (); grub_print_error (); grub_errno = GRUB_ERR_NONE; - grub_printf (_("\nPress any key to continue...")); + grub_putchar ('\n'); + grub_printf (_("Press any key to continue...")); (void) grub_getkey (); } === modified file 'normal/menu_text.c' --- normal/menu_text.c 2009-11-23 20:59:24 +0000 +++ normal/menu_text.c 2009-11-28 01:18:23 +0000 @@ -39,7 +39,8 @@ static grub_uint8_t grub_color_menu_high void grub_wait_after_message (void) { - grub_printf ("\nPress any key to continue..."); + grub_putchar('\n'); + grub_printf (_("Press any key to continue...")); (void) grub_getkey (); grub_putchar ('\n'); } @@ -81,28 +82,128 @@ draw_border (void) } static void +print_spaces (int number_spaces) +{ + int i; + for (i = 0; i < number_spaces; i++) + grub_putchar(' '); +} + +static void +grub_print_ucs4 (const grub_uint32_t* str, const grub_uint32_t* last_position) +{ + while (str < last_position) + { + grub_putcode(*str); + str++; + } +} + +static grub_ssize_t +getstringwidth(grub_uint32_t* str, const grub_uint32_t* last_position) +{ + grub_ssize_t width = 0; + + while (str < last_position) + { + width += grub_getcharwidth(*str); + str++; + } + return width; +} + +static void +print_message_indented(const char* msg) +{ + const int line_len = GRUB_TERM_WIDTH - grub_getcharwidth('m') * 15; + + grub_uint32_t *unicode_msg; + + grub_ssize_t msg_len = grub_strlen(msg); + + 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; + } + + 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; + + while (current_position < last_position) + { + next_new_line = (grub_uint32_t*)last_position; + + while (getstringwidth(current_position,next_new_line) > line_len + || (*next_new_line != ' ' && next_new_line > current_position && + next_new_line != last_position)) + { + next_new_line--; + } + + if (next_new_line == current_position) + { + next_new_line = (next_new_line + line_len > last_position) ? + (grub_uint32_t*)last_position : + next_new_line + line_len; + } + + print_spaces(6); + grub_print_ucs4(current_position,next_new_line); + grub_putchar('\n'); + + next_new_line++; + current_position = next_new_line; + } + grub_free(unicode_msg); +} + +static void print_message (int nested, int edit) { grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); - + + grub_putchar ('\n'); if (edit) { - grub_printf ("\n\ - Minimum Emacs-like screen editing is supported. TAB lists\n\ - completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\ - or ESC to return menu."); + print_message_indented(_("Minimum Emacs-like screen editing is \ +supported. TAB lists completions. Press Ctrl-x to boot, Ctrl-c for a \ +command-line or ESC to return menu.")); } else { - grub_printf (_("\n\ - Use the %C and %C keys to select which entry is highlighted.\n"), - (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); - grub_printf ("\ - Press enter to boot the selected OS, \'e\' to edit the\n\ - commands before booting or \'c\' for a command-line."); + const char *msg = _("Use the %C and %C keys to select which \ +entry is highlighted."); + char* msg_translated = grub_malloc(sizeof(char) * grub_strlen(msg) + 1); + + grub_sprintf(msg_translated, msg, (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); + print_message_indented(msg_translated); + + grub_free (msg_translated); + + print_message_indented(_("Press enter to boot the selected OS, \ +\'e\' to edit the commands before booting or \'c\' for a command-line.")); + if (nested) - grub_printf ("\n\ - ESC to return previous menu."); + { + grub_printf ("\n "); + grub_printf(_("ESC to return previous menu.")); + } } } @@ -265,13 +366,16 @@ get_entry_number (const char *name) static void print_timeout (int timeout, int offset, int second_stage) { - /* NOTE: Do not remove the trailing space characters. - They are required to clear the line. */ - char *msg = " The highlighted entry will be booted automatically in %ds. "; + const char *msg = _("The highlighted entry will be booted automatically in %ds."); + const int msg_localized_len = grub_strlen (msg); + const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len - 3; + char *msg_end = grub_strchr (msg, '%'); - grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3); + grub_gotoxy (second_stage ? (msg_end - msg + 3) : 3, GRUB_TERM_HEIGHT - 3); grub_printf (second_stage ? msg_end : msg, timeout); + print_spaces (second_stage ? number_spaces : 0); + grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); grub_refresh (); }; @@ -360,8 +464,7 @@ run_menu (grub_menu_t menu, int nested, if (timeout >= 0) { grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - grub_printf ("\ - "); + print_spaces (GRUB_TERM_WIDTH - 1); grub_env_unset ("timeout"); grub_env_unset ("fallback"); grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); @@ -517,7 +620,9 @@ static void notify_booting (grub_menu_entry_t entry, void *userdata __attribute__((unused))) { - grub_printf (" Booting \'%s\'\n\n", entry->title); + grub_printf (" "); + grub_printf (_("Booting \'%s\'"), entry->title); + grub_printf ("\n\n"); } /* Callback invoked when a default menu entry executed because of a timeout @@ -527,7 +632,9 @@ static void notify_fallback (grub_menu_entry_t entry, void *userdata __attribute__((unused))) { - grub_printf ("\n Falling back to \'%s\'\n\n", entry->title); + grub_printf ("\n "); + grub_printf (_("Falling back to \'%s\'"), entry->title); + grub_printf ("\n\n"); grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); } @@ -541,7 +648,9 @@ notify_execution_failure (void *userdata grub_print_error (); grub_errno = GRUB_ERR_NONE; } - grub_printf ("\n Failed to boot default entries.\n"); + grub_printf ("\n "); + grub_printf (_("Failed to boot default entries.")); + grub_putchar ('\n'); grub_wait_after_message (); } ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: gettext: normal_menu.c 2009-11-28 12:21 ` Carles Pina i Estany @ 2009-11-28 19:09 ` Robert Millan 2009-11-29 1:04 ` Carles Pina i Estany 0 siblings, 1 reply; 8+ messages in thread From: Robert Millan @ 2009-11-28 19:09 UTC (permalink / raw) To: The development of GNU GRUB Please remember about spaces in our coding style: On Sat, Nov 28, 2009 at 12:21:28PM +0000, Carles Pina i Estany wrote: > + next_new_line = (grub_uint32_t*)last_position; ^ ^ > + while (getstringwidth(current_position,next_new_line) > line_len ^ ^ etc. If in doubt, use indent(1). -- Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all." ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: gettext: normal_menu.c 2009-11-28 19:09 ` Robert Millan @ 2009-11-29 1:04 ` Carles Pina i Estany 2009-11-29 1:17 ` Vladimir 'φ-coder/phcoder' Serbinenko 2009-12-03 23:22 ` Carles Pina i Estany 0 siblings, 2 replies; 8+ messages in thread From: Carles Pina i Estany @ 2009-11-29 1:04 UTC (permalink / raw) To: The development of GNU GRUB [-- Attachment #1: Type: text/plain, Size: 903 bytes --] Hello, On Nov/28/2009, Robert Millan wrote: > > Please remember about spaces in our coding style: > > On Sat, Nov 28, 2009 at 12:21:28PM +0000, Carles Pina i Estany wrote: > > + next_new_line = (grub_uint32_t*)last_position; > ^ ^ > > + while (getstringwidth(current_position,next_new_line) > line_len > ^ ^ > etc. If in doubt, use indent(1). Attached the new patch. Comments are welcomed. The original normal/* files are not indent consistent. So I: 1.- copied the files to old/ 2.- applied the patch to the original files and copy to new/ 3.- indent old/* and new/* 4.- diff -p -u old/ new/ For next time: what you think to make a patch + ChangeLog entry and push to trunk and then another push with the changes to the indent-compliant files? Cheers, -- Carles Pina i Estany http://pinux.info [-- Attachment #2: normal_menu_gettext4.patch --] [-- Type: text/x-diff, Size: 7570 bytes --] diff -p -u old/menu_entry.c new/menu_entry.c --- old/menu_entry.c 2009-11-29 00:56:42.020701488 +0000 +++ new/menu_entry.c 2009-11-29 00:56:06.748700757 +0000 @@ -833,7 +833,9 @@ store_completion (const char *item, grub } grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - grub_printf (" Possible %s are:\n ", what); + grub_printf (" "); + grub_printf (_("Possible %s are:"), what); + grub_printf ("\n "); } /* Make sure that the completion buffer has enough room. */ @@ -994,7 +996,9 @@ run (struct screen *screen) } grub_cls (); - grub_printf (_(" Booting a command list\n\n")); + grub_printf (" "); + grub_printf (_("Booting a command list")); + grub_printf ("\n\n"); /* Execute the script, line for line. */ @@ -1174,6 +1178,7 @@ fail: grub_cls (); grub_print_error (); grub_errno = GRUB_ERR_NONE; - grub_printf (_("\nPress any key to continue...")); + grub_putchar ('\n'); + grub_printf (_("Press any key to continue...")); (void) grub_getkey (); } diff -p -u old/menu_text.c new/menu_text.c --- old/menu_text.c 2009-11-29 00:56:33.700701575 +0000 +++ new/menu_text.c 2009-11-29 00:56:09.736702258 +0000 @@ -39,7 +39,8 @@ static grub_uint8_t grub_color_menu_high void grub_wait_after_message (void) { - grub_printf ("\nPress any key to continue..."); + grub_putchar ('\n'); + grub_printf (_("Press any key to continue...")); (void) grub_getkey (); grub_putchar ('\n'); } @@ -81,27 +82,130 @@ draw_border (void) } static void +print_spaces (int number_spaces) +{ + int i; + for (i = 0; i < number_spaces; i++) + grub_putchar (' '); +} + +static void +grub_print_ucs4 (const grub_uint32_t * str, + const grub_uint32_t * last_position) +{ + while (str < last_position) + { + grub_putcode (*str); + str++; + } +} + +static grub_ssize_t +getstringwidth (grub_uint32_t * str, const grub_uint32_t * last_position) +{ + grub_ssize_t width = 0; + + while (str < last_position) + { + width += grub_getcharwidth (*str); + str++; + } + return width; +} + +static void +print_message_indented (const char *msg) +{ + const int line_len = GRUB_TERM_WIDTH - grub_getcharwidth ('m') * 15; + + grub_uint32_t *unicode_msg; + + grub_ssize_t msg_len = grub_strlen (msg); + + 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; + } + + 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; + + while (current_position < last_position) + { + next_new_line = (grub_uint32_t *) last_position; + + while (getstringwidth (current_position, next_new_line) > line_len + || (*next_new_line != ' ' && next_new_line > current_position && + next_new_line != last_position)) + { + next_new_line--; + } + + if (next_new_line == current_position) + { + next_new_line = (next_new_line + line_len > last_position) ? + (grub_uint32_t *) last_position : next_new_line + line_len; + } + + print_spaces (6); + grub_print_ucs4 (current_position, next_new_line); + grub_putchar ('\n'); + + next_new_line++; + current_position = next_new_line; + } + grub_free (unicode_msg); +} + +static void print_message (int nested, int edit) { grub_setcolorstate (GRUB_TERM_COLOR_NORMAL); + grub_putchar ('\n'); if (edit) { - grub_printf ("\n\ - Minimum Emacs-like screen editing is supported. TAB lists\n\ - completions. Press Ctrl-x to boot, Ctrl-c for a command-line\n\ - or ESC to return menu."); + print_message_indented (_("Minimum Emacs-like screen editing is \ +supported. TAB lists completions. Press Ctrl-x to boot, Ctrl-c for a \ +command-line or ESC to return menu.")); } else { - grub_printf (_("\n\ - Use the %C and %C keys to select which entry is highlighted.\n"), (grub_uint32_t) GRUB_TERM_DISP_UP, (grub_uint32_t) GRUB_TERM_DISP_DOWN); - grub_printf ("\ - Press enter to boot the selected OS, \'e\' to edit the\n\ - commands before booting or \'c\' for a command-line."); + const char *msg = _("Use the %C and %C keys to select which \ +entry is highlighted."); + char *msg_translated = + grub_malloc (sizeof (char) * grub_strlen (msg) + 1); + + grub_sprintf (msg_translated, msg, (grub_uint32_t) GRUB_TERM_DISP_UP, + (grub_uint32_t) GRUB_TERM_DISP_DOWN); + print_message_indented (msg_translated); + + grub_free (msg_translated); + + print_message_indented (_("Press enter to boot the selected OS, \ +\'e\' to edit the commands before booting or \'c\' for a command-line.")); + if (nested) - grub_printf ("\n\ - ESC to return previous menu."); + { + grub_printf ("\n "); + grub_printf (_("ESC to return previous menu.")); + } } } @@ -266,14 +370,17 @@ get_entry_number (const char *name) static void print_timeout (int timeout, int offset, int second_stage) { - /* NOTE: Do not remove the trailing space characters. - They are required to clear the line. */ - char *msg = - " The highlighted entry will be booted automatically in %ds. "; + const char *msg = + _("The highlighted entry will be booted automatically in %ds."); + const int msg_localized_len = grub_strlen (msg); + const int number_spaces = GRUB_TERM_WIDTH - msg_localized_len - 3; + char *msg_end = grub_strchr (msg, '%'); - grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3); + grub_gotoxy (second_stage ? (msg_end - msg + 3) : 3, GRUB_TERM_HEIGHT - 3); grub_printf (second_stage ? msg_end : msg, timeout); + print_spaces (second_stage ? number_spaces : 0); + grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset); grub_refresh (); }; @@ -362,8 +469,7 @@ refresh: if (timeout >= 0) { grub_gotoxy (0, GRUB_TERM_HEIGHT - 3); - grub_printf ("\ - "); + print_spaces (GRUB_TERM_WIDTH - 1); grub_env_unset ("timeout"); grub_env_unset ("fallback"); grub_gotoxy (GRUB_TERM_CURSOR_X, @@ -523,7 +629,9 @@ static void notify_booting (grub_menu_entry_t entry, void *userdata __attribute__ ((unused))) { - grub_printf (" Booting \'%s\'\n\n", entry->title); + grub_printf (" "); + grub_printf (_("Booting \'%s\'"), entry->title); + grub_printf ("\n\n"); } /* Callback invoked when a default menu entry executed because of a timeout @@ -533,7 +641,9 @@ static void notify_fallback (grub_menu_entry_t entry, void *userdata __attribute__ ((unused))) { - grub_printf ("\n Falling back to \'%s\'\n\n", entry->title); + grub_printf ("\n "); + grub_printf (_("Falling back to \'%s\'"), entry->title); + grub_printf ("\n\n"); grub_millisleep (DEFAULT_ENTRY_ERROR_DELAY_MS); } @@ -547,7 +657,9 @@ notify_execution_failure (void *userdata grub_print_error (); grub_errno = GRUB_ERR_NONE; } - grub_printf ("\n Failed to boot default entries.\n"); + grub_printf ("\n "); + grub_printf (_("Failed to boot default entries.")); + grub_putchar ('\n'); grub_wait_after_message (); } [-- Attachment #3: ChangeLog.normal --] [-- Type: text/plain, Size: 673 bytes --] 2009-11-28 Carles Pina i Estany <carles@pina.cat> * normal/menu_text.c (grub_color_menu_high): Gettexttize string. (print_spaces): New function. (grub_print_ucs4): New function. (print_message_indented): New function. (getstringwidth): New function. (print_message): Gettexttize strings using print_message_indented. (run_menu): Replaces grub_printf by print_spaces and dynamic terminal width. (get_entry_number): Gettextize and uses dynamic terminal width. (notify_booting, notify_fallback, notify_execution_failure): Gettextize. * normal/menu_entry.c (store_completion): Cleanup the gettextized string. (run): Likewise. (grub_menu_entry_run): Likewise. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: gettext: normal_menu.c 2009-11-29 1:04 ` Carles Pina i Estany @ 2009-11-29 1:17 ` Vladimir 'φ-coder/phcoder' Serbinenko 2009-12-03 23:22 ` Carles Pina i Estany 1 sibling, 0 replies; 8+ messages in thread From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2009-11-29 1:17 UTC (permalink / raw) To: The development of GNU GRUB [-- Attachment #1: Type: text/plain, Size: 1711 bytes --] Carles Pina i Estany wrote: > Hello, > > On Nov/28/2009, Robert Millan wrote: > >> Please remember about spaces in our coding style: >> >> On Sat, Nov 28, 2009 at 12:21:28PM +0000, Carles Pina i Estany wrote: >> >>> + next_new_line = (grub_uint32_t*)last_position; >>> >> ^ ^ >> >>> + while (getstringwidth(current_position,next_new_line) > line_len >>> >> ^ ^ >> etc. If in doubt, use indent(1). >> > > Attached the new patch. Comments are welcomed. > > The original normal/* files are not indent consistent. So I: > 1.- copied the files to old/ > 2.- applied the patch to the original files and copy to new/ > 3.- indent old/* and new/* > 4.- diff -p -u old/ new/ > > For next time: what you think to make a patch + ChangeLog entry and > push to trunk and then another push with the changes to the > indent-compliant files? > > If you find badly-indented files and you know nobody else is working on those files right now (e.g. no changes on it in experimental) you can indent them in the trunk without mentionning it on the list. If you're aware of people working on these files notify them. Also check that indent didn't make the things worse and add a Changlog entry like YYYY-MM-DD ..... * <file>: Indented. > Cheers, > > > ------------------------------------------------------------------------ > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel -- Regards Vladimir 'φ-coder/phcoder' Serbinenko [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 293 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: gettext: normal_menu.c 2009-11-29 1:04 ` Carles Pina i Estany 2009-11-29 1:17 ` Vladimir 'φ-coder/phcoder' Serbinenko @ 2009-12-03 23:22 ` Carles Pina i Estany 1 sibling, 0 replies; 8+ messages in thread From: Carles Pina i Estany @ 2009-12-03 23:22 UTC (permalink / raw) To: The development of GNU GRUB Hello, On Nov/29/2009, Carles Pina i Estany wrote: > + grub_printf (_("Failed to boot default entries.")); > + grub_putchar ('\n'); This is the only string that I've spotted that it's "String\n" other ones are: "\nString" "String\n " Up to the discussion in the grub_printfnl I would change it to grub_printfnl(_("Failed to boot default entries.")); or grub_printf ("Failed to boot default entries."); Any feedback for the rest of the patch? Thanks, -- Carles Pina i Estany http://pinux.info ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-12-03 23:22 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-11-28 0:09 gettext: normal_menu.c Carles Pina i Estany 2009-11-28 1:24 ` Carles Pina i Estany 2009-11-28 1:47 ` Carles Pina i Estany 2009-11-28 12:21 ` Carles Pina i Estany 2009-11-28 19:09 ` Robert Millan 2009-11-29 1:04 ` Carles Pina i Estany 2009-11-29 1:17 ` Vladimir 'φ-coder/phcoder' Serbinenko 2009-12-03 23:22 ` Carles Pina i Estany
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.