# tools/dumpdb.c

Go to the documentation of this file.

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