Main Page Modules Data Structures File List Data Fields Globals Related Pages

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