IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 8, 2007, 2:34:21 PM (19 years ago)
Author:
jhoblitt
Message:

add -faultimfile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/regtool.c

    r10671 r10972  
    3131static bool updateexpMode(pxConfig *config);
    3232static bool updateimfileMode(pxConfig *config);
     33static bool faultimfileMode(pxConfig *config);
    3334static bool rawimfileMode(pxConfig *config);
    3435// static p1PendingExpRow *newToP1PendingExp(newExpRow *newExp);
     
    3839static rawDetrendExpRow *newToRawDetrendExp(pxConfig *config, newExpRow *exp);
    3940static rawImfileRow *newToRawImfile(pxConfig *config, newImfileRow *exp);
     41static psU32 mapCodeStrToInt(char *codeStr);
    4042
    4143
     
    5860        MODECASE(P0TOOL_MODE_UPDATEEXP,       updateexpMode);
    5961        MODECASE(P0TOOL_MODE_UPDATEIMFILE,    updateimfileMode);
     62        MODECASE(P0TOOL_MODE_FAULTIMFILE,     faultimfileMode);
    6063        MODECASE(P0TOOL_MODE_RAWIMFILE,       rawimfileMode);
    6164        default:
     
    234237
    235238    psFree(output);
     239
     240    return true;
     241}
     242
     243static bool faultimfileMode(pxConfig *config)
     244{
     245    PS_ASSERT_PTR_NON_NULL(config, false);
     246
     247    bool status = false;
     248    psString codeStr = psMetadataLookupStr(&status, config->args, "-code");
     249    if (!status) {
     250        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -code");
     251        return false;
     252    }
     253    if (!codeStr) {
     254        psError(PS_ERR_UNKNOWN, true, "-code is required");
     255        return false;
     256    }
     257
     258    // map code string to numeric fault code
     259    psU32 code = mapCodeStrToInt(codeStr);
     260    if (code == (psU32)-1) {
     261        psError(PS_ERR_UNKNOWN, false, "error resolving error code");
     262        return false;
     263    }
     264
     265    // update the database
     266    psMetadata *values = psMetadataAlloc();
     267    if (!psMetadataAddU32(values, PS_LIST_HEAD, "flags", 0, NULL, code)) {
     268        psError(PS_ERR_UNKNOWN, false, "failed to add metadata item flags");
     269        psFree(values);
     270        return false;
     271    }
     272    psFree(values);
     273
     274    long rowsAffected = psDBUpdateRows(config->dbh, "newImfile", config->where, values);
     275    if (rowsAffected < 0) {
     276        // database error
     277        psError(PS_ERR_UNKNOWN, false, "database error");
     278        return false;
     279    }
     280    if (rowsAffected < 1) {
     281        // we didn't do anything
     282        psError(PS_ERR_UNKNOWN, false, "zero rows were affected - either the search criteria didn't match any rows or the field already had the value being set.");
     283        return false;
     284    }
    236285
    237286    return true;
     
    10251074}
    10261075
     1076static psU32 mapCodeStrToInt(char *codeStr)
     1077{
     1078    if (strcasestr(codeStr, "none")) {
     1079        return PX_ERROR_NONE;
     1080    } else if (strcasestr(codeStr, "unknown")) {
     1081        return PX_ERROR_UNKNOWN;
     1082    } else if (strcasestr(codeStr, "bad_data")) {
     1083        return PX_ERROR_BAD_DATA;
     1084    } else if (strcasestr(codeStr, "id10t")) {
     1085        return PX_ERROR_ID10T;
     1086    }
     1087
     1088    psError(PS_ERR_UNKNOWN, true, "invalid fault code string");
     1089
     1090    return (psU32) -1;
     1091}
Note: See TracChangeset for help on using the changeset viewer.