annotate src/dumpblocks.c @ 51:06c0262ad689 stable-0-6-5

code cleanup
author carl
date Tue, 22 Jan 2008 14:39:02 -0800
parents f66078abed38
children 034641c26ab9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
1 #include "define.h"
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
2
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 #include <stdio.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 #include <stdlib.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 #include <unistd.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6 #include "libpst.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8 #define OUT_BUF 20
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 int main(int argc, char **argv) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10 pst_file pstfile;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11 pst_index_ll *ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12 char *outdir=NULL, *file=NULL, *outname=NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 unsigned char *buf=NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14 int c;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15 FILE *fp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
17 while ((c=getopt(argc, argv, "o:"))!=-1) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
18 switch(c) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 case 'o':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
20 outdir=optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 printf("Unknown switch %c\n", c);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
24 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
25 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
26 if (optind < argc) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
27 file = argv[optind];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
28 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29 printf("Usage: dumpblocks [options] pstfile\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
30 printf("\tcopies the datablocks from the pst file into seperate files\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
31 printf("Options: \n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
32 printf("\t-o target\tSpecify the output directory\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 DEBUG_INIT("dumpblocks.log");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 DEBUG_REGISTER_CLOSE();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
37 DEBUG_ENT("main");
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
38
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
39 printf("Opening file %s\n",file);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
40 if (pst_open(&pstfile, file, "r")) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
41 printf("Failed to open file %s\n", file);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
42 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
43 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
44
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45 printf("Reading Indexes\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46 if (pst_load_index(&pstfile)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 printf("Failed to load indexes in file %s\n", argv[1]);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
48 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
49 }
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
50
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51 if (outdir != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52 if (chdir(outdir)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
53 printf("Failed to change into directory %s\n", outdir);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
54 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
55 }
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
56
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
57 ptr = pstfile.i_head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
58 outname = (char*) xmalloc(OUT_BUF);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
59 printf("Saving blocks\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
60 while (ptr != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
61 /* if (pstfile.encryption == PST_ENC) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
62 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
63 } else {*/
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
64 if ((ptr->id & 0x02)==0 && pstfile.encryption == PST_ENC) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
65 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
66 } else {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
67 c = pst_ff_getIDblock(&pstfile, ptr->id, &buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
68 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
69
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
70 if (c > 0) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
71 snprintf(outname, OUT_BUF, "%llx", ptr->id);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
72 if ((fp = fopen(outname, "wb")) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
73 printf("Failed to open file %s\n", outname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
74 continue;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
75 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
76 fwrite(buf, 1, c, fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
77 fclose(fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
78 } else {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 16
diff changeset
79 printf("Failed to read block id %#llx\n", ptr->id);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
80 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81 ptr = ptr->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83 pst_close(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
84 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
85 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
86 }