Index: trunk/ippTools/src/labeltool.c
===================================================================
--- trunk/ippTools/src/labeltool.c	(revision 28075)
+++ trunk/ippTools/src/labeltool.c	(revision 28076)
@@ -81,62 +81,42 @@
 static bool definelabelMode(pxConfig *config)
 {
-#ifdef notyet
     PS_ASSERT_PTR_NON_NULL(config, false);
 
     // required
-    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
-    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false);
-    PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", false, false);
+    PXOPT_LOOKUP_STR(label,    config->args, "-set_label", true, false);
+    // XXX: perhaps we should have a default priority?
+    PXOPT_LOOKUP_S32(priority, config->args, "-set_priority", true, false);
 
     // optional
-    PXOPT_LOOKUP_BOOL(inverse, config->args, "-inverse", false);
-    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
-    PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
-    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
+    PXOPT_LOOKUP_BOOL(inactive, config->args, "-set_inactive", false);
+    PXOPT_LOOKUP_STR(comment, config->args, "-set_comment", false, false);
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
-    magicRunRow *run = magicRunRowAlloc(
-            0,          // ID
-            exp_id,
-            diff_id ? diff_id : PS_MAX_S64,
-            inverse,
-            "reg",      // state
-            workdir,
-            "dirty",    // workdir_state
+    LabelRow *row = LabelRowAlloc(
             label,
-            NULL,       // data_group
-            dvodb,
-            registered,
-            0,          // fault
-            NULL
+            priority,
+            inactive ? false : true,
+            comment
     );
 
-    if (!run) {
-        psError(PS_ERR_UNKNOWN, false, "failed to alloc magicRun object");
-        return false;
-    }
-    if (!magicRunInsertObject(config->dbh, run)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(run);
-        return false;
-    }
-
-    // get the assigned magic_id
-    psS64 magic_id = psDBLastInsertID(config->dbh);
-    run->magic_id = magic_id;
-
-    if (!magicRunPrintObject(stdout, run, !simple)) {
+    if (!row) {
+        psError(PS_ERR_UNKNOWN, false, "failed to allocate Label object");
+        return false;
+    }
+    if (!LabelInsertObject(config->dbh, row)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(row);
+        return false;
+    }
+
+    if (!LabelPrintObject(stdout, row, !simple)) {
             psError(PS_ERR_UNKNOWN, false, "failed to print object");
-            psFree(run);
+            psFree(row);
             return false;
     }
 
-    psFree(run);
-
-    return magic_id;
-#else
-
-    return false;
-#endif
+    psFree(row);
+
+    return true;
 }
 
@@ -144,12 +124,90 @@
 static bool updatelabelMode(pxConfig *config)
 {
-    return false;
-#ifdef notyet
+    PXOPT_LOOKUP_STR(label,    config->args, "-label", true, false);
+
+
+    // optional (at least one is required)
+    PXOPT_LOOKUP_S32(priority, config->args, "-set_priority", false, false);
+    PXOPT_LOOKUP_BOOL(inactive, config->args, "-set_inactive", false);
+    PXOPT_LOOKUP_BOOL(active, config->args, "-set_active", false);
+    PXOPT_LOOKUP_STR(comment, config->args, "-set_comment", false, false);
+
+    if (! (priority || active || inactive || comment) ) {
+        psError(PS_ERR_UNKNOWN, true, "at least one -set option is required\n");
+        return false;
+    }
+    if (active && inactive) {
+        psError(PS_ERR_UNKNOWN, true, "only one of -active and -inactive may be supplied");
+        return false;
+    }
+
+    psString query = psStringCopy("UPDATE Label SET");
+    char sep = ' ';
+
+    if (priority) {
+        psStringAppend(&query, "%c priority = %d", sep, priority);
+        sep = ',';
+    }
+    if (active) {
+        psStringAppend(&query, "%c active = %d", sep, 1);
+        sep = ',';
+    }
+    if (inactive) {
+        psStringAppend(&query, "%c active = %d", sep, 0);
+        sep = ',';
+    }
+    if (comment) {
+        psStringAppend(&query, "%c comment = '%s'", sep, comment);
+        sep = ',';
+    }
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    return true;
+}
+
+static bool deletelabelMode(pxConfig *config)
+{
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    PXOPT_LOOKUP_STR(label,    config->args, "-label", true, false);
+
+    psString query = NULL;
+    
+    psStringAppend(&query, "DELETE FROM Label WHERE label = '%s'", label);
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    psFree(query);
+
+    return true;
+}
+
+static bool listlabelMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
     psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
-    PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "==");
-    PXOPT_COPY_STR(config->args, where, "-node", "node", "==");
+    PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE");
+
+    PXOPT_LOOKUP_BOOL(active, config->args,   "-active", false);
+    PXOPT_LOOKUP_BOOL(inactive, config->args, "-inactive", false);
+    if (active && inactive) {
+        psError(PS_ERR_UNKNOWN, true, "only one of -active and inactive may be supplied");
+        return false;
+    }
+    PXOPT_LOOKUP_BOOL(lowtohigh, config->args, "-lowtohigh", false);
+    PXOPT_LOOKUP_BOOL(hightolow, config->args, "-hightolow", false);
+    if (lowtohigh && hightolow) {
+        psError(PS_ERR_UNKNOWN, true, "only one of -lowtohigh and -hightolow may be supplied");
+        return false;
+    }
 
     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
@@ -157,16 +215,27 @@
 
     // find all rawImfiles matching the default query
-    psString query = pxDataGet("magictool_inputskyfile.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-        return false;
-    }
-
+    psString query = psStringCopy("SELECT * FROM Label\n");
+
+    char *sep = " WHERE ";
     if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, "magicInputSkyfile");
-        psStringAppend(&query, " AND %s", whereClause);
+        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&query, " WHERE %s", whereClause);
         psFree(whereClause);
+        sep = " AND ";
     }
     psFree(where);
+
+    if (active) {
+        psStringAppend(&query, "%s active\n", sep);
+        sep = " AND ";
+    } else if (inactive) {
+        psStringAppend(&query, "%s NOT active\n", sep);
+        sep = " AND ";
+    }
+
+    if (lowtohigh || hightolow) {
+        char *order = lowtohigh ? "" : "DESC";
+        psStringAppend(&query, "\nORDER BY priority %s\n", order);
+    }
 
     // treat limit == 0 as "no limit"
@@ -199,178 +268,4 @@
     }
     if (!psArrayLength(output)) {
-        psTrace("magictool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return true;
-    }
-
-    if (psArrayLength(output)) {
-        // negative simple so the default is true
-        if (!ippdbPrintMetadatas(stdout, output, "magicInputSkyfile", !simple)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(output);
-            return false;
-        }
-    }
-
-    psFree(output);
-
-    return true;
-#endif
-}
-
-static bool deletelabelMode(pxConfig *config)
-{
-    return false;
-#ifdef notdef
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "==");
-    pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "==");
-
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    // look for "inputs" that need to processed
-    psString query = pxDataGet("magictool_totree.sql");
-    if (!query) {
-        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-        return false;
-    }
-
-    if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %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) {
-        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)) {
-        psTrace("magictool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return true;
-    }
-
-    if (psArrayLength(output)) {
-        // negative simple so the default is true
-        if (!ippdbPrintMetadatas(stdout, output, "totree", !simple)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(output);
-            return false;
-        }
-    }
-
-    psFree(output);
-
-    return true;
-#endif
-}
-
-static bool listlabelMode(pxConfig *config)
-{
-    PS_ASSERT_PTR_NON_NULL(config, false);
-    PS_ASSERT_PTR_NON_NULL(config, false);
-
-    psMetadata *where = psMetadataAlloc();
-    PXOPT_COPY_STR(config->args, where, "-label", "label", "LIKE");
-
-    PXOPT_LOOKUP_BOOL(active, config->args,   "-active", false);
-    PXOPT_LOOKUP_BOOL(inactive, config->args, "-inactive", false);
-    if (active && inactive) {
-        psError(PS_ERR_UNKNOWN, true, "only one of -active and inactive may be supplied");
-        return false;
-    }
-    PXOPT_LOOKUP_BOOL(lowtohigh, config->args, "-lowtohigh", false);
-    PXOPT_LOOKUP_BOOL(hightolow, config->args, "-hightolow", false);
-    if (lowtohigh && hightolow) {
-        psError(PS_ERR_UNKNOWN, true, "only one of -lowtohigh and -hightolow may be supplied");
-        return false;
-    }
-
-    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
-    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-
-    // find all rawImfiles matching the default query
-    psString query = psStringCopy("SELECT * FROM Label\n");
-
-    char *sep = " WHERE ";
-    if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " WHERE %s", whereClause);
-        psFree(whereClause);
-        sep = " AND ";
-    }
-    psFree(where);
-
-    if (active) {
-        psStringAppend(&query, "%s active\n", sep);
-        sep = " AND ";
-    } else if (inactive) {
-        psStringAppend(&query, "%s NOT active\n", sep);
-        sep = " AND ";
-    }
-
-    if (lowtohigh || hightolow) {
-        char *order = lowtohigh ? "" : "DESC";
-        psStringAppend(&query, "\nORDER BY priority %s\n", order);
-    }
-
-    // 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)) {
         psTrace("labeltool", PS_LOG_INFO, "no rows found");
         psFree(output);
Index: trunk/ippTools/src/labeltoolConfig.c
===================================================================
--- trunk/ippTools/src/labeltoolConfig.c	(revision 28075)
+++ trunk/ippTools/src/labeltoolConfig.c	(revision 28076)
@@ -53,13 +53,13 @@
     psMetadataAddBool(definelabelArgs, PS_LIST_TAIL, "-set_inactive", 0, "set label inactive", false);
     psMetadataAddStr(definelabelArgs, PS_LIST_TAIL, "-set_comment",  0, "define label comment", NULL);
+    psMetadataAddBool(definelabelArgs, PS_LIST_TAIL, "-simple",  0, "use the simple output format", false);
 
     // -updatelabel
     psMetadata *updatelabelArgs = psMetadataAlloc();
     psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-label", 0, "search by label (LIKE comparison) (required)", NULL);
-    psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-set_label",   0, "define label", NULL);
-    psMetadataAddS64(updatelabelArgs, PS_LIST_TAIL, "-set_priority", 0, "define priority", 0);
+    psMetadataAddS64(updatelabelArgs, PS_LIST_TAIL, "-set_priority", 0, "define new priority", 0);
     psMetadataAddBool(updatelabelArgs, PS_LIST_TAIL, "-set_active", 0, "set label active", false);
     psMetadataAddBool(updatelabelArgs, PS_LIST_TAIL, "-set_inactive", 0, "set label inactive", false);
-    psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-set_comment",  0, "define label comment", NULL);
+    psMetadataAddStr(updatelabelArgs, PS_LIST_TAIL, "-set_comment",  0, "define new label comment", NULL);
 
     // -deletelabel
