2 const char *__progname;
4 #include <rpm/rpmcli.h>
5 #include <rpm/rpmbuild.h>
6 #include <rpm/rpmlog.h>
15 MODE_QUERY = (1 << 0),
16 MODE_PARSE = (1 << 1),
19 static int mode = MODE_UNKNOWN;
20 static int source = RPMQV_SPECRPMS;
21 const char *target = NULL;
22 char *queryformat = NULL;
24 static struct poptOption specOptsTable[] = {
25 { "parse", 'P', POPT_ARG_VAL, &mode, MODE_PARSE,
26 N_("parse spec file(s) to stdout"), NULL },
27 { "query", 'q', POPT_ARG_VAL, &mode, MODE_QUERY,
28 N_("query spec file(s)"), NULL },
29 { "rpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECRPMS,
30 N_("operate on binary rpms generated by spec (default)"), NULL },
31 { "srpm", 0, POPT_ARG_VAL, &source, RPMQV_SPECSRPM,
32 N_("operate on source rpm generated by spec"), NULL },
33 { "target", 0, POPT_ARG_STRING, &target, 0,
34 N_("override target platform"), NULL },
35 { "queryformat", 0, POPT_ARG_STRING, &queryformat, 0,
36 N_("use the following query format"), "QUERYFORMAT" },
37 { "qf", 0, (POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN), &queryformat, 0,
42 /* the structure describing the options we take and the defaults */
43 static struct poptOption optionsTable[] = {
44 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, specOptsTable, 0,
45 N_("Spec options:"), NULL },
47 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
48 N_("Common options for all rpm modes and executables:"), NULL },
55 int main(int argc, char *argv[])
58 QVA_t qva = &rpmQVKArgs;
63 optCon = rpmcliInit(argc, argv, optionsTable);
65 if (rpmcliPipeOutput && initPipe())
71 rpmReadConfigFiles(rpmcliRcfile, target);
78 if (!poptPeekArg(optCon))
79 argerror(_("no arguments given for query"));
81 qva->qva_queryFormat = queryformat;
82 qva->qva_source = source;
83 qva->qva_specQuery = rpmspecQuery;
84 ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
89 if (!poptPeekArg(optCon))
90 argerror(_("no arguments given for parse"));
92 while ((spath = poptGetArg(optCon)) != NULL) {
93 rpmSpec spec = rpmSpecParse(spath, (RPMSPEC_ANYARCH|RPMSPEC_FORCE), NULL);
98 fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE));
105 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
106 printUsage(optCon, stderr, 0);
116 free(qva->qva_queryFormat);