Add --qf to rpmgi.
authorjbj <devnull@localhost>
Sun, 10 Oct 2004 20:55:11 +0000 (20:55 +0000)
committerjbj <devnull@localhost>
Sun, 10 Oct 2004 20:55:11 +0000 (20:55 +0000)
CVS patchset: 7446
CVS date: 2004/10/10 20:55:11

lib/rpmgi.c
lib/rpmgi.h
lib/tgi.c

index 42fd7a2..65260bf 100644 (file)
@@ -61,6 +61,7 @@ fprintf(stderr, "*** gi %p\t%p[%d]\n", gi, gi->argv, gi->argc);
        break;
     }
 
+    gi->queryFormat = _free(gi->queryFormat);
     if (gi->ftsp != NULL) {
        int xx;
        xx = Fts_close(gi->ftsp);
@@ -146,6 +147,29 @@ static const char * ftsInfoStr(int fts_info) {
     return ftsInfoStrings[ fts_info ];
 }
 
+/*@only@*/
+static const char * rpmgiPathOrQF(rpmgi gi, const char * fn,
+               /*@null@*/ Header * hdrp)
+       /*@modifies gi, *hdrp @*/
+{
+    const char * fmt = ((gi->queryFormat != NULL)
+       ? gi->queryFormat : "%{name}-%{version}-%{release}");
+    const char * val = NULL;
+    Header h = NULL;
+
+    if (hdrp != NULL && *hdrp != NULL)
+       h = headerLink(*hdrp);
+
+    if (h != NULL)
+       val = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, NULL);
+    else
+       val = xstrdup(fn);
+
+    h = headerFree(h);
+
+    return val;
+}
+
 const char * rpmgiNext(/*@null@*/ rpmgi gi)
        /*@modifies gi @*/
 {
@@ -158,8 +182,7 @@ const char * rpmgiNext(/*@null@*/ rpmgi gi)
     case RPMGI_RPMDB:
        h = rpmdbNextIterator(gi->mi);
        if (h != NULL) {
-           const char * fmt = "%{NAME}-%{VERSION}-%{RELEASE}";
-           val = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, NULL);
+           val = rpmgiPathOrQF(gi, "rpmdb", &h);
        } else {
            gi->mi = rpmdbFreeIterator(gi->mi);
            gi->i = -1;
@@ -171,14 +194,19 @@ const char * rpmgiNext(/*@null@*/ rpmgi gi)
        if (gi->argv != NULL && gi->argv[gi->i] != NULL) {
 if (_rpmgi_debug  < 0)
 fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->argv, gi->i, gi->argv[gi->i]);
-           val = xstrdup(gi->argv[gi->i]);
+           val = rpmgiPathOrQF(gi, gi->argv[gi->i], NULL);
        } else
            gi->i = -1;
        break;
     case RPMGI_FTSWALK:
-       if (gi->ftsp == NULL && gi->i == 0)
+       if (gi->argv == NULL)
+           break;
+       if (gi->ftsp == NULL && gi->i == 0) {
            gi->ftsp = Fts_open(gi->argv, gi->ftsOpts, NULL);
+           /* XXX NULL with open(2)/malloc(3) errno set */
+       }
 
+       if (gi->ftsp != NULL)
        while (val == NULL && (gi->fts = Fts_read(gi->ftsp)) != NULL) {
            FTSENT * fts = gi->fts;
 
@@ -192,7 +220,7 @@ fprintf(stderr, "FTS_%s\t%*s %s\n", ftsInfoStr(fts->fts_info),
            case FTS_SL:
 if (_rpmgi_debug  < 0)
 fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->ftsp, gi->i, fts->fts_path);
-               val = xstrdup(fts->fts_path);
+               val = rpmgiPathOrQF(gi, fts->fts_path, NULL);
                break;
            default:
                break;
@@ -209,4 +237,17 @@ fprintf(stderr, "*** gi %p\t%p[%d]: %s\n", gi, gi->ftsp, gi->i, fts->fts_path);
 
     return val;
 }
+
+int rpmgiSetQueryFormat(rpmgi gi, const char * queryFormat)
+{
+    int rc = 0;
+                                                                                
+    if (gi != NULL) {
+       gi->queryFormat = _free(gi->queryFormat);
+        gi->queryFormat = xstrdup(queryFormat);
+    }
+    return rc;
+
+}
+
 /*@=modfilesys@*/
index 0ee41c5..5a7e1c2 100644 (file)
@@ -34,16 +34,24 @@ typedef enum rpmgiTag_e {
 /** \ingroup rpmio
  */
 struct rpmgi_s {
+/*@refcounted@*/
     rpmts ts;
     int tag;
     int i;
 
+/*@dependent@*/
     rpmdbMatchIterator mi;
 
+/*@only@*/
+    const char * queryFormat;
+
+/*@dependent@*/
     char *const * argv;
     int argc;
     int ftsOpts;
+/*@dependent@*/
     FTS * ftsp;
+/*@dependent@*/
     FTSENT * fts;
 
 /*@refs@*/
@@ -112,6 +120,9 @@ rpmgi rpmgiNew(rpmts ts, int tag, const void * keyp, size_t keylen)
 const char * rpmgiNext(/*@null@*/ rpmgi gi)
         /*@modifies gi @*/;
 
+int rpmgiSetQueryFormat(rpmgi gi, const char * queryFormat)
+       /*@modifies gi @*/;
+
 #ifdef __cplusplus
 }
 #endif
index 580d7f6..1508840 100644 (file)
--- a/lib/tgi.c
+++ b/lib/tgi.c
@@ -14,6 +14,8 @@
 static int gitag = RPMGI_FTSWALK;
 static int ftsOpts = 0;
 
+static const char * queryFormat = NULL;
+
 static struct poptOption optionsTable[] = {
  { "rpmgidebug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1,
        N_("debug generalized iterator"), NULL},
@@ -27,6 +29,11 @@ static struct poptOption optionsTable[] = {
  { "ftswalk", '\0', POPT_ARG_VAL, &gitag, RPMGI_FTSWALK,
        N_("iterate fts(3) walk"), NULL },
 
+ { "qf", '\0', POPT_ARG_STRING, &queryFormat, 0,
+        N_("use the following query format"), "QUERYFORMAT" },
+ { "queryformat", '\0', POPT_ARG_STRING, &queryFormat, 0,
+        N_("use the following query format"), "QUERYFORMAT" },
+
  { "comfollow", '\0', POPT_BIT_SET,    &ftsOpts, FTS_COMFOLLOW,
        N_("follow command line symlinks"), NULL },
  { "logical", '\0', POPT_BIT_SET,      &ftsOpts, FTS_LOGICAL,
@@ -44,16 +51,6 @@ static struct poptOption optionsTable[] = {
  { "whiteout", '\0', POPT_BIT_SET,     &ftsOpts, FTS_WHITEOUT,
        N_("return whiteout information"), NULL },
 
-#ifdef DYING
- { "ftpdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_ftp_debug, -1,
-       N_("debug protocol data stream"), NULL},
- { "rpmiodebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmio_debug, -1,
-       N_("debug rpmio I/O"), NULL},
- { "urldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_url_debug, -1,
-       N_("debug URL cache handling"), NULL},
- { "verbose", 'v', 0, 0, 'v',                          NULL, NULL },
-#endif
-
  { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0,
         N_("Common options for all rpm modes and executables:"),
         NULL },
@@ -84,6 +81,7 @@ main(int argc, char *const argv[])
     ts = rpmtsCreate();
     av = poptGetArgs(optCon);
     gi = rpmgiNew(ts, gitag, av, ftsOpts);
+    (void) rpmgiSetQueryFormat(gi, queryFormat);
 
     ac = 0;
     while ((arg = rpmgiNext(gi)) != NULL) {