Handle config.guess and config.sub with DOS EOLs
[platform/upstream/rpm.git] / rpmspec.c
index ff72570..86e3285 100644 (file)
--- a/rpmspec.c
+++ b/rpmspec.c
@@ -1,5 +1,4 @@
 #include "system.h"
-const char *__progname;
 
 #include <rpm/rpmcli.h>
 #include <rpm/rpmbuild.h>
@@ -13,26 +12,37 @@ const char *__progname;
 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;
 
-/* the structure describing the options we take and the defaults */
-static struct poptOption optionsTable[] = {
+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 },
+       N_("query spec file(s)"), NULL },
     { "rpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECRPMS,
-       N_("Operate on binary rpms generated by spec (default)"), NULL },
+       N_("operate on binary rpms generated by spec (default)"), NULL },
+    { "builtrpms", 0, POPT_ARG_VAL, &source, RPMQV_SPECBUILTRPMS,
+       N_("operate on binary rpms that would be built from spec"), 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 },
+       N_("operate on source rpm generated by spec"), 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 },
 
-    /* XXX FIXME: only queryformat is relevant for spec queries */
-    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmQueryPoptTable, 0,
-       N_("Query options (with -q or --query):"), NULL },
     { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
        N_("Common options for all rpm modes and executables:"), NULL },
 
@@ -49,6 +59,8 @@ int main(int argc, char *argv[])
     poptContext optCon;
     int ec = 0;
 
+    xsetprogname(argv[0]); /* Portability call -- see system.h */
+
     optCon = rpmcliInit(argc, argv, optionsTable);
 
     if (rpmcliPipeOutput && initPipe())
@@ -67,11 +79,29 @@ int main(int argc, char *argv[])
        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);
@@ -80,10 +110,11 @@ int main(int argc, char *argv[])
        break;
     }
 
-    ts = rpmtsFree(ts);
-    finishPipe();
+    rpmtsFree(ts);
+    if (finishPipe())
+       ec = EXIT_FAILURE;
 
-    qva->qva_queryFormat = _free(qva->qva_queryFormat);
+    free(qva->qva_queryFormat);
 
     rpmcliFini(optCon);