IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 28, 2007, 2:52:51 PM (19 years ago)
Author:
jhoblitt
Message:

implement magictool -inputtree

File:
1 edited

Legend:

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

    r14666 r14688  
    11/*
    2  * warptool.c
     2 * magictool.c
    33 *
    4  * Copyright (C) 2006  Joshua Hoblitt
     4 * Copyright (C) 2006-2007  Joshua Hoblitt
    55 *
    66 * This program is free software; you can redistribute it and/or modify it
     
    4343
    4444static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state);
     45static bool parseAndInsertNodeDeps(pxConfig *config, psS64 magic_id, const char *filename);
    4546
    4647# define MODECASE(caseName, func) \
     
    220221{
    221222    PS_ASSERT_PTR_NON_NULL(config, false);
     223
     224    bool status = false;
     225    psString magic_id = psMetadataLookupStr(&status, config->args, "-magic_id");
     226    if (!status) {
     227        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -magic_id");
     228        return false;
     229    }
     230    if (!magic_id) {
     231        psError(PS_ERR_UNKNOWN, true, "-magic_id is required");
     232        return false;
     233    }
     234
     235    psString diff_id = psMetadataLookupStr(&status, config->args, "-diff_id");
     236    if (!status) {
     237        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -diff_id");
     238        return false;
     239    }
     240    if (!diff_id) {
     241        psError(PS_ERR_UNKNOWN, true, "-diff_id is required");
     242        return false;
     243    }
     244
     245    psString node = psMetadataLookupStr(&status, config->args, "-node");
     246    if (!status) {
     247        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -node");
     248        return false;
     249    }
     250    if (!node) {
     251        psError(PS_ERR_UNKNOWN, true, "-node is required");
     252        return false;
     253    }
     254
     255    magicInputSkyfileInsert(
     256            config->dbh,
     257            (psS64)atoll(magic_id),
     258            (psS64)atoll(diff_id),
     259            node
     260    );
     261
    222262    return true;
    223263}
     
    227267{
    228268    PS_ASSERT_PTR_NON_NULL(config, false);
     269
     270    bool status = false;
     271    psString magic_id = psMetadataLookupStr(&status, config->args, "-magic_id");
     272    if (!status) {
     273        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -magic_id");
     274        return false;
     275    }
     276    if (!magic_id) {
     277        psError(PS_ERR_UNKNOWN, true, "-magic_id is required");
     278        return false;
     279    }
     280
     281    psString dep_file = psMetadataLookupStr(&status, config->args, "-dep_file");
     282    if (!status) {
     283        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -dep_file");
     284        return false;
     285    }
     286    if (!dep_file) {
     287        psError(PS_ERR_UNKNOWN, true, "-dep_file is required");
     288        return false;
     289    }
     290
     291    if (!parseAndInsertNodeDeps(config, (psS64)atoll(magic_id), dep_file)) {
     292    }
     293
    229294    return true;
    230295}
     
    14481513}
    14491514#endif
     1515
     1516static bool parseAndInsertNodeDeps(pxConfig *config, psS64 magic_id, const char *filename)
     1517{
     1518    unsigned int nFail = 0;
     1519    psMetadata *deps = psMetadataConfigRead(NULL, &nFail, filename, false);
     1520    if (!deps) {
     1521        psError(PS_ERR_UNKNOWN, false, "failed to parse file: %s", filename);
     1522        return false;
     1523    }
     1524    if (nFail) {
     1525        psError(PS_ERR_UNKNOWN, false, "there were %d errors parsing file: %s", nFail, filename);
     1526        psFree(deps);
     1527        return false;
     1528    }
     1529
     1530    psMetadataItem *item = NULL;
     1531    psMetadataIterator *iter = psMetadataIteratorAlloc(deps, 0, NULL);
     1532    while ((item = psMetadataGetAndIncrement(iter))) {
     1533        if (item->type != PS_DATA_STRING) {
     1534            psError(PS_ERR_UNKNOWN, false, "file: %s is in the wrong format", filename);
     1535            psFree(iter);
     1536            psFree(deps);
     1537            return false;
     1538        }
     1539
     1540        char *name = item->name;
     1541        char *dependsOn = item->data.str;
     1542
     1543        if (!magicTreeInsert(
     1544                config->dbh,
     1545                magic_id,
     1546                name,
     1547                dependsOn
     1548            )) {
     1549            psError(PS_ERR_UNKNOWN, false, "database error");
     1550            psFree(iter);
     1551            psFree(deps);
     1552            return false;
     1553        }
     1554    }
     1555    psFree(iter);
     1556    psFree(deps);
     1557
     1558    return true;
     1559}
Note: See TracChangeset for help on using the changeset viewer.