2010-10-04 18:33:18 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
#include <rpm/rpmcli.h>
|
|
|
|
#include <rpm/rpmbuild.h>
|
|
|
|
#include <rpm/rpmlog.h>
|
|
|
|
#include <rpm/rpmts.h>
|
|
|
|
|
|
|
|
#include "cliutils.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
enum modes {
|
|
|
|
MODE_UNKNOWN = 0,
|
|
|
|
MODE_QUERY = (1 << 0),
|
2011-06-17 18:53:43 +08:00
|
|
|
MODE_PARSE = (1 << 1),
|
2010-10-04 18:33:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int mode = MODE_UNKNOWN;
|
2010-10-12 19:44:56 +08:00
|
|
|
static int source = RPMQV_SPECRPMS;
|
2010-10-12 19:56:18 +08:00
|
|
|
const char *target = NULL;
|
2010-10-12 20:07:38 +08:00
|
|
|
char *queryformat = NULL;
|
2010-10-04 18:33:18 +08:00
|
|
|
|
2010-11-15 15:07:10 +08:00
|
|
|
static struct poptOption specOptsTable[] = {
|
2011-06-17 18:53:43 +08:00
|
|
|
{ "parse", 'P', POPT_ARG_VAL, &mode, MODE_PARSE,
|
|
|
|
N_("parse spec file(s) to stdout"), NULL },
|
2010-10-04 18:33:18 +08:00
|
|
|
{ "query", 'q', POPT_ARG_VAL, &mode, MODE_QUERY,
|
2010-10-12 20:10:26 +08:00
|
|
|
N_("query spec file(s)"), NULL },
|
2010-10-12 19:44:56 +08:00
|
|
|
{ "rpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECRPMS,
|
2010-10-12 20:10:26 +08:00
|
|
|
N_("operate on binary rpms generated by spec (default)"), NULL },
|
2016-03-09 00:32:22 +08:00
|
|
|
{ "builtrpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECBUILTRPMS,
|
|
|
|
N_("operate on binary rpms that would be built from spec"), NULL },
|
2010-10-12 19:44:56 +08:00
|
|
|
{ "srpm", 0, POPT_ARG_VAL, &source, RPMQV_SPECSRPM,
|
2010-10-12 20:10:26 +08:00
|
|
|
N_("operate on source rpm generated by spec"), NULL },
|
2010-10-12 20:07:38 +08:00
|
|
|
{ "queryformat", 0, POPT_ARG_STRING, &queryformat, 0,
|
|
|
|
N_("use the following query format"), "QUERYFORMAT" },
|
|
|
|
{ "qf", 0, (POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN), &queryformat, 0,
|
|
|
|
NULL, NULL },
|
2010-11-15 15:07:10 +08:00
|
|
|
POPT_TABLEEND
|
|
|
|
};
|
|
|
|
|
|
|
|
/* the structure describing the options we take and the defaults */
|
|
|
|
static struct poptOption optionsTable[] = {
|
|
|
|
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, specOptsTable, 0,
|
|
|
|
N_("Spec options:"), NULL },
|
2010-10-04 18:33:18 +08:00
|
|
|
|
|
|
|
{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
|
|
|
|
N_("Common options for all rpm modes and executables:"), NULL },
|
|
|
|
|
|
|
|
POPT_AUTOALIAS
|
|
|
|
POPT_AUTOHELP
|
|
|
|
POPT_TABLEEND
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
rpmts ts = NULL;
|
|
|
|
QVA_t qva = &rpmQVKArgs;
|
|
|
|
|
|
|
|
poptContext optCon;
|
|
|
|
int ec = 0;
|
|
|
|
|
2013-08-18 03:50:41 +08:00
|
|
|
xsetprogname(argv[0]); /* Portability call -- see system.h */
|
|
|
|
|
2010-10-04 18:33:18 +08:00
|
|
|
optCon = rpmcliInit(argc, argv, optionsTable);
|
|
|
|
|
|
|
|
if (rpmcliPipeOutput && initPipe())
|
|
|
|
exit(EXIT_FAILURE);
|
2010-10-12 19:56:18 +08:00
|
|
|
|
|
|
|
if (target) {
|
|
|
|
rpmFreeMacros(NULL);
|
|
|
|
rpmFreeRpmrc();
|
|
|
|
rpmReadConfigFiles(rpmcliRcfile, target);
|
|
|
|
}
|
2010-10-04 18:33:18 +08:00
|
|
|
|
|
|
|
ts = rpmtsCreate();
|
|
|
|
switch (mode) {
|
|
|
|
|
|
|
|
case MODE_QUERY:
|
|
|
|
if (!poptPeekArg(optCon))
|
|
|
|
argerror(_("no arguments given for query"));
|
|
|
|
|
2010-10-12 20:07:38 +08:00
|
|
|
qva->qva_queryFormat = queryformat;
|
2010-10-12 19:44:56 +08:00
|
|
|
qva->qva_source = source;
|
2010-10-04 18:33:18 +08:00
|
|
|
qva->qva_specQuery = rpmspecQuery;
|
|
|
|
ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
|
|
|
|
break;
|
|
|
|
|
2011-06-17 18:53:43 +08:00
|
|
|
case MODE_PARSE: {
|
|
|
|
const char * spath;
|
|
|
|
if (!poptPeekArg(optCon))
|
|
|
|
argerror(_("no arguments given for parse"));
|
|
|
|
|
|
|
|
while ((spath = poptGetArg(optCon)) != NULL) {
|
2013-01-22 08:47:15 +08:00
|
|
|
rpmSpec spec = rpmSpecParse(spath, (RPMSPEC_ANYARCH|RPMSPEC_FORCE), NULL);
|
2011-06-17 18:53:43 +08:00
|
|
|
if (spec == NULL) {
|
|
|
|
ec++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE));
|
|
|
|
rpmSpecFree(spec);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-10-04 18:33:18 +08:00
|
|
|
case MODE_UNKNOWN:
|
|
|
|
if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
|
|
|
|
printUsage(optCon, stderr, 0);
|
|
|
|
ec = argc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-30 14:36:03 +08:00
|
|
|
rpmtsFree(ts);
|
2011-09-05 13:38:31 +08:00
|
|
|
if (finishPipe())
|
|
|
|
ec = EXIT_FAILURE;
|
2010-10-04 18:33:18 +08:00
|
|
|
|
2011-05-30 14:36:03 +08:00
|
|
|
free(qva->qva_queryFormat);
|
2010-10-04 18:33:18 +08:00
|
|
|
|
|
|
|
rpmcliFini(optCon);
|
|
|
|
|
|
|
|
return RETVAL(ec);
|
|
|
|
}
|