changeset 46:b2a7f2e0926a

more fixes for 64 bit format
author carl
date Sat, 12 Jan 2008 15:20:53 -0800
parents b961bcdadd0e
children 5fb8d997feed
files ChangeLog configure.in regression/regression-tests.bash src/common.h src/debug.c src/define.h src/deltasearch.cpp src/dumpblocks.c src/getidblock.c src/libpst.c src/libpst.h src/lspst.c src/pst2ldif.cpp src/readpst.c src/readpstlog.c src/timeconv.c xml/libpst.in
diffstat 17 files changed, 1172 insertions(+), 1134 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jan 08 16:33:23 2008 -0800
+++ b/ChangeLog	Sat Jan 12 15:20:53 2008 -0800
@@ -1,3 +1,11 @@
+LibPST 0.6.2 (2008-01-12)
+===============================
+
+	* More fixes for Outlook 2003 64 bit parsing.
+	* All buffer sizes changed to size_t, all file offsets changed to off_t,
+	all function names start with pst_, many other type consistency issues
+	found by splint. Many changes to #llx in debug printing for 64 bit items.
+
 LibPST 0.6.1 (2008-01-06)
 ===============================
 
--- a/configure.in	Tue Jan 08 16:33:23 2008 -0800
+++ b/configure.in	Sat Jan 12 15:20:53 2008 -0800
@@ -1,7 +1,7 @@
 AC_INIT(configure.in)
 
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(libpst,0.6.1)
+AM_INIT_AUTOMAKE(libpst,0.6.2)
 AC_PATH_PROGS(BASH, bash)
 
 AC_LANG_CPLUSPLUS
--- a/regression/regression-tests.bash	Tue Jan 08 16:33:23 2008 -0800
+++ b/regression/regression-tests.bash	Sat Jan 12 15:20:53 2008 -0800
@@ -14,14 +14,15 @@
 $val  ../src/readpst -S     -o output3 ams.pst                       >out3.err 2>&1
 $val  ../src/readpst -M     -o output4 ams.pst                       >out4.err 2>&1
 $val  ../src/readpst        -o output5 mbmg.archive.pst              >out5.err 2>&1
-$val  ../src/readpst        -o output6 test.pst                      >out6.err 2>&1
+
+$val  ../src/readpst        -o output6 -d dumper test.pst            >out6.err 2>&1
+      ../src/readpstlog -f I dumper >dumpertest.log
+
 $val  ../src/readpst -cv    -o output7 -d dumper sample_64.pst       >out7.err 2>&1
       ../src/readpstlog -f I dumper >sample_64.log
 
 $val  ../src/lspst ams.pst >out8.err 2>&1
       ../src/readpstlog -f I lspst.debug >lspst.log
 
-#   ../src/readpst        -o output6 -d dumper /tmp/test.pst
-#   ../src/readpstlog -f I dumper >dumpertest.log
+rm -f dumper lspst.debug
 
-    rm -f dumper
--- a/src/common.h	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/common.h	Sat Jan 12 15:20:53 2008 -0800
@@ -14,7 +14,7 @@
 # define FILETIME_DEFINED
   /*Win32 Filetime struct - copied from WINE*/
   typedef struct {
-	  unsigned int dwLowDateTime;
+    unsigned int dwLowDateTime;
     unsigned int dwHighDateTime;
   } FILETIME;
 # endif
--- a/src/debug.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/debug.c	Sat Jan 12 15:20:53 2008 -0800
@@ -11,24 +11,24 @@
 # define vsnprintf _vsnprintf
 #endif
 
-struct _debug_item {
-	int type;
-	char * function;
-	unsigned int line;
-	char * file;
-	char * text;
-	struct _debug_item *next;
+struct pst_debug_item {
+    int type;
+    char * function;
+    unsigned int line;
+    char * file;
+    char * text;
+    struct pst_debug_item *next;
 } *item_head=NULL, *item_tail=NULL, *item_ptr=NULL, *info_ptr=NULL, *temp_list=NULL;
 
 
-struct _debug_func {
-	char * name;
-	struct _debug_func *next;
+struct pst_debug_func {
+    char * name;
+    struct pst_debug_func *next;
 } *func_head=NULL, *func_ptr=NULL;
 
 
-void _debug_write_msg(struct _debug_item *item, char *fmt, va_list *ap, int size);
-void _debug_write_hex(struct _debug_item *item, unsigned char *buf, int size, int col);
+void pst_debug_write_msg(struct pst_debug_item *item, char *fmt, va_list *ap, int size);
+void pst_debug_write_hex(struct pst_debug_item *item, unsigned char *buf, size_t size, int col);
 void * xmalloc(size_t size);
 
 // the largest text size we will store in memory. Otherwise we
@@ -36,47 +36,47 @@
 // text body directly to the file
 #define MAX_MESSAGE_SIZE 4096
 
-void _pst_debug(char *fmt, ...) {
-	va_list ap;
-	va_start(ap,fmt);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
+void pst_debug(char *fmt, ...) {
+    va_list ap;
+    va_start(ap,fmt);
+    vfprintf(stderr, fmt, ap);
+    va_end(ap);
 }
 
 
 #define NUM_COL 30
-void _pst_debug_hexdump(FILE *out, unsigned char *buf, size_t size, int col, int delta) {
-	int off = 0, toff;
-	int count = 0;
+void pst_debug_hexdumper(FILE *out, unsigned char *buf, size_t size, int col, int delta) {
+    int off = 0, toff;
+    int count = 0;
 
-	if (!out) return;	// no file
-	if (col == -1) col = NUM_COL;
-	fprintf(out, "\n");
-	while (off < size) {
-		fprintf(out, "%06X\t:", off+delta);
-		toff = off;
-		while (count < col && off < size) {
-			fprintf(out, "%02hhx ", buf[off]);
-			off++; count++;
-		}
-		off = toff;
-		while (count < col) {
-			// 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) {
-			fprintf(out, "%c", isgraph(buf[off])?buf[off]:'.');
-			off++; count ++;
-		}
+    if (!out) return;   // no file
+    if (col == -1) col = NUM_COL;
+    fprintf(out, "\n");
+    while (off < size) {
+        fprintf(out, "%06X\t:", off+delta);
+        toff = off;
+        while (count < col && off < size) {
+            fprintf(out, "%02hhx ", buf[off]);
+            off++; count++;
+        }
+        off = toff;
+        while (count < col) {
+            // 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) {
+            fprintf(out, "%c", isgraph(buf[off])?buf[off]:'.');
+            off++; count ++;
+        }
 
-		fprintf(out, "\n");
-		count=0;
-	}
+        fprintf(out, "\n");
+        count=0;
+    }
 
-	fprintf(out, "\n");
+    fprintf(out, "\n");
 }
 
 
@@ -84,356 +84,355 @@
 unsigned int max_items=DEBUG_MAX_ITEMS, curr_items=0;
 
 
-void _debug_init(char* fname) {
-	unsigned char version = DEBUG_VERSION;
-	item_head = item_tail = NULL;
-	curr_items = 0;
-	if (debug_fp) _debug_close();
-	if (!fname) return;
-	if ((debug_fp = fopen(fname, "wb")) == NULL) {
-	  fprintf(stderr, "Opening of file %s failed\n", fname);
-	  exit(1);
-	}
-	fwrite(&version, 1, sizeof(char), debug_fp);
+void pst_debug_init(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);
+    }
+    fwrite(&version, 1, sizeof(char), debug_fp);
 }
 
 
-// function must be called before _debug_msg. It sets up the
+// function must be called before pst_debug_msg. It sets up the
 // structure for the function that follows
-void _debug_msg_info(int line, char* file, int type) {
-	char *x;
-	if (!debug_fp) return;	// no file
-	info_ptr = (struct _debug_item*) xmalloc(sizeof(struct _debug_item));
-	info_ptr->type = type;
-	info_ptr->line = line;
-	x = (func_head==NULL?"No Function":func_head->name);
-	info_ptr->function = (char*) xmalloc(strlen(x)+1);
-	strcpy(info_ptr->function, x);
+void pst_debug_msg_info(int line, char* file, int type) {
+    char *x;
+    if (!debug_fp) return;  // no file
+    info_ptr = (struct pst_debug_item*) xmalloc(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*) xmalloc(strlen(x)+1);
+    strcpy(info_ptr->function, x);
 
-	info_ptr->file = (char*) xmalloc(strlen(file)+1);
-	strcpy(info_ptr->file, file);
+    info_ptr->file = (char*) xmalloc(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;
+    //put the current record on a temp linked list
+    info_ptr->next = temp_list;
+    temp_list = info_ptr;
 }
 
 
-void _debug_msg_text(char* fmt, ...) {
-	va_list ap;
-	int f, g;
-	char x[2];
-	struct _debug_item *temp;
-	if (!debug_fp) return;	// no file
-	va_start(ap, fmt);
-	// 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);
-	}
-	// according to glibc 2.1, this should return the req. number of bytes for
-	// the string
+void pst_debug_msg_text(char* fmt, ...) {
+    va_list ap;
+    int f, g;
+    char x[2];
+    struct pst_debug_item *temp;
+    if (!debug_fp) return;  // no file
+    va_start(ap, fmt);
+    // 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);
+    }
+    // according to glibc 2.1, this should return the req. number of bytes for
+    // the string
   #ifdef _WIN32
-	// vsnprintf trick doesn't work. must use function called _vscprintf
-	// cannot find much documentation about this on internet or anywhere.
-	// I assume it isn't a standard function, but only in VisualC++
-	f = _vscprintf(fmt, ap);
+    // vsnprintf trick doesn't work. must use function called _vscprintf
+    // cannot find much documentation about this on internet or anywhere.
+    // I assume it isn't a standard function, but only in VisualC++
+    f = _vscprintf(fmt, ap);
   #else
-	f = vsnprintf(x, 1, fmt, ap);
+    f = vsnprintf(x, 1, fmt, ap);
   #endif
-	va_end(ap);  // must be called after vsnprintf()
+    va_end(ap);  // must be called after vsnprintf()
 
-	if (f > 0 && f < MAX_MESSAGE_SIZE) {
-		info_ptr->text = (char*) xmalloc(f+1);
-		va_start(ap, fmt);
-		if ((g = vsnprintf(info_ptr->text, f, fmt, ap)) == -1) {
-			fprintf(stderr, "_debug_msg: Dieing! 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;
-		_debug_write(); // dump the current messages
-		info_ptr = temp;
-		va_start(ap, fmt);
-		_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";
-	}
+    if (f > 0 && f < MAX_MESSAGE_SIZE) {
+        info_ptr->text = (char*) xmalloc(f+1);
+        va_start(ap, fmt);
+        if ((g = vsnprintf(info_ptr->text, f, fmt, ap)) == -1) {
+            fprintf(stderr, "_debug_msg: Dieing! 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";
+    }
 
-	if (!item_head)
-	  item_head = info_ptr;
+    if (!item_head)
+      item_head = info_ptr;
 
-	info_ptr->next = NULL;
-	if (item_tail) item_tail->next = info_ptr;
-	item_tail = 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
-		_debug_write();
-		info_ptr = NULL;
-	}
+    if (++curr_items == max_items) {
+        // here we will jump off and save the contents
+        pst_debug_write();
+        info_ptr = NULL;
+    }
 }
 
 
-void _debug_hexdump(unsigned char *x, int y, int cols, int delta) {
-	struct _debug_item *temp;
-	if (!debug_fp) return;	// no file
-	info_ptr = temp_list;
-	if (info_ptr) temp_list = info_ptr->next;
-	temp = info_ptr;
-	_debug_write();
-	info_ptr = temp;
-	_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_hexdump(unsigned 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 _debug_func(char *function) {
-	func_ptr = xmalloc (sizeof(struct _debug_func));
-	func_ptr->name = xmalloc(strlen(function)+1);
-	strcpy(func_ptr->name, function);
-	func_ptr->next = func_head;
-	func_head = func_ptr;
+void pst_debug_func(char *function) {
+    func_ptr = xmalloc (sizeof(struct pst_debug_func));
+    func_ptr->name = xmalloc(strlen(function)+1);
+    strcpy(func_ptr->name, function);
+    func_ptr->next = func_head;
+    func_head = func_ptr;
 }
 
 
-void _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"));
-	}
+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"));
+    }
 }
 
 
-void _debug_close(void) {
-	_debug_write();
-	while (func_head) {
-		func_ptr = func_head;
-		func_head = func_head->next;
-		free(func_ptr->name);
-		free(func_ptr);
-	}
-	if (debug_fp) fclose(debug_fp);
-	debug_fp = NULL;
+void pst_debug_close(void) {
+    pst_debug_write();
+    while (func_head) {
+        func_ptr = func_head;
+        func_head = func_head->next;
+        free(func_ptr->name);
+        free(func_ptr);
+    }
+    if (debug_fp) fclose(debug_fp);
+    debug_fp = NULL;
 }
 
 
-void _debug_write() {
-	size_t size, ptr, funcname, filename, text, end;
-	char *buf = NULL, rec_type;
-	if (!debug_fp) return;	// no file
-	off_t index_pos = ftell (debug_fp);
+void pst_debug_write() {
+    size_t size, ptr, funcname, filename, text, end;
+    char *buf = NULL, rec_type;
+    if (!debug_fp) return;  // no file
+    off_t index_pos = ftell (debug_fp);
     off_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(off_t));
-	off_t *index;
-	int index_ptr = 0;
-	struct _debug_file_rec_m mfile_rec;
-	struct _debug_file_rec_l lfile_rec;
+    // add 2. One for the pointer to the next index,
+    // one for the count of this index
+    int index_size = ((curr_items+2) * sizeof(off_t));
+    off_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.
+    if (curr_items == 0) return;    // no items to write.
 
-	index = (int*) xmalloc(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
-	fwrite(index, index_size, 1, debug_fp);
-	index[index_ptr++] = curr_items;
+    index = (off_t*)xmalloc(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
+    fwrite(index, index_size, 1, debug_fp);
+    index[index_ptr++] = curr_items;
 
-	item_ptr = item_head;
-	while (item_ptr) {
-		file_pos = ftell(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 = xmalloc(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';
-			fwrite(&rec_type, 1, sizeof(char), 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;
-			fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-		} else {
-			rec_type = 'M';
-			fwrite(&rec_type, 1, sizeof(char), 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;
-			fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
-		}
-		fwrite(buf, 1, ptr, 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] = ftell(debug_fp);
+    item_ptr = item_head;
+    while (item_ptr) {
+        file_pos = ftell(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 = xmalloc(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';
+            fwrite(&rec_type, 1, sizeof(char), 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;
+            fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
+        } else {
+            rec_type = 'M';
+            fwrite(&rec_type, 1, sizeof(char), 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;
+            fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
+        }
+        fwrite(buf, 1, ptr, 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] = ftell(debug_fp);
 
-	// we should now have a complete index
-	fseek(debug_fp, index_pos, SEEK_SET);
-	fwrite(index, index_size, 1, debug_fp);
-	fseek(debug_fp, 0, SEEK_END);
-	item_ptr = item_head = item_tail = NULL;
-	free(index);
-	if (buf) free(buf);
+    // we should now have a complete index
+    fseek(debug_fp, index_pos, SEEK_SET);
+    fwrite(index, index_size, 1, debug_fp);
+    fseek(debug_fp, 0, SEEK_END);
+    item_ptr = item_head = item_tail = NULL;
+    free(index);
+    if (buf) free(buf);
 }
 
 
-void _debug_write_msg(struct _debug_item *item, char *fmt, va_list *ap, int size) {
-	struct _debug_file_rec_l lfile_rec;
-	struct _debug_file_rec_m mfile_rec;
-	unsigned char rec_type;
-	int index_size = 3 * sizeof(off_t);
-	off_t index[3];
-	off_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_pos = ftell(debug_fp);
-	fwrite(index, index_size, 1, debug_fp);
+void pst_debug_write_msg(struct pst_debug_item *item, 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(off_t);
+    off_t index[3];
+    off_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_pos = ftell(debug_fp);
+    fwrite(index, index_size, 1, debug_fp);
 
-	index[1] = ftell(debug_fp);
+    index[1] = ftell(debug_fp);
 
-	if (size > USHRT_MAX) { // bigger than can be stored in a short
-		rec_type = 'L';
-		fwrite(&rec_type, 1, sizeof(char), 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;
-		fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-	} else {
-		rec_type = 'M';
-		fwrite(&rec_type, 1, sizeof(char), 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;
-		fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
-	}
-	file_pos = ftell(debug_fp);
-	fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
-	fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
-	vfprintf(debug_fp, fmt, *ap);
-	fwrite(&zero, 1, 1, debug_fp);
+    if (size > USHRT_MAX) { // bigger than can be stored in a short
+        rec_type = 'L';
+        fwrite(&rec_type, 1, sizeof(char), 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;
+        fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
+    } else {
+        rec_type = 'M';
+        fwrite(&rec_type, 1, sizeof(char), 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;
+        fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
+    }
+    file_pos = ftell(debug_fp);
+    fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
+    fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
+    vfprintf(debug_fp, fmt, *ap);
+    fwrite(&zero, 1, 1, debug_fp);
 
-	end = ftell(debug_fp)-file_pos;
+    end = ftell(debug_fp)-file_pos;
 
-	index[2] = ftell(debug_fp);
-	fseek(debug_fp, index_pos, SEEK_SET);
-	fwrite(index, index_size, 1, debug_fp);
-	if (size > USHRT_MAX) {
-		fwrite(&rec_type, 1, sizeof(char), debug_fp);
-		lfile_rec.end = end;
-		fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-	} else {
-		fwrite(&rec_type, 1, sizeof(char), debug_fp);
-		mfile_rec.end = end;
-		fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
-	}
-	fseek(debug_fp, 0, SEEK_END);
+    index[2] = ftell(debug_fp);
+    fseek(debug_fp, index_pos, SEEK_SET);
+    fwrite(index, index_size, 1, debug_fp);
+    if (size > USHRT_MAX) {
+        fwrite(&rec_type, 1, sizeof(char), debug_fp);
+        lfile_rec.end = end;
+        fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
+    } else {
+        fwrite(&rec_type, 1, sizeof(char), debug_fp);
+        mfile_rec.end = end;
+        fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
+    }
+    fseek(debug_fp, 0, SEEK_END);
 }
 
 
-void _debug_write_hex(struct _debug_item *item, unsigned char *buf, int size, int col) {
-	struct _debug_file_rec_l lfile_rec;
-	unsigned char rec_type;
-	int index_size = 3 * sizeof(off_t);
-	off_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 = ftell(debug_fp);
-	fwrite(index, index_size, 1, debug_fp);
-	index[1] = ftell(debug_fp);
+void pst_debug_write_hex(struct pst_debug_item *item, unsigned char *buf, size_t size, int col) {
+    struct pst_debug_file_rec_l lfile_rec;
+    unsigned char rec_type;
+    int index_size = 3 * sizeof(off_t);
+    off_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 = ftell(debug_fp);
+    fwrite(index, index_size, 1, debug_fp);
+    index[1] = ftell(debug_fp);
 
-	// always use the long
-	rec_type = 'L';
-	fwrite(&rec_type, 1, sizeof(char), 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;
-	fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
+    // always use the long
+    rec_type = 'L';
+    fwrite(&rec_type, 1, sizeof(char), 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;
+    fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
 
-	file_pos = ftell(debug_fp);
-	fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
-	fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
+    file_pos = ftell(debug_fp);
+    fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
+    fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
 
-	_pst_debug_hexdump(debug_fp, buf, size, col, 0);
-	fwrite(&zero, 1, 1, debug_fp);
-	lfile_rec.end = ftell(debug_fp) - file_pos;
+    pst_debug_hexdumper(debug_fp, buf, size, col, 0);
+    fwrite(&zero, 1, 1, debug_fp);
+    lfile_rec.end = ftell(debug_fp) - file_pos;
 
-	index[2] = ftell(debug_fp);
-	fseek(debug_fp, index_pos, SEEK_SET);
-	fwrite(index, index_size, 1, debug_fp);
-	fwrite(&rec_type, 1, sizeof(char), debug_fp);
-	fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
-	fseek(debug_fp, 0, SEEK_END);
+    index[2] = ftell(debug_fp);
+    fseek(debug_fp, index_pos, SEEK_SET);
+    fwrite(index, index_size, 1, debug_fp);
+    fwrite(&rec_type, 1, sizeof(char), debug_fp);
+    fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
+    fseek(debug_fp, 0, SEEK_END);
 }
 
 
 void *xmalloc(size_t size) {
-	void *mem = malloc(size);
-	if (!mem) {
-		fprintf(stderr, "xMalloc: Out Of memory [req: %ld]\n", (long)size);
-		exit(1);
-	}
-  //memset(mem, 0, size);	// valgrind
-	return mem;
+    void *mem = malloc(size);
+    if (!mem) {
+        fprintf(stderr, "xMalloc: Out Of memory [req: %ld]\n", (long)size);
+        exit(1);
+    }
+    return mem;
 }
 
--- a/src/define.h	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/define.h	Sat Jan 12 15:20:53 2008 -0800
@@ -51,23 +51,23 @@
 #endif
 
 
-void _pst_debug(char *fmt, ...);
-void _pst_debug_hexdump(FILE* out, unsigned char* buf, size_t size, int col, int delta);
-void _pst_debug_hexprint(char *data, int size);
+void pst_debug(char *fmt, ...);
+void pst_debug_hexdumper(FILE* out, unsigned char* buf, size_t size, int col, int delta);
+void pst_debug_hexprint(char *data, int size);
 
-void _debug_init(char *fname);
-void _debug_msg_info (int line, char *file, int type);
-void _debug_msg_text(char* fmt, ...);
-void _debug_hexdump(unsigned char *x, int y, int cols, int delta);
-void _debug_func(char *function);
-void _debug_func_ret();
-void _debug_close(void);
-void _debug_write();
+void pst_debug_init(char *fname);
+void pst_debug_msg_info (int line, char *file, int type);
+void pst_debug_msg_text(char* fmt, ...);
+void pst_debug_hexdump(unsigned char *x, size_t y, int cols, int delta);
+void pst_debug_func(char *function);
+void pst_debug_func_ret();
+void pst_debug_close(void);
+void pst_debug_write();
 
 void * xmalloc(size_t size);
 
-#define MESSAGEPRINT(x,y) {_debug_msg_info(__LINE__,__FILE__,y);\
-						   _debug_msg_text x;}
+#define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\
+						   pst_debug_msg_text x;}
 
 #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();}
 
@@ -82,7 +82,7 @@
 }
 
 #ifdef DEBUGPRINT
-#define DEBUG_PRINT(x) _pst_debug x;
+#define DEBUG_PRINT(x) pst_debug x;
 #else
 #define DEBUG_PRINT(x) {}
 #endif
@@ -101,8 +101,8 @@
 
 #ifdef DEBUG_MODE_EMAIL
 #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
-#define DEBUG_EMAIL_HEXPRINT(x,y) {_debug_msg_info(__LINE__, __FILE__, 11);\
-								   _debug_hexdump(x, y, 0x10, 0);}
+#define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\
+								   pst_debug_hexdump(x, y, 0x10, 0);}
 #else
 #define DEBUG_EMAIL(x) {}
 #define DEBUG_EMAIL_HEXPRINT(x,y) {}
@@ -146,38 +146,38 @@
 
 #ifdef DEBUG_MODE_HEXDUMP
 #define DEBUG_HEXDUMP(x, s)\
-  {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
-   _debug_hexdump(x, s, 0x10, 0);}
+  {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
+   pst_debug_hexdump(x, s, 0x10, 0);}
 #define DEBUG_HEXDUMPC(x, s, c)\
-  {_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
-   _debug_hexdump(x, s, c, 0);}
+  {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
+   pst_debug_hexdump(x, s, c, 0);}
 #else
 #define DEBUG_HEXDUMP(x, s) {}
 #define DEBUG_HEXDUMPC(x, s, c) {}
 #endif
 
-#define DEBUG_FILE(x) {_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
-					   _debug_msg_text x;}
+#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)											\
 	{															\
-		 _debug_func(x);										\
+		 pst_debug_func(x);										\
 		MESSAGEPRINT(("Entering function\n"),DEBUG_FUNCENT_NO); \
 	}
 # define DEBUG_RET()											\
 	{															\
 		MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO);  \
-		_debug_func_ret();										\
+		pst_debug_func_ret();										\
 	}
 #else
 # define DEBUG_ENT(x) {}
 # define DEBUG_RET() {}
 #endif
 
-#define DEBUG_INIT(fname) {_debug_init(fname);}
-#define DEBUG_CLOSE() {_debug_close();}
-#define DEBUG_REGISTER_CLOSE() {if(atexit(_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}
+#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);}
@@ -186,7 +186,7 @@
 	if (res) {return ret_val;}
 
 #define DEBUG_VERSION 1
-struct _debug_file_rec_m {
+struct pst_debug_file_rec_m {
   unsigned short int funcname;
   unsigned short int filename;
   unsigned short int text;
@@ -195,7 +195,7 @@
   unsigned int type;
 };
 
-struct _debug_file_rec_l {
+struct pst_debug_file_rec_l {
   unsigned int funcname;
   unsigned int filename;
   unsigned int text;
--- a/src/deltasearch.cpp	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/deltasearch.cpp	Sat Jan 12 15:20:53 2008 -0800
@@ -57,14 +57,14 @@
 		off_t size = st.st_size;
 		unsigned char buf[size];
 		size_t s = read(fd, buf, size);
-		_pst_debug_hexdump(stdout, buf, s, 16, 0);
+		pst_debug_hexdumper(stdout, buf, s, 16, 0);
 		cout << endl;
 		cout << endl;
 		cout << " dump decrypted data " << endl;
 		for (off_t i=0; i<size; i++) {
 			buf[i] = comp_enc[buf[i]];
 		}
-		_pst_debug_hexdump(stdout, buf, s, 16, 0);
+		pst_debug_hexdumper(stdout, buf, s, 16, 0);
 		close(fd);
 	}
 	return 0;
--- a/src/dumpblocks.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/dumpblocks.c	Sat Jan 12 15:20:53 2008 -0800
@@ -34,7 +34,7 @@
   DEBUG_INIT("dumpblocks.log");
   DEBUG_REGISTER_CLOSE();
   DEBUG_ENT("main");
-  
+
   printf("Opening file %s\n",file);
   if (pst_open(&pstfile, file, "r")) {
     printf("Failed to open file %s\n", file);
@@ -46,28 +46,28 @@
     printf("Failed to load indexes in file %s\n", argv[1]);
     exit(1);
    }
-  
+
   if (outdir != NULL)
     if (chdir(outdir)) {
       printf("Failed to change into directory %s\n", outdir);
       exit(1);
     }
-  
+
   ptr = pstfile.i_head;
   outname = (char*) xmalloc(OUT_BUF);
   printf("Saving blocks\n");
   while (ptr != NULL) {
     /*    if (pstfile.encryption == PST_ENC) {
-      c = _pst_ff_getIDblock_dec(&pstfile, ptr->id, buf);
+      c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf);
       } else {*/
     if ((ptr->id & 0x02)==0 && pstfile.encryption == PST_ENC) {
-      c = _pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
+      c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
     } else {
-      c = _pst_ff_getIDblock(&pstfile, ptr->id, &buf);
+      c = pst_ff_getIDblock(&pstfile, ptr->id, &buf);
     }
 
     if (c > 0) {
-      snprintf(outname, OUT_BUF, "%x", ptr->id);
+      snprintf(outname, OUT_BUF, "%llx", ptr->id);
       if ((fp = fopen(outname, "wb")) == NULL) {
 	printf("Failed to open file %s\n", outname);
 	continue;
@@ -75,7 +75,7 @@
       fwrite(buf, 1, c, fp);
       fclose(fp);
     } else {
-      printf("Failed to read block id %#x\n", ptr->id);
+      printf("Failed to read block id %#llx\n", ptr->id);
     }
     ptr = ptr->next;
   }
--- a/src/getidblock.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/getidblock.c	Sat Jan 12 15:20:53 2008 -0800
@@ -69,26 +69,26 @@
 	DIE(("Error loading file index\n"));
   }
 
-  //  if ((ptr = _pst_getID(&pstfile, id)) == NULL) {
+  //  if ((ptr = pst_getID(&pstfile, id)) == NULL) {
   //	DIE(("id not found [%#x]\n", id));
   //  }
 
   DEBUG_MAIN(("Loading block\n"));
 
-  if ((readSize = _pst_ff_getIDblock(&pstfile, id, &buf)) <= 0 || buf == NULL) {
-	//	if ((readSize = _pst_read_block_size(&pstfile, ptr->offset, ptr->size, &buf, 1, 1)) < ptr->size) {
+  if ((readSize = pst_ff_getIDblock(&pstfile, id, &buf)) <= 0 || buf == NULL) {
+	//	if ((readSize = pst_read_block_size(&pstfile, ptr->offset, ptr->size, &buf, 1, 1)) < ptr->size) {
 	DIE(("Error loading block\n"));
   }
   if (binary==0) printf("Block %#x, size %#x[%i]\n",id, (unsigned int)readSize, (int) readSize);
 
   if (decrypt!=0)
-	if (_pst_decrypt(buf, readSize, (int)pstfile.encryption) != 0) {
+	if (pst_decrypt(buf, readSize, (int)pstfile.encryption) != 0) {
 	  DIE(("Error decrypting block\n"));
 	}
 
   DEBUG_MAIN(("Printing block... [id %#x, size %#x]\n", id, readSize));
   if (binary==0) {
-	_pst_debug_hexdump(stdout, buf, readSize, 0x10, 0);
+	pst_debug_hexdumper(stdout, buf, readSize, 0x10, 0);
   } else {
 	if (fwrite(buf, 1, readSize, stdout) != 0) {
 	  DIE(("Error occured during writing of buf to stdout\n"));
@@ -108,12 +108,12 @@
 	}
 	if (ptr == NULL) {
 	  ptr = (pst_desc_ll*)xmalloc(sizeof(pst_desc_ll));
-	  ptr->desc = _pst_getID(&pstfile, id);
+	  ptr->desc = pst_getID(&pstfile, id);
 	  ptr->list_index = NULL;
 	}
 	if (ptr != NULL) {
-	  if ((item = _pst_parse_item(&pstfile, ptr)) != NULL)
-	_pst_freeItem(item);
+	  if ((item = pst_parse_item(&pstfile, ptr)) != NULL)
+	pst_freeItem(item);
 	} else {
 	  DEBUG_MAIN(("item not found with this ID\n"));
 	  printf("Cannot find the owning Record of this ID. Cannot parse\n");
--- a/src/libpst.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/libpst.c	Sat Jan 12 15:20:53 2008 -0800
@@ -34,62 +34,67 @@
 #define INDEX_TYPE32            0x0E
 #define INDEX_TYPE64            0x17
 
-#define FILE_SIZE_POINTER32     0xA8
-#define INDEX_POINTER32         0xC4
-#define INDEX_COUNT32           0xC0
-#define SECOND_POINTER32        0xBC
-#define SECOND_COUNT32          0xB8
-#define INDEX_TYPE_OFFSET32     0x0A
-#define ENC_OFFSET32            0x1CD
-
-#define FILE_SIZE_POINTER64     0xB8
-#define INDEX_POINTER64         0xF0
-#define INDEX_COUNT64           0xE8
-#define SECOND_POINTER64        0xE0
-#define SECOND_COUNT64          0xD8
-#define INDEX_TYPE_OFFSET64     0x0A
-#define ENC_OFFSET64            0x201
-
-#define FILE_SIZE_POINTER ((do_read64) ? FILE_SIZE_POINTER64 : FILE_SIZE_POINTER32)
-#define INDEX_POINTER     ((do_read64) ? INDEX_POINTER64     : INDEX_POINTER32)
-#define INDEX_COUNT       ((do_read64) ? INDEX_COUNT64       : INDEX_COUNT32)
-#define SECOND_POINTER    ((do_read64) ? SECOND_POINTER64    : SECOND_POINTER32)
-#define SECOND_COUNT      ((do_read64) ? SECOND_COUNT64      : SECOND_COUNT32)
-#define INDEX_TYPE_OFFSET ((do_read64) ? INDEX_TYPE_OFFSET64 : INDEX_TYPE_OFFSET32)
-#define INDEX_TYPE        ((do_read64) ? INDEX_TYPE64        : INDEX_TYPE32)
-#define ENC_OFFSET        ((do_read64) ? ENC_OFFSET64        : ENC_OFFSET32)
+#define FILE_SIZE_POINTER32     (off_t)0xA8
+#define INDEX_POINTER32         (off_t)0xC4
+#define INDEX_BACK32            (off_t)0xC0
+#define SECOND_POINTER32        (off_t)0xBC
+#define SECOND_BACK32           (off_t)0xB8
+#define INDEX_TYPE_OFFSET32     (off_t)0x0A
+#define ENC_OFFSET32            (off_t)0x1CD
+
+#define FILE_SIZE_POINTER64     (off_t)0xB8
+#define INDEX_POINTER64         (off_t)0xF0
+#define INDEX_BACK64            (off_t)0xE8
+#define SECOND_POINTER64        (off_t)0xE0
+#define SECOND_BACK64           (off_t)0xD8
+#define INDEX_TYPE_OFFSET64     (off_t)0x0A
+#define ENC_OFFSET64            (off_t)0x201
+
+#define FILE_SIZE_POINTER ((pf->do_read64) ? FILE_SIZE_POINTER64 : FILE_SIZE_POINTER32)
+#define INDEX_POINTER     ((pf->do_read64) ? INDEX_POINTER64     : INDEX_POINTER32)
+#define INDEX_BACK        ((pf->do_read64) ? INDEX_BACK64        : INDEX_BACK32)
+#define SECOND_POINTER    ((pf->do_read64) ? SECOND_POINTER64    : SECOND_POINTER32)
+#define SECOND_BACK       ((pf->do_read64) ? SECOND_BACK64       : SECOND_BACK32)
+#define INDEX_TYPE_OFFSET ((pf->do_read64) ? INDEX_TYPE_OFFSET64 : INDEX_TYPE_OFFSET32)
+#define INDEX_TYPE        ((pf->do_read64) ? INDEX_TYPE64        : INDEX_TYPE32)
+#define ENC_OFFSET        ((pf->do_read64) ? ENC_OFFSET64        : ENC_OFFSET32)
 
 #define PST_SIGNATURE 0x4E444221
 
-int do_read64 = 0; //set this to 1 in order to try and read 64-bit pst files (Outlook 2003)
-
-struct _pst_table_ptr_struct32{
-  int32_t start;
-  int32_t u1;
-  int32_t offset;
+
+struct pst_table_ptr_struct32{
+  uint32_t start;
+  uint32_t u1;
+  uint32_t offset;
 };
-struct _pst_table_ptr_structn{
-  int64_t start;
-  int64_t u1;
-  int64_t offset;
+struct pst_table_ptr_structn{
+  uint64_t start;
+  uint64_t u1;
+  uint64_t offset;
 };
 
-typedef struct _pst_block_header {
-    int16_t type;
-    int16_t count;
+typedef struct pst_block_header {
+    uint16_t type;
+    uint16_t count;
 } pst_block_header;
 
-typedef struct _pst_id2_assoc {
+typedef struct pst_id2_assoc32 {
     uint32_t id2;
     uint32_t id;
-    int32_t  table2;
+    uint32_t table2;
+} pst_id2_assoc32;
+
+typedef struct pst_id2_assoc {
+    uint64_t id2;
+    uint64_t id;
+    uint64_t table2;
 } pst_id2_assoc;
 
 // this is an array of the un-encrypted values. the un-encrypted value is in the position
 // of the encrypted value. ie the encrypted value 0x13 represents 0x02
 //                     0     1     2     3     4     5     6     7
 //                     8     9     a     b     c     d     e     f
-unsigned char comp_enc [] =
+static unsigned char comp_enc [] =
   { 0x47, 0xf1, 0xb4, 0xe6, 0x0b, 0x6a, 0x72, 0x48,
     0x85, 0x4e, 0x9e, 0xeb, 0xe2, 0xf8, 0x94, 0x53, /*0x0f*/
     0xe0, 0xbb, 0xa0, 0x02, 0xe8, 0x5a, 0x09, 0xab,
@@ -124,26 +129,8 @@
     0xed, 0x9a, 0x64, 0x3f, 0xc1, 0x6c, 0xf9, 0xec}; /*0xff*/
 
 
-void dump_desc(off_t off, int depth, int i, pst_descn *desc_rec ) {
-    //desc_rec->d_id = 0x0102030405060708;
-    DEBUG_INDEX(("%08x [%i] Item(%#x) = [d_id = %#llx, desc_id = %#llx, "
-        "list_id = %#llx, parent_id = %#x, u1 = %#x] %#x %p %p\n",
-        off,
-        depth, i, desc_rec->d_id,
-        desc_rec->desc_id, desc_rec->list_id, desc_rec->parent_id, desc_rec->u1));
-    DEBUG_HEXDUMPC( (char*)desc_rec, sizeof( pst_descn ), 0x10 );
-    DEBUG_INDEX(("WTF? %d %x %x %x %x %x\n",
-        sizeof( uint32_t ),
-        (int)(&desc_rec->d_id) - (int)desc_rec,
-        (int)(&desc_rec->desc_id) - (int)desc_rec,
-        (int)(&desc_rec->list_id) - (int)desc_rec,
-        (int)(&desc_rec->parent_id) - (int)desc_rec,
-        (int)(&desc_rec->u1) - (int)desc_rec ));
-}
-
-
-int32_t pst_open(pst_file *pf, char *name, char *mode) {
-    uint32_t sig;
+int pst_open(pst_file *pf, char *name, char *mode) {
+    int32_t sig;
 
     unicode_init();
 
@@ -154,7 +141,7 @@
         DEBUG_RET();
         return -1;
     }
-    memset(pf, 0, sizeof(pst_file));
+    memset(pf, 0, sizeof(*pf));
 
 #ifdef _MSC_VER
     // set the default open mode for windows
@@ -167,28 +154,28 @@
     }
 
     // Check pst file magic
-    if (fread(&sig, sizeof(sig), 1, pf->fp) == 0) {
-        fclose(pf->fp);
+    if (fread(&sig, sizeof(sig), (size_t)1, pf->fp) == 0) {
+        (void)fclose(pf->fp);
         WARN(("cannot read signature from PST file. Closing on error\n"));
         DEBUG_RET();
         return -1;
     }
     LE32_CPU(sig);
     DEBUG_INFO(("sig = %X\n", sig));
-    if (sig != PST_SIGNATURE) {
-        fclose(pf->fp);
+    if (sig != (int32_t)PST_SIGNATURE) {
+        (void)fclose(pf->fp);
         WARN(("not a PST file that I know. Closing with error\n"));
         DEBUG_RET();
         return -1;
     }
 
     // read index type
-    do_read64 = 0;  // start with 32 bit format
-    _pst_getAtPos(pf->fp, INDEX_TYPE_OFFSET, &(pf->ind_type), sizeof(unsigned char));
+    pf->do_read64 = 0;  // start with 32 bit format
+    (void)pst_getAtPos(pf->fp, INDEX_TYPE_OFFSET, &(pf->ind_type), sizeof(pf->ind_type));
     DEBUG_INFO(("index_type = %i\n", pf->ind_type));
     if (pf->ind_type != INDEX_TYPE) {
         // try with 64 bit format
-        do_read64 = 1;
+        pf->do_read64 = 1;
         if (pf->ind_type != INDEX_TYPE) {
             WARN(("unknown .pst format, possibly newer than Outlook 2003 PST file?\n"));
             DEBUG_RET();
@@ -200,24 +187,24 @@
     }
 
     // read encryption setting
-    _pst_getAtPos(pf->fp, ENC_OFFSET, &(pf->encryption), sizeof(unsigned char));
+    (void)pst_getAtPos(pf->fp, ENC_OFFSET, &(pf->encryption), sizeof(pf->encryption));
     DEBUG_INFO(("encrypt = %i\n", pf->encryption));
 
-    pf->index2_count = _pst_getIntAtPos(pf->fp, SECOND_COUNT);
-    pf->index2       = _pst_getIntAtPos(pf->fp, SECOND_POINTER );
-    pf->size         = _pst_getIntAtPos( pf->fp, FILE_SIZE_POINTER );
-    DEBUG_INFO(("Pointer2 is %#X, count %i[%#x]\n", pf->index2, pf->index2_count, pf->index2_count));
-
-    pf->index1_count = _pst_getIntAtPos(pf->fp, INDEX_COUNT);
-    pf->index1       = _pst_getIntAtPos(pf->fp, INDEX_POINTER);
-    DEBUG_INFO(("Pointer1 is %#X, count %i[%#x]\n", pf->index1, pf->index1_count, pf->index1_count));
+    pf->index2_back  = pst_getIntAtPos(pf, SECOND_BACK);
+    pf->index2       = pst_getIntAtPos(pf, SECOND_POINTER);
+    pf->size         = pst_getIntAtPos(pf, FILE_SIZE_POINTER);
+    DEBUG_INFO(("Pointer2 is %#llx, count %lli[%#llx]\n", pf->index2, pf->index2_back, pf->index2_back));
+
+    pf->index1_back  = pst_getIntAtPos(pf, INDEX_BACK);
+    pf->index1       = pst_getIntAtPos(pf, INDEX_POINTER);
+    DEBUG_INFO(("Pointer1 is %#llx, count %lli[%#llx]\n", pf->index1, pf->index1_back, pf->index1_back));
 
     DEBUG_RET();
     return 0;
 }
 
 
-int32_t pst_close(pst_file *pf) {
+int pst_close(pst_file *pf) {
     DEBUG_ENT("pst_close");
     if (!pf->fp) {
         WARN(("cannot close NULL fp\n"));
@@ -230,9 +217,9 @@
         return -1;
     }
     // we must free the id linklist and the desc tree
-    _pst_free_id (pf->i_head);
-    _pst_free_desc (pf->d_head);
-    _pst_free_xattrib (pf->x_head);
+    pst_free_id (pf->i_head);
+    pst_free_desc (pf->d_head);
+    pst_free_xattrib (pf->x_head);
     DEBUG_RET();
     return 0;
 }
@@ -247,24 +234,24 @@
     } else if (!root->message_store->top_of_personal_folder) {
         // this is the OST way
         // ASSUMPTION: Top Of Folders record in PST files is *always* descid 0x2142
-        ret = _pst_getDptr(pf, 0x2142);
+        ret = pst_getDptr(pf, (uint64_t)0x2142);
     } else {
-        ret = _pst_getDptr(pf, root->message_store->top_of_personal_folder->id);
+        ret = pst_getDptr(pf, root->message_store->top_of_personal_folder->id);
     }
     DEBUG_RET();
     return ret;
 }
 
 
-int32_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b){
-    int32_t size=0;
+size_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b){
+    size_t size=0;
     pst_index_ll *ptr;
     struct holder h = {b, NULL, 0, "", 0};
     DEBUG_ENT("pst_attach_to_mem");
-    if (attach->id_val != -1) {
-        ptr = _pst_getID(pf, attach->id_val);
+    if (attach->id_val != (uint64_t)-1) {
+        ptr = pst_getID(pf, attach->id_val);
         if (ptr) {
-            size = _pst_ff_getID2data(pf, ptr, &h);
+            size = pst_ff_getID2data(pf, ptr, &h);
         } else {
             DEBUG_WARN(("Couldn't find ID pointer. Cannot handle attachment\n"));
             size = 0;
@@ -278,15 +265,15 @@
 }
 
 
-int32_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) {
+size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp) {
     pst_index_ll *ptr;
     struct holder h = {NULL, fp, 0, "", 0};
-    int32_t size;
+    size_t size;
     DEBUG_ENT("pst_attach_to_file");
-    if (attach->id_val != -1) {
-        ptr = _pst_getID(pf, attach->id_val);
+    if (attach->id_val != (uint64_t)-1) {
+        ptr = pst_getID(pf, attach->id_val);
         if (ptr) {
-            size = _pst_ff_getID2data(pf, ptr, &h);
+            size = pst_ff_getID2data(pf, ptr, &h);
         } else {
             DEBUG_WARN(("Couldn't find ID pointer. Cannot save attachment to file\n"));
             size = 0;
@@ -295,27 +282,27 @@
     } else {
         // save the attachment to file
         size = attach->size;
-        pst_fwrite(attach->data, 1, size, fp);
+        (void)pst_fwrite(attach->data, (size_t)1, size, fp);
     }
     DEBUG_RET();
-    return 1;
+    return size;
 }
 
 
-int32_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp) {
+size_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp) {
     pst_index_ll *ptr;
     struct holder h = {NULL, fp, 1, "", 0};
-    int32_t size;
+    size_t size;
     char *c;
     DEBUG_ENT("pst_attach_to_file_base64");
-    if (attach->id_val != -1) {
-        ptr = _pst_getID(pf, attach->id_val);
+    if (attach->id_val != (uint64_t)-1) {
+        ptr = pst_getID(pf, attach->id_val);
         if (ptr) {
-            size = _pst_ff_getID2data(pf, ptr, &h);
+            size = pst_ff_getID2data(pf, ptr, &h);
             // will need to encode any bytes left over
-            c = base64_encode(h.base64_extra_chars, h.base64_extra);
+            c = base64_encode(h.base64_extra_chars, (size_t)h.base64_extra);
             if (c) {
-                pst_fwrite(c, 1, strlen(c), fp);
+                (void)pst_fwrite(c, (size_t)1, strlen(c), fp);
                 free(c);    // caught by valgrind
             }
         } else {
@@ -327,18 +314,18 @@
         // encode the attachment to the file
         c = base64_encode(attach->data, attach->size);
         if (c) {
-            pst_fwrite(c, 1, strlen(c), fp);
+            (void)pst_fwrite(c, (size_t)1, strlen(c), fp);
             free(c);    // caught by valgrind
         }
         size = attach->size;
     }
     DEBUG_RET();
-    return 1;
+    return size;
 }
 
 
-int32_t pst_load_index (pst_file *pf) {
-    int32_t  x;
+int pst_load_index (pst_file *pf) {
+    int  x;
     uint64_t y;
     DEBUG_ENT("pst_load_index");
     if (!pf) {
@@ -347,14 +334,14 @@
         return -1;
     }
 
-    x = _pst_build_id_ptr(pf, pf->index1, 0, pf->index1_count, 0, UINT64_MAX);
+    x = pst_build_id_ptr(pf, pf->index1, 0, pf->index1_back, 0, UINT64_MAX);
     DEBUG_INDEX(("build id ptr returns %i\n", x));
 
     y = 0;
-    x = _pst_build_desc_ptr(pf, pf->index2, 0, pf->index2_count, &y, 0x21, UINT64_MAX);
+    x = pst_build_desc_ptr(pf, pf->index2, 0, pf->index2_back, &y, (uint64_t)0x21, UINT64_MAX);
     DEBUG_INDEX(("build desc ptr returns %i\n", x));
 
-    DEBUG_CODE(_pst_printDptr(pf););
+    DEBUG_CODE((void)pst_printDptr(pf););
     DEBUG_RET();
     return 0;
 }
@@ -374,7 +361,7 @@
 }
 
 
-typedef struct _pst_x_attrib {
+typedef struct pst_x_attrib {
     uint16_t extended;
     uint16_t zero;
     uint16_t type;
@@ -382,18 +369,19 @@
 } pst_x_attrib;
 
 
-int32_t pst_load_extended_attributes(pst_file *pf) {
+int pst_load_extended_attributes(pst_file *pf) {
     // for PST files this will load up ID2 0x61 and check it's "list" attribute.
     pst_desc_ll *p;
     pst_num_array *na;
-    pst_index2_ll *list2 = NULL;
-    unsigned char * buffer=NULL, *headerbuffer=NULL;//, *tc;
+    pst_index2_ll *id2_head = NULL;
+    unsigned char *buffer=NULL, *headerbuffer=NULL;
+    size_t bsize=0, hsize=0, bptr=0;
     pst_x_attrib xattrib;
-    int32_t bptr = 0, bsize, hsize, tint, err=0, x;
+    int32_t tint, err=0, x;
     pst_x_attrib_ll *ptr, *p_head=NULL, *p_sh=NULL, *p_sh2=NULL;
 
     DEBUG_ENT("pst_loadExtendedAttributes");
-    if ((p = _pst_getDptr(pf, 0x61)) == NULL) {
+    if ((p = pst_getDptr(pf, (uint64_t)0x61)) == NULL) {
         DEBUG_WARN(("Cannot find DescID 0x61 for loading the Extended Attributes\n"));
         DEBUG_RET();
         return 0;
@@ -406,34 +394,36 @@
     }
 
     if (p->list_index) {
-        list2 = _pst_build_id2(pf, p->list_index, NULL);
-        _pst_printID2ptr(list2);
+        id2_head = pst_build_id2(pf, p->list_index, NULL);
+        (void)pst_printID2ptr(id2_head);
     } else {
         DEBUG_WARN(("Have not been able to fetch any id2 values for item 0x61. Brace yourself!\n"));
     }
 
-    na = _pst_parse_block(pf, p->desc->id, list2);
+    na = pst_parse_block(pf, p->desc->id, id2_head);
     if (!na) {
         DEBUG_WARN(("Cannot process desc block for item 0x61. Not loading extended Attributes\n"));
-        if (list2) _pst_free_id2(list2);
+        if (id2_head) pst_free_id2(id2_head);
         DEBUG_RET();
         return 0;
     }
 
     x = 0;
     while (x < na->count_item) {
-        if (na->items[x]->id == 0x0003) {
+        if (na->items[x]->id == (uint32_t)0x0003) {
             buffer = na->items[x]->data;
             bsize = na->items[x]->size;
-        } else if (na->items[x]->id == 0x0004) {
+        } else if (na->items[x]->id == (uint32_t)0x0004) {
             headerbuffer = na->items[x]->data;
             hsize = na->items[x]->size;
+        } else {
+            // leave them null
         }
         x++;
     }
 
     if (!buffer) {
-        if (na) _pst_free_list(na);
+        if (na) pst_free_list(na);
         DEBUG_WARN(("No extended attributes buffer found. Not processing\n"));
         DEBUG_RET();
         return 0;
@@ -447,10 +437,10 @@
     bptr += sizeof(xattrib);
 
     while (xattrib.type != 0 && bptr < bsize) {
-        ptr = (pst_x_attrib_ll*) xmalloc(sizeof(pst_x_attrib_ll));
-        memset(ptr, 0, sizeof(pst_x_attrib_ll));
+        ptr = (pst_x_attrib_ll*) xmalloc(sizeof(*ptr));
+        memset(ptr, 0, sizeof(*ptr));
         ptr->type = xattrib.type;
-        ptr->map = xattrib.map+0x8000;
+        ptr->map  = xattrib.map+0x8000;
         ptr->next = NULL;
         DEBUG_INDEX(("xattrib: ext = %#hx, zero = %#hx, type = %#hx, map = %#hx\n",
              xattrib.extended, xattrib.zero, xattrib.type, xattrib.map));
@@ -462,10 +452,10 @@
                 // copy the size of the header. It is 32 bit int
                 memcpy(&tint, &(headerbuffer[xattrib.extended]), sizeof(tint));
                 LE32_CPU(tint);
-                wt = (char*) xmalloc(tint+2); // plus 2 for a uni-code zero
-                memset(wt, 0, tint+2);
-                memcpy(wt, &(headerbuffer[xattrib.extended+sizeof(tint)]), tint);
-                ptr->data = _pst_wide_to_single(wt, tint);
+                wt = (char*) xmalloc((size_t)(tint+2)); // plus 2 for a uni-code zero
+                memset(wt, 0, (size_t)(tint+2));
+                memcpy(wt, &(headerbuffer[xattrib.extended+sizeof(tint)]), (size_t)tint);
+                ptr->data = pst_wide_to_single(wt, tint);
                 free(wt);
                 DEBUG_INDEX(("Read string (converted from UTF-16): %s\n", ptr->data));
             } else {
@@ -474,9 +464,9 @@
             ptr->mytype = PST_MAP_HEADER;
         } else {
             // contains the attribute code to map to.
-            ptr->data = (int*)xmalloc(sizeof(int32_t));
-            memset(ptr->data, 0, sizeof(int32_t));
-            *((int32_t*)ptr->data) = xattrib.extended;
+            ptr->data = (uint32_t*)xmalloc(sizeof(uint32_t));
+            memset(ptr->data, 0, sizeof(uint32_t));
+            *((uint32_t*)ptr->data) = xattrib.extended;
             ptr->mytype = PST_MAP_ATTRIB;
             DEBUG_INDEX(("Mapped attribute %#x to %#x\n", ptr->map, *((int32_t*)ptr->data)));
         }
@@ -509,8 +499,8 @@
         LE16_CPU(xattrib.map);
         bptr += sizeof(xattrib);
     }
-    if (list2) _pst_free_id2(list2);
-    if (na)    _pst_free_list(na);
+    if (id2_head) pst_free_id2(id2_head);
+    if (na)       pst_free_list(na);
     pf->x_head = p_head;
     DEBUG_RET();
     return 1;
@@ -536,20 +526,21 @@
 #define INDEX_COUNT_MAX64          20       // max active items
 #define DESC_COUNT_MAX64           15       // max active items
 
-#define BLOCK_SIZE               ((do_read64) ? BLOCK_SIZE64             : BLOCK_SIZE32)
-#define DESC_BLOCK_SIZE          ((do_read64) ? DESC_BLOCK_SIZE64        : DESC_BLOCK_SIZE32)
-#define ITEM_COUNT_OFFSET        ((do_read64) ? ITEM_COUNT_OFFSET64      : ITEM_COUNT_OFFSET32)
-#define LEVEL_INDICATOR_OFFSET   ((do_read64) ? LEVEL_INDICATOR_OFFSET64 : LEVEL_INDICATOR_OFFSET32)
-#define BACKLINK_OFFSET          ((do_read64) ? BACKLINK_OFFSET64        : BACKLINK_OFFSET32)
-#define ITEM_SIZE                ((do_read64) ? ITEM_SIZE64              : ITEM_SIZE32)
-#define DESC_SIZE                ((do_read64) ? DESC_SIZE64              : DESC_SIZE32)
-#define INDEX_COUNT_MAX          ((do_read64) ? INDEX_COUNT_MAX64        : INDEX_COUNT_MAX32)
-#define DESC_COUNT_MAX           ((do_read64) ? DESC_COUNT_MAX64         : DESC_COUNT_MAX32)
-
-
-int _pst_decode_desc( pst_descn *desc, char *buf ) {
-    int r;
-    if (do_read64) {
+#define BLOCK_SIZE               (size_t)((pf->do_read64) ? BLOCK_SIZE64             : BLOCK_SIZE32)
+#define DESC_BLOCK_SIZE          (size_t)((pf->do_read64) ? DESC_BLOCK_SIZE64        : DESC_BLOCK_SIZE32)
+#define ITEM_COUNT_OFFSET        (size_t)((pf->do_read64) ? ITEM_COUNT_OFFSET64      : ITEM_COUNT_OFFSET32)
+#define LEVEL_INDICATOR_OFFSET   (size_t)((pf->do_read64) ? LEVEL_INDICATOR_OFFSET64 : LEVEL_INDICATOR_OFFSET32)
+#define BACKLINK_OFFSET          (size_t)((pf->do_read64) ? BACKLINK_OFFSET64        : BACKLINK_OFFSET32)
+#define ITEM_SIZE                (size_t)((pf->do_read64) ? ITEM_SIZE64              : ITEM_SIZE32)
+#define DESC_SIZE                (size_t)((pf->do_read64) ? DESC_SIZE64              : DESC_SIZE32)
+#define INDEX_COUNT_MAX         (int32_t)((pf->do_read64) ? INDEX_COUNT_MAX64        : INDEX_COUNT_MAX32)
+#define DESC_COUNT_MAX          (int32_t)((pf->do_read64) ? DESC_COUNT_MAX64         : DESC_COUNT_MAX32)
+
+
+static size_t pst_decode_desc(pst_file *pf, pst_descn *desc, char *buf);
+static size_t pst_decode_desc(pst_file *pf, pst_descn *desc, char *buf) {
+    size_t r;
+    if (pf->do_read64) {
         DEBUG_INDEX(("Decoding desc64\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_descn), 0x10);
         memcpy(desc, buf, sizeof(pst_descn));
@@ -580,37 +571,39 @@
 }
 
 
-int _pst_decode_table( struct _pst_table_ptr_structn *table, char *buf ) {
-    int r;
-    if (do_read64) {
+static size_t pst_decode_table(pst_file *pf, struct pst_table_ptr_structn *table, char *buf);
+static size_t pst_decode_table(pst_file *pf, struct pst_table_ptr_structn *table, char *buf) {
+    size_t r;
+    if (pf->do_read64) {
         DEBUG_INDEX(("Decoding table64\n"));
-        DEBUG_HEXDUMPC(buf, sizeof(struct _pst_table_ptr_structn), 0x10);
-        memcpy(table, buf, sizeof(struct _pst_table_ptr_structn));
+        DEBUG_HEXDUMPC(buf, sizeof(struct pst_table_ptr_structn), 0x10);
+        memcpy(table, buf, sizeof(struct pst_table_ptr_structn));
         LE64_CPU(table->start);
         LE64_CPU(table->u1);
         LE64_CPU(table->offset);
-        r =sizeof(struct _pst_table_ptr_structn);
+        r =sizeof(struct pst_table_ptr_structn);
     }
     else {
-        struct _pst_table_ptr_struct32 t32;
+        struct pst_table_ptr_struct32 t32;
         DEBUG_INDEX(("Decoding table32\n"));
-        DEBUG_HEXDUMPC(buf, sizeof( struct _pst_table_ptr_struct32), 0x10);
-        memcpy(&t32, buf, sizeof(struct _pst_table_ptr_struct32));
+        DEBUG_HEXDUMPC(buf, sizeof( struct pst_table_ptr_struct32), 0x10);
+        memcpy(&t32, buf, sizeof(struct pst_table_ptr_struct32));
         LE32_CPU(t32.start);
         LE32_CPU(t32.u1);
         LE32_CPU(t32.offset);
         table->start  = t32.start;
         table->u1     = t32.u1;
         table->offset = t32.offset;
-        r = sizeof(struct _pst_table_ptr_struct32);
+        r = sizeof(struct pst_table_ptr_struct32);
     }
     return r;
 }
 
 
-int _pst_decode_index( pst_index *index, char *buf ) {
-    int r;
-    if (do_read64) {
+static size_t pst_decode_index(pst_file *pf, pst_index *index, char *buf);
+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_HEXDUMPC(buf, sizeof(pst_index), 0x10);
         memcpy(index, buf, sizeof(pst_index));
@@ -625,10 +618,10 @@
         DEBUG_INDEX(("Decoding index32\n"));
         DEBUG_HEXDUMPC(buf, sizeof(pst_index32), 0x10);
         memcpy(&index32, buf, sizeof(pst_index32));
-        LE32_CPU(index32->id);
-        LE32_CPU(index32->offset);
-        LE16_CPU(index32->size);
-        LE16_CPU(index32->u1);
+        LE32_CPU(index32.id);
+        LE32_CPU(index32.offset);
+        LE16_CPU(index32.size);
+        LE16_CPU(index32.u1);
         index->id     = index32.id;
         index->offset = index32.offset;
         index->size   = index32.size;
@@ -639,15 +632,43 @@
 }
 
 
-int32_t _pst_build_id_ptr(pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t start_val, uint64_t end_val) {
-    struct _pst_table_ptr_structn table, table2;
+static size_t pst_decode_assoc(pst_file *pf, pst_id2_assoc *assoc, char *buf);
+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_HEXDUMPC(buf, sizeof(pst_id2_assoc), 0x10);
+        memcpy(assoc, buf, sizeof(pst_id2_assoc));
+        LE64_CPU(assoc->id2);
+        LE64_CPU(assoc->id);
+        LE64_CPU(assoc->table2);
+        r = sizeof(pst_id2_assoc);
+    } else {
+        pst_id2_assoc32 assoc32;
+        DEBUG_INDEX(("Decoding assoc32\n"));
+        DEBUG_HEXDUMPC(buf, sizeof(pst_id2_assoc32), 0x10);
+        memcpy(&assoc32, buf, sizeof(pst_id2_assoc32));
+        LE32_CPU(assoc32.id2);
+        LE32_CPU(assoc32.id);
+        LE32_CPU(assoc32.table2);
+        assoc->id2    = assoc32.id2;
+        assoc->id     = assoc32.id;
+        assoc->table2 = assoc32.table2;
+        r = sizeof(pst_id2_assoc32);
+    }
+    return r;
+}
+
+
+int pst_build_id_ptr(pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val) {
+    struct pst_table_ptr_structn table, table2;
     pst_index_ll *i_ptr=NULL;
     pst_index index;
     int32_t x, item_count;
     uint64_t old = start_val;
     char *buf = NULL, *bptr;
 
-    DEBUG_ENT("_pst_build_id_ptr");
+    DEBUG_ENT("pst_build_id_ptr");
     DEBUG_INDEX(("offset %x depth %i linku1 %llx start %llx end %llx\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:%#llx, end:%#llx]\n", start_val, end_val));
@@ -655,7 +676,7 @@
         return -1;
     }
     DEBUG_INDEX(("Reading index block\n"));
-    if (_pst_read_block_size(pf, offset, BLOCK_SIZE, &buf, 0, 0) < BLOCK_SIZE) {
+    if (pst_read_block_size(pf, offset, BLOCK_SIZE, &buf, 0, 0) < BLOCK_SIZE) {
         DEBUG_WARN(("Failed to read %i bytes\n", BLOCK_SIZE));
         if (buf) free(buf);
         DEBUG_RET();
@@ -663,14 +684,14 @@
     }
     bptr = buf;
     DEBUG_HEXDUMPC(buf, BLOCK_SIZE, ITEM_SIZE32);
-    item_count = (int)(unsigned)(buf[ITEM_COUNT_OFFSET]);
+    item_count = (int32_t)(unsigned)(buf[ITEM_COUNT_OFFSET]);
     if (item_count > INDEX_COUNT_MAX) {
         DEBUG_WARN(("Item count %i too large, max is %i\n", item_count, INDEX_COUNT_MAX));
         if (buf) free(buf);
         DEBUG_RET();
         return -1;
     }
-    index.id = _getIntAt(buf+BACKLINK_OFFSET);
+    index.id = pst_getIntAt(pf, buf+BACKLINK_OFFSET);
     if (index.id != linku1) {
         DEBUG_WARN(("Backlink %#llx in this node does not match required %#llx\n", index.id, linku1));
         if (buf) free(buf);
@@ -682,10 +703,10 @@
         // this node contains leaf pointers
         x = 0;
         while (x < item_count) {
-            bptr += _pst_decode_index(&index, bptr);
+            bptr += pst_decode_index(pf, &index, bptr);
             x++;
             if (index.id == 0) break;
-            DEBUG_INDEX(("[%i]%i Item [id = %#x, offset = %#x, u1 = %#x, size = %i(%#x)]\n",
+            DEBUG_INDEX(("[%i]%i Item [id = %#llx, offset = %#llx, 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 >= end_val) || (index.id < old)) {
@@ -695,7 +716,7 @@
                 return -1;
             }
             old = index.id;
-            if (x == 1) {   // first entry
+            if (x == (int32_t)1) {   // first entry
                 if ((start_val) && (index.id != start_val)) {
                     DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n"));
                     if (buf) free(buf);
@@ -717,16 +738,16 @@
         // this node contains node pointers
         x = 0;
         while (x < item_count) {
-            bptr += _pst_decode_table(&table, bptr);
+            bptr += pst_decode_table(pf, &table, bptr);
             x++;
             if (table.start == 0) break;
             if (x < item_count) {
-                _pst_decode_table(&table2, bptr);
+                (void)pst_decode_table(pf, &table2, bptr);
             }
             else {
                 table2.start = end_val;
             }
-            DEBUG_INDEX(("[%i] %i Index Table [start id = %#x, u1 = %#x, offset = %#x, end id = %#x]\n",
+            DEBUG_INDEX(("[%i] %i Index Table [start id = %#llx, u1 = %#llx, offset = %#llx, end id = %#llx]\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"));
@@ -735,7 +756,7 @@
                 return -1;
             }
             old = table.start;
-            if (x == 1) {   // first entry
+            if (x == (int32_t)1) {  // first entry
                 if ((start_val) && (table.start != start_val)) {
                     DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n"));
                     if (buf) free(buf);
@@ -743,7 +764,7 @@
                     return -1;
                 }
             }
-            _pst_build_id_ptr(pf, table.offset, depth+1, table.u1, table.start, table2.start);
+            (void)pst_build_id_ptr(pf, table.offset, depth+1, table.u1, table.start, table2.start);
         }
     }
     if (buf) free (buf);
@@ -765,16 +786,17 @@
     struct cache_list_node *next;
     struct cache_list_node *prev;
 };
-struct cache_list_node *cache_head;
-struct cache_list_node *cache_tail;
-struct cache_list_node *lostfound_head;
-int32_t cache_count;
+static struct cache_list_node *cache_head;
+static struct cache_list_node *cache_tail;
+static struct cache_list_node *lostfound_head;
+static int cache_count;
 
 
 /**
     add the d_ptr descriptor into the global tree
 */
-void record_descriptor(pst_file *pf, pst_desc_ll *d_ptr, uint64_t parent_id) {
+static void record_descriptor(pst_file *pf, pst_desc_ll *d_ptr, uint64_t parent_id);
+static void record_descriptor(pst_file *pf, pst_desc_ll *d_ptr, uint64_t parent_id) {
     struct cache_list_node *lostfound_ptr = NULL;
     struct cache_list_node *cache_ptr     = NULL;
     pst_desc_ll            *parent        = NULL;
@@ -797,14 +819,14 @@
         while (cache_ptr && (cache_ptr->ptr->id != parent_id)) {
             cache_ptr = cache_ptr->next;
         }
-        if (!cache_ptr && (parent = _pst_getDptr(pf, parent_id)) == NULL) {
+        if (!cache_ptr && (parent = pst_getDptr(pf, parent_id)) == NULL) {
             // check in the lost/found list
             lostfound_ptr = lostfound_head;
             while (lostfound_ptr && (lostfound_ptr->ptr->id != parent_id)) {
                 lostfound_ptr = lostfound_ptr->next;
             }
             if (!lostfound_ptr) {
-                DEBUG_WARN(("ERROR -- cannot find parent with id %#x. Adding to lost/found\n", parent_id));
+                DEBUG_WARN(("ERROR -- cannot find parent with id %#llx. Adding to lost/found\n", parent_id));
                 lostfound_ptr = (struct cache_list_node*) xmalloc(sizeof(struct cache_list_node));
                 lostfound_ptr->prev   = NULL;
                 lostfound_ptr->next   = lostfound_head;
@@ -813,7 +835,7 @@
                 lostfound_head = lostfound_ptr;
             } else {
                 parent = lostfound_ptr->ptr;
-                DEBUG_INDEX(("Found parent (%#x) in Lost and Found\n", parent->id));
+                DEBUG_INDEX(("Found parent (%#llx) in Lost and Found\n", parent->id));
             }
         }
 
@@ -851,8 +873,8 @@
     }
 }
 
-int32_t _pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t *high_id, uint64_t start_val, uint64_t end_val) {
-    struct _pst_table_ptr_structn table, table2;
+int pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t *high_id, uint64_t start_val, uint64_t end_val) {
+    struct pst_table_ptr_structn table, table2;
     pst_descn desc_rec;
     pst_desc_ll *d_ptr=NULL, *parent=NULL;
     int32_t x, item_count;
@@ -871,26 +893,26 @@
         cache_count    = 0;
     }
 
-    DEBUG_ENT("_pst_build_desc_ptr");
-    DEBUG_INDEX(("offset %x depth %i linku1 %x start %x end %x\n", offset, depth, linku1, start_val, end_val));
+    DEBUG_ENT("pst_build_desc_ptr");
+    DEBUG_INDEX(("offset %llx depth %i linku1 %llx start %llx end %llx\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:%#x, end:%#x]\n", start_val, end_val));
+        DEBUG_WARN(("The end value is BEFORE the start value. This function will quit. Soz. [start:%#llx, end:%#llx]\n", start_val, end_val));
         DEBUG_RET();
         return -1;
     }
     DEBUG_INDEX(("Reading desc block\n"));
-    if (_pst_read_block_size(pf, offset, DESC_BLOCK_SIZE, &buf, 0, 0) < DESC_BLOCK_SIZE) {
+    if (pst_read_block_size(pf, offset, DESC_BLOCK_SIZE, &buf, 0, 0) < DESC_BLOCK_SIZE) {
         DEBUG_WARN(("Failed to read %i bytes\n", DESC_BLOCK_SIZE));
         if (buf) free(buf);
         DEBUG_RET();
         return -1;
     }
     bptr = buf;
-    item_count = (int)(unsigned)(buf[ITEM_COUNT_OFFSET]);
-
-    desc_rec.d_id = _getIntAt(buf+BACKLINK_OFFSET);
+    item_count = (int32_t)(unsigned)(buf[ITEM_COUNT_OFFSET]);
+
+    desc_rec.d_id = pst_getIntAt(pf, buf+BACKLINK_OFFSET);
     if (desc_rec.d_id != linku1) {
-        DEBUG_WARN(("Backlink %#x in this node does not match required %#x\n", desc_rec.d_id, linku1));
+        DEBUG_WARN(("Backlink %#llx in this node does not match required %#llx\n", desc_rec.d_id, linku1));
         if (buf) free(buf);
         DEBUG_RET();
         return -1;
@@ -906,10 +928,10 @@
         }
         x = 0;
         while (x < item_count) {
-            bptr += _pst_decode_desc(&desc_rec, bptr);
+            bptr += pst_decode_desc(pf, &desc_rec, bptr);
             x++;
             if (desc_rec.d_id == 0) break;
-            DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#x, desc_id = %#x, list_id = %#x, parent_id = %#x]\n",
+            DEBUG_INDEX(("[%i] Item(%#x) = [d_id = %#llx, desc_id = %#llx, list_id = %#llx, parent_id = %#x]\n",
                         depth, x, desc_rec.d_id, desc_rec.desc_id, desc_rec.list_id, desc_rec.parent_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"));
@@ -919,7 +941,7 @@
                 return -1;
             }
             old = desc_rec.d_id;
-            if (x == 1) {   // first entry
+            if (x == (int32_t)1) {   // first entry
                 if (start_val && (desc_rec.d_id != start_val)) {
                     DEBUG_WARN(("This item isn't right. Must be corruption, or I got it wrong!\n"));
                     if (buf) free(buf);
@@ -929,13 +951,13 @@
             }
             // When duplicates found, just update the info.... perhaps this is correct functionality
             DEBUG_INDEX(("Searching for existing record\n"));
-            if (desc_rec.d_id <= *high_id && (d_ptr = _pst_getDptr(pf, desc_rec.d_id))) {
+            if (desc_rec.d_id <= *high_id && (d_ptr = pst_getDptr(pf, desc_rec.d_id))) {
                 DEBUG_INDEX(("Updating Existing Values\n"));
-                d_ptr->list_index = _pst_getID(pf, desc_rec.list_id);
-                d_ptr->desc = _pst_getID(pf, desc_rec.desc_id);
-                DEBUG_INDEX(("\tdesc = %#x\tlist_index=%#x\n",
-                        (d_ptr->desc==NULL?0:d_ptr->desc->id),
-                        (d_ptr->list_index==NULL?0:d_ptr->list_index->id)));
+                d_ptr->list_index = pst_getID(pf, desc_rec.list_id);
+                d_ptr->desc = pst_getID(pf, desc_rec.desc_id);
+                DEBUG_INDEX(("\tdesc = %#llx\tlist_index=%#llx\n",
+                        (d_ptr->desc==NULL?0LL:d_ptr->desc->id),
+                        (d_ptr->list_index==NULL?0LL:d_ptr->list_index->id)));
                 if (d_ptr->parent && desc_rec.parent_id != d_ptr->parent->id) {
                     DEBUG_INDEX(("WARNING -- Parent of record has changed. Moving it\n"));
                     //hmmm, we must move the record.
@@ -973,8 +995,8 @@
                 DEBUG_INDEX(("New Record\n"));
                 d_ptr             = (pst_desc_ll*) xmalloc(sizeof(pst_desc_ll));
                 d_ptr->id         = desc_rec.d_id;
-                d_ptr->list_index = _pst_getID(pf, desc_rec.list_id);
-                d_ptr->desc       = _pst_getID(pf, desc_rec.desc_id);
+                d_ptr->list_index = pst_getID(pf, desc_rec.list_id);
+                d_ptr->desc       = pst_getID(pf, desc_rec.desc_id);
                 d_ptr->prev       = NULL;
                 d_ptr->next       = NULL;
                 d_ptr->parent     = NULL;
@@ -989,7 +1011,7 @@
             lostfound_shd = NULL;
             while (lostfound_ptr) {
                 if (lostfound_ptr->parent == d_ptr->id) {
-                    DEBUG_INDEX(("Found a child  (%#x) of the current record. Joining to main structure.\n", lostfound_ptr->ptr->id));
+                    DEBUG_INDEX(("Found a child  (%#llx) of the current record. Joining to main structure.\n", lostfound_ptr->ptr->id));
                     parent = d_ptr;
                     d_ptr = lostfound_ptr->ptr;
                     parent->no_child++;
@@ -1020,16 +1042,16 @@
         }
         x = 0;
         while (x < item_count) {
-            bptr += _pst_decode_table(&table, bptr);
+            bptr += pst_decode_table(pf, &table, bptr);
             x++;
             if (table.start == 0) break;
             if (x < item_count) {
-                _pst_decode_table(&table2, bptr);
+                (void)pst_decode_table(pf, &table2, bptr);
             }
             else {
                 table2.start = end_val;
             }
-            DEBUG_INDEX(("[%i] %i Descriptor Table [start id = %#x, u1 = %#x, offset = %#x, end id = %#x]\n",
+            DEBUG_INDEX(("[%i] %i Descriptor Table [start id = %#llx, u1 = %#llx, offset = %#llx, end id = %#llx]\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"));
@@ -1038,15 +1060,15 @@
                 return -1;
             }
             old = table.start;
-            if (x == 1) {   // first entry
-                if (start_val != -1 && table.start != start_val) {
+            if (x == (int32_t)1) {   // first entry
+                if (start_val && (table.start != start_val)) {
                     DEBUG_WARN(("This table isn't right. Must be corruption, or I got it wrong!\n"));
                     if (buf) free(buf);
                     DEBUG_RET();
                     return -1;
                 }
             }
-            _pst_build_desc_ptr(pf, table.offset, depth+1, table.u1, high_id, table.start, table2.start);
+            (void)pst_build_desc_ptr(pf, table.offset, depth+1, table.u1, high_id, table.start, table2.start);
         }
     }
     if (depth == 0) {
@@ -1059,7 +1081,7 @@
         // free the lost and found
         while (lostfound_head) {
             lostfound_ptr = lostfound_head->next;
-            WARN(("unused lost/found item with parent %d))", lostfound_head->parent));
+            WARN(("unused lost/found item with parent %lld))", lostfound_head->parent));
             free(lostfound_head);
             lostfound_head = lostfound_ptr;
         }
@@ -1070,14 +1092,14 @@
 }
 
 
-pst_item* _pst_parse_item(pst_file *pf, pst_desc_ll *d_ptr) {
+pst_item* pst_parse_item(pst_file *pf, pst_desc_ll *d_ptr) {
     pst_num_array * list;
     pst_index2_ll *id2_head = NULL;
     pst_index_ll *id_ptr = NULL;
     pst_item *item = NULL;
     pst_item_attach *attach = NULL;
-    int x;
-    DEBUG_ENT("_pst_parse_item");
+    int32_t x;
+    DEBUG_ENT("pst_parse_item");
     if (!d_ptr) {
         DEBUG_WARN(("you cannot pass me a NULL! I don't want it!\n"));
         DEBUG_RET();
@@ -1091,16 +1113,16 @@
     }
 
     if (d_ptr->list_index) {
-        id2_head = _pst_build_id2(pf, d_ptr->list_index, NULL);
-        _pst_printID2ptr(id2_head);
+        id2_head = pst_build_id2(pf, d_ptr->list_index, NULL);
+        (void)pst_printID2ptr(id2_head);
     } else {
         DEBUG_WARN(("Have not been able to fetch any id2 values for this item. Brace yourself!\n"));
     }
 
-    list = _pst_parse_block(pf, d_ptr->desc->id, id2_head);
+    list = pst_parse_block(pf, d_ptr->desc->id, id2_head);
     if (!list) {
-        DEBUG_WARN(("_pst_parse_block() returned an error for d_ptr->desc->id [%#x]\n", d_ptr->desc->id));
-        if (id2_head) _pst_free_id2(id2_head);
+        DEBUG_WARN(("pst_parse_block() returned an error for d_ptr->desc->id [%#llx]\n", d_ptr->desc->id));
+        if (id2_head) pst_free_id2(id2_head);
         DEBUG_RET();
         return NULL;
     }
@@ -1108,18 +1130,18 @@
     item = (pst_item*) xmalloc(sizeof(pst_item));
     memset(item, 0, sizeof(pst_item));
 
-    if (_pst_process(list, item, NULL)) {
-        DEBUG_WARN(("_pst_process() returned non-zero value. That is an error\n"));
-        if (item)     _pst_freeItem(item);
-        if (list)     _pst_free_list(list);
-        if (id2_head) _pst_free_id2(id2_head);
+    if (pst_process(list, item, NULL)) {
+        DEBUG_WARN(("pst_process() returned non-zero value. That is an error\n"));
+        if (item)     pst_freeItem(item);
+        if (list)     pst_free_list(list);
+        if (id2_head) pst_free_id2(id2_head);
         DEBUG_RET();
         return NULL;
     }
-    if (list) _pst_free_list(list);
-    list = NULL; //_pst_process will free the items in the list
-
-    if ((id_ptr = _pst_getID2(id2_head, 0x671))) {
+    if (list) pst_free_list(list);
+    list = NULL; //pst_process will free the items in the list
+
+    if ((id_ptr = pst_getID2(id2_head, (uint64_t)0x671))) {
         // attachments exist - so we will process them
         while (item->attach) {
             attach = item->attach->next;
@@ -1128,10 +1150,10 @@
         }
 
         DEBUG_EMAIL(("ATTACHMENT processing attachment\n"));
-        if ((list = _pst_parse_block(pf, id_ptr->id, id2_head)) == NULL) {
+        if ((list = pst_parse_block(pf, id_ptr->id, id2_head)) == NULL) {
             DEBUG_WARN(("ERROR error processing main attachment record\n"));
-            if (item) _pst_freeItem(item);
-            if (id2_head) _pst_free_id2(id2_head);
+            if (item) pst_freeItem(item);
+            if (id2_head) pst_free_id2(id2_head);
             DEBUG_RET();
             return NULL;
         }
@@ -1145,15 +1167,15 @@
                 x++;
             }
 
-            if (_pst_process(list, item, item->attach)) {
-                DEBUG_WARN(("ERROR _pst_process() failed with attachments\n"));
-                if (item)     _pst_freeItem(item);
-                if (list)     _pst_free_list(list);
-                if (id2_head) _pst_free_id2(id2_head);
+            if (pst_process(list, item, item->attach)) {
+                DEBUG_WARN(("ERROR pst_process() failed with attachments\n"));
+                if (item)     pst_freeItem(item);
+                if (list)     pst_free_list(list);
+                if (id2_head) pst_free_id2(id2_head);
                 DEBUG_RET();
                 return NULL;
             }
-            if (list) _pst_free_list(list);
+            if (list) pst_free_list(list);
             list = NULL;
 
             // now we will have initial information of each attachment stored in item->attach...
@@ -1161,54 +1183,60 @@
             // each attachment
             attach = item->attach;
             while (attach) {
-              if ((id_ptr = _pst_getID2(id2_head, attach->id2_val))) {
+              if ((id_ptr = pst_getID2(id2_head, attach->id2_val))) {
                   // id_ptr is a record describing the attachment
                   // we pass NULL instead of id2_head cause we don't want it to
                   // load all the extra stuff here.
-                  if ((list = _pst_parse_block(pf, id_ptr->id, NULL)) == NULL) {
+                  if ((list = pst_parse_block(pf, id_ptr->id, NULL)) == NULL) {
                       DEBUG_WARN(("ERROR error processing an attachment record\n"));
                       attach = attach->next;
                       continue;
                   }
-                  if (_pst_process(list, item, attach)) {
-                      DEBUG_WARN(("ERROR _pst_process() failed with an attachment\n"));
-                      if (list) _pst_free_list(list);
+                  if (pst_process(list, item, attach)) {
+                      DEBUG_WARN(("ERROR pst_process() failed with an attachment\n"));
+                      if (list) pst_free_list(list);
                       list = NULL;
                       attach = attach->next;
                       continue;
                   }
-                  if (list) _pst_free_list(list);
+                  if (list) pst_free_list(list);
                   list = NULL;
-                  id_ptr = _pst_getID2(id2_head, attach->id2_val);
+                  id_ptr = pst_getID2(id2_head, attach->id2_val);
                   if (id_ptr) {
                       // id2_val has been updated to the ID2 value of the datablock containing the
                       // attachment data
                       attach->id_val = id_ptr->id;
                   } else {
-                      DEBUG_WARN(("have not located the correct value for the attachment [%#x]\n", attach->id2_val));
+                      DEBUG_WARN(("have not located the correct value for the attachment [%#llx]\n", attach->id2_val));
                   }
               } else {
-                  DEBUG_WARN(("ERROR cannot locate id2 value %#x\n", attach->id2_val));
+                  DEBUG_WARN(("ERROR cannot locate id2 value %#llx\n", attach->id2_val));
               }
               attach = attach->next;
             }
         }
     }
 
-    _pst_free_id2(id2_head);
-    id2_head = NULL;
+    if (id2_head) pst_free_id2(id2_head);
     DEBUG_RET();
     return item;
 }
 
 
-void freeall(unsigned char *buf, pst_block_offset_pointer *p1,
-                                 pst_block_offset_pointer *p2,
-                                 pst_block_offset_pointer *p3,
-                                 pst_block_offset_pointer *p4,
-                                 pst_block_offset_pointer *p5,
-                                 pst_block_offset_pointer *p6,
-                                 pst_block_offset_pointer *p7) {
+static void freeall(unsigned char *buf, pst_block_offset_pointer *p1,
+                                        pst_block_offset_pointer *p2,
+                                        pst_block_offset_pointer *p3,
+                                        pst_block_offset_pointer *p4,
+                                        pst_block_offset_pointer *p5,
+                                        pst_block_offset_pointer *p6,
+                                        pst_block_offset_pointer *p7);
+static void freeall(unsigned char *buf, pst_block_offset_pointer *p1,
+                                        pst_block_offset_pointer *p2,
+                                        pst_block_offset_pointer *p3,
+                                        pst_block_offset_pointer *p4,
+                                        pst_block_offset_pointer *p5,
+                                        pst_block_offset_pointer *p6,
+                                        pst_block_offset_pointer *p7) {
     if (buf) free(buf);
     if (p1->needfree) free(p1->from);
     if (p2->needfree) free(p2->from);
@@ -1220,7 +1248,7 @@
 }
 
 
-pst_num_array * _pst_parse_block(pst_file *pf, uint32_t block_id, pst_index2_ll *i2_head) {
+pst_num_array * pst_parse_block(pst_file *pf, uint64_t block_id, pst_index2_ll *i2_head) {
     unsigned char *buf = NULL;
     pst_num_array *na_ptr = NULL, *na_head = NULL;
     pst_block_offset_pointer block_offset1;
@@ -1230,20 +1258,18 @@
     pst_block_offset_pointer block_offset5;
     pst_block_offset_pointer block_offset6;
     pst_block_offset_pointer block_offset7;
-    uint32_t size;
-    uint32_t x;
-    uint32_t num_recs;
-    uint32_t count_rec;
-    uint32_t num_list;
-    uint32_t cur_list;
-    uint32_t block_type;
+    int32_t  x;
+    int      num_recs;
+    int      count_rec;
+    int32_t  num_list;
+    int32_t  cur_list;
+    int32_t  block_type;
     uint32_t rec_size = 0;
     uint32_t ind_ptr;
     unsigned char* list_start;
-    unsigned char* t_ptr;
     unsigned char* fr_ptr;
     unsigned char* to_ptr;
-    unsigned char* ind2_end;
+    unsigned char* ind2_end = NULL;
     unsigned char* ind2_ptr = NULL;
     size_t read_size=0;
     pst_x_attrib_ll *mapptr;
@@ -1285,9 +1311,9 @@
         uint32_t u1;
     } * type_d_rec;
 
-    DEBUG_ENT("_pst_parse_block");
-    if ((read_size = _pst_ff_getIDblock_dec(pf, block_id, &buf)) == 0) {
-        WARN(("Error reading block id %#x\n", block_id));
+    DEBUG_ENT("pst_parse_block");
+    if ((read_size = pst_ff_getIDblock_dec(pf, block_id, &buf)) == 0) {
+        WARN(("Error reading block id %#llx\n", block_id));
         if (buf) free (buf);
         DEBUG_RET();
         return NULL;
@@ -1309,10 +1335,10 @@
 
     ind_ptr = block_hdr.index_offset;
 
-    if (block_hdr.type == 0xBCEC) { //type 1
+    if (block_hdr.type == (uint16_t)0xBCEC) { //type 1
         block_type = 1;
 
-        if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, block_hdr.offset, &block_offset1)) {
+        if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, block_hdr.offset, &block_offset1)) {
             DEBUG_WARN(("internal error (bc.b5 offset %#x) in reading block id %#x\n", block_hdr.offset, block_id));
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
@@ -1324,15 +1350,15 @@
         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));
 
-        if (table_rec.type != 0x02B5) {
-            WARN(("Unknown second block constant - %#X for id %#x\n", table_rec.type, block_id));
+        if (table_rec.type != (uint16_t)0x02B5) {
+            WARN(("Unknown second block constant - %#hx for id %#llx\n", table_rec.type, block_id));
             DEBUG_HEXDUMPC(buf, sizeof(table_rec), 0x10);
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
             return NULL;
         }
 
-        if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset2)) {
+        if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset2)) {
             DEBUG_WARN(("internal error (bc.b5.desc offset) in reading block id %#x\n", table_rec.value, block_id));
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
@@ -1343,10 +1369,10 @@
         num_list = (to_ptr - list_start)/sizeof(table_rec);
         num_recs = 1; // only going to be one object in these blocks
     }
-    else if (block_hdr.type == 0x7CEC) { //type 2
+    else if (block_hdr.type == (uint16_t)0x7CEC) { //type 2
         block_type = 2;
 
-        if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, block_hdr.offset, &block_offset3)) {
+        if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, block_hdr.offset, &block_offset3)) {
             DEBUG_WARN(("internal error (7c.7c offset %#x) in reading block id %#x\n", block_hdr.offset, block_id));
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
@@ -1376,7 +1402,7 @@
         rec_size = seven_c_blk.rec_size;
         num_list = seven_c_blk.item_count;
 
-        if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.b_five_offset, &block_offset4)) {
+        if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.b_five_offset, &block_offset4)) {
             DEBUG_WARN(("internal error (7c.b5 offset %#x) in reading block id %#x\n", seven_c_blk.b_five_offset, block_id));
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
@@ -1387,22 +1413,22 @@
         LE16_CPU(table_rec.ref_type);
         LE32_CPU(table_rec.value);
 
-        if (table_rec.type != 0x04B5) { // different constant than a type 1 record
-            WARN(("Unknown second block constant - %#X for id %#x\n", table_rec.type, block_id));
+        if (table_rec.type != (uint16_t)0x04B5) { // different constant than a type 1 record
+            WARN(("Unknown second block constant - %#hx for id %#llx\n", table_rec.type, block_id));
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
             return NULL;
         }
 
-        if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset5)) {
-            DEBUG_WARN(("internal error (7c.5b.desc offset %#x) in reading block id %#x\n", table_rec.value, block_id));
+        if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset5)) {
+            DEBUG_WARN(("internal error (7c.5b.desc offset %#x) in reading block id %#llx\n", table_rec.value, block_id));
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
             return NULL;
         }
         num_recs = (block_offset5.to - block_offset5.from) / 6; // this will give the number of records in this block
 
-        if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.ind2_offset, &block_offset6)) {
+        if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, seven_c_blk.ind2_offset, &block_offset6)) {
             DEBUG_WARN(("internal error (7c.ind2 offset %#x) in reading block id %#x\n", seven_c_blk.ind2_offset, block_id));
             freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
             DEBUG_RET();
@@ -1411,16 +1437,16 @@
         ind2_ptr = block_offset6.from;
         ind2_end = block_offset6.to;
     }
-    else if (block_hdr.index_offset == 0x0101) { //type 2
+    else if (block_hdr.index_offset == (uint16_t)0x0101) { //type 3
         unsigned char *buf2 = NULL;
-        int n = block_hdr.type; // count
-        int m = sizeof(table3_rec);
-        int i;
+        uint16_t n = block_hdr.type; // count
+        size_t   m = sizeof(table3_rec);
+        uint16_t i;
         block_type = 3;
         for (i=0; i<n; i++) {
             memcpy(&table3_rec, buf+8+i*m, m);
             LE32_CPU(table3_rec.id);
-            _pst_ff_getIDblock_dec(pf, table3_rec.id, &buf2);
+            (void)pst_ff_getIDblock_dec(pf, table3_rec.id, &buf2);
             if (buf2) free(buf2);
             buf2 = NULL;
         }
@@ -1428,7 +1454,7 @@
         DEBUG_RET();
         return NULL;
     } else {
-        WARN(("ERROR: Unknown block constant - %#X for id %#x\n", block_hdr.type, block_id));
+        WARN(("ERROR: Unknown block constant - %#hx for id %#llx\n", block_hdr.type, block_id));
         DEBUG_HEXDUMPC(buf, read_size,0x10);
         freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
         DEBUG_RET();
@@ -1441,8 +1467,8 @@
         memset(na_ptr, 0, sizeof(pst_num_array));
         na_ptr->next = na_head;
         na_head = na_ptr;
-        // allocate an array of count num_recs to contain sizeof(struct_pst_num_item)
-        na_ptr->items       = (struct _pst_num_item**) xmalloc(sizeof(struct _pst_num_item)*num_list);
+        // allocate an array of count num_recs to contain sizeof(structpst_num_item)
+        na_ptr->items       = (struct pst_num_item**) xmalloc(sizeof(struct pst_num_item)*num_list);
         na_ptr->count_item  = num_list;
         na_ptr->orig_count  = num_list;
         na_ptr->count_array = num_recs; // each record will have a record of the total number of records
@@ -1454,14 +1480,14 @@
         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
             unsigned char* value_pointer = NULL;    // needed for block type 2 with values larger than 4 bytes
-            int value_size = 0;
-            if (block_type == 1) {
+            size_t value_size = 0;
+            if (block_type == (int32_t)1) {
                 memcpy(&table_rec, fr_ptr, sizeof(table_rec));
                 LE16_CPU(table_rec.type);
                 LE16_CPU(table_rec.ref_type);
                 //LE32_CPU(table_rec.value);    // done later, some may be order invariant
                 fr_ptr += sizeof(table_rec);
-            } else if (block_type == 2) {
+            } else if (block_type == (int32_t)2) {
                 // we will copy the table2_rec values into a table_rec record so that we can keep the rest of the code
                 memcpy(&table2_rec, fr_ptr, sizeof(table2_rec));
                 LE16_CPU(table2_rec.ref_type);
@@ -1473,8 +1499,8 @@
                 table_rec.ref_type = table2_rec.ref_type;
                 table_rec.value    = 0;
                 if ((ind2_end - ind2_ptr) >= (table2_rec.ind2_off + table2_rec.size)) {
-                    int n = table2_rec.size;
-                    int m = sizeof(table_rec.value);
+                    size_t n = table2_rec.size;
+                    size_t m = sizeof(table_rec.value);
                     if (n <= m) {
                         memcpy(&table_rec.value, ind2_ptr + table2_rec.ind2_off, n);
                     }
@@ -1492,7 +1518,7 @@
             } else {
                 WARN(("Missing code for block_type %i\n", block_type));
                 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
-                if (na_head) _pst_free_list(na_head);
+                if (na_head) pst_free_list(na_head);
                 DEBUG_RET();
                 return NULL;
             }
@@ -1500,22 +1526,25 @@
                 x, table_rec.type, table_rec.ref_type, table_rec.value));
 
             if (!na_ptr->items[x]) {
-                na_ptr->items[x] = (struct _pst_num_item*) xmalloc(sizeof(struct _pst_num_item));
+                na_ptr->items[x] = (struct pst_num_item*) xmalloc(sizeof(struct pst_num_item));
             }
-            memset(na_ptr->items[x], 0, sizeof(struct _pst_num_item)); //init it
+            memset(na_ptr->items[x], 0, sizeof(struct pst_num_item)); //init it
 
             // check here to see if the id of the attribute is a mapped one
             mapptr = pf->x_head;
             while (mapptr && (mapptr->map < table_rec.type)) mapptr = mapptr->next;
             if (mapptr && (mapptr->map == table_rec.type)) {
                 if (mapptr->mytype == PST_MAP_ATTRIB) {
-                    na_ptr->items[x]->id = *((int*)mapptr->data);
+                    na_ptr->items[x]->id = *((uint32_t*)mapptr->data);
                     DEBUG_EMAIL(("Mapped attrib %#x to %#x\n", table_rec.type, na_ptr->items[x]->id));
                 } else if (mapptr->mytype == PST_MAP_HEADER) {
                     DEBUG_EMAIL(("Internet Header mapping found %#x\n", table_rec.type));
-                    na_ptr->items[x]->id = PST_ATTRIB_HEADER;
+                    na_ptr->items[x]->id = (uint32_t)PST_ATTRIB_HEADER;
                     na_ptr->items[x]->extra = mapptr->data;
                 }
+                else {
+                    // nothing, should be assertion failure here
+                }
             } else {
                 na_ptr->items[x]->id = table_rec.type;
             }
@@ -1542,27 +1571,27 @@
                 0x1102 - Array of Binary data
             */
 
-            if (table_rec.ref_type == 0x0002 ||
-                table_rec.ref_type == 0x0003 ||
-                table_rec.ref_type == 0x000b) {
+            if (table_rec.ref_type == (uint16_t)0x0002 ||
+                table_rec.ref_type == (uint16_t)0x0003 ||
+                table_rec.ref_type == (uint16_t)0x000b) {
                 //contains 32 bits of data
                 na_ptr->items[x]->size = sizeof(int32_t);
                 na_ptr->items[x]->type = table_rec.ref_type;
                 na_ptr->items[x]->data = xmalloc(sizeof(int32_t));
                 memcpy(na_ptr->items[x]->data, &(table_rec.value), sizeof(int32_t));
 
-            } else if (table_rec.ref_type == 0x0005 ||
-                       table_rec.ref_type == 0x000d ||
-                       table_rec.ref_type == 0x0014 ||
-                       table_rec.ref_type == 0x001e ||
-                       table_rec.ref_type == 0x001f ||
-                       table_rec.ref_type == 0x0040 ||
-                       table_rec.ref_type == 0x0048 ||
-                       table_rec.ref_type == 0x0102 ||
-                       table_rec.ref_type == 0x1003 ||
-                       table_rec.ref_type == 0x1014 ||
-                       table_rec.ref_type == 0x101e ||
-                       table_rec.ref_type == 0x1102) {
+            } else if (table_rec.ref_type == (uint16_t)0x0005 ||
+                       table_rec.ref_type == (uint16_t)0x000d ||
+                       table_rec.ref_type == (uint16_t)0x0014 ||
+                       table_rec.ref_type == (uint16_t)0x001e ||
+                       table_rec.ref_type == (uint16_t)0x001f ||
+                       table_rec.ref_type == (uint16_t)0x0040 ||
+                       table_rec.ref_type == (uint16_t)0x0048 ||
+                       table_rec.ref_type == (uint16_t)0x0102 ||
+                       table_rec.ref_type == (uint16_t)0x1003 ||
+                       table_rec.ref_type == (uint16_t)0x1014 ||
+                       table_rec.ref_type == (uint16_t)0x101e ||
+                       table_rec.ref_type == (uint16_t)0x1102) {
                 //contains index reference to data
                 LE32_CPU(table_rec.value);
                 if (value_pointer) {
@@ -1573,8 +1602,8 @@
                     na_ptr->items[x]->data = xmalloc(value_size);
                     memcpy(na_ptr->items[x]->data, value_pointer, value_size);
                 }
-                else if (_pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset7)) {
-                    if ((table_rec.value & 0xf) == 0xf) {
+                else if (pst_getBlockOffsetPointer(pf, i2_head, buf, read_size, ind_ptr, table_rec.value, &block_offset7)) {
+                    if ((table_rec.value & 0xf) == (uint32_t)0xf) {
                         DEBUG_WARN(("failed to get block offset for table_rec.value of %#x to be read later.\n", table_rec.value));
                         na_ptr->items[x]->size = 0;
                         na_ptr->items[x]->data = NULL;
@@ -1596,11 +1625,11 @@
                     memcpy(na_ptr->items[x]->data, block_offset7.from, value_size);
                     na_ptr->items[x]->data[value_size] = '\0';  // it might be a string, null terminate it.
                 }
-                if (table_rec.ref_type == 0xd) {
+                if (table_rec.ref_type == (uint16_t)0xd) {
                     // there is still more to do for the type of 0xD embedded objects
                     type_d_rec = (struct _type_d_rec*) na_ptr->items[x]->data;
                     LE32_CPU(type_d_rec->id);
-                    na_ptr->items[x]->size = _pst_ff_getID2block(pf, type_d_rec->id, i2_head, &(na_ptr->items[x]->data));
+                    na_ptr->items[x]->size = pst_ff_getID2block(pf, type_d_rec->id, i2_head, &(na_ptr->items[x]->data));
                     if (!na_ptr->items[x]->size){
                         DEBUG_WARN(("not able to read the ID2 data. Setting to be read later. %#x\n", type_d_rec->id));
                         na_ptr->items[x]->type = type_d_rec->id;    // fetch before freeing data, alias pointer
@@ -1608,16 +1637,23 @@
                         na_ptr->items[x]->data = NULL;
                     }
                 }
-                if (table_rec.ref_type == 0x1f) {
+                if (table_rec.ref_type == (uint16_t)0x1f) {
                     // there is more to do for the type 0x1f unicode strings
-                    VBUF_STATIC(strbuf, 1024);
-                    VBUF_STATIC(unibuf, 1024);
+                    static vbuf *strbuf = NULL;
+                    static vbuf *unibuf = NULL;
+                    if (!strbuf) strbuf=vballoc((size_t)1024);
+                    if (!unibuf) unibuf=vballoc((size_t)1024);
+
+                    // splint barfed on the following lines
+                    //VBUF_STATIC(strbuf, 1024);
+                    //VBUF_STATIC(unibuf, 1024);
+
                     //need UTF-16 zero-termination
                     vbset(strbuf, na_ptr->items[x]->data, na_ptr->items[x]->size);
-                    vbappend(strbuf, "\0\0", 2);
+                    vbappend(strbuf, "\0\0", (size_t)2);
                     DEBUG_INDEX(("Iconv in:\n"));
                     DEBUG_HEXDUMPC(strbuf->b, strbuf->dlen, 0x10);
-                    vb_utf16to8(unibuf, strbuf->b, strbuf->dlen);
+                    (void)vb_utf16to8(unibuf, strbuf->b, strbuf->dlen);
                     free(na_ptr->items[x]->data);
                     na_ptr->items[x]->size = unibuf->dlen;
                     na_ptr->items[x]->data = xmalloc(unibuf->dlen);
@@ -1627,9 +1663,9 @@
                 }
                 if (na_ptr->items[x]->type == 0) na_ptr->items[x]->type = table_rec.ref_type;
             } else {
-                WARN(("ERROR Unknown ref_type %#x\n", table_rec.ref_type));
+                WARN(("ERROR Unknown ref_type %#hx\n", table_rec.ref_type));
                 freeall(buf, &block_offset1, &block_offset2, &block_offset3, &block_offset4, &block_offset5, &block_offset6, &block_offset7);
-                if (na_head) _pst_free_list(na_head);
+                if (na_head) pst_free_list(na_head);
                 DEBUG_RET();
                 return NULL;
             }
@@ -1655,7 +1691,7 @@
 #define LIST_COPY(targ, type) {                               \
     targ = type realloc(targ, list->items[x]->size+1);        \
     memcpy(targ, list->items[x]->data, list->items[x]->size); \
-    memset(((char*)targ)+list->items[x]->size, 0, 1);         \
+    memset(((char*)targ)+list->items[x]->size, 0, (size_t)1); \
 }
 // malloc space and copy the current item's data and size
 #define LIST_COPY_SIZE(targ, type, mysize) {    \
@@ -1682,12 +1718,12 @@
 }
 
 
-int32_t _pst_process(pst_num_array *list , pst_item *item, pst_item_attach *attach) {
+int pst_process(pst_num_array *list , pst_item *item, pst_item_attach *attach) {
     int32_t x, t;
     int32_t next = 0;
     pst_item_extra_field *ef;
 
-    DEBUG_ENT("_pst_process");
+    DEBUG_ENT("pst_process");
     if (!item) {
         DEBUG_EMAIL(("item cannot be NULL.\n"));
         DEBUG_RET();
@@ -2025,7 +2061,7 @@
                     DEBUG_EMAIL(("Internet Header - "));
                     MALLOC_EMAIL(item);
                     LIST_COPY(item->email->header, (char*));
-                    //DEBUG_EMAIL(("%s\n", item->email->header));
+                    DEBUG_EMAIL(("%s\n", item->email->header));
                     DEBUG_EMAIL(("NOT PRINTED\n"));
                     break;
                 case 0x0C17: // PR_REPLY_REQUESTED
@@ -2364,7 +2400,7 @@
                     MOVE_NEXT(attach);
                     if (!list->items[x]->data) { //special case
                         attach->id2_val = list->items[x]->type;
-                        DEBUG_EMAIL(("Seen a Reference. The data hasn't been loaded yet. [%#x][%#x]\n",
+                        DEBUG_EMAIL(("Seen a Reference. The data hasn't been loaded yet. [%#llx][%#x]\n",
                                  attach->id2_val, list->items[x]->type));
                     } else {
                         LIST_COPY(attach->data, (char*));
@@ -2932,11 +2968,13 @@
                     break;
                 case 0x67F2: // ID2 value of the attachments proper record
                     DEBUG_EMAIL(("Attachment ID2 value - "));
-                    if (attach){
+                    if (attach) {
+                        uint32_t tempid;
                         MOVE_NEXT(attach);
-                        memcpy(&(attach->id2_val), list->items[x]->data, sizeof(attach->id2_val));
-                        LE32_CPU(attach->id2_val);
-                        DEBUG_EMAIL(("%#x\n", attach->id2_val));
+                        memcpy(&(tempid), list->items[x]->data, sizeof(tempid));
+                        LE32_CPU(tempid);
+                        attach->id2_val = tempid;
+                        DEBUG_EMAIL(("%#llx\n", attach->id2_val));
                     } else {
                         DEBUG_EMAIL(("NOT AN ATTACHMENT: %#x\n", list->items[x]->id));
                     }
@@ -3282,9 +3320,9 @@
 }
 
 
-int32_t _pst_free_list(pst_num_array *list) {
+void pst_free_list(pst_num_array *list) {
     pst_num_array *l;
-    DEBUG_ENT("_pst_free_list");
+    DEBUG_ENT("pst_free_list");
     while (list) {
         if (list->items) {
             int32_t x;
@@ -3301,39 +3339,36 @@
         free (l);
     }
     DEBUG_RET();
-    return 1;
 }
 
 
-int32_t _pst_free_id2(pst_index2_ll * head) {
+void pst_free_id2(pst_index2_ll * head) {
     pst_index2_ll *t;
-    DEBUG_ENT("_pst_free_id2");
+    DEBUG_ENT("pst_free_id2");
     while (head) {
         t = head->next;
         free (head);
         head = t;
     }
     DEBUG_RET();
-    return 1;
 }
 
 
-int32_t _pst_free_id (pst_index_ll *head) {
+void pst_free_id (pst_index_ll *head) {
     pst_index_ll *t;
-    DEBUG_ENT("_pst_free_id");
+    DEBUG_ENT("pst_free_id");
     while (head) {
         t = head->next;
         free(head);
         head = t;
     }
     DEBUG_RET();
-    return 1;
 }
 
 
-int32_t _pst_free_desc (pst_desc_ll *head) {
+void pst_free_desc (pst_desc_ll *head) {
     pst_desc_ll *t;
-    DEBUG_ENT("_pst_free_desc");
+    DEBUG_ENT("pst_free_desc");
     while (head) {
         while (head->child) {
             head = head->child;
@@ -3352,13 +3387,12 @@
         head = t;
     }
     DEBUG_RET();
-    return 1;
 }
 
 
-int32_t _pst_free_xattrib(pst_x_attrib_ll *x) {
+void pst_free_xattrib(pst_x_attrib_ll *x) {
     pst_x_attrib_ll *t;
-    DEBUG_ENT("_pst_free_xattrib");
+    DEBUG_ENT("pst_free_xattrib");
     while (x) {
         if (x->data) free(x->data);
         t = x->next;
@@ -3366,25 +3400,25 @@
         x = t;
     }
     DEBUG_RET();
-    return 1;
 }
 
 
-pst_index2_ll * _pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr) {
+pst_index2_ll * pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr) {
     pst_block_header block_head;
     pst_index2_ll *head = NULL, *tail = NULL;
-    int32_t x = 0, b_ptr = 0;
+    uint16_t x = 0;
+    char *b_ptr = NULL;
     char *buf = NULL;
     pst_id2_assoc id2_rec;
     pst_index_ll *i_ptr = NULL;
     pst_index2_ll *i2_ptr = NULL;
-    DEBUG_ENT("_pst_build_id2");
+    DEBUG_ENT("pst_build_id2");
 
     if (head_ptr) {
         head = head_ptr;
         while (head_ptr) head_ptr = (tail = head_ptr)->next;
     }
-    if (_pst_read_block_size(pf, list->offset, list->size, &buf, PST_NO_ENC, 0) < list->size) {
+    if (pst_read_block_size(pf, list->offset, list->size, &buf, PST_NO_ENC, 0) < list->size) {
         //an error occured in block read
         WARN(("block read error occured. offset = %#llx, size = %#llx\n", list->offset, list->size));
         if (buf) free(buf);
@@ -3397,29 +3431,30 @@
     LE16_CPU(block_head.type);
     LE16_CPU(block_head.count);
 
-    if (block_head.type != 0x0002) { // some sort of constant?
+    if (block_head.type != (uint16_t)0x0002) { // some sort of constant?
         WARN(("Unknown constant [%#x] at start of id2 values [offset %#llx].\n", block_head.type, list->offset));
         if (buf) free(buf);
         DEBUG_RET();
         return NULL;
     }
 
-    DEBUG_INDEX(("ID %#x is likely to be a description record. Count is %i (offset %#x)\n",
+    DEBUG_INDEX(("ID %#llx is likely to be a description record. Count is %i (offset %#llx)\n",
             list->id, block_head.count, list->offset));
     x = 0;
-    b_ptr = 0x04;
+    b_ptr = buf + ((pf->do_read64) ? 0x08 : 0x04);
     while (x < block_head.count) {
-        memcpy(&id2_rec, &(buf[b_ptr]), sizeof(id2_rec));
-        LE32_CPU(id2_rec.id2);
-        LE32_CPU(id2_rec.id);
-        LE32_CPU(id2_rec.table2);
-
-        b_ptr += sizeof(id2_rec);
-        DEBUG_INDEX(("\tid2 = %#x, id = %#x, table2 = %#x\n", id2_rec.id2, id2_rec.id, id2_rec.table2));
-        if ((i_ptr = _pst_getID(pf, id2_rec.id)) == NULL) {
-            DEBUG_WARN(("\t\t%#x - Not Found\n", id2_rec.id));
+        b_ptr += pst_decode_assoc(pf, &id2_rec, b_ptr);
+      //  memcpy(&id2_rec, &(buf[b_ptr]), sizeof(id2_rec));
+      //  LE32_CPU(id2_rec.id2);
+      //  LE32_CPU(id2_rec.id);
+      //  LE32_CPU(id2_rec.table2);
+      //
+      //  b_ptr += sizeof(id2_rec);
+        DEBUG_INDEX(("\tid2 = %#llx, id = %#llx, table2 = %#llx\n", id2_rec.id2, id2_rec.id, id2_rec.table2));
+        if ((i_ptr = pst_getID(pf, id2_rec.id)) == NULL) {
+            DEBUG_WARN(("\t\t%#llx - Not Found\n", id2_rec.id));
         } else {
-            DEBUG_INDEX(("\t\t%#x - Offset %#x, u1 %#x, Size %i(%#x)\n", i_ptr->id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size));
+            DEBUG_INDEX(("\t\t%#llx - Offset %#llx, u1 %#llx, Size %lli(%#llx)\n", i_ptr->id, i_ptr->offset, i_ptr->u1, i_ptr->size, i_ptr->size));
             // add it to the linked list
             i2_ptr = (pst_index2_ll*) xmalloc(sizeof(pst_index2_ll));
             i2_ptr->id2  = id2_rec.id2;
@@ -3429,13 +3464,13 @@
             if (tail)  tail->next = i2_ptr;
             tail = i2_ptr;
             if (id2_rec.table2 != 0) {
-                if ((i_ptr = _pst_getID(pf, id2_rec.table2)) == NULL) {
+                if ((i_ptr = pst_getID(pf, id2_rec.table2)) == NULL) {
                     DEBUG_WARN(("\tTable2 [%#x] not found\n", id2_rec.table2));
                 }
                 else {
                     DEBUG_INDEX(("\tGoing deeper for table2 [%#x]\n", id2_rec.table2));
-                    if ((i2_ptr = _pst_build_id2(pf, i_ptr, head))) {
-                    //  DEBUG_INDEX(("_pst_build_id2(): \t\tAdding new list onto end of current\n"));
+                    if ((i2_ptr = pst_build_id2(pf, i_ptr, head))) {
+                    //  DEBUG_INDEX(("pst_build_id2(): \t\tAdding new list onto end of current\n"));
                     //  if (!head)
                     //    head = i2_ptr;
                     //  if (tail)
@@ -3463,11 +3498,11 @@
 // This version of free does NULL check first
 #define SAFE_FREE(x) {if (x) free(x);}
 
-void _pst_freeItem(pst_item *item) {
+void pst_freeItem(pst_item *item) {
     pst_item_attach *t;
     pst_item_extra_field *et;
 
-    DEBUG_ENT("_pst_freeItem");
+    DEBUG_ENT("pst_freeItem");
     if (item) {
         if (item->email) {
             SAFE_FREE(item->email->arrival_date);
@@ -3657,19 +3692,19 @@
   * Or, the offset might end in 0xf, so it is an id2 pointer, in which case we read the id2 block.
   * Otherwise, the offset>>4 is an index into the table of offsets in the buffer.
 */
-int32_t _pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset_pointer *p) {
-    int32_t size;
+int pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, unsigned char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset_pointer *p) {
+    size_t size;
     pst_block_offset block_offset;
-    DEBUG_ENT("_pst_getBlockOffsetPointer");
+    DEBUG_ENT("pst_getBlockOffsetPointer");
     if (p->needfree) free(p->from);
     p->from = NULL;
     p->needfree = 0;
     if (!offset) {
         p->from = p->to = NULL;
     }
-    else if ((offset & 0xf) == 0xf) {
+    else if ((offset & 0xf) == (uint32_t)0xf) {
         DEBUG_WARN(("Found id2 %#x value. Will follow it\n", offset));
-        size = _pst_ff_getID2block(pf, offset, i2_head, &(p->from));
+        size = pst_ff_getID2block(pf, offset, i2_head, &(p->from));
         if (size) {
             p->to = p->from + size;
             p->needfree = 1;
@@ -3678,7 +3713,7 @@
             p->from = p->to = NULL;
         }
     }
-    else if (_pst_getBlockOffset(buf, read_size, i_offset, offset, &block_offset)) {
+    else if (pst_getBlockOffset(buf, read_size, i_offset, offset, &block_offset)) {
         p->from = p->to = NULL;
     }
     else {
@@ -3690,10 +3725,10 @@
 }
 
 
-int32_t _pst_getBlockOffset(unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset *p) {
-    int32_t low = offset & 0xf;
-    int32_t of1 = offset >> 4;
-    DEBUG_ENT("_pst_getBlockOffset");
+int pst_getBlockOffset(unsigned char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p) {
+    uint32_t low = offset & 0xf;
+    uint32_t of1 = offset >> 4;
+    DEBUG_ENT("pst_getBlockOffset");
     if (!p || !buf || !i_offset || low || (i_offset+2+of1+sizeof(*p) > read_size)) {
         DEBUG_WARN(("p is NULL or buf is NULL or offset is 0 or offset has low bits or beyond read size (%p, %p, %#x, %i, %i)\n", p, buf, offset, read_size, i_offset));
         DEBUG_RET();
@@ -3713,16 +3748,16 @@
 }
 
 
-pst_index_ll* _pst_getID(pst_file* pf, uint64_t id) {
+pst_index_ll* pst_getID(pst_file* pf, uint64_t id) {
     pst_index_ll *ptr = NULL;
-    DEBUG_ENT("_pst_getID");
+    DEBUG_ENT("pst_getID");
     if (id == 0) {
         DEBUG_RET();
         return NULL;
     }
 
-    //if (id & 1) DEBUG_INDEX(("have odd id bit %#x\n", id));
-    //if (id & 2) DEBUG_INDEX(("have two id bit %#x\n", id));
+    //if (id & 1) DEBUG_INDEX(("have odd id bit %#llx\n", id));
+    //if (id & 2) DEBUG_INDEX(("have two id bit %#llx\n", id));
     id -= (id & 1);
 
     DEBUG_INDEX(("Trying to find %#llx\n", id));
@@ -3730,22 +3765,22 @@
     while (ptr && (ptr->id != id)) {
         ptr = ptr->next;
     }
-    if (ptr) {DEBUG_INDEX(("Found Value %#x\n", id));            }
-    else     {DEBUG_INDEX(("ERROR: Value %#x not found\n", id)); }
+    if (ptr) {DEBUG_INDEX(("Found Value %#llx\n", id));            }
+    else     {DEBUG_INDEX(("ERROR: Value %#llx not found\n", id)); }
     DEBUG_RET();
     return ptr;
 }
 
 
-pst_index_ll * _pst_getID2(pst_index2_ll *ptr, uint32_t id) {
-    DEBUG_ENT("_pst_getID2");
+pst_index_ll * pst_getID2(pst_index2_ll *ptr, uint64_t id) {
+    DEBUG_ENT("pst_getID2");
     DEBUG_INDEX(("Head = %p\n", ptr));
     DEBUG_INDEX(("Trying to find %#x\n", id));
     while (ptr && (ptr->id2 != id)) {
         ptr = ptr->next;
     }
     if (ptr) {
-        if (ptr->id) {DEBUG_INDEX(("Found value %#x\n", ptr->id->id));   }
+        if (ptr->id) {DEBUG_INDEX(("Found value %#llx\n", ptr->id->id));   }
         else         {DEBUG_INDEX(("Found value, though it is NULL!\n"));}
         DEBUG_RET();
         return ptr->id;
@@ -3764,9 +3799,9 @@
  *
  * @return pointer to the pst_desc_ll node in the descriptor tree
 */
-pst_desc_ll* _pst_getDptr(pst_file *pf, uint32_t id) {
+pst_desc_ll* pst_getDptr(pst_file *pf, uint64_t id) {
     pst_desc_ll *ptr = pf->d_head;
-    DEBUG_ENT("_pst_getDptr");
+    DEBUG_ENT("pst_getDptr");
     while (ptr && (ptr->id != id)) {
         if (ptr->child) {
             ptr = ptr->child;
@@ -3782,11 +3817,11 @@
 }
 
 
-int32_t _pst_printDptr(pst_file *pf) {
+int32_t pst_printDptr(pst_file *pf) {
     pst_desc_ll *ptr = pf->d_head;
     int32_t depth = 0;
     char spaces[100];
-    DEBUG_ENT("_pst_printDptr");
+    DEBUG_ENT("pst_printDptr");
     memset(spaces, ' ', 99);
     spaces[99] = '\0';
     while (ptr) {
@@ -3809,9 +3844,9 @@
 }
 
 
-int32_t _pst_printIDptr(pst_file* pf) {
+int32_t pst_printIDptr(pst_file* pf) {
     pst_index_ll *ptr = pf->i_head;
-    DEBUG_ENT("_pst_printIDptr");
+    DEBUG_ENT("pst_printIDptr");
     while (ptr) {
         DEBUG_INDEX(("%#x offset=%#x size=%#x\n", ptr->id, ptr->offset, ptr->size));
         ptr = ptr->next;
@@ -3821,8 +3856,8 @@
 }
 
 
-int32_t _pst_printID2ptr(pst_index2_ll *ptr) {
-    DEBUG_ENT("_pst_printID2ptr");
+int32_t pst_printID2ptr(pst_index2_ll *ptr) {
+    DEBUG_ENT("pst_printID2ptr");
     while (ptr) {
         DEBUG_INDEX(("%#x id=%#x\n", ptr->id2, (ptr->id!=NULL?ptr->id->id:0)));
         ptr = ptr->next;
@@ -3832,56 +3867,31 @@
 }
 
 
-size_t _pst_read_block(FILE *fp, off_t offset, void **buf) {
-    int16_t size16;
-    size_t size;
-    off_t fpos;
-    DEBUG_ENT("_pst_read_block");
-    DEBUG_READ(("Reading block from %#x\n", offset));
-    fpos = ftell(fp);
-    fseek(fp, offset, SEEK_SET);
-    fread(&size16, sizeof(int16_t), 1, fp);
-    LE16_CPU(size16);
-    size = size16;
-    fseek(fp, offset, SEEK_SET);
-    DEBUG_READ(("Allocating %i bytes\n", size));
-    if (*buf) {
-        DEBUG_READ(("Freeing old memory\n"));
-        free(*buf);
-    }
-    *buf = (void*)xmalloc(size);
-    size = fread(*buf, 1, size, fp);
-    fseek(fp, fpos, SEEK_SET);
-    DEBUG_RET();
-    return size;
-}
-
-
 // when the first byte of the block being read is 01, then we can assume
 // that it is a list of further ids to read and we will follow those ids
 // recursively calling this function until we have all the data
 // we could do decryption of the encrypted PST files here
-size_t _pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf, int32_t do_enc, unsigned char is_index) {
+size_t pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf, int32_t do_enc, unsigned char is_index) {
     off_t fpos;
-    int32_t x;
+    uint32_t x;
     int16_t count, y;
     char *buf2 = NULL, *buf3 = NULL;
     unsigned char fdepth;
     pst_index_ll *ptr = NULL;
     size_t rsize, z;
 
-    DEBUG_ENT("_pst_read_block_size");
+    DEBUG_ENT("pst_read_block_size");
     DEBUG_READ(("Reading block from %#x, %i bytes\n", offset, size));
 
     fpos = ftell(pf->fp);
-    fseek(pf->fp, offset, SEEK_SET);
+    (void)fseek(pf->fp, offset, SEEK_SET);
     if (*buf) {
         DEBUG_READ(("Freeing old memory\n"));
         free(*buf);
     }
 
     *buf = (void*) xmalloc(size+1); //plus one so that we can NUL terminate it later
-    rsize = fread(*buf, 1, size, pf->fp);
+    rsize = fread(*buf, (size_t)1, size, pf->fp);
     if (rsize != size) {
         DEBUG_WARN(("Didn't read all that I could. fread returned less [%i instead of %i]\n", rsize, size));
         if (feof(pf->fp)) {
@@ -3897,7 +3907,7 @@
     //  DEBUG_HEXDUMP(*buf, size);
 
     /*  if (is_index) {
-      DEBUG_READ(("_pst_read_block_size: ODD_BLOCK should be here\n"));
+      DEBUG_READ(("pst_read_block_size: ODD_BLOCK should be here\n"));
       DEBUG_READ(("\t: byte 0-1: %#x %#x\n", (*buf)[0], (*buf)[1]));
       }*/
 
@@ -3913,9 +3923,9 @@
         size = 0;
         y = 0;
         while (y < count) {
-            memcpy(&x, &(*buf)[0x08+(y*4)], sizeof(int32_t));
+            memcpy(&x, &(*buf)[0x08+(y*4)], sizeof(uint32_t));
             LE32_CPU(x);
-            if ((ptr = _pst_getID(pf, x)) == NULL) {
+            if ((ptr = pst_getID(pf, x)) == NULL) {
                 WARN(("Error. Cannot find ID [%#x] during multi-block read\n", x));
                 buf3 = (char*) realloc(buf3, size+1);
                 buf3[size] = '\0';
@@ -3924,7 +3934,7 @@
                 DEBUG_RET();
                 return size;
             }
-            if ((z = _pst_read_block_size(pf, ptr->offset, ptr->size, &buf2, do_enc, fdepth-1)) < ptr->size) {
+            if ((z = pst_read_block_size(pf, ptr->offset, ptr->size, &buf2, do_enc, fdepth-1)) < ptr->size) {
                 buf3 = (char*) realloc(buf3, size+1);
                 buf3[size] = '\0';
                 *buf = buf3;
@@ -3944,23 +3954,26 @@
         if (!buf3) {
             // this can happen if count == 0. We should create an empty buffer so we don't
             // confuse any clients
-            buf3 = (char*) xmalloc(1);
+            buf3 = (char*) xmalloc((size_t)1);
         }
         *buf = buf3;
-    } else if (do_enc && pf->encryption)
-        _pst_decrypt(*buf, size, pf->encryption);
+    } else if (do_enc && pf->encryption) {
+        (void)pst_decrypt(*buf, size, pf->encryption);
+    } else {
+        // nothing to do
+    }
 
     (*buf)[size] = '\0'; //should be byte after last one read
-    fseek(pf->fp, fpos, SEEK_SET);
+    (void)fseek(pf->fp, fpos, SEEK_SET);
     DEBUG_RET();
     return size;
 }
 
 
-int32_t _pst_decrypt(unsigned char *buf, size_t size, int32_t type) {
+int pst_decrypt(unsigned char *buf, size_t size, unsigned char type) {
     size_t x = 0;
     unsigned char y;
-    DEBUG_ENT("_pst_decrypt");
+    DEBUG_ENT("pst_decrypt");
     if (!buf) {
         DEBUG_RET();
         return -1;
@@ -3984,10 +3997,10 @@
 }
 
 
-int64_t _getIntAt(char *buf) {
-    int64_t buf64;
-    int32_t buf32;
-    if (do_read64) {
+uint64_t pst_getIntAt(pst_file *pf, char *buf) {
+    uint64_t buf64;
+    uint32_t buf32;
+    if (pf->do_read64) {
         memcpy(&buf64, buf, sizeof(buf64));
         LE64_CPU(buf64);
         return buf64;
@@ -4000,24 +4013,24 @@
 }
 
 
-int64_t _pst_getIntAtPos(FILE *fp, off_t pos ) {
-    int64_t buf64;
-    int32_t buf32;
-    if (do_read64) {
-        _pst_getAtPos(fp, pos, &buf64, sizeof(buf64));
+uint64_t pst_getIntAtPos(pst_file *pf, off_t pos ) {
+    uint64_t buf64;
+    uint32_t buf32;
+    if (pf->do_read64) {
+        (void)pst_getAtPos(pf->fp, pos, &buf64, sizeof(buf64));
         LE64_CPU(buf64);
         return buf64;
     }
     else {
-        _pst_getAtPos(fp, pos, &buf32, sizeof(buf32));
+        (void)pst_getAtPos(pf->fp, pos, &buf32, sizeof(buf32));
         LE32_CPU(buf32);
         return buf32;
     }
 }
 
 
-int32_t _pst_getAtPos(FILE *fp, off_t pos, void* buf, uint32_t size) {
-    DEBUG_ENT("_pst_getAtPos");
+int pst_getAtPos(FILE *fp, off_t pos, void* buf, size_t size) {
+    DEBUG_ENT("pst_getAtPos");
     if (fseek(fp, pos, SEEK_SET) == -1) {
         DEBUG_RET();
         return 1;
@@ -4031,8 +4044,8 @@
 }
 
 
-int32_t _pst_get (FILE *fp, void *buf, uint32_t size) {
-    DEBUG_ENT("_pst_get");
+int pst_get (FILE *fp, void *buf, size_t size) {
+    DEBUG_ENT("pst_get");
     if (fread(buf, 1,  size, fp) < size) {
         DEBUG_RET();
         return 1;
@@ -4042,14 +4055,14 @@
 }
 
 
-size_t _pst_ff_getIDblock_dec(pst_file *pf, uint32_t id, unsigned char **b) {
+size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, unsigned char **b) {
     size_t r;
-    DEBUG_ENT("_pst_ff_getIDblock_dec");
+    int noenc = (int)(id & 2);   // disable encryption
+    DEBUG_ENT("pst_ff_getIDblock_dec");
     DEBUG_INDEX(("for id %#x\n", id));
-    r = _pst_ff_getIDblock(pf, id, b);
-    int noenc = (id & 2);   // disable encryption
-    if ((pf->encryption) & !(noenc)) {
-        _pst_decrypt(*b, r, pf->encryption);
+    r = pst_ff_getIDblock(pf, id, b);
+    if ((pf->encryption) && !(noenc)) {
+        (void)pst_decrypt(*b, r, pf->encryption);
     }
     DEBUG_HEXDUMPC(*b, r, 16);
     DEBUG_RET();
@@ -4057,16 +4070,16 @@
 }
 
 
-size_t _pst_ff_getIDblock(pst_file *pf, uint32_t id, unsigned char** b) {
+size_t pst_ff_getIDblock(pst_file *pf, uint64_t id, unsigned char** b) {
     pst_index_ll *rec;
-    size_t rsize = 0;//, re_size=0;
-    DEBUG_ENT("_pst_ff_getIDblock");
-    if ((rec = _pst_getID(pf, id)) == NULL) {
+    size_t rsize = 0;
+    DEBUG_ENT("pst_ff_getIDblock");
+    if ((rec = pst_getID(pf, id)) == NULL) {
         DEBUG_INDEX(("Cannot find ID %#x\n", id));
         DEBUG_RET();
         return 0;
     }
-    fseek(pf->fp, rec->offset, SEEK_SET);
+    (void)fseek(pf->fp, rec->offset, SEEK_SET);
     if (*b) {
         DEBUG_INDEX(("freeing old memory in b\n"));
         free(*b);
@@ -4091,12 +4104,12 @@
 
 
 #define PST_PTR_BLOCK_SIZE 0x120
-size_t _pst_ff_getID2block(pst_file *pf, uint32_t id2, pst_index2_ll *id2_head, unsigned char** buf) {
+size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, unsigned char** buf) {
     pst_index_ll* ptr;
     //  size_t ret;
     struct holder h = {buf, NULL, 0, "", 0};
-    DEBUG_ENT("_pst_ff_getID2block");
-    ptr = _pst_getID2(id2_head, id2);
+    DEBUG_ENT("pst_ff_getID2block");
+    ptr = pst_getID2(id2_head, id2);
 
     if (!ptr) {
         DEBUG_INDEX(("Cannot find id2 value %#x\n", id2));
@@ -4104,33 +4117,36 @@
         return 0;
     }
     DEBUG_RET();
-    return _pst_ff_getID2data(pf, ptr, &h);
+    return pst_ff_getID2data(pf, ptr, &h);
 }
 
 
-size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h) {
-    int32_t ret;
+size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h) {
+    size_t ret;
     unsigned char *b = NULL, *t;
-    DEBUG_ENT("_pst_ff_getID2data");
+    DEBUG_ENT("pst_ff_getID2data");
     if (!(ptr->id & 0x02)) {
-        ret = _pst_ff_getIDblock_dec(pf, ptr->id, &b);
+        ret = pst_ff_getIDblock_dec(pf, ptr->id, &b);
         if (h->buf) {
             *(h->buf) = b;
         } else if ((h->base64 == 1) && h->fp) {
             t = base64_encode(b, ret);
             if (t) {
-                pst_fwrite(t, 1, strlen(t), h->fp);
+                (void)pst_fwrite(t, 1, strlen(t), h->fp);
                 free(t);    // caught by valgrind
             }
             free(b);
         } else if (h->fp) {
-            pst_fwrite(b, 1, ret, h->fp);
+            (void)pst_fwrite(b, 1, ret, h->fp);
             free(b);
+        } else {
+            // h-> does not specify any output
         }
+
     } 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"));
-        ret = _pst_ff_compile_ID(pf, ptr->id, h, 0);
+        ret = pst_ff_compile_ID(pf, ptr->id, h, (size_t)0);
     }
     if (h->buf && *h->buf)
         (*(h->buf))[ret]='\0';
@@ -4139,15 +4155,15 @@
 }
 
 
-size_t _pst_ff_compile_ID(pst_file *pf, uint32_t id, struct holder *h, int32_t size) {
+size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, struct holder *h, size_t size) {
     size_t z, a;
     uint16_t count, y;
     uint32_t x, b;
     unsigned char * buf3 = NULL, *buf2 = NULL, *t;
     unsigned char fdepth;
 
-    DEBUG_ENT("_pst_ff_compile_ID");
-    a = _pst_ff_getIDblock(pf, id, &buf3);
+    DEBUG_ENT("pst_ff_compile_ID");
+    a = pst_ff_getIDblock(pf, id, &buf3);
     if (!a) {
         if (buf3) free(buf3);
         return 0;
@@ -4156,19 +4172,21 @@
         //  if ((buf3)[0] != 0x1 && (buf3)[1] > 4) {
         DEBUG_WARN(("WARNING: buffer doesn't start with 0x1, but I expected it to or doesn't have it's two-bit set!\n"));
         DEBUG_WARN(("Treating as normal buffer\n"));
-        if (pf->encryption) _pst_decrypt(buf3, a, pf->encryption);
+        if (pf->encryption) (void)pst_decrypt(buf3, a, pf->encryption);
         if (h->buf)
             *(h->buf) = buf3;
         else if (h->base64 == 1 && h->fp) {
             t = base64_encode(buf3, a);
             if (t) {
-                pst_fwrite(t, 1, strlen(t), h->fp);
+                (void)pst_fwrite(t, 1, strlen(t), h->fp);
                 free(t);    // caught by valgrind
             }
             free(buf3);
         } else if (h->fp) {
-            pst_fwrite(buf3, 1, a, h->fp);
+            (void)pst_fwrite(buf3, 1, a, h->fp);
             free(buf3);
+        } else {
+            // h-> does not specify any output
         }
         DEBUG_RET();
         return a;
@@ -4184,24 +4202,23 @@
         memcpy(&x, &buf3[0x08+(y*4)], sizeof(int32_t));
         LE32_CPU(x);
         if (fdepth == 0x1) {
-            if ((z = _pst_ff_getIDblock(pf, x, &buf2)) == 0) {
+            if ((z = pst_ff_getIDblock(pf, x, &buf2)) == 0) {
                 DEBUG_WARN(("call to getIDblock returned zero %i\n", z));
                 if (buf2) free(buf2);
                 free(buf3);
                 return z;
             }
-            if (pf->encryption) _pst_decrypt(buf2, z, pf->encryption);
+            if (pf->encryption) (void)pst_decrypt(buf2, z, pf->encryption);
             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));
                 memcpy(&((*(h->buf))[size]), buf2, z);
-            }
-            else if ((h->base64 == 1) && h->fp) {
+            } else if ((h->base64 == 1) && h->fp) {
                 // include any byte left over from the last one encoding
                 buf2 = (char*)realloc(buf2, z+h->base64_extra);
                 memmove(buf2+h->base64_extra, buf2, z);
                 memcpy(buf2, h->base64_extra_chars, h->base64_extra);
-                z+= h->base64_extra;
+                z += h->base64_extra;
 
                 b = z % 3; // find out how many bytes will be left over after the encoding.
                 // and save them
@@ -4210,19 +4227,20 @@
                 t = base64_encode(buf2, z-b);
                 if (t) {
                     DEBUG_READ(("writing %i bytes to file as base64 [%i]. Currently %i\n", z, strlen(t), size));
-                    pst_fwrite(t, 1, strlen(t), h->fp);
+                    (void)pst_fwrite(t, 1, strlen(t), h->fp);
                     free(t);    // caught by valgrind
                 }
-            }
-            else if (h->fp) {
+            } else if (h->fp) {
                 DEBUG_READ(("writing %i bytes to file. Currently %i\n", z, size));
-                pst_fwrite(buf2, 1, z, h->fp);
+                (void)pst_fwrite(buf2, 1, z, h->fp);
+            } else {
+                // h-> does not specify any output
             }
             size += z;
             y++;
         }
         else {
-            if ((z = _pst_ff_compile_ID(pf, x, h, size)) == 0) {
+            if ((z = pst_ff_compile_ID(pf, x, h, size)) == 0) {
                 DEBUG_WARN(("recursive called returned zero %i\n", z));
                 free(buf3);
                 DEBUG_RET();
@@ -4277,7 +4295,7 @@
 
 #endif //_MSC_VER
 
-int32_t pst_stricmp(char *a, char *b) {
+int pst_stricmp(char *a, char *b) {
     // compare strings case-insensitive.
     // returns -1 if a < b, 0 if a==b, 1 if a > b
     while(*a != '\0' && *b != '\0' && toupper(*a)==toupper(*b)) {
@@ -4292,10 +4310,10 @@
 }
 
 
-int32_t pst_strincmp(char *a, char *b, int32_t x) {
+int pst_strincmp(char *a, char *b, size_t x) {
     // compare upto x chars in string a and b case-insensitively
     // returns -1 if a < b, 0 if a==b, 1 if a > b
-    int32_t y = 0;
+    size_t y = 0;
     while (*a != '\0' && *b != '\0' && y < x && toupper(*a)==toupper(*b)) {
         a++; b++; y++;
     }
@@ -4323,10 +4341,10 @@
 }
 
 
-char * _pst_wide_to_single(char *wt, int32_t size) {
+char * pst_wide_to_single(char *wt, int32_t size) {
     // returns the first byte of each wide char. the size is the number of bytes in source
     char *x, *y;
-    DEBUG_ENT("_pst_wide_to_single");
+    DEBUG_ENT("pst_wide_to_single");
     x = xmalloc((size/2)+1);
     y = x;
     while (size != 0 && *wt != '\0') {
@@ -4396,9 +4414,8 @@
 
 int pst_chr_count(char *str, char x) {
     int r = 0;
-    while (*str != '\0') {
-        if (*str == x)
-            r++;
+    while (*str) {
+        if (*str == x) r++;
         str++;
     }
     return r;
--- a/src/libpst.h	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/libpst.h	Sat Jan 12 15:20:53 2008 -0800
@@ -2,7 +2,7 @@
  * libpst.h
  * Part of LibPST project
  * Written by David Smith
- *			  dave.s@earthcorp.com
+ *            dave.s@earthcorp.com
  */
 // LibPST - Library for Accessing Outlook .pst files
 // Dave Smith - davesmith@users.sourceforge.net
@@ -35,21 +35,21 @@
 #if BYTE_ORDER == BIG_ENDIAN
 #  define LE64_CPU(x) \
   x = ((((x) & 0xff00000000000000) >> 56) | \
-	   (((x) & 0x00ff000000000000) >> 40) | \
-	   (((x) & 0x0000ff0000000000) >> 24) | \
-	   (((x) & 0x000000ff00000000) >> 8 ) | \
-	   (((x) & 0x00000000ff000000) << 8 ) | \
-	   (((x) & 0x0000000000ff0000) << 24) | \
-	   (((x) & 0x000000000000ff00) << 40) | \
-	   (((x) & 0x00000000000000ff) << 56));
+       (((x) & 0x00ff000000000000) >> 40) | \
+       (((x) & 0x0000ff0000000000) >> 24) | \
+       (((x) & 0x000000ff00000000) >> 8 ) | \
+       (((x) & 0x00000000ff000000) << 8 ) | \
+       (((x) & 0x0000000000ff0000) << 24) | \
+       (((x) & 0x000000000000ff00) << 40) | \
+       (((x) & 0x00000000000000ff) << 56));
 #  define LE32_CPU(x) \
   x = ((((x) & 0xff000000) >> 24) | \
-	   (((x) & 0x00ff0000) >> 8 ) | \
-	   (((x) & 0x0000ff00) << 8 ) | \
-	   (((x) & 0x000000ff) << 24));
+       (((x) & 0x00ff0000) >> 8 ) | \
+       (((x) & 0x0000ff00) << 8 ) | \
+       (((x) & 0x000000ff) << 24));
 #  define LE16_CPU(x) \
   x = ((((x) & 0xff00) >> 8) | \
-	   (((x) & 0x00ff) << 8));
+       (((x) & 0x00ff) << 8));
 #elif BYTE_ORDER == LITTLE_ENDIAN
 #  define LE64_CPU(x) {}
 #  define LE32_CPU(x) {}
@@ -86,8 +86,8 @@
 #define PST_ENCRYPT 2
 
 // defines different types of mappings
-#define PST_MAP_ATTRIB 1
-#define PST_MAP_HEADER 2
+#define PST_MAP_ATTRIB (uint32_t)1
+#define PST_MAP_HEADER (uint32_t)2
 
 // define my custom email attributes.
 #define PST_ATTRIB_HEADER -1
@@ -99,21 +99,19 @@
 #define PST_FREEBUSY_OUT_OF_OFFICE 3
 
 // defines labels for appointment->label
-#define PST_APP_LABEL_NONE		  0 // None
+#define PST_APP_LABEL_NONE        0 // None
 #define PST_APP_LABEL_IMPORTANT   1 // Important
-#define PST_APP_LABEL_BUSINESS	  2 // Business
-#define PST_APP_LABEL_PERSONAL	  3 // Personal
-#define PST_APP_LABEL_VACATION	  4 // Vacation
+#define PST_APP_LABEL_BUSINESS    2 // Business
+#define PST_APP_LABEL_PERSONAL    3 // Personal
+#define PST_APP_LABEL_VACATION    4 // Vacation
 #define PST_APP_LABEL_MUST_ATTEND 5 // Must Attend
 #define PST_APP_LABEL_TRAVEL_REQ  6 // Travel Required
 #define PST_APP_LABEL_NEEDS_PREP  7 // Needs Preparation
-#define PST_APP_LABEL_BIRTHDAY	  8 // Birthday
+#define PST_APP_LABEL_BIRTHDAY    8 // Birthday
 #define PST_APP_LABEL_ANNIVERSARY 9 // Anniversary
 #define PST_APP_LABEL_PHONE_CALL  10// Phone Call
 
-extern int do_read64;
-
-typedef struct _pst_misc_6_struct {
+typedef struct pst_misc_6_struct {
   int32_t i1;
   int32_t i2;
   int32_t i3;
@@ -122,20 +120,20 @@
   int32_t i6;
 } pst_misc_6;
 
-typedef struct _pst_entryid_struct {
+typedef struct pst_entryid_struct {
   int32_t u1;
   char entryid[16];
   uint32_t id;
 } pst_entryid;
 
-typedef struct _pst_desc_struct32 {
+typedef struct pst_desc_struct32 {
   uint32_t d_id;
   uint32_t desc_id;
   uint32_t list_id;
   uint32_t parent_id;
 } pst_desc32;
 
-typedef struct _pst_desc_structn {
+typedef struct pst_desc_structn {
   uint64_t d_id;
   uint64_t desc_id;
   uint64_t list_id;
@@ -143,127 +141,127 @@
   uint32_t u1;         // padding
 } pst_descn;
 
-typedef struct _pst_index_struct32 {
+typedef struct pst_index_struct32 {
   uint32_t id;
-  int32_t  offset;
+  uint32_t offset;
   uint16_t size;
   int16_t  u1;
 } pst_index32;
 
-typedef struct _pst_index_struct {
+typedef struct pst_index_struct {
   uint64_t id;
-  int64_t  offset;
+  uint64_t offset;
   uint16_t size;
   int16_t  u0;
   int32_t  u1;
 } pst_index;
 
-typedef struct _pst_index_tree32 {
+typedef struct pst_index_tree32 {
   uint32_t id;
-  int32_t  offset;
-  int32_t  size;
+  uint32_t offset;
+  uint32_t size;
   int32_t  u1;
-  struct _pst_index_tree * next;
+  struct pst_index_tree * next;
 } pst_index_ll32;
 
-typedef struct _pst_index_tree {
+typedef struct pst_index_tree {
   uint64_t id;
-  int64_t  offset;
-  int64_t  size;
+  uint64_t offset;
+  uint64_t size;
   int64_t  u1;
-  struct _pst_index_tree * next;
+  struct pst_index_tree * next;
 } pst_index_ll;
 
-typedef struct _pst_index2_tree {
-  uint32_t id2;
+typedef struct pst_index2_tree {
+  uint64_t id2;
   pst_index_ll *id;
-  struct _pst_index2_tree * next;
+  struct pst_index2_tree * next;
 } pst_index2_ll;
 
-typedef struct _pst_desc_tree {
-  uint32_t id;
+typedef struct pst_desc_tree {
+  uint64_t id;
   pst_index_ll * list_index;
   pst_index_ll * desc;
   int32_t no_child;
-  struct _pst_desc_tree * prev;
-  struct _pst_desc_tree * next;
-  struct _pst_desc_tree * parent;
-  struct _pst_desc_tree * child;
-  struct _pst_desc_tree * child_tail;
+  struct pst_desc_tree * prev;
+  struct pst_desc_tree * next;
+  struct pst_desc_tree * parent;
+  struct pst_desc_tree * child;
+  struct pst_desc_tree * child_tail;
 } pst_desc_ll;
 
-typedef struct _pst_item_email_subject {
+typedef struct pst_item_email_subject {
   int32_t off1;
   int32_t off2;
   char   *subj;
 } pst_item_email_subject;
 
-typedef struct _pst_item_email {
+typedef struct pst_item_email {
   FILETIME *arrival_date;
-  int32_t	autoforward; // 1 = true, 0 = not set, -1 = false
-  char	   *body;
-  char	   *cc_address;
-  char	   *common_name;
-  int32_t	conv_index;
-  int32_t	conversion_prohib;
-  int32_t	delete_after_submit; // 1 = true, 0 = false
-  int32_t	delivery_report; // 1 = true, 0 = false
-  char	   *encrypted_body;
-  int32_t	encrypted_body_size;
-  char	   *encrypted_htmlbody;
-  int32_t	encrypted_htmlbody_size;
-  int32_t	flag;
-  char	   *header;
-  char	   *htmlbody;
-  int32_t	importance;
-  char	   *in_reply_to;
-  int32_t	message_cc_me; // 1 = true, 0 = false
-  int32_t	message_recip_me; // 1 = true, 0 = false
-  int32_t	message_to_me; // 1 = true, 0 = false
-  char	   *messageid;
-  int32_t	orig_sensitivity;
-  char	   *outlook_recipient;
-  char	   *outlook_recipient2;
-  char	   *outlook_sender;
-  char	   *outlook_sender_name;
-  char	   *outlook_sender2;
-  int32_t	priority;
-  char	   *proc_subject;
-  int32_t	read_receipt;
-  char	   *recip_access;
-  char	   *recip_address;
-  char	   *recip2_access;
-  char	   *recip2_address;
-  int32_t	reply_requested;
-  char	   *reply_to;
-  char	   *return_path_address;
-  int32_t	rtf_body_char_count;
-  int32_t	rtf_body_crc;
-  char	   *rtf_body_tag;
-  char	   *rtf_compressed;
+  int32_t   autoforward; // 1 = true, 0 = not set, -1 = false
+  char     *body;
+  char     *cc_address;
+  char     *common_name;
+  int32_t   conv_index;
+  int32_t   conversion_prohib;
+  int32_t   delete_after_submit; // 1 = true, 0 = false
+  int32_t   delivery_report; // 1 = true, 0 = false
+  char     *encrypted_body;
+  int32_t   encrypted_body_size;
+  char     *encrypted_htmlbody;
+  int32_t   encrypted_htmlbody_size;
+  int32_t   flag;
+  char     *header;
+  char     *htmlbody;
+  int32_t   importance;
+  char     *in_reply_to;
+  int32_t   message_cc_me; // 1 = true, 0 = false
+  int32_t   message_recip_me; // 1 = true, 0 = false
+  int32_t   message_to_me; // 1 = true, 0 = false
+  char     *messageid;
+  int32_t   orig_sensitivity;
+  char     *outlook_recipient;
+  char     *outlook_recipient2;
+  char     *outlook_sender;
+  char     *outlook_sender_name;
+  char     *outlook_sender2;
+  int32_t   priority;
+  char     *proc_subject;
+  int32_t   read_receipt;
+  char     *recip_access;
+  char     *recip_address;
+  char     *recip2_access;
+  char     *recip2_address;
+  int32_t   reply_requested;
+  char     *reply_to;
+  char     *return_path_address;
+  int32_t   rtf_body_char_count;
+  int32_t   rtf_body_crc;
+  char     *rtf_body_tag;
+  char     *rtf_compressed;
   uint32_t rtf_compressed_size;
-  int32_t	rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false
-  int32_t	rtf_ws_prefix_count;
-  int32_t	rtf_ws_trailing_count;
-  char	   *sender_access;
-  char	   *sender_address;
-  char	   *sender2_access;
-  char	   *sender2_address;
-  int32_t	sensitivity;
+  int32_t   rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false
+  int32_t   rtf_ws_prefix_count;
+  int32_t   rtf_ws_trailing_count;
+  char     *sender_access;
+  char     *sender_address;
+  char     *sender2_access;
+  char     *sender2_address;
+  int32_t   sensitivity;
   FILETIME *sent_date;
   pst_entryid *sentmail_folder;
-  char		  *sentto_address;
+  char        *sentto_address;
   pst_item_email_subject *subject;
 } pst_item_email;
 
-typedef struct _pst_item_folder {
+typedef struct pst_item_folder {
   int32_t  email_count;
   int32_t  unseen_email_count;
   int32_t  assoc_count;
   char subfolder;
 } pst_item_folder;
 
-typedef struct _pst_item_message_store {
+typedef struct pst_item_message_store {
   pst_entryid *deleted_items_folder;
   pst_entryid *search_root_folder;
   pst_entryid *top_of_personal_folder;
@@ -272,7 +270,7 @@
   int32_t pwd_chksum;
 } pst_item_message_store;
 
-typedef struct _pst_item_contact {
+typedef struct pst_item_contact {
   char *access_method;
   char *account_name;
   char *address1;
@@ -368,33 +366,33 @@
   FILETIME *wedding_anniversary;
 } pst_item_contact;
 
-typedef struct _pst_item_attach {
+typedef struct pst_item_attach {
   char *filename1;
   char *filename2;
   char *mimetype;
   char *data;
   size_t   size;
-  int32_t  id2_val;
-  int32_t  id_val; // calculated from id2_val during creation of record
+  uint64_t id2_val;
+  uint64_t id_val; // calculated from id2_val during creation of record
   int32_t  method;
   int32_t  position;
   int32_t  sequence;
-  struct _pst_item_attach *next;
+  struct pst_item_attach *next;
 } pst_item_attach;
 
-typedef struct _pst_item_extra_field {
+typedef struct pst_item_extra_field {
   char *field_name;
   char *value;
-  struct _pst_item_extra_field *next;
+  struct pst_item_extra_field *next;
 } pst_item_extra_field;
 
-typedef struct _pst_item_journal {
+typedef struct pst_item_journal {
   FILETIME *end;
   FILETIME *start;
   char *type;
 } pst_item_journal;
 
-typedef struct _pst_item_appointment {
+typedef struct pst_item_appointment {
   FILETIME *end;
   char *location;
   FILETIME *reminder;
@@ -405,15 +403,15 @@
   int32_t all_day;
 } pst_item_appointment;
 
-typedef struct _pst_item {
-  struct _pst_item_email         *email;            // data reffering to email
-  struct _pst_item_folder        *folder;           // data reffering to folder
-  struct _pst_item_contact       *contact;          // data reffering to contact
-  struct _pst_item_attach        *attach;           // linked list of attachments
-  struct _pst_item_message_store *message_store;    // data referring to the message store
-  struct _pst_item_extra_field   *extra_fields;     // linked list of extra headers and such
-  struct _pst_item_journal       *journal;          // data reffering to a journal entry
-  struct _pst_item_appointment   *appointment;      // data reffering to a calendar entry
+typedef struct pst_item {
+  struct pst_item_email         *email;            // data reffering to email
+  struct pst_item_folder        *folder;           // data reffering to folder
+  struct pst_item_contact       *contact;          // data reffering to contact
+  struct pst_item_attach        *attach;           // linked list of attachments
+  struct pst_item_message_store *message_store;    // data referring to the message store
+  struct pst_item_extra_field   *extra_fields;     // linked list of extra headers and such
+  struct pst_item_journal       *journal;          // data reffering to a journal entry
+  struct pst_item_appointment   *appointment;      // data reffering to a calendar entry
   int32_t   type;
   char     *ascii_type;
   char     *file_as;
@@ -428,124 +426,122 @@
   int32_t   private_member;
 } pst_item;
 
-typedef struct _pst_x_attrib_ll {
-  int32_t type;
-  int32_t mytype;
-  int32_t map;
+typedef struct pst_x_attrib_ll {
+  uint32_t type;
+  uint32_t mytype;
+  uint32_t map;
   void *data;
-  struct _pst_x_attrib_ll *next;
+  struct pst_x_attrib_ll *next;
 } pst_x_attrib_ll;
 
-typedef struct _pst_file {
+typedef struct pst_file {
   pst_index_ll *i_head, *i_tail;
   pst_index2_ll *i2_head;
   pst_desc_ll *d_head, *d_tail;
   pst_x_attrib_ll *x_head;
-  int32_t index1;
-  int32_t index1_count;
-  int32_t index2;
-  int32_t index2_count;
-  int64_t index1_64;
-  int64_t index1_count_64;
-  int64_t index2_64;
-  int64_t index2_count_64;
-  FILE * fp;				// file pointer to opened PST file
-  size_t size;				// pst file size
+
+  //set this to 0 to read 32-bit pst files (pre Outlook 2003)
+  //set this to 1 to read 64-bit pst files (Outlook 2003 and later)
+  int do_read64;
+
+  uint64_t index1;
+  uint64_t index1_back;
+  uint64_t index2;
+  uint64_t index2_back;
+  FILE * fp;                // file pointer to opened PST file
+  uint64_t size;            // pst file size
   unsigned char encryption; // pst encryption setting
-  unsigned char ind_type;	// pst index type
+  unsigned char ind_type;   // pst index type
 } pst_file;
 
-typedef struct _pst_block_offset {
+typedef struct pst_block_offset {
   int16_t from;
   int16_t to;
 } pst_block_offset;
 
-typedef struct _pst_block_offset_pointer {
+typedef struct pst_block_offset_pointer {
   unsigned char *from;
   unsigned char *to;
-  int			needfree;
+  int           needfree;
 } pst_block_offset_pointer;
 
-struct _pst_num_item {
+struct pst_num_item {
   uint32_t id;
   unsigned char *data;
-  int32_t type;
-  size_t size;
-  char *extra;
+  uint32_t type;
+  size_t  size;
+  char   *extra;
 };
 
-typedef struct _pst_num_array {
+typedef struct pst_num_array {
   int32_t count_item;
   int32_t orig_count;
   int32_t count_array;
-  struct _pst_num_item ** items;
-  struct _pst_num_array *next;
+  struct pst_num_item ** items;
+  struct pst_num_array *next;
 } pst_num_array;
 
 struct holder {
   unsigned char **buf;
-  FILE * fp;
-  int32_t base64;
-  char base64_extra_chars[3];
-  int32_t base64_extra;
+  FILE *    fp;
+  int       base64;
+  char      base64_extra_chars[3];
+  uint32_t  base64_extra;
 };
 
 // prototypes
-void set_read64();
-int32_t pst_open(pst_file *pf, char *name, char *mode);
-int32_t pst_close(pst_file *pf);
-pst_desc_ll * pst_getTopOfFolders(pst_file *pf, pst_item *root);
-int32_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b);
-int32_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
-int32_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
-int32_t pst_load_index (pst_file *pf);
-pst_desc_ll* pst_getNextDptr(pst_desc_ll* d);
-int32_t pst_load_extended_attributes(pst_file *pf);
+int            pst_open(pst_file *pf, char *name, char *mode);
+int            pst_close(pst_file *pf);
+pst_desc_ll *  pst_getTopOfFolders(pst_file *pf, pst_item *root);
+size_t         pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b);
+size_t         pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
+size_t         pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
+int            pst_load_index (pst_file *pf);
+pst_desc_ll*   pst_getNextDptr(pst_desc_ll* d);
+int            pst_load_extended_attributes(pst_file *pf);
 
-int32_t _pst_build_id_ptr(pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t start_val, uint64_t end_val);
-int32_t _pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t *high_id, uint64_t start_id, uint64_t end_val);
-pst_item* _pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
-pst_item* _pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr);
-pst_num_array * _pst_parse_block(pst_file *pf, uint32_t block_id, pst_index2_ll *i2_head);
-int32_t _pst_process(pst_num_array *list, pst_item *item, pst_item_attach *attach);
-int32_t _pst_free_list(pst_num_array *list);
-void _pst_freeItem(pst_item *item);
-int32_t _pst_free_id2(pst_index2_ll * head);
-int32_t _pst_free_id (pst_index_ll *head);
-int32_t _pst_free_desc (pst_desc_ll *head);
-int32_t _pst_free_xattrib(pst_x_attrib_ll *x);
-int32_t _pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset_pointer *p);
-int32_t _pst_getBlockOffset(unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset *p);
-pst_index2_ll * _pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr);
-pst_index_ll * _pst_getID(pst_file* pf, uint64_t id);
-pst_index_ll * _pst_getID2(pst_index2_ll * ptr, uint32_t id);
-pst_desc_ll * _pst_getDptr(pst_file *pf, uint32_t id);
-size_t _pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf, int32_t do_enc, unsigned char is_index);
-int32_t _pst_decrypt(unsigned char *buf, size_t size, int32_t type);
-int64_t _getIntAt(char *buf);
-int64_t _pst_getIntAtPos(FILE *fp, off_t pos);
-int32_t _pst_getAtPos(FILE *fp, off_t pos, void* buf, uint32_t size);
-int32_t _pst_get (FILE *fp, void *buf, uint32_t size);
-size_t _pst_ff_getIDblock_dec(pst_file *pf, uint32_t id, unsigned char **b);
-size_t _pst_ff_getIDblock(pst_file *pf, uint32_t id, unsigned char** b);
-size_t _pst_ff_getID2block(pst_file *pf, uint32_t id2, pst_index2_ll *id2_head, unsigned char** buf);
-size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h);
-size_t _pst_ff_compile_ID(pst_file *pf, uint32_t id, struct holder *h, int32_t size);
+int            pst_build_id_ptr(pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val);
+int            pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, uint64_t linku1, uint64_t *high_id, uint64_t start_val, uint64_t end_val);
+pst_item*      pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
+pst_item*      pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr);
+pst_num_array* pst_parse_block(pst_file *pf, uint64_t block_id, pst_index2_ll *i2_head);
+int            pst_process(pst_num_array *list, pst_item *item, pst_item_attach *attach);
+void           pst_free_list(pst_num_array *list);
+void           pst_freeItem(pst_item *item);
+void           pst_free_id2(pst_index2_ll * head);
+void           pst_free_id (pst_index_ll *head);
+void           pst_free_desc (pst_desc_ll *head);
+void           pst_free_xattrib(pst_x_attrib_ll *x);
+int            pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, unsigned char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset_pointer *p);
+int            pst_getBlockOffset(unsigned char *buf, size_t read_size, uint32_t i_offset, uint32_t offset, pst_block_offset *p);
+pst_index2_ll* pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr);
+pst_index_ll*  pst_getID(pst_file* pf, uint64_t id);
+pst_index_ll*  pst_getID2(pst_index2_ll * ptr, uint64_t id);
+pst_desc_ll*   pst_getDptr(pst_file *pf, uint64_t id);
+size_t         pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf, int32_t do_enc, unsigned char is_index);
+int            pst_decrypt(unsigned char *buf, size_t size, unsigned char type);
+uint64_t       pst_getIntAt(pst_file *pf, char *buf);
+uint64_t       pst_getIntAtPos(pst_file *pf, off_t pos);
+int            pst_getAtPos(FILE *fp, off_t pos, void* buf, size_t size);
+int            pst_get (FILE *fp, void *buf, size_t size);
+size_t         pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, unsigned char **b);
+size_t         pst_ff_getIDblock(pst_file *pf, uint64_t id, unsigned char** b);
+size_t         pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_index2_ll *id2_head, unsigned char** buf);
+size_t         pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h);
+size_t         pst_ff_compile_ID(pst_file *pf, uint64_t id, struct holder *h, size_t size);
 
-int32_t pst_strincmp(char *a, char *b, int32_t x);
-int32_t pst_stricmp(char *a, char *b);
-size_t  pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
-char * _pst_wide_to_single(char *wt, int32_t size);
+int            pst_strincmp(char *a, char *b, size_t x);
+int            pst_stricmp(char *a, char *b);
+size_t         pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
+char *         pst_wide_to_single(char *wt, int32_t size);
 
-char *pst_rfc2426_escape(char *str);
-int   pst_chr_count(char *str, char x);
-char *pst_rfc2425_datetime_format(FILETIME *ft);
-char *pst_rfc2445_datetime_format(FILETIME *ft);
+char *         pst_rfc2426_escape(char *str);
+int            pst_chr_count(char *str, char x);
+char *         pst_rfc2425_datetime_format(FILETIME *ft);
+char *         pst_rfc2445_datetime_format(FILETIME *ft);
 
-// DEBUG functions
-int32_t _pst_printDptr(pst_file *pf);
-int32_t _pst_printIDptr(pst_file* pf);
-int32_t _pst_printID2ptr(pst_index2_ll *ptr);
-void * xmalloc(size_t size);
+int32_t        pst_printDptr(pst_file *pf);
+int32_t        pst_printIDptr(pst_file* pf);
+int32_t        pst_printID2ptr(pst_index2_ll *ptr);
 
 #endif // defined LIBPST_H
--- a/src/lspst.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/lspst.c	Sat Jan 12 15:20:53 2008 -0800
@@ -69,7 +69,7 @@
         else {
             DEBUG_MAIN(("main: Desc Email ID %x [d_ptr->id = %x]\n", d_ptr->desc->id, d_ptr->id));
 
-            item = _pst_parse_item(&pstfile, d_ptr);
+            item = pst_parse_item(&pstfile, d_ptr);
             DEBUG_MAIN(("main: About to process item @ %p.\n", item));
             if (item) {
                 if (item->message_store) {
@@ -134,7 +134,7 @@
                     DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
                                       item->type, item->ascii_type));
                 }
-                _pst_freeItem(item);
+                pst_freeItem(item);
             } else {
                 ff.skip_count++;
                 DEBUG_MAIN(("main: A NULL item was seen\n"));
@@ -151,7 +151,6 @@
     pst_desc_ll *d_ptr;
     char *temp  = NULL; //temporary char pointer
     char *d_log = NULL;
-    struct file_ll  *f = NULL, *head = NULL;
 
     if (argc <= 1) DIE(("Missing PST filename.\n"));
 
@@ -168,7 +167,7 @@
     pst_load_extended_attributes(&pstfile);
 
     d_ptr = pstfile.d_head; // first record is main record
-    item  = _pst_parse_item(&pstfile, d_ptr);
+    item  = pst_parse_item(&pstfile, d_ptr);
     if (!item || !item->message_store) {
         DEBUG_RET();
         DIE(("main: Could not get root record\n"));
@@ -193,7 +192,7 @@
     DEBUG_MAIN(("d_ptr(TOF) = %p.\n", d_ptr));
 
     process(item, d_ptr->child);    // do the childred of TOPF
-    _pst_freeItem(item);
+    pst_freeItem(item);
     pst_close(&pstfile);
 
     DEBUG_RET();
--- a/src/pst2ldif.cpp	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/pst2ldif.cpp	Sat Jan 12 15:20:53 2008 -0800
@@ -147,7 +147,7 @@
 	pst_item *item = NULL;
 	while (d_ptr) {
 		if (d_ptr->desc) {
-			item = (pst_item*)_pst_parse_item(&pstfile, d_ptr);
+			item = (pst_item*)pst_parse_item(&pstfile, d_ptr);
 			DEBUG_INFO(("item pointer is %p\n", item));
 			if (item) {
 				if (item->message_store) {
@@ -363,7 +363,7 @@
 					DEBUG_INFO(("item is not a contact\n"));
 				}
 			}
-			_pst_freeItem(item);
+			pst_freeItem(item);
 		}
 		d_ptr = d_ptr->next;
 	}
@@ -431,7 +431,7 @@
 	pst_load_extended_attributes(&pstfile);
 
 	d_ptr = pstfile.d_head; // first record is main record
-	item  = (pst_item*)_pst_parse_item(&pstfile, d_ptr);
+	item  = (pst_item*)pst_parse_item(&pstfile, d_ptr);
 	if (!item || !item->message_store) {
 		DEBUG_RET();
 		DIE(("main: Could not get root record\n"));
@@ -443,7 +443,7 @@
 		DIE(("Top of folders record not found. Cannot continue\n"));
 	}
 
-	_pst_freeItem(item);
+	pst_freeItem(item);
 
 	// write the ldap header
 	printf("dn: %s\n", ldap_base);
--- a/src/readpst.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/readpst.c	Sat Jan 12 15:20:53 2008 -0800
@@ -154,7 +154,7 @@
         else {
             DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id));
 
-            item = _pst_parse_item(&pstfile, d_ptr);
+            item = pst_parse_item(&pstfile, d_ptr);
             DEBUG_MAIN(("main: About to process item\n"));
             if (item && item->email && item->email->subject && item->email->subject->subj) {
                 DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject));
@@ -227,7 +227,7 @@
                     DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
                                 item->type, item->ascii_type));
                 }
-                _pst_freeItem(item);
+                pst_freeItem(item);
             } else {
                 ff.skip_count++;
                 DEBUG_MAIN(("main: A NULL item was seen\n"));
@@ -334,8 +334,8 @@
         }
 
         while (0 != ( l = fread( buf, 1, 1024, fp))) {
-            if (0 != _pst_decrypt( buf, l, PST_COMP_ENCRYPT))
-                fprintf(stderr, "_pst_decrypt() failed (I'll try to continue)\n");
+            if (0 != pst_decrypt( buf, l, PST_COMP_ENCRYPT))
+                fprintf(stderr, "pst_decrypt() failed (I'll try to continue)\n");
 
             if (l != fwrite( buf, 1, l, stdout)) {
                 fprintf(stderr, "Couldn't output to stdout?\n");
@@ -362,7 +362,7 @@
     if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n");
 
     d_ptr = pstfile.d_head; // first record is main record
-    item  = _pst_parse_item(&pstfile, d_ptr);
+    item  = pst_parse_item(&pstfile, d_ptr);
     if (!item || !item->message_store) {
         DEBUG_RET();
         DIE(("main: Could not get root record\n"));
@@ -390,7 +390,7 @@
     }
 
     process(item, d_ptr->child);  // do the children of TOPF
-    _pst_freeItem(item);
+    pst_freeItem(item);
     pst_close(&pstfile);
 
     DEBUG_RET();
@@ -570,12 +570,11 @@
 
 
 char *mk_seperate_dir(char *dir) {
-    DEBUG_ENT("mk_seperate_dir");
-
     size_t dirsize = strlen(dir) + 10;
     char dir_name[dirsize];
     int x = 0, y = 0;
 
+    DEBUG_ENT("mk_seperate_dir");
     do {
         if (y == 0)
             snprintf(dir_name, dirsize, "%s", dir);
@@ -713,7 +712,6 @@
 
 void write_separate_attachment(char f_name[], pst_item_attach* current_attach, int attach_num, pst_file* pst)
 {
-    DEBUG_ENT("write_separate_attachment");
     FILE *fp = NULL;
     int x = 0;
     char *temp = NULL;
@@ -722,6 +720,7 @@
     // use the 8.3 filename (filename1)
     char *attach_filename = (current_attach->filename2) ? current_attach->filename2
                                                         : current_attach->filename1;
+    DEBUG_ENT("write_separate_attachment");
 
     check_filename(f_name);
     if (!attach_filename) {
@@ -749,7 +748,7 @@
         if (current_attach->data)
             fwrite(current_attach->data, 1, current_attach->size, fp);
         else {
-            pst_attach_to_file(pst, current_attach, fp);
+            (void)pst_attach_to_file(pst, current_attach, fp);
         }
         fclose(fp);
     }
@@ -760,8 +759,8 @@
 
 void write_inline_attachment(FILE* f_output, pst_item_attach* current_attach, char boundary[], pst_file* pst)
 {
+    char *enc = NULL; // base64 encoded attachment
     DEBUG_ENT("write_inline_attachment");
-    char *enc; // base64 encoded attachment
     DEBUG_EMAIL(("Attachment Size is %i\n", current_attach->size));
     DEBUG_EMAIL(("Attachment Pointer is %p\n", current_attach->data));
     if (current_attach->data) {
@@ -798,7 +797,7 @@
         DEBUG_EMAIL(("Attachment Size after encoding is %i\n", strlen(enc)));
         free(enc);  // caught by valgrind
     } else {
-        pst_attach_to_file_base64(pst, current_attach, f_output);
+        (void)pst_attach_to_file_base64(pst, current_attach, f_output);
     }
     fprintf(f_output, "\n\n");
     DEBUG_RET();
@@ -807,7 +806,6 @@
 
 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf)
 {
-    DEBUG_ENT("write_normal_email");
     char *boundary = NULL;      // the boundary marker between multipart sections
     int boundary_created = 0;   // we have not (yet) created a new boundary
     char *temp = NULL;
@@ -815,6 +813,7 @@
     time_t em_time;
     char *c_time;
     pst_item_attach* current_attach;
+    DEBUG_ENT("write_normal_email");
 
     // convert the sent date if it exists, or set it to a fixed date
     if (item->email->sent_date) {
--- a/src/readpstlog.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/readpstlog.c	Sat Jan 12 15:20:53 2008 -0800
@@ -21,15 +21,16 @@
 
 int main(int argc, char** argv) {
 	int level = 0;
-	int *i=NULL, x, ptr, stop=0, flag;
+    off_t *i = NULL;
+	int x, ptr, stop=0, flag;
 	char *fname, *buf, rec_type;
 	unsigned char version;
 	int *show_type=NULL, show_size=0;
 	int *ex_type=NULL, ex_size=0;
-	unsigned int funcname, filename, text, end, dtype, line, c;
+	unsigned int funcname=0, filename=0, text=0, end=0, dtype=0, line=0, c;
 	FILE *fp;
-	struct _debug_file_rec_m mfile_rec;
-	struct _debug_file_rec_l lfile_rec;
+	struct pst_debug_file_rec_m mfile_rec;
+	struct pst_debug_file_rec_l lfile_rec;
 	char format = 'D';  // default
 	while ((c = getopt(argc, argv, "f:t:x:")) != -1) {
 		switch(c) {
--- a/src/timeconv.c	Tue Jan 08 16:33:23 2008 -0800
+++ b/src/timeconv.c	Sat Jan 12 15:20:53 2008 -0800
@@ -15,9 +15,6 @@
 #include "common.h"
 #include "timeconv.h"
 
-time_t fileTimeToUnixTime( const FILETIME *filetime, DWORD *remainder );
-char * fileTimeToAscii (const FILETIME *filetime);
-
 char * fileTimeToAscii (const FILETIME *filetime) {
   time_t t1;
 
@@ -80,7 +77,7 @@
     else                        a1 += (1 << 16) - 54590 - carry, carry = 1;
 
     a2 -= 27111902 + carry;
-    
+
     /* If a is negative, replace a by (-1-a) */
     negative = (a2 >= ((UINT32)1) << 31);
     if (negative)
--- a/xml/libpst.in	Tue Jan 08 16:33:23 2008 -0800
+++ b/xml/libpst.in	Sat Jan 12 15:20:53 2008 -0800
@@ -1275,8 +1275,8 @@
             </para>
         </refsect1>
 
-        <refsect1 id='pst.file.list.5'>
-            <title>Associated List Item</title>
+        <refsect1 id='pst.file.list.32.5'>
+            <title>32 bit Associated List Item</title>
             <para>
                 Contains associations between id1 and id2 for the items controlled by the record.
                 In the above 32 bit leaf node, we have a tuple of (0x61, 0x02a82c, 0x02a836, 0)
@@ -1291,7 +1291,28 @@
   repeating
 0004  id2             [4 bytes] 0x00819f   in this case
 0008  id              [4 bytes] 0x02a830   in this case
-000c  unknown         [4 bytes] 0          in this case
+000c  table2          [4 bytes] 0          in this case
+]]></literallayout>
+        </refsect1>
+
+        <refsect1 id='pst.file.list.64.5'>
+            <title>64 bit Associated List Item</title>
+            <para>
+                Contains associations between id1 and id2 for the items controlled by the record.
+            </para>
+            <literallayout class="monospaced"><![CDATA[
+0000  02 00 02 00  00 00 00 00  92 06 00 00  00 00 00 00
+0010  a8 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00
+0020  3f 80 00 00  00 00 00 00  98 00 00 00  00 00 00 00
+0030  00 00 00 00  00 00 00 00
+
+0000  unknown         [2 bytes] 0x0002     constant
+0002  count           [2 bytes] 0x0002     in this case
+0004  unknown         [4 bytes] 0   	   possibly constant
+  repeating
+0008  id2             [8 bytes] 0x000692   in this case
+0008  id              [8 bytes] 0x0000a8   in this case
+000c  table2          [8 bytes] 0          in this case
 ]]></literallayout>
         </refsect1>