/* * Copyright 2005-2019 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2014 Mike Frysinger - */ #ifndef _APPLETS_H_ #define _APPLETS_H_ 1 #if defined(__sun) && defined(__SVR4) /* workaround non-const defined name in option struct, such that we * don't get a zillion of warnings */ #define no_argument 0 #define required_argument 1 #define optional_argument 2 struct option { const char *name; int has_arg; int *flag; int val; }; extern int getopt_long(int, char * const *, const char *, const struct option *, int *); #else # include #endif #include #include #include "xarray.h" /* applet prototypes */ typedef int (*APPLET)(int, char **); #define DECLARE_APPLET(applet) \ extern int applet##_main(int, char **) __attribute__((weak)); DECLARE_APPLET(q) DECLARE_APPLET(qcheck) DECLARE_APPLET(qdepends) DECLARE_APPLET(qfile) DECLARE_APPLET(qlist) DECLARE_APPLET(qlop) DECLARE_APPLET(qsearch) DECLARE_APPLET(qsize) DECLARE_APPLET(qtbz2) DECLARE_APPLET(quse) DECLARE_APPLET(qxpak) DECLARE_APPLET(qpkg) DECLARE_APPLET(qgrep) DECLARE_APPLET(qatom) DECLARE_APPLET(qmerge) DECLARE_APPLET(qkeyword) /*DECLARE_APPLET(qglsa) disable */ DECLARE_APPLET(qtegrity) #undef DECLARE_APPLET static const struct applet_t { const char *name; APPLET func; const char *opts; const char *desc; } applets[] = { /* q must always be the first applet */ {"q", q_main, " ", "virtual applet"}, {"qatom", qatom_main, "", "split atom strings"}, {"qkeyword", qkeyword_main, " ", "list packages based on keywords"}, {"qcheck", qcheck_main, "", "verify integrity of installed packages"}, {"qdepends", qdepends_main, "", "show dependency info"}, {"qfile", qfile_main, "", "list all pkgs owning files"}, /* {"qglsa", qglsa_main, " ", "check GLSAs against system"}, */ {"qgrep", qgrep_main, " [pkg ...]", "grep in ebuilds"}, {"qlist", qlist_main, "", "list files owned by pkgname"}, {"qlop", qlop_main, "", "emerge log analyzer"}, {"qmerge", qmerge_main, "", "fetch and merge binary package"}, {"qpkg", qpkg_main, "", "manipulate Gentoo binpkgs"}, {"qsearch", qsearch_main, "", "search pkgname/desc"}, {"qsize", qsize_main, "", "calculate size usage"}, {"qtbz2", qtbz2_main, "", "manipulate tbz2 packages"}, {"quse", quse_main, "", "find pkgs using useflags"}, {"qxpak", qxpak_main, "", "manipulate xpak archives"}, {"qtegrity", qtegrity_main, "", "verify files with IMA"}, /* aliases for equery compatibility */ {"belongs", qfile_main, NULL, NULL}, /*"changes"*/ {"check", qcheck_main, NULL, NULL}, {"depends", qdepends_main, NULL, NULL}, /*"depgraph"*/ {"files", qlist_main, NULL, NULL}, /*"glsa"*/ {"hasuse", quse_main, NULL, NULL}, /*"list"*/ {"size", qsize_main, NULL, NULL}, /*"stats"*/ /*"uses"*/ /*"which"*/ /* alias for quickpkg */ {"uickpkg", qpkg_main, NULL, NULL}, /* {"glsa", qglsa_main, NULL, NULL}, */ /* alias for qtegrity */ {"integrity", qtegrity_main, NULL, NULL}, {NULL, NULL, NULL, NULL} }; /* Common usage for all applets */ #define COMMON_FLAGS "vqChV" #define COMMON_LONG_OPTS \ {"root", a_argument, NULL, 0x1}, \ {"verbose", no_argument, NULL, 'v'}, \ {"quiet", no_argument, NULL, 'q'}, \ {"nocolor", no_argument, NULL, 'C'}, \ {"help", no_argument, NULL, 'h'}, \ {"version", no_argument, NULL, 'V'}, \ {NULL, no_argument, NULL, 0x0} #define COMMON_OPTS_HELP \ "Set the ROOT env var", \ "Make a lot of noise", \ "Tighter output; suppress warnings", \ "Don't output color", \ "Print this help and exit", \ "Print version and exit", \ NULL #define COMMON_GETOPTS_CASES(applet) \ case 0x1: portroot = optarg; break; \ case 'v': ++verbose; break; \ case 'q': setup_quiet(); break; \ case 'V': version_barf(); break; \ case 'h': applet ## _usage(EXIT_SUCCESS); break; \ case 'C': no_colors(); break; \ default: applet ## _usage(EXIT_FAILURE); break; extern char *modpath; extern char *portroot; extern int verbose; extern int quiet; extern char pretend; extern char *config_protect; extern char *config_protect_mask; extern char *portvdb; extern char *portlogdir; extern char *pkg_install_mask; extern char *binhost; extern char *pkgdir; extern char *port_tmpdir; extern char *features; extern char *install_mask; extern DEFINE_ARRAY(overlays); void no_colors(void); void setup_quiet(void); void version_barf(void); void usage(int status, const char *flags, struct option const opts[], const char * const help[], const char *desc, int blabber); int lookup_applet_idx(const char *); APPLET lookup_applet(const char *applet); void freeargv(int argc, char **argv); void makeargv(const char *string, int *argc, char ***argv); #endif