14#if defined(WIN32) || defined(__MINGW32__)
18#define realpath( a, b ) GetFullPathName( a, PATH_MAX, b, NULL )
19#define strtoll _strtoi64
20typedef SSIZE_T ssize_t;
27#if defined __cplusplus
42static void XMLCALL xDataXML_parseStartElement(
void *userData,
char const *name,
char const **attris );
43static void XMLCALL xDataXML_parseEndElement(
void *userData,
char const *name );
44static void XMLCALL xDataXML_parseCharacterData(
void *userData,
XML_Char const *s,
int len );
56static char *xDataXML_smrUserInterface(
void *userData );
57static char const *xDataXML_shortStringForMessage(
size_t size,
char *Out,
char const *In );
77 if( xDataXML_constructTOM( smr, (&TOM->
root), element ) != 0 )
goto Err;
95 char buffer[10 * 1000];
96 ssize_t count, n =
sizeof( buffer ) - 1;
99 if( ( doc = xDataXML_mallocDoc( smr ) ) == NULL )
return( NULL );
100 if( xDataXML_setFileName( smr, doc, fileName ) == 0 ) {
101 f = open( fileName, O_RDONLY );
103 xDataXML_endXMLParsing( smr, doc );
106 while( ( count = read( f, buffer, n ) ) > 0 ) {
108 if( xDataXML_parse( doc, buffer ) )
break;
112 xDataXML_endXMLParsing( smr, doc );
149 xDataXML_smrUserInterfaceInitialize( doc );
155 xDataXML_initializeRootElement( doc, &(doc->
root), NULL, 0 );
174 "status = %d\nXML_Error code = %d\nXML_ErrorString = %s\nerror line, column = %d, %d",
xDataXML_errXMLParser,
188 xDataXML_endXMLParsing( smr, doc );
192 xDataXML_smrUserInterfaceFree( doc );
203 for( ; element != NULL; element = next ) {
204 next = element->
next;
205 xDataXML_freeElementItems( smr, element );
235static void XMLCALL xDataXML_parseStartElement(
void *userData,
char const *name,
char const **attris ) {
240 xDataXML_addElementToRoot( doc->
smr, doc->
currentRoot, name, attris );
245static void XMLCALL xDataXML_parseEndElement(
void *userData,
char const * ) {
255static void XMLCALL xDataXML_parseCharacterData(
void *userData,
XML_Char const *s,
int len ) {
261 size_t needSize = text->
length + len + 1, l;
265 if( needSize < 8 ) needSize = 8;
269 if( l < 100 ) l = 100;
277 strncpy( p, s, len );
300 xDataXML_parseGetCurrentPosition( doc, &(text->
docInfo) );
313 int i,
n, status = 1;
316 char const **pAttris;
321 if( element == NULL )
return( 1 );
322 xDataXML_parseGetCurrentPosition( doc, &(element->
docInfo) );
327 xDataXML_initializeRootElement( doc, &(element->
childrenRoot), element, parentRoot->
depth + 1 );
328 element->
next = NULL;
329 if( ( element->
name = (
char *)
smr_malloc2( doc->
smr, strlen( name ) + 1, 0,
"name" ) ) == NULL ) {
333 strcpy( element->
name, name );
334 if( ( element->
fullName = xDataXML_getTraceback( smr, element ) ) == NULL ) {
339 for( i = 0, lens = 0, pAttris = attris; *pAttris; i++, pAttris++ ) lens += strlen( *pAttris ) + 1;
351 for( i = 0, pAttris = attris; ( i <
n ) && status; i++, a++, pAttris++ ) {
352 lens = strlen( *pAttris ) + 1;
354 strcpy( p, *pAttris );
357 lens = strlen( *pAttris ) + 1;
359 strcpy( p, *pAttris );
361 if( !strcmp(
"index", a->name ) ) {
362 element->
index = (int) strtoll( a->value, &e, 10 );
378 xDataXML_init_xDataTypeNone( &(element->
xDataTypeInfo), element );
380 xDataXML_parseInitializeText( doc, &(element->
text) );
432 return( item->
mode );
460 return( item->
mode );
469 for( i = 0; i < attributes->
number; i++ ) {
470 if( !strcmp( attributes->
attributes[i].
name, name ) )
return( 1 );
488 for( i = 0; i < attributes->
number; i++ ) {
505 return( attributes->
number );
512 if( index >= attributes->
number )
return( NULL );
545 "element %s is not xData", element->
fullName );
581 if( xDT->
start < 0 ) {
608 "missing required attribute '%s'", name );
614 "could not convert attribute %s's value = %s to an integer", name, value );
631 "missing required attribute '%s'", name );
634 *d = strtod( value, &e );
637 "could not convert attribute %s's values = %s to a double", name, value );
670 if( !strcmp( child->
name, tagName ) ) {
690 1,
"element %s does not have sub-element named %s", element->
fullName, name ); }
691 else if( list->
n > 1 ) {
693 "element %s contains more than one sub-element named %s", element->
fullName, name ); }
719 size = (int) strlen( name ) + 1;
720 if( ( s = xDataXML_getTraceback2( smr, element->
parentRoot, size ) ) != NULL ) {
735 s = (
char *)
smr_malloc2( smr, n + 1, 0,
"traceback string" );
739 size = (int) strlen( name ) + 1;
741 if( ( s = xDataXML_getTraceback2( smr, parentRoot->
parentRoot, n ) ) != NULL ) {
753 if( xDT->
ID == NULL ) {
756 else if( xDT->
ID != ID ) {
758 "Element %s is not xData object of ID %s but %s", xDT->
element->
fullName, ID, xDT->
ID );
760 return( xDT->
ID == ID );
785 if( fileName != NULL ) {
787 if( realpath( fileName, realPath ) != NULL ) {
808 if( doc == NULL )
return( NULL );
839static char *xDataXML_smrUserInterface(
void *userData ) {
847 else if( smrUserInterface->
doc->
fileName != NULL ) {
860 int status = 1, n =
sizeof( tmp );
862 for( s = c; *s != 0; s++ )
if( !isspace( *s ) )
break;
867 if( *endings == 0 )
while( isspace( **e ) ) (*e)++;
871 if( *endings == 0 ) {
873 xDataXML_shortStringForMessage( n, tmp, c ) ); }
875 if( strchr( endings, **e ) == NULL ) {
877 xDataXML_shortStringForMessage( n, tmp, c ) ); }
893 int status = 1, n =
sizeof( tmp );
895 for( s = c; *s != 0; s++ )
if( !isspace( *s ) )
break;
896 *value = strtod( s, e );
899 xDataXML_shortStringForMessage( n, tmp, c ));}
901 if( *endings == 0 )
while( isspace( **e ) ) (*e)++;
905 if( *endings == 0 ) {
907 xDataXML_shortStringForMessage( n, tmp, c ) ); }
909 if( strchr( endings, **e ) == NULL ) {
911 xDataXML_shortStringForMessage( n, tmp, c ) ); }
938static char const *xDataXML_shortStringForMessage(
size_t size,
char *Out,
char const *In ) {
940 if( strlen( In ) > size ) {
941 strncpy( Out, In, size - 5 );
943 strcat( Out,
" ..." );
961 for( i = 0; 1; i++ ) {
970 if( xDataValue == NULL ) {
972 status = xDataXML_constructTOM( smr, TOMChild, XMLChild );
994 printf(
"Unsupported xData type '%s' in element '%s'\n", xDataValue, XE->
name );
997 "Unsupported xData type = \"%s\"", xDataValue );
1013 return( xDI->
data );
1016#if defined __cplusplus
XML_ParserCreate(const XML_Char *encoding)
XML_GetErrorCode(XML_Parser parser)
XML_SetUserData(XML_Parser parser, void *userData)
XML_ParserFree(XML_Parser parser)
XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end)
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
XML_ErrorString(enum XML_Error code)
XML_SetCharacterDataHandler(XML_Parser parser, XML_CharacterDataHandler handler)
const char * name(G4int ptype)
#define smr_setReportError2(smr, libraryID, code, fmt,...)
#define smr_setReportError2p(smr, libraryID, code, fmt)
#define smr_setReportError3(smr, userInterface, libraryID, code, fmt,...)
#define smr_realloc2(smr, old, size, forItem)
#define smr_allocateCopyString2(smr, s, forItem)
void * smr_freeMemory(void **p)
#define smr_setReportError3p(smr, userInterface, libraryID, code, fmt)
int smr_isOk(statusMessageReporting *smr)
char * smr_allocateFormatMessage(char const *fmt,...)
#define smr_malloc2(smr, size, zero, forItem)
xDataTOM_xDataInfo xDataInfo
xDTXML_releaseFunction release
enum xDataXML_xDataType status
xDTXML_toDataFunction toData
xDataXML_element * element
xDTXML_toStringFunction toString
xDataXML_attribute * attributes
xDataXML_rootElement root
statusMessageReporting * smr
xDataXML_rootElement * currentRoot
xDataXML_smr smrUserInterface
enum xDataXML_status status
enum xDataXML_errorCodes error
xDataXML_element * element
xDataXML_elementListItem * items
xDataXMLType xDataTypeInfo
xDataXML_rootElement childrenRoot
xDataXML_attributionList attributes
xDataXML_rootElement * parentRoot
xDataXML_element * element
enum xDataXML_itemMode mode
xDataXML_element * parentElement
xDataXML_element * currentChild
xDataXML_rootElement * parentRoot
xDataXML_element * parentElement
xDataXML_element * children
xDataXML_document * xData_doc
smr_userInterface smrUserInterface
xDataTOM_TOM * xDataTOM_mallocTOM(statusMessageReporting *smr)
int xDataTOME_addAttribute(statusMessageReporting *smr, xDataTOM_element *element, char const *name, char const *value)
xDataTOM_element * xDataTOM_addElementInElement(statusMessageReporting *smr, xDataTOM_element *parent, int index, char const *name)
int xDataTOM_setFileNameTOM(statusMessageReporting *smr, xDataTOM_TOM *doc, const char *fileName)
void * xData_initializeData(statusMessageReporting *smr, xDataTOM_element *TE, char const *ID, size_t size)
void * xDataTOM_freeTOM(statusMessageReporting *smr, xDataTOM_TOM **TOM)
char const * xDataXML_getFileName(xDataXML_document *doc)
enum xDataXML_itemMode xDataXML_getNextItem(xDataXML_item *item)
void * xDataXML_initializeData(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE, char const *ID, size_t size)
int xDataXML_KalbachMannToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
int xDataXML_regionsW_XYs_LegendreSeriesToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
int xDataXML_getAccessed(statusMessageReporting *smr, xDataXML_element *element)
int xDataXML_polynomialToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
xDataXML_elementList * xDataXML_getElementsByTagName(statusMessageReporting *smr, xDataXML_element *element, char const *tagName)
int xDataXML_W_XYs_LegendreSeriesToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
void * xDataXML_freeDoc(statusMessageReporting *smr, xDataXML_document *doc)
void xDataXML_freeElementList(statusMessageReporting *smr, xDataXML_elementList *list)
int xDataXML_is_xDataType(statusMessageReporting *smr, xDataXMLType *xDT, char const *const type, int setMsg)
int xDataXML_stringTo_double(statusMessageReporting *smr, void *smrUserInterface, char const *c, double *value, char const *endings, char **e)
int xDataXML_XYsToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
int xDataXML_V_W_XYs_LegendreSeriesToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
@ xDataXML_statusCompleted
void * xDataXML_get_smrUserInterfaceFromElement(xDataXML_element *element)
struct xDataXML_elementList_s xDataXML_elementList
xDataXML_element * xDataXML_getNextElement(xDataXML_element *element)
char * xDataXML_getAttributesValue(xDataXML_attributionList *attributes, char const *name)
int xDataXML_W_XYsToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
int xDataXML_addToAccessed(statusMessageReporting *smr, xDataXML_element *element, int increment)
@ xDataXML_errXML_ParserCreate
int xDataXML_attributeListLength(xDataXML_attributionList *attributes)
int xDataXML_parseIsError(xDataXML_document *doc)
xDataTOM_Int xDataXML_convertAttributeTo_xDataTOM_Int(statusMessageReporting *smr, xDataXML_element *element, char const *name, xDataTOM_Int *n, int required)
xDataTOM_TOM * xDataXML_importFile(statusMessageReporting *smr, char const *fileName)
xDataXML_element * xDataXML_getDocumentsElement(xDataXML_document *doc)
char const * xDataXML_getRealFileName(xDataXML_document *doc)
struct xDataXML_attribute_s xDataXML_attribute
int xDataXML_getCommonData(statusMessageReporting *smr, xDataXML_element *element, xDataTOM_Int *index, xDataTOM_Int *start, xDataTOM_Int *end, xDataTOM_Int *length)
char const * xDataXML_getAttributesValueInElement(xDataXML_element *element, char const *name)
int xDataXML_stringTo_xDataTOM_Int(statusMessageReporting *smr, void *smrUserInterface, char const *c, xDataTOM_Int *value, char const *endings, char **e)
xDataXML_element * xDataXML_getFirstElement(xDataXML_element *element)
xDataXML_document * xDataXML_getElementsDocument(xDataXML_element *element)
int xDataXML_isAttributeInElement(xDataXML_element *element, char const *name)
int xDataXML_xDataTypeConvertAttributes(statusMessageReporting *smr, xDataXML_element *element)
xDataXML_element * xDataXML_getOneElementByTagName(statusMessageReporting *smr, xDataXML_element *element, char *name, int required)
int xDataXML_regionsXYsToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
int xDataXML_axesElememtToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_axes *axes)
@ xDataXML_itemModeElement
void * xDataXML_get_smrUserInterfaceFromDocument(xDataXML_document *doc)
int xDataXML_numberOfElementsByTagName(statusMessageReporting *smr, xDataXML_element *element, char const *tagName)
int xDataXML_convertAttributeToDouble(statusMessageReporting *smr, xDataXML_element *element, char const *name, double *d, int required)
enum xDataXML_itemMode xDataXML_getFirstItem(xDataXML_element *element, xDataXML_item *item)
xDataXML_attribute * xDataXML_attributeByIndex(xDataXML_attributionList *attributes, int index)
int xDataXML_V_W_XYsToTOM(statusMessageReporting *smr, xDataXML_element *XE, xDataTOM_element *TE)
int xDataXML_isAttributeInList(xDataXML_attributionList *attributes, char const *name)
xDataXML_document * xDataXML_importFile2(statusMessageReporting *smr, char const *fileName)
char const * xDataTOM_KalbachMann_ID
char const * xDataTOM_V_W_XYs_ID
char const * xDataTOM_regionsW_XYs_LegendreSeries_ID
char const * xDataTOM_polynomial_ID
char const * xDataTOM_W_XYs_ID
char const * xDataTOM_regionsXYs_ID
char const * xDataTOM_W_XYs_LegendreSeries_ID
char const * xDataTOM_XYs_ID
char const * xDataTOM_V_W_XYs_LegendreSeries_ID
int xDataTOM_smrLibraryID
XML_Size XMLCALL XML_GetCurrentColumnNumber(XML_Parser parser)
XML_Size XMLCALL XML_GetCurrentLineNumber(XML_Parser parser)