Index: trunk/include/regfio.h
===================================================================
--- trunk/include/regfio.h	(revision 53)
+++ trunk/include/regfio.h	(revision 54)
@@ -57,6 +57,6 @@
 #define REG_BINARY 	               3
 #define REG_DWORD	               4
-#define REG_DWORD_LE	               4	/* DWORD, little endian */
-#define REG_DWORD_BE	               5	/* DWORD, big endian */
+#define REG_DWORD_LE	               4  /* DWORD, little endian */
+#define REG_DWORD_BE	               5  /* DWORD, big endian */
 #define REG_LINK                       6
 #define REG_MULTI_SZ  	               7
@@ -95,6 +95,7 @@
 #define NK_TYPE_ROOTKEY		0x002c
 
-#define HBIN_STORE_REF(x, y)	{ x->hbin = y; y->ref_count++ };
-#define HBIN_REMOVE_REF(x, y)	{ x->hbin = NULL; y->ref_count-- /* if the count == 0; we can clean up */ };
+#define HBIN_STORE_REF(x, y) { x->hbin = y; y->ref_count++ };
+/* if the count == 0; we can clean up */
+#define HBIN_REMOVE_REF(x, y){ x->hbin = NULL; y->ref_count-- };
 
 
@@ -107,15 +108,18 @@
   uint32 free_off;       /* offset to free space within the hbin record */
   uint32 free_size;      /* amount of data left in the block */
-  int    ref_count;      /* how many active records are pointing to this block (not used currently) */
+  int    ref_count;      /* how many active records are pointing to this
+                          * block (not used currently) 
+			  */
 	
   uint8  header[HBIN_HDR_SIZE]; /* "hbin" */
   uint32 first_hbin_off; /* offset from first hbin block */
-  uint32 block_size;     /* block size of this blockually a multiple of 4096Kb) */
-  prs_struct ps;	       /* data */
+  uint32 block_size;     /* block size of this block is
+                          * usually a multiple of 4096Kb 
+			  */
+  prs_struct ps;	 /* data */
   bool dirty;            /* has this hbin block been modified? */
 } REGF_HBIN;
 
 /* ??? List -- list of key offsets and hashed names for consistency */
-
 typedef struct {
   uint32 nk_off;
@@ -124,7 +128,9 @@
 
 typedef struct {
-  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing this nk record */
-  uint32 hbin_off;	/* offset from beginning of this hbin block */
-  uint32 rec_size;	/* ((start_offset - end_offset) & 0xfffffff8) */
+  REGF_HBIN *hbin;       /* pointer to HBIN record (in memory) containing 
+			  * this nk record 
+			  */
+  uint32 hbin_off;	 /* offset from beginning of this hbin block */
+  uint32 rec_size;	 /* ((start_offset - end_offset) & 0xfffffff8) */
   
   uint8 header[REC_HDR_SIZE];
@@ -136,8 +142,10 @@
 
 typedef struct {
-  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing this nk record */
+  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing 
+			 * this nk record 
+			 */
   uint32 hbin_off;	/* offset from beginning of this hbin block */
   uint32 rec_size;	/* ((start_offset - end_offset) & 0xfffffff8) */
-  uint32 rec_off;		/* offset stored in the value list */
+  uint32 rec_off;	/* offset stored in the value list */
   
   uint8  header[REC_HDR_SIZE];
@@ -156,10 +164,13 @@
 typedef struct _regf_sk_rec {
   struct _regf_sk_rec *next, *prev;
-  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing this nk record */
+  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing 
+			 * this nk record 
+			 */
   uint32 hbin_off;	/* offset from beginning of this hbin block */
   uint32 rec_size;	/* ((start_offset - end_offset) & 0xfffffff8) */
   
-  uint32 sk_off;		/* offset parsed from NK record used as a key
-				   to lookup reference to this SK record */
+  uint32 sk_off;	/* offset parsed from NK record used as a key
+			 * to lookup reference to this SK record 
+			 */
   
   uint8  header[REC_HDR_SIZE];
@@ -174,5 +185,7 @@
 
 typedef struct {
-  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing this nk record */
+  REGF_HBIN *hbin;	/* pointer to HBIN record (in memory) containing 
+			 * this nk record 
+			 */
   uint32 hbin_off;	/* offset from beginning of this hbin block */
   uint32 subkey_index;	/* index to next subkey record to return */
@@ -180,5 +193,4 @@
   
   /* header information */
-  
   uint8  header[REC_HDR_SIZE];
   uint16 key_type;
@@ -190,24 +202,20 @@
   
   /* max lengths */
-  
-  uint32 max_bytes_subkeyname;		/* max subkey name * 2 */
-  uint32 max_bytes_subkeyclassname;	/* max subkey classname length (as if) */
-  uint32 max_bytes_valuename;		/* max valuename * 2 */
-  uint32 max_bytes_value;			/* max value data size */
+  uint32 max_bytes_subkeyname;	    /* max subkey name * 2 */
+  uint32 max_bytes_subkeyclassname; /* max subkey classname length (as if) */
+  uint32 max_bytes_valuename;	    /* max valuename * 2 */
+  uint32 max_bytes_value;           /* max value data size */
   
   /* unknowns */
-  
-  uint32 unk_index;			/* nigel says run time index ? */
+  uint32 unk_index;		    /* nigel says run time index ? */
   
   /* children */
-  
   uint32 num_subkeys;
   uint32 subkeys_off;	/* hash records that point to NK records */	
   uint32 num_values;
   uint32 values_off;	/* value lists which point to VK records */
-  uint32 sk_off;		/* offset to SK record */
+  uint32 sk_off;	/* offset to SK record */
   
   /* link in the other records here */
-  
   REGF_LF_REC subkeys;
   REGF_VK_REC *values;
@@ -220,22 +228,24 @@
 typedef struct {
   /* run time information */
-  
-  int fd;				/* file descriptor */
-  int open_flags;			/* flags passed to the open() call */
-  void *mem_ctx;		/* memory context for run-time file access information */
-  REGF_HBIN *block_list;		/* list of open hbin blocks */
+  int fd;	  /* file descriptor */
+  int open_flags; /* flags passed to the open() call */
+  void *mem_ctx;  /* memory context for run-time file access information */
+  REGF_HBIN *block_list; /* list of open hbin blocks */
   
   /* file format information */
   
   uint8  header[REGF_HDR_SIZE];	/* "regf" */
-  uint32 data_offset;		/* offset to record in the first (or any?) hbin block */
+  uint32 data_offset;		/* offset to record in the first (or any?) 
+				 * hbin block 
+				 */
   uint32 last_block;		/* offset to last hbin block in file */
   uint32 checksum;		/* XOR of bytes 0x0000 - 0x01FB */
   NTTIME mtime;
   
-  REGF_SK_REC *sec_desc_list;	/* list of security descriptors referenced by NK records */
+  REGF_SK_REC *sec_desc_list;	/* list of security descriptors referenced 
+				 * by NK records 
+				 */
   
   /* unknowns used to simply writing */
-  
   uint32 unknown1;
   uint32 unknown2;
@@ -247,6 +257,7 @@
 
 
+/******************************************************************************/
 /* Function Declarations */
- 
+
 const char*   regfio_type_val2str(unsigned int val);
 int           regfio_type_str2val(const char* str);
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 53)
+++ trunk/src/reglookup.c	(revision 54)
@@ -184,5 +184,5 @@
 
   /* XXX: this MULTI_SZ parser is pretty inefficient.  Should be
-   *      redone with fewer malloc and better string concatenation. 
+   *      redone with fewer malloc calls and better string concatenation. 
    */
   case REG_MULTI_SZ:
@@ -317,6 +317,5 @@
   if (buf == NULL)
     return NULL;
-  buf[0] = '/';
-  buf[1] = '\0';
+  buf[0] = '\0';
 
   iter = void_stack_iterator_new(nk_stack);
@@ -472,5 +471,5 @@
 
 
-/* XXX: this function is god-awful.  Needs to be re-designed. */
+/* XXX: this function is awful.  Needs to be re-designed. */
 void printKeyTree(REGF_FILE* f, void_stack* nk_stack, char* prefix)
 {
@@ -479,5 +478,4 @@
   char* path = NULL;
   char* val_path = NULL;
-
   int key_type = regfio_type_str2val("KEY");
   
@@ -486,11 +484,24 @@
     cur->subkey_index = 0;
     path = stack2Path(nk_stack);
-    
+
+    if(print_verbose)
+    {
+      if(prefix[0] == '\0')
+	fprintf(stderr, "VERBOSE: Printing key tree under path: /\n");
+      else
+	fprintf(stderr, "VERBOSE: Printing key tree under path: %s\n",
+		prefix);
+    }
 
     val_path = (char*)malloc(strlen(prefix)+strlen(path)+1);
     sprintf(val_path, "%s%s", prefix, path);
+    if(val_path[0] == '\0')
+    {
+      val_path[0] = '/';
+      val_path[1] = '\0';
+    }
+
     if(!type_filter_enabled || (key_type == type_filter))
       printKey(cur, val_path);
-
     if(!type_filter_enabled || (key_type != type_filter))
       printValueList(cur, val_path);
@@ -527,4 +538,6 @@
     }
   }
+  if(print_verbose)
+    fprintf(stderr, "VERBOSE: Finished printing key tree.\n");
 }
 
@@ -559,4 +572,8 @@
   cur = (REGF_NK_REC*)void_stack_cur(nk_stack);
 
+  if(print_verbose)
+    fprintf(stderr, "VERBOSE: Beginning retrieval of specified path: %s\n", 
+	    path_filter);
+
   while(void_stack_size(path_stack) > 1)
   {
@@ -575,6 +592,9 @@
       }
     }
+    if(print_verbose && !found_cur)
+      fprintf(stderr, "VERBOSE: Could not find KEY '%s' in specified path.\n", 
+	      cur_str);
+
     free(cur_str);
-
     if(!found_cur)
       return 1;
@@ -583,4 +603,8 @@
   /* Last round, search value and key records */
   cur_str = (char*)void_stack_pop(path_stack);
+
+  if(print_verbose)
+    fprintf(stderr, "VERBOSE: Searching values for last component"
+	            " of specified path.\n");
 
   for(i=0; (i < cur->num_values); i++)
@@ -594,7 +618,15 @@
       if(path != NULL)
 	free(path);
+
+      if(print_verbose)
+	fprintf(stderr, "VERBOSE: Found final path element as value.\n");
+
       return 0;
     }
   }
+
+  if(print_verbose)
+    fprintf(stderr, "VERBOSE: Searching keys for last component"
+	            " of specified path.\n");
 
   while((sub = regfio_fetch_subkey(f, cur)) != NULL)
@@ -611,8 +643,16 @@
       strcat(prefix, "/");
       strcat(prefix, sub->keyname);
+
+      if(print_verbose)
+	fprintf(stderr, "VERBOSE: Found final path element as key.\n");
+
       printKeyTree(f, sub_nk_stack, prefix);
+
       return 0;
     }
   }
+
+  if(print_verbose)
+    fprintf(stderr, "VERBOSE: Could not find last element of path.\n");
 
   return 1;
