changeset 202:2f38c4ce606f

remove readpstlog, switch to plain ascii debug log files
author Carl Byington <carl@five-ten-sg.com>
date Mon, 18 May 2009 15:55:05 -0700
parents 3850a3b11745
children 9fb600ef4e03
files ChangeLog TODO libpst.spec.in regression/regression-tests.bash src/Makefile.am src/debug.c src/define.h src/dumpblocks.c src/getidblock.c src/libpst.c src/lspst.c src/pst2dii.cpp.in src/pst2ldif.cpp src/readpst.c xml/libpst.in
diffstat 15 files changed, 432 insertions(+), 1041 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat May 16 10:32:26 2009 -0700
+++ b/ChangeLog	Mon May 18 15:55:05 2009 -0700
@@ -11,6 +11,8 @@
     * decode more recurrence mapi elements.
     * change interfaces to be thread safe.
     * readpst changes for parallel operation on multi processor machines.
+    * remove readpstlog - the debug log files are now plain ascii. Add locking
+      if needed so parallel jobs can produce debug logs.
 
 LibPST 0.6.37 (2009-04-17)
 ===============================
--- a/TODO	Sat May 16 10:32:26 2009 -0700
+++ b/TODO	Mon May 18 15:55:05 2009 -0700
@@ -6,7 +6,3 @@
 
 At the next soname bump (to libpst.so.5) we should
     move some of readpst into the shared library, in particular write_normal_email()
-    remove readpstlog, and produce ascii debug log files
-    add debug FILE* into the pst_file structure, so all debug printing
-        will be passed the pst_file struct. Also add a semaphore in there
-        to synchronize debug printing.
--- a/libpst.spec.in	Sat May 16 10:32:26 2009 -0700
+++ b/libpst.spec.in	Mon May 18 15:55:05 2009 -0700
@@ -152,6 +152,8 @@
 - add python interface to the shared library.
 - bump soname to version 4 for many changes to the interface.
 - better decoding of recurrence data in appointments.
+- remove readpstlog since debug log files are now plain text.
+- add readpst -j option for parallel jobs for each folder.
 
 * Fri Apr 17 2009 Carl Byington <carl@five-ten-sg.com> - 0.6.37-1
 - add pst_attach_to_mem() back into the shared library interface.
--- a/regression/regression-tests.bash	Sat May 16 10:32:26 2009 -0700
+++ b/regression/regression-tests.bash	Mon May 18 15:55:05 2009 -0700
@@ -49,17 +49,13 @@
     fn="$2"
     echo $fn
     ba=$(basename "$fn" .pst)
+    jobs=""
+    [ -n "$val" ] && jobs="-j 0"
     rm -rf output$n
     mkdir output$n
-    #    ../src/readpst -cv -o output$n $fn >$ba.err 2>&1
-    #           readpst -cv -o output$n -d dumper $fn >$ba.err 2>&1
-    $val ../src/readpst -r -D -cv -o output$n  $fn
-  # $val ../src/readpst -r -D -cv -o output$n -d dumper $fn >$ba.err 2>&1
-  #      ../src/readpstlog -f I dumper >$ba.log
-
-    #../src/getidblock -d -p $fn 0 >$ba.fulldump
-    #../src/readpstlog -f I getidblock.log >$ba.fulldump.log
-
+    #val ../src/readpst $jobs -r -D -cv -o output$n            $fn
+    $val ../src/readpst $jobs -r -D -cv -o output$n -d $ba.log $fn >$ba.err 2>&1
+    #../src/getidblock -p $fn 0 >$ba.fulldump
     #rm -f dumper
 }
 
@@ -95,38 +91,38 @@
     doldif  13 test-text.pst
     doldif  14 joe.romanowski.pst
     doldif  15 hourig1.pst
-    #doldif  16 hourig2.pst
-    #doldif  17 hourig3.pst
+    doldif  16 hourig2.pst
+    doldif  17 hourig3.pst
     doldif  18 test-mac.pst
-    #doldif  19 harris.pst
+    doldif  19 harris.pst
     doldif  20 spam.pst
-    dolif   21 rendgen.pst
+    doldif  21 rendgen.pst
 else
-    #dopst   1 ams.pst
-    #dopst   2 sample_64.pst
-    #dopst   3 test.pst
-    #dopst   4 big_mail.pst
-    #dopst   5 mbmg.archive.pst
-    #dopst   6 Single2003-read.pst
-    #dopst   7 Single2003-unread.pst
-    #dopst   8 ol2k3high.pst
-    #dopst   9 ol97high.pst
-    #dopst  10 returned_message.pst
-    #dopst  11 flow.pst
-    #dopst  12 test-html.pst
-    #dopst  13 test-text.pst
-    #dopst  14 joe.romanowski.pst
-    #dopst  15 hourig1.pst
-    dopst  16 hourig2.pst
+    dopst   1 ams.pst
+    dopst   2 sample_64.pst
+    dopst   3 test.pst
+    dopst   4 big_mail.pst
+    dopst   5 mbmg.archive.pst
+    dopst   6 Single2003-read.pst
+    dopst   7 Single2003-unread.pst
+    dopst   8 ol2k3high.pst
+    dopst   9 ol97high.pst
+    dopst  10 returned_message.pst
+    dopst  11 flow.pst
+    dopst  12 test-html.pst
+    dopst  13 test-text.pst
+    dopst  14 joe.romanowski.pst
+    dopst  15 hourig1.pst
+    #dopst  16 hourig2.pst
     #dopst  17 hourig3.pst
-    #dopst  18 test-mac.pst
-    #dopst  19 harris.pst
-    #dopst  20 spam.pst
-    #dopst  21 rendgen.pst       # single email appointment
-    #dopst  22 rendgen2.pst      # email appointment with no termination date
-    #dopst  23 rendgen3.pst      # mime signed email
-    #dopst  24 rendgen4.pst      # appointment test cases
-    #dopst  25 rendgen5.pst      # appointment test cases
+    dopst  18 test-mac.pst
+    dopst  19 harris.pst
+    dopst  20 spam.pst
+    dopst  21 rendgen.pst       # single email appointment
+    dopst  22 rendgen2.pst      # email appointment with no termination date
+    dopst  23 rendgen3.pst      # mime signed email
+    dopst  24 rendgen4.pst      # appointment test cases
+    dopst  25 rendgen5.pst      # appointment test cases
 fi
 
 grep 'lost:' *err | grep -v 'lost: 0 '
--- a/src/Makefile.am	Sat May 16 10:32:26 2009 -0700
+++ b/src/Makefile.am	Mon May 18 15:55:05 2009 -0700
@@ -32,13 +32,12 @@
 endif
 
 noinst_PROGRAMS     = deltasearch dumpblocks getidblock
-bin_PROGRAMS        = lspst readpst readpstlog pst2ldif
+bin_PROGRAMS        = lspst readpst pst2ldif
 if BUILD_DII
     bin_PROGRAMS   += pst2dii
 endif
 lspst_SOURCES       = lspst.c          $(common_header)
 readpst_SOURCES     = readpst.c        $(common_header)
-readpstlog_SOURCES  = readpstlog.c     $(common_header)
 pst2ldif_SOURCES    = pst2ldif.cpp     $(common_header)
 pst2dii_SOURCES     = pst2dii.cpp      $(common_header)
 deltasearch_SOURCES = deltasearch.cpp  $(common_header)
@@ -47,7 +46,6 @@
 
 lspst_CFLAGS        = $(AM_CFLAGS)
 readpst_CFLAGS      = $(AM_CFLAGS)
-readpstlog_CFLAGS   = $(AM_CFLAGS)
 pst2ldif_CFLAGS     = $(AM_CFLAGS)
 pst2dii_CFLAGS      = $(AM_CFLAGS)
 deltasearch_CFLAGS  = $(AM_CFLAGS)
@@ -56,7 +54,6 @@
 
 lspst_DEPENDENCIES        = libpst.la
 readpst_DEPENDENCIES      = libpst.la
-readpstlog_DEPENDENCIES   = libpst.la
 pst2ldif_DEPENDENCIES     = libpst.la
 pst2dii_DEPENDENCIES      = libpst.la
 deltasearch_DEPENDENCIES  = libpst.la
@@ -81,8 +78,7 @@
 libpst_la_SOURCES     = $(common_source) $(common_header)
 libpst_la_LIBADD      = $(LTLIBICONV)
 
-
-EXTRA_DIST = testdebug.c
+EXTRA_DIST =
 if !NEED_XGETOPT
     EXTRA_DIST += XGetopt.c XGetopt.h
 endif
@@ -93,7 +89,6 @@
 # the library search path.
 lspst_LDADD       = $(all_libraries) $(PSTLIB) $(LTLIBICONV)
 readpst_LDADD     = $(all_libraries) $(PSTLIB) $(LTLIBICONV) $(REGEXLIB)
-readpstlog_LDADD  = $(all_libraries) $(PSTLIB) $(LTLIBICONV)
 pst2ldif_LDADD    = $(all_libraries) $(PSTLIB) $(LTLIBICONV)
 pst2dii_LDADD     = $(all_libraries) $(PSTLIB) $(LTLIBICONV) -lgd
 dumpblocks_LDADD  = $(all_libraries) $(PSTLIB) $(LTLIBICONV)
--- a/src/debug.c	Sat May 16 10:32:26 2009 -0700
+++ b/src/debug.c	Mon May 18 15:55:05 2009 -0700
@@ -1,73 +1,135 @@
 #include "define.h"
 
-struct pst_debug_item {
-    int type;
-    char * function;
-    unsigned int line;
-    char * file;
-    char * text;
-    struct pst_debug_item *next;
-};
-
-static struct pst_debug_item *item_head=NULL, *item_tail=NULL, *item_ptr=NULL, *info_ptr=NULL, *temp_list=NULL;
-
 
 struct pst_debug_func {
     char * name;
     struct pst_debug_func *next;
 };
 
-static struct pst_debug_func *func_head=NULL, *func_ptr=NULL;
+
+#define NUM_COL 32
+#define MAX_DEPTH 32
+
+static struct pst_debug_func *func_head = NULL;
+static int func_depth = 0;
+static char indent[MAX_DEPTH*4+1];
+static FILE *debug_fp = NULL;
+#ifdef HAVE_SEMAPHORE_H
+    static sem_t* debug_mutex = NULL;
+#endif
+
+
+void pst_debug_lock()
+{
+    #ifdef HAVE_SEMAPHORE_H
+        if (debug_mutex) sem_wait(debug_mutex);
+    #endif
+}
 
 
-static void pst_debug_write_msg(struct pst_debug_item *item, const char *fmt, va_list *ap, int size);
-static void pst_debug_write_hex(struct pst_debug_item *item, char *buf, size_t size, int col);
-static void pst_debug_write();
+void pst_debug_unlock()
+{
+    #ifdef HAVE_SEMAPHORE_H
+        if (debug_mutex) sem_post(debug_mutex);
+    #endif
+}
 
 
-static size_t pst_debug_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
-static size_t pst_debug_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream) {
-    return fwrite(ptr, size, nitems, stream);
+void pst_debug_init(const char* fname, void* output_mutex) {
+    #ifdef HAVE_SEMAPHORE_H
+        debug_mutex = (sem_t*)output_mutex;
+    #endif
+    memset(indent, ' ', MAX_DEPTH);
+    indent[MAX_DEPTH] = '\0';
+    if (debug_fp) pst_debug_close();
+    if (!fname) return;
+    if ((debug_fp = fopen(fname, "wb")) == NULL) {
+        fprintf(stderr, "Opening of file %s failed\n", fname);
+        exit(1);
+    }
 }
 
 
-// the largest text size we will store in memory. Otherwise we
-// will do a debug_write, then create a new record, and write the
-// text body directly to the file
-#define MAX_MESSAGE_SIZE 4096
+void pst_debug_func(const char* function) {
+    struct pst_debug_func *func_ptr = pst_malloc (sizeof(struct pst_debug_func));
+    func_ptr->name = strdup(function);
+    func_ptr->next = func_head;
+    func_head = func_ptr;
+    func_depth++;
+}
+
 
-void pst_debug(const char *fmt, ...) {
-    va_list ap;
-    va_start(ap,fmt);
-    vfprintf(stderr, fmt, ap);
-    va_end(ap);
+void pst_debug_func_ret() {
+    //remove the head item
+    struct pst_debug_func *func_ptr = func_head;
+    if (func_head) {
+        func_head = func_head->next;
+        free(func_ptr->name);
+        free(func_ptr);
+        func_depth--;
+    } else {
+        DIE(("function list is empty!\n"));
+    }
 }
 
 
-#define NUM_COL 30
-void pst_debug_hexdumper(FILE *out, char *buf, size_t size, int col, int delta) {
+static void pst_debug_info(int line, const char* file);
+static void pst_debug_info(int line, const char* file) {
+    int le = (func_depth > MAX_DEPTH) ? MAX_DEPTH : func_depth;
+    if (le > 0) le--;
+    char *func = (func_head ? func_head->name : "No Function");
+    pst_debug_lock();
+    fprintf(debug_fp, "%06d %.*s%s %s(%d) ", getpid(), le*4, indent, func, file, line);
+}
+
+
+void pst_debug(int line, const char* file, const char *fmt, ...) {
+    if (debug_fp) {
+        pst_debug_info(line, file);
+            va_list ap;
+            va_start(ap,fmt);
+            vfprintf(debug_fp, fmt, ap);
+            va_end(ap);
+            fflush(debug_fp);
+        pst_debug_unlock();
+    }
+}
+
+
+void pst_debug_hexdump(int line, const char *file, const char *buf, size_t size, int cols, int delta) {
+    if (debug_fp) {
+        pst_debug_info(line, file);
+           pst_debug_hexdumper(debug_fp, buf, size, cols, delta);
+        pst_debug_unlock();
+    }
+}
+
+
+void pst_debug_hexdumper(FILE *out, const char *buf, size_t size, int cols, int delta) {
+    int le = (func_depth > MAX_DEPTH) ? MAX_DEPTH : func_depth;
     size_t off = 0, toff;
     int count = 0;
 
     if (!out) return;   // no file
-    if (col == -1) col = NUM_COL;
+
+    if (cols == -1) cols = NUM_COL;
     fprintf(out, "\n");
     while (off < size) {
-        fprintf(out, "%06"PRIx64"\t:", (int64_t)(off+delta));
+        fprintf(out, "%06d %.*s%06"PRIx64"\t:", getpid(), le*4, indent, (int64_t)(off+delta));
         toff = off;
-        while (count < col && off < size) {
+        while (count < cols && off < size) {
             fprintf(out, "%02hhx ", (unsigned char)buf[off]);
             off++; count++;
         }
         off = toff;
-        while (count < col) {
+        while (count < cols) {
             // only happens at end of block to pad the text over to the text column
             fprintf(out, "   ");
             count++;
         }
         count = 0;
         fprintf(out, ":");
-        while (count < col && off < size) {
+        while (count < cols && off < size) {
             fprintf(out, "%c", isgraph(buf[off])?buf[off]:'.');
             off++; count ++;
         }
@@ -77,172 +139,13 @@
     }
 
     fprintf(out, "\n");
-}
-
-
-static FILE *debug_fp = NULL;
-static unsigned int max_items=DEBUG_MAX_ITEMS, curr_items=0;
-
-
-void pst_debug_init(const char* fname) {
-    unsigned char version = DEBUG_VERSION;
-    item_head = item_tail = NULL;
-    curr_items = 0;
-    if (debug_fp) pst_debug_close();
-    if (!fname) return;
-    if ((debug_fp = fopen(fname, "wb")) == NULL) {
-      fprintf(stderr, "Opening of file %s failed\n", fname);
-      exit(1);
-    }
-    pst_debug_fwrite(&version, sizeof(char), 1, debug_fp);
-}
-
-
-// function must be called before pst_debug_msg. It sets up the
-// structure for the function that follows
-void pst_debug_msg_info(int line, const char* file, int type) {
-    char *x;
-    if (!debug_fp) return;  // no file
-    info_ptr = (struct pst_debug_item*) pst_malloc(sizeof(struct pst_debug_item));
-    info_ptr->type = type;
-    info_ptr->line = line;
-    x = (func_head==NULL?"No Function":func_head->name);
-    info_ptr->function = (char*) pst_malloc(strlen(x)+1);
-    strcpy(info_ptr->function, x);
-
-    info_ptr->file = (char*) pst_malloc(strlen(file)+1);
-    strcpy(info_ptr->file, file);
-
-    //put the current record on a temp linked list
-    info_ptr->next = temp_list;
-    temp_list = info_ptr;
-}
-
-
-void pst_debug_msg_text(const char* fmt, ...) {
-    va_list ap;
-    int f, g;
-    char x[2];
-    #ifdef _WIN32
-        char *buf = NULL;
-    #endif
-    struct pst_debug_item *temp;
-    if (!debug_fp) return;  // no file
-    // get the record off of the temp_list
-    info_ptr = temp_list;
-    if (info_ptr)
-        temp_list = info_ptr->next;
-    else {
-        fprintf(stderr, "NULL info_ptr. ERROR!!\n");
-        exit(-2);
-    }
-
-    #ifdef _WIN32
-        // vsnprintf trick doesn't work on msvc.
-        g = 2000;
-        f = -1;
-        while (f < 0) {
-            buf = realloc(buf, g+1);
-            va_start(ap, fmt);
-            f = vsnprintf(buf, g, fmt, ap);
-            va_end(ap);
-            g += g/2;
-        }
-        free(buf);
-    #else
-        // according to glibc 2.1, this should return the req. number of bytes for
-        // the string
-        va_start(ap, fmt);
-        f = vsnprintf(x, 1, fmt, ap);
-        va_end(ap);
-    #endif
-
-    if (f > 0 && f < MAX_MESSAGE_SIZE) {
-        info_ptr->text = (char*) pst_malloc(f+1);
-        va_start(ap, fmt);
-        if ((g = vsnprintf(info_ptr->text, f, fmt, ap)) == -1) {
-            fprintf(stderr, "_debug_msg: Dying! vsnprintf returned -1 for format \"%s\"\n", fmt);
-            exit(-2);
-        }
-        va_end(ap);
-        info_ptr->text[g] = '\0';
-        if (f != g) {
-            fprintf(stderr, "_debug_msg: f != g\n");
-        }
-    } else if (f > 0) { // it is over the max_message_size then
-        f += strlen(info_ptr->file)+strlen(info_ptr->function);
-        temp = info_ptr;
-        pst_debug_write(); // dump the current messages
-        info_ptr = temp;
-        va_start(ap, fmt);
-        pst_debug_write_msg(info_ptr, fmt, &ap, f);
-        va_end(ap);
-        free(info_ptr->function);
-        free(info_ptr->file);
-        free(info_ptr);
-        info_ptr = NULL;
-        return;
-    } else {
-        fprintf(stderr, "_debug_msg: error getting requested size of debug message\n");
-        info_ptr->text = "ERROR Saving\n";
-    }
-
-    // add to the linked list of pending items
-    if (!item_head) item_head = info_ptr;
-    info_ptr->next = NULL;
-    if (item_tail) item_tail->next = info_ptr;
-    item_tail = info_ptr;
-
-    if (++curr_items == max_items) {
-        // here we will jump off and save the contents
-        pst_debug_write();
-        info_ptr = NULL;
-    }
-}
-
-
-void pst_debug_hexdump(char *x, size_t y, int cols, int delta) {
-    struct pst_debug_item *temp;
-    if (!debug_fp) return;  // no file
-    info_ptr = temp_list;
-    if (info_ptr) temp_list = info_ptr->next;
-    temp = info_ptr;
-    pst_debug_write();
-    info_ptr = temp;
-    pst_debug_write_hex(info_ptr, x, y, cols);
-    free(info_ptr->function);
-    free(info_ptr->file);
-    free(info_ptr);
-    info_ptr = NULL;
-}
-
-
-void pst_debug_func(const char *function) {
-    func_ptr = pst_malloc (sizeof(struct pst_debug_func));
-    func_ptr->name = pst_malloc(strlen(function)+1);
-    strcpy(func_ptr->name, function);
-    func_ptr->next = func_head;
-    func_head = func_ptr;
-}
-
-
-void pst_debug_func_ret() {
-    //remove the head item
-    func_ptr = func_head;
-    if (func_head) {
-        func_head = func_head->next;
-        free(func_ptr->name);
-        free(func_ptr);
-    } else {
-        DIE(("function list is empty!\n"));
-    }
+    fflush(out);
 }
 
 
 void pst_debug_close(void) {
-    pst_debug_write();
     while (func_head) {
-        func_ptr = func_head;
+        struct pst_debug_func *func_ptr = func_head;
         func_head = func_head->next;
         free(func_ptr->name);
         free(func_ptr);
@@ -252,195 +155,6 @@
 }
 
 
-static void pst_debug_write() {
-    size_t size, ptr, funcname, filename, text, end;
-    char *buf = NULL, rec_type;
-    if (!debug_fp) return;  // no file
-    int64_t index_pos = ftello(debug_fp);
-    int64_t file_pos  = index_pos;
-    // add 2. One for the pointer to the next index,
-    // one for the count of this index
-    int index_size = ((curr_items+2) * sizeof(int64_t));
-    int64_t *index;
-    int index_ptr = 0;
-    struct pst_debug_file_rec_m mfile_rec;
-    struct pst_debug_file_rec_l lfile_rec;
-
-    if (curr_items == 0) return;    // no items to write.
-
-    index = (int64_t*)pst_malloc(index_size);
-    memset(index, 0, index_size);   // valgrind, avoid writing uninitialized data
-    file_pos += index_size;
-    // write the index first, we will re-write it later, but
-    // we want to allocate the space
-    pst_debug_fwrite(index, index_size, 1, debug_fp);
-    index[index_ptr++] = curr_items;
-
-    item_ptr = item_head;
-    while (item_ptr) {
-        file_pos = ftello(debug_fp);
-        index[index_ptr++] = file_pos;
-        size = strlen(item_ptr->function) +
-               strlen(item_ptr->file)     +
-               strlen(item_ptr->text)     + 3; //for the three \0s
-        if (buf) free(buf);
-        buf = pst_malloc(size+1);
-        ptr = 0;
-        funcname=ptr;
-        ptr += sprintf(&(buf[ptr]), "%s", item_ptr->function)+1;
-        filename=ptr;
-        ptr += sprintf(&(buf[ptr]), "%s", item_ptr->file)+1;
-        text=ptr;
-        ptr += sprintf(&(buf[ptr]), "%s", item_ptr->text)+1;
-        end=ptr;
-        if (end > USHRT_MAX) { // bigger than can be stored in a short
-            rec_type = 'L';
-            pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-            lfile_rec.type     = item_ptr->type;
-            lfile_rec.line     = item_ptr->line;
-            lfile_rec.funcname = funcname;
-            lfile_rec.filename = filename;
-            lfile_rec.text     = text;
-            lfile_rec.end      = end;
-            pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-        } else {
-            rec_type = 'M';
-            pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-            mfile_rec.type     = item_ptr->type;
-            mfile_rec.line     = item_ptr->line;
-            mfile_rec.funcname = funcname;
-            mfile_rec.filename = filename;
-            mfile_rec.text     = text;
-            mfile_rec.end      = end;
-            pst_debug_fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
-        }
-        pst_debug_fwrite(buf, ptr, 1, debug_fp);
-        if (buf) free(buf); buf = NULL;
-        item_head = item_ptr->next;
-        free(item_ptr->function);
-        free(item_ptr->file);
-        free(item_ptr->text);
-        free(item_ptr);
-        item_ptr = item_head;
-    }
-    curr_items = 0;
-    index[index_ptr] = ftello(debug_fp);
-
-    // we should now have a complete index
-    fseeko(debug_fp, index_pos, SEEK_SET);
-    pst_debug_fwrite(index, index_size, 1, debug_fp);
-    fseeko(debug_fp, 0, SEEK_END);
-    item_ptr = item_head = item_tail = NULL;
-    free(index);
-    if (buf) free(buf);
-}
-
-
-static void pst_debug_write_msg(struct pst_debug_item *item, const char *fmt, va_list *ap, int size) {
-    struct pst_debug_file_rec_l lfile_rec;
-    struct pst_debug_file_rec_m mfile_rec;
-    unsigned char rec_type;
-    int index_size = 3 * sizeof(int64_t);
-    int64_t index[3];
-    int64_t index_pos, file_pos;
-    char zero = '\0';
-    unsigned int end;
-    if (!debug_fp) return;  // no file
-    index[0] = 1; // only one item in this index
-    index[1] = 0; // valgrind, avoid writing uninitialized data
-    index[2] = 0; // ""
-    index_pos = ftello(debug_fp);
-    pst_debug_fwrite(index, index_size, 1, debug_fp);
-
-    index[1] = ftello(debug_fp);
-
-    if (size > USHRT_MAX) { // bigger than can be stored in a short
-        rec_type = 'L';
-        pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-        lfile_rec.type     = item->type;
-        lfile_rec.line     = item->line;
-        lfile_rec.funcname = 0;
-        lfile_rec.filename = strlen(item->function)+1;
-        lfile_rec.text     = lfile_rec.filename+strlen(item->file)+1;
-        lfile_rec.end      = 0; // valgrind, avoid writing uninitialized data
-        pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-    } else {
-        rec_type = 'M';
-        pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-        mfile_rec.type     = item->type;
-        mfile_rec.line     = item->line;
-        mfile_rec.funcname = 0;
-        mfile_rec.filename = strlen(item->function)+1;
-        mfile_rec.text     = mfile_rec.filename+strlen(item->file)+1;
-        mfile_rec.end      = 0; // valgrind, avoid writing uninitialized data
-        pst_debug_fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
-    }
-    file_pos = ftello(debug_fp);
-    pst_debug_fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
-    pst_debug_fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
-    vfprintf(debug_fp, fmt, *ap);
-    pst_debug_fwrite(&zero, 1, 1, debug_fp);
-
-    end = (unsigned int) (ftello(debug_fp) - file_pos);
-
-    index[2] = ftello(debug_fp);
-    fseeko(debug_fp, index_pos, SEEK_SET);
-    pst_debug_fwrite(index, index_size, 1, debug_fp);
-    if (size > USHRT_MAX) {
-        pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-        lfile_rec.end = end;
-        pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-    } else {
-        pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-        mfile_rec.end = end;
-        pst_debug_fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
-    }
-    fseeko(debug_fp, 0, SEEK_END);
-}
-
-
-void pst_debug_write_hex(struct pst_debug_item *item, char *buf, size_t size, int col) {
-    struct pst_debug_file_rec_l lfile_rec;
-    unsigned char rec_type;
-    int index_size = 3 * sizeof(int64_t);
-    int64_t index_pos, file_pos, index[3];
-    char zero='\0';
-    if (!debug_fp) return;  // no file
-    index[0] = 1; // only one item in this index run
-    index[1] = 0; // valgrind, avoid writing uninitialized data
-    index[2] = 0; // ""
-    index_pos = ftello(debug_fp);
-    pst_debug_fwrite(index, index_size, 1, debug_fp);
-    index[1] = ftello(debug_fp);
-
-    // always use the long
-    rec_type = 'L';
-    pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-    lfile_rec.funcname = 0;
-    lfile_rec.filename = strlen(item->function)+1;
-    lfile_rec.text = lfile_rec.filename+strlen(item->file)+1;
-    lfile_rec.end  = 0; // valgrind, avoid writing uninitialized data
-    lfile_rec.line = item->line;
-    lfile_rec.type = item->type;
-    pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-
-    file_pos = ftello(debug_fp);
-    pst_debug_fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
-    pst_debug_fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
-
-    pst_debug_hexdumper(debug_fp, buf, size, col, 0);
-    pst_debug_fwrite(&zero, 1, 1, debug_fp);
-    lfile_rec.end = ftello(debug_fp) - file_pos;
-
-    index[2] = ftello(debug_fp);
-    fseeko(debug_fp, index_pos, SEEK_SET);
-    pst_debug_fwrite(index, index_size, 1, debug_fp);
-    pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
-    pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-    fseeko(debug_fp, 0, SEEK_END);
-}
-
-
 void *pst_malloc(size_t size) {
     void *mem = malloc(size);
     if (!mem) {
--- a/src/define.h	Sat May 16 10:32:26 2009 -0700
+++ b/src/define.h	Mon May 18 15:55:05 2009 -0700
@@ -17,32 +17,6 @@
 #include "libstrfunc.h"
 #include "vbuf.h"
 
-#define DEBUG_MODE_GEN
-#define DEBUGPRINT
-#define DEBUG_MODE_WARN
-#define DEBUG_MODE_READ
-#define DEBUG_MODE_EMAIL
-#define DEBUG_MODE_MAIN
-#define DEBUG_MODE_INDEX
-#define DEBUG_MODE_CODE
-#define DEBUG_MODE_INFO
-#define DEBUG_MODE_HEXDUMP
-#define DEBUG_MODE_FUNC
-
-//number of items to save in memory between writes
-#define DEBUG_MAX_ITEMS 0
-
-#define DEBUG_FILE_NO     1
-#define DEBUG_INDEX_NO    2
-#define DEBUG_EMAIL_NO    3
-#define DEBUG_WARN_NO     4
-#define DEBUG_READ_NO     5
-#define DEBUG_INFO_NO     6
-#define DEBUG_MAIN_NO     7
-#define DEBUG_DECRYPT_NO  8
-#define DEBUG_FUNCENT_NO  9
-#define DEBUG_FUNCRET_NO 10
-#define DEBUG_HEXDUMP_NO 11
 
 #ifdef HAVE_TIME_H
     #include <time.h>
@@ -153,157 +127,54 @@
 #endif
 
 
-void  pst_debug(const char *fmt, ...);
-void  pst_debug_hexdumper(FILE* out, char* buf, size_t size, int col, int delta);
-void  pst_debug_hexprint(char *data, int size);
-void  pst_debug_init(const char *fname);
-void  pst_debug_msg_info (int line, const char *file, int type);
-void  pst_debug_msg_text(const char* fmt, ...);
-void  pst_debug_hexdump(char *x, size_t y, int cols, int delta);
-void  pst_debug_func(const char *function);
+void  pst_debug_lock();
+void  pst_debug_unlock();
+void  pst_debug_init(const char* fname, void* output_mutex);
+void  pst_debug_func(const char* function);
 void  pst_debug_func_ret();
+void  pst_debug(int line, const char *file, const char *fmt, ...);
+void  pst_debug_hexdump(int line, const char *file, const char* buf, size_t size, int cols, int delta);
+void  pst_debug_hexdumper(FILE* out, const char* buf, size_t size, int cols, int delta);
 void  pst_debug_close(void);
 void* pst_malloc(size_t size);
 
-#define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\
-                           pst_debug_msg_text x;}
-
-#define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();}
+#define MESSAGEPRINT(...) pst_debug(__LINE__, __FILE__,  __VA_ARGS__)
 
-#define DIE(x) {            \
-    MESSAGEPRINT(x, 0);     \
-    printf x;               \
-    fflush(stdout);         \
-    exit(EXIT_FAILURE);     \
-}
 #define WARN(x) {           \
-    MESSAGEPRINT(x, 0);     \
-    printf x;               \
-    fflush(stdout);         \
+    MESSAGEPRINT x;         \
+    pst_debug_lock();       \
+        printf x;           \
+        fflush(stdout);     \
+    pst_debug_unlock();     \
 }
 
-#ifdef DEBUGPRINT
-#define DEBUG_PRINT(x) pst_debug x;
-#else
-#define DEBUG_PRINT(x) {}
-#endif
-
-#ifdef DEBUG_MODE_GEN
-#define DEBUG(x) {DEBUG_PRINT(x);}
-#else
-#define DEBUG(x) {}
-#endif
-
-#ifdef DEBUG_MODE_INDEX
-#define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO);
-#else
-#define DEBUG_INDEX(x) {}
-#endif
-
-#ifdef DEBUG_MODE_EMAIL
-#define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
-#define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\
-                                   pst_debug_hexdump((char*)x, y, 0x10, 0);}
-#else
-#define DEBUG_EMAIL(x) {}
-#define DEBUG_EMAIL_HEXPRINT(x,y) {}
-#endif
-
-#ifdef DEBUG_MODE_WARN
-#define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO);
-#else
-#define DEBUG_WARN(x) {}
-#endif
-
-#ifdef DEBUG_MODE_READ
-#define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO);
-#else
-#define DEBUG_READ(x) {}
-#endif
+#define DIE(x) {            \
+    WARN(x);                \
+    exit(EXIT_FAILURE);     \
+}
 
-#ifdef DEBUG_MODE_INFO
-#define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO);
-#else
-#define DEBUG_INFO(x) {}
-#endif
-
-#ifdef DEBUG_MODE_MAIN
-#define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO);
-#else
-#define DEBUG_MAIN(x) {}
-#endif
-
-#ifdef DEBUG_MODE_CODE
-#define DEBUG_CODE(x) {x}
-#else
-#define DEBUG_CODE(x) {}
-#endif
+#define DEBUG_WARN(x)           MESSAGEPRINT x
+#define DEBUG_INFO(x)           MESSAGEPRINT x
+#define DEBUG_HEXDUMP(x, s)     pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, 0x10, 0)
+#define DEBUG_HEXDUMPC(x, s, c) pst_debug_hexdump(__LINE__, __FILE__, (char*)x, s, c, 0)
 
-#ifdef DEBUG_MODE_DECRYPT
-#define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO);
-#else
-#define DEBUG_DECRYPT(x) {}
-#endif
 
-#ifdef DEBUG_MODE_HEXDUMP
-#define DEBUG_HEXDUMP(x, s)\
-  {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
-   pst_debug_hexdump((char*)x, s, 0x10, 0);}
-#define DEBUG_HEXDUMPC(x, s, c)\
-  {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
-   pst_debug_hexdump((char*)x, s, c, 0);}
-#else
-#define DEBUG_HEXDUMP(x, s) {}
-#define DEBUG_HEXDUMPC(x, s, c) {}
-#endif
-
-#define DEBUG_FILE(x) {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
-                       pst_debug_msg_text x;}
-
-#ifdef DEBUG_MODE_FUNC
 # define DEBUG_ENT(x)                                           \
     {                                                           \
         pst_debug_func(x);                                      \
-        MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNCENT_NO); \
+        pst_debug(__LINE__, __FILE__, "Entering function\n");   \
     }
 # define DEBUG_RET()                                            \
     {                                                           \
-        MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO);  \
+        pst_debug(__LINE__, __FILE__, "Leaving function\n");    \
         pst_debug_func_ret();                                   \
     }
-#else
-# define DEBUG_ENT(x) {}
-# define DEBUG_RET() {}
-#endif
-
-#define DEBUG_INIT(fname) {pst_debug_init(fname);}
-#define DEBUG_CLOSE() {pst_debug_close();}
-#define DEBUG_REGISTER_CLOSE() {if(atexit(pst_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}
-
-#define RET_DERROR(res, ret_val, x)\
-    if (res) { DIE(x);}
-
-#define RET_ERROR(res, ret_val)\
-    if (res) {return ret_val;}
 
-#define DEBUG_VERSION 1
-struct pst_debug_file_rec_m {
-    unsigned short int funcname;
-    unsigned short int filename;
-    unsigned short int text;
-    unsigned short int end;
-    unsigned int line;
-    unsigned int type;
-};
+#define DEBUG_INIT(fname,mutex) {pst_debug_init(fname,mutex);}
+#define DEBUG_CLOSE()           {pst_debug_close();}
+#define RET_DERROR(res, ret_val, x) if (res) { DIE(x);}
 
-struct pst_debug_file_rec_l {
-    unsigned int funcname;
-    unsigned int filename;
-    unsigned int text;
-    unsigned int end;
-    unsigned int line;
-    unsigned int type;
-};
+
 
 #if BYTE_ORDER == BIG_ENDIAN
 #  define LE64_CPU(x) \
--- a/src/dumpblocks.c	Sat May 16 10:32:26 2009 -0700
+++ b/src/dumpblocks.c	Mon May 18 15:55:05 2009 -0700
@@ -29,8 +29,7 @@
         printf("\t-o target\tSpecify the output directory\n");
         exit(1);
     }
-    DEBUG_INIT("dumpblocks.log");
-    DEBUG_REGISTER_CLOSE();
+    DEBUG_INIT("dumpblocks.log", NULL);
     DEBUG_ENT("main");
 
     printf("Opening file %s\n", file);
--- a/src/getidblock.c	Sat May 16 10:32:26 2009 -0700
+++ b/src/getidblock.c	Mon May 18 15:55:05 2009 -0700
@@ -13,6 +13,7 @@
     printf("\tid - ID of the block to fetch (0 to fetch all) - can begin with 0x for hex\n");
     printf("\toptions\n");
     printf("\t\t-p\tProcess the block before finishing.\n");
+    printf("\t\t-b\tDump the blocks in binary to stdout.\n");
     printf("\t\t\tView the debug log for information\n");
 }
 
@@ -24,13 +25,13 @@
     size_t readSize;
     pst_desc_tree *ptr;
 
-    DEBUG_MAIN(("\n\n\nLooking at block index1 id %#"PRIx64"\n", i_id));
+    DEBUG_INFO(("\n\n\nLooking at block index1 id %#"PRIx64"\n", i_id));
 
     if ((readSize = pst_ff_getIDblock_dec(&pstfile, i_id, &buf)) <= 0 || buf == 0) {
         DIE(("Error loading block\n"));
     }
 
-    DEBUG_MAIN(("Printing block id %#"PRIx64", size %#"PRIx64"\n", i_id, (uint64_t)readSize));
+    DEBUG_INFO(("Printing block id %#"PRIx64", size %#"PRIx64"\n", i_id, (uint64_t)readSize));
     if (binary) {
         if (fwrite(buf, 1, readSize, stdout) != 0) {
             DIE(("Error occured during writing of buf to stdout\n"));
@@ -42,7 +43,7 @@
     if (buf) free(buf);
 
     if (process) {
-        DEBUG_MAIN(("Parsing block id %#"PRIx64"\n", i_id));
+        DEBUG_INFO(("Parsing block id %#"PRIx64"\n", i_id));
         ptr = pstfile.d_head;
         while (ptr) {
             if (ptr->assoc_tree && ptr->assoc_tree->i_id == i_id)
@@ -66,7 +67,7 @@
 void dump_desc(pst_desc_tree *ptr)
 {
     while (ptr) {
-        DEBUG_MAIN(("\n\n\nLooking at block desc id %#"PRIx64"\n", ptr->d_id));
+        DEBUG_INFO(("\n\n\nLooking at block desc id %#"PRIx64"\n", ptr->d_id));
         if (ptr->desc       && ptr->desc->i_id)       dumper(ptr->desc->i_id);
         if (ptr->assoc_tree && ptr->assoc_tree->i_id) dumper(ptr->assoc_tree->i_id);
         if (ptr->child) dump_desc(ptr->child);
@@ -82,11 +83,10 @@
     uint64_t i_id;
     int c;
 
-    DEBUG_INIT("getidblock.log");
-    DEBUG_REGISTER_CLOSE();
+    DEBUG_INIT("getidblock.log", NULL);
     DEBUG_ENT("main");
 
-    while ((c = getopt(argc, argv, "bdp")) != -1) {
+    while ((c = getopt(argc, argv, "bp")) != -1) {
         switch (c) {
             case 'b':
                 // enable binary output
@@ -111,13 +111,13 @@
     sid   = argv[optind + 1];
     i_id  = (uint64_t)strtoll(sid, NULL, 0);
 
-    DEBUG_MAIN(("Opening file\n"));
+    DEBUG_INFO(("Opening file\n"));
     memset(&pstfile, 0, sizeof(pstfile));
     if (pst_open(&pstfile, fname)) {
         DIE(("Error opening file\n"));
     }
 
-    DEBUG_MAIN(("Loading Index\n"));
+    DEBUG_INFO(("Loading Index\n"));
     if (pst_load_index(&pstfile) != 0) {
         DIE(("Error loading file index\n"));
     }
--- a/src/libpst.c	Sat May 16 10:32:26 2009 -0700
+++ b/src/libpst.c	Mon May 18 15:55:05 2009 -0700
@@ -403,7 +403,7 @@
 static void add_descriptor_to_list(pst_desc_tree *node, pst_desc_tree **head, pst_desc_tree **tail)
 {
     DEBUG_ENT("add_descriptor_to_list");
-    //DEBUG_INDEX(("Added node %#"PRIx64" parent %#"PRIx64" real parent %#"PRIx64" prev %#"PRIx64" next %#"PRIx64"\n",
+    //DEBUG_INFO(("Added node %#"PRIx64" parent %#"PRIx64" real parent %#"PRIx64" prev %#"PRIx64" next %#"PRIx64"\n",
     //             node->id, node->parent_d_id,
     //             (node->parent ? node->parent->id : (uint64_t)0),
     //             (node->prev   ? node->prev->id   : (uint64_t)0),
@@ -438,7 +438,7 @@
     while (n) {
         if (n->parent_d_id == node->d_id) {
             // found a child of this node
-            DEBUG_INDEX(("Found orphan child %#"PRIx64" of parent %#"PRIx64"\n", n->d_id, node->d_id));
+            DEBUG_INFO(("Found orphan child %#"PRIx64" of parent %#"PRIx64"\n", n->d_id, node->d_id));
             pst_desc_tree *nn = n->next;
             pst_desc_tree *pp = n->prev;
             node->no_child++;
@@ -456,24 +456,24 @@
     // now hook this node into the global tree
     if (node->parent_d_id == 0) {
         // add top level node to the descriptor tree
-        //DEBUG_INDEX(("Null parent\n"));
+        //DEBUG_INFO(("Null parent\n"));
         add_descriptor_to_list(node, &pf->d_head, &pf->d_tail);
     }
     else if (node->parent_d_id == node->d_id) {
         // add top level node to the descriptor tree
-        DEBUG_INDEX(("%#"PRIx64" is its own parent. What is this world coming to?\n", node->d_id));
+        DEBUG_INFO(("%#"PRIx64" is its own parent. What is this world coming to?\n", node->d_id));
         add_descriptor_to_list(node, &pf->d_head, &pf->d_tail);
     } else {
-        //DEBUG_INDEX(("Searching for parent %#"PRIx64" of %#"PRIx64"\n", node->parent_d_id, node->d_id));
+        //DEBUG_INFO(("Searching for parent %#"PRIx64" of %#"PRIx64"\n", node->parent_d_id, node->d_id));
         pst_desc_tree *parent = pst_getDptr(pf, node->parent_d_id);
         if (parent) {
-            //DEBUG_INDEX(("Found parent %#"PRIx64"\n", node->parent_d_id));
+            //DEBUG_INFO(("Found parent %#"PRIx64"\n", node->parent_d_id));
             parent->no_child++;
             node->parent = parent;
             add_descriptor_to_list(node, &parent->child, &parent->child_tail);
         }
         else {
-            DEBUG_INDEX(("No parent %#"PRIx64", have an orphan child %#"PRIx64"\n", node->parent_d_id, node->d_id));
+            DEBUG_INFO(("No parent %#"PRIx64", have an orphan child %#"PRIx64"\n", node->parent_d_id, node->d_id));
             add_descriptor_to_list(node, &pf->d_head, &pf->d_tail);
         }
     }
@@ -506,7 +506,7 @@
     uint32_t topid;
     DEBUG_ENT("pst_getTopOfFolders");
     if (!root || !root->message_store) {
-        DEBUG_INDEX(("There isn't a top of folder record here.\n"));
+        DEBUG_INFO(("There isn't a top of folder record here.\n"));
         DEBUG_RET();
         return NULL;
     }
@@ -517,7 +517,7 @@
     } else {
         topid = root->message_store->top_of_personal_folder->id;
     }
-    DEBUG_INDEX(("looking for top of folder descriptor %#"PRIx32"\n", topid));
+    DEBUG_INFO(("looking for top of folder descriptor %#"PRIx32"\n", topid));
     topnode = pst_getDptr(pf, (uint64_t)topid);
     if (!topnode) {
         // add dummy top record to pickup orphan children
@@ -619,12 +619,13 @@
     }
 
     x = pst_build_id_ptr(pf, pf->index1, 0, pf->index1_back, 0, UINT64_MAX);
-    DEBUG_INDEX(("build id ptr returns %i\n", x));
+    DEBUG_INFO(("build id ptr returns %i\n", x));
 
     x = pst_build_desc_ptr(pf, pf->index2, 0, pf->index2_back, (uint64_t)0x21, UINT64_MAX);
-    DEBUG_INDEX(("build desc ptr returns %i\n", x));
-
-    DEBUG_CODE((void)pst_printDptr(pf, pf->d_head););
+    DEBUG_INFO(("build desc ptr returns %i\n", x));
+
+    pst_printDptr(pf, pf->d_head);
+
     DEBUG_RET();
     return 0;
 }
@@ -694,9 +695,9 @@
         return 0;
     }
 
-    DEBUG_EMAIL(("look thru d_id 0x61 list of mapi objects\n"));
+    DEBUG_INFO(("look thru d_id 0x61 list of mapi objects\n"));
     for (x=0; x < list->count_elements; x++) {
-        DEBUG_EMAIL(("#%d - mapi-id: %#x type: %#x length: %#x\n", x, list->elements[x]->mapi_id, list->elements[x]->type, list->elements[x]->size));
+        DEBUG_INFO(("#%d - mapi-id: %#x type: %#x length: %#x\n", x, list->elements[x]->mapi_id, list->elements[x]->type, list->elements[x]->size));
         if (list->elements[x]->data) {
             DEBUG_HEXDUMPC(list->elements[x]->data, list->elements[x]->size, 0x10);
         }
@@ -727,7 +728,7 @@
         memset(ptr, 0, sizeof(*ptr));
         ptr->map  = xattrib.map+0x8000;
         ptr->next = NULL;
-        DEBUG_INDEX(("xattrib: ext = %#"PRIx32", type = %#"PRIx16", map = %#"PRIx16"\n",
+        DEBUG_INFO(("xattrib: ext = %#"PRIx32", type = %#"PRIx16", map = %#"PRIx16"\n",
              xattrib.extended, xattrib.type, xattrib.map));
         if (xattrib.type & 0x0001) { // if the Bit 1 is set
             // pointer to Unicode field in buffer
@@ -741,9 +742,9 @@
                 memcpy(wt, &(headerbuffer[xattrib.extended+sizeof(tint)]), (size_t)tint);
                 ptr->data = pst_wide_to_single(wt, (size_t)tint);
                 free(wt);
-                DEBUG_INDEX(("Mapped attribute %#"PRIx32" to %s\n", ptr->map, ptr->data));
+                DEBUG_INFO(("Mapped attribute %#"PRIx32" to %s\n", ptr->map, ptr->data));
             } else {
-                DEBUG_INDEX(("Cannot read outside of buffer [%i !< %i]\n", xattrib.extended, hsize));
+                DEBUG_INFO(("Cannot read outside of buffer [%i !< %i]\n", xattrib.extended, hsize));
                 err = 1;
             }
             ptr->mytype = PST_MAP_HEADER;
@@ -753,7 +754,7 @@
             memset(ptr->data, 0, sizeof(uint32_t));
             *((uint32_t*)ptr->data) = xattrib.extended;
             ptr->mytype = PST_MAP_ATTRIB;
-            DEBUG_INDEX(("Mapped attribute %#"PRIx32" to %#"PRIx32"\n", ptr->map, *((uint32_t*)ptr->data)));
+            DEBUG_INFO(("Mapped attribute %#"PRIx32" to %#"PRIx32"\n", ptr->map, *((uint32_t*)ptr->data)));
         }
 
         if (!err) {
@@ -816,7 +817,7 @@
 static size_t pst_decode_desc(pst_file *pf, pst_desc *desc, char *buf) {
     size_t r;
     if (pf->do_read64) {
-        DEBUG_INDEX(("Decoding desc64\n"));
+        DEBUG_INFO(("Decoding desc64\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_desc), 0x10);
         memcpy(desc, buf, sizeof(pst_desc));
         LE64_CPU(desc->d_id);
@@ -828,7 +829,7 @@
     }
     else {
         pst_desc32 d32;
-        DEBUG_INDEX(("Decoding desc32\n"));
+        DEBUG_INFO(("Decoding desc32\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_desc32), 0x10);
         memcpy(&d32, buf, sizeof(pst_desc32));
         LE32_CPU(d32.d_id);
@@ -850,7 +851,7 @@
 static size_t pst_decode_table(pst_file *pf, struct pst_table_ptr_struct *table, char *buf) {
     size_t r;
     if (pf->do_read64) {
-        DEBUG_INDEX(("Decoding table64\n"));
+        DEBUG_INFO(("Decoding table64\n"));
         DEBUG_HEXDUMPC(buf, sizeof(struct pst_table_ptr_struct), 0x10);
         memcpy(table, buf, sizeof(struct pst_table_ptr_struct));
         LE64_CPU(table->start);
@@ -860,7 +861,7 @@
     }
     else {
         struct pst_table_ptr_struct32 t32;
-        DEBUG_INDEX(("Decoding table32\n"));
+        DEBUG_INFO(("Decoding table32\n"));
         DEBUG_HEXDUMPC(buf, sizeof( struct pst_table_ptr_struct32), 0x10);
         memcpy(&t32, buf, sizeof(struct pst_table_ptr_struct32));
         LE32_CPU(t32.start);
@@ -879,7 +880,7 @@
 static size_t pst_decode_index(pst_file *pf, pst_index *index, char *buf) {
     size_t r;
     if (pf->do_read64) {
-        DEBUG_INDEX(("Decoding index64\n"));
+        DEBUG_INFO(("Decoding index64\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_index), 0x10);
         memcpy(index, buf, sizeof(pst_index));
         LE64_CPU(index->id);
@@ -890,7 +891,7 @@
         r = sizeof(pst_index);
     } else {
         pst_index32 index32;
-        DEBUG_INDEX(("Decoding index32\n"));
+        DEBUG_INFO(("Decoding index32\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_index32), 0x10);
         memcpy(&index32, buf, sizeof(pst_index32));
         LE32_CPU(index32.id);
@@ -912,7 +913,7 @@
 static size_t pst_decode_assoc(pst_file *pf, pst_id2_assoc *assoc, char *buf) {
     size_t r;
     if (pf->do_read64) {
-        DEBUG_INDEX(("Decoding assoc64\n"));
+        DEBUG_INFO(("Decoding assoc64\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_id2_assoc), 0x10);
         memcpy(assoc, buf, sizeof(pst_id2_assoc));
         LE32_CPU(assoc->id2);
@@ -921,7 +922,7 @@
         r = sizeof(pst_id2_assoc);
     } else {
         pst_id2_assoc32 assoc32;
-        DEBUG_INDEX(("Decoding assoc32\n"));
+        DEBUG_INFO(("Decoding assoc32\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_id2_assoc32), 0x10);
         memcpy(&assoc32, buf, sizeof(pst_id2_assoc32));
         LE32_CPU(assoc32.id2);
@@ -940,14 +941,14 @@
 static size_t pst_decode_type3(pst_file *pf, pst_table3_rec *table3_rec, char *buf) {
     size_t r;
     if (pf->do_read64) {
-        DEBUG_INDEX(("Decoding table3 64\n"));
+        DEBUG_INFO(("Decoding table3 64\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_table3_rec), 0x10);
         memcpy(table3_rec, buf, sizeof(pst_table3_rec));
         LE64_CPU(table3_rec->id);
         r = sizeof(pst_table3_rec);
     } else {
         pst_table3_rec32 table3_rec32;
-        DEBUG_INDEX(("Decoding table3 32\n"));
+        DEBUG_INFO(("Decoding table3 32\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_table3_rec32), 0x10);
         memcpy(&table3_rec32, buf, sizeof(pst_table3_rec32));
         LE32_CPU(table3_rec32.id);
@@ -972,13 +973,13 @@
     char *buf = NULL, *bptr;
 
     DEBUG_ENT("pst_build_id_ptr");
-    DEBUG_INDEX(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val));
+    DEBUG_INFO(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val));
     if (end_val <= start_val) {
         DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#"PRIx64", end:%#"PRIx64"]\n", start_val, end_val));
         DEBUG_RET();
         return -1;
     }
-    DEBUG_INDEX(("Reading index block\n"));
+    DEBUG_INFO(("Reading index block\n"));
     if (pst_read_block_size(pf, offset, BLOCK_SIZE, &buf) < BLOCK_SIZE) {
         DEBUG_WARN(("Failed to read %i bytes\n", BLOCK_SIZE));
         if (buf) free(buf);
@@ -1009,9 +1010,9 @@
             bptr += pst_decode_index(pf, &index, bptr);
             x++;
             if (index.id == 0) break;
-            DEBUG_INDEX(("[%i]%i Item [id = %#"PRIx64", offset = %#"PRIx64", u1 = %#x, size = %i(%#x)]\n",
+            DEBUG_INFO(("[%i]%i Item [id = %#"PRIx64", offset = %#"PRIx64", u1 = %#x, size = %i(%#x)]\n",
                         depth, x, index.id, index.offset, index.u1, index.size, index.size));
-            // if (index.id & 0x02) DEBUG_INDEX(("two-bit set!!\n"));
+            // if (index.id & 0x02) DEBUG_INFO(("two-bit set!!\n"));
             if ((index.id >= end_val) || (index.id < old)) {
                 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n"));
                 if (buf) free(buf);
@@ -1050,7 +1051,7 @@
             else {
                 table2.start = end_val;
             }
-            DEBUG_INDEX(("[%i] %i Index Table [start id = %#"PRIx64", u1 = %#"PRIx64", offset = %#"PRIx64", end id = %#"PRIx64"]\n",
+            DEBUG_INFO(("[%i] %i Index Table [start id = %#"PRIx64", u1 = %#"PRIx64", offset = %#"PRIx64", end id = %#"PRIx64"]\n",
                         depth, x, table.start, table.u1, table.offset, table2.start));
             if ((table.start >= end_val) || (table.start < old)) {
                 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n"));
@@ -1089,13 +1090,13 @@
     char *buf = NULL, *bptr;
 
     DEBUG_ENT("pst_build_desc_ptr");
-    DEBUG_INDEX(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val));
+    DEBUG_INFO(("offset %#"PRIx64" depth %i linku1 %#"PRIx64" start %#"PRIx64" end %#"PRIx64"\n", offset, depth, linku1, start_val, end_val));
     if (end_val <= start_val) {
         DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#"PRIx64", end:%#"PRIx64"]\n", start_val, end_val));
         DEBUG_RET();
         return -1;
     }
-    DEBUG_INDEX(("Reading desc block\n"));
+    DEBUG_INFO(("Reading desc block\n"));
     if (pst_read_block_size(pf, offset, DESC_BLOCK_SIZE, &buf) < DESC_BLOCK_SIZE) {
         DEBUG_WARN(("Failed to read %i bytes\n", DESC_BLOCK_SIZE));
         if (buf) free(buf);
@@ -1123,7 +1124,7 @@
         }
         for (x=0; x<item_count; x++) {
             bptr += pst_decode_desc(pf, &desc_rec, bptr);
-            DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#"PRIx64", desc_id = %#"PRIx64", tree_id = %#"PRIx64", parent_d_id = %#x]\n",
+            DEBUG_INFO(("[%i] Item(%#x) = [d_id = %#"PRIx64", desc_id = %#"PRIx64", tree_id = %#"PRIx64", parent_d_id = %#x]\n",
                         depth, x, desc_rec.d_id, desc_rec.desc_id, desc_rec.tree_id, desc_rec.parent_d_id));
             if ((desc_rec.d_id >= end_val) || (desc_rec.d_id < old)) {
                 DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n"));
@@ -1141,7 +1142,7 @@
                     return -1;
                 }
             }
-            DEBUG_INDEX(("New Record %#"PRIx64" with parent %#x\n", desc_rec.d_id, desc_rec.parent_d_id));
+            DEBUG_INFO(("New Record %#"PRIx64" with parent %#x\n", desc_rec.d_id, desc_rec.parent_d_id));
             {
                 pst_desc_tree *d_ptr = (pst_desc_tree*) pst_malloc(sizeof(pst_desc_tree));
                 d_ptr->d_id        = desc_rec.d_id;
@@ -1169,7 +1170,7 @@
             else {
                 table2.start = end_val;
             }
-            DEBUG_INDEX(("[%i] %i Descriptor Table [start id = %#"PRIx64", u1 = %#"PRIx64", offset = %#"PRIx64", end id = %#"PRIx64"]\n",
+            DEBUG_INFO(("[%i] %i Descriptor Table [start id = %#"PRIx64", u1 = %#"PRIx64", offset = %#"PRIx64", end id = %#"PRIx64"]\n",
                         depth, x, table.start, table.u1, table.offset, table2.start));
             if ((table.start >= end_val) || (table.start < old)) {
                 DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n"));
@@ -1249,7 +1250,7 @@
 
     if ((id2_ptr = pst_getID2(id2_head, (uint64_t)0x692))) {
         // DSN/MDN reports?
-        DEBUG_EMAIL(("DSN/MDN processing\n"));
+        DEBUG_INFO(("DSN/MDN processing\n"));
         list = pst_parse_block(pf, id2_ptr->id->i_id, id2_head);
         if (!list) {
             DEBUG_WARN(("ERROR error processing main DSN/MDN record\n"));
@@ -1275,7 +1276,7 @@
     }
 
     if ((id2_ptr = pst_getID2(id2_head, (uint64_t)0x671))) {
-        DEBUG_EMAIL(("ATTACHMENT processing attachment\n"));
+        DEBUG_INFO(("ATTACHMENT processing attachment\n"));
         list = pst_parse_block(pf, id2_ptr->id->i_id, id2_head);
         if (!list) {
             DEBUG_WARN(("ERROR error processing main attachment record\n"));
@@ -1461,7 +1462,7 @@
     LE16_CPU(block_hdr.index_offset);
     LE16_CPU(block_hdr.type);
     LE32_CPU(block_hdr.offset);
-    DEBUG_EMAIL(("block header (index_offset=%#hx, type=%#hx, offset=%#hx)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset));
+    DEBUG_INFO(("block header (index_offset=%#hx, type=%#hx, offset=%#hx)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset));
 
     if (block_hdr.index_offset == (uint16_t)0x0101) { //type 3
         size_t i;
@@ -1487,7 +1488,7 @@
         LE16_CPU(block_hdr.index_offset);
         LE16_CPU(block_hdr.type);
         LE32_CPU(block_hdr.offset);
-        DEBUG_EMAIL(("block header (index_offset=%#hx, type=%#hx, offset=%#hx)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset));
+        DEBUG_INFO(("block header (index_offset=%#hx, type=%#hx, offset=%#hx)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset));
     }
     else {
         // setup the subblock descriptors, but we only have one block
@@ -1511,7 +1512,7 @@
         LE16_CPU(table_rec.type);
         LE16_CPU(table_rec.ref_type);
         LE32_CPU(table_rec.value);
-        DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
+        DEBUG_INFO(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
 
         if ((table_rec.type != (uint16_t)0x02B5) || (table_rec.ref_type != 6)) {
             DEBUG_WARN(("Unknown second block constant - %#hx %#hx for id %#"PRIx64"\n", table_rec.type, table_rec.ref_type, block_id));
@@ -1574,7 +1575,7 @@
         LE16_CPU(table_rec.type);
         LE16_CPU(table_rec.ref_type);
         LE32_CPU(table_rec.value);
-        DEBUG_EMAIL(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
+        DEBUG_INFO(("table_rec (type=%#hx, ref_type=%#hx, value=%#x)\n", table_rec.type, table_rec.ref_type, table_rec.value));
 
         if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record
             DEBUG_WARN(("Unknown second block constant - %#hx for id %#"PRIx64"\n", table_rec.type, block_id));
@@ -1609,7 +1610,7 @@
         return NULL;
     }
 
-    DEBUG_EMAIL(("Mallocing number of records %i\n", num_recs));
+    DEBUG_INFO(("Mallocing number of records %i\n", num_recs));
     for (count_rec=0; count_rec<num_recs; count_rec++) {
         mo_ptr = (pst_mapi_object*) pst_malloc(sizeof(pst_mapi_object));
         memset(mo_ptr, 0, sizeof(pst_mapi_object));
@@ -1623,7 +1624,7 @@
         for (x=0; x<num_list; x++) mo_ptr->elements[x] = NULL;
         x = 0;
 
-        DEBUG_EMAIL(("going to read %i (%#x) items\n", mo_ptr->count_elements, mo_ptr->count_elements));
+        DEBUG_INFO(("going to read %i (%#x) items\n", mo_ptr->count_elements, mo_ptr->count_elements));
 
         fr_ptr = list_start; // initialize fr_ptr to the start of the list.
         for (cur_list=0; cur_list<num_list; cur_list++) { //we will increase fr_ptr as we progress through index
@@ -1670,7 +1671,7 @@
                 DEBUG_RET();
                 return NULL;
             }
-            DEBUG_EMAIL(("reading block %i (type=%#x, ref_type=%#x, value=%#x)\n",
+            DEBUG_INFO(("reading block %i (type=%#x, ref_type=%#x, value=%#x)\n",
                 x, table_rec.type, table_rec.ref_type, table_rec.value));
 
             if (!mo_ptr->elements[x]) {
@@ -1684,9 +1685,9 @@
             if (mapptr && (mapptr->map == table_rec.type)) {
                 if (mapptr->mytype == PST_MAP_ATTRIB) {
                     mo_ptr->elements[x]->mapi_id = *((uint32_t*)mapptr->data);
-                    DEBUG_EMAIL(("Mapped attrib %#x to %#x\n", table_rec.type, mo_ptr->elements[x]->mapi_id));
+                    DEBUG_INFO(("Mapped attrib %#x to %#x\n", table_rec.type, mo_ptr->elements[x]->mapi_id));
                 } else if (mapptr->mytype == PST_MAP_HEADER) {
-                    DEBUG_EMAIL(("Internet Header mapping found %#"PRIx32" to %s\n", table_rec.type, mapptr->data));
+                    DEBUG_INFO(("Internet Header mapping found %#"PRIx32" to %s\n", table_rec.type, mapptr->data));
                     mo_ptr->elements[x]->mapi_id = (uint32_t)PST_ATTRIB_HEADER;
                     mo_ptr->elements[x]->extra   = mapptr->data;
                 }
@@ -1800,7 +1801,7 @@
                     //need UTF-16 zero-termination
                     pst_vbset(utf16buf, mo_ptr->elements[x]->data, mo_ptr->elements[x]->size);
                     pst_vbappend(utf16buf, "\0\0", (size_t)2);
-                    DEBUG_INDEX(("Iconv in:\n"));
+                    DEBUG_INFO(("Iconv in:\n"));
                     DEBUG_HEXDUMPC(utf16buf->b, utf16buf->dlen, 0x10);
                     rc = pst_vb_utf16to8(utf8buf, utf16buf->b, utf16buf->dlen);
                     if (rc == (size_t)-1) {
@@ -1812,7 +1813,7 @@
                         mo_ptr->elements[x]->data = pst_malloc(utf8buf->dlen);
                         memcpy(mo_ptr->elements[x]->data, utf8buf->b, utf8buf->dlen);
                     }
-                    DEBUG_INDEX(("Iconv out:\n"));
+                    DEBUG_INFO(("Iconv out:\n"));
                     DEBUG_HEXDUMPC(mo_ptr->elements[x]->data, mo_ptr->elements[x]->size, 0x10);
                 }
                 if (mo_ptr->elements[x]->type == 0) mo_ptr->elements[x]->type = table_rec.ref_type;
@@ -1825,7 +1826,7 @@
             }
             x++;
         }
-        DEBUG_EMAIL(("increasing ind2_ptr by %i [%#x] bytes. Was %#x, Now %#x\n", rec_size, rec_size, ind2_ptr, ind2_ptr+rec_size));
+        DEBUG_INFO(("increasing ind2_ptr by %i [%#x] bytes. Was %#x, Now %#x\n", rec_size, rec_size, ind2_ptr, ind2_ptr+rec_size));
         ind2_ptr += rec_size;
     }
     freeall(&subblocks, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
@@ -1874,10 +1875,10 @@
         DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size);    \
     }                                                                       \
     if (*(int16_t*)list->elements[x]->data) {                               \
-        DEBUG_EMAIL((label" - True\n"));                                    \
+        DEBUG_INFO((label" - True\n"));                                    \
         targ = 1;                                                           \
     } else {                                                                \
-        DEBUG_EMAIL((label" - False\n"));                                   \
+        DEBUG_INFO((label" - False\n"));                                   \
         targ = 0;                                                           \
     }                                                                       \
 }
@@ -1908,7 +1909,7 @@
 
 #define LIST_COPY_INT16(label, targ) {                          \
     LIST_COPY_INT16_N(targ);                                    \
-    DEBUG_EMAIL((label" - %i %#x\n", (int)targ, (int)targ));    \
+    DEBUG_INFO((label" - %i %#x\n", (int)targ, (int)targ));    \
 }
 
 #define LIST_COPY_INT32_N(targ) {                                           \
@@ -1922,7 +1923,7 @@
 
 #define LIST_COPY_INT32(label, targ) {                          \
     LIST_COPY_INT32_N(targ);                                    \
-    DEBUG_EMAIL((label" - %i %#x\n", (int)targ, (int)targ));    \
+    DEBUG_INFO((label" - %i %#x\n", (int)targ, (int)targ));    \
 }
 
 #define LIST_COPY_EMAIL_INT32(label, targ) {                    \
@@ -1949,7 +1950,7 @@
     char *tlabels[] = {__VA_ARGS__};                            \
     LIST_COPY_INT32_N(targ);                                    \
     targ += delta;                                              \
-    DEBUG_EMAIL((label" - %s [%i]\n",                           \
+    DEBUG_INFO((label" - %s [%i]\n",                           \
         (((int)targ < 0) || ((int)targ >= count))               \
             ? "**invalid"                                       \
             : tlabels[(int)targ], (int)targ));                  \
@@ -1969,7 +1970,7 @@
     char *tlabels[] = {__VA_ARGS__};                            \
     LIST_COPY_INT16_N(targ);                                    \
     targ += delta;                                              \
-    DEBUG_EMAIL((label" - %s [%i]\n",                           \
+    DEBUG_INFO((label" - %s [%i]\n",                           \
         (((int)targ < 0) || ((int)targ >= count))               \
             ? "**invalid"                                       \
             : tlabels[(int)targ], (int)targ));                  \
@@ -1984,7 +1985,7 @@
     LIST_COPY(targ, (pst_entryid*));                            \
     LE32_CPU(targ->u1);                                         \
     LE32_CPU(targ->id);                                         \
-    DEBUG_EMAIL((label" u1=%#x, id=%#x\n", targ->u1, targ->id));\
+    DEBUG_INFO((label" u1=%#x, id=%#x\n", targ->u1, targ->id));\
 }
 
 #define LIST_COPY_EMAIL_ENTRYID(label, targ) {                  \
@@ -2003,7 +2004,7 @@
 #define LIST_COPY_STR(label, targ) {                                    \
     LIST_COPY_CSTR(targ.str);                                           \
     targ.is_utf8 = (list->elements[x]->type == 0x1f) ? 1 : 0;           \
-    DEBUG_EMAIL((label" - unicode %d - %s\n", targ.is_utf8, targ.str)); \
+    DEBUG_INFO((label" - unicode %d - %s\n", targ.is_utf8, targ.str)); \
 }
 
 #define LIST_COPY_EMAIL_STR(label, targ) {                      \
@@ -2036,7 +2037,7 @@
     memcpy(targ, list->elements[x]->data, list->elements[x]->size);         \
     LE32_CPU(targ->dwLowDateTime);                                          \
     LE32_CPU(targ->dwHighDateTime);                                         \
-    DEBUG_EMAIL((label" - %s", pst_fileTimeToAscii(targ, time_buffer)));    \
+    DEBUG_INFO((label" - %s", pst_fileTimeToAscii(targ, time_buffer)));    \
 }
 
 #define LIST_COPY_EMAIL_TIME(label, targ) {                     \
@@ -2075,13 +2076,13 @@
 #define LIST_COPY_EMAIL_BIN(label, targ) {          \
     MALLOC_EMAIL(item);                             \
     LIST_COPY_BIN(targ);                            \
-    DEBUG_EMAIL((label"\n"));                       \
+    DEBUG_INFO((label"\n"));                       \
 }
 #define LIST_COPY_APPT_BIN(label, targ) {           \
     MALLOC_APPOINTMENT(item);                       \
     LIST_COPY_BIN(targ);                            \
-    DEBUG_EMAIL((label"\n"));                       \
-    DEBUG_EMAIL_HEXPRINT(targ.data, targ.size);     \
+    DEBUG_INFO((label"\n"));                       \
+    DEBUG_HEXDUMP(targ.data, targ.size);            \
 }
 
 #define NULL_CHECK(x) { if (!x) { DEBUG_WARN(("NULL_CHECK: Null Found\n")); break;} }
@@ -2104,7 +2105,7 @@
 static int pst_process(pst_mapi_object *list, pst_item *item, pst_item_attach *attach) {
     DEBUG_ENT("pst_process");
     if (!item) {
-        DEBUG_EMAIL(("item cannot be NULL.\n"));
+        DEBUG_WARN(("item cannot be NULL.\n"));
         DEBUG_RET();
         return -1;
     }
@@ -2114,7 +2115,7 @@
         char time_buffer[30];
         for (x=0; x<list->count_elements; x++) {
             int32_t t;
-            DEBUG_EMAIL(("#%d - mapi-id: %#x type: %#x length: %#x\n", x, list->elements[x]->mapi_id, list->elements[x]->type, list->elements[x]->size));
+            DEBUG_INFO(("#%d - mapi-id: %#x type: %#x length: %#x\n", x, list->elements[x]->mapi_id, list->elements[x]->type, list->elements[x]->size));
 
             switch (list->elements[x]->mapi_id) {
                 case PST_ATTRIB_HEADER: // CUSTOM attribute for saying the Extra Headers
@@ -2126,7 +2127,7 @@
                             ef->field_name = strdup(list->elements[x]->extra);
                             ef->next       = item->extra_fields;
                             item->extra_fields = ef;
-                            DEBUG_EMAIL(("Extra Field - \"%s\" = \"%s\"\n", ef->field_name, ef->value));
+                            DEBUG_INFO(("Extra Field - \"%s\" = \"%s\"\n", ef->field_name, ef->value));
                             if (strcmp(ef->field_name, "content-type") == 0) {
                                 char *p = strstr(ef->value, "charset=\"");
                                 if (p) {
@@ -2139,7 +2140,7 @@
                                         if (item->body_charset.str) free(item->body_charset.str);
                                         item->body_charset.str     = set;
                                         item->body_charset.is_utf8 = 1;
-                                        DEBUG_EMAIL(("body charset %s from content-type extra field\n", set));
+                                        DEBUG_INFO(("body charset %s from content-type extra field\n", set));
                                     }
                                 }
                             }
@@ -2162,7 +2163,7 @@
                     }
                     break;
                 case 0x0003: // Extended Attributes table
-                    DEBUG_EMAIL(("Extended Attributes Table - NOT PROCESSED\n"));
+                    DEBUG_INFO(("Extended Attributes Table - NOT PROCESSED\n"));
                     break;
                 case 0x0017: // PR_IMPORTANCE - How important the sender deems it to be
                     LIST_COPY_EMAIL_ENUM("Importance Level", item->email->importance, 0, 3, "Low", "Normal", "High");
@@ -2192,7 +2193,7 @@
                             item->type = PST_TYPE_TASK;
                         else
                             item->type = PST_TYPE_OTHER;
-                        DEBUG_EMAIL(("Message class %s [%"PRIi32"] \n", item->ascii_type, item->type));
+                        DEBUG_INFO(("Message class %s [%"PRIi32"] \n", item->ascii_type, item->type));
                     }
                     else {
                         DEBUG_WARN(("What does this mean?\n"));
@@ -2249,25 +2250,25 @@
                     LIST_COPY_EMAIL_STR("Sent on behalf of address 1", item->email->outlook_sender);
                     break;
                 case 0x003F: // PR_RECEIVED_BY_ENTRYID Structure containing Recipient
-                    DEBUG_EMAIL(("Recipient Structure 1 -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Recipient Structure 1 -- NOT PROCESSED\n"));
                     break;
                 case 0x0040: // PR_RECEIVED_BY_NAME Name of Recipient Structure
-                    DEBUG_EMAIL(("Received By Name 1 -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Received By Name 1 -- NOT PROCESSED\n"));
                     break;
                 case 0x0041: // PR_SENT_REPRESENTING_ENTRYID Structure containing Sender
-                    DEBUG_EMAIL(("Sent on behalf of Structure 1 -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Sent on behalf of Structure 1 -- NOT PROCESSED\n"));
                     break;
                 case 0x0042: // PR_SENT_REPRESENTING_NAME
                     LIST_COPY_EMAIL_STR("Sent on behalf of", item->email->outlook_sender_name);
                     break;
                 case 0x0043: // PR_RCVD_REPRESENTING_ENTRYID Recipient Structure 2
-                    DEBUG_EMAIL(("Received on behalf of Structure -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Received on behalf of Structure -- NOT PROCESSED\n"));
                     break;
                 case 0x0044: // PR_RCVD_REPRESENTING_NAME
                     LIST_COPY_EMAIL_STR("Received on behalf of", item->email->outlook_recipient_name);
                     break;
                 case 0x004F: // PR_REPLY_RECIPIENT_ENTRIES Reply-To Structure
-                    DEBUG_EMAIL(("Reply-To Structure -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Reply-To Structure -- NOT PROCESSED\n"));
                     break;
                 case 0x0050: // PR_REPLY_RECIPIENT_NAMES Name of Reply-To Structure
                     LIST_COPY_EMAIL_STR("Reply-To", item->email->reply_to);
@@ -2336,16 +2337,16 @@
                     LIST_COPY_EMAIL_INT32("NDR diag code", item->email->ndr_diag_code);
                     break;
                 case 0x0C06: // PR_NON_RECEIPT_NOTIFICATION_REQUESTED
-                    DEBUG_EMAIL(("Non-Receipt Notification Requested -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Non-Receipt Notification Requested -- NOT PROCESSED\n"));
                     break;
                 case 0x0C17: // PR_REPLY_REQUESTED
                     LIST_COPY_EMAIL_BOOL("Reply Requested", item->email->reply_requested);
                     break;
                 case 0x0C19: // PR_SENDER_ENTRYID Sender Structure 2
-                    DEBUG_EMAIL(("Sender Structure 2 -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Sender Structure 2 -- NOT PROCESSED\n"));
                     break;
                 case 0x0C1A: // PR_SENDER_NAME Name of Sender Structure 2
-                    DEBUG_EMAIL(("Name of Sender Structure 2 -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Name of Sender Structure 2 -- NOT PROCESSED\n"));
                     break;
                 case 0x0C1B: // PR_SUPPLEMENTARY_INFO
                     LIST_COPY_EMAIL_STR("Supplementary info", item->email->supplementary_info);
@@ -2401,8 +2402,8 @@
                     break;
                 case 0x0FF9: // PR_RECORD_KEY Record Header 1
                     LIST_COPY_BIN(item->record_key);
-                    DEBUG_EMAIL(("Record Key\n"));
-                    DEBUG_EMAIL_HEXPRINT(item->record_key.data, item->record_key.size);
+                    DEBUG_INFO(("Record Key\n"));
+                    DEBUG_HEXDUMP(item->record_key.data, item->record_key.size);
                     break;
                 case 0x1000: // PR_BODY
                     LIST_COPY_STR("Plain Text body", item->body);
@@ -2465,7 +2466,7 @@
                     LIST_COPY_TIME("Date 5 (Modify Date)", item->modify_date);
                     break;
                 case 0x300B: // PR_SEARCH_KEY Record Header 2
-                    DEBUG_EMAIL(("Record Search 2 -- NOT PROCESSED\n"));
+                    DEBUG_INFO(("Record Search 2 -- NOT PROCESSED\n"));
                     break;
                 case 0x35DF: // PR_VALID_FOLDER_MASK
                     LIST_COPY_STORE_INT32("Valid Folder Mask", item->message_store->valid_mask);
@@ -2505,7 +2506,7 @@
                     LIST_COPY_CSTR(item->ascii_type);
                     if (pst_strincmp("IPF.Note", item->ascii_type, 8) == 0)
                         item->type = PST_TYPE_NOTE;
-                    if (pst_strincmp("IPF.Imap", item->ascii_type, 8) == 0)
+                    else if (pst_strincmp("IPF.Imap", item->ascii_type, 8) == 0)
                         item->type = PST_TYPE_NOTE;
                     else if (pst_stricmp("IPF", item->ascii_type) == 0)
                         item->type = PST_TYPE_NOTE;
@@ -2522,7 +2523,7 @@
                     else
                         item->type = PST_TYPE_OTHER;
 
-                    DEBUG_EMAIL(("Container class %s [%"PRIi32"]\n", item->ascii_type, item->type));
+                    DEBUG_INFO(("Container class %s [%"PRIi32"]\n", item->ascii_type, item->type));
                     break;
                 case 0x3617: // PR_ASSOC_CONTENT_COUNT
                     // associated content are items that are attached to this folder
@@ -2530,11 +2531,11 @@
                     LIST_COPY_FOLDER_INT32("Associated Content count", item->folder->assoc_count);
                     break;
                 case 0x3701: // PR_ATTACH_DATA_OBJ binary data of attachment
-                    DEBUG_EMAIL(("Binary Data [Size %i] - ", list->elements[x]->size));
+                    DEBUG_INFO(("Binary Data [Size %i] - ", list->elements[x]->size));
                     NULL_CHECK(attach);
                     if (!list->elements[x]->data) { //special case
                         attach->id2_val = list->elements[x]->type;
-                        DEBUG_EMAIL(("Seen a Reference. The data hasn't been loaded yet. [%#"PRIx64"]\n", attach->id2_val));
+                        DEBUG_INFO(("Seen a Reference. The data hasn't been loaded yet. [%#"PRIx64"]\n", attach->id2_val));
                     } else {
                         LIST_COPY_BIN(attach->data);
                     }
@@ -2576,7 +2577,7 @@
                     LIST_COPY_CONTACT_STR("Contact's Account name", item->contact->account_name);
                     break;
                 case 0x3A01: // PR_ALTERNATE_RECIPIENT
-                    DEBUG_EMAIL(("Contact Alternate Recipient - NOT PROCESSED\n"));
+                    DEBUG_INFO(("Contact Alternate Recipient - NOT PROCESSED\n"));
                     break;
                 case 0x3A02: // PR_CALLBACK_TELEPHONE_NUMBER
                     LIST_COPY_CONTACT_STR("Callback telephone number", item->contact->callback_phone);
@@ -2624,13 +2625,13 @@
                     LIST_COPY_CONTACT_STR("Contacts Surname", item->contact->surname);
                     break;
                 case 0x3A12: // PR_ORIGINAL_ENTRY_ID
-                    DEBUG_EMAIL(("Original Entry ID - NOT PROCESSED\n"));
+                    DEBUG_INFO(("Original Entry ID - NOT PROCESSED\n"));
                     break;
                 case 0x3A13: // PR_ORIGINAL_DISPLAY_NAME
-                    DEBUG_EMAIL(("Original Display Name - NOT PROCESSED\n"));
+                    DEBUG_INFO(("Original Display Name - NOT PROCESSED\n"));
                     break;
                 case 0x3A14: // PR_ORIGINAL_SEARCH_KEY
-                    DEBUG_EMAIL(("Original Search Key - NOT PROCESSED\n"));
+                    DEBUG_INFO(("Original Search Key - NOT PROCESSED\n"));
                     break;
                 case 0x3A15: // PR_POSTAL_ADDRESS
                     LIST_COPY_CONTACT_STR("Default Postal Address", item->contact->def_postal_address);
@@ -2672,7 +2673,7 @@
                     LIST_COPY_CONTACT_STR("Pager Phone Number", item->contact->pager_phone);
                     break;
                 case 0x3A22: // PR_USER_CERTIFICATE
-                    DEBUG_EMAIL(("User Certificate - NOT PROCESSED\n"));
+                    DEBUG_INFO(("User Certificate - NOT PROCESSED\n"));
                     break;
                 case 0x3A23: // PR_PRIMARY_FAX_NUMBER
                     LIST_COPY_CONTACT_STR("Primary Fax Number", item->contact->primary_fax);
@@ -2774,7 +2775,7 @@
                     LIST_COPY_CONTACT_STR("Company Main Phone", item->contact->company_main_phone);
                     break;
                 case 0x3A58: // PR_CHILDRENS_NAMES
-                    DEBUG_EMAIL(("Children's Names - NOT PROCESSED\n"));
+                    DEBUG_INFO(("Children's Names - NOT PROCESSED\n"));
                     break;
                 case 0x3A59: // PR_HOME_ADDRESS_CITY
                     LIST_COPY_CONTACT_STR("Home Address City", item->contact->home_city);
@@ -2820,17 +2821,17 @@
                     break;
                 case 0x65E3: // PR_PREDECESSOR_CHANGE_LIST
                     LIST_COPY_BIN(item->predecessor_change);
-                    DEBUG_EMAIL(("Predecessor Change\n"));
-                    DEBUG_EMAIL_HEXPRINT(item->predecessor_change.data, item->predecessor_change.size);
+                    DEBUG_INFO(("Predecessor Change\n"));
+                    DEBUG_HEXDUMP(item->predecessor_change.data, item->predecessor_change.size);
                     break;
                 case 0x67F2: // ID2 value of the attachments proper record
-                    DEBUG_EMAIL(("Attachment ID2 value - "));
+                    DEBUG_INFO(("Attachment ID2 value - "));
                     if (attach) {
                         uint32_t tempid;
                         memcpy(&(tempid), list->elements[x]->data, sizeof(tempid));
                         LE32_CPU(tempid);
                         attach->id2_val = tempid;
-                        DEBUG_EMAIL(("%#"PRIx64"\n", attach->id2_val));
+                        DEBUG_INFO(("%#"PRIx64"\n", attach->id2_val));
                     } else {
                         DEBUG_WARN(("NOT AN ATTACHMENT: %#x\n", list->elements[x]->mapi_id));
                     }
@@ -2979,10 +2980,10 @@
                     LIST_COPY_APPT_BOOL("Reminder alarm", item->appointment->alarm);
                     break;
                 case 0x8516: // Common start
-                    DEBUG_EMAIL(("Common Start Date - %s\n", pst_fileTimeToAscii((FILETIME*)list->elements[x]->data, time_buffer)));
+                    DEBUG_INFO(("Common Start Date - %s\n", pst_fileTimeToAscii((FILETIME*)list->elements[x]->data, time_buffer)));
                     break;
                 case 0x8517: // Common end
-                    DEBUG_EMAIL(("Common End Date - %s\n", pst_fileTimeToAscii((FILETIME*)list->elements[x]->data, time_buffer)));
+                    DEBUG_INFO(("Common End Date - %s\n", pst_fileTimeToAscii((FILETIME*)list->elements[x]->data, time_buffer)));
                     break;
                 case 0x851f: // Play reminder sound filename
                     LIST_COPY_APPT_STR("Appointment reminder sound filename", item->appointment->alarm_filename);
@@ -3245,17 +3246,17 @@
         return NULL;
     }
 
-    DEBUG_INDEX(("ID %#"PRIx64" is likely to be a description record. Count is %i (offset %#"PRIx64")\n",
+    DEBUG_INFO(("ID %#"PRIx64" is likely to be a description record. Count is %i (offset %#"PRIx64")\n",
             list->i_id, block_head.count, list->offset));
     x = 0;
     b_ptr = buf + ((pf->do_read64) ? 0x08 : 0x04);
     while (x < block_head.count) {
         b_ptr += pst_decode_assoc(pf, &id2_rec, b_ptr);
-        DEBUG_INDEX(("id2 = %#x, id = %#"PRIx64", child id = %#"PRIx64"\n", id2_rec.id2, id2_rec.id, id2_rec.child_id));
+        DEBUG_INFO(("id2 = %#x, id = %#"PRIx64", child id = %#"PRIx64"\n", id2_rec.id2, id2_rec.id, id2_rec.child_id));
         if ((i_ptr = pst_getID(pf, id2_rec.id)) == NULL) {
             DEBUG_WARN(("%#"PRIx64" - Not Found\n", id2_rec.id));
         } else {
-            DEBUG_INDEX(("%#"PRIx64" - Offset %#"PRIx64", u1 %#"PRIx64", Size %"PRIi64"(%#"PRIx64")\n",
+            DEBUG_INFO(("%#"PRIx64" - Offset %#"PRIx64", u1 %#"PRIx64", Size %"PRIi64"(%#"PRIx64")\n",
                          i_ptr->i_id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size));
             // add it to the tree
             i2_ptr = (pst_id2_tree*) pst_malloc(sizeof(pst_id2_tree));
@@ -3588,17 +3589,17 @@
         return NULL;
     }
 
-    //if (i_id & 1) DEBUG_INDEX(("have odd id bit %#"PRIx64"\n", i_id));
-    //if (i_id & 2) DEBUG_INDEX(("have two id bit %#"PRIx64"\n", i_id));
+    //if (i_id & 1) DEBUG_INFO(("have odd id bit %#"PRIx64"\n", i_id));
+    //if (i_id & 2) DEBUG_INFO(("have two id bit %#"PRIx64"\n", i_id));
     i_id -= (i_id & 1);
 
-    DEBUG_INDEX(("Trying to find %#"PRIx64"\n", i_id));
+    DEBUG_INFO(("Trying to find %#"PRIx64"\n", i_id));
     ptr = pf->i_head;
     while (ptr && (ptr->i_id != i_id)) {
         ptr = ptr->next;
     }
-    if (ptr) {DEBUG_INDEX(("Found Value %#"PRIx64"\n", i_id));            }
-    else     {DEBUG_INDEX(("ERROR: Value %#"PRIx64" not found\n", i_id)); }
+    if (ptr) {DEBUG_INFO(("Found Value %#"PRIx64"\n", i_id));            }
+    else     {DEBUG_INFO(("ERROR: Value %#"PRIx64" not found\n", i_id)); }
     DEBUG_RET();
     return ptr;
 }
@@ -3606,7 +3607,7 @@
 
 static pst_id2_tree *pst_getID2(pst_id2_tree *head, uint64_t id2) {
     DEBUG_ENT("pst_getID2");
-    DEBUG_INDEX(("looking for id2 = %#"PRIx64"\n", id2));
+    DEBUG_INFO(("looking for id2 = %#"PRIx64"\n", id2));
     pst_id2_tree *ptr = head;
     while (ptr) {
         if (ptr->id2 == id2) break;
@@ -3620,11 +3621,11 @@
         ptr = ptr->next;
     }
     if (ptr && ptr->id) {
-        DEBUG_INDEX(("Found value %#"PRIx64"\n", ptr->id->i_id));
+        DEBUG_INFO(("Found value %#"PRIx64"\n", ptr->id->i_id));
         DEBUG_RET();
         return ptr;
     }
-    DEBUG_INDEX(("ERROR Not Found\n"));
+    DEBUG_INFO(("ERROR Not Found\n"));
     DEBUG_RET();
     return NULL;
 }
@@ -3642,7 +3643,7 @@
     pst_desc_tree *ptr = pf->d_head;
     DEBUG_ENT("pst_getDptr");
     while (ptr && (ptr->d_id != d_id)) {
-        //DEBUG_INDEX(("Looking for %#"PRIx64" at node %#"PRIx64" with parent %#"PRIx64"\n", id, ptr->d_id, ptr->parent_d_id));
+        //DEBUG_INFO(("Looking for %#"PRIx64" at node %#"PRIx64" with parent %#"PRIx64"\n", id, ptr->d_id, ptr->parent_d_id));
         if (ptr->child) {
             ptr = ptr->child;
             continue;
@@ -3660,7 +3661,7 @@
 static void pst_printDptr(pst_file *pf, pst_desc_tree *ptr) {
     DEBUG_ENT("pst_printDptr");
     while (ptr) {
-        DEBUG_INDEX(("%#"PRIx64" [%i] desc=%#"PRIx64", assoc tree=%#"PRIx64"\n", ptr->d_id, ptr->no_child,
+        DEBUG_INFO(("%#"PRIx64" [%i] desc=%#"PRIx64", assoc tree=%#"PRIx64"\n", ptr->d_id, ptr->no_child,
                     (ptr->desc       ? ptr->desc->i_id       : (uint64_t)0),
                     (ptr->assoc_tree ? ptr->assoc_tree->i_id : (uint64_t)0)));
         if (ptr->child) {
@@ -3676,7 +3677,7 @@
     pst_index_ll *ptr = pf->i_head;
     DEBUG_ENT("pst_printIDptr");
     while (ptr) {
-        DEBUG_INDEX(("%#"PRIx64" offset=%#"PRIx64" size=%#"PRIx64"\n", ptr->i_id, ptr->offset, ptr->size));
+        DEBUG_INFO(("%#"PRIx64" offset=%#"PRIx64" size=%#"PRIx64"\n", ptr->i_id, ptr->offset, ptr->size));
         ptr = ptr->next;
     }
     DEBUG_RET();
@@ -3686,7 +3687,7 @@
 static void pst_printID2ptr(pst_id2_tree *ptr) {
     DEBUG_ENT("pst_printID2ptr");
     while (ptr) {
-        DEBUG_INDEX(("%#"PRIx64" id=%#"PRIx64"\n", ptr->id2, (ptr->id ? ptr->id->i_id : (uint64_t)0)));
+        DEBUG_INFO(("%#"PRIx64" id=%#"PRIx64"\n", ptr->id2, (ptr->id ? ptr->id->i_id : (uint64_t)0)));
         if (ptr->child) pst_printID2ptr(ptr->child);
         ptr = ptr->next;
     }
@@ -3706,10 +3707,10 @@
 static size_t pst_read_block_size(pst_file *pf, int64_t offset, size_t size, char **buf) {
     size_t rsize;
     DEBUG_ENT("pst_read_block_size");
-    DEBUG_READ(("Reading block from %#"PRIx64", %x bytes\n", offset, size));
+    DEBUG_INFO(("Reading block from %#"PRIx64", %x bytes\n", offset, size));
 
     if (*buf) {
-        DEBUG_READ(("Freeing old memory\n"));
+        DEBUG_INFO(("Freeing old memory\n"));
         free(*buf);
     }
     *buf = (char*) pst_malloc(size);
@@ -3841,7 +3842,7 @@
 //      p->size      = size;
 //      p->readcount = 1;
 //  }
-//  DEBUG_MAIN(("pst file old offset %#"PRIx64" old size %#x read count %i offset %#"PRIx64" size %#x\n",
+//  DEBUG_INFO(("pst file old offset %#"PRIx64" old size %#x read count %i offset %#"PRIx64" size %#x\n",
 //              p->offset, p->size, p->readcount, pos, size));
 
     if (fseeko(pf->fp, pos, SEEK_SET) == -1) {
@@ -3866,7 +3867,7 @@
     size_t r;
     int noenc = (int)(i_id & 2);   // disable encryption
     DEBUG_ENT("pst_ff_getIDblock_dec");
-    DEBUG_INDEX(("for id %#"PRIi64"\n", i_id));
+    DEBUG_INFO(("for id %#"PRIi64"\n", i_id));
     r = pst_ff_getIDblock(pf, i_id, buf);
     if ((pf->encryption) && !(noenc)) {
         (void)pst_decrypt(i_id, *buf, r, pf->encryption);
@@ -3891,11 +3892,11 @@
     DEBUG_ENT("pst_ff_getIDblock");
     rec = pst_getID(pf, i_id);
     if (!rec) {
-        DEBUG_INDEX(("Cannot find ID %#"PRIx64"\n", i_id));
+        DEBUG_INFO(("Cannot find ID %#"PRIx64"\n", i_id));
         DEBUG_RET();
         return 0;
     }
-    DEBUG_INDEX(("id = %#"PRIx64", record size = %#x, offset = %#x\n", i_id, rec->size, rec->offset));
+    DEBUG_INFO(("id = %#"PRIx64", record size = %#x, offset = %#x\n", i_id, rec->size, rec->offset));
     rsize = pst_read_block_size(pf, rec->offset, rec->size, buf);
     DEBUG_RET();
     return rsize;
@@ -3910,7 +3911,7 @@
     ptr = pst_getID2(id2_head, id2);
 
     if (!ptr) {
-        DEBUG_INDEX(("Cannot find id2 value %#"PRIi64"\n", id2));
+        DEBUG_WARN(("Cannot find id2 value %#"PRIi64"\n", id2));
         DEBUG_RET();
         return 0;
     }
@@ -3944,7 +3945,7 @@
 
     } else {
         // here we will assume it is a block that points to others
-        DEBUG_READ(("Assuming it is a multi-block record because of it's id\n"));
+        DEBUG_INFO(("Assuming it is a multi-block record because of it's id\n"));
         ret = pst_ff_compile_ID(pf, ptr->i_id, h, (size_t)0);
     }
     DEBUG_RET();
@@ -3975,7 +3976,7 @@
     LE16_CPU(block_hdr.index_offset);
     LE16_CPU(block_hdr.type);
     LE32_CPU(block_hdr.offset);
-    DEBUG_EMAIL(("block header (index_offset=%#hx, type=%#hx, offset=%#x)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset));
+    DEBUG_INFO(("block header (index_offset=%#hx, type=%#hx, offset=%#x)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset));
 
     if (block_hdr.index_offset != (uint16_t)0x0101) { //type 3
         DEBUG_WARN(("WARNING: not a type 0x0101 buffer, Treating as normal buffer\n"));
@@ -4013,7 +4014,7 @@
         }
         if (h->buf) {
             *(h->buf) = realloc(*(h->buf), size+z+1);
-            DEBUG_READ(("appending read data of size %i onto main buffer from pos %i\n", z, size));
+            DEBUG_INFO(("appending read data of size %i onto main buffer from pos %i\n", z, size));
             memcpy(&((*(h->buf))[size]), buf2, z);
         } else if ((h->base64 == 1) && h->fp) {
             if (base64_extra) {
@@ -4034,12 +4035,12 @@
             // encode this chunk
             t = pst_base64_encode_multiple(buf2, z, &line_count);
             if (t) {
-                DEBUG_READ(("writing %i bytes to file as base64 [%i]. Currently %i\n", z, strlen(t), size));
+                DEBUG_INFO(("writing %i bytes to file as base64 [%i]. Currently %i\n", z, strlen(t), size));
                 (void)pst_fwrite(t, (size_t)1, strlen(t), h->fp);
                 free(t);    // caught by valgrind
             }
         } else if (h->fp) {
-            DEBUG_READ(("writing %i bytes to file. Currently %i\n", z, size));
+            DEBUG_INFO(("writing %i bytes to file. Currently %i\n", z, size));
             (void)pst_fwrite(buf2, (size_t)1, z, h->fp);
         } else {
             // h-> does not specify any output
@@ -4095,14 +4096,14 @@
 
 size_t pst_fwrite(const void* ptr, size_t size, size_t nmemb, FILE *stream) {
     size_t r;
-    DEBUG_ENT("pst_fwrite");
     if (ptr)
         r = fwrite(ptr, size, nmemb, stream);
     else {
         r = 0;
+        DEBUG_ENT("pst_fwrite");
         DEBUG_WARN(("An attempt to write a NULL Pointer was made\n"));
+        DEBUG_RET();
     }
-    DEBUG_RET();
     return r;
 }
 
--- a/src/lspst.c	Sat May 16 10:32:26 2009 -0700
+++ b/src/lspst.c	Mon May 18 15:55:05 2009 -0700
@@ -54,18 +54,18 @@
 
     while (d_ptr) {
         if (!d_ptr->desc) {
-            DEBUG_WARN(("main: ERROR item's desc record is NULL\n"));
+            DEBUG_WARN(("ERROR item's desc record is NULL\n"));
             ff.skip_count++;
         }
         else {
-            DEBUG_MAIN(("main: Desc Email ID %"PRIx64" [d_ptr->d_id = %"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id));
+            DEBUG_INFO(("Desc Email ID %"PRIx64" [d_ptr->d_id = %"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id));
 
             item = pst_parse_item(&pstfile, d_ptr, NULL);
-            DEBUG_MAIN(("main: About to process item @ %p.\n", item));
+            DEBUG_INFO(("About to process item @ %p.\n", item));
             if (item) {
                 if (item->message_store) {
                     // there should only be one message_store, and we have already done it
-                    DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
+                    DIE(("A second message_store has been found. Sorry, this must be an error.\n"));
                 }
 
                 if (item->folder && d_ptr->child) {
@@ -78,7 +78,7 @@
                     if (!ff.type) ff.type = item->type;
                     // Process Contact item
                     if (ff.type != PST_TYPE_CONTACT) {
-                        DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. Processing anyway\n"));
+                        DEBUG_INFO(("I have a contact, but the folder isn't a contacts folder. Processing anyway\n"));
                     }
                     printf("Contact");
                     if (item->contact->fullname.str)
@@ -89,7 +89,7 @@
                     if (!ff.type) ff.type = item->type;
                     // Process Email item
                     if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) {
-                        DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n"));
+                        DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n"));
                     }
                     printf("Email");
                     if (item->email->outlook_sender_name.str)
@@ -102,7 +102,7 @@
                     if (!ff.type) ff.type = item->type;
                     // Process Journal item
                     if (ff.type != PST_TYPE_JOURNAL) {
-                        DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
+                        DEBUG_INFO(("I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
                     }
                     if (item->subject.str)
                         printf("Journal\t%s\n", pst_rfc2426_escape(item->subject.str));
@@ -111,9 +111,9 @@
                     char time_buffer[30];
                     if (!ff.type) ff.type = item->type;
                     // Process Calendar Appointment item
-                    DEBUG_MAIN(("main: Processing Appointment Entry\n"));
+                    DEBUG_INFO(("Processing Appointment Entry\n"));
                     if (ff.type != PST_TYPE_APPOINTMENT) {
-                        DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
+                        DEBUG_INFO(("I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
                     }
                     printf("Appointment");
                     if (item->subject.str)
@@ -127,13 +127,13 @@
 
                 } else {
                     ff.skip_count++;
-                    DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
+                    DEBUG_INFO(("Unknown item type. %i. Ascii1=\"%s\"\n",
                                       item->type, item->ascii_type));
                 }
                 pst_freeItem(item);
             } else {
                 ff.skip_count++;
-                DEBUG_MAIN(("main: A NULL item was seen\n"));
+                DEBUG_INFO(("A NULL item was seen\n"));
             }
             d_ptr = d_ptr->next;
         }
@@ -203,8 +203,7 @@
         // force a log file
         if (!d_log) d_log = "lspst.log";
     #endif // defined DEBUG_ALL
-    DEBUG_INIT(d_log);
-    DEBUG_REGISTER_CLOSE();
+    DEBUG_INIT(d_log, NULL);
     DEBUG_ENT("main");
 
 	if (argc <= optind) {
@@ -224,7 +223,7 @@
     item  = pst_parse_item(&pstfile, d_ptr, NULL);
     if (!item || !item->message_store) {
         DEBUG_RET();
-        DIE(("main: Could not get root record\n"));
+        DIE(("Could not get root record\n"));
     }
 
     // default the file_as to the same as the main filename if it doesn't exist
--- a/src/pst2dii.cpp.in	Sat May 16 10:32:26 2009 -0700
+++ b/src/pst2dii.cpp.in	Mon May 18 15:55:05 2009 -0700
@@ -180,7 +180,7 @@
     DEBUG_ENT("write_separate_attachment");
     check_filename(fname);
     const char* f_name = fname.c_str();
-    DEBUG_EMAIL(("dirname=%s, pathname=%s, filename=%s\n", output_directory, f_name, attach_filename));
+    DEBUG_INFO(("dirname=%s, pathname=%s, filename=%s\n", output_directory, f_name, attach_filename));
     int len = strlen(output_directory) + 1 + strlen(f_name) + 15;
     if (!attach_filename) {
         // generate our own (dummy) filename for the attachement
@@ -200,7 +200,7 @@
             DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
         }
     }
-    DEBUG_EMAIL(("Saving attachment to %s\n", temp));
+    DEBUG_INFO(("Saving attachment to %s\n", temp));
     if (!(fp = fopen(temp, "wb"))) {
         WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
     } else {
@@ -448,7 +448,7 @@
         removeCR(item->email->header.str);
         char *temp = strstr(item->email->header.str, "\n\n");
         if (temp) {
-            DEBUG_EMAIL(("Found body text in header\n"));
+            DEBUG_INFO(("Found body text in header\n"));
             temp[1] = '\0'; // stop after first \n
         }
         soh = skip_header_prologue(item->email->header.str);
@@ -497,11 +497,11 @@
     write_simple("MSGID", item->email->messageid.str);
     write_simple("READ", (item->flags & 1) ? "Y" : "N");
 
-    DEBUG_EMAIL(("About to print Header\n"));
+    DEBUG_INFO(("About to print Header\n"));
     fprintf(dii_file, "@HEADER\n");
 
     if (item && item->subject.str) {
-        DEBUG_EMAIL(("item->subject = %s\n", item->subject.str));
+        DEBUG_INFO(("item->subject = %s\n", item->subject.str));
     }
 
     if (soh) {
@@ -547,7 +547,7 @@
     print_pdf_only(line, black);
     fprintf(dii_file, "@HEADER-END\n");
 
-    DEBUG_EMAIL(("About to print Body\n"));
+    DEBUG_INFO(("About to print Body\n"));
     fprintf(dii_file, "@EMAIL-BODY\n");
     if (item->body.str) {
         removeCR(item->body.str);
@@ -564,9 +564,9 @@
 
     int attach_num = 0;
     for (pst_item_attach* current_attach = item->attach; current_attach; current_attach = current_attach->next) {
-        DEBUG_EMAIL(("Attempting Attachment encoding\n"));
+        DEBUG_INFO(("Attempting Attachment encoding\n"));
         if (!current_attach->data.data) {
-            DEBUG_EMAIL(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->data.size));
+            DEBUG_WARN(("Data of attachment is NULL!. Size is supposed to be %i\n", current_attach->data.size));
         }
         string an = write_separate_attachment(f.name, current_attach, ++attach_num, pst);
         fprintf(dii_file, "@EATTACH %s\n", an.c_str());
@@ -613,16 +613,16 @@
                     process(item, &ff, d_ptr->child);
                 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT || item->type == PST_TYPE_OTHER)) {
                     ff.email_count++;
-                    DEBUG_MAIN(("main: Processing Email\n"));
+                    DEBUG_INFO(("Processing Email\n"));
                     if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT) && (ff.type != PST_TYPE_OTHER)) {
-                        DEBUG_MAIN(("main: I have an email, but the folder isn't an email folder. Processing anyway\n"));
+                        DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n"));
                     }
                     write_normal_email(ff, item, &pstfile);
                 }
                 pst_freeItem(item);
             } else {
                 ff.skip_count++;
-                DEBUG_MAIN(("main: A NULL item was seen\n"));
+                DEBUG_INFO(("A NULL item was seen\n"));
             }
         }
         d_ptr = d_ptr->next;
@@ -691,8 +691,7 @@
         // force a log file
         if (!d_log) d_log = "pst2dii.log";
     #endif
-    DEBUG_INIT(d_log);
-    DEBUG_REGISTER_CLOSE();
+    DEBUG_INIT(d_log, NULL);
     DEBUG_ENT("main");
     RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n"));
     RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
@@ -703,7 +702,7 @@
     item  = (pst_item*)pst_parse_item(&pstfile, d_ptr, NULL);
     if (!item || !item->message_store) {
         DEBUG_RET();
-        DIE(("main: Could not get root record\n"));
+        DIE(("Could not get root record\n"));
     }
 
     d_ptr = pst_getTopOfFolders(&pstfile, item);
--- a/src/pst2ldif.cpp	Sat May 16 10:32:26 2009 -0700
+++ b/src/pst2ldif.cpp	Mon May 18 15:55:05 2009 -0700
@@ -626,8 +626,7 @@
         // force a log file
         if (!d_log) d_log = "pst2ldif.log";
     #endif
-    DEBUG_INIT(d_log);
-    DEBUG_REGISTER_CLOSE();
+    DEBUG_INIT(d_log, NULL);
     DEBUG_ENT("main");
     RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n"));
     RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
--- a/src/readpst.c	Sat May 16 10:32:26 2009 -0700
+++ b/src/readpst.c	Mon May 18 15:55:05 2009 -0700
@@ -130,6 +130,7 @@
 #ifdef HAVE_SEMAPHORE_H
 int         shared_memory_id;
 sem_t*      global_children = NULL;
+sem_t*      output_mutex    = NULL;
 #endif
 
 
@@ -141,7 +142,7 @@
     if (global_children) {
         sem_getvalue(global_children, &available);
         //printf("grim reaper %s for pid %d (parent %d) with %d children, %d available\n", (waitall) ? "all" : "", getpid(), getppid(), active_children, available);
-        fflush(stdout);
+        //fflush(stdout);
         int i,j;
         for (i=0; i<active_children; i++) {
             pid_t child = child_processes[i];
@@ -157,7 +158,7 @@
         }
         sem_getvalue(global_children, &available);
         //printf("grim reaper %s for pid %d with %d children, %d available\n", (waitall) ? "all" : "", getpid(), active_children, available);
-        fflush(stdout);
+        //fflush(stdout);
     }
 #endif
 #endif
@@ -187,7 +188,7 @@
             // fork worked, and we are the parent, record this child that we need to wait for
             pid_t me = getpid();
             //printf("parent %d forked child pid %d to process folder %s\n", me, child, folder);
-            fflush(stdout);
+            //fflush(stdout);
             child_processes[active_children++] = child;
         }
         return child;
@@ -211,31 +212,35 @@
     create_enter_dir(&ff, outeritem);
 
     for (; d_ptr; d_ptr = d_ptr->next) {
-        DEBUG_MAIN(("main: New item record\n"));
+        DEBUG_INFO(("New item record\n"));
         if (!d_ptr->desc) {
             ff.skip_count++;
-            DEBUG_WARN(("main: ERROR item's desc record is NULL\n"));
+            DEBUG_WARN(("ERROR item's desc record is NULL\n"));
             continue;
         }
-        DEBUG_MAIN(("main: Desc Email ID %#"PRIx64" [d_ptr->d_id = %#"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id));
+        DEBUG_INFO(("Desc Email ID %#"PRIx64" [d_ptr->d_id = %#"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id));
 
         item = pst_parse_item(&pstfile, d_ptr, NULL);
-        DEBUG_MAIN(("main: About to process item\n"));
+        DEBUG_INFO(("About to process item\n"));
 
         if (!item) {
             ff.skip_count++;
-            DEBUG_MAIN(("main: A NULL item was seen\n"));
+            DEBUG_INFO(("A NULL item was seen\n"));
             continue;
         }
 
         if (item->subject.str) {
-            DEBUG_EMAIL(("item->subject = %s\n", item->subject.str));
+            DEBUG_INFO(("item->subject = %s\n", item->subject.str));
         }
 
         if (item->folder && item->file_as.str) {
-            DEBUG_MAIN(("Processing Folder \"%s\"\n", item->file_as.str));
-            if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as.str);
-            fflush(stdout);
+            DEBUG_INFO(("Processing Folder \"%s\"\n", item->file_as.str));
+            if (output_mode != OUTPUT_QUIET) {
+                pst_debug_lock();
+                    printf("Processing Folder \"%s\"\n", item->file_as.str);
+                    fflush(stdout);
+                pst_debug_unlock();
+            }
             ff.item_count++;
             if (d_ptr->child && (deleted_mode == DMODE_INCLUDE || strcasecmp(item->file_as.str, "Deleted Items"))) {
                 //if this is a non-empty folder other than deleted items, we want to recurse into it
@@ -262,10 +267,10 @@
 
         } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
             if (!ff.type) ff.type = item->type;
-            DEBUG_MAIN(("main: Processing Contact\n"));
+            DEBUG_INFO(("Processing Contact\n"));
             if (ff.type != PST_TYPE_CONTACT) {
                 ff.skip_count++;
-                DEBUG_MAIN(("main: I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Skipping it\n", ff.type));
+                DEBUG_INFO(("I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Skipping it\n", ff.type));
             }
             else {
                 ff.item_count++;
@@ -283,10 +288,10 @@
 
         } else if (item->email && ((item->type == PST_TYPE_NOTE) || (item->type == PST_TYPE_SCHEDULE) || (item->type == PST_TYPE_REPORT))) {
             if (!ff.type) ff.type = item->type;
-            DEBUG_MAIN(("main: Processing Email\n"));
+            DEBUG_INFO(("Processing Email\n"));
             if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) {
                 ff.skip_count++;
-                DEBUG_MAIN(("main: I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type));
+                DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type));
             }
             else {
                 char *extra_mime_headers = NULL;
@@ -297,10 +302,10 @@
 
         } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
             if (!ff.type) ff.type = item->type;
-            DEBUG_MAIN(("main: Processing Journal Entry\n"));
+            DEBUG_INFO(("Processing Journal Entry\n"));
             if (ff.type != PST_TYPE_JOURNAL) {
                 ff.skip_count++;
-                DEBUG_MAIN(("main: I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Skipping it\n", ff.type));
+                DEBUG_INFO(("I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Skipping it\n", ff.type));
             }
             else {
                 ff.item_count++;
@@ -311,10 +316,10 @@
 
         } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) {
             if (!ff.type) ff.type = item->type;
-            DEBUG_MAIN(("main: Processing Appointment Entry\n"));
+            DEBUG_INFO(("Processing Appointment Entry\n"));
             if (ff.type != PST_TYPE_APPOINTMENT) {
                 ff.skip_count++;
-                DEBUG_MAIN(("main: I have an appointment, but the folder type %"PRIi32" isn't an appointment folder. Skipping it\n", ff.type));
+                DEBUG_INFO(("I have an appointment, but the folder type %"PRIi32" isn't an appointment folder. Skipping it\n", ff.type));
             }
             else {
                 ff.item_count++;
@@ -326,11 +331,11 @@
         } else if (item->message_store) {
             // there should only be one message_store, and we have already done it
             ff.skip_count++;
-            DEBUG_MAIN(("item with message store content, type %i %s folder type %i, skipping it\n", item->type, item->ascii_type, ff.type));
+            DEBUG_INFO(("item with message store content, type %i %s folder type %i, skipping it\n", item->type, item->ascii_type, ff.type));
 
         } else {
             ff.skip_count++;
-            DEBUG_MAIN(("main: Unknown item type %i (%s) name (%s)\n",
+            DEBUG_INFO(("Unknown item type %i (%s) name (%s)\n",
                         item->type, item->ascii_type, item->file_as.str));
         }
         pst_freeItem(item);
@@ -433,12 +438,35 @@
         exit(2);
     }
 
+#ifdef _SC_NPROCESSORS_ONLN
+    number_processors =  sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+    max_children    = (max_child_specified) ? max_children : number_processors * 4;
+    active_children = 0;
+    child_processes = (pid_t *)pst_malloc(sizeof(pid_t) * max_children);
+    memset(child_processes, 0, sizeof(pid_t) * max_children);
+
+#ifdef HAVE_SEMAPHORE_H
+    if (max_children) {
+        shared_memory_id = shmget(IPC_PRIVATE, sizeof(sem_t)*2, 0777);
+        if (shared_memory_id >= 0) {
+            global_children = (sem_t *)shmat(shared_memory_id, NULL, 0);
+            if (global_children == (sem_t *)-1) global_children = NULL;
+            if (global_children) {
+                output_mutex = &(global_children[1]);
+                sem_init(global_children, 1, max_children);
+                sem_init(output_mutex, 1, 1);
+            }
+            shmctl(shared_memory_id, IPC_RMID, NULL);
+        }
+    }
+#endif
+
     #ifdef DEBUG_ALL
         // force a log file
         if (!d_log) d_log = "readpst.log";
     #endif // defined DEBUG_ALL
-    DEBUG_INIT(d_log);
-    DEBUG_REGISTER_CLOSE();
+    DEBUG_INIT(d_log, output_mutex);
     DEBUG_ENT("main");
 
     if (output_mode != OUTPUT_QUIET) printf("Opening PST file and indexes...\n");
@@ -452,14 +480,14 @@
         x = errno;
         pst_close(&pstfile);
         DEBUG_RET();
-        DIE(("main: Cannot change to output dir %s: %s\n", output_dir, strerror(x)));
+        DIE(("Cannot change to output dir %s: %s\n", output_dir, strerror(x)));
     }
 
     d_ptr = pstfile.d_head; // first record is main record
     item  = pst_parse_item(&pstfile, d_ptr, NULL);
     if (!item || !item->message_store) {
         DEBUG_RET();
-        DIE(("main: Could not get root record\n"));
+        DIE(("Could not get root record\n"));
     }
 
     // default the file_as to the same as the main filename if it doesn't exist
@@ -474,9 +502,9 @@
         item->file_as.str = (char*)pst_malloc(strlen(temp)+1);
         strcpy(item->file_as.str, temp);
         item->file_as.is_utf8 = 1;
-        DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as.str));
+        DEBUG_INFO(("file_as was blank, so am using %s\n", item->file_as.str));
     }
-    DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as.str));
+    DEBUG_INFO(("Root Folder Name: %s\n", item->file_as.str));
 
     d_ptr = pst_getTopOfFolders(&pstfile, item);
     if (!d_ptr) {
@@ -484,41 +512,21 @@
         DIE(("Top of folders record not found. Cannot continue\n"));
     }
 
-#ifdef _SC_NPROCESSORS_ONLN
-    number_processors =  sysconf(_SC_NPROCESSORS_ONLN);
-#endif
-    max_children    = (d_log) ? 0 : (!max_child_specified) ? number_processors * 4 : max_children;
-    active_children = 0;
-    child_processes = (pid_t *)pst_malloc(sizeof(pid_t) * max_children);
-    memset(child_processes, 0, sizeof(pid_t) * max_children);
-
-#ifdef HAVE_SEMAPHORE_H
-    if (max_children) {
-        shared_memory_id = shmget(IPC_PRIVATE, sizeof(sem_t), 0777);
-        //printf("shared memory id %d\n", shared_memory_id);
-        if (shared_memory_id >= 0) {
-            global_children = (sem_t *)shmat(shared_memory_id, NULL, 0);
-            //printf("shared memory pointer %p\n", (void*)global_children);
-            if (global_children == (sem_t *)-1) global_children = NULL;
-            if (global_children) sem_init(global_children, 1, max_children);
-            shmctl(shared_memory_id, IPC_RMID, NULL);
-        }
-    }
-#endif
-
     process(item, d_ptr->child);    // do the children of TOPF
     grim_reaper(1); // wait for all child processes
 
+    pst_freeItem(item);
+    pst_close(&pstfile);
+    DEBUG_RET();
+
 #ifdef HAVE_SEMAPHORE_H
     if (global_children) {
         sem_destroy(global_children);
+        sem_destroy(output_mutex);
         shmdt(global_children);
     }
 #endif
 
-    pst_freeItem(item);
-    pst_close(&pstfile);
-    DEBUG_RET();
     regfree(&meta_charset_pattern);
     return 0;
 }
@@ -527,7 +535,6 @@
 void write_email_body(FILE *f, char *body) {
     char *n = body;
     DEBUG_ENT("write_email_body");
-    DEBUG_INFO(("buffer pointer %p\n", body));
     while (n) {
         if (strncmp(body, "From ", 5) == 0)
             fprintf(f, ">");
@@ -615,8 +622,7 @@
     sprintf(dir, OUTPUT_KMAIL_DIR_TEMPLATE, fname);
     check_filename(dir);
     if (D_MKDIR(dir)) {
-        //error occured
-        if (errno != EEXIST) {
+        if (errno != EEXIST) {  // not an error because it exists
             x = errno;
             DIE(("mk_kmail_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
         }
@@ -656,16 +662,15 @@
 }
 
 
-// this will create a directory by that name, then make an mbox file inside
-// that dir.  any subsequent dirs will be created by name, and they will
-// contain mbox files
+// this will create a directory by that name,
+// then make an mbox file inside that directory.
 char *mk_recurse_dir(char *dir, int32_t folder_type) {
     int x;
     char *out_name;
     DEBUG_ENT("mk_recurse_dir");
     check_filename(dir);
     if (D_MKDIR (dir)) {
-        if (errno != EEXIST) { // not an error because it exists
+        if (errno != EEXIST) {  // not an error because it exists
             x = errno;
             DIE(("mk_recurse_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
         }
@@ -723,7 +728,7 @@
             snprintf(dir_name, dirsize, "%s" SEP_MAIL_FILE_TEMPLATE, dir, y); // enough for 9 digits allocated above
 
         check_filename(dir_name);
-        DEBUG_MAIN(("about to try creating %s\n", dir_name));
+        DEBUG_INFO(("about to try creating %s\n", dir_name));
         if (D_MKDIR(dir_name)) {
             if (errno != EEXIST) { // if there is an error, and it doesn't already exist
                 x = errno;
@@ -783,7 +788,7 @@
 int mk_separate_file(struct file_ll *f) {
     const int name_offset = 1;
     DEBUG_ENT("mk_separate_file");
-    DEBUG_MAIN(("opening next file to save email\n"));
+    DEBUG_INFO(("opening next file to save email\n"));
     if (f->item_count > 999999999) { // bigger than nine 9's
         DIE(("mk_separate_file: The number of emails in this folder has become too high to handle\n"));
     }
@@ -880,7 +885,7 @@
             DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
         }
     }
-    DEBUG_EMAIL(("Saving attachment to %s\n", temp));
+    DEBUG_INFO(("Saving attachment to %s\n", temp));
     if (!(fp = fopen(temp, "w"))) {
         DEBUG_WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
     } else {
@@ -924,7 +929,7 @@
 {
     char *attach_filename;
     DEBUG_ENT("write_inline_attachment");
-    DEBUG_EMAIL(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->i_id));
+    DEBUG_INFO(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->i_id));
 
     if (!attach->data.data) {
         // make sure we can fetch data from the id
@@ -963,7 +968,7 @@
 {
     DEBUG_ENT("header_has_field");
     if (my_stristr(header, field) || (strncasecmp(header, field+1, strlen(field)-1) == 0)) {
-        DEBUG_EMAIL(("header block has %s header\n", field+1));
+        DEBUG_INFO(("header block has %s header\n", field+1));
         *flag = 1;
     }
     DEBUG_RET();
@@ -996,7 +1001,7 @@
         *e = '\0';
             snprintf(body_subfield, size_subfield, "%s", s);  // copy the subfield to our buffer
         *e = save;
-        DEBUG_EMAIL(("body %s %s from headers\n", subfield, body_subfield));
+        DEBUG_INFO(("body %s %s from headers\n", subfield, body_subfield));
     }
     DEBUG_RET();
 }
@@ -1050,7 +1055,7 @@
     DEBUG_ENT("test_base64");
     while (*b != 0) {
         if ((*b < 32) && (*b != 9) && (*b != 10)) {
-            DEBUG_EMAIL(("found base64 byte %d\n", (int)*b));
+            DEBUG_INFO(("found base64 byte %d\n", (int)*b));
             DEBUG_HEXDUMPC(body, strlen(body), 0x10);
             b64 = 1;
             break;
@@ -1077,15 +1082,15 @@
             html[e] = '\0';
                 snprintf(charset, charsetlen, "%s", html+s);    // copy the html charset
             html[e] = save;
-            DEBUG_EMAIL(("charset %s from html text\n", charset));
+            DEBUG_INFO(("charset %s from html text\n", charset));
         }
         else {
-            DEBUG_EMAIL(("matching %d %d %d %d", match[0].rm_so, match[0].rm_eo, match[1].rm_so, match[1].rm_eo));
+            DEBUG_INFO(("matching %d %d %d %d", match[0].rm_so, match[0].rm_eo, match[1].rm_so, match[1].rm_eo));
             DEBUG_HEXDUMPC(html, strlen(html), 0x10);
         }
     }
     else {
-        DEBUG_EMAIL(("regexec returns %d\n", rc));
+        DEBUG_INFO(("regexec returns %d\n", rc));
     }
     DEBUG_RET();
 }
@@ -1102,7 +1107,7 @@
             t = header_get_field(headers, "\nContent-Type: ");
             if (t) {
                 t++;
-                DEBUG_EMAIL(("found content type header\n"));
+                DEBUG_INFO(("found content type header\n"));
                 char *n = strchr(t, '\n');
                 char *s = strstr(t, ": ");
                 char *e = strchr(t, ';');
@@ -1111,12 +1116,12 @@
                     s += 2;
                     if (!strncasecmp(s, RFC822, e-s)) {
                         headers = temp+2;   // found rfc822 header
-                        DEBUG_EMAIL(("found 822 headers\n%s\n", headers));
+                        DEBUG_INFO(("found 822 headers\n%s\n", headers));
                         break;
                     }
                 }
             }
-            //DEBUG_EMAIL(("skipping to next block after\n%s\n", headers));
+            //DEBUG_INFO(("skipping to next block after\n%s\n", headers));
             headers = temp+2;   // skip to next chunk of headers
         }
         *extra_mime_headers = headers;
@@ -1133,13 +1138,13 @@
         // is not utf-8, and the data came from a unicode (utf16) field
         // and is now in utf-8.
         size_t rc;
-        DEBUG_EMAIL(("Convert %s utf-8 to %s\n", mime, charset));
+        DEBUG_INFO(("Convert %s utf-8 to %s\n", mime, charset));
         pst_vbuf *newer = pst_vballoc(2);
         rc = pst_vb_utf8to8bit(newer, body->str, strlen(body->str), charset);
         if (rc == (size_t)-1) {
             // unable to convert, change the charset to utf8
             free(newer->b);
-            DEBUG_EMAIL(("Failed to convert %s utf-8 to %s\n", mime, charset));
+            DEBUG_INFO(("Failed to convert %s utf-8 to %s\n", mime, charset));
             charset = "utf-8";
         }
         else {
@@ -1269,7 +1274,7 @@
             // pointer to all the embedded MIME headers.
             // we use these to find the actual rfc822 headers for embedded message/rfc822 mime parts
             *extra_mime_headers = temp+2;
-            DEBUG_EMAIL(("Found extra mime headers\n%s\n", temp+2));
+            DEBUG_INFO(("Found extra mime headers\n%s\n", temp+2));
         }
 
         // Check if the headers have all the necessary fields
@@ -1314,11 +1319,11 @@
         header_strip_field(headers, "\nX-From_: ");
     }
 
-    DEBUG_EMAIL(("About to print Header\n"));
+    DEBUG_INFO(("About to print Header\n"));
 
     if (item && item->subject.str) {
         pst_convert_utf8(item, &item->subject);
-        DEBUG_EMAIL(("item->subject = %s\n", item->subject.str));
+        DEBUG_INFO(("item->subject = %s\n", item->subject.str));
     }
 
     if (mode != MODE_SEPARATE) {
@@ -1423,7 +1428,7 @@
 
     if (item->email->rtf_compressed.data && save_rtf) {
         pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
-        DEBUG_EMAIL(("Adding RTF body as attachment\n"));
+        DEBUG_INFO(("Adding RTF body as attachment\n"));
         memset(attach, 0, sizeof(pst_item_attach));
         attach->next = item->attach;
         item->attach = attach;
@@ -1438,7 +1443,7 @@
         // if either the body or htmlbody is encrypted, add them as attachments
         if (item->email->encrypted_body.data) {
             pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
-            DEBUG_EMAIL(("Adding Encrypted Body as attachment\n"));
+            DEBUG_INFO(("Adding Encrypted Body as attachment\n"));
             attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach));
             memset(attach, 0, sizeof(pst_item_attach));
             attach->next = item->attach;
@@ -1450,7 +1455,7 @@
 
         if (item->email->encrypted_htmlbody.data) {
             pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
-            DEBUG_EMAIL(("Adding encrypted HTML body as attachment\n"));
+            DEBUG_INFO(("Adding encrypted HTML body as attachment\n"));
             attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach));
             memset(attach, 0, sizeof(pst_item_attach));
             attach->next = item->attach;
@@ -1474,9 +1479,9 @@
             pst_convert_utf8_null(item, &attach->filename1);
             pst_convert_utf8_null(item, &attach->filename2);
             pst_convert_utf8_null(item, &attach->mimetype);
-            DEBUG_EMAIL(("Attempting Attachment encoding\n"));
+            DEBUG_INFO(("Attempting Attachment encoding\n"));
             if (!attach->data.data && attach->mimetype.str && !strcmp(attach->mimetype.str, RFC822)) {
-                DEBUG_EMAIL(("seem to have special embedded message attachment\n"));
+                DEBUG_INFO(("seem to have special embedded message attachment\n"));
                 find_rfc822_headers(extra_mime_headers);
                 write_embedded_message(f_output, attach, boundary, pst, extra_mime_headers);
             }
@@ -1812,11 +1817,11 @@
         sprintf(temp, "%s", f->name);
         check_filename(temp);
         while ((f->output = fopen(temp, "r"))) {
-            DEBUG_MAIN(("need to increase filename because one already exists with that name\n"));
-            DEBUG_MAIN(("- increasing it to %s%d\n", f->name, x));
+            DEBUG_INFO(("need to increase filename because one already exists with that name\n"));
+            DEBUG_INFO(("- increasing it to %s%d\n", f->name, x));
             x++;
             sprintf(temp, "%s%08d", f->name, x);
-            DEBUG_MAIN(("- trying \"%s\"\n", f->name));
+            DEBUG_INFO(("- trying \"%s\"\n", f->name));
             if (x == 99999999) {
                 DIE(("create_enter_dir: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x));
             }
@@ -1830,7 +1835,7 @@
         }
     }
 
-    DEBUG_MAIN(("f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as.str));
+    DEBUG_INFO(("f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as.str));
     if (mode != MODE_SEPARATE) {
         check_filename(f->name);
         if (!(f->output = fopen(f->name, "w"))) {
@@ -1843,10 +1848,14 @@
 
 void close_enter_dir(struct file_ll *f)
 {
-    DEBUG_MAIN(("main: processed item count for folder %s is %i, skipped %i, total %i \n",
+    DEBUG_INFO(("processed item count for folder %s is %i, skipped %i, total %i \n",
                 f->dname, f->item_count, f->skip_count, f->stored_count));
-    if (output_mode != OUTPUT_QUIET) printf("\t\"%s\" - %i items done, %i items skipped.\n",
-                                            f->dname, f->item_count, f->skip_count);
+    if (output_mode != OUTPUT_QUIET) {
+        pst_debug_lock();
+            printf("\t\"%s\" - %i items done, %i items skipped.\n", f->dname, f->item_count, f->skip_count);
+            fflush(stdout);
+        pst_debug_unlock();
+    }
     if (f->output) {
         struct stat st;
         fclose(f->output);
--- a/xml/libpst.in	Sat May 16 10:32:26 2009 -0700
+++ b/xml/libpst.in	Mon May 18 15:55:05 2009 -0700
@@ -129,9 +129,8 @@
                 <varlistentry>
                     <term>-d <replaceable class="parameter">debug-file</replaceable></term>
                     <listitem><para>
-                        Specify name of debug log file. The
-                        log file is not an ascii file, it is a binary file readable
-                        by <command>readpstlog</command>.
+                        Specify name of debug log file. The log file is now an ascii file,
+                        instead of the binary file used in previous versions.
                     </para></listitem>
                 </varlistentry>
                 <varlistentry>
@@ -188,13 +187,6 @@
             </variablelist>
         </refsect1>
 
-        <refsect1 id='readpst.also.1'>
-            <title>See Also</title>
-            <para>
-                <citerefentry><refentrytitle>readpstlog</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>
-            </para>
-        </refsect1>
-
         <refsect1 id='readpst.author.1'>
             <title>Author</title>
             <para>
@@ -273,9 +265,8 @@
                 <varlistentry>
                     <term>-d <replaceable class="parameter">debug-file</replaceable></term>
                     <listitem><para>
-                        Specify name of debug log file. The
-                        log file is not an ascii file, it is a binary file readable
-                        by <command>readpstlog</command>.
+                        Specify name of debug log file. The log file is now an ascii file,
+                        instead of the binary file used in previous versions.
                     </para></listitem>
                 </varlistentry>
                 <varlistentry>
@@ -295,13 +286,6 @@
             </para>
         </refsect1>
 
-        <refsect1 id='lspst.also.1'>
-            <title>See Also</title>
-            <para>
-                <citerefentry><refentrytitle>readpstlog</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>
-            </para>
-        </refsect1>
-
         <refsect1 id='lspst.author.1'>
             <title>Author</title>
             <para>
@@ -337,181 +321,6 @@
     </refentry>
 
 
-    <refentry id="readpstlog.1">
-        <refentryinfo>
-            <date>2009-05-16</date>
-        </refentryinfo>
-
-        <refmeta>
-            <refentrytitle>readpstlog</refentrytitle>
-            <manvolnum>1</manvolnum>
-            <refmiscinfo>readpstlog @VERSION@</refmiscinfo>
-        </refmeta>
-
-        <refnamediv id='readpstlog.name.1'>
-            <refname>readpstlog</refname>
-            <refpurpose>convert a <command>readpst</command> logfile to text format</refpurpose>
-        </refnamediv>
-
-        <refsynopsisdiv id='readpstlog.synopsis.1'>
-            <title>Synopsis</title>
-            <cmdsynopsis>
-                <command>readpstlog</command>
-                <arg><option>-f <replaceable class="parameter">format</replaceable></option></arg>
-                <arg><option>-t <replaceable class="parameter">include-types</replaceable></option></arg>
-                <arg><option>-x <replaceable class="parameter">exclude-types</replaceable></option></arg>
-                <arg choice='plain'>logfile</arg>
-            </cmdsynopsis>
-        </refsynopsisdiv>
-
-        <refsect1 id='readpstlog.description.1'>
-            <title>Description</title>
-            <para><command>readpstlog</command>
-                is a program that converts the binary logfile generated
-                by <command>readpst</command> to a more desirable text format.
-            </para>
-        </refsect1>
-
-        <refsect1 id='readpstlog.options.1'>
-            <title>Options</title>
-            <variablelist>
-                <varlistentry>
-                    <term>-f <replaceable class="parameter">format</replaceable></term>
-                    <listitem><para>
-                        Sets the format of the text log output.  Currently, the only valid output
-                        formats are T, for single line text, D for the default default multi line
-                        format, and I for an indented style with single line text.
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>-t <replaceable class="parameter">include-types</replaceable></term>
-                    <listitem><para>
-                        Print only the specified types of log messages.
-                        Types are specified in a comma-delimited list (e.g. 3,10,5,6).
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>-x <replaceable class="parameter">exclude-types</replaceable></term>
-                    <listitem><para>
-                        Exclude the specified types of log messages.
-                        Types are specified in a comma-delimited list (e.g. 3,10,5,6).
-                    </para></listitem>
-                </varlistentry>
-            </variablelist>
-        </refsect1>
-
-        <refsect1 id='readpstlog.message.types.1'>
-            <title>Message Types</title>
-            <para><command>readpstlog</command> understands the following types of log
-                messages:
-            </para>
-            <variablelist>
-                <varlistentry>
-                    <term>1</term>
-                    <listitem><para>
-                        File accesses
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>2</term>
-                    <listitem><para>
-                        Index accesses
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>3</term>
-                    <listitem><para>
-                        New email found
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>4</term>
-                    <listitem><para>
-                        Warnings
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>5</term>
-                    <listitem><para>
-                        Read accesses
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>6</term>
-                    <listitem><para>
-                        Informational messages
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>7</term>
-                    <listitem><para>
-                        Main function calls
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>8</term>
-                    <listitem><para>
-                        Decrypting calls
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>9</term>
-                    <listitem><para>
-                        Function entries
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>10</term>
-                    <listitem><para>
-                        Function exits
-                    </para></listitem>
-                </varlistentry>
-                <varlistentry>
-                    <term>11</term>
-                    <listitem><para>
-                        HexDump calls
-                    </para></listitem>
-                </varlistentry>
-            </variablelist>
-        </refsect1>
-
-        <refsect1 id='readpstlog.author.1'>
-            <title>Author</title>
-            <para>
-                This manual page was written by Joe Nahmias &lt;joe@nahmias.net&gt;
-                for the Debian GNU/Linux system (but may be used by others). It was
-                converted to xml format by Carl Byington &lt;carl@five-ten-sg.com&gt;.
-            </para>
-        </refsect1>
-
-        <refsect1 id='readpstlog.copyright.1'>
-            <title>Copyright</title>
-            <para>
-                Copyright (C) 2002 by David Smith &lt;dave.s@earthcorp.com&gt;.
-                XML version Copyright (C) 2008 by 510 Software Group &lt;carl@five-ten-sg.com&gt;.
-            </para>
-            <para>
-                This program is free software; you can redistribute it and/or modify it
-                under the terms of the GNU General Public License as published by the
-                Free Software Foundation; either version 2, or (at your option) any
-                later version.
-            </para>
-            <para>
-                You should have received a copy of the GNU General Public License along
-                with this program; see the file COPYING.  If not, please write to the
-                Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
-            </para>
-        </refsect1>
-
-        <refsect1 id='readpstlog.version.1'>
-            <title>Version</title>
-            <para>
-                @VERSION@
-            </para>
-        </refsect1>
-    </refentry>
-
-
     <refentry id="pst2ldif.1">
         <refentryinfo>
             <date>2009-05-16</date>