Index: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	(revision 36)
+++ trunk/src/Makefile	(revision 37)
@@ -12,5 +12,5 @@
 	$(CC) $(CFLAGS) $(OPTS) -o $@ reglookup.o $(LIBS)
 
-reglookup.o:
+reglookup.o: reglookup.c
 	$(CC) $(CFLAGS) $(OPTS) -c -o $@ reglookup.c
 
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 36)
+++ trunk/src/reglookup.c	(revision 37)
@@ -28,11 +28,17 @@
 #include "../include/void_stack.h"
 
-
+/* XXX: this needs to be rewritten to malloc each resulting string, instead of
+ *      altering them in place
+ */
 void_stack* path2Stack(const char* s)
 {
   void_stack* ret_val = void_stack_new(1024);
-  char* cur = strdup(s);
   char* next = NULL;
-  
+  char* cur;
+  if (s == NULL)
+    return ret_val;
+  else
+    cur = strdup(s);
+
   while((next = strrchr(cur, '/')) != NULL)
   {
@@ -51,8 +57,8 @@
 {
   const REGF_NK_REC* cur;
-  unsigned int buf_left = 127;
-  unsigned int buf_len = buf_left+1;
-  unsigned int name_len = 0;
-  unsigned int grow_amt;
+  uint32 buf_left = 127;
+  uint32 buf_len = buf_left+1;
+  uint32 name_len = 0;
+  uint32 grow_amt;
   char* buf; 
   char* new_buf;
@@ -81,5 +87,5 @@
     if(name_len+1 > buf_left)
     {
-      grow_amt = (unsigned int)(buf_len/2);
+      grow_amt = (uint32)(buf_len/2);
       buf_len += name_len+1+grow_amt-buf_left;
       if((new_buf = realloc(buf, buf_len)) == NULL)
@@ -112,9 +118,10 @@
 void printValueList(REGF_NK_REC* nk, char* prefix)
 {
-  unsigned int i;
+  uint32 i;
   
   for(i=0; i < nk->num_values; i++)
     printValue(&nk->values[i], prefix);
 }
+
 
 /* XXX: this function is god-awful.  Needs to be re-designed. */
@@ -179,6 +186,6 @@
   char* cur_str = NULL;
   bool found_cur = true;
-  unsigned int i;
-  unsigned short path_depth;
+  uint32 i;
+  uint16 path_depth;
   if(path_stack == NULL)
     return -1;
@@ -210,5 +217,5 @@
 
     if(!found_cur)
-      return 0;
+      return 1;
   }
 
@@ -242,4 +249,27 @@
 
 
+static void usage(void)
+{
+  fprintf(stderr, "Usage: readreg [-f <PREFIX_FILTER>] [-t <TYPE_FILTER>] "
+                  "[-v] [-s] <REGISTRY_FILE>\n");
+  /* XXX: replace version string with Subversion property? */
+  fprintf(stderr, "Version: 0.2\n");
+  fprintf(stderr, "\n\t-v\t sets verbose mode.");
+  fprintf(stderr, "\n\t-f\t a simple prefix filter.");
+  fprintf(stderr, "\n\t-t\t restrict results to a specific type.");
+  fprintf(stderr, "\n\t-s\t prints security descriptors.");
+  fprintf(stderr, "\n");
+}
+
+/* Globals, influenced by command line parameters */
+bool print_verbose = false;
+bool print_security = false;
+bool prefix_filter_enabled = false;
+bool type_filter_enabled = false;
+char* prefix_filter = NULL;
+char* type_filter = NULL;
+char* registry_file = NULL;
+
+
 int main(int argc, char** argv)
 {
@@ -249,30 +279,93 @@
   REGF_NK_REC* root;
   int retr_path_ret;
-  char* path = "/ControlSet002/Services/Eventlog/";
-
+  uint32 argi;
+
+  /* Process command line arguments */
   if(argc < 2)
   {
     printf("ERROR: Requires 1 argument.\n");
-    return 1;
-  }
-
-  f = regfio_open( argv[1] );
+    usage();
+    exit(1);
+  }
+  
+  for(argi = 1; argi < argc; argi++)
+  {
+    if (strcmp("-f", argv[argi]) == 0)
+    {
+      if(++argi > argc)
+      {
+	fprintf(stderr, "ERROR: '-f' option requires parameter.\n");
+	usage();
+	exit(1);
+      }
+      if((prefix_filter = strdup(argv[argi])) == NULL)
+      {
+	fprintf(stderr, "ERROR: Memory allocation problem.\n");
+	exit(2);
+      }
+      prefix_filter_enabled = true;
+    }
+    else if (strcmp("-t", argv[argi]) == 0)
+    {
+      if(++argi > argc)
+      {
+	fprintf(stderr, "ERROR: '-t' option requires parameter.\n");
+	usage();
+	exit(1);
+      }
+      if((prefix_filter = strdup(argv[argi])) == NULL)
+      {
+	fprintf(stderr, "ERROR: Memory allocation problem.\n");
+	exit(2);
+      }
+      type_filter_enabled = true;
+    }
+    else if (strcmp("-s", argv[argi]) == 0)
+      print_security = true;
+    else if (strcmp("-v", argv[argi]) == 0)
+      print_verbose = true;
+    else if (argv[argi][0] == '-')
+    {
+      fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]);
+      usage();
+      exit(1);
+    }
+    else
+    {
+      if((registry_file = strdup(argv[argi])) == NULL)
+      {
+	fprintf(stderr, "ERROR: Memory allocation problem.\n");
+	exit(2);
+      }      
+    }
+  }
+
+  f = regfio_open(registry_file);
+  if(f == NULL)
+  {
+    fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
+    exit(1);
+  }
   root = regfio_rootkey(f);
-
   nk_stack = void_stack_new(1024);
+
   if(void_stack_push(nk_stack, root))
   {
-    path_stack = path2Stack(path);
+    path_stack = path2Stack(prefix_filter);
     if(void_stack_size(path_stack) < 1)
       printKeyTree(f, nk_stack, "");
     else
     {
-      retr_path_ret = retrievePath(f, nk_stack, 
-				   path_stack);
+      retr_path_ret = retrievePath(f, nk_stack, path_stack);
       if(retr_path_ret == 1)
-	printf("WARNING: specified path not found.\n");
+	fprintf(stderr, "WARNING: specified path not found.\n");
       else if(retr_path_ret != 0)
-	printf("ERROR\n");
-    }
+	fprintf(stderr, "ERROR:\n");
+    }
+  }
+  else
+  {
+    fprintf(stderr, "ERROR: Memory allocation problem.\n");
+    exit(2);
   }
   void_stack_destroy(nk_stack);
