IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12441


Ignore:
Timestamp:
Mar 14, 2007, 4:19:09 PM (19 years ago)
Author:
jhoblitt
Message:

fix serveral psMetdataConfig* bugs related to 'overwrite' & METADATA handling

Location:
trunk/psLib
Files:
4 edited

Legend:

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

    r12435 r12441  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.130 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2007-03-14 02:37:34 $
     12*  @version $Revision: 1.131 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2007-03-15 02:19:09 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6767static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)
    6868;
    69 static bool parseLine(psArray* levelArray, char*  linePtr,
    70                       psS32 lineCount, bool overwrite);
     69static bool parseLine(psArray* levelArray,
     70                      char* linePtr,
     71                      bool overwrite,
     72                      bool *notBlank);
    7173static bool parseMetadataItem(char* keyName, psArray* levelArray,
    72                               char* linePtr, psS32 lineCount, psMetadataFlags flags);
     74                              char* linePtr, psMetadataFlags flags);
    7375static psString formatMetadataItem(psMetadataItem *item);
    7476static psArray *p_psMetadataKeyArray(psMetadata *md);
     
    7678                         psArray* levelArray,
    7779                         char* linePtr,
    78                          psS32 lineCount,
    7980                         psMetadataFlags flags);
    8081static bool parseType(char* keyName,
    8182                      psArray* levelArray,
    8283                      char* linePtr,
    83                       psS32 lineCount,
    8484                      psMetadataFlags flags);
    8585static bool parseMetadataEnd(char* keyName,
    8686                             psArray* levelArray,
    8787                             char* linePtr,
    88                              psS32 lineCount,
    8988                             psMetadataFlags flags);
    9089
     
    672671                       psArray* levelArray,
    673672                       char* linePtr,
    674                        psS32 lineCount,
    675673                       psMetadataFlags flags)
    676674{
     
    679677    psDataType           mdType        = PS_DATA_UNKNOWN;
    680678    psElemType           vectorType    = PS_TYPE_S8;
    681     char*                strType       = NULL;
    682679    char*                strValue      = NULL;
    683680    char*                strComment    = NULL;
     
    699696    psTimeType timeType = PS_TIME_TAI;
    700697
     698    long level = psArrayLength(levelArray) - 1;
     699
    701700    // Get the metadata item type
    702     strType = getToken(&linePtr, " ", &status,true);
    703 
    704     long level = psArrayLength(levelArray) - 1;
     701    char *strType = getToken(&linePtr, " ", &status,true);
    705702
    706703    // Check for no type
    707     if(strType==NULL) {
    708         psError(PS_ERR_IO, true,
    709                 _("Failed to read a metadata %s on line %u."), "type",lineCount);
    710         returnValue = false;
     704    if (strType == NULL) {
     705        psError(PS_ERR_IO, true, _("Failed to read a metadata type."));
     706        return false;
     707    }
     708
     709    // Set metadata type based on type token
     710    // Check if the keyName specifies a vector and if so use strType token to
     711    // find vector type
     712    if (*keyName == '@') {
     713        mdType = PS_DATA_VECTOR;
     714        // Get the type of vector
     715        if(!strncmp(strType, "U8", 2)) {
     716            vectorType = PS_TYPE_U8;
     717        } else if (!strncmp(strType,"U16",3)) {
     718            vectorType = PS_TYPE_U16;
     719        } else if (!strncmp(strType,"U32",3)) {
     720            vectorType = PS_TYPE_U32;
     721        } else if (!strncmp(strType,"U64",3)) {
     722            vectorType = PS_TYPE_U64;
     723        } else if (!strncmp(strType,"S8",2)) {
     724            vectorType = PS_TYPE_S8;
     725        } else if (!strncmp(strType,"S16",3)) {
     726            vectorType = PS_TYPE_S16;
     727        } else if (!strncmp(strType,"S32",3)) {
     728            vectorType = PS_TYPE_S32;
     729        } else if (!strncmp(strType,"S64",3)) {
     730            vectorType = PS_TYPE_S64;
     731        } else if (!strncmp(strType,"F32",3)) {
     732            vectorType = PS_TYPE_F32;
     733        } else if (!strncmp(strType,"F64",3)) {
     734            vectorType = PS_TYPE_F64;
     735        } else {
     736            psError(PS_ERR_IO, true,
     737                    _("Failed to parse the value '%s' of metadata item %s, type %s, "),
     738                      "", keyName,  strType);
     739            psFree(strType);
     740            return false;
     741        }
     742    } else if(!strncmp(strType, "STR", 3)) {
     743        mdType = PS_DATA_STRING;
     744    } else if(!strncmp(strType, "BOOL", 4)) {
     745        mdType = PS_DATA_BOOL;
     746    } else if(!strncmp(strType, "S8", 2)) {
     747        mdType = PS_DATA_S8;
     748    } else if(!strncmp(strType, "S16", 3)) {
     749        mdType = PS_DATA_S16;
     750    } else if(!strncmp(strType, "S32", 3)) {
     751        mdType = PS_DATA_S32;
     752    } else if(!strncmp(strType, "S64", 3)) {
     753        mdType = PS_DATA_S64;
     754    } else if(!strncmp(strType, "U8", 2)) {
     755        mdType = PS_DATA_U8;
     756    } else if(!strncmp(strType, "U16", 3)) {
     757        mdType = PS_DATA_U16;
     758    } else if(!strncmp(strType, "U32", 3)) {
     759        mdType = PS_DATA_U32;
     760    } else if(!strncmp(strType, "U64", 3)) {
     761        mdType = PS_DATA_U64;
     762    } else if(!strncmp(strType, "F32", 3)) {
     763        mdType = PS_DATA_F32;
     764    } else if(!strncmp(strType, "F64", 3)) {
     765        mdType = PS_DATA_F64;
     766    } else if(!strncmp(strType, "MULTI", 5)) {
     767        mdType = PS_DATA_METADATA_MULTI;
     768    } else if(!strncmp(strType, "METADATA", 8)) {
     769        mdType = PS_DATA_METADATA;
     770    } else if( !strncmp(strType, "UTC", 3) || !strncmp(strType, "TAI", 3)
     771               || !strncmp(strType, "UT1", 3) || !strncmp(strType, "TT", 3)) {
     772        mdType = PS_DATA_TIME;
    711773    } else {
    712 
    713         // Set metadata type based on type token
    714 
    715         // Check if the keyName specifies a vector and if so use strType token to find vector type
    716         if(*keyName == '@') {
    717             mdType = PS_DATA_VECTOR;
    718             // Get the type of vector
    719             if(!strncmp(strType, "U8", 2)) {
    720                 vectorType = PS_TYPE_U8;
    721             } else if (!strncmp(strType,"U16",3)) {
    722                 vectorType = PS_TYPE_U16;
    723             } else if (!strncmp(strType,"U32",3)) {
    724                 vectorType = PS_TYPE_U32;
    725             } else if (!strncmp(strType,"U64",3)) {
    726                 vectorType = PS_TYPE_U64;
    727             } else if (!strncmp(strType,"S8",2)) {
    728                 vectorType = PS_TYPE_S8;
    729             } else if (!strncmp(strType,"S16",3)) {
    730                 vectorType = PS_TYPE_S16;
    731             } else if (!strncmp(strType,"S32",3)) {
    732                 vectorType = PS_TYPE_S32;
    733             } else if (!strncmp(strType,"S64",3)) {
    734                 vectorType = PS_TYPE_S64;
    735             } else if (!strncmp(strType,"F32",3)) {
    736                 vectorType = PS_TYPE_F32;
    737             } else if (!strncmp(strType,"F64",3)) {
    738                 vectorType = PS_TYPE_F64;
    739             } else {
    740                 psError(PS_ERR_IO, true,
    741                         _("Failed to parse the value '%s' of metadata item %s, type %s, "
    742                           "on line %u."), "", keyName,  strType, lineCount);
    743                 psFree(strType);
    744                 return false;
    745             }
    746         } else if(!strncmp(strType, "STR", 3)) {
    747             mdType = PS_DATA_STRING;
    748         } else if(!strncmp(strType, "BOOL", 4)) {
    749             mdType = PS_DATA_BOOL;
    750         } else if(!strncmp(strType, "S8", 2)) {
    751             mdType = PS_DATA_S8;
    752         } else if(!strncmp(strType, "S16", 3)) {
    753             mdType = PS_DATA_S16;
    754         } else if(!strncmp(strType, "S32", 3)) {
    755             mdType = PS_DATA_S32;
    756         } else if(!strncmp(strType, "S64", 3)) {
    757             mdType = PS_DATA_S64;
    758         } else if(!strncmp(strType, "U8", 2)) {
    759             mdType = PS_DATA_U8;
    760         } else if(!strncmp(strType, "U16", 3)) {
    761             mdType = PS_DATA_U16;
    762         } else if(!strncmp(strType, "U32", 3)) {
    763             mdType = PS_DATA_U32;
    764         } else if(!strncmp(strType, "U64", 3)) {
    765             mdType = PS_DATA_U64;
    766         } else if(!strncmp(strType, "F32", 3)) {
    767             mdType = PS_DATA_F32;
    768         } else if(!strncmp(strType, "F64", 3)) {
    769             mdType = PS_DATA_F64;
    770         } else if(!strncmp(strType, "MULTI", 5)) {
    771             mdType = PS_DATA_METADATA_MULTI;
    772         } else if(!strncmp(strType, "METADATA", 8)) {
    773             mdType = PS_DATA_METADATA;
    774         } else if( !strncmp(strType, "UTC", 3) || !strncmp(strType, "TAI", 3)
    775                    || !strncmp(strType, "UT1", 3) || !strncmp(strType, "TT", 3)) {
    776             mdType = PS_DATA_TIME;
    777         } else {
    778             // Search through user types
    779             typeArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->typeArray;
    780             templateArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->templateArray;
    781             for(psS32 k = 0; k < typeArray->n; k++) {
    782                 if(strcmp(strType,(char*)typeArray->data[k]) == 0) {
    783                     tempMeta = setMetadataItem((psMetadata*)templateArray->data[k],linePtr);
    784                     if(tempMeta != NULL) {
    785                         // Add metadata item
    786                         md = ((p_psParseLevelInfo*)(levelArray->data[level]))->metadata;
    787                         addStatus = psMetadataAdd(md,PS_LIST_TAIL,keyName,
    788                                                   PS_DATA_METADATA | flags,"",tempMeta);
    789                         // Check for add failure
    790                         if (! addStatus) {
    791                             psError(PS_ERR_IO, true,
    792                                     _("Duplicate Metadata item, %s, found on line %u.  "
    793                                       "Overwrite not allowed."),
    794                                     keyName, lineCount);
    795                             psFree(strType);
    796                             psFree(tempMeta);
    797                             return false;
    798                         }
     774        // Search through user types
     775        typeArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->typeArray;
     776        templateArray = ((p_psParseLevelInfo*)(levelArray->data[level]))->templateArray;
     777        for(psS32 k = 0; k < typeArray->n; k++) {
     778            if(strcmp(strType,(char*)typeArray->data[k]) == 0) {
     779                tempMeta = setMetadataItem((psMetadata*)templateArray->data[k],linePtr);
     780                if(tempMeta != NULL) {
     781                    // Add metadata item
     782                    md = ((p_psParseLevelInfo*)(levelArray->data[level]))->metadata;
     783                    addStatus = psMetadataAdd(md,PS_LIST_TAIL,keyName,
     784                                              PS_DATA_METADATA | flags,"",tempMeta);
     785                    // Check for add failure
     786                    if (! addStatus) {
     787                        psError(PS_ERR_IO, true,
     788                                _("Duplicate Metadata item, %s, found.  "
     789                                  "Overwrite not allowed."),
     790                                keyName);
     791                        psFree(strType);
    799792                        psFree(tempMeta);
    800                     } else {
    801                         // Metadata type read error
    802                         psError(PS_ERR_IO,true,
    803                                 _("Failed to read a metadata %s on line %u."),
    804                                 keyName, lineCount);
    805                         psFree(strType);
    806793                        return false;
    807794                    }
    808                     typeFound = true;
    809                     break;
     795                    psFree(tempMeta);
     796                } else {
     797                    // Metadata type read error
     798                    psError(PS_ERR_IO,true,
     799                            _("Failed to read a metadata %s."), keyName);
     800                    psFree(strType);
     801                    return false;
    810802                }
    811             }
    812             if(!typeFound) {
    813                 psError(PS_ERR_IO, true,
    814                         _("Metadata type '%s', found on line %u, is invalid."),
    815                         strType, lineCount);
    816                 psFree(strType);
    817                 return false;
    818             } else {
    819                 psFree(strType);
    820                 return true;
    821             }
     803                typeFound = true;
     804                break;
     805            }
     806        }
     807        if(!typeFound) {
     808            psError(PS_ERR_IO, true,
     809                    _("Metadata type '%s' is invalid."), strType);
     810            psFree(strType);
     811            return false;
     812        } else {
     813            psFree(strType);
     814            return true;
    822815        }
    823816    }
     
    830823
    831824        if(status) {
    832             psError(PS_ERR_IO, true,
    833                     _("Failed to read a metadata %s on line %u."), "value", lineCount);
     825            psError(PS_ERR_IO, true, _("Failed to read a metadata value."));
    834826            psFree(strType);
    835827            psFree(strValue);
     
    838830
    839831        if(strValue==NULL) {
    840             psError(PS_ERR_IO, true,
    841                     _("Failed to read a metadata %s on line %u."), "value", lineCount);
     832            psError(PS_ERR_IO, true, _("Failed to read a metadata value."));
    842833            psFree(strType);
    843834            psFree(strValue);
     
    850841        strComment = getToken(&linePtr, "", &status, true);
    851842        if(status) {
    852             psError(PS_ERR_IO, true,
    853                     _("Failed to read a metadata %s on line %u."), "comment", lineCount);
     843            psError(PS_ERR_IO, true, _("Failed to read a metadata comment"));
    854844            psFree(strType);
    855845            psFree(strValue);
     
    876866        } else {
    877867            psError(PS_ERR_IO, true,
    878                     _("Failed to parse the value '%s' of metadata item %s, type %s, "
    879                       "on line %u."), strValue, keyName, strType, lineCount);
     868                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     869                      strValue, keyName, strType);
    880870            returnValue = false;
    881871        }
     
    890880        } else {
    891881            psError(PS_ERR_IO, true,
    892                     _("Failed to parse the value '%s' of metadata item %s, type %s, "
    893                       "on line %u."), strValue, keyName, strType, lineCount);
     882                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     883                      strValue, keyName, strType);
    894884            returnValue = false;
    895885        }
     
    902892        } else {
    903893            psError(PS_ERR_IO, true,
    904                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    905                     strValue, keyName, strType, lineCount);
     894                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     895                    strValue, keyName, strType);
    906896            returnValue = false;
    907897        }
     
    914904        } else {
    915905            psError(PS_ERR_IO, true,
    916                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    917                     strValue, keyName, strType, lineCount);
     906                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     907                    strValue, keyName, strType);
    918908            returnValue = false;
    919909        }
     
    926916        } else {
    927917            psError(PS_ERR_IO, true,
    928                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    929                     strValue, keyName, strType, lineCount);
     918                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     919                    strValue, keyName, strType);
    930920            returnValue = false;
    931921        }
     
    938928        } else {
    939929            psError(PS_ERR_IO, true,
    940                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    941                     strValue, keyName, strType, lineCount);
     930                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     931                    strValue, keyName, strType);
    942932            returnValue = false;
    943933        }
     
    950940        } else {
    951941            psError(PS_ERR_IO, true,
    952                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    953                     strValue, keyName, strType, lineCount);
     942                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     943                    strValue, keyName, strType);
    954944            returnValue = false;
    955945        }
     
    962952        } else {
    963953            psError(PS_ERR_IO, true,
    964                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    965                     strValue, keyName, strType, lineCount);
     954                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     955                    strValue, keyName, strType);
    966956            returnValue = false;
    967957        }
     
    974964        } else {
    975965            psError(PS_ERR_IO, true,
    976                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    977                     strValue, keyName, strType, lineCount);
     966                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     967                    strValue, keyName, strType);
    978968            returnValue = false;
    979969        }
     
    986976        } else {
    987977            psError(PS_ERR_IO, true,
    988                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    989                     strValue, keyName, strType, lineCount);
     978                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     979                    strValue, keyName, strType);
    990980            returnValue = false;
    991981        }
     
    1009999        } else {
    10101000            psError(PS_ERR_IO, true,
    1011                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    1012                     strValue, keyName, strType, lineCount);
     1001                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     1002                    strValue, keyName, strType);
    10131003            returnValue = false;
    10141004        }
     
    10231013        } else {
    10241014            psError(PS_ERR_IO, true,
    1025                     _("Failed to parse the value '%s' of metadata item %s, type %s, on line %u."),
    1026                     strValue, keyName, strType, lineCount);
     1015                    _("Failed to parse the value '%s' of metadata item %s, type %s."),
     1016                    strValue, keyName, strType);
    10271017            returnValue = false;
    10281018        }
     
    10351025        for(psS32 k=0; k < nonUniqueKeys->n; k++) {
    10361026            if(strcmp(keyName,(char*)nonUniqueKeys->data[k]) == 0) {
    1037                 psError(PS_ERR_IO,true,_("Duplicate MULTI specifier on line %u."),
    1038                         lineCount);
     1027                psError(PS_ERR_IO,true,_("Duplicate MULTI specifier."));
    10391028                psFree(strType);
    10401029                return false;
     
    10471036        break;
    10481037    case PS_DATA_METADATA: {
     1038            // check to see if this keyname already exists and is allowed as a
     1039            // MULTI.  If we don't do this check first, it's possible that we
     1040            // can create a new "scope" yet fail to add the new metdata.
     1041            psMetadataItem *item = psMetadataLookup (md, keyName);
     1042            if ((item != NULL) &&
     1043                    ((item->type != PS_DATA_METADATA_MULTI) &&
     1044                    ((flags & PS_META_REPLACE) == 0))
     1045            ) {
     1046                psError(PS_ERR_IO, true, _("Duplicate Metadata declaration: %s is not allowed without 'overwrite' or MULTI specifier."), keyName);
     1047                break;
     1048            }
     1049           
    10491050            // create the nested metadata
    10501051            psMetadata *newScope = psMetadataAlloc();
     
    10531054            nextLevelInfo = p_psParseLevelInfoAlloc();
    10541055
    1055             // switch to the scope to the new metadata
    1056             nextLevelInfo->metadata = newScope;
    1057 
    1058             // Add next level to levelArray
    1059             levelArray = psArrayAdd(levelArray, 0, nextLevelInfo);
    1060             psFree(nextLevelInfo);
    1061 
     1056
     1057            // try to add the new metdata to the current one
    10621058            addStatus = psMetadataAdd(md, PS_LIST_TAIL, keyName,
    10631059                                      mdType | flags,
    10641060                                      strComment, newScope);
     1061
     1062            if (addStatus) {
     1063                // switch to the scope to the new metadata
     1064                nextLevelInfo->metadata = psMemIncrRefCounter(newScope);
     1065
     1066                // Add next level to levelArray
     1067                levelArray = psArrayAdd(levelArray, 0, nextLevelInfo);
     1068            }
     1069
     1070            psFree(nextLevelInfo);
     1071            psFree(newScope);
     1072
    10651073            break;
    10661074        }
    10671075    default:
    10681076        psError(PS_ERR_IO, true,
    1069                 _("Metadata of unknown type found on line %u."), lineCount);
     1077                _("Metadata of unknown type found."));
    10701078        break;
    10711079    }
     
    10831091}
    10841092
    1085 bool parseLine(psArray* levelArray,
    1086                char* linePtr,
    1087                psS32 lineCount,
    1088                bool overwrite)
     1093static bool parseLine(psArray* levelArray,
     1094                      char* linePtr,
     1095                      bool overwrite,
     1096                      bool *notBlank)
    10891097{
    10901098    psMetadataFlags     flags  = PS_META_DEFAULT;
     
    10981106    if (ignoreLine(linePtr)) {
    10991107        // do nothing and return
     1108        if (notBlank) {
     1109            *notBlank = false;
     1110        }
    11001111        return true;
    11011112    }
     1113
     1114    // even if it's a "bad line" we know it can't be "blank" after this point
     1115    *notBlank = true;
    11021116
    11031117    // Check for more than one '@' in a line
     
    11061120    if (repeatedChars(linePtr, '@') > 1) {
    11071121        psError(PS_ERR_IO, true,
    1108                 _("More than one '@' character not allowed.  Found on line %u."), lineCount);
     1122                _("More than one '@' character is not allowed"));
    11091123        return false;
    11101124    }
     
    11141128    char *keyName = getToken(&linePtr, " ", &status, true);
    11151129    if (status) {
    1116         psError(PS_ERR_IO, true,
    1117                 _("Failed to read item key name on line %u."), lineCount);
     1130        psError(PS_ERR_IO, true, _("Failed to read item key name on line"));
    11181131        psFree(keyName);
    11191132        return false;
     
    11221135    // Check for special keyName values "TYPE", "END"
    11231136    if (strcmp(keyName, "END") == 0) {
    1124         if (!parseMetadataEnd(keyName, levelArray, linePtr, lineCount, flags)) {
     1137        if (!parseMetadataEnd(keyName, levelArray, linePtr, flags)) {
    11251138            goto FAIL;
    11261139        }
    11271140    } else if (strcmp(keyName,"TYPE") == 0 ) {
    1128         if (!parseType(keyName, levelArray, linePtr, lineCount, flags)) {
     1141        if (!parseType(keyName, levelArray, linePtr, flags)) {
    11291142            goto FAIL;
    11301143        }
    11311144    } else {
    1132         if (!parseGeneric(keyName, levelArray, linePtr, lineCount, flags)) {
     1145        if (!parseGeneric(keyName, levelArray, linePtr, flags)) {
    11331146            goto FAIL;
    11341147        }
     
    11401153
    11411154FAIL:
    1142     psError(PS_ERR_UNKNOWN, false,
    1143             _("Failed to parse line %u: %s."), lineCount, linePtr);
     1155    psError(PS_ERR_UNKNOWN, false, _("Failed to parse line"));
    11441156    psFree(keyName);
    11451157    return false;
     
    11491161                         psArray* levelArray,
    11501162                         char* linePtr,
    1151                          psS32 lineCount,
    11521163                         psMetadataFlags flags)
    11531164{
     
    11691180
    11701181    // Parse metadataItem
    1171     if (!parseMetadataItem(keyName, levelArray, linePtr, lineCount, flags)) {
     1182    if (!parseMetadataItem(keyName, levelArray, linePtr, flags)) {
    11721183        return false;
    11731184    }
     
    11791190                      psArray* levelArray,
    11801191                      char* linePtr,
    1181                       psS32 lineCount,
    11821192                      psMetadataFlags flags)
    11831193{
     
    11921202    char *strType = getToken(&linePtr, " ", &status, true);
    11931203    if(!strType) {
    1194         psError(PS_ERR_IO,true,
    1195                 _("Failed to read item type on line %u."), lineCount);
     1204        psError(PS_ERR_IO,true, _("Failed to read item type."));
    11961205        return false;
    11971206    }
    11981207    if (status) {
    1199         psError(PS_ERR_IO, true,
    1200                 _("Failed to read item type on line %u."), lineCount);
     1208        psError(PS_ERR_IO, true, _("Failed to read item type."));
    12011209        psFree(strType);
    12021210        return false;
     
    12061214    psMetadata *tempTemplate = getMetadataType(linePtr);
    12071215    if (!tempTemplate) {
    1208         psError(PS_ERR_IO,true,
    1209                 _("Metadata type '%s', found on line %u, is invalid."),
    1210                 strType,lineCount);
     1216        psError(PS_ERR_IO,true, _("Metadata type '%s' is invalid."), strType);
    12111217        psFree(strType);
    12121218        return false;
     
    12211227        if (strcmp(strType, (char*)typeArray->data[k]) == 0) {
    12221228            psError(PS_ERR_IO,true,
    1223                     _("Specified type, %s, on line %u is already defined."),
    1224                     strType, lineCount);
     1229                    _("Specified type %s is already defined."), strType);
    12251230            psFree(tempTemplate);
    12261231            psFree(strType);
     
    12441249                             psArray* levelArray,
    12451250                             char* linePtr,
    1246                              psS32 lineCount,
    12471251                             psMetadataFlags flags)
    12481252{
     
    13791383        return NULL;
    13801384    }
     1385
     1386    // accept completely empty strings
     1387    // nFail == 0 / nPass == 0 - OK
    13811388    if (psListLength(doc) == 0) {
    1382         psError(PS_ERR_UNKNOWN, false, "string contained no lines");
     1389        psTrace("psLib.types", PS_LOG_INFO, "string contained no lines");
    13831390        psFree(doc);
    1384         if (allocedMD) {
    1385             psFree(md);
    1386         }
    1387         return NULL;
     1391        return md;
    13881392    }
    13891393
     
    14011405    psErrorClear();
    14021406
     1407    // line type counts
     1408    long nLines = 0;                // all lines
     1409    long nGood  = 0;                // valid lines excluding blank/comment
     1410    long nBad   = 0;                // invalid lines
     1411
    14031412    // While loop to parse the file
    1404     long lineCount = 0;
    14051413    char *line = NULL;
    14061414    psListIterator *iter = psListIteratorAlloc(doc, 0, false);
    14071415    while ((line = psListGetAndIncrement(iter))) {
    1408         lineCount++; // indexed from 1
    1409 
    1410         if (!parseLine(parseLevelInfoArray, line, lineCount,
    1411                        overwrite)) {
    1412             if (nFail != NULL) {
    1413                 (*nFail)++;
    1414             } else {
    1415                 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Error parsing line: %s", line);
    1416             }
    1417             psTrace("psLib.types", 4, "Error parsing line: %s", line);
     1416        nLines++; // indexed from 1
     1417
     1418        bool notBlank = false;
     1419        if (!parseLine(parseLevelInfoArray, line, overwrite, &notBlank)) {
     1420            nBad++;
     1421            psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Error parsing line #%lu : %s", nLines, line);
     1422        } else if (notBlank) {
     1423        // do not count blank/comment lines as "good" lines
     1424            nGood++;
    14181425        }
    14191426    }
     
    14251432    psFree(parseLevelInfoArray);
    14261433
     1434    // nFail > 0 / nPass == 0 - NULL
     1435    if ((nBad > 0) && (nGood == 0)) {
     1436        psError(PS_ERR_UNKNOWN, false, "string contained no data lines and %ld bad lines", nBad);
     1437        psFree(md);
     1438        return NULL;
     1439    }
     1440
     1441    // pass back the number of failed lines
     1442    if (nFail) {
     1443        *nFail = nBad;
     1444    }
     1445
     1446    // nFail == 0 / nPass > 0
     1447    // nFail > 0 / nPass > 0
    14271448    return md;
    14281449}
  • trunk/psLib/test/types/metaconf.in

    r9895 r12441  
     1#
     2# Good lines
     3#
     4
    15item1            BOOL      T                # I am a boolean
    2 item1            BOOL      F                # I am a boolean2
    36item2            S32       55               # I am int
    47item3            F32       3.14
    58item4            F64       6.28             # I am float
    6 item4-1          F64       6.28 1           # I am float
    79item5            STR       GNIRTS           # I am a string
    8 item6            S32       10 1
    9 item6-1          S32       ~
    1010item7            S64       555
    11 item7-1          S64       555 x
    1211item8            S8        3
    13 item8            S8        5
    14 item8-1          S8        5 1
    1512itemu1           U16       2
    16 itemu1-1         U16       2 1
    1713itemu2           U32       55
    18 itemu2-1         U32       55 1
    19 itemu3-1         U8        1 2
    2014itemu3           U8        1
    2115itemu4           U64       1634
    22 itemu4-1         U64       1634 1
    2316item9            BOOL      F                # I am a boolean2
    2417item10           S16       16
    25 item10-1         S16       16 16
    2618@vector1  S8  1 2 3 4 5   # I am a vector
    27 @vector1-1 S8 % #
    2819@vector2  S16 1 2 3 4 5
    2920@vector3  S32 1 2 3 4 5
     
    3526@vector9  F32 1.0 2.3 3.1 4.5 5.0   # I am a vector
    3627@vector10 F64 1.0 2.0 3.0 4.0 5.0
    37 @vector11 C64 1.0 2.0 3.0 4.0 5.0
    38 @@@vector12 F64 1.0 2.0 3.0 4.0 5.0
    3928time01           TT        1970-01-01T00:16:39Z  # I am time
    4029time02           UTC       NULL     # I am time2
    41 
    42 ps1  S32  NAN
    4330
    4431f32 MULTI
    4532f32              S32       666              # f32_1
    4633f32              S32       665              # f32_2
    47 f32 MULTI
    4834
    4935f32 METADATA
     
    5440meta1 METADATA
    5541    itemS32   S32       666              # f32_1
    56 END
    57 meta1 METADATA
    58     M2   S32       666
    5942END
    6043
     
    6851   ITEM03           F64       666.666          # I AM DOUBLE
    6952END
    70 
    71      TYPE  C32  3
    72      TYPE  C32  3
    73      TYPE PS_TYPE_C32 2                 #
    74 newC32      C32 7i+5
    75 newC32      PS_TYPE_C32 7i+5
    7653#item11           C32       16+2i            # I am Complex
    7754
    7855TYPE PS_TYPE_DD D
     56DD2     PS_TYPE_DD   ""
     57     TYPE  C32  3
     58newC32      C32 7i+5
     59
     60#
     61# Bad lines : 28 (-1 for the GOOD line in meta1) & 3 valid duplicates
     62#
     63item1            BOOL      F                # duplicate
     64item8            S8        5                # duplicate
     65item4-1          F64       6.28 1           # I am float
     66item6            S32       10 1
     67item6-1          S32       ~
     68item7-1          S64       555 x
     69item8-1          S8        5 1
     70itemu1-1         U16       2 1
     71itemu2-1         U32       55 1
     72itemu3-1         U8        1 2
     73itemu4-1         U64       1634 1
     74item10-1         S16       16 16
     75@vector1-1 S8 % #
     76@@@vector12 F64 1.0 2.0 3.0 4.0 5.0
     77@vector11 C64 1.0 2.0 3.0 4.0 5.0
     78meta1 METADATA                              # duplicate
     79    M2   S32       666  # this line is "GOOD" but parsed in the top level
     80END
    7981newDD   PS_TYPE_DD
    80 DD2     PS_TYPE_DD   ""
    81 
    8282TYPE            1
    8383TYPE
    8484TYPE         #  # 1
     85     TYPE  C32  3
     86     TYPE PS_TYPE_C32 2                 #
     87newC32      PS_TYPE_C32 7i+5        # duplicate but with borken type
     88ps1  S32  NAN
     89f32 MULTI
    8590\n
  • trunk/psLib/test/types/table3.dat

    r9746 r12441  
    1 #  Table with valid types and index-values
     1#
     2# This file is not valid metdataconfig syntax
    23#
    34#psF32     psU16    psU32     psU64    psS8    psS16    psS32    psS64    psU8   psF64
  • trunk/psLib/test/types/tap_psMetadataConfig_input.c

    r12408 r12441  
    1919#include "pstap.h"
    2020
    21 static void testMetaConfigRead(void);
    22 static void testMetaConfigParse(void);
    23 
    24 
    2521int main(void)
    2622{
     23    plan_tests(42);
     24
    2725    psLogSetFormat("HLNM");
    28     plan_tests(39);
    29 
    30     note("Tests for psMetadataConfig Input Functions");
    31     testMetaConfigRead();
    32     testMetaConfigParse();
    33 }
    34 
    35 void testMetaConfigRead(void)
    36 {
    37     note("  >>>Test 1:  psMetadataConfigRead");
    38 
    39     //Return NULL for NULL filename input
     26//    psTraceSetLevel("err", 10);
     27
     28
     29    // Return NULL for NULL filename input
    4030    {
    4131        unsigned int nfail = 0;
    4232        psMetadata *out = psMetadataConfigRead(NULL, &nfail, NULL, false);
    43         ok( out == NULL,
    44             "psMetadataConfigRead: return NULL for NULL filename input.");
    45     }
    46     //Return NULL for invalid filename input
     33
     34        ok(out == NULL, "return NULL for NULL filename input.");
     35    }
     36
     37    // Return NULL for invalid filename input
    4738    {
    4839        unsigned int nfail = 0;
    4940        psMetadata *out = psMetadataConfigRead(NULL, &nfail, ".", false);
    50         ok( out == NULL,
    51             "psMetadataConfigRead: return NULL for invalid filename input.");
    52     }
    53     //Return NULL for missing file input
     41
     42        ok(out == NULL, "return NULL for invalid filename input.");
     43    }
     44
     45    // Return NULL for missing file input
    5446    {
    5547        unsigned int nfail = 0;
    5648        psMetadata *out = psMetadataConfigRead(NULL, &nfail, "table4.dat", false);
    57         ok( out == NULL,
    58             "psMetadataConfigRead: return NULL for missing file input.");
    59     }
    60     //Return empty metadata for read-only file with invalid syntax
     49        ok(out == NULL, "return NULL for missing file input.");
     50    }
     51
     52    // Return NULL for read-only file with comments, bad syntax, and no good
     53    // lines
    6154    {
    6255        unsigned int nfail = 0;
    6356        psMetadata *out = psMetadataConfigRead(NULL, &nfail, "table3.dat", false);
    64         ok( out != NULL && out->list->n == 0,
    65             "psMetadataConfigRead: return empty metadata for file"
    66             " with invalid syntax.");
    67         psFree(out);
    68     }
    69     //Return true for valid inputs - overwrite = false
     57        ok(out == NULL, "return NULL for all bad syntax");
     58        is_int(nfail, 0, "correct nfail");
     59
     60        psFree(out);
     61    }
     62
     63    // Return true for valid inputs - overwrite = false
    7064    {
    7165        unsigned int nfail = 0;
    7266        psMetadata *out = psMetadataConfigRead(NULL, &nfail, "metaconf.in", false);
    73         psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD);
    74 
    75         //XXX: Josh, please review the "metaconf.in" in this directory and ensure that
    76         //the number of failed lines, which we test next, should indeed be 26.
    77         ok(out != NULL && nfail == 26,
    78             "psMetadataConfigRead: return correct metadata for valid inputs (nfail was %d)", nfail);
    79         skip_start(tempItem == NULL, 6,
    80                      "Skipping 1 tests because metadata container is empty!");
    81         ok_str(tempItem->name, "item1",
    82                "psMetadataConfigRead: return correct metadataItem name from "
    83                "returned metadata.");
    84         ok(tempItem->type == PS_DATA_BOOL && tempItem->data.B == true,
    85             "psMetadataConfigRead: return correct metadataItem data from "
    86             "returned metadata.");
    87         ok_str(tempItem->comment, "I am a boolean",
    88                 "psMetadataConfigRead: return correct metadataItem comment from "
    89                 "returned metadata.");
     67
     68        ok(out != NULL, "return metadata for valid input");
     69        is_int(nfail, 27, "return correct nFail count");
     70
     71        skip_start(out == NULL, 8,
     72                     "Skipping 1 tests because metadata container is empty!");
     73
     74        // look at the first item
     75        psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD);
     76        // XXX shouldn't assume tempItem isn't NULL
     77        ok_str(tempItem->name, "item1", "metadataItem name");
     78        ok(tempItem->type == PS_DATA_BOOL, "metadataItem type");
     79        is_bool(tempItem->data.B, true, "metdataItem value");
     80        ok_str(tempItem->comment, "I am a boolean", "metadataItem comment.");
     81
     82        // look at the last item
    9083        tempItem = psMetadataGet(out, PS_LIST_TAIL);
    91         ok_str(tempItem->name, "DD2",
    92                 "psMetadataConfigRead: return correct metadataItem name from returned metadata");
    93         ok(tempItem->type == PS_DATA_METADATA &&
    94             ((psMetadata*)(tempItem->data.V))->list->n == 1
    95             && strlen(tempItem->comment) == 0,
    96             "psMetadataConfigRead: return correct metadataItem data from "
    97             "returned metadata.");
    98         skip_end();
    99         // psMetadataConfigWrite(out, "mdc-overwrite_false.txt");
    100         psFree(out);
    101     }
    102 
    103     //Return true for valid inputs - overwrite = true
     84        // XXX shouldn't assume tempItem isn't NULL
     85        ok_str(tempItem->name, "M2", "metadataItem name");
     86        ok(tempItem->type == PS_DATA_S32, "metdataItem type");
     87        is_int(tempItem->data.S32, 666, "metdataItem value");
     88        ok_str(tempItem->comment, "this line is \"GOOD\" but parsed in the top level", "metadataItem comment.");
     89
     90        skip_end();
     91        psFree(out);
     92    }
     93
     94    // Return true for valid inputs - overwrite = true
    10495    {
    10596        unsigned int nfail = 0;
    10697        psMetadata *out = psMetadataConfigRead(NULL, &nfail, "metaconf.in", true);
    107         psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD);
    108         //XXX: Josh, please review the "metaconf.in" in this directory and ensure that
    109         //the number of failed lines, which we test next, should indeed be 23.
    110         ok( out != NULL  && nfail == 23,
    111             "psMetadataConfigRead: return correct metadata for valid inputs (nfail was %d).", nfail);
    112         skip_start(  tempItem == NULL, 6,
    113                      "Skipping 1 tests because metadata container is empty!");
    114         ok_str( tempItem->name, "item1",
    115                 "psMetadataConfigRead: return correct metadataItem name from "
    116                 "returned metadata.");
    117         ok( tempItem->type == PS_DATA_BOOL && tempItem->data.B == false,
    118             "psMetadataConfigRead: return correct metadataItem data from "
    119             "returned metadata.");
    120         ok_str( tempItem->comment, "I am a boolean2",
    121                 "psMetadataConfigRead: return correct metadataItem comment from "
    122                 "returned metadata.");
     98//        psMetadataConfigPrint(stdout, out);
     99
     100        ok(out != NULL, "return metadata for valid input");
     101        is_int(nfail, 23, "return correct nFail count");
     102
     103        skip_start(out == NULL, 7,
     104                     "Skipping 1 tests because metadata container is empty!");
     105
     106        // look at the first item
     107        psMetadataItem *tempItem = psMetadataGet(out, PS_LIST_HEAD);
     108        // XXX shouldn't assume tempItem isn't NULL
     109        // note that item1 gets added to the "tail" of the metdata was it's
     110        // replaced
     111        ok_str(tempItem->name, "item2", "metadataItem name");
     112        ok(tempItem->type == PS_DATA_S32, "metdataItem type");
     113        is_bool(tempItem->data.S32, 55, "metadataItem value");
     114        ok_str(tempItem->comment, "I am int", "metadataItem value");
     115
     116        // look at the last item
    123117        tempItem = psMetadataGet(out, PS_LIST_TAIL);
    124         ok_str( tempItem->name, "DD2",
    125                 "psMetadataConfigRead: return correct metadataItem name from "
    126                 "returned metadata.");
    127         ok( tempItem->type == PS_DATA_METADATA &&
    128             ((psMetadata*)(tempItem->data.V))->list->n == 1
    129             && strlen(tempItem->comment) == 0,
    130             "psMetadataConfigRead: return correct metadataItem data from "
    131             "returned metadata.");
    132         skip_end();
    133         // psMetadataConfigWrite(out, "mdc-overwrite_true.txt");
    134         psFree(out);
    135     }
    136 
    137     //Check for Memory leaks
     118        // XXX shouldn't assume tempItem isn't NULL
     119        // meta1 is from "the bad section"
     120        ok_str(tempItem->name, "meta1", "metadataItem name");
     121        ok(tempItem->type == PS_DATA_METADATA, "metadataItem type");
     122
     123        ok_str(tempItem->comment, "", "metadataItem comment");
     124
     125        skip_end();
     126        psFree(out);
     127    }
     128
     129    // Check for Memory leaks
    138130    checkMem();
    139 }
    140 
    141 void testMetaConfigParse(void)
    142 {
    143     note("  >>>Test 2: psMetadataConfigParse");
    144 
    145     //Return NULL for NULL string input
     131
     132    // Return NULL for NULL string input
    146133    {
    147134        psMemId id = psMemGetId();
    148135        unsigned int nfail = 0;
    149136        psMetadata *out = psMetadataConfigParse(NULL, &nfail, NULL, false);
    150         ok(out == NULL,
    151            "psMetadataConfigParse: return NULL for NULL string input.");
    152         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    153     }
    154 
    155     //Return empty metadata for incorrect string input
     137
     138        ok(out == NULL, "psMetadataConfigParse: return NULL for NULL string input.");
     139
     140        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     141    }
     142
     143    // Return empty metadata for incorrect string input
    156144    {
    157145        psMemId id = psMemGetId();
     
    167155    }
    168156
    169     //Return correct metadata for correct string input - S32
     157    // Return correct metadata for correct string input - S32
    170158    {
    171159        psMemId id = psMemGetId();
     
    188176    }
    189177
    190     //Return correct metadata for correct string input - F64
     178    // Return correct metadata for correct string input - F64
    191179    {
    192180        psMemId id = psMemGetId();
     
    213201    }
    214202
    215     //Return correct metadata for string with duplicate entry - S8
     203    // Return correct metadata for string with duplicate entry - S8
    216204    {
    217205        psMemId id = psMemGetId();
Note: See TracChangeset for help on using the changeset viewer.