tools/dumpdb.c

Go to the documentation of this file.
00001 #include "system.h"
00002 const char *__progname;
00003 
00004 #include <rpmlib.h>
00005 #include "header_internal.h"
00006 
00007 #include "rpmdb.h"
00008 
00009 #include "debug.h"
00010 
00011 int main(int argc, char ** argv)
00012 {
00013     unsigned int dspBlockNum = 0;               /* default to all */
00014     rpmdb db;
00015 
00016     setprogname(argv[0]);       /* Retrofit glibc __progname */
00017     rpmReadConfigFiles(NULL, NULL);
00018 
00019     if (argc == 2) {
00020         dspBlockNum = atoi(argv[1]);
00021     } else if (argc != 1) {
00022         fprintf(stderr, _("dumpdb <block num>\n"));
00023         exit(1);
00024     }
00025 
00026     if (rpmdbOpen("", &db, O_RDONLY, 0644)) {
00027         fprintf(stderr, _("cannot open Packages\n"));
00028         exit(1);
00029     }
00030 
00031     {   Header h = NULL;
00032         unsigned int blockNum = 0;
00033         rpmdbMatchIterator mi;
00034 #define _RECNUM rpmdbGetIteratorOffset(mi)
00035 
00036         mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
00037 
00038         while ((h = rpmdbNextIterator(mi)) != NULL) {
00039 
00040             blockNum++;
00041             if (!(dspBlockNum != 0 && dspBlockNum != blockNum))
00042                 continue;
00043 
00044             headerDump(h, stdout, HEADER_DUMP_INLINE, rpmTagTable);
00045             fprintf(stdout, "Offset: %d\n", _RECNUM);
00046     
00047             if (dspBlockNum && blockNum > dspBlockNum)
00048                 exit(0);
00049         }
00050 
00051         mi = rpmdbFreeIterator(mi);
00052 
00053     }
00054 
00055     rpmdbClose(db);
00056 
00057     return 0;
00058 }

Generated on Fri Oct 12 08:44:55 2007 for rpm by  doxygen 1.5.2