- fix: add rpmlib(VersionedDependencies) if versioned Provides: found.
[platform/upstream/rpm.git] / tools / rpmdeps.c
1 #include "system.h"
2
3 #include <rpmbuild.h>
4 #include <argv.h>
5 #include <rpmds.h>
6 #include <rpmfc.h>
7
8 #include "debug.h"
9
10 /*@unchecked@*/
11 char *progname;
12
13 /*@unchecked@*/
14 static int print_provides;
15
16 /*@unchecked@*/
17 static int print_requires;
18
19 static void rpmdsPrint(const char * msg, rpmds ds, FILE * fp)
20 {
21     if (fp == NULL) fp = stderr;
22
23     if (msg)
24         fprintf(fp, "===================================== %s\n", msg);
25
26     ds = rpmdsInit(ds);
27     while (rpmdsNext(ds) >= 0)
28         fprintf(fp, "%s\n", rpmdsDNEVR(ds)+2);
29 }
30
31 static struct poptOption optionsTable[] = {
32
33  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
34         N_("Common options for all rpm modes and executables:"),
35         NULL }, 
36
37  { "provides", 'P', POPT_ARG_VAL, &print_provides, -1,
38         NULL, NULL },
39  { "requires", 'R', POPT_ARG_VAL, &print_requires, -1,
40         NULL, NULL },
41
42    POPT_AUTOALIAS
43    POPT_AUTOHELP
44    POPT_TABLEEND
45 };
46
47 int
48 main(int argc, char *const argv[])
49 {
50     poptContext optCon;
51     ARGV_t av = NULL;
52     rpmfc fc;
53     int ac = 0;
54     int ec = 1;
55     int xx;
56 char buf[BUFSIZ];
57
58 /*@-modobserver@*/
59     if ((progname = strrchr(argv[0], '/')) != NULL)
60         progname++;
61     else
62         progname = argv[0];
63 /*@=modobserver@*/
64
65     optCon = rpmcliInit(argc, argv, optionsTable);
66     if (optCon == NULL)
67         goto exit;
68
69     av = poptGetArgs(optCon);
70     ac = argvCount(av);
71
72     if (ac == 0) {
73         char * b, * be;
74         av = NULL;
75         while ((b = fgets(buf, sizeof(buf), stdin)) != NULL) {
76             buf[sizeof(buf)-1] = '\0';
77             be = b + strlen(buf) - 1;
78             while (strchr("\r\n", *be) != NULL)
79                 *be-- = '\0';
80             xx = argvAdd(&av, b);
81         }
82         ac = argvCount(av);
83     }
84
85     /* Make sure file names are sorted. */
86     xx = argvSort(av, NULL);
87
88     /* Build file class dictionary. */
89     fc = rpmfcNew();
90     xx = rpmfcClassify(fc, av);
91
92     /* Build file/package dependency dictionary. */
93     xx = rpmfcApply(fc);
94
95 if (_rpmfc_debug) {
96 sprintf(buf, "final: files %d cdict[%d] %d%% ddictx[%d]", fc->nfiles, argvCount(fc->cdict), ((100 * fc->fknown)/fc->nfiles), argiCount(fc->ddictx));
97 rpmfcPrint(buf, fc, NULL);
98 }
99
100     if (print_provides)
101         rpmdsPrint(NULL, fc->provides, stdout);
102     if (print_requires)
103         rpmdsPrint(NULL, fc->requires, stdout);
104
105     fc = rpmfcFree(fc);
106
107     ec = 0;
108
109 exit:
110     optCon = rpmcliFini(optCon);
111     return ec;
112 }