grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] improve formatting and content of target list in grub-probe help
@ 2013-12-07 13:27 Andrey Borzenkov
  2013-12-09 23:55 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Borzenkov @ 2013-12-07 13:27 UTC (permalink / raw)
  To: grub-devel

The number of targets in grub-probe became too large to fit in one line.
Change display to match this of grub-mkimage. Additionally sort the target
list to make it easier to read.

Table driven target list also makes sure new targets are always included in
help output automatically.

---
 util/grub-probe.c | 115 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 73 insertions(+), 42 deletions(-)

diff --git a/util/grub-probe.c b/util/grub-probe.c
index db68d61..291cbd2 100644
--- a/util/grub-probe.c
+++ b/util/grub-probe.c
@@ -72,9 +72,59 @@ enum {
   PRINT_DISK
 };
 
+static const char *targets[] =
+  {
+    [PRINT_FS]                 = "fs",
+    [PRINT_FS_UUID]            = "fs_uuid",
+    [PRINT_FS_LABEL]           = "fs_label",
+    [PRINT_DRIVE]              = "drive",
+    [PRINT_DEVICE]             = "device",
+    [PRINT_PARTMAP]            = "partmap",
+    [PRINT_ABSTRACTION]        = "abstraction",
+    [PRINT_CRYPTODISK_UUID]    = "cryptodisk_uuid",
+    [PRINT_HINT_STR]           = "hints_string",
+    [PRINT_BIOS_HINT]          = "bios_hints",
+    [PRINT_IEEE1275_HINT]      = "ieee1275_hints",
+    [PRINT_BAREMETAL_HINT]     = "baremetal_hints",
+    [PRINT_EFI_HINT]           = "efi_hints",
+    [PRINT_ARC_HINT]           = "arc_hints",
+    [PRINT_COMPATIBILITY_HINT] = "compatibility_hint",
+    [PRINT_MSDOS_PARTTYPE]     = "msdos_parttype",
+    [PRINT_GPT_PARTTYPE]       = "gpt_parttype",
+    [PRINT_ZERO_CHECK]         = "zero_check",
+    [PRINT_DISK]               = "disk",
+  };
+
 static int print = PRINT_FS;
 static unsigned int argument_is_device = 0;
 
+static char *
+get_targets_string (void)
+{
+  char **arr = xmalloc (sizeof (targets));
+  int len = 0;
+  char *str;
+  char *ptr;
+  unsigned i;
+
+  memcpy (arr, targets, sizeof (targets));
+  qsort (arr, ARRAY_SIZE (targets), sizeof (char *), grub_qsort_strcmp);
+  for (i = 0; i < ARRAY_SIZE (targets); i++)
+    len += strlen (targets[i]) + 2;
+  ptr = str = xmalloc (len);
+  for (i = 0; i < ARRAY_SIZE (targets); i++)
+    {
+      strcpy (ptr, arr[i]);
+      ptr += strlen (arr[i]);
+      *ptr++ = ',';
+      *ptr++ = ' ';
+    }
+  ptr[-2] = '\0';
+  free (arr);
+
+  return str;
+}
+
 static void
 do_print (const char *x)
 {
@@ -655,8 +705,7 @@ static struct argp_option options[] = {
    N_("given argument is a system device, not a path"), 0},
   {"device-map",  'm', N_("FILE"), 0,
    N_("use FILE as the device map [default=%s]"), 0},
-  {"target",  't', "(fs|fs_uuid|fs_label|drive|device|partmap|abstraction|cryptodisk_uuid|msdos_parttype)", 0,
-   N_("print filesystem module, GRUB drive, system device, partition map module, abstraction module or cryptographic container UUID [default=fs]"), 0},
+  {"target",  't', N_("TARGET"), 0, 0, 0},
   {"verbose",     'v', 0,      0, N_("print verbose messages."), 0},
   { 0, 0, 0, 0, 0, 0 }
 };
@@ -669,6 +718,16 @@ help_filter (int key, const char *text, void *input __attribute__ ((unused)))
       case 'm':
         return xasprintf (text, DEFAULT_DEVICE_MAP);
 
+      case 't':
+	{
+	  char *ret, *t = get_targets_string ();
+
+	  ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"),
+			    _("available targets:"), t, targets[print]);
+	  free (t);
+	  return ret;
+	}
+
       default:
         return (char *) text;
     }
@@ -704,46 +763,18 @@ argp_parser (int key, char *arg, struct argp_state *state)
       break;
 
     case 't':
-      if (!strcmp (arg, "fs"))
-	print = PRINT_FS;
-      else if (!strcmp (arg, "fs_uuid"))
-	print = PRINT_FS_UUID;
-      else if (!strcmp (arg, "fs_label"))
-	print = PRINT_FS_LABEL;
-      else if (!strcmp (arg, "drive"))
-	print = PRINT_DRIVE;
-      else if (!strcmp (arg, "device"))
-	print = PRINT_DEVICE;
-      else if (!strcmp (arg, "partmap"))
-	print = PRINT_PARTMAP;
-      else if (!strcmp (arg, "abstraction"))
-	print = PRINT_ABSTRACTION;
-      else if (!strcmp (arg, "cryptodisk_uuid"))
-	print = PRINT_CRYPTODISK_UUID;
-      else if (!strcmp (arg, "msdos_parttype"))
-	print = PRINT_MSDOS_PARTTYPE;
-      else if (!strcmp (arg, "gpt_parttype"))
-	print = PRINT_GPT_PARTTYPE;
-      else if (!strcmp (arg, "hints_string"))
-	print = PRINT_HINT_STR;
-      else if (!strcmp (arg, "bios_hints"))
-	print = PRINT_BIOS_HINT;
-      else if (!strcmp (arg, "ieee1275_hints"))
-	print = PRINT_IEEE1275_HINT;
-      else if (!strcmp (arg, "baremetal_hints"))
-	print = PRINT_BAREMETAL_HINT;
-      else if (!strcmp (arg, "efi_hints"))
-	print = PRINT_EFI_HINT;
-      else if (!strcmp (arg, "arc_hints"))
-	print = PRINT_ARC_HINT;
-      else if (!strcmp (arg, "compatibility_hint"))
-	print = PRINT_COMPATIBILITY_HINT;
-      else if (strcmp (arg, "zero_check") == 0)
-	print = PRINT_ZERO_CHECK;
-      else if (!strcmp (arg, "disk"))
-	print = PRINT_DISK;
-      else
-	argp_usage (state);
+      {
+	int i;
+
+	for (i = PRINT_FS; i < ARRAY_SIZE (targets); i++)
+	  if (!strcmp (arg, targets[i]))
+	    {
+	      print = i;
+	      break;
+	    }
+	if (i == ARRAY_SIZE (targets))
+	  argp_usage (state);
+      }
       break;
 
     case '0':
-- 
tg: (b2de394..) u/grub-probe-gpt-help (depends on: master)


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] improve formatting and content of target list in grub-probe help
  2013-12-07 13:27 [PATCH] improve formatting and content of target list in grub-probe help Andrey Borzenkov
@ 2013-12-09 23:55 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-12-10  5:48   ` Andrey Borzenkov
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-12-09 23:55 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 149 bytes --]

On 07.12.2013 14:27, Andrey Borzenkov wrote:
> +	  ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"),
where does "print" come from?h


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] improve formatting and content of target list in grub-probe help
  2013-12-09 23:55 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-12-10  5:48   ` Andrey Borzenkov
  2013-12-10  8:09     ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Borzenkov @ 2013-12-10  5:48 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 600 bytes --]

В Tue, 10 Dec 2013 00:55:06 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> On 07.12.2013 14:27, Andrey Borzenkov wrote:
> > +	  ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"),
> where does "print" come from?h
> 

You mean "print" as in "print TARGET" or as in `targets[print]'?

+         ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"),
+                           _("available targets:"), t, targets[print]);

The latter has always been there:

 static int print = PRINT_FS;
 static unsigned int argument_is_device = 0;

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] improve formatting and content of target list in grub-probe help
  2013-12-10  5:48   ` Andrey Borzenkov
@ 2013-12-10  8:09     ` Vladimir 'φ-coder/phcoder' Serbinenko
  2013-12-10 10:48       ` Andrey Borzenkov
  0 siblings, 1 reply; 5+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-12-10  8:09 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 862 bytes --]

On 10.12.2013 06:48, Andrey Borzenkov wrote:
> В Tue, 10 Dec 2013 00:55:06 +0100
> Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> 
>> On 07.12.2013 14:27, Andrey Borzenkov wrote:
>>> +	  ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"),
>> where does "print" come from?h
>>
> 
> You mean "print" as in "print TARGET" or as in `targets[print]'?
> 
> +         ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"),
> +                           _("available targets:"), t, targets[print]);
> 
> The latter has always been there:
> 
I mean former
>  static int print = PRINT_FS;
>  static unsigned int argument_is_device = 0;
> 
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] improve formatting and content of target list in grub-probe help
  2013-12-10  8:09     ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-12-10 10:48       ` Andrey Borzenkov
  0 siblings, 0 replies; 5+ messages in thread
From: Andrey Borzenkov @ 2013-12-10 10:48 UTC (permalink / raw)
  To: grub-devel

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

В Tue, 10 Dec 2013 09:09:15 +0100
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> On 10.12.2013 06:48, Andrey Borzenkov wrote:
> > В Tue, 10 Dec 2013 00:55:06 +0100
> > Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:
> > 
> >> On 07.12.2013 14:27, Andrey Borzenkov wrote:
> >>> +	  ret = xasprintf ("%s\n%s %s [default=%s]", _("print TARGET"),
> >> where does "print" come from?h
> >>
> > 
> > You mean "print" as in "print TARGET" or as in `targets[print]'?
> > 
> > 
> I mean former

The original help was "print filesystem module, GRUB drive ..." but it
was too long. As it is mostly internal tool, intention was to provide
reference for possible values for --target (I personally do not
remember them all) rather than explaining what they are.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-12-10 10:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-07 13:27 [PATCH] improve formatting and content of target list in grub-probe help Andrey Borzenkov
2013-12-09 23:55 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-10  5:48   ` Andrey Borzenkov
2013-12-10  8:09     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-10 10:48       ` Andrey Borzenkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).