Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 6262)
+++ trunk/ippTools/src/regtool.c	(revision 6262)
@@ -0,0 +1,132 @@
+#include <stdlib.h>
+
+#include "pxtools.h"
+
+static bool pendingMode(pxConfig *config);
+static bool updateMode(pxConfig *config);
+
+int main(int argc, char **argv)
+{
+    pxConfig        config; 
+
+    p0searchConfig(&config, argc, argv);
+
+    switch (config.mode) {
+        case PX_MODE_PENDING:
+            if (!pendingMode(&config)) {
+                exit(EXIT_FAILURE);
+            }
+            break;
+        case PX_MODE_UPDATE:
+            if (!updateMode(&config)) {
+                exit(EXIT_FAILURE);
+            }
+            break;
+        default:
+            psAbort(argv[0], "invalid option (this should not happen)");
+    }
+
+    exit(EXIT_SUCCESS);
+}
+
+static bool pendingMode(pxConfig *config)
+{
+    psArray *pendingFrames = newFrameSearch(config);
+    if (!pendingFrames) {
+        psError(PS_ERR_UNKNOWN, false, "no newFrames found");
+        return false;
+    }
+    bool status = newFramePrint(stdout, config, pendingFrames);
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false,"newFramePrint() failed");
+        return false;
+    }
+
+    return true;
+}
+
+static bool updateMode(pxConfig *config)
+{
+    // get exp_id/class/class_id/url from the CLI // add the completed imfile to
+    // the p2DoneImfile tables // remove corresponding entries from the
+    // p2PendingImfile table // check to see if any p2PendingExps have no
+    // associated p2PendingImfiles //    if so move the p2PendingExp(s) to
+    // p2DoneExp
+
+    // find pending
+    psArray *pendingImfiles = p2searchPendingImfiles(config);
+    if (!pendingImfiles) {
+        psError(PS_ERR_UNKNOWN, false, "no p2PendingImfiles found");
+        return false;
+    }
+    // insert into done
+    psArray *doneImfiles = p2pendingToDoneImfile(pendingImfiles);
+    for (int i = 0; i < doneImfiles->n; i++) {
+        if (!p2DoneImfileInsertObject(config->database, doneImfiles->data[i])) {
+            psError(PS_ERR_UNKNOWN, false, "database access failed");
+            return false;
+        }
+    }
+    // delete from pending
+    if (p2PendingImfileDeleteRowObjects(config->database, pendingImfiles, MAX_ROWS) < 0) {
+        // there must be atleast 1 Imfile to get this far
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+
+    // look for pending exposures
+    psArray *pendingExps = p2searchPendingExp(config);
+    if (!pendingExps) {
+        psError(PS_ERR_UNKNOWN, false, "no p2PendingExps found");
+        return false;
+    }
+
+    for (int i = 0; i < pendingExps->n; i++) {
+        p2PendingExpRow *pendingExp = pendingExps->data[i];
+
+        psMetadata *where = psMetadataAlloc();
+        psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", pendingExp->exp_id);
+        psArray *pendingImfiles = p2PendingImfileSelectRowObjects(config->database, where, MAX_ROWS);
+        psFree(where)
+        if (!pendingImfiles) {
+            // exp has no coresponding imfiles
+            psArray *nukeMe = psArrayAlloc(1);
+            nukeMe->n = 0;
+            psArrayAdd(nukeMe, 0, pendingExp);
+            bool status = p2PendingExpDeleteRowObjects(config->database, nukeMe, MAX_ROWS);
+            psFree(nukeMe);
+            if (!status) {
+                psError(PS_ERR_UNKNOWN, false, "database access failed");
+                return false;
+            }
+            // XXX need a func to convert from p2PendingExp -> p2DoneExp
+
+            p2DoneExpRow *doneExp = p2pendingToDoneExp(pendingExp);
+            if (!doneExp) {
+                psError(PS_ERR_UNKNOWN, false, "p2PendingExp -> p2DoneExp failed");
+                return false;
+            }
+            if (!p2DoneExpInsertObject(config->database, doneExp)) {
+                psError(PS_ERR_UNKNOWN, false, "database access failed");
+                return false;
+            }
+        }
+        // skip phase 3 for the time being
+        psFree(pendingImfiles);
+    }
+
+    /*
+    psArray *doneFrames = p2pendingToDone(config, pendingFrames);
+    if (!doneFrames) {
+        psError(PS_ERR_UNKNOWN, false, "p2pendingToDone() failed");
+        return false;
+    }
+    bool status = p2insertDoneFrames(config, doneFrames);
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "p2insertDoneFrames() failed");
+        return false;
+    }
+    */
+
+    return true;
+}
