IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9873


Ignore:
Timestamp:
Nov 6, 2006, 6:35:21 PM (20 years ago)
Author:
jhoblitt
Message:

improve error handling in psMetadataConfigParse()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psMetadataConfig.c

    r9872 r9873  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.109 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-11-07 04:21:05 $
     12*  @version $Revision: 1.110 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-11-07 04:35:21 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    12271227{
    12281228    // Check for NULL file name
    1229     PS_ASSERT_PTR_NON_NULL(filename,NULL);
     1229    PS_ASSERT_PTR_NON_NULL(filename, NULL);
    12301230
    12311231    // Attempt to open specified file
     
    12961296                                  bool overwrite)
    12971297{
    1298     psArray*            parseLevelInfoArray  = NULL;
    1299     psS32               nestingLevel         = 0;
    1300     p_psParseLevelInfo* topLevelInfo         = NULL;
     1298    bool allocedMD = false;
     1299
     1300    PS_ASSERT_PTR_NON_NULL(str, NULL);
    13011301
    13021302    // Initialise nFail, if provided
     
    13071307    // Allocate metadata if necessary
    13081308    if (md == NULL) {
     1309        allocedMD = true;
    13091310        md = psMetadataAlloc();
    13101311    }
    13111312
    13121313    // Allocate array to store parse level information
    1313     parseLevelInfoArray = psArrayAllocEmpty(INITIAL_LENGTH);
     1314    psArray *parseLevelInfoArray = psArrayAllocEmpty(INITIAL_LENGTH);
    13141315
    13151316    // Set parse level info for the top level
    1316     topLevelInfo = p_psParseLevelInfoAlloc();
     1317    p_psParseLevelInfo *topLevelInfo = p_psParseLevelInfoAlloc();
    13171318    topLevelInfo->metadata = psMemIncrRefCounter(md);
    1318     parseLevelInfoArray = psArrayAdd(parseLevelInfoArray, 1, topLevelInfo);
     1319    psArrayAdd(parseLevelInfoArray, 0, topLevelInfo);
    13191320    psFree(topLevelInfo);
    13201321
     1322    psList *doc = psStringSplit(str, "\n", false);
     1323    if (!doc) {
     1324        psError(PS_ERR_UNKNOWN, false, "failed to split string: %s", str);
     1325        psFree(parseLevelInfoArray);
     1326        if (allocedMD) {
     1327            psFree(md);
     1328        }
     1329        return NULL;
     1330    }
     1331    if (psListLength(doc) == 0) {
     1332        psError(PS_ERR_UNKNOWN, false, "string contained no lines");
     1333        psFree(doc);
     1334        psFree(parseLevelInfoArray);
     1335        if (allocedMD) {
     1336            psFree(md);
     1337        }
     1338        return NULL;
     1339    }
     1340
     1341    // clear the error stack so we can call psError(..., false, ...) and let
     1342    // errors from the parse loop accumulate
     1343    psErrorClear();
     1344
    13211345    // While loop to parse the file
    1322     psErrorClear();   // so we can call psError(..., false, ...)
    1323 
    1324     psList *doc = psStringSplit(str, "\n", false);
    1325     if (!doc || doc->n == 0) {
    1326         if (doc != NULL)
    1327             psFree(doc);
    1328         psFree(parseLevelInfoArray);
    1329         psFree(md);
    1330         return NULL;
    1331     }
    1332 
    13331346    long lineCount = 0;
    13341347    char *line = NULL;
     1348    psS32 nestingLevel  = 0;
    13351349    psListIterator *iter = psListIteratorAlloc(doc, 0, false);
    1336     while((line = psListGetAndIncrement(iter))) {
     1350    while ((line = psListGetAndIncrement(iter))) {
    13371351        lineCount++; // indexed from 1
    13381352
    1339         if(!parseLine(&nestingLevel, parseLevelInfoArray, line, lineCount,
    1340                       overwrite)) {
     1353        if (!parseLine(&nestingLevel, parseLevelInfoArray, line, lineCount,
     1354                       overwrite)) {
    13411355            if (nFail != NULL) {
    13421356                (*nFail)++;
Note: See TracChangeset for help on using the changeset viewer.