Index: trunk/ippTools/src/difftool.c
===================================================================
--- trunk/ippTools/src/difftool.c	(revision 11784)
+++ trunk/ippTools/src/difftool.c	(revision 11787)
@@ -53,14 +53,14 @@
     psLibInit(NULL);
 
-    pxConfig *config = p4toolConfig(NULL, argc, argv);
+    pxConfig *config = p5toolConfig(NULL, argc, argv);
 
     switch (config->mode) {
-        MODECASE(54TOOL_MODE_DEFINERUN,         definerunMode);
-        MODECASE(54TOOL_MODE_UPDATERUN,         updaterunMode);
-        MODECASE(P4TOOL_MODE_ADDINPUTSCFILE,    addinputscfile);
-        MODECASE(P4TOOL_MODE_INPUTSCFILE,       inputscfileMode);
-        MODECASE(P4TOOL_MODE_TODIFFSCFILE,      todiffscfileMode);
-        MODECASE(P4TOOL_MODE_ADDDIFFSCFILE,     adddiffscfileMode);
-        MODECASE(P4TOOL_MODE_DIFFSCFILE,        diffscfileMode);
+        MODECASE(P5TOOL_MODE_DEFINERUN,         definerunMode);
+        MODECASE(P5TOOL_MODE_UPDATERUN,         updaterunMode);
+        MODECASE(P5TOOL_MODE_ADDINPUTSCFILE,    addinputscfileMode);
+        MODECASE(P5TOOL_MODE_INPUTSCFILE,       inputscfileMode);
+        MODECASE(P5TOOL_MODE_TODIFFSCFILE,      todiffscfileMode);
+        MODECASE(P5TOOL_MODE_ADDDIFFSCFILE,     adddiffscfileMode);
+        MODECASE(P5TOOL_MODE_DIFFSCFILE,        diffscfileMode);
         default:
             psAbort("invalid option (this should not happen)");
@@ -198,12 +198,12 @@
     if (state) {
         // set detRun.state to state
-        return setp4RunState(config, p4_id, state);
-    }
-
-    return true;
-}
-
-
-static bool addinputexpMode(pxConfig *config)
+        return setp5RunState(config, p4_id, state);
+    }
+
+    return true;
+}
+
+
+static bool addinputscfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -261,5 +261,5 @@
 
 
-static bool expMode(pxConfig *config)
+static bool inputscfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -352,93 +352,5 @@
 
 
-static bool imfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
-
-    // find all rawImfiles matching the default query
-    psString query = psStringCopy( 
-        "SELECT\n"
-        "   rawImfile.*\n"
-        " FROM p4Run\n"
-        " JOIN p4InputExp\n"
-        "   USING(p4_id)\n"
-        " JOIN rawImfile\n -- is there any reason not to refer back to rawimfiles?"
-        "   ON p4InputExp.exp_tag = rawImfile.exp_tag\n"
-        " WHERE\n"
-        "   p4Run.state = 'run'\n" 
-    );
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4InputExp");
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psErrorCode err = psErrorCodeLast();
-        switch (err) {
-            case PS_ERR_DB_CLIENT:
-                psError(PXTOOLS_ERR_SYS, false, "database error");
-            case PS_ERR_DB_SERVER:
-                psError(PXTOOLS_ERR_PROG, false, "database error");
-            default:
-                psError(PXTOOLS_ERR_PROG, false, "unknown error");
-        }
-
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no pending rawImfile rows found");
-        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;
-        }
-    }
-
-    if (psArrayLength(output)) {
-        // negative simple so the default is true
-        if (!ippdbPrintMetadatas(stdout, output, "p4InputImfile", !simple)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(output);
-            return false;
-        }
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-
-static bool tooverlapMode(pxConfig *config)
+static bool todiffscfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -538,285 +450,5 @@
 
 
-static bool addoverlapMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    bool status = false;
-    psString mapfile = psMetadataLookupStr(&status, config->args, "-mapfile");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -mapfile");
-        return false;
-    }
-    if (!mapfile) {
-        psError(PS_ERR_UNKNOWN, true, "-mapfile is required");
-        return false;
-    }
-
-    if (!psDBTransaction(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
-    if (!parseAndInsertSkyCellMap(config, mapfile)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to inject mapfile: %s into the database", mapfile);
-        // rollback
-        if (!psDBRollback(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
-        }
-        return false;
-    }
-
-    // point of no return
-    if (!psDBCommit(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
-    return true;
-}
-
-
-static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile)
-{
-    unsigned int nFail = 0;
-    psMetadata *skycells = psMetadataConfigRead(NULL, &nFail, mapfile, false);
-    if (!skycells) {
-        psError(PS_ERR_UNKNOWN, false, "failed to parse mapfile: %s", mapfile);
-        return false;
-    }        
-    if (nFail) {
-        psError(PS_ERR_UNKNOWN, false, "there were %d errors parsing mapfile: %s", nFail, mapfile);
-        psFree(skycells);
-        return false;
-    }
-
-    psMetadataItem *item = NULL;
-    psMetadataIterator *iter = psMetadataIteratorAlloc(skycells, 0, NULL);
-    if ((item = psMetadataGetAndIncrement(iter))) {
-        if (item->type != PS_DATA_METADATA) {
-            psError(PS_ERR_UNKNOWN, false, "mapfile: %s is in the wrong format", mapfile);
-            psFree(iter);
-            psFree(skycells);
-            return false;
-        }
-
-        psMetadata *sc = item->data.md;
-        // this conversion isn't strictly nessicary but it's an easy way of
-        // validating the format
-        p4SkyCellMapRow *row = p4SkyCellMapObjectFromMetadata(sc);
-        if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert mapfile: %s metdata entry into a p4SkyCellMap object", mapfile);
-            psFree(iter);
-            psFree(skycells);
-            return false;
-        }
-
-        if (!p4SkyCellMapInsertObject(config->dbh, row)) {
-            psErrorCode err = psErrorCodeLast();
-            switch (err) {
-                case PS_ERR_DB_CLIENT:
-                    psError(PXTOOLS_ERR_SYS, false, "database error");
-                case PS_ERR_DB_SERVER:
-                    psError(PXTOOLS_ERR_PROG, false, "database error");
-                default:
-                    psError(PXTOOLS_ERR_PROG, false, "unknown error");
-            }
-            psFree(row);
-            psFree(iter);
-            psFree(skycells);
-            return false;
-        }
-
-        psFree(row);
-    }
-    psFree(iter);
-    psFree(skycells);
-
-    return true;
-}
-
-
-static bool scmapMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
-
-    // find all rawImfiles matching the default query
-    psString query = psStringCopy( 
-        "SELECT\n"
-        "   p4SkyCellMap.*\n"
-        " FROM p4Run\n"
-        " JOIN p4SkyCellMap\n"
-        "   USING(p4_id)\n"
-        " WHERE\n"
-        "   p4Run.state = 'run'\n" 
-    );
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4SkyCellMap");
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psErrorCode err = psErrorCodeLast();
-        switch (err) {
-            case PS_ERR_DB_CLIENT:
-                psError(PXTOOLS_ERR_SYS, false, "database error");
-            case PS_ERR_DB_SERVER:
-                psError(PXTOOLS_ERR_PROG, false, "database error");
-            default:
-                psError(PXTOOLS_ERR_PROG, false, "unknown error");
-        }
-
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no p4SkyCellMap rows found");
-        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;
-        }
-    }
-
-    if (psArrayLength(output)) {
-        // negative simple so the default is true
-        if (!ippdbPrintMetadatas(stdout, output, "p4SkyCellMap", !simple)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(output);
-            return false;
-        }
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-
-static bool towarpedMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    bool status = false;
-    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
-    if (!status) {
-        psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");
-        return false;
-    }
-
-    // find all rawImfiles matching the default query
-    psString query = psStringCopy( 
-        "SELECT\n"
-        "   p4SkyCellMap.*\n"
-        " FROM p4Run\n"
-        " JOIN p4SkyCellMap\n"
-        "   USING(p4_id)\n"
-        " LEFT JOIN p4Scfile\n"
-        "   USING(p4_id, skycell_id, tess_id, exp_tag, p3_version)\n"
-        " WHERE\n"
-        "   p4Run.state = 'run'\n" 
-        "   AND p4Scfile.p4_id IS NULL\n"
-        "   AND p4Scfile.skycell_id IS NULL\n"
-        "   AND p4Scfile.tess_id IS NULL\n"
-        "   AND p4Scfile.exp_tag IS NULL\n"
-        "   AND p4Scfile.p3_version IS NULL\n"
-    );
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4SkyCellMap");
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-
-    // treat limit == 0 as "no limit"
-    if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psErrorCode err = psErrorCodeLast();
-        switch (err) {
-            case PS_ERR_DB_CLIENT:
-                psError(PXTOOLS_ERR_SYS, false, "database error");
-            case PS_ERR_DB_SERVER:
-                psError(PXTOOLS_ERR_PROG, false, "database error");
-            default:
-                psError(PXTOOLS_ERR_PROG, false, "unknown error");
-        }
-
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no p4PendingSkyCell rows found");
-        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;
-        }
-    }
-
-    if (psArrayLength(output)) {
-        // negative simple so the default is true
-        if (!ippdbPrintMetadatas(stdout, output, "p4PendingSkyCell", !simple)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(output);
-            return false;
-        }
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-
-static bool addwarpedMode(pxConfig *config)
+static bool adddiffscfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -912,5 +544,5 @@
 }
 
-static bool warpedMode(pxConfig *config)
+static bool diffscfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -998,410 +630,5 @@
 }
 
-#if 0
-static bool tostackedimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    psString query = psStringCopy(
-        " SELECT DISTINCT"
-        "   p4WarpedImfile.*,"
-        "   p4Run.workdir"
-        " FROM p4Run"
-        " JOIN p4WarpedImfile"
-        "   USING(p4_id)"
-        " LEFT JOIN p4StackedImfile"
-        "   USING(p4_id, class_id)"
-        " WHERE"
-        "   p4Run.state = 'run'"
-        "   AND p4StackedImfile.p4_id IS NULL"
-        "   AND p4Stackedmfile.class_id IS NULL"
-    );
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4WarpedImfile");
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no p4WarpedImfile rows found");
-        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;
-        }
-    }
-
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "p4WarpedImfile", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-static bool addstackedimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    bool status = false;
-    psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id");
-        return false;
-    }
-    if (!p4_id) {
-        psError(PS_ERR_UNKNOWN, true, "-p4_id is required");
-        return false;
-    }
-
-    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
-        return false;
-    }
-    if (!class_id) {
-        psError(PS_ERR_UNKNOWN, true, "-class_id 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;
-    }
-
-    // optional
-    psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
-        return false;
-    }
-
-    psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
-        return false;
-    }
-
-    // XXX need to validate that this coresponds to an p4WarpedImfile
-    if (!p4StackedImfileInsert(config->dbh, 
-            (psS32)atoi(p4_id),
-            class_id,
-            uri,
-            b1_uri,
-            b2_uri
-        )) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
-    return true;
-}
-
-static bool stackedimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    psString query = psStringCopy(
-        " SELECT DISTINCT"
-        "   p4StackedImfile.*"
-        " FROM p4Run"
-        " JOIN p4StackedImfile"
-        "   USING(p4_id)"
-        " WHERE"
-        "   p4Run.state = 'run'"
-    );
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4StackedImfile");
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no p4StackedImfile rows found");
-        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;
-        }
-    }
-
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "p4StackedImfile", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-static bool todiffimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    psString query = psStringCopy(
-        " SELECT DISTINCT"
-        "   p4StackedImfile.*,"
-        "   p4WarpedImfile.uri as warped_uri,"
-        "   p4Run.workdir"
-        " FROM p4Run"
-        " JOIN p4StackedImfile"
-        "   USING(p4_id)"
-        " JOIN p4WarpedImfile"
-        "   USING(p4_id, class_id)"
-        " LEFT JOIN p4DiffImfile"
-        "   ON p4WarpedImfile.p4_id = p4DiffImfile.p4_id"
-        "   AND p4WarpedImfile.exp_tag = p4DiffImfile.exp_tag"
-        "   AND p4WarpedImfile.p3_version = p4DiffImfile.p3_version"
-        "   AND p4WarpedImfile.class_id = p4DiffImfile.class_id"
-        " WHERE"
-        "   p4Run.state = 'run'"
-        "   AND p4DiffImfile.p4_id IS NULL"
-        "   AND p4DiffImfile.exp_tag IS NULL"
-        "   AND p4DiffImfile.p3_version IS NULL"
-        "   AND p4DiffImfile.class_id IS NULL"
-    );
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4StackedImfile");
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no p4StackedImfile rows found");
-        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;
-        }
-    }
-
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "p4StackedImfile", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-
-static bool adddiffimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    bool status = false;
-    psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id");
-        return false;
-    }
-    if (!p4_id) {
-        psError(PS_ERR_UNKNOWN, true, "-p4_id is required");
-        return false;
-    }
-
-    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
-        return false;
-    }
-    if (!exp_tag) {
-        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
-        return false;
-    }
-
-    psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id");
-        return false;
-    }
-    if (!class_id) {
-        psError(PS_ERR_UNKNOWN, true, "-class_id 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;
-    }
-
-    // defaults to 0
-    psS32 p3_version = psMetadataLookupS32(&status, config->args, "-p3_version");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version");
-        return false;
-    }
-
-    // optional
-    psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
-        return false;
-    }
-
-    psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
-        return false;
-    }
-
-    // XXX need to validate that this coresponds to an p4InputImfile
-    if (!p4DiffImfileInsert(config->dbh, 
-            (psS32)atoi(p4_id),
-            exp_tag,
-            p3_version,
-            class_id,
-            uri,
-            b1_uri,
-            b2_uri
-        )) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
-    return true;
-}
-
-static bool diffimfileMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, NULL);
-
-    psString query = psStringCopy(
-        " SELECT DISTINCT"
-        "   p4DiffImfile.*"
-        " FROM p4Run"
-        " JOIN p4DiffImfile"
-        "   USING(p4_id)"
-        " WHERE"
-        "   p4Run.state = 'run'"
-    );
-
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4DiffImfile");
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
-    }
-
-    if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-    psFree(query);
-
-    psArray *output = p_psDBFetchResult(config->dbh);
-    if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    if (!psArrayLength(output)) {
-        psError(PS_ERR_UNKNOWN, false, "no p4DiffImfile rows found");
-        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;
-        }
-    }
-
-    // negative simple so the default is true
-    if (!ippdbPrintMetadatas(stdout, output, "p4DiffImfile", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
-    psFree(output);
-
-    return true;
-}
-#endif
-
-static bool setp4RunState(pxConfig *config, const char *p4_id, const char *state)
+static bool setp5RunState(pxConfig *config, const char *p4_id, const char *state)
 {
     PS_ASSERT_PTR_NON_NULL(p4_id, false);
