Index: branches/cleanup/ippTools/src/Makefile.am
===================================================================
--- branches/cleanup/ippTools/src/Makefile.am	(revision 17860)
+++ branches/cleanup/ippTools/src/Makefile.am	(revision 17863)
@@ -69,4 +69,5 @@
 	pxregister.c \
 	pxtag.c \
+	pxtools.c \
 	pxtoolsErrorCodes.c \
 	pxtree.c \
Index: branches/cleanup/ippTools/src/chiptool.c
===================================================================
--- branches/cleanup/ippTools/src/chiptool.c	(revision 17860)
+++ branches/cleanup/ippTools/src/chiptool.c	(revision 17863)
@@ -47,4 +47,5 @@
 static bool pendingcleanupMode(pxConfig *config);
 static bool donecleanupMode(pxConfig *config);
+static bool runMode(pxConfig *config);
 
 static bool chipProcessedCompleteExp(pxConfig *config);
@@ -80,4 +81,5 @@
         MODECASE(CHIPTOOL_MODE_PENDINGCLEANUP,          pendingcleanupMode);
         MODECASE(CHIPTOOL_MODE_DONECLEANUP,             donecleanupMode);
+        MODECASE(CHIPTOOL_MODE_RUN,                     runMode);
         default:
             psAbort("invalid option (this should not happen)");
@@ -1074,4 +1076,79 @@
 
 
+static bool runMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+
+    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
+    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
+    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
+
+    // make sure that the state string is valid
+    if (!pxIsValidState(state)) {
+        psError(PXTOOLS_ERR_DATA, false, "%s is not a valid state", state);
+        return false;
+    }
+
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
+    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
+
+    psString query = pxDataGet("chiptool_run.sql");
+    if (!query) {
+        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        return false;
+    }
+
+    if (where && psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereSQL(where, NULL);
+        psStringAppend(&query, " %s", whereClause);
+        psFree(whereClause);
+    }
+    psFree(where);
+
+    // 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)) {
+        psTrace("chiptool", PS_LOG_INFO, "no rows found");
+        psFree(output);
+        return true;
+    }
+
+    if (!convertIdToStr(output)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings");
+        psFree(output);
+        return false;
+    }
+
+    // negative simple so the default is true
+    if (!ippdbPrintMetadatas(stdout, output, "chipDoneCleanup", !simple)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to print array");
+        psFree(output);
+        return false;
+    }
+
+    psFree(output);
+
+    return true;
+}
+
+
 static bool chipProcessedCompleteExp(pxConfig *config)
 {
@@ -1109,5 +1186,5 @@
         chipRunRow *chipRun = chipRunObjectFromMetadata(row);
         // set chipRun.state to 'stop'
-        if (!pxchipRunSetState(config, chipRun->chip_id, "stop")) {
+        if (!pxchipRunSetState(config, chipRun->chip_id, "full")) {
             psError(PS_ERR_UNKNOWN, false, "failed to change chipRun.state for chip_id: %" PRId64, chipRun->chip_id);
             psFree(chipRun);
Index: branches/cleanup/ippTools/src/chiptool.h
===================================================================
--- branches/cleanup/ippTools/src/chiptool.h	(revision 17860)
+++ branches/cleanup/ippTools/src/chiptool.h	(revision 17863)
@@ -39,4 +39,5 @@
     CHIPTOOL_MODE_PENDINGCLEANUP,
     CHIPTOOL_MODE_DONECLEANUP,
+    CHIPTOOL_MODE_RUN
 } chiptoolMode;
 
Index: branches/cleanup/ippTools/src/chiptoolConfig.c
===================================================================
--- branches/cleanup/ippTools/src/chiptoolConfig.c	(revision 17860)
+++ branches/cleanup/ippTools/src/chiptoolConfig.c	(revision 17863)
@@ -283,4 +283,11 @@
     psMetadataAddU64(donecleanupArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
 
+    // -run
+    psMetadata *runArgs = psMetadataAlloc();
+    psMetadataAddStr(runArgs, PS_LIST_TAIL, "-label",  0,       "search by label", NULL);
+    psMetadataAddBool(runArgs, PS_LIST_TAIL, "-simple",  0,     "use the simple output format", false);
+    psMetadataAddU64(runArgs, PS_LIST_TAIL, "-limit",  0,       "limit result set to N items", 0);
+    psMetadataAddStr(runArgs, PS_LIST_TAIL, "-state", 0,        "search by state (required)", NULL);
+
     psMetadata *argSets = psMetadataAlloc();
     psMetadata *modes = psMetadataAlloc();
@@ -312,4 +319,6 @@
     PXOPT_ADD_MODE("-donecleanup",          "show runs that have been cleaned",
         CHIPTOOL_MODE_DONECLEANUP,          donecleanupArgs);
+    PXOPT_ADD_MODE("-run",                  "show runs",
+        CHIPTOOL_MODE_RUN,                  runArgs);
 
     if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Index: branches/cleanup/ippTools/src/pxchip.c
===================================================================
--- branches/cleanup/ippTools/src/pxchip.c	(revision 17860)
+++ branches/cleanup/ippTools/src/pxchip.c	(revision 17863)
@@ -35,12 +35,6 @@
 
     // check that state is a valid string value
-    if (!(
-            (strncmp(state, "run", 4) == 0)
-            || (strncmp(state, "stop", 5) == 0)
-            || (strncmp(state, "reg", 4) == 0)
-        )
-    ) {
-        psError(PS_ERR_UNKNOWN, false,
-                "invalid chipRun state: %s", state);
+    if (!pxIsValidState(state)) {
+        psError(PS_ERR_UNKNOWN, false, "invalid chipRun state: %s", state);
         return false;
     }
@@ -63,14 +57,9 @@
 
     // check that state is a valid string value
-    if (!(
-            (strncmp(state, "run", 4) == 0)
-            || (strncmp(state, "stop", 5) == 0)
-            || (strncmp(state, "reg", 4) == 0)
-        )
-    ) {
-        psError(PS_ERR_UNKNOWN, false,
-                "invalid chipRun state: %s", state);
+    if (!pxIsValidState(state)) {
+        psError(PS_ERR_UNKNOWN, false, "invalid chipRun state: %s", state);
         return false;
     }
+
 
     psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) SET state = '%s'");
@@ -151,5 +140,5 @@
             0x0, // chip_id
             exp_id,
-            "run",      // state                
+            "new",      // state                
             workdir,
             "dirty",    // workdir_state
@@ -167,2 +156,3 @@
     return psDBLastInsertID(config->dbh);
 }
+
Index: branches/cleanup/ippTools/src/pxchip.h
===================================================================
--- branches/cleanup/ippTools/src/pxchip.h	(revision 17860)
+++ branches/cleanup/ippTools/src/pxchip.h	(revision 17863)
@@ -40,3 +40,4 @@
                          const char *end_stage);
 
+
 #endif // PXCHIP_H
Index: branches/cleanup/ippTools/src/pxtools.c
===================================================================
--- branches/cleanup/ippTools/src/pxtools.c	(revision 17863)
+++ branches/cleanup/ippTools/src/pxtools.c	(revision 17863)
@@ -0,0 +1,43 @@
+/*
+ * pxtool.c
+ *
+ * Copyright (C) 2008  Joshua Hoblitt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include "pxtools.h"
+
+bool pxIsValidState(const char *state)
+{
+    PS_ASSERT_PTR_NON_NULL(state, false);
+
+    if (!((strncmp(state, "new", 4) == 0)
+    || (strncmp(state, "full", 5) == 0)
+    || (strncmp(state, "goto_cleaned", 8) == 0)
+    || (strncmp(state, "cleaned", 8) == 0)
+    || (strncmp(state, "update", 7) == 0)
+    || (strncmp(state, "purged", 7) == 0)
+    || (strncmp(state, "goto_purged", 12) == 0))) {
+        return false;
+    }
+
+    return true;
+}
Index: branches/cleanup/ippTools/src/pxtools.h
===================================================================
--- branches/cleanup/ippTools/src/pxtools.h	(revision 17860)
+++ branches/cleanup/ippTools/src/pxtools.h	(revision 17863)
@@ -41,6 +41,5 @@
 # define PXTOOL_MODE_NONE 0x0
 
-bool pxCreateTables (pxConfig *config);
-bool pxDeleteTables (pxConfig *config);
+bool pxIsValidState(const char *state);
 
 bool pxSetFaultCode(psDB *dbh, const char *tableName, psMetadata *where, psS16 code);
