Fix Werrors with GCC-14.1.0
[platform/upstream/rpm.git] / tools / rpmdeps.c
index dc22391..f260a38 100644 (file)
@@ -1,19 +1,30 @@
 #include "system.h"
-const char *__progname;
 
-#include <rpmbuild.h>
-#include <argv.h>
-#include <rpmds.h>
-#include <rpmfc.h>
+#include <rpm/rpmbuild.h>
+#include <rpm/argv.h>
+#include <rpm/rpmds.h>
+#include <rpm/rpmfc.h>
 
 #include "debug.h"
 
-char *progname;
-
 static int print_provides;
 
 static int print_requires;
 
+static int print_recommends;
+
+static int print_suggests;
+
+static int print_supplements;
+
+static int print_enhances;
+
+static int print_conflicts;
+
+static int print_obsoletes;
+
+static int print_alldeps;
+
 static void rpmdsPrint(const char * msg, rpmds ds, FILE * fp)
 {
     if (fp == NULL) fp = stderr;
@@ -36,6 +47,20 @@ static struct poptOption optionsTable[] = {
         NULL, NULL },
  { "requires", 'R', POPT_ARG_VAL, &print_requires, -1,
         NULL, NULL },
+ { "recommends", '\0', POPT_ARG_VAL, &print_recommends, -1,
+        NULL, NULL },
+ { "suggests", '\0', POPT_ARG_VAL, &print_suggests, -1,
+        NULL, NULL },
+ { "supplements", '\0', POPT_ARG_VAL, &print_supplements, -1,
+        NULL, NULL },
+ { "enhances", '\0', POPT_ARG_VAL, &print_enhances, -1,
+        NULL, NULL },
+ { "conflicts", '\0', POPT_ARG_VAL, &print_conflicts, -1,
+        NULL, NULL },
+ { "obsoletes", '\0', POPT_ARG_VAL, &print_obsoletes, -1,
+        NULL, NULL },
+ { "alldeps", '\0', POPT_ARG_VAL, &print_alldeps, -1,
+        NULL, NULL },
 
    POPT_AUTOALIAS
    POPT_AUTOHELP
@@ -43,66 +68,69 @@ static struct poptOption optionsTable[] = {
 };
 
 int
-main(int argc, char *const argv[])
+main(int argc, char *argv[])
 {
-    poptContext optCon;
+    poptContext optCon = NULL;
     ARGV_t av = NULL;
-    rpmfc fc;
-    int ac = 0;
+    rpmfc fc = NULL;
     int ec = 1;
-    int xx;
-char buf[BUFSIZ];
+    char buf[BUFSIZ];
 
-    if ((progname = strrchr(argv[0], '/')) != NULL)
-       progname++;
-    else
-       progname = argv[0];
+    xsetprogname(argv[0]); /* Portability call -- see system.h */
 
     optCon = rpmcliInit(argc, argv, optionsTable);
     if (optCon == NULL)
        goto exit;
 
-    av = poptGetArgs(optCon);
-    ac = argvCount(av);
-
-    if (ac == 0) {
-       char * b, * be;
-       av = NULL;
-       while ((b = fgets(buf, sizeof(buf), stdin)) != NULL) {
-           buf[sizeof(buf)-1] = '\0';
-           be = b + strlen(buf) - 1;
+    /* normally files get passed through stdin but also accept files as args */
+    if (poptPeekArg(optCon)) {
+       const char *arg;
+       while ((arg = poptGetArg(optCon)) != NULL) {
+           argvAdd(&av, arg);
+       }
+    } else {
+       while (fgets(buf, sizeof(buf), stdin) != NULL) {
+           char *be = buf + strlen(buf) - 1;
            while (strchr("\r\n", *be) != NULL)
                *be-- = '\0';
-           xx = argvAdd(&av, b);
+           argvAdd(&av, buf);
        }
-       ac = argvCount(av);
     }
-
     /* Make sure file names are sorted. */
-    xx = argvSort(av, NULL);
+    argvSort(av, NULL);
 
-    /* Build file class dictionary. */
-    fc = rpmfcNew();
-    xx = rpmfcClassify(fc, av, NULL);
-
-    /* Build file/package dependency dictionary. */
-    xx = rpmfcApply(fc);
-
-if (_rpmfc_debug) {
-sprintf(buf, "final: files %d cdict[%d] %d%% ddictx[%d]", fc->nfiles, argvCount(fc->cdict), ((100 * fc->fknown)/fc->nfiles), argiCount(fc->ddictx));
-rpmfcPrint(buf, fc, NULL);
-}
-
-    if (print_provides)
-       rpmdsPrint(NULL, fc->provides, stdout);
-    if (print_requires)
-       rpmdsPrint(NULL, fc->requires, stdout);
+    /* Build file/package class and dependency dictionaries. */
+    fc = rpmfcCreate(getenv("RPM_BUILD_ROOT"), 0);
+    if (rpmfcClassify(fc, av, NULL) || rpmfcApply(fc))
+       goto exit;
 
-    fc = rpmfcFree(fc);
+    if (print_alldeps || _rpmfc_debug)
+       rpmfcPrint(NULL, fc, print_alldeps ? stdout : NULL);
+
+    if (!print_alldeps) {
+       if (print_provides)
+           rpmdsPrint(NULL, rpmfcProvides(fc), stdout);
+       if (print_requires)
+           rpmdsPrint(NULL, rpmfcRequires(fc), stdout);
+       if (print_recommends)
+           rpmdsPrint(NULL, rpmfcRecommends(fc), stdout);
+       if (print_suggests)
+           rpmdsPrint(NULL, rpmfcSuggests(fc), stdout);
+       if (print_supplements)
+           rpmdsPrint(NULL, rpmfcSupplements(fc), stdout);
+       if (print_enhances)
+           rpmdsPrint(NULL, rpmfcEnhances(fc), stdout);
+       if (print_conflicts)
+           rpmdsPrint(NULL, rpmfcConflicts(fc), stdout);
+       if (print_obsoletes)
+           rpmdsPrint(NULL, rpmfcObsoletes(fc), stdout);
+    }
 
     ec = 0;
 
 exit:
-    optCon = rpmcliFini(optCon);
+    argvFree(av);
+    rpmfcFree(fc);
+    rpmcliFini(optCon);
     return ec;
 }