Added guestfish 'echo' command. 1.0.16
authorRichard Jones <rjones@redhat.com>
Thu, 30 Apr 2009 19:11:04 +0000 (20:11 +0100)
committerRichard Jones <rjones@redhat.com>
Thu, 30 Apr 2009 19:11:04 +0000 (20:11 +0100)
fish/Makefile.am
fish/echo.c [new file with mode: 0644]
fish/fish.c
fish/fish.h

index 016e9b3..b3782ec 100644 (file)
@@ -21,6 +21,7 @@ guestfish_SOURCES = \
        alloc.c \
        cmds.c \
        completion.c \
        alloc.c \
        cmds.c \
        completion.c \
+       echo.c \
        edit.c \
        fish.c \
        fish.h
        edit.c \
        fish.c \
        fish.h
diff --git a/fish/echo.c b/fish/echo.c
new file mode 100644 (file)
index 0000000..b4b5cf1
--- /dev/null
@@ -0,0 +1,39 @@
+/* guestfish - the filesystem interactive shell
+ * Copyright (C) 2009 Red Hat Inc. 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fish.h"
+
+int
+do_echo (const char *cmd, int argc, char *argv[])
+{
+  int i;
+
+  for (i = 0; i < argc; ++i) {
+    if (i > 0) printf (" ");
+    printf ("%s", argv[i]);
+  }
+  printf ("\n");
+
+  return 0;
+}
index 894e351..fcafb5c 100644 (file)
@@ -523,6 +523,8 @@ issue_command (const char *cmd, char *argv[])
   else if (strcasecmp (cmd, "alloc") == 0 ||
           strcasecmp (cmd, "allocate") == 0)
     return do_alloc (cmd, argc, argv);
   else if (strcasecmp (cmd, "alloc") == 0 ||
           strcasecmp (cmd, "allocate") == 0)
     return do_alloc (cmd, argc, argv);
+  else if (strcasecmp (cmd, "echo") == 0)
+    return do_echo (cmd, argc, argv);
   else if (strcasecmp (cmd, "edit") == 0 ||
           strcasecmp (cmd, "vi") == 0 ||
           strcasecmp (cmd, "emacs") == 0)
   else if (strcasecmp (cmd, "edit") == 0 ||
           strcasecmp (cmd, "vi") == 0 ||
           strcasecmp (cmd, "emacs") == 0)
@@ -543,6 +545,8 @@ list_builtin_commands (void)
   printf ("%-20s %s\n",
          "alloc", "allocate an image");
   printf ("%-20s %s\n",
   printf ("%-20s %s\n",
          "alloc", "allocate an image");
   printf ("%-20s %s\n",
+         "echo", "display a line of text");
+  printf ("%-20s %s\n",
          "edit", "edit a file in the image");
 
   /* actions are printed after this (see list_commands) */
          "edit", "edit a file in the image");
 
   /* actions are printed after this (see list_commands) */
@@ -570,6 +574,11 @@ display_builtin_command (const char *cmd)
            "    <nn>M or <nn>MB  number of megabytes\n"
            "    <nn>G or <nn>GB  number of gigabytes\n"
            "    <nn>sects        number of 512 byte sectors\n");
            "    <nn>M or <nn>MB  number of megabytes\n"
            "    <nn>G or <nn>GB  number of gigabytes\n"
            "    <nn>sects        number of 512 byte sectors\n");
+  else if (strcasecmp (cmd, "echo") == 0)
+    printf ("echo - display a line of text\n"
+           "     echo [<params> ...]\n"
+           "\n"
+           "    This echos the parameters to the terminal.\n");
   else if (strcasecmp (cmd, "edit") == 0 ||
           strcasecmp (cmd, "vi") == 0 ||
           strcasecmp (cmd, "emacs") == 0)
   else if (strcasecmp (cmd, "edit") == 0 ||
           strcasecmp (cmd, "vi") == 0 ||
           strcasecmp (cmd, "emacs") == 0)
index c4450a7..40f1990 100644 (file)
@@ -47,6 +47,9 @@ extern char **do_completion (const char *text, int start, int end);
 /* in alloc.c */
 extern int do_alloc (const char *cmd, int argc, char *argv[]);
 
 /* in alloc.c */
 extern int do_alloc (const char *cmd, int argc, char *argv[]);
 
+/* in echo.c */
+extern int do_echo (const char *cmd, int argc, char *argv[]);
+
 /* in edit.c */
 extern int do_edit (const char *cmd, int argc, char *argv[]);
 
 /* in edit.c */
 extern int do_edit (const char *cmd, int argc, char *argv[]);