From 4581eb2523eeb4d094d53af0555cb7e0f760ae2d Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 30 Apr 2009 20:11:04 +0100 Subject: [PATCH] Added guestfish 'echo' command. --- fish/Makefile.am | 1 + fish/echo.c | 39 +++++++++++++++++++++++++++++++++++++++ fish/fish.c | 9 +++++++++ fish/fish.h | 3 +++ 4 files changed, 52 insertions(+) create mode 100644 fish/echo.c diff --git a/fish/Makefile.am b/fish/Makefile.am index 016e9b3..b3782ec 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -21,6 +21,7 @@ guestfish_SOURCES = \ alloc.c \ cmds.c \ completion.c \ + echo.c \ edit.c \ fish.c \ fish.h diff --git a/fish/echo.c b/fish/echo.c new file mode 100644 index 0000000..b4b5cf1 --- /dev/null +++ b/fish/echo.c @@ -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 + +#include +#include +#include + +#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; +} diff --git a/fish/fish.c b/fish/fish.c index 894e351..fcafb5c 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -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, "echo") == 0) + return do_echo (cmd, argc, argv); 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", + "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) */ @@ -570,6 +574,11 @@ display_builtin_command (const char *cmd) " M or MB number of megabytes\n" " G or GB number of gigabytes\n" " sects number of 512 byte sectors\n"); + else if (strcasecmp (cmd, "echo") == 0) + printf ("echo - display a line of text\n" + " echo [ ...]\n" + "\n" + " This echos the parameters to the terminal.\n"); else if (strcasecmp (cmd, "edit") == 0 || strcasecmp (cmd, "vi") == 0 || strcasecmp (cmd, "emacs") == 0) diff --git a/fish/fish.h b/fish/fish.h index c4450a7..40f1990 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -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 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[]); -- 1.8.3.1