580d7f67a7609201095de7171d083165314e2eaa
[tools/librpm-tizen.git] / lib / tgi.c
1 #include "system.h"
2
3 #include <rpmio_internal.h>
4 #define _RPMGI_INTERNAL
5 #include <rpmgi.h>
6 #include <rpmcli.h>
7
8 #include <rpmmacro.h>
9 #include <rpmmessages.h>
10 #include <popt.h>
11
12 #include "debug.h"
13
14 static int gitag = RPMGI_FTSWALK;
15 static int ftsOpts = 0;
16
17 static struct poptOption optionsTable[] = {
18  { "rpmgidebug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
19         N_("debug generalized iterator"), NULL},
20
21  { "rpmdb", '\0', POPT_ARG_VAL, &gitag, RPMGI_RPMDB,
22         N_("iterate rpmdb"), NULL },
23  { "hdlist", '\0', POPT_ARG_VAL, &gitag, RPMGI_HDLIST,
24         N_("iterate hdlist"), NULL },
25  { "arglist", '\0', POPT_ARG_VAL, &gitag, RPMGI_ARGLIST,
26         N_("iterate arglist"), NULL },
27  { "ftswalk", '\0', POPT_ARG_VAL, &gitag, RPMGI_FTSWALK,
28         N_("iterate fts(3) walk"), NULL },
29
30  { "comfollow", '\0', POPT_BIT_SET,     &ftsOpts, FTS_COMFOLLOW,
31         N_("follow command line symlinks"), NULL },
32  { "logical", '\0', POPT_BIT_SET,       &ftsOpts, FTS_LOGICAL,
33         N_("logical walk"), NULL },
34  { "nochdir", '\0', POPT_BIT_SET,       &ftsOpts, FTS_NOCHDIR,
35         N_("don't change directories"), NULL },
36  { "nostat", '\0', POPT_BIT_SET,        &ftsOpts, FTS_NOSTAT,
37         N_("don't get stat info"), NULL },
38  { "physical", '\0', POPT_BIT_SET,      &ftsOpts, FTS_PHYSICAL,
39         N_("physical walk"), NULL },
40  { "seedot", '\0', POPT_BIT_SET,        &ftsOpts, FTS_SEEDOT,
41         N_("return dot and dot-dot"), NULL },
42  { "xdev", '\0', POPT_BIT_SET,          &ftsOpts, FTS_XDEV,
43         N_("don't cross devices"), NULL },
44  { "whiteout", '\0', POPT_BIT_SET,      &ftsOpts, FTS_WHITEOUT,
45         N_("return whiteout information"), NULL },
46
47 #ifdef DYING
48  { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
49         N_("debug protocol data stream"), NULL},
50  { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
51         N_("debug rpmio I/O"), NULL},
52  { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
53         N_("debug URL cache handling"), NULL},
54  { "verbose", 'v', 0, 0, 'v',                           NULL, NULL },
55 #endif
56
57  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
58         N_("Common options for all rpm modes and executables:"),
59         NULL },
60
61   POPT_AUTOALIAS
62   POPT_AUTOHELP
63   POPT_TABLEEND
64 };
65
66 int
67 main(int argc, char *const argv[])
68 {
69     poptContext optCon;
70     rpmts ts = NULL;
71     rpmgi gi = NULL;
72     const char ** av;
73     const char * arg;
74     int ac;
75     int rc = 0;
76
77     optCon = rpmcliInit(argc, argv, optionsTable);
78     if (optCon == NULL)
79         exit(EXIT_FAILURE);
80
81     if (ftsOpts == 0)
82         ftsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);
83
84     ts = rpmtsCreate();
85     av = poptGetArgs(optCon);
86     gi = rpmgiNew(ts, gitag, av, ftsOpts);
87
88     ac = 0;
89     while ((arg = rpmgiNext(gi)) != NULL) {
90         fprintf(stderr, "%5d %s\n", ac, arg);
91         arg = _free(arg);
92         ac++;
93     }
94
95     gi = rpmgiFree(gi);
96     ts = rpmtsFree(ts);
97     optCon = rpmcliFini(optCon);
98
99     return rc;
100 }