From 78d2523ec8997679f7fca810de60620df4001e16 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Sat, 24 Apr 2010 09:10:28 +0100 Subject: [PATCH] fish: Add 'man' command which opens the manual. --- fish/Makefile.am | 1 + fish/fish.c | 16 ++++++++++++-- fish/fish.h | 4 ++++ fish/guestfish.pod | 11 ++++++++-- fish/man.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ po/POTFILES.in | 1 + recipes/clone.example | 3 ++- 7 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 fish/man.c diff --git a/fish/Makefile.am b/fish/Makefile.am index c25a602..3dc1a1e 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -44,6 +44,7 @@ guestfish_SOURCES = \ fish.h \ glob.c \ lcd.c \ + man.c \ more.c \ prep.c \ rc.c \ diff --git a/fish/fish.c b/fish/fish.c index 54989fc..a36ec09 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -622,7 +622,8 @@ script (int prompt) "Welcome to guestfish, the libguestfs filesystem interactive shell for\n" "editing virtual machine filesystems.\n" "\n" - "Type: 'help' for help with commands\n" + "Type: 'help' for a list of commands\n" + " 'man' to read the manual\n" " 'quit' to quit the shell\n" "\n")); @@ -943,6 +944,9 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) r = do_lcd (cmd, argc, argv); else if (STRCASEEQ (cmd, "glob")) r = do_glob (cmd, argc, argv); + else if (STRCASEEQ (cmd, "man") || + STRCASEEQ (cmd, "manual")) + r = do_man (cmd, argc, argv); else if (STRCASEEQ (cmd, "more") || STRCASEEQ (cmd, "less")) r = do_more (cmd, argc, argv); @@ -982,10 +986,12 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) void list_builtin_commands (void) { - /* help and quit should appear at the top */ + /* help, man and quit should appear at the top */ printf ("%-20s %s\n", "help", _("display a list of commands or help on a command")); printf ("%-20s %s\n", + "man", _("read the manual")); + printf ("%-20s %s\n", "quit", _("quit guestfish")); printf ("%-20s %s\n", @@ -1070,6 +1076,12 @@ display_builtin_command (const char *cmd) " Glob runs with wildcards expanded in any\n" " command args. Note that the command is run repeatedly\n" " once for each expanded argument.\n")); + else if (STRCASEEQ (cmd, "man") || + STRCASEEQ (cmd, "manual")) + printf (_("man - read the manual\n" + " man\n" + "\n" + " Opens the manual page for guestfish.\n")); else if (STRCASEEQ (cmd, "help")) printf (_("help - display a list of commands or help on a command\n" " help cmd\n" diff --git a/fish/fish.h b/fish/fish.h index 13efa9a..8cdce26 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -100,6 +100,9 @@ extern int do_lcd (const char *cmd, int argc, char *argv[]); /* in glob.c */ extern int do_glob (const char *cmd, int argc, char *argv[]); +/* in man.c */ +extern int do_man (const char *cmd, int argc, char *argv[]); + /* in more.c */ extern int do_more (const char *cmd, int argc, char *argv[]); @@ -136,6 +139,7 @@ extern char *try_tilde_expansion (char *path); "edit", "vi", "emacs", \ "lcd", \ "glob", \ + "man", "manual", \ "more", "less", \ "reopen", \ "sparse", \ diff --git a/fish/guestfish.pod b/fish/guestfish.pod index b4cde81..cc974d7 100644 --- a/fish/guestfish.pod +++ b/fish/guestfish.pod @@ -27,10 +27,11 @@ guestfish - the libguestfs Filesystem Interactive SHell Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. - Type: 'help' for help with commands + Type: 'help' for a list of commands + 'man' to read the manual 'quit' to quit the shell - > help + > man =head2 From shell scripts @@ -679,6 +680,12 @@ itself. Note that C won't do what you might expect. +=head2 man | manual + + man + +Opens the manual page for guestfish. + =head2 more | less more filename diff --git a/fish/man.c b/fish/man.c new file mode 100644 index 0000000..e28e892 --- /dev/null +++ b/fish/man.c @@ -0,0 +1,58 @@ +/* guestfish - the filesystem interactive shell + * Copyright (C) 2010 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 + +#include "fish.h" + +/* guestfish man command */ + +int +do_man (const char *cmd, int argc, char *argv[]) +{ + if (argc != 0) { + fprintf (stderr, _("use 'man' without parameters to open the manual\n")); + return -1; + } + + /* We have to restore SIGPIPE to the default action around the + * external 'man' command to avoid the warning 'gzip: stdout: Broken pipe'. + */ + struct sigaction sa, old_sa; + memset (&sa, 0, sizeof sa); + sa.sa_handler = SIG_DFL; + sigaction (SIGPIPE, &sa, &old_sa); + + int r = system ("man 1 guestfish"); + + sigaction (SIGPIPE, &old_sa, NULL); + + if (r != 0) + return -1; + if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) { + fprintf (stderr, _("the external 'man' program failed\n")); + return -1; + } + + return 0; +} diff --git a/po/POTFILES.in b/po/POTFILES.in index 8cf6e16..b91bde0 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -75,6 +75,7 @@ fish/edit.c fish/fish.c fish/glob.c fish/lcd.c +fish/man.c fish/more.c fish/prep.c fish/rc.c diff --git a/recipes/clone.example b/recipes/clone.example index 3ee96c5..70be57d 100644 --- a/recipes/clone.example +++ b/recipes/clone.example @@ -8,7 +8,8 @@ $ guestfish -a /tmp/new.img -m /dev/sda1 Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. -Type: 'help' for help with commands +Type: 'help' for a list of commands + 'man' to read the manual 'quit' to quit the shell > cat /etc/resolv.conf -- 1.8.3.1