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