rpm 4.10.90

- 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     MODE_PARSE          = (1 <<  1),
    00017 };
    00018
    00019 static int mode = MODE_UNKNOWN;
    00020 static int source = RPMQV_SPECRPMS;
    00021 const char *target = NULL;
    00022 char *queryformat = NULL;
    00023
    00024 static struct poptOption specOptsTable[] = {
    00025     { "parse", 'P', POPT_ARG_VAL, &mode, MODE_PARSE,
    00026         N_("parse spec file(s) to stdout"), NULL },
    00027     { "query", 'q', POPT_ARG_VAL, &mode, MODE_QUERY,
    00028         N_("query spec file(s)"), NULL },
    00029     { "rpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECRPMS,
    00030         N_("operate on binary rpms generated by spec (default)"), NULL },
    00031     { "srpm", 0, POPT_ARG_VAL, &source, RPMQV_SPECSRPM,
    00032         N_("operate on source rpm generated by spec"), NULL },
    00033     { "target", 0, POPT_ARG_STRING, &target, 0,
    00034         N_("override target platform"), NULL },
    00035     { "queryformat", 0, POPT_ARG_STRING, &queryformat, 0,
    00036         N_("use the following query format"), "QUERYFORMAT" },
    00037     { "qf", 0, (POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN), &queryformat, 0,
    00038         NULL, NULL },
    00039     POPT_TABLEEND
    00040 };
    00041
    00042 /* the structure describing the options we take and the defaults */
    00043 static struct poptOption optionsTable[] = {
    00044     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, specOptsTable, 0,
    00045         N_("Spec options:"), NULL },
    00046
    00047     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
    00048         N_("Common options for all rpm modes and executables:"), NULL },
    00049
    00050    POPT_AUTOALIAS
    00051    POPT_AUTOHELP
    00052    POPT_TABLEEND
    00053 };
    00054
    00055 int main(int argc, char *argv[])
    00056 {
    00057     rpmts ts = NULL;
    00058     QVA_t qva = &rpmQVKArgs;
    00059
    00060     poptContext optCon;
    00061     int ec = 0;
    00062
    00063     optCon = rpmcliInit(argc, argv, optionsTable);
    00064
    00065     if (rpmcliPipeOutput && initPipe())
    00066         exit(EXIT_FAILURE);
    00067
    00068     if (target) {
    00069         rpmFreeMacros(NULL);
    00070         rpmFreeRpmrc();
    00071         rpmReadConfigFiles(rpmcliRcfile, target);
    00072     }
    00073
    00074     ts = rpmtsCreate();
    00075     switch (mode) {
    00076
    00077     case MODE_QUERY:
    00078         if (!poptPeekArg(optCon))
    00079             argerror(_("no arguments given for query"));
    00080
    00081         qva->qva_queryFormat = queryformat;
    00082         qva->qva_source = source;
    00083         qva->qva_specQuery = rpmspecQuery;
    00084         ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
    00085         break;
    00086
    00087     case MODE_PARSE: {
    00088         const char * spath;
    00089         if (!poptPeekArg(optCon))
    00090             argerror(_("no arguments given for parse"));
    00091
    00092         while ((spath = poptGetArg(optCon)) != NULL) {
    00093             rpmSpec spec = rpmSpecParse(spath, 0, NULL);
    00094             if (spec == NULL) {
    00095                 ec++;
    00096                 continue;
    00097             }
    00098             fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE));
    00099             rpmSpecFree(spec);
    00100         }
    00101         break;
    00102     }
    00103
    00104     case MODE_UNKNOWN:
    00105         if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
    00106             printUsage(optCon, stderr, 0);
    00107             ec = argc;
    00108         }
    00109         break;
    00110     }
    00111
    00112     rpmtsFree(ts);
    00113     if (finishPipe())
    00114         ec = EXIT_FAILURE;
    00115
    00116     free(qva->qva_queryFormat);
    00117
    00118     rpmcliFini(optCon);
    00119
    00120     return RETVAL(ec);
    00121 }