diff options
author | Kim Kibum <kb0929.kim@samsung.com> | 2012-05-21 17:49:08 +0900 |
---|---|---|
committer | Kim Kibum <kb0929.kim@samsung.com> | 2012-05-21 17:49:08 +0900 |
commit | dec48cfa66e17ba4a7e50c92cb24b913289feb12 (patch) | |
tree | e1f48cd5cabb40a1d604b36949ff072d01267cb5 /rpmspec.c | |
parent | b7a3bffb8e0341b7e4ef69def268bca3a7f279ff (diff) | |
download | rpm-dec48cfa66e17ba4a7e50c92cb24b913289feb12.tar.gz rpm-dec48cfa66e17ba4a7e50c92cb24b913289feb12.tar.bz2 rpm-dec48cfa66e17ba4a7e50c92cb24b913289feb12.zip |
Upload Tizen:Base source
Diffstat (limited to 'rpmspec.c')
-rw-r--r-- | rpmspec.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/rpmspec.c b/rpmspec.c new file mode 100644 index 0000000..c4d01a9 --- /dev/null +++ b/rpmspec.c @@ -0,0 +1,120 @@ +#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, 0, 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; + } + + ts = rpmtsFree(ts); + finishPipe(); + + qva->qva_queryFormat = _free(qva->qva_queryFormat); + + rpmcliFini(optCon); + + return RETVAL(ec); +} |