rpm 4.11.1-rc1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

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 }