diff --git a/align/Makefile.am b/align/Makefile.am index edae4b976..2b4dee486 100644 --- a/align/Makefile.am +++ b/align/Makefile.am @@ -37,6 +37,8 @@ SHARED_SOURCE_FILES = \ ../df/parallel.c \ ../df/parallel.h \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/align/scan.c b/align/scan.c index 9575eda51..4171f8c35 100644 --- a/align/scan.c +++ b/align/scan.c @@ -40,6 +40,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "parallel.h" #include "domains.h" diff --git a/cat/Makefile.am b/cat/Makefile.am index a2ca16fcb..266e1c589 100644 --- a/cat/Makefile.am +++ b/cat/Makefile.am @@ -41,6 +41,8 @@ CLEANFILES = \ bin_PROGRAMS = virt-cat virt-filesystems virt-log virt-ls SHARED_SOURCE_FILES = \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/cat/cat.c b/cat/cat.c index 9039f7f67..9c8d1a9b8 100644 --- a/cat/cat.c +++ b/cat/cat.c @@ -32,6 +32,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "windows.h" /* Currently open libguestfs handle. */ diff --git a/cat/filesystems.c b/cat/filesystems.c index ab24f2d13..6c8ce01b9 100644 --- a/cat/filesystems.c +++ b/cat/filesystems.c @@ -36,6 +36,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* These globals are shared with options.c. */ guestfs_h *g; diff --git a/cat/log.c b/cat/log.c index bacd8b6af..0968ef57e 100644 --- a/cat/log.c +++ b/cat/log.c @@ -37,6 +37,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* Currently open libguestfs handle. */ guestfs_h *g; diff --git a/cat/ls.c b/cat/ls.c index 282996f05..890315914 100644 --- a/cat/ls.c +++ b/cat/ls.c @@ -37,6 +37,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "visit.h" /* Currently open libguestfs handle. */ diff --git a/df/Makefile.am b/df/Makefile.am index 74a039168..cbfb160cc 100644 --- a/df/Makefile.am +++ b/df/Makefile.am @@ -32,6 +32,8 @@ bin_PROGRAMS = virt-df SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/df/main.c b/df/main.c index f1d874aba..3f9296f28 100644 --- a/df/main.c +++ b/df/main.c @@ -38,6 +38,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "domains.h" #include "parallel.h" #include "virt-df.h" diff --git a/diff/Makefile.am b/diff/Makefile.am index 942177115..87d18c523 100644 --- a/diff/Makefile.am +++ b/diff/Makefile.am @@ -31,6 +31,8 @@ bin_PROGRAMS = virt-diff SHARED_SOURCE_FILES = \ ../cat/visit.h \ ../cat/visit.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/diff/diff.c b/diff/diff.c index 2ac71eb5e..e0eea57b8 100644 --- a/diff/diff.c +++ b/diff/diff.c @@ -39,6 +39,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "visit.h" /* Internal tree structure built for each guest. */ diff --git a/edit/Makefile.am b/edit/Makefile.am index b4dd8a140..709bfcae3 100644 --- a/edit/Makefile.am +++ b/edit/Makefile.am @@ -30,6 +30,8 @@ bin_PROGRAMS = virt-edit SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/file-edit.h \ ../fish/file-edit.c \ diff --git a/edit/edit.c b/edit/edit.c index 8a0c00c3c..6f3e38868 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -37,6 +37,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "windows.h" #include "file-edit.h" diff --git a/fish/Makefile.am b/fish/Makefile.am index aa0ef7438..1e3c1d90f 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -72,6 +72,8 @@ EXTRA_DIST = \ # files must not include other guestfish files. SHARED_SOURCE_FILES = \ config.c \ + display-options.h \ + display-options.c \ domain.c \ inspect.c \ keys.c \ diff --git a/fish/display-options.c b/fish/display-options.c new file mode 100644 index 000000000..18f7700f4 --- /dev/null +++ b/fish/display-options.c @@ -0,0 +1,66 @@ +/* libguestfs - implement --short-options and --long-options + * Copyright (C) 2010-2016 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * This file contains common code used to implement I<--short-options> + * and I<--long-options> in C virt tools. (The equivalent for + * OCaml virt tools is implemented by F). + * + * These "hidden" options are used to implement bash tab completion. + */ + +#include + +#include +#include +#include +#include + +#include "guestfs-internal-all.h" +#include "display-options.h" + +/** + * Implements the internal C> flag, which just + * lists out the short options available. Used by bash completion. + */ +void +display_short_options (const char *format) +{ + while (*format) { + if (*format != ':') + printf ("-%c\n", *format); + ++format; + } + exit (EXIT_SUCCESS); +} + +/** + * Implements the internal C> flag, which just + * lists out the long options available. Used by bash completion. + */ +void +display_long_options (const struct option *long_options) +{ + while (long_options->name) { + if (STRNEQ (long_options->name, "long-options") && + STRNEQ (long_options->name, "short-options")) + printf ("--%s\n", long_options->name); + long_options++; + } + exit (EXIT_SUCCESS); +} diff --git a/fish/display-options.h b/fish/display-options.h new file mode 100644 index 000000000..f295d6d97 --- /dev/null +++ b/fish/display-options.h @@ -0,0 +1,25 @@ +/* libguestfs - implement --short-options and --long-options + * Copyright (C) 2010-2016 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef DISPLAY_OPTIONS_H +#define DISPLAY_OPTIONS_H + +extern void display_short_options (const char *) __attribute__((noreturn)); +extern void display_long_options (const struct option *) __attribute__((noreturn)); + +#endif /* DISPLAY_OPTIONS_H */ diff --git a/fish/fish.c b/fish/fish.c index 302b52f44..f20fbc07f 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -48,6 +48,7 @@ #include "fish.h" #include "options.h" +#include "display-options.h" #include "progress.h" #include "c-ctype.h" diff --git a/fish/options.c b/fish/options.c index 653be24df..96db212c4 100644 --- a/fish/options.c +++ b/fish/options.c @@ -367,34 +367,3 @@ free_mps (struct mp *mp) free (mp); } - -/** - * Implements the internal C> flag, which just - * lists out the short options available. Used by bash completion. - */ -void -display_short_options (const char *format) -{ - while (*format) { - if (*format != ':') - printf ("-%c\n", *format); - ++format; - } - exit (EXIT_SUCCESS); -} - -/** - * Implements the internal C> flag, which just - * lists out the long options available. Used by bash completion. - */ -void -display_long_options (const struct option *long_options) -{ - while (long_options->name) { - if (STRNEQ (long_options->name, "long-options") && - STRNEQ (long_options->name, "short-options")) - printf ("--%s\n", long_options->name); - long_options++; - } - exit (EXIT_SUCCESS); -} diff --git a/fish/options.h b/fish/options.h index bbe38aa74..89afe9e93 100644 --- a/fish/options.h +++ b/fish/options.h @@ -22,7 +22,6 @@ #include #include -#include #include "guestfs-internal-frontend.h" @@ -140,8 +139,6 @@ extern char add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive); extern void mount_mps (struct mp *mp); extern void free_drives (struct drv *drv); extern void free_mps (struct mp *mp); -extern void display_short_options (const char *) __attribute__((noreturn)); -extern void display_long_options (const struct option *) __attribute__((noreturn)); #define OPTION_a \ do { \ diff --git a/format/Makefile.am b/format/Makefile.am index 9951ba1bb..d955e352f 100644 --- a/format/Makefile.am +++ b/format/Makefile.am @@ -30,6 +30,8 @@ bin_PROGRAMS = virt-format SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/format/format.c b/format/format.c index 5933aeb3b..0ce4ac452 100644 --- a/format/format.c +++ b/format/format.c @@ -33,6 +33,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* These globals are shared with options.c. */ guestfs_h *g; diff --git a/fuse/Makefile.am b/fuse/Makefile.am index da0e636f4..c70f6498b 100644 --- a/fuse/Makefile.am +++ b/fuse/Makefile.am @@ -40,6 +40,8 @@ bin_PROGRAMS = \ # between guestfish and guestmount. SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/fuse/guestmount.c b/fuse/guestmount.c index dccc7ba6d..9da96d29d 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -41,6 +41,7 @@ #include "ignore-value.h" #include "options.h" +#include "display-options.h" static int write_pipe_fd (int fd); static int write_pid_file (const char *pid_file, pid_t pid); diff --git a/inspector/Makefile.am b/inspector/Makefile.am index cdaedf3e4..af596bff1 100644 --- a/inspector/Makefile.am +++ b/inspector/Makefile.am @@ -58,6 +58,8 @@ bin_PROGRAMS = virt-inspector SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/inspector/inspector.c b/inspector/inspector.c index 4c027df16..9a8fa4d49 100644 --- a/inspector/inspector.c +++ b/inspector/inspector.c @@ -39,6 +39,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* Currently open libguestfs handle. */ guestfs_h *g; diff --git a/make-fs/Makefile.am b/make-fs/Makefile.am index 2bec12fe1..ea723afd0 100644 --- a/make-fs/Makefile.am +++ b/make-fs/Makefile.am @@ -29,9 +29,11 @@ CLEANFILES = \ bin_PROGRAMS = virt-make-fs SHARED_SOURCE_FILES = \ + ../fish/display-options.h \ + ../fish/display-options.c \ + ../fish/domain.c \ ../fish/options.h \ ../fish/options.c \ - ../fish/domain.c \ ../fish/uri.c virt_make_fs_SOURCES = \ diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c index 2f9137071..ade2e60af 100644 --- a/make-fs/make-fs.c +++ b/make-fs/make-fs.c @@ -40,6 +40,7 @@ #include "xstrtol.h" #include "options.h" +#include "display-options.h" guestfs_h *g; const char *libvirt_uri; diff --git a/rescue/Makefile.am b/rescue/Makefile.am index 156873020..58564dc0b 100644 --- a/rescue/Makefile.am +++ b/rescue/Makefile.am @@ -31,6 +31,8 @@ bin_PROGRAMS = virt-rescue SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/rescue/rescue.c b/rescue/rescue.c index 37b82f69e..0f83f045c 100644 --- a/rescue/rescue.c +++ b/rescue/rescue.c @@ -35,6 +35,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" static void add_scratch_disks (int n, struct drv **drvs); static void do_suggestion (struct drv *drvs);