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
=== 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  <car...@pina.cat>
 
+	* lib/arg.c (AVAILABLE_CHARS_LINE): New macro.
+	(grub_arg_show_help): Cut the help string dynamically.
+
+2009-12-27  Carles Pina i Estany  <car...@pina.cat>
+
 	* 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)
 	    {

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to