Initial revision
authorewt <devnull@localhost>
Tue, 20 Feb 1996 20:55:04 +0000 (20:55 +0000)
committerewt <devnull@localhost>
Tue, 20 Feb 1996 20:55:04 +0000 (20:55 +0000)
CVS patchset: 362
CVS date: 1996/02/20 20:55:04

tools/dump.c [new file with mode: 0644]
tools/dumpdb.c [new file with mode: 0644]

diff --git a/tools/dump.c b/tools/dump.c
new file mode 100644 (file)
index 0000000..906cf6a
--- /dev/null
@@ -0,0 +1,35 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "header.h"
+
+void main(int argc, char ** argv)
+{
+    Header h;
+    int fd;
+
+    if (argc != 2) {
+       fprintf(stderr, "dump <filespec>\n");
+       exit(1);
+    }
+
+    fd = open(argv[1], O_RDONLY);
+    if (fd < 0) {
+       fprintf(stderr, "cannot open %s: %s\n", argv[1], strerror(errno));
+       exit(1);
+    }
+
+    h = readHeader(fd);
+    if (!h) {
+       fprintf(stderr, "readHeader error: %s\n", strerror(errno));
+       exit(1);
+    }
+    close(fd);
+  
+    dumpHeader(h, stdout, 1);
+    freeHeader(h);
+}
+
+  
diff --git a/tools/dumpdb.c b/tools/dumpdb.c
new file mode 100644 (file)
index 0000000..b893365
--- /dev/null
@@ -0,0 +1,54 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "header.h"
+#include "rpmlib.h"
+
+void main(int argc, char ** argv)
+{
+    Header h;
+    int offset;
+    int dspBlockNum = 0;                       /* default to all */
+    int blockNum = 0;
+    rpmdb db;
+
+    if (argc == 2) {
+       dspBlockNum = atoi(argv[1]);
+    } else if (argc != 1) {
+       fprintf(stderr, "dumpdb <block num>\n");
+       exit(1);
+    }
+
+    if (!rpmdbOpen("", &db, O_RDONLY, 0644)) {
+       fprintf(stderr, "cannot open /var/lib/rpm/packages.rpm\n");
+       exit(1);
+    }
+
+    offset = rpmdbFirstRecNum(db);
+    while (offset) {
+       blockNum++;
+
+       if (!dspBlockNum || dspBlockNum == blockNum) {
+           h = rpmdbGetRecord(db, offset);
+           if (!h) {
+               fprintf(stderr, "readHeader failed\n");
+               exit(1);
+           }
+         
+           dumpHeader(h, stdout, 1);
+           printf("Offset: %d\n", offset);
+           freeHeader(h);
+       }
+    
+       if (dspBlockNum && blockNum > dspBlockNum) exit(0);
+
+       offset = rpmdbNextRecNum(db, offset);
+    }
+
+    rpmdbClose(db);
+}
+
+