comparison src/dumpblocks.c @ 16:c508ee15dfca

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