7 #define _RPMGI_INTERNAL
17 rpmgi XrpmgiUnlink(rpmgi gi, const char * msg, const char * fn, unsigned ln)
19 if (gi == NULL) return NULL;
21 if (_rpmgi_debug && msg != NULL)
22 fprintf(stderr, "--> gi %p -- %d %s at %s:%u\n", gi, gi->nrefs, msg, fn, ln);
28 rpmgi XrpmgiLink(rpmgi gi, const char * msg, const char * fn, unsigned ln)
30 if (gi == NULL) return NULL;
33 if (_rpmgi_debug && msg != NULL)
34 fprintf(stderr, "--> gi %p ++ %d %s at %s:%u\n", gi, gi->nrefs, msg, fn, ln);
36 /*@-refcounttrans@*/ return gi; /*@=refcounttrans@*/
39 rpmgi rpmgiFree(rpmgi gi)
45 return rpmgiUnlink(gi, NULL);
48 fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc);
50 (void) rpmgiUnlink(gi, NULL);
64 if (gi->ftsp != NULL) {
66 xx = Fts_close(gi->ftsp);
70 gi->mi = rpmdbFreeIterator(gi->mi);
71 gi->ts = rpmtsFree(gi->ts);
73 memset(gi, 0, sizeof(*gi)); /* XXX trash and burn */
78 rpmgi rpmgiNew(rpmts ts, int tag, const void * keyp, size_t keylen)
80 rpmgi gi = xcalloc(1, sizeof(*gi));
85 gi->ts = rpmtsLink(ts, NULL);
92 gi->mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
95 fprintf(stderr, "*** gi %p\t%p\n", gi, gi->mi);
102 { char *const * argv = keyp;
103 unsigned flags = keylen;
108 while (*argv++ != NULL)
112 if (_rpmgi_debug < 0)
113 fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc);
118 gi = rpmgiLink(gi, NULL);
123 static int indent = 2;
125 static const char * ftsInfoStrings[] = {
143 static const char * ftsInfoStr(int fts_info) {
144 if (!(fts_info >= 1 && fts_info <= 14))
146 return ftsInfoStrings[ fts_info ];
149 const char * rpmgiNext(/*@null@*/ rpmgi gi)
152 const char * val = NULL;
155 if (gi != NULL && ++gi->i >= 0)
159 h = rpmdbNextIterator(gi->mi);
161 const char * fmt = "%{NAME}-%{VERSION}-%{RELEASE}";
162 val = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, NULL);
164 gi->mi = rpmdbFreeIterator(gi->mi);
171 if (gi->argv != NULL && gi->argv[gi->i] != NULL) {
172 if (_rpmgi_debug < 0)
173 fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]);
174 val = xstrdup(gi->argv[gi->i]);
179 if (gi->ftsp == NULL && gi->i == 0)
180 gi->ftsp = Fts_open(gi->argv, gi->ftsOpts, NULL);
182 while (val == NULL && (gi->fts = Fts_read(gi->ftsp)) != NULL) {
183 FTSENT * fts = gi->fts;
185 if (_rpmgi_debug < 0)
186 fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info),
187 indent * (fts->fts_level < 0 ? 0 : fts->fts_level), "",
190 switch (fts->fts_info) {
193 if (_rpmgi_debug < 0)
194 fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->ftsp, gi->i, fts->fts_path);
195 val = xstrdup(fts->fts_path);
201 if (gi->fts == NULL && gi->ftsp != NULL) {
203 xx = Fts_close(gi->ftsp);