IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17507


Ignore:
Timestamp:
May 4, 2008, 1:40:26 PM (18 years ago)
Author:
eugene
Message:

parse METADATA and MULTI directives UPDATE and RESET

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080430/psLib/src/types/psMetadataConfig.c

    r17498 r17507  
    1111*  @author Joshua Hoblitt, University of Hawaii 2006-2007
    1212*
    13 *  @version $Revision: 1.142.8.2 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2008-05-02 00:10:43 $
     13*  @version $Revision: 1.142.8.3 $ $Name: not supported by cvs2svn $
     14*  @date $Date: 2008-05-04 23:40:26 $
    1515*
    1616*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6363/*****************************************************************************/
    6464
    65 static psMetadata* genTypeTemplate(char *linePtr);
    66 static psMetadata* parseTypeValues(psMetadata* template, char* linePtr)
     65static psMetadata *genTypeTemplate(char *linePtr);
     66static psMetadata *parseTypeValues(psMetadata *template, char *linePtr)
    6767;
    68 static bool parseLine(psArray* levelArray,
    69                       char* linePtr,
     68static bool parseLine(psArray *levelArray,
     69                      char *linePtr,
    7070                      bool overwrite,
    7171                      bool *notBlank);
    72 static bool parseMetadataItem(char* keyName, psArray* levelArray,
    73                               char* linePtr, psMetadataFlags flags);
     72static bool parseMetadataItem(char *keyName, psArray *levelArray,
     73                              char *linePtr, psMetadataFlags flags);
    7474static psString formatMetadataItem(psMetadataItem *item);
    7575static psArray *p_psMetadataKeyArray(psMetadata *md);
    76 static bool parseGeneric(char* keyName,
    77                          psArray* levelArray,
    78                          char* linePtr,
     76static bool parseGeneric(char *keyName,
     77                         psArray *levelArray,
     78                         char *linePtr,
    7979                         psMetadataFlags flags);
    80 static bool parseType(char* keyName,
    81                       psArray* levelArray,
    82                       char* linePtr,
     80static bool parseType(char *keyName,
     81                      psArray *levelArray,
     82                      char *linePtr,
    8383                      psMetadataFlags flags);
    84 static bool parseMetadataEnd(char* keyName,
    85                              psArray* levelArray,
    86                              char* linePtr,
     84static bool parseMetadataEnd(char *keyName,
     85                             psArray *levelArray,
     86                             char *linePtr,
    8787                             psMetadataFlags flags);
    8888
     
    9292typedef struct
    9393{
    94     psArray*    nonUniqueKeyArray;      ///< non-unique key names
    95     psHash*     typeTemplates;          ///< hash of user type templates
    96     psMetadata* metadata;               ///< metadata container
     94    psArray *   nonUniqueKeyArray;      ///< non-unique key names
     95    psHash *    typeTemplates;          ///< hash of user type templates
     96    psMetadata *metadata;               ///< metadata container
    9797}
    9898p_psParseLevelInfo;
    9999
    100 static void parseLevelInfoFree(p_psParseLevelInfo* info)
     100static void parseLevelInfoFree(p_psParseLevelInfo *info)
    101101{
    102102    psFree(info->nonUniqueKeyArray);
     
    105105}
    106106
    107 static p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)
     107static p_psParseLevelInfo *p_psParseLevelInfoAlloc(void)
    108108{
    109109    // Allocate memory for parse level info
     
    200200// Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location
    201201// the beginning of the string. Tokens are newly allocated null terminated strings.
    202 static char* getToken(char **inString,
     202// XXX EAM : not sure this API is well-thought-out:
     203// *status must be set to 0 going in.
     204// status is 1 if delimeter is found, but no valid token
     205// returned string is NULL if no valid token is found
     206static char *getToken(char **inString,
    203207                      char *delimiter,
    204208                      psS32 *status,
     
    353357
    354358/** Returns parsed vector filled with with data. The input string must be null terminated. */
    355 static psVector* parseVector(char *inString,
     359static psVector *parseVector(char *inString,
    356360                             psElemType elemType,
    357361                             psS32 *status)
     
    436440/*****************************************************************************/
    437441
    438 bool psMetadataItemPrint(FILE * fd,
     442bool psMetadataItemPrint(FILE  *fd,
    439443                         const char *format,
    440444                         const psMetadataItem* item)
     
    450454
    451455    // determining the format type
    452     char* fType = strchr(format,'%');
     456    char *fType = strchr(format,'%');
    453457    if (fType == NULL) {
    454458        // well, the format contains no reference to the metadataItem's data:
     
    459463
    460464    // skip over any format modifiers
    461     const char* formatEnd = format+strlen(format);
     465    const char *formatEnd = format+strlen(format);
    462466    while ( (fType < formatEnd) &&
    463467        (strchr(" +-01234567890.$#, hlL",*(++fType)) != NULL) ) {}
     
    549553}
    550554
    551 static psMetadata* genTypeTemplate(char* linePtr)
     555static psMetadata *genTypeTemplate(char *linePtr)
    552556{
    553557    psMetadata*     metadataTemplate = NULL;
     
    593597
    594598
    595 static psMetadata* parseTypeValues(psMetadata* template,
    596                                    char* linePtr)
     599static psMetadata *parseTypeValues(psMetadata *template,
     600                                   char *linePtr)
    597601{
    598602    psMetadata*      md           = NULL;
     
    660664}
    661665
    662 bool parseMetadataItem(char* keyName,
    663                        psArray* levelArray,
    664                        char* linePtr,
     666bool parseMetadataItem(char *keyName,
     667                       psArray *levelArray,
     668                       char *linePtr,
    665669                       psMetadataFlags flags)
    666670{
     
    804808    // If type is MULTI or META then check for the (optional) directives UPDATE or RESET;
    805809    // otherwise, get the value and comment.
     810    // line may have the following forms:
     811    // NAME METADATA
     812    // NAME METADATA # Comment
     813    // NAME METADATA#Comment
     814    // NAME METADATA UPDATE # Comment
     815    // NAME METADATA RESET # Comment
     816    // NAME METADATA UPDATE
     817    // NAME METADATA RESET
    806818    if((mdType == PS_DATA_METADATA_MULTI) || (mdType == PS_DATA_METADATA)) {
    807         // Get the metadata item value if there is one.
     819
     820        // Get the metadata directive if there is one.
    808821        status = 0;
    809822        strValue = getToken (&linePtr, "#", &status, true);
    810 
    811         if (status) {
    812             psError(PS_ERR_IO, true, _("Failed to examine line for optional directive."));
    813             psFree(strType);
    814             psFree(strValue);
    815             return false;
    816         }
    817 
    818         if (strValue) {
     823       
     824        if (!status && strValue) {
    819825            // found a directive, what does it say?
    820             if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "UPDATE")) {
     826            if (strcasecmp (strValue, "UPDATE") && strcasecmp (strValue, "RESET")) {
    821827                psError(PS_ERR_IO, true, _("Invalid directive %s for METADATA or MULTI."), strValue);
    822828                psFree(strType);
     
    834840                flags |= PS_META_REPLACE;
    835841            }
    836         }
    837         psFree(strValue);
    838         strValue = NULL;
     842            psFree(strValue);
     843            strValue = NULL;
     844        }
    839845
    840846        // Not all lines will have comments, so NULL is ok.
     
    846852
    847853        if (status) {
    848             psError(PS_ERR_IO, true, _("Error reading a metadata comment"));
     854            psError(PS_ERR_IO, true, _("Error reading metadata line"));
    849855            psFree(strType);
    850856            psFree(strComment);
     
    965971        // Add key to non-unique array of keys
    966972        // Check for duplicate MULTI lines
     973
     974      // XXX currently, we only place the name of the MULTI on this list.  we thus lose
     975      // the associated comment (if any) and the flags (if any) we could probably fix this
     976      // behavior by allowing psMetadataAddItem to be passed an empty MULTI, which would
     977      // have a null data pointer until an element is added (in other words, treat MULTI
     978      // as another type of folder, but without a link of its own on the metadata->list
     979
    967980        addStatus = true;
    968981        for(psS32 k=0; k < nonUniqueKeys->n; k++) {
     
    10341047}
    10351048
    1036 static bool parseLine(psArray* levelArray,
    1037                       char* linePtr,
     1049static bool parseLine(psArray *levelArray,
     1050                      char *linePtr,
    10381051                      bool overwrite,
    10391052                      bool *notBlank)
     
    11011114}
    11021115
    1103 static bool parseGeneric(char* keyName,
    1104                          psArray* levelArray,
    1105                          char* linePtr,
     1116static bool parseGeneric(char *keyName,
     1117                         psArray *levelArray,
     1118                         char *linePtr,
    11061119                         psMetadataFlags flags)
    11071120{
     
    11301143}
    11311144
    1132 static bool parseType(char* keyName,
    1133                       psArray* levelArray,
    1134                       char* linePtr,
     1145static bool parseType(char *keyName,
     1146                      psArray *levelArray,
     1147                      char *linePtr,
    11351148                      psMetadataFlags flags)
    11361149{
     
    11881201}
    11891202
    1190 static bool parseMetadataEnd(char* keyName,
    1191                              psArray* levelArray,
    1192                              char* linePtr,
     1203static bool parseMetadataEnd(char *keyName,
     1204                             psArray *levelArray,
     1205                             char *linePtr,
    11931206                             psMetadataFlags flags)
    11941207{
     
    12141227}
    12151228
    1216 psMetadata* psMetadataConfigRead(psMetadata* md,
     1229psMetadata *psMetadataConfigRead(psMetadata *md,
    12171230                                 unsigned int *nFail,
    12181231                                 const char *filename,
     
    12281241        psError(PS_ERR_IO, true, _("failed to parse file '%s'"), filename);
    12291242        psFree(md);
    1230         return false;
     1243        psFree(file);
     1244        return NULL;
    12311245    }
    12321246
    12331247    psFree(file);
    1234 
    12351248    return md;
    12361249}
Note: See TracChangeset for help on using the changeset viewer.