Index: trunk/ippTools/src/regtool.c
===================================================================
--- trunk/ippTools/src/regtool.c	(revision 10637)
+++ trunk/ippTools/src/regtool.c	(revision 10671)
@@ -82,4 +82,11 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    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;
+    }
+
     // return only exps that:
     // are not in rawScienceExp 
@@ -88,5 +95,5 @@
     // and have no associated imfiles left in newImfile
 
-    char *query =
+    psString query = psStringCopy(
         "SELECT"
         "   newExp.*"
@@ -105,10 +112,19 @@
         "   (SELECT COUNT(exp_tag) FROM rawImfile"
         "       WHERE rawImfile.exp_tag = newExp.exp_tag)"
-        ;
+    );
+
+    // 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");
-        return false;
-    }
+        psFree(query);
+        return false;
+    }
+    psFree(query);
 
     psArray *output = p_psDBFetchResult(config->dbh);
@@ -150,4 +166,11 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    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;
+    }
+
     // select newImfiles that:
     // exp_tag is in newExp
@@ -156,5 +179,6 @@
     // XXX having the same exp_tag in newExp and raw*Exp is probably an error
     // that should be checked for
-    char *query =
+
+    psString query = psStringCopy(
         "SELECT newImfile.* FROM newImfile"
         " LEFT JOIN newExp USING(exp_tag)"
@@ -163,10 +187,20 @@
         " WHERE newExp.exp_tag is NOT NULL"
         " AND rawScienceExp.exp_tag IS NULL"
-        " AND rawDetrendExp.exp_tag IS NULL";
+        " AND rawDetrendExp.exp_tag IS NULL"
+    );
+
+    // 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");
-        return false;
-    }
+        psFree(query);
+        return false;
+    }
+    psFree(query);
 
     psArray *output = p_psDBFetchResult(config->dbh);
