Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 11033)
+++ trunk/ippTools/src/regtool.c	(revision 11037)
@@ -52,4 +52,6 @@
 int main(int argc, char **argv)
 {
+    psExit exit_status = PS_EXIT_SUCCESS;
+
     psLibInit(NULL);
 
@@ -72,7 +74,10 @@
     psLibFinalize();
 
-    exit(EXIT_SUCCESS);
+    exit(exit_status);
 
 FAIL:
+    // use the top-most error to determine the exit status
+    exit_status = pxerrorGetExitStatus();
+
     psFree(config);
     pmConfigDone();
@@ -80,5 +85,5 @@
     psLibFinalize();
 
-    exit(EXIT_FAILURE);
+    exit(exit_status);
 }
 
@@ -90,5 +95,5 @@
     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
         return false;
     }
@@ -96,5 +101,5 @@
     bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
     if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -faulted");
         return false;
     }
@@ -141,5 +146,6 @@
 
     if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
+        psError(PXTOOLS_ERR_PROG, false, "database error");
         psFree(query);
         return false;
@@ -149,10 +155,9 @@
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
+        psError(PXTOOLS_ERR_PROG, false, "database error");
         return false;
     }
     if (!psArrayLength(output)) {
-        // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending newExp rows found");
         psFree(output);
         return true;
@@ -160,16 +165,13 @@
 
     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;
-        }
+    simple = psMetadataLookupBool(&status, config->args, "-simple");
+    if (!status) {
+	psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -simple");
+	return false;
     }
 
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "p0PendingExp", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psError(PXTOOLS_ERR_PROG, false, "failed to print array");
         psFree(output);
         return false;
@@ -188,5 +190,5 @@
     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
         return false;
     }
@@ -194,5 +196,5 @@
     bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
     if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
+        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -faulted");
         return false;
     }
@@ -231,5 +233,6 @@
 
     if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
+        psError(PXTOOLS_ERR_PROG, false, "database error");
         psFree(query);
         return false;
@@ -239,10 +242,9 @@
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
+	// XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms)
+        psError(PXTOOLS_ERR_PROG, false, "database error");
         return false;
     }
     if (!psArrayLength(output)) {
-        // XXX check psError here
-        psError(PS_ERR_UNKNOWN, false, "no pending newImfile rows found");
         psFree(output);
         return true;
@@ -250,16 +252,13 @@
 
     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;
-        }
+    simple = psMetadataLookupBool(&status, config->args, "-simple");
+    if (!status) {
+	psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -simple");
+	return false;
     }
 
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "newImfile", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psError(PXTOOLS_ERR_PROG, false, "failed to print array");
         psFree(output);
         return false;
@@ -1094,21 +1093,2 @@
     return raw;
 }
-
-#if 0
-static psU32 mapCodeStrToInt(const char *codeStr)
-{
-    if (strcasestr(codeStr, "none")) {
-        return PX_ERROR_NONE;
-    } else if (strcasestr(codeStr, "unknown")) {
-        return PX_ERROR_UNKNOWN;
-    } else if (strcasestr(codeStr, "bad_data")) {
-        return PX_ERROR_BAD_DATA;
-    } else if (strcasestr(codeStr, "id10t")) {
-        return PX_ERROR_ID10T;
-    }
-
-    psError(PS_ERR_UNKNOWN, true, "invalid fault code string");
-
-    return (psU32) -1;
-}
-#endif
