rpm: rpmspec.c Source File

rpm 4.13.0

rpmspec.c
Go to the documentation of this file.
1 #include "system.h"
2 const char *__progname;
3
4 #include <rpm/rpmcli.h>
5 #include <rpm/rpmbuild.h>
6 #include <rpm/rpmlog.h>
7 #include <rpm/rpmts.h>
8
9 #include "cliutils.h"
10
11 #include "debug.h"
12
13 enum modes {
14 MODE_UNKNOWN = 0,
15 MODE_QUERY = (1 << 0),
16 MODE_PARSE = (1 << 1),
17 };
18
19 static int mode = MODE_UNKNOWN;
20 static int source = RPMQV_SPECRPMS;
21 const char *target = NULL;
22 char *queryformat = NULL;
23
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,
38 NULL, NULL },
39 POPT_TABLEEND
40 };
41
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 },
46
47 { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
48 N_("Common options for all rpm modes and executables:"), NULL },
49
50 POPT_AUTOALIAS
51 POPT_AUTOHELP
52 POPT_TABLEEND
53 };
54
55 int main(int argc, char *argv[])
56 {
57 rpmts ts = NULL;
58 QVA_t qva = &rpmQVKArgs;
59
60 poptContext optCon;
61 int ec = 0;
62
63 optCon = rpmcliInit(argc, argv, optionsTable);
64
65 if (rpmcliPipeOutput && initPipe())
66 exit(EXIT_FAILURE);
67
68 if (target) {
69 rpmFreeMacros(NULL);
70 rpmFreeRpmrc();
71 rpmReadConfigFiles(rpmcliRcfile, target);
72 }
73
74 ts = rpmtsCreate();
75 switch (mode) {
76
77 case MODE_QUERY:
78 if (!poptPeekArg(optCon))
79 argerror(_("no arguments given for query"));
80
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));
85 break;
86
87 case MODE_PARSE: {
88 const char * spath;
89 if (!poptPeekArg(optCon))
90 argerror(_("no arguments given for parse"));
91
92 while ((spath = poptGetArg(optCon)) != NULL) {
93 rpmSpec spec = rpmSpecParse(spath, (RPMSPEC_ANYARCH|RPMSPEC_FORCE), NULL);
94 if (spec == NULL) {
95 ec++;
96 continue;
97 }
98 fprintf(stdout, "%s", rpmSpecGetSection(spec, RPMBUILD_NONE));
99 rpmSpecFree(spec);
100 }
101 break;
102 }
103
104 case MODE_UNKNOWN:
105 if (poptPeekArg(optCon) != NULL || argc <= 1 || rpmIsVerbose()) {
106 printUsage(optCon, stderr, 0);
107 ec = argc;
108 }
109 break;
110 }
111
112 rpmtsFree(ts);
113 if (finishPipe())
114 ec = EXIT_FAILURE;
115
116 free(qva->qva_queryFormat);
117
118 rpmcliFini(optCon);
119
120 return RETVAL(ec);
121 }
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