Index: trunk/ippTools/src/regtoolConfig.c
===================================================================
--- trunk/ippTools/src/regtoolConfig.c	(revision 7815)
+++ trunk/ippTools/src/regtoolConfig.c	(revision 7820)
@@ -6,8 +6,8 @@
 
 #include "pxtools.h"
-#include "dettool.h"
+#include "p0search.h"
 
 // this function can not fail -- exits on error
-bool p0searchConfig(pxConfig *config, int argc, char **argv) {
+pxConfig *p0searchConfig(pxConfig *config, int argc, char **argv) {
     if (!config) {
         config = pxConfigAlloc();
@@ -15,10 +15,9 @@
 
     // setup site config
-    config->modules = pmConfigRead(argc, argv);
+    config->modules = pmConfigRead(&argc, argv);
     if (!config->modules) {
         psError(PS_ERR_UNKNOWN, false, "Can't find site configuration");
         goto FAIL;
     }
-    argc = config->argc;
 
     // -pending
@@ -50,4 +49,6 @@
 
 #define PXTOOL_MODE(option, modeval, argset) \
+{ \
+    int N = 0; \
     if ((N = psArgumentGet (argc, argv, option))) { \
         psArgumentRemove (N, &argc, argv); \
@@ -57,10 +58,10 @@
         config->mode = modeval; \
         config->args = psMemIncrRefCounter(argset); \
-    }
+    } \
+}
 
     // find which mode we're running under
     PXTOOL_MODE("-pending",     P0SEARCH_MODE_PENDING,      pendingArgs);
-    PXTOOL_MODE("-update",      P0SEARCH_MODE_UPDATE,       updatergs);
-
+    PXTOOL_MODE("-update",      P0SEARCH_MODE_UPDATE,       updateArgs);
 
     bool argErr = false;
@@ -68,5 +69,5 @@
         argErr = true;
         fprintf (stderr, "mode argument is required\n");
-    } else if (! psArgumentParse(args, &argc, argv) || argc != 1) {
+    } else if (! psArgumentParse(config->args, &argc, argv) || argc != 1) {
         argErr = true;
         fprintf (stderr, "error parsing arguments\n");
@@ -104,99 +105,25 @@
 {
     psString str = NULL;
-    int n = 0;
     bool status = false;
-    bool boolean = false;
 
+    addWhereStr(exp_id);
+    // convert '-inst' to 'camera'
+    if ((str = psMetadataLookupStr(&status, config->args, "-inst"))) {
+        if (!psMetadataAddStr(config->where, PS_LIST_TAIL, "camera", 0, "==", str)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item camera");
+            goto FAIL;
+        }
+    }
+    addWhereStr(telescope);
+    addWhereStr(exp_type);
+    addWhereStr(class_id);
+    addWhereStr(filter);
+}
 
-    switch (config->mode) {
-        bool status;
-        case PX_MODE_PENDING:
-            // -exp_id
-            config->exp_id = psMetadataLookupStr(&status, args, "-exp_id");
-            psMemIncrRefCounter(config->exp_id);
-            EMPTY_TO_NULL_STRING(config->exp_id);
-            // -inst
-            config->camera_name = psMetadataLookupStr(&status, args, "-inst");
-            psMemIncrRefCounter(config->camera_name);
-            EMPTY_TO_NULL_STRING(config->camera_name);
-            // -telescope
-            config->camera_name = psMetadataLookupStr(&status, args,
-                "-telescope");
-            psMemIncrRefCounter(config->telescope);
-            EMPTY_TO_NULL_STRING(config->telescope);
-            // -exp_type
-            config->class = psMetadataLookupStr(&status, args, "-exp_type");
-            psMemIncrRefCounter(config->exp_type);
-            EMPTY_TO_NULL_STRING(config->exp_type);
-            // -class
-            config->class = psMetadataLookupStr(&status, args, "-class");
-            psMemIncrRefCounter(config->class);
-            EMPTY_TO_NULL_STRING(config->class);
-            break;
-        case PX_MODE_UPDATE:
-            // -exp_id
-            config->exp_id = psMetadataLookupStr(&status, args, "-exp_id");
-            psMemIncrRefCounter(config->exp_id);
-            EMPTY_TO_NULL_STRING(config->exp_id);
-            // -filter
-            config->filter = psMetadataLookupStr(&status, args, "-filter");
-            psMemIncrRefCounter(config->filter);
-            EMPTY_TO_NULL_STRING(config->filter);
-
-            break;
-        default:
-            psAbort(argv[0], "invalid option (this should not happen)");
+    if (config->where->list->n < 1) {
+        psFree(config->where);
+        config->where = NULL;
     }
 
-    psFree(args);
-    psFree(pendingArgs);
-    psFree(updateArgs);
-
-
-    psMetadata *where = psMetadataAlloc();
-
-    if (config->camera_name != NULL) {
-        if (!psMetadataAddStr(where, PS_LIST_TAIL, "camera", 0, "==",
-            config->camera_name)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to add item camera");
-            psFree(where);
-            return NULL;
-        }
-    }
-    if (config->filter != NULL) {
-        psMetadataAddStr(where, PS_LIST_TAIL, "filter", 0, "==",
-            config->filter);
-    }
-    if (config->exp_id != NULL) {
-        psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==",
-            config->exp_id);
-    }
-    if (config->class != NULL) {
-        psMetadataAddStr(where, PS_LIST_TAIL, "class", 0, "==",
-            config->class);
-    }
-    if (config->class_id != NULL) {
-        psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==",
-             config->class_id);
-    }
-
-    /*
-    // psMetadataConfig does not support times yet
-    if (!psTimeIsZero(config->start) && !psTimeIsZero(config->stop)) {
-        psMetadataAddTime (where, PS_LIST_TAIL, "TIME_START", 0, "<", config->stop);
-        psMetadataAddTime (where, PS_LIST_TAIL, "TIME_STOP", 0, ">", config->start);
-    }
-    */
-
-    if (where->list->n < 1) {
-        psFree(where);
-        where = NULL;
-    }
-
-    config->where = where;
-
-
-    // add the input and output images to the args list
-    //psMetadataAddStr (args, PS_LIST_TAIL, "-output", 0, "Name of the output image", argv[1]);
 
     // define Database handle, if used
