annotate src/dumpblocks.c @ 40:be6d5329cc01 stable-0-5-11

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