rpmspec.c
Go to the documentation of this file.
#include "system.h"
const char *__progname;
#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),
MODE_PARSE = (1 << 1),
};
static int mode = MODE_UNKNOWN;
static int source = RPMQV_SPECRPMS;
const char *target = NULL;
char *queryformat = NULL;
static struct poptOption specOptsTable[] = {
{ "parse", 'P', POPT_ARG_VAL, &mode, MODE_PARSE,
N_("parse spec file(s) to stdout"), NULL },
{ "query", 'q', POPT_ARG_VAL, &mode, MODE_QUERY,
N_("query spec file(s)"), NULL },
{ "rpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECRPMS,
N_("operate on binary rpms generated by spec (default)"), NULL },
{ "srpm", 0, POPT_ARG_VAL, &source, RPMQV_SPECSRPM,
N_("operate on source rpm generated by spec"), NULL },
{ "target", 0, POPT_ARG_STRING, &target, 0,
N_("override target platform"), NULL },
{ "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 },
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 },
{ 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;
optCon = rpmcliInit(argc, argv, optionsTable);
if (rpmcliPipeOutput && initPipe())
exit(EXIT_FAILURE);
if (target) {
rpmFreeMacros(NULL);
rpmFreeRpmrc();
rpmReadConfigFiles(rpmcliRcfile, target);
}
ts = rpmtsCreate();
switch (mode) {
case MODE_QUERY:
if (!poptPeekArg(optCon))
argerror(_("no arguments given for query"));
qva->qva_queryFormat = queryformat;
qva->qva_source = source;
qva->qva_specQuery = rpmspecQuery;
ec = rpmcliQuery(ts, qva, (ARGV_const_t) poptGetArgs(optCon));
break;
case MODE_PARSE: {
const char * spath;
if (!poptPeekArg(optCon))
argerror(_("no arguments given for parse"));
while ((spath = poptGetArg(optCon)) != NULL) {
rpmSpec spec = rpmSpecParse(spath, (RPMSPEC_ANYARCH|RPMSPEC_FORCE), NULL);
if (spec == NULL) {
ec++;
continue;
}
fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE));
rpmSpecFree(spec);
}
break;
}
case MODE_UNKNOWN:
if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
printUsage(optCon, stderr, 0);
ec = argc;
}
break;
}
rpmtsFree(ts);
if (finishPipe())
ec = EXIT_FAILURE;
free(qva->qva_queryFormat);
rpmcliFini(optCon);
return RETVAL(ec);
}
RETVAL
#define RETVAL(rc)
Definition: cliutils.h:9
rpmcliRcfile
const char * rpmcliRcfile
printUsage
void printUsage(poptContext con, FILE *fp, int flags)
Definition: cliutils.c:36
RPMQV_SPECRPMS
Definition: rpmcli.h:88
RPMBUILD_NONE
Definition: rpmbuild.h:22
debug.h
rpmcliQuery
int rpmcliQuery(rpmts ts, QVA_t qva, ARGV_const_t argv)
Display package information.
RPMSPEC_FORCE
Definition: rpmspec.h:37
rpmcliInit
poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable)
Initialize most everything needed by an rpm CLI executable context.
rpmcliFini
poptContext rpmcliFini(poptContext optCon)
Destroy most everything needed by an rpm CLI executable context.
rpmSpecFree
rpmSpec rpmSpecFree(rpmSpec spec)
Destroy Spec structure.
cliutils.h
rpmQVKArgs
struct rpmQVKArguments_s rpmQVKArgs
finishPipe
int finishPipe(void)
Definition: cliutils.c:73
_
#define _(Text)
Definition: system.h:110
rpmQVKArguments_s
Describe query/verify/signature command line operation.
Definition: rpmcli.h:172
rpmIsVerbose
#define rpmIsVerbose()
Definition: rpmlog.h:272
rpmQVKArguments_s::qva_specQuery
QSpecF_t qva_specQuery
Definition: rpmcli.h:179
rpmReadConfigFiles
int rpmReadConfigFiles(const char *file, const char *target)
Read macro configuration file(s) for a target.
source
static int source
Definition: rpmspec.c:20
MODE_QUERY
Definition: rpmspec.c:15
rpmcliPipeOutput
const char * rpmcliPipeOutput
argerror
void argerror(const char *desc)
Definition: cliutils.c:19
modes
modes
Definition: rpmbuild.c:250
rpmQVKArguments_s::qva_source
rpmQVSources qva_source
Definition: rpmcli.h:173
specOptsTable
static struct poptOption specOptsTable[]
Definition: rpmspec.c:24
initPipe
int initPipe(void)
Definition: cliutils.c:48
RPMSPEC_ANYARCH
Definition: rpmspec.h:36
target
const char * target
Definition: rpmspec.c:21
queryformat
char * queryformat
Definition: rpmspec.c:22
rpmSpecGetSection
const char * rpmSpecGetSection(rpmSpec spec, int section)
rpmQVKArguments_s::qva_queryFormat
char * qva_queryFormat
Definition: rpmcli.h:180
ARGV_const_t
char *const * ARGV_const_t
Definition: argv.h:16
rpmtsFree
rpmts rpmtsFree(rpmts ts)
Destroy transaction set, closing the database as well.
rpmspecQuery
int rpmspecQuery(rpmts ts, QVA_t qva, const char *arg)
Function to query spec file(s).
rpmFreeMacros
void rpmFreeMacros(rpmMacroContext mc)
Destroy macro context.
rpmSpecParse
rpmSpec rpmSpecParse(const char *specFile, rpmSpecFlags flags, const char *buildRoot)
Parse spec file into spec control structure.
MODE_UNKNOWN
Definition: rpmspec.c:14
rpmts
struct rpmts_s * rpmts
The main types involved in transaction manipulation.
Definition: rpmtypes.h:63
mode
static int mode
Definition: rpmspec.c:19
system.h
optionsTable
static struct poptOption optionsTable[]
Definition: rpmspec.c:43
rpmFreeRpmrc
void rpmFreeRpmrc(void)
Destroy rpmrc arch/os compatibility tables.
MODE_PARSE
Definition: rpmspec.c:16
__progname
#define __progname
Definition: system.h:96
N_
#define N_(Text)
Definition: system.h:113
rpmtsCreate
rpmts rpmtsCreate(void)
Create an empty transaction set.
main
int main(int argc, char *argv[])
Definition: rpmspec.c:55
rpmcliAllPoptTable
struct poptOption rpmcliAllPoptTable[]
Popt option table for options shared by all modes and executables.
RPMQV_SPECSRPM
Definition: rpmcli.h:93
rpmSpec
struct rpmSpec_s * rpmSpec
Definition: rpmtypes.h:90