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 );
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;
96 ssize_t count, n =
sizeof(
buffer ) - 1;
100 if( ( doc = xDataXML_mallocDoc( smr ) ) == NULL )
return( NULL );
101 if( xDataXML_setFileName( smr, doc, fileName ) == 0 ) {
102 f = open( fileName, O_RDONLY );
104 xDataXML_endXMLParsing( smr, doc );
107 while( ( count = read( f,
buffer, n ) ) > 0 ) {
110 if( xDataXML_parse( doc,
buffer ) )
break;
114 xDataXML_endXMLParsing( smr, doc );
151 xDataXML_smrUserInterfaceInitialize( doc );
157 xDataXML_initializeRootElement( doc, &(doc->
root), NULL, 0 );
176 "status = %d\nXML_Error code = %d\nXML_ErrorString = %s\nerror line, column = %d, %d",
xDataXML_errXMLParser,
190 xDataXML_endXMLParsing( smr, doc );
194 xDataXML_smrUserInterfaceFree( doc );
205 for( ; element != NULL; element = next ) {
206 next = element->
next;
207 xDataXML_freeElementItems( smr, element );
237static void XMLCALL xDataXML_parseStartElement(
void *
userData,
char const *name,
char const **attris ) {
242 xDataXML_addElementToRoot( doc->
smr, doc->
currentRoot, name, attris );
247static void XMLCALL xDataXML_parseEndElement(
void *
userData,
char const * ) {
263 size_t needSize = text->
length + len + 1, l;
267 if( needSize < 8 ) needSize = 8;
271 if( l < 100 ) l = 100;
279 strncpy( p, s, len );
302 xDataXML_parseGetCurrentPosition( doc, &(text->
docInfo) );
315 int i,
n, status = 1;
318 char const **pAttris;
323 if( element == NULL )
return( 1 );
324 xDataXML_parseGetCurrentPosition( doc, &(element->
docInfo) );
329 xDataXML_initializeRootElement( doc, &(element->
childrenRoot), element, parentRoot->
depth + 1 );
330 element->
next = NULL;
331 if( ( element->
name = (
char *)
smr_malloc2( doc->
smr, strlen( name ) + 1, 0,
"name" ) ) == NULL ) {
335 strcpy( element->
name, name );
336 if( ( element->
fullName = xDataXML_getTraceback( smr, element ) ) == NULL ) {
341 for( i = 0, lens = 0, pAttris = attris; *pAttris; i++, pAttris++ ) lens += strlen( *pAttris ) + 1;
353 for( i = 0, pAttris = attris; ( i <
n ) && status; i++, a++, pAttris++ ) {
354 lens = strlen( *pAttris ) + 1;
356 strcpy( p, *pAttris );
359 lens = strlen( *pAttris ) + 1;
361 strcpy( p, *pAttris );
363 if( !strcmp(
"index", a->name ) ) {
364 element->
index = (int) strtoll( a->value, &e, 10 );
380 xDataXML_init_xDataTypeNone( &(element->
xDataTypeInfo), element );
382 xDataXML_parseInitializeText( doc, &(element->
text) );
434 return( item->
mode );
462 return( item->
mode );
471 for( i = 0; i < attributes->
number; i++ ) {
472 if( !strcmp( attributes->
attributes[i].
name, name ) )
return( 1 );
490 for( i = 0; i < attributes->
number; i++ ) {
507 return( attributes->
number );
514 if( index >= attributes->
number )
return( NULL );
547 "element %s is not xData", element->
fullName );
583 if( xDT->
start < 0 ) {
610 "missing required attribute '%s'", name );
616 "could not convert attribute %s's value = %s to an integer", name, value );
633 "missing required attribute '%s'", name );
636 *d = strtod( value, &e );
639 "could not convert attribute %s's values = %s to a double", name, value );
672 if( !strcmp( child->
name, tagName ) ) {
692 1,
"element %s does not have sub-element named %s", element->
fullName, name ); }
693 else if( list->
n > 1 ) {
695 "element %s contains more than one sub-element named %s", element->
fullName, name ); }
721 size = (int) strlen( name ) + 1;
722 if( ( s = xDataXML_getTraceback2( smr, element->
parentRoot, size ) ) != NULL ) {
737 s = (
char *)
smr_malloc2( smr, n + 1, 0,
"traceback string" );
741 size = (int) strlen( name ) + 1;
743 if( ( s = xDataXML_getTraceback2( smr, parentRoot->
parentRoot, n ) ) != NULL ) {
755 if( xDT->
ID == NULL ) {
758 else if( xDT->
ID != ID ) {
760 "Element %s is not xData object of ID %s but %s", xDT->
element->
fullName, ID, xDT->
ID );
762 return( xDT->
ID == ID );
787 if( fileName != NULL ) {
789 if( realpath( fileName, realPath ) != NULL ) {
810 if( doc == NULL )
return( NULL );
841static char *xDataXML_smrUserInterface(
void *
userData ) {
849 else if( smrUserInterface->
doc->
fileName != NULL ) {
862 int status = 1, n =
sizeof( tmp );
864 for( s = c; *s != 0; s++ )
if( !isspace( *s ) )
break;
869 if( *endings == 0 )
while( isspace( **e ) ) (*e)++;
873 if( *endings == 0 ) {
875 xDataXML_shortStringForMessage( n, tmp, c ) ); }
877 if( strchr( endings, **e ) == NULL ) {
879 xDataXML_shortStringForMessage( n, tmp, c ) ); }
895 int status = 1, n =
sizeof( tmp );
897 for( s = c; *s != 0; s++ )
if( !isspace( *s ) )
break;
898 *value = strtod( s, e );
901 xDataXML_shortStringForMessage( n, tmp, c ));}
903 if( *endings == 0 )
while( isspace( **e ) ) (*e)++;
907 if( *endings == 0 ) {
909 xDataXML_shortStringForMessage( n, tmp, c ) ); }
911 if( strchr( endings, **e ) == NULL ) {
913 xDataXML_shortStringForMessage( n, tmp, c ) ); }
940static char const *xDataXML_shortStringForMessage(
size_t size,
char *Out,
char const *In ) {
942 if( strlen( In ) > size ) {
943 strncpy( Out, In, size - 5 );
945 strcat( Out,
" ..." );
963 for( i = 0; 1; i++ ) {
972 if( xDataValue == NULL ) {
974 status = xDataXML_constructTOM( smr, TOMChild, XMLChild );
996 printf(
"Unsupported xData type '%s' in element '%s'\n", xDataValue, XE->
name );
999 "Unsupported xData type = \"%s\"", xDataValue );
1015 return( xDI->
data );
1018#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)