Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/hadronic/models/lend/src/xDataTOM_importXML.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/hadronic/models/lend/src/xDataTOM_importXML.cc (Version 11.3.0) and /processes/hadronic/models/lend/src/xDataTOM_importXML.cc (Version 10.2)


  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)                            <<  14 #ifdef WIN32
 15 #include <basetsd.h>                           <<  15 #include <BaseTsd.h>
 16 #include <io.h>                                    16 #include <io.h>
 17 #include <windows.h>                               17 #include <windows.h>
 18 #define realpath( a, b ) GetFullPathName( a, P     18 #define realpath( a, b ) GetFullPathName( a, PATH_MAX, b, NULL )
 19 #define strtoll _strtoi64                          19 #define strtoll _strtoi64
 20 typedef SSIZE_T ssize_t;                           20 typedef SSIZE_T ssize_t;
 21 #else                                              21 #else
 22 #include <unistd.h>                                22 #include <unistd.h>
 23 #endif                                             23 #endif
 24                                                    24 
 25 #include "xDataTOM_importXML_private.h"            25 #include "xDataTOM_importXML_private.h"
 26                                                    26 
 27 #if defined __cplusplus                            27 #if defined __cplusplus
 28 namespace GIDI {                                   28 namespace GIDI {
 29 using namespace GIDI;                              29 using namespace GIDI;
 30 #endif                                             30 #endif
 31                                                    31 
 32 #ifndef PATH_MAX                                   32 #ifndef PATH_MAX
 33 #define PATH_MAX 4096                              33 #define PATH_MAX 4096
 34 #endif                                             34 #endif
 35                                                    35 
 36 static xDataXML_document *xDataXML_mallocDoc(      36 static xDataXML_document *xDataXML_mallocDoc( statusMessageReporting *smr );
 37 static int xDataXML_initializeDoc( statusMessa     37 static int xDataXML_initializeDoc( statusMessageReporting *smr, xDataXML_document *doc );
 38 static int xDataXML_endXMLParsing( statusMessa     38 static int xDataXML_endXMLParsing( statusMessageReporting *smr, xDataXML_document *doc );
 39 static void *xDataXML_freeElement( statusMessa     39 static void *xDataXML_freeElement( statusMessageReporting *smr, xDataXML_element *element );
 40 static void xDataXML_freeElementItems( statusM     40 static void xDataXML_freeElementItems( statusMessageReporting *smr, xDataXML_element *element );
 41 static int xDataXML_parse( xDataXML_document *     41 static int xDataXML_parse( xDataXML_document *doc, char const *s );
 42 static void XMLCALL xDataXML_parseStartElement     42 static void XMLCALL xDataXML_parseStartElement( void *userData, char const *name, char const **attris );
 43 static void XMLCALL xDataXML_parseEndElement(      43 static void XMLCALL xDataXML_parseEndElement( void *userData, char const *name );
 44 static void XMLCALL xDataXML_parseCharacterDat     44 static void XMLCALL xDataXML_parseCharacterData( void *userData, XML_Char const *s, int len );
 45 static void xDataXML_initializeRootElement( xD     45 static void xDataXML_initializeRootElement( xDataXML_document *doc, xDataXML_rootElement *re, xDataXML_element *parentElement, int depth );
 46 static int xDataXML_parseInitializeText( xData     46 static int xDataXML_parseInitializeText( xDataXML_document *doc, xDataXML_text *text );
 47 static int xDataXML_addElementToRoot( statusMe     47 static int xDataXML_addElementToRoot( statusMessageReporting *smr, xDataXML_rootElement *parentRoot, char const *name, char const **attris );
 48 static enum xDataXML_errorCodes xDataXML_parse     48 static enum xDataXML_errorCodes xDataXML_parseGetCurrentPosition( xDataXML_document *doc, xDataXML_docInfo *docInfo );
 49 static int xDataXML_init_xDataTypeNone( xDataX     49 static int xDataXML_init_xDataTypeNone( xDataXMLType *xDT, xDataXML_element *element );
 50 static char *xDataXML_getTraceback( statusMess     50 static char *xDataXML_getTraceback( statusMessageReporting *smr, xDataXML_element *element );
 51 static char *xDataXML_getTraceback2( statusMes     51 static char *xDataXML_getTraceback2( statusMessageReporting *smr, xDataXML_rootElement *parentRoot, int n );
 52 static int xDataXML_setFileName( statusMessage     52 static int xDataXML_setFileName( statusMessageReporting *smr, xDataXML_document *doc, char const *fileName );
 53                                                    53 
 54 static int xDataXML_smrUserInterfaceInitialize     54 static int xDataXML_smrUserInterfaceInitialize( xDataXML_document *doc );
 55 static int xDataXML_smrUserInterfaceFree( xDat     55 static int xDataXML_smrUserInterfaceFree( xDataXML_document *doc );
 56 static char *xDataXML_smrUserInterface( void *     56 static char *xDataXML_smrUserInterface( void *userData );
 57 static char const *xDataXML_shortStringForMess     57 static char const *xDataXML_shortStringForMessage( size_t size, char *Out, char const *In );
 58                                                    58 
 59 static int xDataXML_constructTOM( statusMessag     59 static int xDataXML_constructTOM( statusMessageReporting *smr, xDataTOM_element *TE, xDataXML_element *element );
 60 /*                                                 60 /*
 61 **********************************************     61 ************************************************************
 62 */                                                 62 */
 63 xDataTOM_TOM *xDataXML_importFile( statusMessa     63 xDataTOM_TOM *xDataXML_importFile( statusMessageReporting *smr, char const *fileName ) {
 64 /*                                                 64 /*
 65 *   Returns NULL is any error occurred. If an      65 *   Returns NULL is any error occurred. If an error occurs in an expat routine, xDataXML_endXMLParsing will set smr appropriately.
 66 */                                                 66 */
 67     xDataTOM_TOM *TOM = NULL;                      67     xDataTOM_TOM *TOM = NULL;
 68     xDataXML_document *XML = NULL;                 68     xDataXML_document *XML = NULL;
 69     xDataXML_element *element;                     69     xDataXML_element *element;
 70                                                    70 
 71     if( ( XML = xDataXML_importFile2( smr, fil     71     if( ( XML = xDataXML_importFile2( smr, fileName ) ) == NULL ) return( NULL );
 72                                                    72 
 73     if( ( TOM = xDataTOM_mallocTOM( smr ) ) ==     73     if( ( TOM = xDataTOM_mallocTOM( smr ) ) == NULL ) goto Err;
 74     if( xDataTOM_setFileNameTOM( smr, TOM, fil     74     if( xDataTOM_setFileNameTOM( smr, TOM, fileName ) != 0 ) goto Err;
 75                                                    75 
 76     element = xDataXML_getDocumentsElement( XM     76     element = xDataXML_getDocumentsElement( XML );
 77     if( xDataXML_constructTOM( smr, (&TOM->roo     77     if( xDataXML_constructTOM( smr, (&TOM->root), element ) != 0 ) goto Err;
 78                                                    78 
 79     xDataXML_freeDoc( smr, XML );                  79     xDataXML_freeDoc( smr, XML );
 80     return( TOM );                                 80     return( TOM );
 81                                                    81 
 82 Err:                                               82 Err:
 83     if( XML != NULL ) xDataXML_freeDoc( smr, X     83     if( XML != NULL ) xDataXML_freeDoc( smr, XML );
 84     if( TOM != NULL ) xDataTOM_freeTOM( smr, &     84     if( TOM != NULL ) xDataTOM_freeTOM( smr, &TOM );
 85     return( NULL );                                85     return( NULL );
 86 }                                                  86 }
 87 /*                                                 87 /*
 88 **********************************************     88 ************************************************************
 89 */                                                 89 */
 90 xDataXML_document *xDataXML_importFile2( statu     90 xDataXML_document *xDataXML_importFile2( statusMessageReporting *smr, char const *fileName ) {
 91 /*                                                 91 /*
 92 *   Returns NULL is any error occurred. If an      92 *   Returns NULL is any error occurred. If an error occurs in an expat routine, xDataXML_endXMLParsing will set smr appropriately.
 93 */                                                 93 */
 94     int f;                                         94     int f;
 95     char buffer[10 * 1000];                        95     char buffer[10 * 1000];
 96     ssize_t count, n = sizeof( buffer ) - 1;       96     ssize_t count, n = sizeof( buffer ) - 1;
                                                   >>  97     ssize_t s = 0;
 97     xDataXML_document *doc;                        98     xDataXML_document *doc;
 98                                                    99 
 99     if( ( doc = xDataXML_mallocDoc( smr ) ) ==    100     if( ( doc = xDataXML_mallocDoc( smr ) ) == NULL ) return( NULL );
100     if( xDataXML_setFileName( smr, doc, fileNa    101     if( xDataXML_setFileName( smr, doc, fileName ) == 0 ) {
101         f = open( fileName, O_RDONLY );           102         f = open( fileName, O_RDONLY );
102         if( f == -1 ) {                           103         if( f == -1 ) {
103                 xDataXML_endXMLParsing( smr, d    104                 xDataXML_endXMLParsing( smr, doc );
104                 smr_setReportError2( smr, xDat    105                 smr_setReportError2( smr, xDataTOM_smrLibraryID, xDataXML_errFileError, "could not open XML file %s", fileName ); }
105         else {                                    106         else {
106                 while( ( count = read( f, buff    107                 while( ( count = read( f, buffer, n ) ) > 0 ) {
                                                   >> 108                     s += count;
107                     buffer[count] = 0;            109                     buffer[count] = 0;
108                     if( xDataXML_parse( doc, b    110                     if( xDataXML_parse( doc, buffer ) ) break;
109                     if( !smr_isOk( doc->smr )     111                     if( !smr_isOk( doc->smr ) ) break;
110                 }  // Loop checking, 11.06.201    112                 }  // Loop checking, 11.06.2015, T. Koi
111                 close( f );                       113                 close( f );
112                 xDataXML_endXMLParsing( smr, d    114                 xDataXML_endXMLParsing( smr, doc );
113                 if( count < 0 ) smr_setReportE    115                 if( count < 0 ) smr_setReportError2( smr, xDataTOM_smrLibraryID, xDataXML_errFileError, "read failed with errno = %d for XML %s", 
114                     errno, fileName );            116                     errno, fileName );
115         }                                         117         }
116     }                                             118     }
117     if( doc != NULL ) {                           119     if( doc != NULL ) {
118         if( !smr_isOk( smr ) ) {                  120         if( !smr_isOk( smr ) ) {
119             xDataXML_freeDoc( smr, doc );         121             xDataXML_freeDoc( smr, doc );
120             doc = NULL;                           122             doc = NULL;
121         }                                         123         }
122     }                                             124     }
123     return( doc );                                125     return( doc );
124 }                                                 126 }
125 /*                                                127 /*
126 **********************************************    128 ************************************************************
127 */                                                129 */
128 static xDataXML_document *xDataXML_mallocDoc(     130 static xDataXML_document *xDataXML_mallocDoc( statusMessageReporting *smr ) {
129                                                   131 
130     xDataXML_document *doc;                       132     xDataXML_document *doc;
131                                                   133 
132     if( ( doc = (xDataXML_document *) smr_mall    134     if( ( doc = (xDataXML_document *) smr_malloc2( smr, sizeof( xDataXML_document ), 1, "xDataXML_document" ) ) != NULL ) {
133         if( xDataXML_initializeDoc( smr, doc )    135         if( xDataXML_initializeDoc( smr, doc ) ) doc = (xDataXML_document *) xDataXML_freeDoc( smr, doc );
134     }                                             136     }
135     return( doc );                                137     return( doc );
136 }                                                 138 }
137 /*                                                139 /*
138 **********************************************    140 ************************************************************
139 */                                                141 */
140 static int xDataXML_initializeDoc( statusMessa    142 static int xDataXML_initializeDoc( statusMessageReporting *smr, xDataXML_document *doc ) {
141                                                   143 
142     doc->status = xDataXML_statusParsing;         144     doc->status = xDataXML_statusParsing;
143     doc->error = xDataXML_errNone;                145     doc->error = xDataXML_errNone;
144     doc->err = XML_ERROR_NONE;                    146     doc->err = XML_ERROR_NONE;
145     doc->err_line = 0;                            147     doc->err_line = 0;
146     doc->err_column = 0;                          148     doc->err_column = 0;
147     doc->fileName = NULL;                         149     doc->fileName = NULL;
148     doc->realFileName = NULL;                     150     doc->realFileName = NULL;
149     xDataXML_smrUserInterfaceInitialize( doc )    151     xDataXML_smrUserInterfaceInitialize( doc );
150     doc->smr= smr;                                152     doc->smr= smr;
151     if( ( doc->xmlParser = XML_ParserCreate( N    153     if( ( doc->xmlParser = XML_ParserCreate( NULL ) ) == NULL ) {
152         smr_setReportError2p( smr, xDataTOM_sm    154         smr_setReportError2p( smr, xDataTOM_smrLibraryID, xDataXML_errXML_ParserCreate, "XML_ParserCreate failed" ); }
153     else {                                        155     else {
154         XML_SetUserData( doc->xmlParser, doc      156         XML_SetUserData( doc->xmlParser, doc  );
155         xDataXML_initializeRootElement( doc, &    157         xDataXML_initializeRootElement( doc, &(doc->root), NULL, 0 );
156         doc->currentRoot = &(doc->root);          158         doc->currentRoot = &(doc->root);
157         XML_SetElementHandler( doc->xmlParser,    159         XML_SetElementHandler( doc->xmlParser, xDataXML_parseStartElement, xDataXML_parseEndElement );
158         XML_SetCharacterDataHandler( doc->xmlP    160         XML_SetCharacterDataHandler( doc->xmlParser, xDataXML_parseCharacterData );
159     }                                             161     }
160     return( !smr_isOk( smr ) );                   162     return( !smr_isOk( smr ) );
161 }                                                 163 }
162 /*                                                164 /*
163 **********************************************    165 ************************************************************
164 */                                                166 */
165 static int xDataXML_endXMLParsing( statusMessa    167 static int xDataXML_endXMLParsing( statusMessageReporting *smr, xDataXML_document *doc ) {
166                                                   168 
167     if( doc->xmlParser ) {                        169     if( doc->xmlParser ) {
168         doc->err = XML_GetErrorCode( doc->xmlP    170         doc->err = XML_GetErrorCode( doc->xmlParser );
169         doc->err_line = XML_GetCurrentLineNumb    171         doc->err_line = XML_GetCurrentLineNumber( doc->xmlParser );
170         doc->err_column = XML_GetCurrentColumn    172         doc->err_column = XML_GetCurrentColumnNumber( doc->xmlParser );
171         if( smr_isOk( smr ) && ( XML_Parse( do    173         if( smr_isOk( smr ) && ( XML_Parse( doc->xmlParser, NULL, 0, 1 ) == XML_STATUS_ERROR ) ) {
172             doc->status = xDataXML_statusError    174             doc->status = xDataXML_statusError;
173             smr_setReportError3( smr, xDataXML    175             smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromDocument( doc ), xDataTOM_smrLibraryID, xDataXML_errXMLParser, 
174                 "status = %d\nXML_Error code =    176                 "status = %d\nXML_Error code = %d\nXML_ErrorString = %s\nerror line, column = %d, %d", xDataXML_errXMLParser, 
175                 doc->err, XML_ErrorString( doc    177                 doc->err, XML_ErrorString( doc->err ), doc->err_line, doc->err_column );
176         }                                         178         }
177         XML_ParserFree( doc->xmlParser );         179         XML_ParserFree( doc->xmlParser );
178         doc->xmlParser = NULL;                    180         doc->xmlParser = NULL;
179         if( doc->status != xDataXML_statusErro    181         if( doc->status != xDataXML_statusError ) doc->status = xDataXML_statusCompleted;
180     }                                             182     }
181     return( 0 );                                  183     return( 0 );
182 }                                                 184 }
183 /*                                                185 /*
184 **********************************************    186 ************************************************************
185 */                                                187 */
186 void *xDataXML_freeDoc( statusMessageReporting    188 void *xDataXML_freeDoc( statusMessageReporting *smr, xDataXML_document *doc ) {
187                                                   189 
188     xDataXML_endXMLParsing( smr, doc );           190     xDataXML_endXMLParsing( smr, doc );
189     doc->root.children = (xDataXML_element *)     191     doc->root.children = (xDataXML_element *) xDataXML_freeElement( smr, doc->root.children );
190     smr_freeMemory( (void **) &(doc->fileName)    192     smr_freeMemory( (void **) &(doc->fileName) );
191     smr_freeMemory( (void **) &(doc->realFileN    193     smr_freeMemory( (void **) &(doc->realFileName) );
192     xDataXML_smrUserInterfaceFree( doc );         194     xDataXML_smrUserInterfaceFree( doc );
193     smr_freeMemory( (void **) &doc );             195     smr_freeMemory( (void **) &doc );
194     return( NULL );                               196     return( NULL );
195 }                                                 197 }
196 /*                                                198 /*
197 **********************************************    199 ************************************************************
198 */                                                200 */
199 static void *xDataXML_freeElement( statusMessa    201 static void *xDataXML_freeElement( statusMessageReporting *smr, xDataXML_element *element ) {
200                                                   202     
201     xDataXML_element *next;                       203     xDataXML_element *next;
202                                                   204 
203     for( ; element != NULL; element = next ) {    205     for( ; element != NULL; element = next ) {
204         next = element->next;                     206         next = element->next;
205         xDataXML_freeElementItems( smr, elemen    207         xDataXML_freeElementItems( smr, element );
206         smr_freeMemory( (void **) &element );     208         smr_freeMemory( (void **) &element );
207     }                                             209     }
208     return( NULL );                               210     return( NULL );
209 }                                                 211 }
210 /*                                                212 /*
211 **********************************************    213 ************************************************************
212 */                                                214 */
213 static void xDataXML_freeElementItems( statusM    215 static void xDataXML_freeElementItems( statusMessageReporting *smr, xDataXML_element *element ) {
214                                                   216 
215     element->childrenRoot.children = (xDataXML    217     element->childrenRoot.children = (xDataXML_element *) xDataXML_freeElement( smr, element->childrenRoot.children );
216 /* BRB, The next line needs work */               218 /* BRB, The next line needs work */
217     if( ( !strcmp( element->name, "xData" ) )     219     if( ( !strcmp( element->name, "xData" ) ) && ( element->xDataTypeInfo.release != NULL ) ) element->xDataTypeInfo.release( smr, &(element->xDataTypeInfo) );
218     smr_freeMemory( (void **) &(element->name)    220     smr_freeMemory( (void **) &(element->name) );
219     smr_freeMemory( (void **) &(element->fullN    221     smr_freeMemory( (void **) &(element->fullName) );
220     if( element->attributes.attributes ) smr_f    222     if( element->attributes.attributes ) smr_freeMemory( (void **) &(element->attributes.attributes) );
221     if( element->text.text ) smr_freeMemory( (    223     if( element->text.text ) smr_freeMemory( (void **) &(element->text.text) );
222 }                                                 224 }
223 /*                                                225 /*
224 **********************************************    226 ************************************************************
225 */                                                227 */
226 static int xDataXML_parse( xDataXML_document *    228 static int xDataXML_parse( xDataXML_document *doc, char const *s ) {
227                                                   229 
228     if( doc->status != xDataXML_statusParsing     230     if( doc->status != xDataXML_statusParsing ) return( doc->status );
229     if( XML_Parse( doc->xmlParser, s, (int) st    231     if( XML_Parse( doc->xmlParser, s, (int) strlen( s ), 0 ) == XML_STATUS_ERROR ) return( -1 );
230     return( 0 );                                  232     return( 0 );
231 }                                                 233 }
232 /*                                                234 /*
233 **********************************************    235 ************************************************************
234 */                                                236 */
235 static void XMLCALL xDataXML_parseStartElement    237 static void XMLCALL xDataXML_parseStartElement( void *userData, char const *name, char const **attris ) {
236                                                   238 
237     xDataXML_document *doc = (xDataXML_documen    239     xDataXML_document *doc = (xDataXML_document *) userData;
238                                                   240 
239     if( !smr_isOk( doc->smr ) ) return;           241     if( !smr_isOk( doc->smr ) ) return;
240     xDataXML_addElementToRoot( doc->smr, doc->    242     xDataXML_addElementToRoot( doc->smr, doc->currentRoot, name, attris );
241 }                                                 243 }
242 /*                                                244 /*
243 **********************************************    245 ************************************************************
244 */                                                246 */
245 static void XMLCALL xDataXML_parseEndElement(     247 static void XMLCALL xDataXML_parseEndElement( void *userData, char const * /*name*/ ) {
246                                                   248 
247     xDataXML_document *doc = (xDataXML_documen    249     xDataXML_document *doc = (xDataXML_document *) userData;
248                                                   250 
249     doc->currentRoot->currentChild = NULL;        251     doc->currentRoot->currentChild = NULL;
250     doc->currentRoot = doc->currentRoot->paren    252     doc->currentRoot = doc->currentRoot->parentRoot;
251 }                                                 253 }
252 /*                                                254 /*
253 **********************************************    255 ************************************************************
254 */                                                256 */
255 static void XMLCALL xDataXML_parseCharacterDat    257 static void XMLCALL xDataXML_parseCharacterData( void *userData, XML_Char const *s, int len ) {
256 /*                                                258 /*
257 *   Always terminates text with a 0.              259 *   Always terminates text with a 0.
258 */                                                260 */
259     xDataXML_document *doc = (xDataXML_documen    261     xDataXML_document *doc = (xDataXML_document *) userData;
260     xDataXML_text *text = &(doc->currentRoot->    262     xDataXML_text *text = &(doc->currentRoot->parentRoot->currentChild->text);
261     size_t needSize = text->length + len + 1,     263     size_t needSize = text->length + len + 1, l; 
262     char *p;                                      264     char *p;
263                                                   265 
264     if( !smr_isOk( doc->smr ) ) return;           266     if( !smr_isOk( doc->smr ) ) return;
265     if( needSize < 8  ) needSize = 8;             267     if( needSize < 8  ) needSize = 8;
266     if( needSize > text->allocated ) {            268     if( needSize > text->allocated ) {
267         if( text->allocated != 0 ) {              269         if( text->allocated != 0 ) {
268             l = ( 20 * text->allocated ) / 100    270             l = ( 20 * text->allocated ) / 100;
269             if( l < 100 ) l = 100;                271             if( l < 100 ) l = 100;
270             if( needSize < ( text->allocated +    272             if( needSize < ( text->allocated + l ) ) needSize = text->allocated + l;
271         }                                         273         }
272         text->allocated = needSize;               274         text->allocated = needSize;
273         text->text = (char *) smr_realloc2( do    275         text->text = (char *) smr_realloc2( doc->smr, text->text, text->allocated, "text" );
274         if( !smr_isOk( doc->smr ) ) return;       276         if( !smr_isOk( doc->smr ) ) return;
275     }                                             277     }
276     p = &(text->text[text->length]);              278     p = &(text->text[text->length]);
277     strncpy( p, s, len );                         279     strncpy( p, s, len );
278     text->length += len;                          280     text->length += len;
279     p[len] = 0;                                   281     p[len] = 0;
280 }                                                 282 }
281 /*                                                283 /*
282 **********************************************    284 ************************************************************
283 */                                                285 */
284 static void xDataXML_initializeRootElement( xD    286 static void xDataXML_initializeRootElement( xDataXML_document *doc, xDataXML_rootElement *re, xDataXML_element *parentElement, int depth ) {
285                                                   287 
286     re->xData_doc = doc;                          288     re->xData_doc = doc;
287     re->parentElement = parentElement;            289     re->parentElement = parentElement;
288     re->parentRoot = NULL;                        290     re->parentRoot = NULL;
289     if( parentElement != NULL ) re->parentRoot    291     if( parentElement != NULL ) re->parentRoot = parentElement->parentRoot;
290     re->depth = depth;                            292     re->depth = depth;
291     re->numberOfElements = 0;                     293     re->numberOfElements = 0;
292     re->children = NULL;                          294     re->children = NULL;
293     re->currentChild = NULL;                      295     re->currentChild = NULL;
294 }                                                 296 }
295 /*                                                297 /*
296 **********************************************    298 ************************************************************
297 */                                                299 */
298 static int xDataXML_parseInitializeText( xData    300 static int xDataXML_parseInitializeText( xDataXML_document *doc, xDataXML_text *text ) {
299                                                   301 
300     xDataXML_parseGetCurrentPosition( doc, &(t    302     xDataXML_parseGetCurrentPosition( doc, &(text->docInfo) );
301     text->allocated = 0;                          303     text->allocated = 0;
302     text->length = 0;                             304     text->length = 0;
303     text->text = NULL;                            305     text->text = NULL;
304     return( 0 );                                  306     return( 0 );
305 }                                                 307 }
306 /*                                                308 /*
307 **********************************************    309 ************************************************************
308 */                                                310 */
309 static int xDataXML_addElementToRoot( statusMe    311 static int xDataXML_addElementToRoot( statusMessageReporting *smr, xDataXML_rootElement *parentRoot, char const *name, char const **attris ) {
310                                                   312 
311     xDataXML_document *doc = parentRoot->xData    313     xDataXML_document *doc = parentRoot->xData_doc;
312     xDataXML_element *element;                    314     xDataXML_element *element;
313     int i, n, status = 1;                         315     int i, n, status = 1;
314     size_t lens;                                  316     size_t lens;
315     char *p, *e;                                  317     char *p, *e;
316     char const **pAttris;                         318     char const **pAttris;
317     xDataXML_attribute *a;                        319     xDataXML_attribute *a;
318     void *smrUser;                                320     void *smrUser;
319                                                   321 
320     element = (xDataXML_element *) smr_malloc2    322     element = (xDataXML_element *) smr_malloc2( doc->smr, sizeof( xDataXML_element ), 1, "xDataXML_element" );
321     if( element == NULL ) return( 1 );            323     if( element == NULL ) return( 1 );
322     xDataXML_parseGetCurrentPosition( doc, &(e    324     xDataXML_parseGetCurrentPosition( doc, &(element->docInfo) );
323     element->ordinal = parentRoot->numberOfEle    325     element->ordinal = parentRoot->numberOfElements;
324     element->index = -1;                          326     element->index = -1;
325     element->accessed = 0;                        327     element->accessed = 0;
326     element->parentRoot = parentRoot;             328     element->parentRoot = parentRoot;
327     xDataXML_initializeRootElement( doc, &(ele    329     xDataXML_initializeRootElement( doc, &(element->childrenRoot), element, parentRoot->depth + 1 );
328     element->next = NULL;                         330     element->next = NULL;
329     if( ( element->name = (char *) smr_malloc2    331     if( ( element->name = (char *) smr_malloc2( doc->smr, strlen( name ) + 1, 0, "name" ) ) == NULL ) {
330         smr_freeMemory( (void **) &element );     332         smr_freeMemory( (void **) &element );
331         return( 1 );                              333         return( 1 );
332     }                                             334     }
333     strcpy( element->name, name );                335     strcpy( element->name, name );
334     if( ( element->fullName = xDataXML_getTrac    336     if( ( element->fullName = xDataXML_getTraceback( smr, element ) ) == NULL ) {
335         smr_freeMemory( (void **) &(element->n    337         smr_freeMemory( (void **) &(element->name) );
336         smr_freeMemory( (void **) &element );     338         smr_freeMemory( (void **) &element );
337         return( 1 );                              339         return( 1 );
338     }                                             340     }
339     for( i = 0, lens = 0, pAttris = attris; *p    341     for( i = 0, lens = 0, pAttris = attris; *pAttris; i++, pAttris++ ) lens += strlen( *pAttris ) + 1;
340     n = i / 2;                                    342     n = i / 2;
341     element->attributes.size = n * sizeof( xDa    343     element->attributes.size = n * sizeof( xDataXML_attribute ) + lens;
342     element->attributes.number = n;               344     element->attributes.number = n;
343     element->attributes.attributes = NULL;        345     element->attributes.attributes = NULL;
344     smrUser = xDataXML_get_smrUserInterfaceFro    346     smrUser = xDataXML_get_smrUserInterfaceFromElement( element );
345     if( element->attributes.size  ) {             347     if( element->attributes.size  ) {
346         if( ( element->attributes.attributes =    348         if( ( element->attributes.attributes = (xDataXML_attribute *) smr_malloc2( doc->smr, element->attributes.size, 0, "attributes") ) == NULL ) {
347             status = 0; }                         349             status = 0; }
348         else {                                    350         else {
349             a = element->attributes.attributes    351             a = element->attributes.attributes;
350             p = (char *) &(element->attributes    352             p = (char *) &(element->attributes.attributes[n]);
351             for( i = 0, pAttris = attris; ( i     353             for( i = 0, pAttris = attris; ( i < n ) && status; i++, a++, pAttris++ ) {
352                 lens = strlen( *pAttris ) + 1;    354                 lens = strlen( *pAttris ) + 1;
353                 a->name = p;                      355                 a->name = p;
354                 strcpy( p, *pAttris );            356                 strcpy( p, *pAttris );
355                 p += lens;                        357                 p += lens;
356                 pAttris++;                        358                 pAttris++;
357                 lens = strlen( *pAttris ) + 1;    359                 lens = strlen( *pAttris ) + 1;
358                 a->value= p;                      360                 a->value= p;
359                 strcpy( p, *pAttris );            361                 strcpy( p, *pAttris );
360                 p += lens;                        362                 p += lens;
361                 if( !strcmp( "index", a->name     363                 if( !strcmp( "index", a->name ) ) {
362                     element->index = (int) str    364                     element->index = (int) strtoll( a->value, &e, 10 );
363                     if( *e != 0 ) {               365                     if( *e != 0 ) {
364                         status = 0;               366                         status = 0;
365                         smr_setReportError3( d    367                         smr_setReportError3( doc->smr, smrUser, xDataTOM_smrLibraryID, -1, "could not convert index attribute = %s to integer", a->value );
366                     }                             368                     }
367                 }                                 369                 }
368             }                                     370             }
369         }                                         371         }
370     }                                             372     }
371     if( !status ) {                               373     if( !status ) {
372         smr_freeMemory( (void **) &(element->a    374         smr_freeMemory( (void **) &(element->attributes.attributes) );
373         smr_freeMemory( (void **) &(element->n    375         smr_freeMemory( (void **) &(element->name) );
374         smr_freeMemory( (void **) &(element->f    376         smr_freeMemory( (void **) &(element->fullName) );
375         smr_freeMemory( (void **) &element );     377         smr_freeMemory( (void **) &element );
376         return( 1 );                              378         return( 1 );
377     }                                             379     }
378     xDataXML_init_xDataTypeNone( &(element->xD    380     xDataXML_init_xDataTypeNone( &(element->xDataTypeInfo), element );
379     element->textOffset = 0;                      381     element->textOffset = 0;
380     xDataXML_parseInitializeText( doc, &(eleme    382     xDataXML_parseInitializeText( doc, &(element->text) );
381     if( parentRoot->parentElement != NULL ) el    383     if( parentRoot->parentElement != NULL ) element->textOffset = parentRoot->parentElement->text.length;
382     if( parentRoot->currentChild == NULL ) {      384     if( parentRoot->currentChild == NULL ) {
383         parentRoot->children = element; }         385         parentRoot->children = element; }
384     else {                                        386     else {
385         parentRoot->currentChild->next = eleme    387         parentRoot->currentChild->next = element;
386     }                                             388     }
387     parentRoot->numberOfElements++;               389     parentRoot->numberOfElements++;
388     parentRoot->currentChild = element;           390     parentRoot->currentChild = element;
389     doc->currentRoot = &(element->childrenRoot    391     doc->currentRoot = &(element->childrenRoot);
390     return( 0 );                                  392     return( 0 );
391 }                                                 393 }
392 /*                                                394 /*
393 **********************************************    395 ************************************************************
394 */                                                396 */
395 static enum xDataXML_errorCodes xDataXML_parse    397 static enum xDataXML_errorCodes xDataXML_parseGetCurrentPosition( xDataXML_document *doc, xDataXML_docInfo *docInfo ) {
396                                                   398 
397     docInfo->column = XML_GetCurrentColumnNumb    399     docInfo->column = XML_GetCurrentColumnNumber( doc->xmlParser );
398     docInfo->line = XML_GetCurrentLineNumber(     400     docInfo->line = XML_GetCurrentLineNumber( doc->xmlParser );
399     return( xDataXML_errNone );                   401     return( xDataXML_errNone );
400 }                                                 402 }
401 /*                                                403 /*
402 **********************************************    404 ************************************************************
403 */                                                405 */
404 int xDataXML_parseIsError( xDataXML_document *    406 int xDataXML_parseIsError( xDataXML_document *doc ) {
405                                                   407 
406     return( doc->status == xDataXML_statusErro    408     return( doc->status == xDataXML_statusError );
407 }                                                 409 }
408 /*                                                410 /*
409 **********************************************    411 ************************************************************
410 */                                                412 */
411 xDataXML_element *xDataXML_getDocumentsElement    413 xDataXML_element *xDataXML_getDocumentsElement( xDataXML_document *doc ) { return( doc->root.children ); }
412 xDataXML_element *xDataXML_getFirstElement( xD    414 xDataXML_element *xDataXML_getFirstElement( xDataXML_element *element ) { return( element->childrenRoot.children ); }
413 xDataXML_element *xDataXML_getNextElement( xDa    415 xDataXML_element *xDataXML_getNextElement( xDataXML_element *element ) { return( element->next ); }
414 /*                                                416 /*
415 **********************************************    417 ************************************************************
416 */                                                418 */
417 enum xDataXML_itemMode xDataXML_getFirstItem(     419 enum xDataXML_itemMode xDataXML_getFirstItem( xDataXML_element *element, xDataXML_item *item ) {
418                                                   420 
419     item->parentElement = element;                421     item->parentElement = element;
420     item->element = xDataXML_getFirstElement(     422     item->element = xDataXML_getFirstElement( element );
421     if( item->element == NULL ) {                 423     if( item->element == NULL ) {
422         item->mode = xDataXML_itemModeText;       424         item->mode = xDataXML_itemModeText;
423         if( element->text.length == 0 ) item->    425         if( element->text.length == 0 ) item->mode = xDataXML_itemModeEnd; }
424     else {                                        426     else {
425         item->mode = xDataXML_itemModeElement;    427         item->mode = xDataXML_itemModeElement;
426         if( 0 < item->element->textOffset ) it    428         if( 0 < item->element->textOffset ) item->mode = xDataXML_itemModeText;
427     }                                             429     }
428     item->textOffset = 0;                         430     item->textOffset = 0;
429     item->textLength = element->text.length;      431     item->textLength = element->text.length;
430     if( item->element != NULL ) item->textLeng    432     if( item->element != NULL ) item->textLength = item->element->textOffset;
431     item->text = element->text.text;              433     item->text = element->text.text;
432     return( item->mode );                         434     return( item->mode );
433 }                                                 435 }
434 /*                                                436 /*
435 **********************************************    437 ************************************************************
436 */                                                438 */
437 enum xDataXML_itemMode xDataXML_getNextItem( x    439 enum xDataXML_itemMode xDataXML_getNextItem( xDataXML_item *item ) {
438                                                   440 
439     if( item->mode != xDataXML_itemModeEnd ) {    441     if( item->mode != xDataXML_itemModeEnd ) {
440         if( item->mode == xDataXML_itemModeTex    442         if( item->mode == xDataXML_itemModeText ) {
441             item->mode = xDataXML_itemModeElem    443             item->mode = xDataXML_itemModeElement;
442             if( item->element == NULL ) item->    444             if( item->element == NULL ) item->mode = xDataXML_itemModeEnd;
443             item->textOffset += item->textLeng    445             item->textOffset += item->textLength;
444             item->textLength = 0;                 446             item->textLength = 0;
445             item->text = &(item->parentElement    447             item->text = &(item->parentElement->text.text[item->textOffset]); }
446         else {                                    448         else {
447             item->element = item->element->nex    449             item->element = item->element->next;
448             item->mode = xDataXML_itemModeText    450             item->mode = xDataXML_itemModeText;
449             if( item->element == NULL ) {         451             if( item->element == NULL ) {
450                 if( item->textOffset < item->p    452                 if( item->textOffset < item->parentElement->text.length ) {
451                     item->textLength = item->p    453                     item->textLength = item->parentElement->text.length - item->textOffset; }
452                 else {                            454                 else {
453                     item->mode = xDataXML_item    455                     item->mode = xDataXML_itemModeEnd;
454                 } }                               456                 } }
455             else {                                457             else {
456                 item->textLength = item->eleme    458                 item->textLength = item->element->textOffset - item->textOffset;
457             }                                     459             }
458         }                                         460         }
459     }                                             461     }
460     return( item->mode );                         462     return( item->mode );
461 }                                                 463 }
462 /*                                                464 /*
463 **********************************************    465 ************************************************************
464 */                                                466 */
465 int xDataXML_isAttributeInList( xDataXML_attri    467 int xDataXML_isAttributeInList( xDataXML_attributionList *attributes, char const *name ) {
466                                                   468 
467     int i;                                        469     int i;
468                                                   470 
469     for( i = 0; i < attributes->number; i++ )     471     for( i = 0; i < attributes->number; i++ ) {
470         if( !strcmp( attributes->attributes[i]    472         if( !strcmp( attributes->attributes[i].name, name ) ) return( 1 );
471     }                                             473     }
472     return( 0 );                                  474     return( 0 );
473 }                                                 475 }
474 /*                                                476 /*
475 **********************************************    477 ************************************************************
476 */                                                478 */
477 int xDataXML_isAttributeInElement( xDataXML_el    479 int xDataXML_isAttributeInElement( xDataXML_element *element, char const *name ) {
478                                                   480 
479     return( xDataXML_isAttributeInList( &(elem    481     return( xDataXML_isAttributeInList( &(element->attributes), name ) );
480 }                                                 482 }
481 /*                                                483 /*
482 **********************************************    484 ************************************************************
483 */                                                485 */
484 char *xDataXML_getAttributesValue( xDataXML_at    486 char *xDataXML_getAttributesValue( xDataXML_attributionList *attributes, char const *name ) {
485                                                   487 
486     int i;                                        488     int i;
487                                                   489 
488     for( i = 0; i < attributes->number; i++ )     490     for( i = 0; i < attributes->number; i++ ) {
489         if( !strcmp( attributes->attributes[i]    491         if( !strcmp( attributes->attributes[i].name, name ) ) return( attributes->attributes[i].value );
490     }                                             492     }
491     return( NULL );                               493     return( NULL );
492 }                                                 494 }
493 /*                                                495 /*
494 **********************************************    496 ************************************************************
495 */                                                497 */
496 char const *xDataXML_getAttributesValueInEleme    498 char const *xDataXML_getAttributesValueInElement( xDataXML_element *element, char const *name ) {
497                                                   499 
498     return( (char const *) xDataXML_getAttribu    500     return( (char const *) xDataXML_getAttributesValue( &(element->attributes), name ) );
499 }                                                 501 }
500 /*                                                502 /*
501 **********************************************    503 ************************************************************
502 */                                                504 */
503 int xDataXML_attributeListLength( xDataXML_att    505 int xDataXML_attributeListLength( xDataXML_attributionList *attributes ) {
504                                                   506 
505     return( attributes->number );                 507     return( attributes->number );
506 }                                                 508 }
507 /*                                                509 /*
508 **********************************************    510 ************************************************************
509 */                                                511 */
510 xDataXML_attribute *xDataXML_attributeByIndex(    512 xDataXML_attribute *xDataXML_attributeByIndex( xDataXML_attributionList *attributes, int index ) {
511                                                   513 
512     if( index >= attributes->number ) return(     514     if( index >= attributes->number ) return( NULL );
513     return( &(attributes->attributes[index]) )    515     return( &(attributes->attributes[index]) );
514 }                                                 516 }
515 /*                                                517 /*
516 **********************************************    518 ************************************************************
517 */                                                519 */
518 static int xDataXML_init_xDataTypeNone( xDataX    520 static int xDataXML_init_xDataTypeNone( xDataXMLType *xDT, xDataXML_element *element ) {
519                                                   521 
520     xDT->status = xDataXML_xDataType_Ok;          522     xDT->status = xDataXML_xDataType_Ok;
521     xDT->ID = NULL;                               523     xDT->ID = NULL;
522     xDT->element = element;                       524     xDT->element = element;
523     xDT->toData = NULL;                           525     xDT->toData = NULL;
524     xDT->toString = NULL;                         526     xDT->toString = NULL;
525     xDT->release = NULL;                          527     xDT->release = NULL;
526     xDT->indexPresent = 1;                  /*    528     xDT->indexPresent = 1;                  /* The following describes the meaning of present variables. */
527     xDT->startPresent = 1;                  /*    529     xDT->startPresent = 1;                  /* If < 0, an error occured in converting value to an integer. */
528     xDT->endPresent = 1;                    /*    530     xDT->endPresent = 1;                    /* If > 0, not present as an attribute. */
529     xDT->lengthPresent = 1;                 /*    531     xDT->lengthPresent = 1;                 /* Else, if 0, present and converted without an error. */
530     xDT->index = -1;                              532     xDT->index = -1;
531     xDT->start = -1;                              533     xDT->start = -1;
532     xDT->end = -1;                                534     xDT->end = -1;
533     xDT->length = -1;                             535     xDT->length = -1;
534     xDT->data = NULL;                             536     xDT->data = NULL;
535     return( 0 );                                  537     return( 0 );
536 }                                                 538 }
537 /*                                                539 /*
538 **********************************************    540 ************************************************************
539 */                                                541 */
540 int xDataXML_getCommonData( statusMessageRepor    542 int xDataXML_getCommonData( statusMessageReporting *smr, xDataXML_element *element, xDataTOM_Int *index, xDataTOM_Int *start, xDataTOM_Int *end,
541         xDataTOM_Int *length ) {                  543         xDataTOM_Int *length ) {
542                                                   544 
543     if( element->xDataTypeInfo.ID == NULL ) {     545     if( element->xDataTypeInfo.ID == NULL ) {
544         smr_setReportError3( smr, xDataXML_get    546         smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( element ), xDataTOM_smrLibraryID, 1, 
545             "element %s is not xData", element    547             "element %s is not xData", element->fullName );
546         return( 1 );                              548         return( 1 );
547     }                                             549     }
548     *index = element->xDataTypeInfo.index;        550     *index = element->xDataTypeInfo.index;
549     *start = element->xDataTypeInfo.start;        551     *start = element->xDataTypeInfo.start;
550     *end = element->xDataTypeInfo.end;            552     *end = element->xDataTypeInfo.end;
551     *length = element->xDataTypeInfo.length;      553     *length = element->xDataTypeInfo.length;
552     return( 0 );                                  554     return( 0 );
553 }                                                 555 }
554 /*                                                556 /*
555 **********************************************    557 ************************************************************
556 */                                                558 */
557 int xDataXML_xDataTypeConvertAttributes( statu    559 int xDataXML_xDataTypeConvertAttributes( statusMessageReporting *smr, xDataXML_element *element ) {
558                                                   560 
559     xDataXMLType *xDT = &(element->xDataTypeIn    561     xDataXMLType *xDT = &(element->xDataTypeInfo);
560     void *smrUser = xDataXML_get_smrUserInterf    562     void *smrUser = xDataXML_get_smrUserInterfaceFromElement( element );
561                                                   563 
562     xDT->index = -1;                              564     xDT->index = -1;
563     xDT->start = -1;                              565     xDT->start = -1;
564     xDT->end = -1;                                566     xDT->end = -1;
565     xDT->length = -1;                             567     xDT->length = -1;
566     if( ( xDT->indexPresent = xDataXML_convert    568     if( ( xDT->indexPresent = xDataXML_convertAttributeTo_xDataTOM_Int( smr, element, "index", &(xDT->index), 0 ) ) < 0 ) return( 1 );
567     if( ( xDT->startPresent = xDataXML_convert    569     if( ( xDT->startPresent = xDataXML_convertAttributeTo_xDataTOM_Int( smr, element, "start", &(xDT->start), 0 ) ) < 0 ) return( 1 );
568     if( ( xDT->endPresent = xDataXML_convertAt    570     if( ( xDT->endPresent = xDataXML_convertAttributeTo_xDataTOM_Int( smr, element, "end", &(xDT->end), 0 ) ) < 0 ) return( 1 );
569     if( ( xDT->lengthPresent = xDataXML_conver    571     if( ( xDT->lengthPresent = xDataXML_convertAttributeTo_xDataTOM_Int( smr, element, "length", &(xDT->length), 0 ) ) < 0 ) return( 1 );
570     if( ( xDT->endPresent > 0 ) ) {               572     if( ( xDT->endPresent > 0 ) ) {
571         if( xDT->lengthPresent > 0 ) {            573         if( xDT->lengthPresent > 0 ) {
572             smr_setReportError3p( smr, smrUser    574             smr_setReportError3p( smr, smrUser, xDataTOM_smrLibraryID, 1, "missing length (or end) in xData" );
573             return( 1 );                          575             return( 1 );
574         }                                         576         }
575         xDT->end = xDT->length; }                 577         xDT->end = xDT->length; }
576     else {                                        578     else {
577         if( xDT->lengthPresent > 0 ) xDT->leng    579         if( xDT->lengthPresent > 0 ) xDT->length = xDT->end;
578     }                                             580     }
579                                                   581 
580     if( xDT->startPresent > 0 ) xDT->start = 0    582     if( xDT->startPresent > 0 ) xDT->start = 0;
581     if( xDT->start < 0 ) {                        583     if( xDT->start < 0 ) {
582         smr_setReportError3( smr, smrUser, xDa    584         smr_setReportError3( smr, smrUser, xDataTOM_smrLibraryID, 1, "start = %d < 0", xDT->start );
583         return( 1 );                              585         return( 1 );
584     }                                             586     }
585     if( xDT->end < xDT->start ) {                 587     if( xDT->end < xDT->start ) {
586         smr_setReportError3( smr, smrUser, xDa    588         smr_setReportError3( smr, smrUser, xDataTOM_smrLibraryID, 1, "start = %d >= end = %d", xDT->start, xDT->end );
587         return( 1 );                              589         return( 1 );
588     }                                             590     }
589     if( xDT->length < 0 ) {                       591     if( xDT->length < 0 ) {
590         smr_setReportError3( smr, smrUser, xDa    592         smr_setReportError3( smr, smrUser, xDataTOM_smrLibraryID, 1, "length = %d < 0", xDT->length );
591         return( 1 );                              593         return( 1 );
592     }                                             594     }
593                                                   595 
594     return( 0 );                                  596     return( 0 );
595 }                                                 597 }
596 /*                                                598 /*
597 **********************************************    599 ************************************************************
598 */                                                600 */
599 xDataTOM_Int xDataXML_convertAttributeTo_xData    601 xDataTOM_Int xDataXML_convertAttributeTo_xDataTOM_Int( statusMessageReporting *smr, xDataXML_element *element, char const *name, xDataTOM_Int *n, int required ) {
600 /*                                                602 /*
601 *   Returns 1 if no such attribute, -1 if erro    603 *   Returns 1 if no such attribute, -1 if error converting to xDataTOM_Int and 0 if successful.
602 */                                                604 */
603     char const *value;                            605     char const *value;
604     char *e;                                      606     char *e;
605                                                   607 
606     if( ( value = xDataXML_getAttributesValueI    608     if( ( value = xDataXML_getAttributesValueInElement( element, name ) ) == NULL ) {
607         if( required ) smr_setReportError3( sm    609         if( required ) smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( element ), xDataTOM_smrLibraryID, 1,
608             "missing required attribute '%s'",    610             "missing required attribute '%s'", name );
609         return( 1 );                              611         return( 1 );
610     }                                             612     }
611     *n = (xDataTOM_Int) strtoll( value, &e, 10    613     *n = (xDataTOM_Int) strtoll( value, &e, 10 );
612     if( *e != 0 ) {                               614     if( *e != 0 ) {
613         smr_setReportError3( smr, xDataXML_get    615         smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( element ), xDataTOM_smrLibraryID, 1, 
614             "could not convert attribute %s's     616             "could not convert attribute %s's value = %s to an integer", name, value );
615         return( -1 );                             617         return( -1 );
616     }                                             618     }
617     return( 0 );                                  619     return( 0 );
618 }                                                 620 }
619 /*                                                621 /*
620 **********************************************    622 ************************************************************
621 */                                                623 */
622 int xDataXML_convertAttributeToDouble( statusM    624 int xDataXML_convertAttributeToDouble( statusMessageReporting *smr, xDataXML_element *element, char const *name, double *d, int required ) {
623 /*                                                625 /*
624 *   Returns 1 if no such attribute, -1 if erro    626 *   Returns 1 if no such attribute, -1 if error converting to double and 0 if successful.
625 */                                                627 */
626     char const *value;                            628     char const *value;
627     char *e;                                      629     char *e;
628                                                   630 
629     if( ( value = xDataXML_getAttributesValueI    631     if( ( value = xDataXML_getAttributesValueInElement( element, name ) ) == NULL ) {
630         if( required ) smr_setReportError3( sm    632         if( required ) smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( element ), xDataTOM_smrLibraryID, 1,
631             "missing required attribute '%s'",    633             "missing required attribute '%s'", name );
632         return( 1 );                              634         return( 1 );
633     }                                             635     }
634     *d = strtod( value, &e );                     636     *d = strtod( value, &e );
635     if( *e != 0 ) {                               637     if( *e != 0 ) {
636         smr_setReportError3( smr, xDataXML_get    638         smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( element) , xDataTOM_smrLibraryID, 1, 
637             "could not convert attribute %s's     639             "could not convert attribute %s's values = %s to a double", name, value );
638         return( -1 );                             640         return( -1 );
639     }                                             641     }
640     return( 0 );                                  642     return( 0 );
641 }                                                 643 }
642 /*                                                644 /*
643 **********************************************    645 ************************************************************
644 */                                                646 */
645 int xDataXML_numberOfElementsByTagName( status    647 int xDataXML_numberOfElementsByTagName( statusMessageReporting * /*smr*/, xDataXML_element *element, char const *tagName ) {
646                                                   648 
647     int n = 0;                                    649     int n = 0;
648     xDataXML_element *child;                      650     xDataXML_element *child;
649                                                   651 
650     for( child = xDataXML_getFirstElement( ele    652     for( child = xDataXML_getFirstElement( element ); child != NULL; child = xDataXML_getNextElement( child ) ) if( !strcmp( child->name, tagName ) ) n++;
651     return( n );                                  653     return( n );
652 }                                                 654 }
653 /*                                                655 /*
654 **********************************************    656 ************************************************************
655 */                                                657 */
656 xDataXML_elementList *xDataXML_getElementsByTa    658 xDataXML_elementList *xDataXML_getElementsByTagName( statusMessageReporting *smr, xDataXML_element *element, char const *tagName ) {
657                                                   659 
658     int n = xDataXML_numberOfElementsByTagName    660     int n = xDataXML_numberOfElementsByTagName( smr, element, tagName );
659     size_t size;                                  661     size_t size;
660     xDataXML_element *child;                      662     xDataXML_element *child;
661     xDataXML_elementListItem *p;                  663     xDataXML_elementListItem *p;
662     xDataXML_elementList *list = NULL;            664     xDataXML_elementList *list = NULL;
663                                                   665 
664                                                   666 
665     size = sizeof( xDataXML_elementList ) + n     667     size = sizeof( xDataXML_elementList ) + n * sizeof( xDataXML_elementListItem );
666     if( ( list = (xDataXML_elementList *) smr_    668     if( ( list = (xDataXML_elementList *) smr_malloc2( smr, size, 0, "list" ) ) != NULL ) {
667         list->n = n;                              669         list->n = n;
668         p = list->items = (xDataXML_elementLis    670         p = list->items = (xDataXML_elementListItem *) &(list[1]);
669         for( child = xDataXML_getFirstElement(    671         for( child = xDataXML_getFirstElement( element ); child != NULL; child = xDataXML_getNextElement( child ) ) {
670             if( !strcmp( child->name, tagName     672             if( !strcmp( child->name, tagName ) ) {
671                 p->element = child;               673                 p->element = child;
672                 p->sortString = NULL;             674                 p->sortString = NULL;
673                 p++;                              675                 p++;
674             }                                     676             }
675         }                                         677         }
676     }                                             678     }
677     return( list );                               679     return( list );
678 }                                                 680 }
679 /*                                                681 /*
680 **********************************************    682 ************************************************************
681 */                                                683 */
682 xDataXML_element *xDataXML_getOneElementByTagN    684 xDataXML_element *xDataXML_getOneElementByTagName( statusMessageReporting *smr, xDataXML_element *element, char *name, int required ) {
683                                                   685 
684     xDataXML_elementList *list;                   686     xDataXML_elementList *list;
685     xDataXML_element *xData = NULL;               687     xDataXML_element *xData = NULL;
686                                                   688 
687     if( ( list = xDataXML_getElementsByTagName    689     if( ( list = xDataXML_getElementsByTagName( smr, element, name ) ) != NULL ) {
688         if( list->n == 0 ) {                      690         if( list->n == 0 ) {
689             if( required ) smr_setReportError3    691             if( required ) smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( element ), xDataTOM_smrLibraryID, 
690                 1, "element %s does not have s    692                 1, "element %s does not have sub-element named %s", element->fullName, name ); }
691         else if( list->n > 1 ) {                  693         else if( list->n > 1 ) {
692             smr_setReportError3( smr, xDataXML    694             smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( element ), xDataTOM_smrLibraryID, 1, 
693                 "element %s contains more than    695                 "element %s contains more than one sub-element named %s", element->fullName, name ); }
694         else {                                    696         else {
695             xData = list->items[0].element;       697             xData = list->items[0].element;
696         }                                         698         }
697         xDataXML_freeElementList( smr, list );    699         xDataXML_freeElementList( smr, list );
698     }                                             700     }
699     return( xData );                              701     return( xData );
700 }                                                 702 }
701 /*                                                703 /*
702 **********************************************    704 ************************************************************
703 */                                                705 */
704 void xDataXML_freeElementList( statusMessageRe    706 void xDataXML_freeElementList( statusMessageReporting * /*smr*/, xDataXML_elementList *list ) {
705                                                   707 
706     smr_freeMemory( (void **) &list );            708     smr_freeMemory( (void **) &list );
707 }                                                 709 }
708 /*                                                710 /*
709 **********************************************    711 ************************************************************
710 */                                                712 */
711 static char *xDataXML_getTraceback( statusMess    713 static char *xDataXML_getTraceback( statusMessageReporting *smr, xDataXML_element *element ) {
712 /*                                                714 /*
713 *   Returned string must be freed by calling r    715 *   Returned string must be freed by calling routine.
714 */                                                716 */
715     int size;                                     717     int size;
716     char *s, *name;                               718     char *s, *name;
717                                                   719 
718     name = element->name;                         720     name = element->name;
719     size = (int) strlen( name ) + 1;              721     size = (int) strlen( name ) + 1;
720     if( ( s = xDataXML_getTraceback2( smr, ele    722     if( ( s = xDataXML_getTraceback2( smr, element->parentRoot, size ) ) != NULL ) {
721         strcat( s, "/" );                         723         strcat( s, "/" );
722         strcat( s, name );                        724         strcat( s, name );
723     }                                             725     }
724     return( s );                                  726     return( s );
725 }                                                 727 }
726 /*                                                728 /*
727 **********************************************    729 ************************************************************
728 */                                                730 */
729 static char *xDataXML_getTraceback2( statusMes    731 static char *xDataXML_getTraceback2( statusMessageReporting *smr, xDataXML_rootElement *parentRoot, int n ) {
730                                                   732 
731     int size;                                     733     int size;
732     char *s, *name;                               734     char *s, *name;
733                                                   735 
734     if( parentRoot->parentRoot == NULL ) {        736     if( parentRoot->parentRoot == NULL ) {
735         s = (char *) smr_malloc2( smr, n + 1,     737         s = (char *) smr_malloc2( smr, n + 1, 0, "traceback string" );
736         *s = 0; }                                 738         *s = 0; }
737     else {                                        739     else {
738         name = parentRoot->parentElement->name    740         name = parentRoot->parentElement->name;
739         size = (int) strlen( name ) + 1;          741         size = (int) strlen( name ) + 1;
740         n += size;                                742         n += size;
741         if( ( s = xDataXML_getTraceback2( smr,    743         if( ( s = xDataXML_getTraceback2( smr, parentRoot->parentRoot, n ) ) != NULL ) {
742             strcat( s, "/" );                     744             strcat( s, "/" );
743             strcat( s, name );                    745             strcat( s, name );
744         }                                         746         }
745     }                                             747     }
746     return( s );                                  748     return( s );
747 }                                                 749 }
748 /*                                                750 /*
749 **********************************************    751 ************************************************************
750 */                                                752 */
751 int xDataXML_is_xDataType( statusMessageReport    753 int xDataXML_is_xDataType( statusMessageReporting *smr, xDataXMLType *xDT, char const * const ID, int setMsg ) {
752                                                   754 
753     if( xDT->ID == NULL ) {                       755     if( xDT->ID == NULL ) {
754         if( setMsg ) smr_setReportError3( smr,    756         if( setMsg ) smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( xDT->element ), xDataTOM_smrLibraryID, 1, 
755             "element %s not xData object", xDT    757             "element %s not xData object", xDT->element->fullName ); }
756     else if( xDT->ID != ID ) {                    758     else if( xDT->ID != ID ) {
757         if( setMsg ) smr_setReportError3( smr,    759         if( setMsg ) smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( xDT->element ), xDataTOM_smrLibraryID, 1, 
758             "Element %s is not xData object of    760             "Element %s is not xData object of ID %s but %s", xDT->element->fullName, ID, xDT->ID );
759     }                                             761     }
760     return( xDT->ID == ID );                      762     return( xDT->ID == ID );
761 }                                                 763 }
762 /*                                                764 /*
763 **********************************************    765 ************************************************************
764 */                                                766 */
765 char const *xDataXML_getFileName( xDataXML_doc    767 char const *xDataXML_getFileName( xDataXML_document *doc ) {
766                                                   768 
767     return( doc->fileName );                      769     return( doc->fileName );
768 }                                                 770 }
769 /*                                                771 /*
770 **********************************************    772 ************************************************************
771 */                                                773 */
772 char const *xDataXML_getRealFileName( xDataXML    774 char const *xDataXML_getRealFileName( xDataXML_document *doc ) {
773                                                   775 
774     return( doc->realFileName );                  776     return( doc->realFileName );
775 }                                                 777 }
776 /*                                                778 /*
777 **********************************************    779 ************************************************************
778 */                                                780 */
779 static int xDataXML_setFileName( statusMessage    781 static int xDataXML_setFileName( statusMessageReporting *smr, xDataXML_document *doc, char const *fileName ) {
780                                                   782 
781     char realPath[PATH_MAX+1];                    783     char realPath[PATH_MAX+1];
782                                                   784 
783     smr_freeMemory( (void **) &(doc->fileName)    785     smr_freeMemory( (void **) &(doc->fileName) );
784     smr_freeMemory( (void **) &(doc->realFileN    786     smr_freeMemory( (void **) &(doc->realFileName) );
785     if( fileName != NULL ) {                      787     if( fileName != NULL ) {
786         if( ( doc->fileName = smr_allocateCopy    788         if( ( doc->fileName = smr_allocateCopyString2( smr, fileName, "fileName" ) ) == NULL ) return( 1 );
787         if( realpath( fileName, realPath ) !=     789         if( realpath( fileName, realPath ) != NULL ) {
788             if( ( doc->realFileName = smr_allo    790             if( ( doc->realFileName = smr_allocateCopyString2( smr, realPath, "realFileName" ) ) == NULL ) return( 1 );
789         }                                         791         }
790     }                                             792     }
791     return( 0 );                                  793     return( 0 );
792 }                                                 794 }
793 /*                                                795 /*
794 **********************************************    796 ************************************************************
795 */                                                797 */
796 xDataXML_document *xDataXML_getElementsDocumen    798 xDataXML_document *xDataXML_getElementsDocument( xDataXML_element *element ) {
797                                                   799 
798     xDataXML_rootElement* root = element->pare    800     xDataXML_rootElement* root = element->parentRoot;
799                                                   801 
800     while( root->parentRoot != NULL ) root = r    802     while( root->parentRoot != NULL ) root = root->parentRoot; // Loop checking, 11.06.2015, T. Koi
801     return( root->xData_doc );                    803     return( root->xData_doc );
802 }                                                 804 }
803 /*                                                805 /*
804 **********************************************    806 ************************************************************
805 */                                                807 */
806 void *xDataXML_get_smrUserInterfaceFromDocumen    808 void *xDataXML_get_smrUserInterfaceFromDocument( xDataXML_document *doc ) {
807                                                   809 
808     if( doc == NULL ) return( NULL );             810     if( doc == NULL ) return( NULL );
809     return( &(doc->smrUserInterface ) );          811     return( &(doc->smrUserInterface ) );
810 }                                                 812 }
811 /*                                                813 /*
812 **********************************************    814 ************************************************************
813 */                                                815 */
814 void *xDataXML_get_smrUserInterfaceFromElement    816 void *xDataXML_get_smrUserInterfaceFromElement( xDataXML_element *element ) {
815                                                   817 
816     return( xDataXML_get_smrUserInterfaceFromD    818     return( xDataXML_get_smrUserInterfaceFromDocument( xDataXML_getElementsDocument( element ) ) );
817 }                                                 819 }
818 /*                                                820 /*
819 **********************************************    821 ************************************************************
820 */                                                822 */
821 static int xDataXML_smrUserInterfaceInitialize    823 static int xDataXML_smrUserInterfaceInitialize( xDataXML_document *doc ) {
822                                                   824 
823     doc->smrUserInterface.smrUserInterface = x    825     doc->smrUserInterface.smrUserInterface = xDataXML_smrUserInterface;
824     doc->smrUserInterface.doc = doc;              826     doc->smrUserInterface.doc = doc;
825     return( 0 );                                  827     return( 0 );
826 }                                                 828 }
827 /*                                                829 /*
828 **********************************************    830 ************************************************************
829 */                                                831 */
830 static int xDataXML_smrUserInterfaceFree( xDat    832 static int xDataXML_smrUserInterfaceFree( xDataXML_document *doc ) {
831                                                   833 
832     doc->smrUserInterface.smrUserInterface = N    834     doc->smrUserInterface.smrUserInterface = NULL;
833     doc->smrUserInterface.doc = NULL;             835     doc->smrUserInterface.doc = NULL;
834     return( 0 );                                  836     return( 0 );
835 }                                                 837 }
836 /*                                                838 /*
837 **********************************************    839 ************************************************************
838 */                                                840 */
839 static char *xDataXML_smrUserInterface( void *    841 static char *xDataXML_smrUserInterface( void *userData ) {
840                                                   842 
841     xDataXML_smr *smrUserInterface = (xDataXML    843     xDataXML_smr *smrUserInterface = (xDataXML_smr *) userData;
842     xDataXML_rootElement *currentRoot = smrUse    844     xDataXML_rootElement *currentRoot = smrUserInterface->doc->currentRoot;
843                                                   845 
844     if( currentRoot->parentElement != NULL ) {    846     if( currentRoot->parentElement != NULL ) {
845         return( smr_allocateFormatMessage( "\n    847         return( smr_allocateFormatMessage( "\nat line %d and column %d of file %s\nin element %s", currentRoot->parentElement->docInfo.line, 
846             currentRoot->parentElement->docInf    848             currentRoot->parentElement->docInfo.column, smrUserInterface->doc->fileName, currentRoot->parentElement->fullName ) ); }
847     else if( smrUserInterface->doc->fileName !    849     else if( smrUserInterface->doc->fileName != NULL ) {
848         return( smr_allocateFormatMessage( "\n    850         return( smr_allocateFormatMessage( "\nof file %s", smrUserInterface->doc->fileName ) );
849     }                                             851     }
850     return( smr_allocateFormatMessage( "\nat l    852     return( smr_allocateFormatMessage( "\nat line %d and column %d\nin element %s", currentRoot->parentElement->docInfo.line,
851         currentRoot->parentElement->docInfo.co    853         currentRoot->parentElement->docInfo.column, currentRoot->parentElement->fullName ) );
852 }                                                 854 }
853 /*                                                855 /*
854 **********************************************    856 ************************************************************
855 */                                                857 */
856 int xDataXML_stringTo_xDataTOM_Int( statusMess    858 int xDataXML_stringTo_xDataTOM_Int( statusMessageReporting *smr, void *smrUserInterface, char const *c, xDataTOM_Int *value, char const *endings, char **e ) {
857                                                   859 
858     char const *s;                                860     char const *s;
859     char tmp[64];                                 861     char tmp[64];
860     int status = 1, n = sizeof( tmp );            862     int status = 1, n = sizeof( tmp );
861                                                   863 
862     for( s = c; *s != 0; s++ ) if( !isspace( *    864     for( s = c; *s != 0; s++ ) if( !isspace( *s ) ) break;
863     *value = (xDataTOM_Int) strtoll( s, e, 10     865     *value = (xDataTOM_Int) strtoll( s, e, 10 );
864     if( *e == s ) {                               866     if( *e == s ) {
865         smr_setReportError3(smr, smrUserInterf    867         smr_setReportError3(smr, smrUserInterface, xDataTOM_smrLibraryID, 1, "could not convert \"%s\" to an integer", xDataXML_shortStringForMessage( n, tmp, c ));}
866     else {                                        868     else {
867         if( *endings == 0 ) while( isspace( **    869         if( *endings == 0 ) while( isspace( **e ) ) (*e)++; // Loop checking, 11.06.2015, T. Koi
868         if( **e == 0 ) {                          870         if( **e == 0 ) {
869             status = 0; }                         871             status = 0; }
870         else {                                    872         else {
871             if( *endings == 0 ) {                 873             if( *endings == 0 ) {
872                 smr_setReportError3( smr, smrU    874                 smr_setReportError3( smr, smrUserInterface, xDataTOM_smrLibraryID, 1, "integer string \"%s\" does not end with a '\\0'", 
873                     xDataXML_shortStringForMes    875                     xDataXML_shortStringForMessage( n, tmp, c ) ); }
874             else {                                876             else {
875                 if( strchr( endings, **e ) ==     877                 if( strchr( endings, **e ) == NULL ) {
876                     smr_setReportError3( smr,     878                     smr_setReportError3( smr, smrUserInterface, xDataTOM_smrLibraryID, 1, "integer string \"%s\" does not end with a white space or a '\\0\'", 
877                         xDataXML_shortStringFo    879                         xDataXML_shortStringForMessage( n, tmp, c ) ); }
878                 else {                            880                 else {
879                     status = 0;                   881                     status = 0;
880                 }                                 882                 }
881             }                                     883             }
882         }                                         884         }
883     }                                             885     }
884     return( status );                             886     return( status );
885 }                                                 887 }
886 /*                                                888 /*
887 **********************************************    889 ************************************************************
888 */                                                890 */
889 int xDataXML_stringTo_double( statusMessageRep    891 int xDataXML_stringTo_double( statusMessageReporting *smr, void *smrUserInterface, char const *c, double *value, char const *endings, char **e ) {
890                                                   892 
891     char const *s;                                893     char const *s;
892     char tmp[64];                                 894     char tmp[64];
893     int status = 1, n = sizeof( tmp );            895     int status = 1, n = sizeof( tmp );
894                                                   896 
895     for( s = c; *s != 0; s++ ) if( !isspace( *    897     for( s = c; *s != 0; s++ ) if( !isspace( *s ) ) break;
896     *value = strtod( s, e );                      898     *value = strtod( s, e );
897     if( *e == s ) {                               899     if( *e == s ) {
898         smr_setReportError3( smr, smrUserInter    900         smr_setReportError3( smr, smrUserInterface, xDataTOM_smrLibraryID, 1, "could not convert \"%s\" to an double", 
899             xDataXML_shortStringForMessage( n,    901             xDataXML_shortStringForMessage( n, tmp, c ));}
900     else {                                        902     else {
901         if( *endings == 0 ) while( isspace( **    903         if( *endings == 0 ) while( isspace( **e ) ) (*e)++; // Loop checking, 11.06.2015, T. Koi
902         if( **e == 0 ) {                          904         if( **e == 0 ) {
903             status = 0; }                         905             status = 0; }
904         else {                                    906         else {
905             if( *endings == 0 ) {                 907             if( *endings == 0 ) {
906                 smr_setReportError3( smr, smrU    908                 smr_setReportError3( smr, smrUserInterface, xDataTOM_smrLibraryID, 1, "double string \"%s\" does not end with a '\\0'", 
907                     xDataXML_shortStringForMes    909                     xDataXML_shortStringForMessage( n, tmp, c ) ); }
908             else {                                910             else {
909                 if( strchr( endings, **e ) ==     911                 if( strchr( endings, **e ) == NULL ) {
910                     smr_setReportError3( smr,     912                     smr_setReportError3( smr, smrUserInterface, xDataTOM_smrLibraryID, 1, "double string \"%s\" does not end with a white space or a '\\0\'", 
911                         xDataXML_shortStringFo    913                         xDataXML_shortStringForMessage( n, tmp, c ) ); }
912                 else {                            914                 else {
913                     status = 0;                   915                     status = 0;
914                 }                                 916                 }
915             }                                     917             }
916         }                                         918         }
917     }                                             919     }
918     return( status );                             920     return( status );
919 }                                                 921 }
920 /*                                                922 /*
921 **********************************************    923 ************************************************************
922 */                                                924 */
923 int xDataXML_addToAccessed( statusMessageRepor    925 int xDataXML_addToAccessed( statusMessageReporting * /*smr*/, xDataXML_element *element, int increment ) {
924                                                   926 
925     element->accessed += increment;               927     element->accessed += increment;
926     return( element->accessed );                  928     return( element->accessed );
927 }                                                 929 }
928 /*                                                930 /*
929 **********************************************    931 ************************************************************
930 */                                                932 */
931 int xDataXML_getAccessed( statusMessageReporti    933 int xDataXML_getAccessed( statusMessageReporting * /*smr*/, xDataXML_element *element ) {
932                                                   934 
933     return( element->accessed );                  935     return( element->accessed );
934 }                                                 936 }
935 /*                                                937 /*
936 **********************************************    938 ************************************************************
937 */                                                939 */
938 static char const *xDataXML_shortStringForMess    940 static char const *xDataXML_shortStringForMessage( size_t size, char *Out, char const *In ) {
939                                                   941 
940     if( strlen( In ) > size ) {                   942     if( strlen( In ) > size ) {
941         strncpy( Out, In, size - 5 );             943         strncpy( Out, In, size - 5 );
942         Out[size-5] = 0;                          944         Out[size-5] = 0;
943         strcat( Out, " ..." );                    945         strcat( Out, " ..." );
944         return( Out );                            946         return( Out );
945     }                                             947     }
946     return( In );                                 948     return( In );
947 }                                                 949 }
948 /*                                                950 /*
949 **********************************************    951 ************************************************************
950 */                                                952 */
951 static int xDataXML_constructTOM( statusMessag    953 static int xDataXML_constructTOM( statusMessageReporting *smr, xDataTOM_element *TE, xDataXML_element *XE ) {
952                                                   954 
953     int i, status = 0;                            955     int i, status = 0;
954     xDataTOM_element *TOMChild;                   956     xDataTOM_element *TOMChild;
955     xDataXML_element *XMLChild;                   957     xDataXML_element *XMLChild;
956     xDataXML_attribute *attribute;                958     xDataXML_attribute *attribute;
957     char const *xDataValue = xDataXML_getAttri    959     char const *xDataValue = xDataXML_getAttributesValueInElement( XE, "xData" );
958                                                   960 
959     if( !smr_isOk( smr ) ) return( 1 );           961     if( !smr_isOk( smr ) ) return( 1 );
960     if( ( TOMChild = xDataTOM_addElementInElem    962     if( ( TOMChild = xDataTOM_addElementInElement( smr, TE, XE->index, XE->name ) ) == NULL ) return( 1 );
961     for( i = 0; 1; i++ ) {                        963     for( i = 0; 1; i++ ) {
962         if( ( attribute = xDataXML_attributeBy    964         if( ( attribute = xDataXML_attributeByIndex( &(XE->attributes), i ) ) == NULL ) break;
963         if( xDataTOME_addAttribute( smr, TOMCh    965         if( xDataTOME_addAttribute( smr, TOMChild, attribute->name, attribute->value ) != 0 ) return( 1 );
964     }                                             966     }
965                                                   967 
966     if( !strcmp( XE->name, xDataTOM_KalbachMan    968     if( !strcmp( XE->name, xDataTOM_KalbachMann_ID ) ) {
967         xDataValue = xDataTOM_KalbachMann_ID;     969         xDataValue = xDataTOM_KalbachMann_ID;
968     }                                             970     }
969                                                   971 
970     if( xDataValue == NULL ) {                    972     if( xDataValue == NULL ) {
971         for( XMLChild = xDataXML_getFirstEleme    973         for( XMLChild = xDataXML_getFirstElement( XE ); ( status == 0 ) && ( XMLChild != NULL ); XMLChild = xDataXML_getNextElement( XMLChild ) ) {
972             status = xDataXML_constructTOM( sm    974             status = xDataXML_constructTOM( smr, TOMChild, XMLChild );
973         } }                                       975         } }
974     else {                                        976     else {
975         if( strcmp( xDataValue, xDataTOM_XYs_I    977         if( strcmp( xDataValue, xDataTOM_XYs_ID ) == 0 ) {
976             status = xDataXML_XYsToTOM( smr, X    978             status = xDataXML_XYsToTOM( smr, XE, TOMChild ); }
977         else if( strcmp( xDataValue, xDataTOM_    979         else if( strcmp( xDataValue, xDataTOM_regionsXYs_ID ) == 0 ) {
978             status = xDataXML_regionsXYsToTOM(    980             status = xDataXML_regionsXYsToTOM( smr, XE, TOMChild ); }
979         else if( strcmp( xDataValue, xDataTOM_    981         else if( strcmp( xDataValue, xDataTOM_W_XYs_ID ) == 0 ) {
980             status = xDataXML_W_XYsToTOM( smr,    982             status = xDataXML_W_XYsToTOM( smr, XE, TOMChild ); }
981         else if( strcmp( xDataValue, xDataTOM_    983         else if( strcmp( xDataValue, xDataTOM_V_W_XYs_ID ) == 0 ) {
982             status = xDataXML_V_W_XYsToTOM( sm    984             status = xDataXML_V_W_XYsToTOM( smr, XE, TOMChild ); }
983         else if( strcmp( xDataValue, xDataTOM_    985         else if( strcmp( xDataValue, xDataTOM_W_XYs_LegendreSeries_ID ) == 0 ) {
984             status = xDataXML_W_XYs_LegendreSe    986             status = xDataXML_W_XYs_LegendreSeriesToTOM( smr, XE, TOMChild ); }
985         else if( strcmp( xDataValue, xDataTOM_    987         else if( strcmp( xDataValue, xDataTOM_regionsW_XYs_LegendreSeries_ID ) == 0 ) {
986             status = xDataXML_regionsW_XYs_Leg    988             status = xDataXML_regionsW_XYs_LegendreSeriesToTOM( smr, XE, TOMChild ); }
987         else if( strcmp( xDataValue, xDataTOM_    989         else if( strcmp( xDataValue, xDataTOM_V_W_XYs_LegendreSeries_ID ) == 0 ) {
988             status = xDataXML_V_W_XYs_Legendre    990             status = xDataXML_V_W_XYs_LegendreSeriesToTOM( smr, XE, TOMChild ); }
989         else if( strcmp( xDataValue, xDataTOM_    991         else if( strcmp( xDataValue, xDataTOM_KalbachMann_ID ) == 0 ) {
990             status = xDataXML_KalbachMannToTOM    992             status = xDataXML_KalbachMannToTOM( smr, XE, TOMChild ); }
991         else if( strcmp( xDataValue, xDataTOM_    993         else if( strcmp( xDataValue, xDataTOM_polynomial_ID ) == 0 ) {
992             status = xDataXML_polynomialToTOM(    994             status = xDataXML_polynomialToTOM( smr, XE, TOMChild ); }
993         else {                                    995         else {
994             printf( "Unsupported xData type '%    996             printf( "Unsupported xData type '%s' in element '%s'\n", xDataValue, XE->name );
995 #if 0                                             997 #if 0
996             smr_setReportError3( smr, xDataXML    998             smr_setReportError3( smr, xDataXML_get_smrUserInterfaceFromElement( XE ), xDataTOM_smrLibraryID, -1, 
997                 "Unsupported xData type = \"%s    999                 "Unsupported xData type = \"%s\"", xDataValue );
998             status = 1;                           1000             status = 1;
999 #endif                                            1001 #endif
1000         }                                        1002         }
1001     }                                            1003     }
1002     return( status );                            1004     return( status );
1003 }                                                1005 }
1004 /*                                               1006 /*
1005 *********************************************    1007 ************************************************************
1006 */                                               1008 */
1007 void *xDataXML_initializeData( statusMessageR    1009 void *xDataXML_initializeData( statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE, char const *ID, size_t size ) {
1008                                                  1010 
1009     xDataTOM_xDataInfo *xDI = &(TE->xDataInfo    1011     xDataTOM_xDataInfo *xDI = &(TE->xDataInfo);
1010                                                  1012 
1011     if( xData_initializeData( smr, TE, ID, si    1013     if( xData_initializeData( smr, TE, ID, size ) == NULL ) return( NULL );
1012     if( xDataXML_axesElememtToTOM( smr, XE, &    1014     if( xDataXML_axesElememtToTOM( smr, XE, &(xDI->axes) ) != 0 ) smr_freeMemory( (void **) &(xDI->data) );
1013     return( xDI->data );                         1015     return( xDI->data );
1014 }                                                1016 }
1015                                                  1017 
1016 #if defined __cplusplus                          1018 #if defined __cplusplus
1017 }                                                1019 }
1018 #endif                                           1020 #endif
1019                                                  1021