diff src/dumpblocks.c @ 73:3cb02cb1e6cd stable-0-6-10

Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them). More changes for Fedora packaging (#434727) Fixes for const correctness.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 29 May 2008 18:51:02 -0700
parents 7d5c637aaafb
children 87216aefc6df
line wrap: on
line diff
--- a/src/dumpblocks.c	Fri May 16 09:06:17 2008 -0700
+++ b/src/dumpblocks.c	Thu May 29 18:51:02 2008 -0700
@@ -6,81 +6,82 @@
 #include "libpst.h"
 
 #define OUT_BUF 20
-int main(int argc, char **argv) {
-  pst_file pstfile;
-  pst_index_ll *ptr;
-  char *outdir=NULL, *file=NULL, *outname=NULL;
-  char *buf=NULL;
-  int c;
-  FILE *fp;
+int main(int argc, char **argv)
+{
+    pst_file pstfile;
+    pst_index_ll *ptr;
+    char *outdir = NULL, *file = NULL, *outname = NULL;
+    char *buf = NULL;
+    int c;
+    FILE *fp;
 
-  while ((c=getopt(argc, argv, "o:"))!=-1) {
-    switch(c) {
-    case 'o':
-      outdir=optarg;
-      break;
-    default:
-      printf("Unknown switch %c\n", c);
+    while ((c = getopt(argc, argv, "o:")) != -1) {
+        switch (c) {
+            case 'o':
+                outdir = optarg;
+                break;
+            default:
+                printf("Unknown switch %c\n", c);
+        }
     }
-  }
-  if (optind < argc) {
-    file = argv[optind];
-  } else {
-    printf("Usage: dumpblocks [options] pstfile\n");
-    printf("\tcopies the datablocks from the pst file into seperate files\n");
-    printf("Options: \n");
-    printf("\t-o target\tSpecify the output directory\n");
-    exit(1);
-  }
-  DEBUG_INIT("dumpblocks.log");
-  DEBUG_REGISTER_CLOSE();
-  DEBUG_ENT("main");
+    if (optind < argc) {
+        file = argv[optind];
+    } else {
+        printf("Usage: dumpblocks [options] pstfile\n");
+        printf("\tcopies the datablocks from the pst file into seperate files\n");
+        printf("Options: \n");
+        printf("\t-o target\tSpecify the output directory\n");
+        exit(1);
+    }
+    DEBUG_INIT("dumpblocks.log");
+    DEBUG_REGISTER_CLOSE();
+    DEBUG_ENT("main");
 
-  printf("Opening file %s\n",file);
-  if (pst_open(&pstfile, file)) {
-    printf("Failed to open file %s\n", file);
-    exit(1);
-  }
-
-  printf("Reading Indexes\n");
-  if (pst_load_index(&pstfile)) {
-    printf("Failed to load indexes in file %s\n", argv[1]);
-    exit(1);
-   }
-
-  if (outdir != NULL)
-    if (chdir(outdir)) {
-      printf("Failed to change into directory %s\n", outdir);
-      exit(1);
+    printf("Opening file %s\n", file);
+    if (pst_open(&pstfile, file)) {
+        printf("Failed to open file %s\n", file);
+        exit(1);
     }
 
-  ptr = pstfile.i_head;
-  outname = (char*) xmalloc(OUT_BUF);
-  printf("Saving blocks\n");
-  while (ptr != NULL) {
-    /*    if (pstfile.encryption == PST_ENC) {
-      c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf);
-      } else {*/
-    if ((ptr->id & 0x02)==0 && pstfile.encryption == PST_ENC) {
-      c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
-    } else {
-      c = pst_ff_getIDblock(&pstfile, ptr->id, &buf);
+    printf("Reading Indexes\n");
+    if (pst_load_index(&pstfile)) {
+        printf("Failed to load indexes in file %s\n", argv[1]);
+        exit(1);
     }
 
-    if (c > 0) {
-      snprintf(outname, OUT_BUF, "%llx", ptr->id);
-      if ((fp = fopen(outname, "wb")) == NULL) {
-	printf("Failed to open file %s\n", outname);
-	continue;
-      }
-      fwrite(buf, 1, c, fp);
-      fclose(fp);
-    } else {
-      printf("Failed to read block id %#llx\n", ptr->id);
+    if (outdir != NULL)
+        if (chdir(outdir)) {
+            printf("Failed to change into directory %s\n", outdir);
+            exit(1);
+        }
+
+    ptr = pstfile.i_head;
+    outname = (char *) xmalloc(OUT_BUF);
+    printf("Saving blocks\n");
+    while (ptr != NULL) {
+        /*    if (pstfile.encryption == PST_ENC) {
+           c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf);
+           } else { */
+        if ((ptr->id & 0x02) == 0 && pstfile.encryption == PST_ENC) {
+            c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
+        } else {
+            c = pst_ff_getIDblock(&pstfile, ptr->id, &buf);
+        }
+
+        if (c > 0) {
+            snprintf(outname, OUT_BUF, "%llx", ptr->id);
+            if ((fp = fopen(outname, "wb")) == NULL) {
+                printf("Failed to open file %s\n", outname);
+                continue;
+            }
+            pst_fwrite(buf, 1, c, fp);
+            fclose(fp);
+        } else {
+            printf("Failed to read block id %#llx\n", ptr->id);
+        }
+        ptr = ptr->next;
     }
-    ptr = ptr->next;
-  }
-  pst_close(&pstfile);
-  DEBUG_RET();
-  return 0;
+    pst_close(&pstfile);
+    DEBUG_RET();
+    return 0;
 }