Index: /branches/end_stage/ippTools/src/pzgetexp.c
===================================================================
--- /branches/end_stage/ippTools/src/pzgetexp.c	(revision 16100)
+++ /branches/end_stage/ippTools/src/pzgetexp.c	(revision 16101)
@@ -69,24 +69,8 @@
     PS_ASSERT_PTR_NON_NULL(config, NULL);
 
-    bool status = false;
-    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
-        return false;
-    }
-    if (!camera) {
-        psError(PS_ERR_UNKNOWN, true, "-inst is required");
-        return false;
-    }
-
-    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
-        return false;
-    }
-    if (!telescope) {
-        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
-        return false;
-    }
+    // required
+    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
+    PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false);
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false);
 
     // find last fileset/exp_name (if we have one)
@@ -119,5 +103,4 @@
     // invoke dsproductls
     // dsproductls --uri <> --last_fileset <>
-    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     psString cmd = NULL;
     if (haveLastFileSet) {
@@ -275,15 +258,7 @@
     // these are constants for all records parsed -- look them up before we do
     // any work
-    bool status = false;
-    char *camera = psMetadataLookupStr(&status, config->args, "-inst");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup item '-inst'");
-        return NULL;
-    }
-    char *telescope = psMetadataLookupStr(&status, config->args, "-telescope");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup item '-telescope'");
-        return NULL;
-    }
+    // required
+    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
+    PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false);
 
     // split the string into lines
Index: /branches/end_stage/ippTools/src/pzgetimfiles.c
===================================================================
--- /branches/end_stage/ippTools/src/pzgetimfiles.c	(revision 16100)
+++ /branches/end_stage/ippTools/src/pzgetimfiles.c	(revision 16101)
@@ -2,5 +2,5 @@
  * pzgetimfiles.c
  *
- * Copyright (C) 2006  Joshua Hoblitt
+ * Copyright (C) 2006-2008  Joshua Hoblitt
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -70,44 +70,9 @@
     PS_ASSERT_PTR_NON_NULL(config, NULL);
 
-    bool status = false;
-    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
-        return false;
-    }
-    if (!uri) {
-        psError(PS_ERR_UNKNOWN, true, "-uri is required");
-        return false;
-    }
-
-    psString filesetid = psMetadataLookupStr(&status, config->args, "-filesetid");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -filesetid");
-        return false;
-    }
-    if (!filesetid) {
-        psError(PS_ERR_UNKNOWN, true, "-filesetid is required");
-        return false;
-    }
-
-    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
-        return NULL;
-    }
-    if (!camera) {
-        psError(PS_ERR_UNKNOWN, true, "-inst is required");
-        return NULL;
-    }
-
-    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
-        return NULL;
-    }
-    if (!telescope) {
-        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
-        return NULL;
-    }
+    // required
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false);
+    PXOPT_LOOKUP_STR(filesetid, config->args, "-filesetid", true, false);
+    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
+    PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false);
 
     // invoke dsfilesetls
@@ -429,34 +394,7 @@
     // these are constants for all records parsed -- look them up before we do
     // any work
-    bool status = false;
-    psString exp_name = psMetadataLookupStr(&status, config->args, "-filesetid");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for '-filesetid'");
-        return NULL;
-    }
-    if (!exp_name) {
-        psError(PS_ERR_UNKNOWN, true, "-filesetid is required");
-        return NULL;
-    }
-
-    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
-        return NULL;
-    }
-    if (!camera) {
-        psError(PS_ERR_UNKNOWN, true, "-inst is required");
-        return NULL;
-    }
-
-    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
-        return NULL;
-    }
-    if (!telescope) {
-        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
-        return NULL;
-    }
+    PXOPT_LOOKUP_STR(exp_name, config->args, "-filesetid", true, false);
+    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
+    PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false);
 
     // split the string into lines
Index: /branches/end_stage/ippTools/src/pztool.c
===================================================================
--- /branches/end_stage/ippTools/src/pztool.c	(revision 16100)
+++ /branches/end_stage/ippTools/src/pztool.c	(revision 16101)
@@ -92,34 +92,8 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
-        return false;
-    }
-    if (!camera) {
-        psError(PS_ERR_UNKNOWN, true, "-inst is required");
-        return false;
-    }
-
-    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
-        return false;
-    }
-    if (!telescope) {
-        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
-        return false;
-    }
-
-    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
-        return false;
-    }
-    if (!uri) {
-        psError(PS_ERR_UNKNOWN, true, "-uri is required");
-        return false;
-    }
+    // required
+    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
+    PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false);
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false);
 
     if (!pzDataStoreInsert(config->dbh,
@@ -139,4 +113,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+
     if (!p_psDBRunQuery(config->dbh, "SELECT * FROM pzDataStore")) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -153,14 +129,4 @@
         psFree(output);
         return true;
-    }
-
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
     }
 
@@ -180,4 +146,6 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
+
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     psString query = psStringCopy("SELECT * FROM summitExp");
@@ -207,14 +175,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            return false;
-        }
-    }
-
     // negative simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "summitExp", !simple)) {
@@ -233,10 +191,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     psString query = psStringCopy(
@@ -279,15 +233,4 @@
     }
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            psFree(output);
-            return false;
-        }
-    }
-
     // negative simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "pzPendingExp", !simple)) {
@@ -306,10 +249,6 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
-        return false;
-    }
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
     psArray *cameras = pzGetPendingCameras(config);
@@ -330,4 +269,5 @@
         }
 
+        bool status;
         psString camera = psMetadataLookupStr(&status, cameras->data[i], "camera");
         psStringAppend(&query, " WHERE camera = \"%s\"", camera);
@@ -380,15 +320,4 @@
     psFree(cameraImfiles);
 
-    bool simple = false;
-    {
-        bool status = false;
-        simple = psMetadataLookupBool(&status, config->args, "-simple");
-        if (!status) {
-            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
-            psFree(output);
-            return false;
-        }
-    }
-
     // negative simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "pzPendingImfile", !simple)) {
@@ -407,64 +336,11 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    bool status = false;
-    psString exp_name = psMetadataLookupStr(&status, config->args, "-exp_name");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_name");
-        return false;
-    }
-    if (!exp_name) {
-        psError(PS_ERR_UNKNOWN, true, "-exp_name is required");
-        return false;
-    }
-
-    psString camera = psMetadataLookupStr(&status, config->args, "-inst");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -inst");
-        return NULL;
-    }
-    if (!camera) {
-        psError(PS_ERR_UNKNOWN, true, "-inst is required");
-        return NULL;
-    }
-
-    psString telescope = psMetadataLookupStr(&status, config->args, "-telescope");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -telescope");
-        return NULL;
-    }
-    if (!telescope) {
-        psError(PS_ERR_UNKNOWN, true, "-telescope is required");
-        return NULL;
-    }
-
-    psString class = psMetadataLookupStr(&status, config->args, "-class");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class");
-        return NULL;
-    }
-    if (!class) {
-        psError(PS_ERR_UNKNOWN, true, "-class is required");
-        return NULL;
-    }
-
-    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
-        return NULL;
-    }
-    if (!class_id) {
-        psError(PS_ERR_UNKNOWN, true, "-class_id is required");
-        return NULL;
-    }
-
-    psString uri = psMetadataLookupStr(&status, config->args, "-uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");
-        return false;
-    }
-    if (!uri) {
-        psError(PS_ERR_UNKNOWN, true, "-uri is required");
-        return false;
-    }
+    // required
+    PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false);
+    PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false);
+    PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false);
+    PXOPT_LOOKUP_STR(class, config->args, "-class", true, false);
+    PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
+    PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false);
 
     // need to know exp_name, camera, telescope, class, class_id (to find the
@@ -476,5 +352,4 @@
         return false;
     }
-  
 
     // cp the imfile into pzDoneImfile
