Geant4 Cross Reference |
1 /* 1 /* 2 # <<BEGIN-copyright>> 2 # <<BEGIN-copyright>> 3 # <<END-copyright>> 3 # <<END-copyright>> 4 */ 4 */ 5 5 6 #include <stdlib.h> 6 #include <stdlib.h> 7 #include <string.h> 7 #include <string.h> 8 #include <ctype.h> 8 #include <ctype.h> 9 #include <sys/types.h> 9 #include <sys/types.h> 10 #include <sys/stat.h> 10 #include <sys/stat.h> 11 #include <fcntl.h> 11 #include <fcntl.h> 12 #include <errno.h> 12 #include <errno.h> 13 13 14 #if defined(WIN32) || defined(__MINGW32__) << 14 #ifdef WIN32 15 #include <windows.h> 15 #include <windows.h> 16 #define realpath( a, b ) GetFullPathName( a, P 16 #define realpath( a, b ) GetFullPathName( a, PATH_MAX, b, NULL ) 17 #define strtoll _strtoi64 17 #define strtoll _strtoi64 18 #else 18 #else 19 #include <unistd.h> 19 #include <unistd.h> 20 #endif 20 #endif 21 21 22 #include "xDataTOM_importXML_private.h" 22 #include "xDataTOM_importXML_private.h" 23 #include "xDataTOM_private.h" 23 #include "xDataTOM_private.h" 24 24 25 #if defined __cplusplus 25 #if defined __cplusplus 26 namespace GIDI { 26 namespace GIDI { 27 using namespace GIDI; 27 using namespace GIDI; 28 #endif 28 #endif 29 29 30 #ifndef PATH_MAX 30 #ifndef PATH_MAX 31 #define PATH_MAX 4096 31 #define PATH_MAX 4096 32 #endif 32 #endif 33 33 34 int xDataTOM_smrLibraryID = smr_unknownID; 34 int xDataTOM_smrLibraryID = smr_unknownID; 35 35 36 static int xDataTOME_initializeElement( status 36 static int xDataTOME_initializeElement( statusMessageReporting *smr, xDataTOM_element *element, xDataTOM_element *parent, int ordinal, int index, 37 char const *name ); 37 char const *name ); 38 static void xDataTOME_displayTree( statusMessa 38 static void xDataTOME_displayTree( statusMessageReporting *smr, xDataTOM_element *element, int printAttributes, int level ); 39 39 40 static int xDataTOM_initialize_xData( statusMe 40 static int xDataTOM_initialize_xData( statusMessageReporting *smr, xDataTOM_xDataInfo *xDataInfo ); 41 /* 41 /* 42 ********************************************** 42 ************************************************************ 43 */ 43 */ 44 xDataTOM_TOM *xDataTOM_importFile( statusMessa 44 xDataTOM_TOM *xDataTOM_importFile( statusMessageReporting *smr, const char *fileName ) { 45 /* 45 /* 46 * Returns NULL is an error occurred. 46 * Returns NULL is an error occurred. 47 */ 47 */ 48 48 49 return( xDataXML_importFile( smr, fileName 49 return( xDataXML_importFile( smr, fileName ) ); 50 } 50 } 51 /* 51 /* 52 ********************************************** 52 ************************************************************ 53 */ 53 */ 54 xDataTOM_TOM *xDataTOM_mallocTOM( statusMessag 54 xDataTOM_TOM *xDataTOM_mallocTOM( statusMessageReporting *smr ) { 55 /* 55 /* 56 * Returns NULL is an error occurred. 56 * Returns NULL is an error occurred. 57 */ 57 */ 58 xDataTOM_TOM *TOM; 58 xDataTOM_TOM *TOM; 59 59 60 if( ( TOM = (xDataTOM_TOM *) smr_malloc2( 60 if( ( TOM = (xDataTOM_TOM *) smr_malloc2( smr, sizeof( xDataTOM_TOM ), 1, "xDataTOM_TOM" ) ) != NULL ) { 61 if( xDataTOM_initializeTOM( smr, TOM ) 61 if( xDataTOM_initializeTOM( smr, TOM ) ) smr_freeMemory( (void **) &TOM ); 62 } 62 } 63 return( TOM ); 63 return( TOM ); 64 } 64 } 65 /* 65 /* 66 ********************************************** 66 ************************************************************ 67 */ 67 */ 68 int xDataTOM_initializeTOM( statusMessageRepor 68 int xDataTOM_initializeTOM( statusMessageReporting *smr, xDataTOM_TOM *TOM ) { 69 69 70 TOM->fileName = NULL; 70 TOM->fileName = NULL; 71 TOM->realFileName = NULL; 71 TOM->realFileName = NULL; 72 xDataTOME_initializeElement( smr, &(TOM->r 72 xDataTOME_initializeElement( smr, &(TOM->root), NULL, 0, 0, "" ); 73 return( !smr_isOk( smr ) ); 73 return( !smr_isOk( smr ) ); 74 } 74 } 75 /* 75 /* 76 ********************************************** 76 ************************************************************ 77 */ 77 */ 78 void *xDataTOM_freeTOM( statusMessageReporting 78 void *xDataTOM_freeTOM( statusMessageReporting * /*smr*/, xDataTOM_TOM **TOM ) { 79 79 80 xDataTOM_TOM *TOMp; 80 xDataTOM_TOM *TOMp; 81 81 82 if( TOM == NULL ) return( NULL ); 82 if( TOM == NULL ) return( NULL ); 83 TOMp = *TOM; 83 TOMp = *TOM; 84 if( TOMp == NULL ) return( NULL ); 84 if( TOMp == NULL ) return( NULL ); 85 xDataTOM_releaseElement( &(TOMp->root) ); 85 xDataTOM_releaseElement( &(TOMp->root) ); 86 smr_freeMemory( (void **) &(TOMp->fileName 86 smr_freeMemory( (void **) &(TOMp->fileName) ); 87 smr_freeMemory( (void **) &(TOMp->realFile 87 smr_freeMemory( (void **) &(TOMp->realFileName) ); 88 smr_freeMemory( (void **) TOM ); 88 smr_freeMemory( (void **) TOM ); 89 return( NULL ); 89 return( NULL ); 90 } 90 } 91 /* 91 /* 92 ********************************************** 92 ************************************************************ 93 */ 93 */ 94 int xDataTOM_setFileNameTOM( statusMessageRepo 94 int xDataTOM_setFileNameTOM( statusMessageReporting *smr, xDataTOM_TOM *TOM, const char *fileName ) { 95 /* 95 /* 96 * Returns not zero value if error occurred. 96 * Returns not zero value if error occurred. 97 */ 97 */ 98 98 99 char realPath[PATH_MAX+1]; 99 char realPath[PATH_MAX+1]; 100 100 101 smr_freeMemory( (void **) &(TOM->fileName) 101 smr_freeMemory( (void **) &(TOM->fileName) ); 102 smr_freeMemory( (void **) &(TOM->realFileN 102 smr_freeMemory( (void **) &(TOM->realFileName) ); 103 if( fileName != NULL ) { 103 if( fileName != NULL ) { 104 if( ( TOM->fileName = smr_allocateCopy 104 if( ( TOM->fileName = smr_allocateCopyString2( smr, fileName, "fileName" ) ) == NULL ) return( 1 ); 105 if( realpath( fileName, realPath ) != 105 if( realpath( fileName, realPath ) != NULL ) { 106 if( ( TOM->realFileName = smr_allo 106 if( ( TOM->realFileName = smr_allocateCopyString2( smr, realPath, "realFileName" ) ) == NULL ) return( 1 ); 107 } 107 } 108 } 108 } 109 return( 0 ); 109 return( 0 ); 110 } 110 } 111 /* 111 /* 112 ********************************************** 112 ************************************************************ 113 */ 113 */ 114 void xDataTOM_displayTree( statusMessageReport 114 void xDataTOM_displayTree( statusMessageReporting *smr, xDataTOM_TOM *TOM, int printAttributes ) { 115 115 116 if( TOM->root.children != NULL ) xDataTOME 116 if( TOM->root.children != NULL ) xDataTOME_displayTree( smr, TOM->root.children, printAttributes, 0 ); 117 } 117 } 118 118 119 /**************************************** 119 /**************************************** 120 * Element functions. 120 * Element functions. 121 ****************************************/ 121 ****************************************/ 122 /* 122 /* 123 ********************************************** 123 ************************************************************ 124 */ 124 */ 125 xDataTOM_element *xDataTOM_mallocElement( stat 125 xDataTOM_element *xDataTOM_mallocElement( statusMessageReporting *smr, xDataTOM_element *parent, int ordinal, int index, char const *name ) { 126 /* 126 /* 127 * Returns NULL is an error occurred. 127 * Returns NULL is an error occurred. 128 */ 128 */ 129 xDataTOM_element *element; 129 xDataTOM_element *element; 130 130 131 if( ( element = (xDataTOM_element *) smr_m 131 if( ( element = (xDataTOM_element *) smr_malloc2( smr, sizeof( xDataTOM_element ), 1, "xDataTOM_elelument" ) ) != NULL ) { 132 if( xDataTOME_initializeElement( smr, 132 if( xDataTOME_initializeElement( smr, element, parent, ordinal, index, name ) ) smr_freeMemory( (void **) &element ); 133 } 133 } 134 return( element ); 134 return( element ); 135 } 135 } 136 /* 136 /* 137 ********************************************** 137 ************************************************************ 138 */ 138 */ 139 void xDataTOM_freeElement( xDataTOM_element ** 139 void xDataTOM_freeElement( xDataTOM_element **element ) { 140 140 141 if( element == NULL ) return; 141 if( element == NULL ) return; 142 xDataTOM_releaseElement( *element ); 142 xDataTOM_releaseElement( *element ); 143 smr_freeMemory( (void **) element ); 143 smr_freeMemory( (void **) element ); 144 } 144 } 145 /* 145 /* 146 ********************************************** 146 ************************************************************ 147 */ 147 */ 148 void xDataTOM_releaseElement( xDataTOM_element 148 void xDataTOM_releaseElement( xDataTOM_element *element ) { 149 149 150 xDataTOM_element *child, *nextChild; 150 xDataTOM_element *child, *nextChild; 151 151 152 if( element == NULL ) return; 152 if( element == NULL ) return; 153 xDataTOMAL_release( &(element->attributes) 153 xDataTOMAL_release( &(element->attributes) ); 154 for( child = element->children; child != N 154 for( child = element->children; child != NULL; child = nextChild ) { 155 nextChild = child->next; 155 nextChild = child->next; 156 xDataTOM_freeElement( &child ); 156 xDataTOM_freeElement( &child ); 157 } 157 } 158 if( element->xDataInfo.ID != NULL ) { 158 if( element->xDataInfo.ID != NULL ) { 159 xDataTOM_axes_release( &(element->xDat 159 xDataTOM_axes_release( &(element->xDataInfo.axes) ); 160 if( strcmp( element->xDataInfo.ID, xDa 160 if( strcmp( element->xDataInfo.ID, xDataTOM_XYs_ID ) == 0 ) { 161 xDataTOM_XYs_free( &(element->xDat 161 xDataTOM_XYs_free( &(element->xDataInfo ) ); } 162 else if( strcmp( element->xDataInfo.ID 162 else if( strcmp( element->xDataInfo.ID, xDataTOM_regionsXYs_ID ) == 0 ) { 163 xDataTOM_regionsXYs_free( &(elemen 163 xDataTOM_regionsXYs_free( &(element->xDataInfo ) ); } 164 else if( strcmp( element->xDataInfo.ID 164 else if( strcmp( element->xDataInfo.ID, xDataTOM_W_XYs_ID ) == 0 ) { 165 xDataTOM_W_XYs_freeFrom_xDataInfo( 165 xDataTOM_W_XYs_freeFrom_xDataInfo( &(element->xDataInfo ) ); } 166 else if( strcmp( element->xDataInfo.ID 166 else if( strcmp( element->xDataInfo.ID, xDataTOM_V_W_XYs_ID ) == 0 ) { 167 xDataTOM_V_W_XYs_free( &(element-> 167 xDataTOM_V_W_XYs_free( &(element->xDataInfo ) ); } 168 else if( strcmp( element->xDataInfo.ID 168 else if( strcmp( element->xDataInfo.ID, xDataTOM_W_XYs_LegendreSeries_ID ) == 0 ) { 169 xDataTOM_W_XYs_LegendreSeries_free 169 xDataTOM_W_XYs_LegendreSeries_free( &(element->xDataInfo ) ); } 170 else if( strcmp( element->xDataInfo.ID 170 else if( strcmp( element->xDataInfo.ID, xDataTOM_regionsW_XYs_LegendreSeries_ID ) == 0 ) { 171 xDataTOM_regionsW_XYs_LegendreSeri 171 xDataTOM_regionsW_XYs_LegendreSeries_free( &(element->xDataInfo ) ); } 172 else if( strcmp( element->xDataInfo.ID 172 else if( strcmp( element->xDataInfo.ID, xDataTOM_V_W_XYs_LegendreSeries_ID ) == 0 ) { 173 xDataTOM_V_W_XYs_LegendreSeries_fr 173 xDataTOM_V_W_XYs_LegendreSeries_free( &(element->xDataInfo ) ); } 174 else if( strcmp( element->xDataInfo.ID 174 else if( strcmp( element->xDataInfo.ID, xDataTOM_KalbachMann_ID ) == 0 ) { 175 xDataTOM_KalbachMann_free( &(eleme 175 xDataTOM_KalbachMann_free( &(element->xDataInfo ) ); } 176 else if( strcmp( element->xDataInfo.ID 176 else if( strcmp( element->xDataInfo.ID, xDataTOM_polynomial_ID ) == 0 ) { 177 xDataTOM_polynomial_free( &(elemen 177 xDataTOM_polynomial_free( &(element->xDataInfo ) ); } 178 else { 178 else { 179 printf( "not freed for %s\n", elem 179 printf( "not freed for %s\n", element->xDataInfo.ID ); 180 } 180 } 181 } 181 } 182 element->parent = NULL; 182 element->parent = NULL; 183 smr_freeMemory( (void **) &(element->name) 183 smr_freeMemory( (void **) &(element->name) ); 184 } 184 } 185 /* 185 /* 186 ********************************************** 186 ************************************************************ 187 */ 187 */ 188 xDataTOM_element *xDataTOM_addElementInElement 188 xDataTOM_element *xDataTOM_addElementInElement( statusMessageReporting *smr, xDataTOM_element *parent, int index, char const *name ) { 189 189 190 xDataTOM_element *element; 190 xDataTOM_element *element; 191 191 192 if( ( element = xDataTOM_mallocElement( sm 192 if( ( element = xDataTOM_mallocElement( smr, parent, parent->numberOfChildren, index, name ) ) == NULL ) return( NULL ); 193 if( parent->children == NULL ) { 193 if( parent->children == NULL ) { 194 parent->children = element; } 194 parent->children = element; } 195 else { 195 else { 196 xDataTOM_element *last; 196 xDataTOM_element *last; 197 197 198 for( last = parent->children; last->ne 198 for( last = parent->children; last->next != NULL; last = last->next ) ; 199 last->next = element; 199 last->next = element; 200 } 200 } 201 (parent->numberOfChildren)++; 201 (parent->numberOfChildren)++; 202 return( element ); 202 return( element ); 203 } 203 } 204 /* 204 /* 205 ********************************************** 205 ************************************************************ 206 */ 206 */ 207 static int xDataTOME_initializeElement( status 207 static int xDataTOME_initializeElement( statusMessageReporting *smr, xDataTOM_element *element, xDataTOM_element *parent, int ordinal, int index, 208 char const *name ) { 208 char const *name ) { 209 209 210 element->ordinal = ordinal; 210 element->ordinal = ordinal; 211 element->index = index; 211 element->index = index; 212 element->parent = parent; 212 element->parent = parent; 213 element->next = NULL; 213 element->next = NULL; 214 element->name = smr_allocateCopyString2( s 214 element->name = smr_allocateCopyString2( smr, name, "element->name" ); 215 xDataTOMAL_initial( smr, &(element->attrib 215 xDataTOMAL_initial( smr, &(element->attributes) ); 216 element->numberOfChildren = 0; 216 element->numberOfChildren = 0; 217 element->children = NULL; 217 element->children = NULL; 218 return( ( xDataTOM_initialize_xData( smr, 218 return( ( xDataTOM_initialize_xData( smr, &(element->xDataInfo) ) || ( element->name == NULL ) ) ? 1 : 0 ); 219 } 219 } 220 /* 220 /* 221 ********************************************** 221 ************************************************************ 222 */ 222 */ 223 xDataTOM_element *xDataTOM_getDocumentsElement 223 xDataTOM_element *xDataTOM_getDocumentsElement( xDataTOM_TOM *TOM ) { 224 224 225 return( TOM->root.children ); 225 return( TOM->root.children ); 226 } 226 } 227 /* 227 /* 228 ********************************************** 228 ************************************************************ 229 */ 229 */ 230 xDataTOM_element *xDataTOME_getFirstElement( x 230 xDataTOM_element *xDataTOME_getFirstElement( xDataTOM_element *element ) { 231 231 232 if( element != NULL ) element = element->c 232 if( element != NULL ) element = element->children; 233 return( element ); 233 return( element ); 234 } 234 } 235 /* 235 /* 236 ********************************************** 236 ************************************************************ 237 */ 237 */ 238 xDataTOM_element *xDataTOME_getNextElement( xD 238 xDataTOM_element *xDataTOME_getNextElement( xDataTOM_element *element ) { 239 239 240 if( element != NULL ) element = element->n 240 if( element != NULL ) element = element->next; 241 return( element ); 241 return( element ); 242 } 242 } 243 /* 243 /* 244 ********************************************** 244 ************************************************************ 245 */ 245 */ 246 xDataTOM_element *xDataTOME_getOneElementByNam 246 xDataTOM_element *xDataTOME_getOneElementByName( statusMessageReporting *smr, xDataTOM_element *element, char const *name, int required ) { 247 247 248 int n = 0; 248 int n = 0; 249 xDataTOM_element *child, *desired = NULL; 249 xDataTOM_element *child, *desired = NULL; 250 250 251 for( child = xDataTOME_getFirstElement( el 251 for( child = xDataTOME_getFirstElement( element ); child != NULL; child = xDataTOME_getNextElement( child ) ) { 252 if( strcmp( child->name, name ) == 0 ) 252 if( strcmp( child->name, name ) == 0 ) { 253 if( n == 0 ) desired = child; 253 if( n == 0 ) desired = child; 254 n++; 254 n++; 255 } 255 } 256 } 256 } 257 if( n == 0 ) { 257 if( n == 0 ) { 258 if( required ) smr_setReportError2( sm 258 if( required ) smr_setReportError2( smr, smr_unknownID, 1, "elements '%s' not found in element '%s'", name, element->name ); } 259 else if( n > 1 ) { 259 else if( n > 1 ) { 260 smr_setReportError2( smr, smr_unknownI 260 smr_setReportError2( smr, smr_unknownID, 1, "multiple (= %d) elements '%s' found in element '%s'", name, element->name ); 261 desired = NULL; 261 desired = NULL; 262 } 262 } 263 return( desired ); 263 return( desired ); 264 } 264 } 265 /* 265 /* 266 ********************************************** 266 ************************************************************ 267 */ 267 */ 268 int xDataTOM_numberOfElementsByName( statusMes 268 int xDataTOM_numberOfElementsByName( statusMessageReporting * /*smr*/, xDataTOM_element *element, char const *name ) { 269 269 270 int n = 0; 270 int n = 0; 271 xDataTOM_element *child; 271 xDataTOM_element *child; 272 272 273 for( child = xDataTOME_getFirstElement( el 273 for( child = xDataTOME_getFirstElement( element ); child != NULL; child = xDataTOME_getNextElement( child ) ) if( !strcmp( child->name, name ) ) n++; 274 return( n ); 274 return( n ); 275 } 275 } 276 /* 276 /* 277 ********************************************** 277 ************************************************************ 278 */ 278 */ 279 int xDataTOME_addAttribute( statusMessageRepor 279 int xDataTOME_addAttribute( statusMessageReporting *smr, xDataTOM_element *element, char const *name, char const *value ) { 280 280 281 return( xDataTOMAL_addAttribute( smr, &(el 281 return( xDataTOMAL_addAttribute( smr, &(element->attributes), name, value ) ); 282 } 282 } 283 /* 283 /* 284 ********************************************** 284 ************************************************************ 285 */ 285 */ 286 char const *xDataTOM_getAttributesValueInEleme 286 char const *xDataTOM_getAttributesValueInElement( xDataTOM_element *element, char const *name ) { 287 287 288 return( xDataTOMAL_getAttributesValue( &(e 288 return( xDataTOMAL_getAttributesValue( &(element->attributes), name ) ); 289 } 289 } 290 /* 290 /* 291 ********************************************** 291 ************************************************************ 292 */ 292 */ 293 int xDataTOME_copyAttributionList( statusMessa 293 int xDataTOME_copyAttributionList( statusMessageReporting *smr, xDataTOM_attributionList *desc, xDataTOM_element *element ) { 294 294 295 return( xDataTOMAL_copyAttributionList( sm 295 return( xDataTOMAL_copyAttributionList( smr, desc, &(element->attributes) ) ); 296 } 296 } 297 /* 297 /* 298 ********************************************** 298 ************************************************************ 299 */ 299 */ 300 int xDataTOME_convertAttributeToInteger( statu 300 int xDataTOME_convertAttributeToInteger( statusMessageReporting *smr, xDataTOM_element *element, char const *name, int *n ) { 301 301 302 return( xDataTOMAL_convertAttributeToInteg 302 return( xDataTOMAL_convertAttributeToInteger( smr, &(element->attributes), name, n ) ); 303 } 303 } 304 /* 304 /* 305 ********************************************** 305 ************************************************************ 306 */ 306 */ 307 int xDataTOME_convertAttributeToDouble( status 307 int xDataTOME_convertAttributeToDouble( statusMessageReporting *smr, xDataTOM_element *element, char const *name, double *d ) { 308 308 309 return( xDataTOMAL_convertAttributeToDoubl 309 return( xDataTOMAL_convertAttributeToDouble( smr, &(element->attributes), name, d ) ); 310 } 310 } 311 /* 311 /* 312 ********************************************** 312 ************************************************************ 313 */ 313 */ 314 int xDataTOME_getInterpolation( statusMessageR 314 int xDataTOME_getInterpolation( statusMessageReporting *smr, xDataTOM_element *element, int index, enum xDataTOM_interpolationFlag *independent, 315 enum xDataTOM_interpolationFlag *dependent 315 enum xDataTOM_interpolationFlag *dependent, enum xDataTOM_interpolationQualifier *qualifier ) { 316 316 317 xDataTOM_xDataInfo *xDI = &(element->xData 317 xDataTOM_xDataInfo *xDI = &(element->xDataInfo); 318 318 319 if( xDI->ID == NULL ) return( 1 ); 319 if( xDI->ID == NULL ) return( 1 ); 320 320 321 return( xDataTOM_axes_getInterpolation( sm 321 return( xDataTOM_axes_getInterpolation( smr, &(xDI->axes), index, independent, dependent, qualifier ) ); 322 } 322 } 323 /* 323 /* 324 ********************************************** 324 ************************************************************ 325 */ 325 */ 326 static void xDataTOME_displayTree( statusMessa 326 static void xDataTOME_displayTree( statusMessageReporting *smr, xDataTOM_element *element, int printAttributes, int level ) { 327 327 328 int i; 328 int i; 329 xDataTOM_element *child; 329 xDataTOM_element *child; 330 330 331 for( i = 0; i < level; i++ ) printf( " 331 for( i = 0; i < level; i++ ) printf( " " ); 332 printf( "/%s", element->name ); 332 printf( "/%s", element->name ); 333 if( element->index >= 0 ) printf( " (%d)", 333 if( element->index >= 0 ) printf( " (%d)", element->index ); 334 if( printAttributes ) { 334 if( printAttributes ) { 335 xDataTOM_attribute *attribute; 335 xDataTOM_attribute *attribute; 336 336 337 for( attribute = element->attributes.a 337 for( attribute = element->attributes.attributes; attribute != NULL; attribute = attribute->next ) { 338 printf( " (%s, \"%s\")", attribute 338 printf( " (%s, \"%s\")", attribute->name, attribute->value ); 339 } 339 } 340 } 340 } 341 printf( "\n" ); 341 printf( "\n" ); 342 for( child = xDataTOME_getFirstElement( el 342 for( child = xDataTOME_getFirstElement( element ); child != NULL; child = xDataTOME_getNextElement( child ) ) { 343 xDataTOME_displayTree( smr, child, pri 343 xDataTOME_displayTree( smr, child, printAttributes, level + 1 ); 344 } 344 } 345 } 345 } 346 346 347 /**************************************** 347 /**************************************** 348 * Attribute functions. 348 * Attribute functions. 349 ****************************************/ 349 ****************************************/ 350 /* 350 /* 351 ********************************************** 351 ************************************************************ 352 */ 352 */ 353 void xDataTOMAL_initial( statusMessageReportin 353 void xDataTOMAL_initial( statusMessageReporting * /*smr*/, xDataTOM_attributionList *attributes ) { 354 354 355 attributes->number = 0; 355 attributes->number = 0; 356 attributes->attributes = NULL; 356 attributes->attributes = NULL; 357 } 357 } 358 /* 358 /* 359 ********************************************** 359 ************************************************************ 360 */ 360 */ 361 void xDataTOMAL_release( xDataTOM_attributionL 361 void xDataTOMAL_release( xDataTOM_attributionList *attributes ) { 362 362 363 xDataTOM_attribute *attribute, *next; 363 xDataTOM_attribute *attribute, *next; 364 364 365 for( attribute = attributes->attributes; a 365 for( attribute = attributes->attributes; attribute != NULL; attribute = next ) { 366 next = attribute->next; 366 next = attribute->next; 367 smr_freeMemory( (void **) &(attribute- 367 smr_freeMemory( (void **) &(attribute->name) ); 368 smr_freeMemory( (void **) &(attribute- 368 smr_freeMemory( (void **) &(attribute->value) ); 369 smr_freeMemory( (void **) &(attribute) 369 smr_freeMemory( (void **) &(attribute) ); 370 } 370 } 371 xDataTOMAL_initial( NULL, attributes ); 371 xDataTOMAL_initial( NULL, attributes ); 372 } 372 } 373 /* 373 /* 374 ********************************************** 374 ************************************************************ 375 */ 375 */ 376 int xDataTOMAL_addAttribute( statusMessageRepo 376 int xDataTOMAL_addAttribute( statusMessageReporting *smr, xDataTOM_attributionList *attributes, char const *name, char const *value ) { 377 377 378 xDataTOM_attribute *attribute; 378 xDataTOM_attribute *attribute; 379 379 380 if( ( attribute = (xDataTOM_attribute *) s 380 if( ( attribute = (xDataTOM_attribute *) smr_malloc2( smr, sizeof( xDataTOM_attribute ), 1, "xDataTOM_attribute" ) ) == NULL ) return( 1 ); 381 if( ( attribute->name = smr_allocateCopySt 381 if( ( attribute->name = smr_allocateCopyString2( smr, name, "name" ) ) == NULL ) goto err; 382 if( ( attribute->value = smr_allocateCopyS 382 if( ( attribute->value = smr_allocateCopyString2( smr, value, "value" ) ) == NULL ) goto err; 383 if( attributes->attributes == NULL ) { 383 if( attributes->attributes == NULL ) { 384 attributes->attributes = attribute; } 384 attributes->attributes = attribute; } 385 else { 385 else { 386 xDataTOM_attribute *last; 386 xDataTOM_attribute *last; 387 387 388 for( last = attributes->attributes; la 388 for( last = attributes->attributes; last->next != NULL; last = last->next ) ; 389 last->next = attribute; 389 last->next = attribute; 390 } 390 } 391 attributes->number++; 391 attributes->number++; 392 return( 0 ); 392 return( 0 ); 393 393 394 err: 394 err: 395 smr_freeMemory( (void **) &(attribute->nam 395 smr_freeMemory( (void **) &(attribute->name) ); 396 smr_freeMemory( (void **) &(attribute->val 396 smr_freeMemory( (void **) &(attribute->value) ); 397 smr_freeMemory( (void **) &(attribute) ); 397 smr_freeMemory( (void **) &(attribute) ); 398 return( 1 ); 398 return( 1 ); 399 } 399 } 400 /* 400 /* 401 ********************************************** 401 ************************************************************ 402 */ 402 */ 403 char const *xDataTOMAL_getAttributesValue( xDa 403 char const *xDataTOMAL_getAttributesValue( xDataTOM_attributionList *attributes, char const *name ) { 404 404 405 xDataTOM_attribute *attribute; 405 xDataTOM_attribute *attribute; 406 406 407 for( attribute = attributes->attributes; a 407 for( attribute = attributes->attributes; attribute != NULL; attribute = attribute->next ) { 408 if( !strcmp( attribute->name, name ) ) 408 if( !strcmp( attribute->name, name ) ) return( attribute->value ); 409 } 409 } 410 return( NULL ); 410 return( NULL ); 411 } 411 } 412 /* 412 /* 413 ********************************************** 413 ************************************************************ 414 */ 414 */ 415 int xDataTOMAL_copyAttributionList( statusMess 415 int xDataTOMAL_copyAttributionList( statusMessageReporting *smr, xDataTOM_attributionList *desc, xDataTOM_attributionList *src ) { 416 416 417 xDataTOM_attribute *attribute; 417 xDataTOM_attribute *attribute; 418 418 419 xDataTOMAL_initial( smr, desc ); 419 xDataTOMAL_initial( smr, desc ); 420 for( attribute = src->attributes; attribut 420 for( attribute = src->attributes; attribute != NULL; attribute = attribute->next ) { 421 if( xDataTOMAL_addAttribute( smr, desc 421 if( xDataTOMAL_addAttribute( smr, desc, attribute->name, attribute->value ) != 0 ) goto err; 422 422 423 } 423 } 424 return( 0 ); 424 return( 0 ); 425 425 426 err: 426 err: 427 xDataTOMAL_release( desc ); 427 xDataTOMAL_release( desc ); 428 return( 1 ); 428 return( 1 ); 429 } 429 } 430 /* 430 /* 431 ********************************************** 431 ************************************************************ 432 */ 432 */ 433 int xDataTOMAL_convertAttributeToInteger( stat 433 int xDataTOMAL_convertAttributeToInteger( statusMessageReporting *smr, xDataTOM_attributionList *attributes, char const *name, int *n ) { 434 434 435 char const *value = xDataTOMAL_getAttribut 435 char const *value = xDataTOMAL_getAttributesValue( attributes, name ); 436 char *e; 436 char *e; 437 437 438 if( value != NULL ) { 438 if( value != NULL ) { 439 *n = (int) strtoll( value, &e, 10 ); 439 *n = (int) strtoll( value, &e, 10 ); 440 if( *e == 0 ) return( 0 ); 440 if( *e == 0 ) return( 0 ); 441 smr_setReportError2( smr, xDataTOM_smr 441 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1, "could not convert attribute %s's value = '%s' to an integer", name, value ); } 442 else { 442 else { 443 smr_setReportError2( smr, xDataTOM_smr 443 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1, "no attribute named '%s'", name ); 444 } 444 } 445 return( 1 ); 445 return( 1 ); 446 } 446 } 447 /* 447 /* 448 ********************************************** 448 ************************************************************ 449 */ 449 */ 450 int xDataTOMAL_convertAttributeToDouble( statu 450 int xDataTOMAL_convertAttributeToDouble( statusMessageReporting *smr, xDataTOM_attributionList *attributes, char const *name, double *d ) { 451 451 452 char const *value = xDataTOMAL_getAttribut 452 char const *value = xDataTOMAL_getAttributesValue( attributes, name ); 453 char *e; 453 char *e; 454 454 455 if( value != NULL ) { 455 if( value != NULL ) { 456 *d = strtod( value, &e ); 456 *d = strtod( value, &e ); 457 if( *e == 0 ) return( 0 ); 457 if( *e == 0 ) return( 0 ); 458 smr_setReportError2( smr, xDataTOM_smr 458 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1, "could not convert attribute %s's values = '%s' to a double", name, value ); } 459 else { 459 else { 460 smr_setReportError2( smr, xDataTOM_smr 460 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1, "no attribute named '%s'", name ); 461 } 461 } 462 return( 1 ); 462 return( 1 ); 463 } 463 } 464 464 465 465 466 /**************************************** 466 /**************************************** 467 * xData functions. 467 * xData functions. 468 ****************************************/ 468 ****************************************/ 469 /* 469 /* 470 ********************************************** 470 ************************************************************ 471 */ 471 */ 472 static int xDataTOM_initialize_xData( statusMe 472 static int xDataTOM_initialize_xData( statusMessageReporting * /*smr*/, xDataTOM_xDataInfo * /*xDataInfo*/ ) { 473 473 474 return( 0 ); 474 return( 0 ); 475 } 475 } 476 /* 476 /* 477 ********************************************** 477 ************************************************************ 478 */ 478 */ 479 void *xData_initializeData( statusMessageRepor 479 void *xData_initializeData( statusMessageReporting *smr, xDataTOM_element *TE, char const *ID, size_t size ) { 480 480 481 xDataTOM_xDataInfo *xDI = &(TE->xDataInfo) 481 xDataTOM_xDataInfo *xDI = &(TE->xDataInfo); 482 482 483 xDI->data = NULL; 483 xDI->data = NULL; 484 xDI->ID = ID; 484 xDI->ID = ID; 485 xDI->element = TE; 485 xDI->element = TE; 486 return( xDI->data = (void *) smr_malloc2( 486 return( xDI->data = (void *) smr_malloc2( smr, size, 1, "xDI->data" ) ); 487 } 487 } 488 /* 488 /* 489 ********************************************** 489 ************************************************************ 490 */ 490 */ 491 int xDataTOM_isXDataID( xDataTOM_element *TE, 491 int xDataTOM_isXDataID( xDataTOM_element *TE, char const *ID ) { 492 492 493 xDataTOM_xDataInfo *xDI = &(TE->xDataInfo) 493 xDataTOM_xDataInfo *xDI = &(TE->xDataInfo); 494 494 495 if( xDI->ID != NULL ) { 495 if( xDI->ID != NULL ) { 496 return( !strcmp( xDI->ID, ID ) ); 496 return( !strcmp( xDI->ID, ID ) ); 497 } 497 } 498 498 499 return( 0 ); 499 return( 0 ); 500 } 500 } 501 /* 501 /* 502 ********************************************** 502 ************************************************************ 503 */ 503 */ 504 xDataTOM_xDataInfo *xDataTOME_getXData( xDataT 504 xDataTOM_xDataInfo *xDataTOME_getXData( xDataTOM_element *TE ) { 505 505 506 if( TE->xDataInfo.ID == NULL ) return( NUL 506 if( TE->xDataInfo.ID == NULL ) return( NULL ); 507 return( &(TE->xDataInfo) ); 507 return( &(TE->xDataInfo) ); 508 } 508 } 509 /* 509 /* 510 ********************************************** 510 ************************************************************ 511 */ 511 */ 512 void *xDataTOME_getXDataIfID( statusMessageRep 512 void *xDataTOME_getXDataIfID( statusMessageReporting *smr, xDataTOM_element *TE, char const *ID ) { 513 513 514 xDataTOM_xDataInfo *xDI = xDataTOME_getXDa 514 xDataTOM_xDataInfo *xDI = xDataTOME_getXData( TE ); 515 515 516 if( xDI == NULL ) { 516 if( xDI == NULL ) { 517 smr_setReportError2( smr, xDataTOM_smr 517 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1, "element '%s' does not have xData", TE->name ); 518 return( NULL ); 518 return( NULL ); 519 } 519 } 520 if( strcmp( ID, xDI->ID ) ) { 520 if( strcmp( ID, xDI->ID ) ) { 521 smr_setReportError2( smr, xDataTOM_smr 521 smr_setReportError2( smr, xDataTOM_smrLibraryID, 1, "xData has ID = '%s' not '%s' for element %s", xDI->ID, ID, TE->name ); 522 return( NULL ); 522 return( NULL ); 523 } 523 } 524 return( xDI->data ); 524 return( xDI->data ); 525 525 526 } 526 } 527 527 528 #if defined __cplusplus 528 #if defined __cplusplus 529 } 529 } 530 #endif 530 #endif 531 531