Index: trunk/ippTools/src/chiptool.c
===================================================================
--- trunk/ippTools/src/chiptool.c	(revision 11024)
+++ trunk/ippTools/src/chiptool.c	(revision 11033)
@@ -33,8 +33,10 @@
 static bool pendingimfileMode(pxConfig *config);
 static bool addprocessedimfileMode(pxConfig *config);
-static bool faultimfileMode(pxConfig *config);
+static bool processedimfileMode(pxConfig *config);
+static bool updateprocessedimfileMode(pxConfig *config);
 static bool blockMode(pxConfig *config);
 static bool maskedMode(pxConfig *config);
 static bool unblockMode(pxConfig *config);
+
 static p2ProcessedImfileRow *p2PendingToProcessedImfile(pxConfig *config, p2PendingImfileRow *imfile);
 static p2ProcessedExpRow *p2PendingToProcessedExp(pxConfig *config, p2PendingExpRow *pendingExp);
@@ -59,5 +61,6 @@
         MODECASE(P2TOOL_MODE_PENDINGIMFILE,         pendingimfileMode);
         MODECASE(P2TOOL_MODE_ADDPROCESSEDIMFILE,    addprocessedimfileMode);
-        MODECASE(P2TOOL_MODE_FAULTIMFILE,           faultimfileMode);
+        MODECASE(P2TOOL_MODE_PROCESSEDIMFILE,       processedimfileMode);
+        MODECASE(P2TOOL_MODE_UPDATEPROCESSEDIMFILE, updateprocessedimfileMode);
         MODECASE(P2TOOL_MODE_BLOCK,                 blockMode);
         MODECASE(P2TOOL_MODE_MASKED,                maskedMode);
@@ -183,10 +186,4 @@
     }
 
-    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
-        return false;
-    }
-
     // XXX does this need to be constrained so that it won't return any results
     // if a match p2PendingExp hasn't been registered?
@@ -212,12 +209,4 @@
     }
 
-    if (faulted) {
-        // list only faulted rows
-        psStringAppend(&query, " %s", "AND p2PendingImfile.fault != 0");
-    } else {
-        // don't list faulted rows
-        psStringAppend(&query, " %s", "AND p2PendingImfile.fault = 0");
-    }
-
     // treat limit == 0 as "no limit"
     if (limit) {
@@ -433,5 +422,98 @@
 
 
-static bool faultimfileMode(pxConfig *config)
+static bool processedimfileMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
+    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;
+    }
+
+    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
+        return false;
+    }
+
+    // XXX does this need to be constrained so that it won't return any results
+    // if a match p2PendingExp hasn't been registered?
+    psString query = psStringCopy(
+            "SELECT"
+            "   p2ProcessedImfile.*,"
+            "   rawScienceExp.camera"
+            " FROM p2ProcessedImfile"
+            " JOIN rawScienceExp"
+            "   USING(exp_tag)"
+            " WHERE "
+            "   p2ProcessedImfile.exp_tag is NOT NULL" // bogus test -- just here so there there is a 'WHERE' stmt to append conditionals too
+        );
+
+    if (config->where) {
+        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p2ProcessedImfile");
+        psStringAppend(&query, " AND %s", whereClause);
+        psFree(whereClause);
+    }
+
+    if (faulted) {
+        // list only faulted rows
+        psStringAppend(&query, " %s", "AND p2ProcessedImfile.fault != 0");
+    } else {
+        // don't list faulted rows
+        psStringAppend(&query, " %s", "AND p2ProcessedImfile.fault = 0");
+    }
+
+    // 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) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+    if (!psArrayLength(output)) {
+        // XXX check psError here
+        psError(PS_ERR_UNKNOWN, false, "no p2ProcessedImfile 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, "p2ProcessedImfile", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+
+static bool updateprocessedimfileMode(pxConfig *config)
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
@@ -444,5 +526,5 @@
     }
 
-    if (!pxSetFaultCode(config->dbh, "p2PendingImfile", config->where, code)) {
+    if (!pxSetFaultCode(config->dbh, "p2ProcessedImfile", config->where, code)) {
         psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
         return false;
@@ -733,4 +815,11 @@
     }
 
+    // default values
+    psS8 code = psMetadataLookupS8(&status, config->args, "-code");
+    if (!status) {
+        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
+        return false;
+    }
+
     return p2ProcessedImfileRowAlloc(
         imfile->exp_tag,
@@ -744,5 +833,6 @@
         b2_uri,
         imfile->p1_version,
-        imfile->p2_version
+        imfile->p2_version,
+        code
     );
 }
