nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0042-util-grub-install.c-List-available-targets.patch

0dc71c
From d25ddbcafa537525f606938df0e500c50a5e93e1 Mon Sep 17 00:00:00 2001
0dc71c
From: Vladimir Serbinenko <phcoder@gmail.com>
0dc71c
Date: Fri, 24 Jan 2014 18:09:25 +0100
0dc71c
Subject: [PATCH 042/143] 	* util/grub-install.c: List available targets.
0dc71c
0dc71c
---
0dc71c
 ChangeLog                   |  4 ++++
0dc71c
 include/grub/util/install.h |  2 ++
0dc71c
 util/grub-install-common.c  | 30 ++++++++++++++++++++++++++++++
0dc71c
 util/grub-install.c         | 10 ++++++++--
0dc71c
 4 files changed, 44 insertions(+), 2 deletions(-)
0dc71c
0dc71c
diff --git a/ChangeLog b/ChangeLog
0dc71c
index eee8e78..20e8baa 100644
0dc71c
--- a/ChangeLog
0dc71c
+++ b/ChangeLog
0dc71c
@@ -1,3 +1,7 @@
0dc71c
+2014-01-24  Vladimir Serbinenko  <phcoder@gmail.com>
0dc71c
+
0dc71c
+	* util/grub-install.c: List available targets.
0dc71c
+
0dc71c
 2014-01-23  Colin Watson  <cjwatson@ubuntu.com>
0dc71c
 
0dc71c
 	* util/grub-install.c (write_to_disk): Add an info message.
0dc71c
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
0dc71c
index bc987aa..aedcd29 100644
0dc71c
--- a/include/grub/util/install.h
0dc71c
+++ b/include/grub/util/install.h
0dc71c
@@ -138,6 +138,8 @@ grub_install_get_platform_cpu (enum grub_install_plat platid);
0dc71c
 const char *
0dc71c
 grub_install_get_platform_platform (enum grub_install_plat platid);
0dc71c
 
0dc71c
+char *
0dc71c
+grub_install_get_platforms_string (void);
0dc71c
 
0dc71c
 typedef enum {
0dc71c
   GRUB_COMPRESSION_AUTO,
0dc71c
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
0dc71c
index 6ea0a8e..c8bedcb 100644
0dc71c
--- a/util/grub-install-common.c
0dc71c
+++ b/util/grub-install-common.c
0dc71c
@@ -668,6 +668,36 @@ static struct
0dc71c
   }; 
0dc71c
 
0dc71c
 char *
0dc71c
+grub_install_get_platforms_string (void)
0dc71c
+{
0dc71c
+  char **arr = xmalloc (sizeof (char *) * ARRAY_SIZE (platforms));
0dc71c
+  int platform_strins_len = 0;
0dc71c
+  char *platforms_string;
0dc71c
+  char *ptr;
0dc71c
+  unsigned i;
0dc71c
+  for (i = 0; i < ARRAY_SIZE (platforms); i++)
0dc71c
+    {
0dc71c
+      arr[i] = xasprintf ("%s-%s", platforms[i].cpu,
0dc71c
+			  platforms[i].platform);
0dc71c
+      platform_strins_len += strlen (arr[i]) + 2;
0dc71c
+    }
0dc71c
+  ptr = platforms_string = xmalloc (platform_strins_len);
0dc71c
+  qsort (arr, ARRAY_SIZE (platforms), sizeof (char *), grub_qsort_strcmp);
0dc71c
+  for (i = 0; i < ARRAY_SIZE (platforms); i++)
0dc71c
+    {
0dc71c
+      strcpy (ptr, arr[i]);
0dc71c
+      ptr += strlen (arr[i]);
0dc71c
+      *ptr++ = ',';
0dc71c
+      *ptr++ = ' ';
0dc71c
+      free (arr[i]);
0dc71c
+    }
0dc71c
+  ptr[-2] = 0;
0dc71c
+  free (arr);
0dc71c
+ 
0dc71c
+  return platforms_string;
0dc71c
+}
0dc71c
+
0dc71c
+char *
0dc71c
 grub_install_get_platform_name (enum grub_install_plat platid)
0dc71c
 {
0dc71c
   return xasprintf ("%s-%s", platforms[platid].cpu,
0dc71c
diff --git a/util/grub-install.c b/util/grub-install.c
0dc71c
index 787dc90..2e6226a 100644
0dc71c
--- a/util/grub-install.c
0dc71c
+++ b/util/grub-install.c
0dc71c
@@ -256,7 +256,7 @@ static struct argp_option options[] = {
0dc71c
    OPTION_HIDDEN, 0, 2},
0dc71c
   {"target", OPTION_TARGET, N_("TARGET"),
0dc71c
    /* TRANSLATORS: "TARGET" as in "target platform".  */
0dc71c
-   0, N_("install GRUB for TARGET platform [default=%s]"), 2},
0dc71c
+   0, N_("install GRUB for TARGET platform [default=%s]; available targets: %s"), 2},
0dc71c
   {"grub-setup", OPTION_SETUP, "FILE", OPTION_HIDDEN, 0, 2},
0dc71c
   {"grub-mkrelpath", OPTION_MKRELPATH, "FILE", OPTION_HIDDEN, 0, 2},
0dc71c
   {"grub-mkdevicemap", OPTION_MKDEVICEMAP, "FILE", OPTION_HIDDEN, 0, 2},
0dc71c
@@ -340,7 +340,13 @@ help_filter (int key, const char *text, void *input __attribute__ ((unused)))
0dc71c
     case OPTION_BOOT_DIRECTORY:
0dc71c
       return xasprintf (text, GRUB_DIR_NAME, GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME);
0dc71c
     case OPTION_TARGET:
0dc71c
-      return xasprintf (text, get_default_platform ());
0dc71c
+      {
0dc71c
+	char *plats = grub_install_get_platforms_string ();
0dc71c
+	char *ret;
0dc71c
+	ret = xasprintf (text, get_default_platform (), plats);
0dc71c
+	free (plats);
0dc71c
+	return ret;
0dc71c
+      }
0dc71c
     case ARGP_KEY_HELP_POST_DOC:
0dc71c
       return xasprintf (text, program_name, GRUB_BOOT_DIR_NAME "/" GRUB_DIR_NAME);
0dc71c
     default:
0dc71c
-- 
0dc71c
1.9.3
0dc71c