]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* util/grub-fstest.c (cmd_cat): New function.
authorColin Watson <cjwatson@ubuntu.com>
Tue, 17 May 2011 17:03:59 +0000 (18:03 +0100)
committerColin Watson <cjwatson@ubuntu.com>
Tue, 17 May 2011 17:03:59 +0000 (18:03 +0100)
(fstest): Handle CMD_CAT.
(options): Add cat.
(argp_parser): Handle cat.

ChangeLog
util/grub-fstest.c

index 47d23d811b12005042d3bdb8f2bdd4a41ac6ab7d..4f17525b6f53205f77151c3571de103b075c83e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-05-17  Colin Watson  <cjwatson@ubuntu.com>
+
+       * util/grub-fstest.c (cmd_cat): New function.
+       (fstest): Handle CMD_CAT.
+       (options): Add cat.
+       (argp_parser): Handle cat.
+
 2011-05-17  Colin Watson  <cjwatson@ubuntu.com>
 
        * Makefile.util.def (grub-bin2h): Don't install.
index 293bdf74a5885c50372c7d2dba5a419fbca7fe93..f253a96f61cd1820f63df4c6497f37698a3ebeb2 100644 (file)
@@ -54,12 +54,15 @@ execute_command (char *name, int n, char **args)
   return (cmd->func) (cmd, n, args);
 }
 
-#define CMD_LS          1
-#define CMD_CP          2
-#define CMD_CMP         3
-#define CMD_HEX         4
-#define CMD_CRC         6
-#define CMD_BLOCKLIST   7
+enum {
+  CMD_LS = 1,
+  CMD_CP,
+  CMD_CAT,
+  CMD_CMP,
+  CMD_HEX,
+  CMD_CRC,
+  CMD_BLOCKLIST
+};
 
 #define BUF_SIZE  32256
 
@@ -182,6 +185,26 @@ cmd_cp (char *src, char *dest)
   fclose (ff);
 }
 
+static void
+cmd_cat (char *src)
+{
+  auto int cat_hook (grub_off_t ofs, char *buf, int len);
+  int cat_hook (grub_off_t ofs, char *buf, int len)
+  {
+    (void) ofs;
+
+    if ((int) fwrite (buf, 1, len, stdout) != len)
+      {
+       grub_util_error (_("write error"));
+       return 1;
+      }
+
+    return 0;
+  }
+
+  read_file (src, cat_hook);
+}
+
 static void
 cmd_cmp (char *src, char *dest)
 {
@@ -321,6 +344,9 @@ fstest (int n, char **args)
     case CMD_CP:
       cmd_cp (args[0], args[1]);
       break;
+    case CMD_CAT:
+      cmd_cat (args[0]);
+      break;
     case CMD_CMP:
       cmd_cmp (args[0], args[1]);
       break;
@@ -356,6 +382,7 @@ static struct argp_option options[] = {
   {0,          0, 0      , OPTION_DOC, N_("Commands:"), 1},
   {N_("ls PATH"),  0, 0      , OPTION_DOC, N_("List files in PATH."), 1},
   {N_("cp FILE LOCAL"),  0, 0, OPTION_DOC, N_("Copy FILE to local file LOCAL."), 1},
+  {N_("cat FILE"), 0, 0      , OPTION_DOC, N_("Copy FILE to standard output."), 1},
   {N_("cmp FILE LOCAL"), 0, 0, OPTION_DOC, N_("Compare FILE with local file LOCAL."), 1},
   {N_("hex FILE"), 0, 0      , OPTION_DOC, N_("Hex dump FILE."), 1},
   {N_("crc FILE"), 0, 0     , OPTION_DOC, N_("Get crc32 checksum of FILE."), 1},
@@ -468,6 +495,11 @@ argp_parser (int key, char *arg, struct argp_state *state)
          cmd = CMD_CP;
           nparm = 2;
        }
+      else if (!grub_strcmp (arg, "cat"))
+       {
+         cmd = CMD_CAT;
+         nparm = 1;
+       }
       else if (!grub_strcmp (arg, "cmp"))
        {
          cmd = CMD_CMP;