IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4540 for trunk/psLib/src/types


Ignore:
Timestamp:
Jul 12, 2005, 9:12:01 AM (21 years ago)
Author:
desonia
Message:

massive restructuring of codebase.

Location:
trunk/psLib/src/types
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/Makefile.am

    r4446 r4540  
    1 #Makefile for collections functions of psLib
     1#Makefile for types functions of psLib
    22#
     3noinst_LTLIBRARIES = libpslibtypes.la
    34
    4 INCLUDES = \
    5         -I$(top_srcdir)/src/astro \
    6         -I$(top_srcdir)/src/db \
    7         -I$(top_srcdir)/src/fft \
    8         -I$(top_srcdir)/src/fits \
    9         -I$(top_srcdir)/src/imageops \
    10         -I$(top_srcdir)/src/math \
    11         -I$(top_srcdir)/src/mathtypes \
    12         -I$(top_srcdir)/src/sys \
    13         -I$(top_srcdir)/src/types \
    14         -I$(top_srcdir)/src/xml \
    15         $(all_includes)
     5libpslibtypes_la_SOURCES = \
     6        psArray.c \
     7        psBitSet.c \
     8        psHash.c \
     9        psList.c \
     10        psLookupTable.c \
     11        psMetadata.c \
     12        psMetadataConfig.c \
     13        psPixels.c
    1614
    17 noinst_LTLIBRARIES = libpslibcollections.la
    18 
    19 libpslibcollections_la_SOURCES = \
    20         psBitSet.c \
    21         psVector.c \
    22         psPixels.c \
    23         psList.c \
    24         psScalar.c \
    25         psCompare.c \
    26         psArray.c \
    27         psHash.c \
    28         psMetadata.c \
    29         psMetadataIO.c
    30 
    31 BUILT_SOURCES = psCollectionsErrors.h
    32 EXTRA_DIST = psCollectionsErrors.dat psCollectionsErrors.h collections.i
    33 
    34 psCollectionsErrors.h:psCollectionsErrors.dat
    35         $(top_srcdir)/src/psParseErrorCodes --data=$? $@
     15EXTRA_DIST = types.i
    3616
    3717pslibincludedir = $(includedir)
    3818pslibinclude_HEADERS = \
     19        psArray.h \
    3920        psBitSet.h \
    40         psVector.h \
    41         psPixels.h \
     21        psHash.h \
    4222        psList.h \
    43         psScalar.h \
    44         psCompare.h \
    45         psArray.h \
    46         psHash.h \
     23        psLookupTable.h \
    4724        psMetadata.h \
    48         psMetadataIO.h
    49 
     25        psMetadataConfig.h \
     26        psPixels.h
  • trunk/psLib/src/types/psArray.c

    r4392 r4540  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-06-25 02:02:04 $
     11 *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-07-12 19:12:01 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2828#include "psLogMsg.h"
    2929
    30 #include "psCollectionsErrors.h"
     30#include "psErrorText.h"
    3131
    3232/*****************************************************************************
  • trunk/psLib/src/types/psBitSet.c

    r4392 r4540  
    1111 *  @author Robert DeSonia, MHPCC
    1212 *
    13  *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2005-06-25 02:02:05 $
     13 *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-07-12 19:12:01 $
    1515 *
    1616 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2828#include "psString.h"
    2929
    30 #include "psCollectionsErrors.h"
     30#include "psErrorText.h"
    3131
    3232enum {
  • trunk/psLib/src/types/psHash.c

    r4392 r4540  
    1212*  @author GLG, MHPCC
    1313*
    14 *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2005-06-25 02:02:05 $
     14*  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2005-07-12 19:12:01 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2727#include "psConstants.h"
    2828
    29 #include "psCollectionsErrors.h"
     29#include "psErrorText.h"
    3030
    3131static psHashBucket* hashBucketAlloc(const char *key, psPtr data, psHashBucket* next);
  • trunk/psLib/src/types/psList.c

    r4392 r4540  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-06-25 02:02:05 $
     8 *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-07-12 19:12:01 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "psLogMsg.h"
    2424
    25 #include "psCollectionsErrors.h"
     25#include "psErrorText.h"
    2626
    2727#define ITER_INIT_HEAD ((psPtr )1)         // next iteration should return head
  • trunk/psLib/src/types/psLookupTable.c

    r4392 r4540  
    77*  @author Ross Harman, MHPCC
    88*
    9 *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    10 *  @date $Date: 2005-06-25 02:02:05 $
     9*  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     10*  @date $Date: 2005-07-12 19:12:01 $
    1111*
    1212*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     
    2525#include "psError.h"
    2626#include "psLookupTable.h"
    27 #include "psFileUtilsErrors.h"
     27#include "psErrorText.h"
    2828#include "psConstants.h"
    2929
  • trunk/psLib/src/types/psMetadata.c

    r4401 r4540  
    1212*  @author Ross Harman, MHPCC
    1313*
    14 *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
    15 *  @date $Date: 2005-06-27 20:38:12 $
     14*  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2005-07-12 19:12:01 $
    1616*
    1717*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3636#include "psLookupTable.h"
    3737#include "psString.h"
    38 #include "psAstronomyErrors.h"
     38#include "psErrorText.h"
    3939#include "psConstants.h"
    4040#include "psLogMsg.h"
  • trunk/psLib/src/types/psMetadataConfig.c

    r4432 r4540  
    1 /** @file  psMetadataIO.c
     1/** @file  psMetadataConfig.c
    22*
    33*  @brief Contains metadata input/output functions.
     
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-06-30 00:04:12 $
     12*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-07-12 19:12:01 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1616*/
    1717
    18 #include <libxml/parser.h>
    1918#include <fitsio.h>
    2019#include <string.h>
     
    3130#include "psVector.h"
    3231#include "psMetadata.h"
    33 #include "psMetadataIO.h"
     32#include "psMetadataConfig.h"
    3433#include "psConstants.h"
    35 #include "psAstronomyErrors.h"
    36 
    37 /******************************************************************************/
    38 /*  DEFINE STATEMENTS                                                         */
    39 /******************************************************************************/
     34#include "psErrorText.h"
    4035
    4136/** Check for FITS errors */
     
    5954#define MAX_STRING_LENGTH 256
    6055
    61 
    62 /******************************************************************************/
    63 /*  TYPE DEFINITIONS                                                          */
    64 /******************************************************************************/
    65 
    66 // None
    67 
    68 /*****************************************************************************/
    69 /*  GLOBAL VARIABLES                                                         */
    70 /*****************************************************************************/
    71 
    72 // None
    73 
    74 /*****************************************************************************/
    75 /*  FILE STATIC VARIABLES                                                    */
    76 /*****************************************************************************/
    77 
    78 // None
    79 
    80 /*****************************************************************************/
    81 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    82 /*****************************************************************************/
    83 
    84 static void saxEndElement(void *ctx, const xmlChar *tagName);
    85 static void initVectorXml(void *ctx, char *tagName);
    86 static void initMetadataItemXml(void *ctx, char *tagName);
    87 static void saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts);
    8856static psMetadata* getMetadataType(char *linePtr);
     57
    8958static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)
    9059;
     60
    9161static void parseLevelInfoFree(p_psParseLevelInfo* info);
     62
    9263static psBool parseLine(psS32* level,   psArray* levelArray,
    93                         char*  linePtr, psS32 lineCount,     char* fileName, psBool overwrite);
    94 static psBool parseMetadataItem(char* keyName, psS32* level,     psArray* levelArray,
    95                                 char* linePtr, psS32  lineCount, char*    fileName,    psMetadataFlags flags);
     64                        char*  linePtr, psS32 lineCount, char* fileName,
     65                        psBool overwrite);
     66
     67static psBool parseMetadataItem(char* keyName, psS32* level,
     68                                psArray* levelArray, char* linePtr,
     69                                psS32 lineCount, char* fileName,
     70                                psMetadataFlags flags);
    9671
    9772static void parseLevelInfoFree(p_psParseLevelInfo* info)
     
    10681// Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string
    10782// must be null terminated.
    108 psBool ignoreLine(char *inString)
     83static psBool ignoreLine(char *inString)
    10984{
    11085    while(*inString!='\0' && *inString!='#') {
     
    12196//  Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
    12297//  terminated copy of the original input string.
    123 char *cleanString(char *inString, psS32 sLen, psBool ignoreComment)
     98static char *cleanString(char *inString, psS32 sLen, psBool ignoreComment)
    12499{
    125100    char *ptrB = NULL;
     
    167142
    168143// Count repeat occurances of a single character within a line. The input string must be null terminated.
    169 psS32 repeatedChars(char *inString, char ch)
     144static psS32 repeatedChars(char *inString, char ch)
    170145{
    171146    psS32 count = 0;
     
    183158// Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location
    184159// the beginning of the string. Tokens are newly allocated null terminated strings.
    185 char* getToken(char **inString, char *delimiter, psS32 *status, psBool ignoreComment)
     160static char* getToken(char **inString, char *delimiter, psS32 *status, psBool ignoreComment)
    186161{
    187162    char *cleanToken = NULL;
     
    217192// Returns single parsed value as a double precision number. The input string must be cleaned and null
    218193// terminated.
    219 double parseValue(char *inString, psS32 *status)
     194static double parseValue(char *inString, psS32 *status)
    220195{
    221196    char *end = NULL;
     
    233208
    234209/** Returns true or false. 'T', 't', '1', 'F', 'f', and '0' are acceptable, parsable variations. */
    235 psBool parseBool(char *inString, psS32 *status)
     210static psBool parseBool(char *inString, psS32 *status)
    236211{
    237212    psBool value = false;
     
    250225
    251226/** Returns parsed vector filled with with data. The input string must be null terminated. */
    252 psVector* parseVector(char *inString, psElemType elemType, psS32 *status)
     227static psVector* parseVector(char *inString, psElemType elemType, psS32 *status)
    253228{
    254229    char*      end       = NULL;
     
    11381113}
    11391114
    1140 
    1141 static void saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts)
    1142 {
    1143     psU64 i = 0;
    1144     char* psTagName = NULL;
    1145     char *psAttName = NULL;
    1146     char *psAttValue = NULL;
    1147     const xmlChar *attName = NULL;
    1148     const xmlChar *attValue = NULL;
    1149     psMetadata* md = NULL;
    1150     psHash* htAtts = NULL;
    1151     xmlParserCtxtPtr ctxt = NULL;
    1152     xmlParserInputPtr input = NULL;
    1153 
    1154 
    1155     // Get and check initial data pointers
    1156     ctxt = (xmlParserCtxtPtr)ctx;
    1157     PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
    1158     md = (psMetadata*)ctxt->sax->_private;
    1159     PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
    1160     input = (xmlParserInputPtr)ctxt->input;
    1161     PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
    1162 
    1163     // Copy XML strings to psStrings to avoid libxml2/psLib memory corruption problems
    1164     psTagName = psStringCopy((const char*)tagName);
    1165 
    1166     // Metadata containter for housing element attributes used by other SAX events
    1167     htAtts = psHashAlloc(10);
    1168 
    1169 
    1170     // Get tag name
    1171     if(psTagName != NULL) {
    1172         psHashAdd(htAtts, "tagName", psTagName);
    1173     } else {
    1174         PS_ASSERT_GENERAL_PTR_NON_NULL(psTagName, return);
    1175         psFree(htAtts);
    1176         psFree(psTagName);
    1177         return;
    1178     }
    1179 
    1180     // Get all attribute names and attribute values
    1181     if(atts != NULL) {
    1182         attName = atts[i++];
    1183         attValue = atts[i++];
    1184         while(attName != NULL) {
    1185             if(attValue != NULL) {
    1186 
    1187                 // Copy XML strings to psStrings to avoid libxml2/psLib memory corruption problems
    1188                 psAttName = psStringCopy((const char*)attName);
    1189                 psAttValue = psStringCopy((const char*)attValue);
    1190                 psHashAdd(htAtts, psAttName, psAttValue);
    1191                 psFree(psAttName);
    1192                 psFree(psAttValue);
    1193             } else {
    1194                 PS_ASSERT_GENERAL_PTR_NON_NULL(psAttValue, return);
    1195                 psFree(htAtts);
    1196                 psFree(psTagName);
    1197                 return;
    1198             }
    1199             attName = atts[i++];
    1200             attValue = atts[i++];
    1201         }
    1202     }
    1203 
    1204     // Add attributes to metadata
    1205 
    1206     psMetadataAdd(md, PS_LIST_TAIL, "htAtts",
    1207                   PS_META_HASH | PS_META_DUPLICATE_OK,
    1208                   NULL, htAtts);
    1209 
    1210     psFree(psTagName);
    1211     psFree(htAtts);
    1212 
    1213     return;
    1214 }
    1215 
    1216 static void initMetadataItemXml(void *ctx, char *tagName)
    1217 {
    1218     psBool overwrite = false;
    1219     psBool tempBool = false;
    1220     psS32 status = 0;
    1221     psU32 lineNumber = 0;
    1222     psF64 tempDbl = 0.0;
    1223     psS32 tempInt = 0.0;
    1224     psMetadataType mdType = PS_META_UNKNOWN;
    1225     char *fileName = NULL;
    1226     char *strName = NULL;
    1227     char *strType = NULL;
    1228     char *strValue = NULL;
    1229     psMetadata* md = NULL;
    1230     psHash* htAtts = NULL;
    1231     psMetadataItem *metadataItem = NULL;
    1232     xmlParserCtxtPtr ctxt = NULL;
    1233     xmlParserInputPtr input = NULL;
    1234 
    1235 
    1236     // Get and check initial data pointers
    1237     ctxt = (xmlParserCtxtPtr)ctx;
    1238     PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
    1239     md = (psMetadata*)ctxt->sax->_private;
    1240     PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
    1241     input = (xmlParserInputPtr)ctxt->input;
    1242     PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
    1243     metadataItem = psMetadataLookup(md, "htAtts");
    1244     PS_ASSERT_GENERAL_PTR_NON_NULL(metadataItem, return);
    1245     PS_ASSERT_GENERAL_PTR_NON_NULL(metadataItem->data.list, return);
    1246     metadataItem = (psMetadataItem*)psListGet(metadataItem->data.list,PS_LIST_TAIL);
    1247     htAtts = (psHash*)metadataItem->data.list;
    1248     PS_ASSERT_GENERAL_PTR_NON_NULL(htAtts, return);
    1249     fileName = (char*)input->filename;
    1250     PS_ASSERT_GENERAL_PTR_NON_NULL(fileName, return);
    1251     lineNumber = input->line;
    1252 
    1253     // Get attribute name
    1254     strName = psHashLookup(htAtts, "name");
    1255     if(strName == NULL) {
    1256         psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_NO_NAME, lineNumber, fileName);
    1257         return;
    1258     }
    1259 
    1260     // Get attribute type, if there is one
    1261     strType = psHashLookup(htAtts, "psType");
    1262     if(strType!= NULL) {
    1263         if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psString")) {
    1264             mdType = PS_META_STR;
    1265         } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psBool")) {
    1266             mdType = PS_META_BOOL;
    1267         } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psS32")) {
    1268             mdType = PS_META_S32;
    1269         } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF32")) {
    1270             mdType = PS_META_F32;
    1271         } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF64")) {
    1272             mdType = PS_META_F64;
    1273         } else {
    1274             psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TYPE_INVALID_LINE_FILE, strType, lineNumber,
    1275                     fileName);
    1276             return;
    1277         }
    1278     }
    1279 
    1280     // Get attribute value, if there is one
    1281     strValue = psHashLookup(htAtts, "value");
    1282 
    1283     /* If metadata item is found, and is not a folder node, and overwrite is allowed, then remove
    1284     existing and allow switch/case below to add new item. If overwrite is false, then report error. If
    1285     found item is folder node, then psMetadataAdd will automatically add a new child. */
    1286     metadataItem = psMetadataLookup(md, "overwrite");
    1287     if(metadataItem != NULL) {
    1288         overwrite = parseBool((char*)strValue, &status);
    1289         if(status) {
    1290             status = 0;
    1291             psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
    1292                     lineNumber, fileName);
    1293         }
    1294         metadataItem = psMetadataLookup(md, strName);
    1295         if(metadataItem != NULL) {
    1296             if(metadataItem->type != PS_META_LIST) {
    1297                 if(overwrite) {
    1298                     psMetadataRemove(md, INT_MIN, strName);
    1299                 } else {
    1300                     psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM, strName, lineNumber,
    1301                             fileName);
    1302                     return;
    1303                 }
    1304             }
    1305         }
    1306     }
    1307 
    1308     // Create metadata item and add to metadata
    1309     switch(mdType) {
    1310     case PS_META_LIST:
    1311         psMetadataAdd(md, PS_LIST_TAIL, strName,
    1312                       mdType | PS_META_DUPLICATE_OK,
    1313                       NULL, NULL);
    1314         break;
    1315     case PS_META_STR:
    1316         psMetadataAdd(md, PS_LIST_TAIL, strName,
    1317                       mdType | PS_META_DUPLICATE_OK,
    1318                       NULL, strValue);
    1319         break;
    1320     case PS_META_BOOL:
    1321         tempBool = parseBool((char*)strValue, &status);
    1322         if(!status) {
    1323             psMetadataAdd(md, PS_LIST_TAIL, strName,
    1324                           mdType | PS_META_DUPLICATE_OK,
    1325                           NULL, tempBool);
    1326         } else {
    1327             status = 0;
    1328             psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
    1329                     lineNumber, fileName);
    1330         }
    1331         break;
    1332     case PS_META_S32:
    1333         tempInt = (psS32)parseValue((char*)strValue, &status);
    1334         if(!status) {
    1335             psMetadataAdd(md, PS_LIST_TAIL, strName,
    1336                           mdType | PS_META_DUPLICATE_OK,
    1337                           NULL, tempInt);
    1338         } else {
    1339             status = 0;
    1340             psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
    1341                     lineNumber, fileName);
    1342         }
    1343         break;
    1344     case PS_META_F32:
    1345     case PS_META_F64:
    1346         tempDbl = parseValue((char*)strValue, &status);
    1347         if(!status) {
    1348             psMetadataAdd(md, PS_LIST_TAIL, strName,
    1349                           mdType | PS_META_DUPLICATE_OK,
    1350                           NULL, tempDbl);
    1351         } else {
    1352             status = 0;
    1353             psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
    1354                     lineNumber, fileName);
    1355         }
    1356         break;
    1357     default:
    1358         psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID, strType, lineNumber, fileName);
    1359     } // End switch
    1360 
    1361     return;
    1362 }
    1363 
    1364 
    1365 static void initVectorXml(void *ctx, char *tagName)
    1366 {
    1367     bool overwrite = false;
    1368     psS32 status = 0;
    1369     psU32 lineNumber = 0;
    1370     psElemType pType = 0;
    1371     char *strName = NULL;
    1372     char *strType = NULL;
    1373     char *strValue = NULL;
    1374     char *fileName = NULL;
    1375     psMetadataItem *table = NULL;
    1376     psMetadataItem *tables = NULL;
    1377     psMetadataItem *metadataItem = NULL;
    1378     psVector *vec = NULL;
    1379     psMetadata* md = NULL;
    1380     psHash* htAtts = NULL;
    1381     xmlParserCtxtPtr ctxt = NULL;
    1382     xmlParserInputPtr input = NULL;
    1383 
    1384 
    1385     // Get and check initial data pointers
    1386     ctxt = (xmlParserCtxtPtr)ctx;
    1387     PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
    1388     md = (psMetadata*)ctxt->sax->_private;
    1389     PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
    1390     input = (xmlParserInputPtr)ctxt->input;
    1391     PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
    1392     tables = psMetadataLookup(md, "htAtts");
    1393     PS_ASSERT_GENERAL_PTR_NON_NULL(tables, return);
    1394     PS_ASSERT_GENERAL_PTR_NON_NULL(tables->data.list, return);
    1395     table = (psMetadataItem*)psListGet(tables->data.list,PS_LIST_TAIL);
    1396     htAtts = (psHash*)table->data.list;
    1397     PS_ASSERT_GENERAL_PTR_NON_NULL(htAtts, return);
    1398     fileName = (char*)input->filename;
    1399     PS_ASSERT_GENERAL_PTR_NON_NULL(fileName, return);
    1400     lineNumber = input->line;
    1401 
    1402     // Get attribute name
    1403     strName = psHashLookup(htAtts, "name");
    1404     if(strName == NULL) {
    1405         psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_NO_NAME, lineNumber, fileName);
    1406         return;
    1407     }
    1408 
    1409     // Get attribute type, if there is one
    1410     strType = psHashLookup(htAtts, "psType");
    1411     if(strType!= NULL) {
    1412         if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psBool")) {
    1413             pType = PS_TYPE_U8;
    1414         } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psS32")) {
    1415             pType = PS_TYPE_S32;
    1416         } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF32")) {
    1417             pType = PS_TYPE_F32;
    1418         } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF64")) {
    1419             pType = PS_TYPE_F64;
    1420         } else {
    1421             psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TYPE_INVALID_LINE_FILE, strName, lineNumber,
    1422                     fileName);
    1423             return;
    1424         }
    1425     }
    1426 
    1427     strValue = psHashLookup(htAtts, "value");
    1428     PS_ASSERT_GENERAL_PTR_NON_NULL(strValue, return);
    1429 
    1430 
    1431     /* If metadata item is found, and is not a folder node, and overwrite is allowed, then remove
    1432     existing and allow switch/case below to add new item. If overwrite is false, then report error. If
    1433     found item is folder node, then psMetadataAdd will automatically add a new child. */
    1434     metadataItem = psMetadataLookup(md, "overwrite");
    1435     if(metadataItem != NULL) {
    1436         overwrite = parseBool((char*)strValue, &status);
    1437         if(status) {
    1438             status = 0;
    1439             psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
    1440                     input->line, input->filename);
    1441         }
    1442         metadataItem = psMetadataLookup(md, strName);
    1443         if(metadataItem != NULL) {
    1444             if(metadataItem->type != PS_META_LIST) {
    1445                 if(overwrite) {
    1446                     psMetadataRemove(md, INT_MIN, strName);
    1447                 } else {
    1448                     psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM, strName, lineNumber,
    1449                             fileName);
    1450                     return;
    1451                 }
    1452             }
    1453         }
    1454     }
    1455 
    1456     // Get value
    1457     vec = parseVector((char*)strValue, pType, &status);
    1458     if(!status) {
    1459         psMetadataAdd(md, PS_LIST_TAIL, strName+1,
    1460                       PS_META_VEC | PS_META_DUPLICATE_OK,
    1461                       NULL, vec);
    1462     } else {
    1463         psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
    1464                 lineNumber, fileName);
    1465     }
    1466     psFree(vec);
    1467 }
    1468 
    1469 static void saxEndElement(void *ctx, const xmlChar *tagName)
    1470 {
    1471     char *psStartTagName = NULL;
    1472     char *psEndTagName = NULL;
    1473     psMetadata* md = NULL;
    1474     psHash* htAtts = NULL;
    1475     psMetadataItem *table = NULL;
    1476     psMetadataItem *tables = NULL;
    1477     xmlParserCtxtPtr ctxt = NULL;
    1478     xmlParserInputPtr input = NULL;
    1479 
    1480 
    1481     // Get and check initial data pointers
    1482     ctxt = (xmlParserCtxtPtr)ctx;
    1483     PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
    1484     md = (psMetadata*)ctxt->sax->_private;
    1485     PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
    1486     input = (xmlParserInputPtr)ctxt->input;
    1487     PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
    1488     tables = psMetadataLookup(md, "htAtts");
    1489     PS_ASSERT_GENERAL_PTR_NON_NULL(tables, return);
    1490     PS_ASSERT_GENERAL_PTR_NON_NULL(tables->data.list, return);
    1491     table = (psMetadataItem*)psListGet(tables->data.list,PS_LIST_TAIL);
    1492     htAtts = (psHash*)table->data.list;
    1493     PS_ASSERT_GENERAL_PTR_NON_NULL(htAtts, return);
    1494 
    1495     // Copy XML strings to psStrings to avoid libxml2/psLib memory corruption problems
    1496     psEndTagName = psStringCopy((const char*)tagName);
    1497 
    1498     // Compare start and end tag names
    1499     psStartTagName = psHashLookup(htAtts, "tagName");
    1500     PS_ASSERT_GENERAL_PTR_NON_NULL(psStartTagName, return);
    1501     if(strcmp(psEndTagName, psStartTagName)) {
    1502         psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TAG_MISMATCH, psStartTagName, psEndTagName);
    1503     }
    1504 
    1505     // Initialize psLib structs
    1506     if(!strcmp(psEndTagName, "psMetadataItem")) {
    1507         initMetadataItemXml(ctx, psEndTagName);
    1508     } else if(!strcmp(psEndTagName, "psVector")) {
    1509         initVectorXml(ctx, psEndTagName);
    1510     } else if(strcmp(psEndTagName, "psRoot")) {
    1511         psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TAG_UNKNOWN, psEndTagName);
    1512     }
    1513 
    1514     // Free temporary metadata item and its hash table
    1515     psListRemove(tables->data.list, PS_LIST_TAIL);
    1516 
    1517     psFree(psEndTagName);
    1518 
    1519     return;
    1520 }
    1521 
    1522 psMetadata*  psMetadataConfigParseXml(psMetadata* md, psU32 *nFail, const char *fileName, psBool overwrite)
    1523 {
    1524     xmlSAXHandler saxHandler;
    1525 
    1526 
    1527     // Error checks
    1528     PS_ASSERT_PTR_NON_NULL(fileName, NULL);
    1529 
    1530     // Allocate metadata if necessary
    1531     if (md == NULL) {
    1532         md = psMetadataAlloc();
    1533     }
    1534 
    1535     // Sax handler initializations
    1536     saxHandler.internalSubset           = NULL;
    1537     saxHandler.isStandalone             = NULL;
    1538     saxHandler.hasInternalSubset        = NULL;
    1539     saxHandler.hasExternalSubset        = NULL;
    1540     saxHandler.resolveEntity            = NULL;
    1541     saxHandler.getEntity                = NULL;
    1542     saxHandler.entityDecl               = NULL;
    1543     saxHandler.notationDecl             = NULL;
    1544     saxHandler.attributeDecl            = NULL;
    1545     saxHandler.elementDecl              = NULL;
    1546     saxHandler.unparsedEntityDecl       = NULL;
    1547     saxHandler.setDocumentLocator       = NULL;
    1548     saxHandler.startDocument            = NULL;
    1549     saxHandler.endDocument              = NULL;
    1550     saxHandler.startElement             = saxStartElement;
    1551     saxHandler.endElement               = saxEndElement;
    1552     saxHandler.reference                = NULL;
    1553     saxHandler.characters               = NULL;
    1554     saxHandler.ignorableWhitespace      = NULL;
    1555     saxHandler.processingInstruction    = NULL;
    1556     saxHandler.comment                  = NULL;
    1557     saxHandler.warning                  = xmlParserError;
    1558     saxHandler.error                    = xmlParserError;
    1559     saxHandler.fatalError               = xmlParserError;
    1560     saxHandler.getParameterEntity       = NULL;
    1561     saxHandler.cdataBlock               = NULL;
    1562     saxHandler.externalSubset           = NULL;
    1563     saxHandler.initialized              = 1;
    1564     saxHandler._private                 = md;
    1565     saxHandler.startElementNs           = NULL;
    1566     saxHandler.endElementNs             = NULL;
    1567     saxHandler.serror                   = NULL;
    1568 
    1569     // Parse XML file
    1570     if (xmlSAXUserParseFile(&saxHandler, NULL, fileName)) {
    1571         psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_OPEN_FAILED, fileName);
    1572         return NULL;
    1573     }
    1574 
    1575     // Parser and memory cleanups for libxml2
    1576     xmlCleanupParser();
    1577     xmlMemoryDump();
    1578 
    1579     return md;
    1580 }
  • trunk/psLib/src/types/psMetadataConfig.h

    r4409 r4540  
    1 /** @file  psMetadataIO.h
     1/** @file  psMetadataConfig.h
    22 *
    33 *  @brief Contains metadata input/output functions.
     
    1010 *  @author Robert DeSonia, MHPCC
    1111 *
    12  *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2005-06-28 20:17:52 $
     12 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2005-07-12 19:12:01 $
    1414 *
    1515 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
    1616 */
    17 #ifndef PS_METADATAIO_H
    18 #define PS_METADATAIO_H
     17#ifndef PS_METADATACONFIG_H
     18#define PS_METADATACONFIG_H
     19
     20#include "psMetadata.h"
    1921
    2022/// @addtogroup Metadata
     
    2224
    2325/** A metadata data structure used in parsing arrays.
    24  * 
     26 *
    2527 *  Contains array information and the metadata storage location.
    2628*/
     
    3638
    3739/** Allocates a p_psParseLevelInfo structure
    38  *   
     40 *
    3941 *  @return p_psParseLevelInfo* :   new p_psParseLevelInfo struct
    4042 */
     
    8688);
    8789
    88 /** Read XML metadata configuration file.
    89  *
    90  *  Loads pre-defined XML settings by parsing a configuration file into a psMetadata structure.
    91  *
    92  *  @return psMetadata* : Resulting metadata from read.
    93  */
    94 
    95 psMetadata*  psMetadataConfigParseXml(
    96     psMetadata* md,                    ///< Resulting metadata from read.
    97     psU32 *nFail,                      ///< Number of failed lines.
    98     const char *fileName,              ///< Name of file to read.
    99     psBool overwrite                   ///< Allow overwrite of duplicate specifications.
    100 );
    101 
    10290/// @}
    10391
  • trunk/psLib/src/types/psPixels.c

    r4401 r4540  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2005-06-27 20:38:12 $
     9 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2005-07-12 19:12:01 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2020
    2121#include "psError.h"
    22 #include "psCollectionsErrors.h"
     22#include "psErrorText.h"
    2323
    2424typedef int(*qsortCompareFcn)(const void *, const void *);
Note: See TracChangeset for help on using the changeset viewer.