- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# rpmspec.c

Go to the documentation of this file.

    00001 #include "system.h"
    00002 const char *__progname;
    00003
    00004 #include <rpm/rpmcli.h>
    00005 #include <rpm/rpmbuild.h>
    00006 #include <rpm/rpmlog.h>
    00007 #include <rpm/rpmts.h>
    00008
    00009 #include "cliutils.h"
    00010
    00011 #include "debug.h"
    00012
    00013 enum modes {
    00014     MODE_UNKNOWN        = 0,
    00015     MODE_QUERY          = (1 <<  0),
    00016 };
    00017
    00018 static int mode = MODE_UNKNOWN;
    00019 static int source = RPMQV_SPECRPMS;
    00020 const char *target = NULL;
    00021 char *queryformat = NULL;
    00022
    00023 static struct poptOption specOptsTable[] = {
    00024     { "query", 'q', POPT_ARG_VAL, &mode, MODE_QUERY,
    00025         N_("query spec file(s)"), NULL },
    00026     { "rpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECRPMS,
    00027         N_("operate on binary rpms generated by spec (default)"), NULL },
    00028     { "srpm", 0, POPT_ARG_VAL, &source, RPMQV_SPECSRPM,
    00029         N_("operate on source rpm generated by spec"), NULL },
    00030     { "target", 0, POPT_ARG_STRING, &target, 0,
    00031         N_("override target platform"), NULL },
    00032     { "queryformat", 0, POPT_ARG_STRING, &queryformat, 0,
    00033         N_("use the following query format"), "QUERYFORMAT" },
    00034     { "qf", 0, (POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN), &queryformat, 0,
    00035         NULL, NULL },
    00036     POPT_TABLEEND
    00037 };
    00038
    00039 /* the structure describing the options we take and the defaults */
    00040 static struct poptOption optionsTable[] = {
    00041     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, specOptsTable, 0,
    00042         N_("Spec options:"), NULL },
    00043
    00044     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
    00045         N_("Common options for all rpm modes and executables:"), NULL },
    00046
    00047    POPT_AUTOALIAS
    00048    POPT_AUTOHELP
    00049    POPT_TABLEEND
    00050 };
    00051
    00052 int main(int argc, char *argv[])
    00053 {
    00054     rpmts ts = NULL;
    00055     QVA_t qva = &rpmQVKArgs;
    00056
    00057     poptContext optCon;
    00058     int ec = 0;
    00059
    00060     optCon = rpmcliInit(argc, argv, optionsTable);
    00061
    00062     if (rpmcliPipeOutput && initPipe())
    00063         exit(EXIT_FAILURE);
    00064
    00065     if (target) {
    00066         rpmFreeMacros(NULL);
    00067         rpmFreeRpmrc();
    00068         rpmReadConfigFiles(rpmcliRcfile, target);
    00069     }
    00070
    00071     ts = rpmtsCreate();
    00072     switch (mode) {
    00073
    00074     case MODE_QUERY:
    00075         if (!poptPeekArg(optCon))
    00076             argerror(_("no arguments given for query"));
    00077
    00078         qva->qva_queryFormat = queryformat;
    00079         qva->qva_source = source;
    00080         qva->qva_specQuery = rpmspecQuery;
    00081         ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
    00082         break;
    00083
    00084     case MODE_UNKNOWN:
    00085         if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
    00086             printUsage(optCon, stderr, 0);
    00087             ec = argc;
    00088         }
    00089         break;
    00090     }
    00091
    00092     ts = rpmtsFree(ts);
    00093     finishPipe();
    00094
    00095     qva->qva_queryFormat = _free(qva->qva_queryFormat);
    00096
    00097     rpmcliFini(optCon);
    00098
    00099     return RETVAL(ec);
    00100 }