44 #ifndef _SSIZE_T_DEFINED
46 #define _SSIZE_T_DEFINED
57#if defined __cplusplus
64static void XMLCALL xData_parseStartElement(
void *
userData,
const char *name,
const char **attris );
65static void XMLCALL xData_parseEndElement(
void *
userData,
const char *name );
75static int xData_elementList_defaultSorter(
void const *p1,
void const *p2 );
76static int xData_elementList_indexSorter(
void const *p1,
void const *p2 );
79static int xData_smrUserInterface(
void *
userData,
char **smr );
80static char const *xData_shortStringForMessage(
size_t size,
char *Out,
char const *In );
90 ssize_t count, n =
sizeof(
buffer ) - 1;
96 f = open( fileName, O_RDONLY );
101 while( ( count = read( f,
buffer, n ) ) > 0 ) {
110 "read failed with errno = %d for %s", errno, fileName );
113 if( ( doc != NULL ) && ( !
smr_isOk( smr ) ) ) {
170 xData_smrUserInterfaceInitialize( doc );
173 if( xmlParser == NULL ) {
177 xData_parseInitializeRootElement( doc, &(doc->
root), NULL, 0 );
196 "status = %d\nXML_Error code = %d\nXML_ErrorString = %s\nerror line, column = %d, %d",
xData_errXMLParser,
215 xData_smrUserInterfaceFree( doc );
226 if( element == NULL )
return( NULL );
227 for( ; element != NULL; element = next ) {
228 next = element->
next;
229 xData_parseFreeElementItems( smr, element );
260static void XMLCALL xData_parseStartElement(
void *
userData,
const char *name,
const char **attris ) {
265 xData_parseAddElementToRoot( doc->
smr, doc->
currentRoot, name, attris );
270static void XMLCALL xData_parseEndElement(
void *
userData,
const char *name ) {
276 if( !strcmp( name,
"xData" ) ) {
296 "Unsupported xData type = %s", value );
314 int needSize = text->
length + len + 1, l;
318 if( needSize < 8 ) needSize = 8;
323 if( l < 100 ) l = 100;
333 strncpy( p, s, len );
357 xData_parseGetCurrentPosition( doc, &(text->
docInfo) );
370 int i,
n, status = 1;
373 const char **pAttris;
379 if( element == NULL )
return( 1 );
380 xData_parseGetCurrentPosition( doc, &(element->
docInfo) );
385 xData_parseInitializeRootElement( doc, &(element->
childrenRoot), element, parentRoot->
depth + 1 );
386 element->
next = NULL;
388 if( ( element->
name = (
char*)
xData_malloc2( doc->
smr, strlen( name ) + 1, 0,
"name" ) ) == NULL ) {
392 strcpy( element->
name, name );
393 if( ( element->
fullName = xData_getTraceback( smr, element ) ) == NULL ) {
398 for( i = 0, lens = 0, pAttris = attris; *pAttris; i++, pAttris++ ) lens += strlen( *pAttris ) + 1;
411 for( i = 0, pAttris = attris; ( i <
n ) && status; i++, a++, pAttris++ ) {
412 lens = strlen( *pAttris ) + 1;
414 strcpy( p, *pAttris );
417 lens = strlen( *pAttris ) + 1;
419 strcpy( p, *pAttris );
421 if( !strcmp(
"index", a->name ) ) {
423 element->
index = strtoll( a->value, &e, 10 );
426 element->
index = strtol( a->value, &e, 10 );
430 smr_setMessageError( doc->
smr, smrUser, __FILE__, __LINE__, -1,
"could not convert index attribute = %s to integer", a->value );
443 xData_init_xDataTypeNone( &(element->
xDataTypeInfo), element );
445 xData_parseInitializeText( doc, &(element->
text) );
497 return( item->
mode );
525 return( item->
mode );
535 for( i = 0; i < attributes->
number; i++ ) {
557 attributes->
size = 0;
580 for( i = 0; i < src->
number; i++, s++, d++ ) {
581 lens = strlen( s->
name ) + 1;
583 strcpy( p, s->
name );
585 lens = strlen( s->
value ) + 1;
587 strcpy( p, s->
value );
598 return( attributes->
number );
605 if( index >= attributes->
number )
return( NULL );
614 attributes->
size = 0;
683 smr_setMessageError( smr, smrUser, __FILE__, __LINE__, 1,
"missing length (or end) in xData" );
692 if( xDT->
start < 0 ) {
719 *n = strtol( value, &e, 10 );
722 "could not convert attribute %s's value = %s to an integer", name, value );
738 *d = strtod( value, &e );
741 "could not convert attribute %s's values = %s to a double", name, value );
776 if( !strcmp( child->
name, tagName ) ) {
796 if( sortFunction == NULL ) {
798 if( sortAttributeName == NULL ) sortFunction = (
xData_sortElementFunc) xData_elementList_indexSorter;
800 if( sortAttributeName == NULL ) sortAttributeName =
"index";
818 1,
"element %s does not have sub-element named %s", element->
fullName, name ); }
819 else if( list->
n > 1 ) {
821 "element %s contains more than one sub-element named %s", element->
fullName, name ); }
846 name = element->
name;
847 size = strlen( name ) + 1;
848 if( ( s = xData_getTraceback2( smr, element->
parentRoot, size ) ) != NULL ) {
864 s = (
char*)
xData_malloc2( smr, n + 1, 0,
"traceback string" );
868 size = strlen( name ) + 1;
870 if( ( s = xData_getTraceback2( smr, parentRoot->
parentRoot, n ) ) != NULL ) {
880static int xData_elementList_defaultSorter(
void const *p1,
void const *p2 ) {
884 if( s2 == NULL )
return( -1 );
885 if( s1 == NULL )
return( 1 );
886 return( strcmp( s1, s2 ) );
891static int xData_elementList_indexSorter(
void const *p1,
void const *p2 ) {
895 return( e1->
index - e2->index );
907 "Element %s is not xData object of type %s", type );
924 if( fileName != NULL ) {
926 if( ( doc->
fileName = (
char*)
xData_malloc2( smr, strlen( fileName ) + 1, 0,
"doc->fileName" ) ) == NULL )
return( 1 );
946 if( doc == NULL )
return( NULL );
959static int xData_smrUserInterfaceInitialize(
xData_document *doc ) {
977static int xData_smrUserInterface(
void *
userData,
char **str ) {
979 int size, fileNameSize = 0, elementSize = 0;
981 static char lcl[] =
"\nat line %d and column %d", el[] =
"\nin element ", fl[] =
"\nof file ";
982 char str_lcl[
sizeof( lcl ) + 40];
985 if( smrUserInterface->
doc->
fileName != NULL ) fileNameSize = strlen( smrUserInterface->
doc->
fileName ) + strlen( fl );
986 if( currentRoot != NULL ) {
987 if( currentRoot->parentElement != NULL ) {
988 sprintf( str_lcl, lcl, currentRoot->parentElement->docInfo.line, currentRoot->parentElement->docInfo.column );
989 elementSize = strlen( str_lcl ) + strlen( currentRoot->parentElement->fullName ) + strlen( el );
992 size = fileNameSize + elementSize;
993 if( ( fileNameSize != 0 ) && ( elementSize != 0 ) ) size++;
994 if( ( size > 0 ) && ( str != NULL ) ) {
996 if( ( *str = (
char*) malloc( size + 1 ) ) == NULL )
return( -1 );
997 if( ( size != 0 ) && ( elementSize != 0 ) ) {
998 sprintf( *str,
"%s%s%s%s%s", str_lcl, el, currentRoot->parentElement->fullName, fl, smrUserInterface->
doc->
fileName ); }
999 else if( size != 0 ) {
1000 sprintf( *str,
"%s%s", fl, smrUserInterface->
doc->
fileName ); }
1002 sprintf( *str,
"%s%s%s", str_lcl, el, currentRoot->parentElement->fullName );
1014 int status = 1, n =
sizeof( tmp );
1016 for( s = c; *s != 0; s++ )
if( !isspace( *s ) )
break;
1018 *value = strtol( s, e, 10 );
1020 smr_setMessageError(smr, smrUserInterface, __FILE__, __LINE__, 1,
"could not convert \"%s\" to an integer", xData_shortStringForMessage( n, tmp, c ));}
1022 if( *endings == 0 )
while( isspace( **e ) ) (*e)++;
1026 if( *endings == 0 ) {
1027 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1,
"integer string \"%s\" does not end with a '\\0'",
1028 xData_shortStringForMessage( n, tmp, c ) ); }
1030 if( strchr( endings, **e ) == NULL ) {
1031 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1,
"integer string \"%s\" does not end with a white space or a '\\0\'",
1032 xData_shortStringForMessage( n, tmp, c ) ); }
1048 int status = 1, n =
sizeof( tmp );
1050 for( s = c; *s != 0; s++ )
if( !isspace( *s ) )
break;
1051 *value = strtod( s, e );
1053 smr_setMessageError(smr, smrUserInterface, __FILE__, __LINE__, 1,
"could not convert \"%s\" to an double", xData_shortStringForMessage( n, tmp, c ));}
1055 if( *endings == 0 )
while( isspace( **e ) ) (*e)++;
1059 if( *endings == 0 ) {
1060 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1,
"double string \"%s\" does not end with a '\\0'",
1061 xData_shortStringForMessage( n, tmp, c ) ); }
1063 if( strchr( endings, **e ) == NULL ) {
1064 smr_setMessageError( smr, smrUserInterface, __FILE__, __LINE__, 1,
"double string \"%s\" does not end with a white space or a '\\0\'",
1065 xData_shortStringForMessage( n, tmp, c ) ); }
1094static char const *xData_shortStringForMessage(
size_t size,
char *Out,
char const *In ) {
1096 if( strlen( In ) > size ) {
1097 strncpy( Out, In, size - 5 );
1099 strcat( Out,
" ..." );
1105#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)
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_isOk(statusMessageReporting *smr)
enum xData_xDataType status
xDT_releaseFunction release
xDT_toStringFunction toString
signed char lengthPresent
xDT_toDataFunction toData
xData_attribute * attributes
statusMessageReporting * smr
void * xDataTypeOk_userData
xData_rootElement * currentRoot
xData_xDataTypeOk xDataTypeOk_userFunction
xData_smr smrUserInterface
enum xData_errorCodes error
xData_elementListItem * items
xData_attributionList attributes
xData_rootElement * parentRoot
xData_rootElement childrenRoot
xData_element * parentElement
xData_document * xData_doc
xData_element * currentChild
xData_rootElement * parentRoot
xData_element * parentElement
smr_userInterface smrUserInterface
char const * xData_getFileName(xData_document *doc)
int xData_convertAttributeToDouble(statusMessageReporting *smr, xData_element *element, const char *name, double *d)
void * xData_free(statusMessageReporting *smr, void *p)
int xData_stringTo_double(statusMessageReporting *smr, void *smrUserInterface, char const *c, double *value, char const *endings, char **e)
void * xData_get_smrUserInterfaceFromElement(xData_element *element)
enum xData_itemMode xData_getFirstItem(xData_element *element, xData_item *item)
void xData_freeElementList(statusMessageReporting *smr, xData_elementList *list)
int xData_init_2d_xShared_yHistogram(statusMessageReporting *smr, xData_element *element)
int xData_getAccessed(statusMessageReporting *smr, xData_element *element)
xData_document * xData_getElementsDocument(xData_element *element)
int xData_initializeAttributionList(statusMessageReporting *smr, xData_attributionList *attributes)
xData_elementList * xData_getElementsByTagNameAndSort(statusMessageReporting *smr, xData_element *element, const char *tagName, const char *sortAttributeName, xData_sortElementFunc sortFunction)
struct xData_attribute_s xData_attribute
int(* xData_sortElementFunc)(const void *, const void *)
int xData_is_xDataType(statusMessageReporting *smr, xDataType *xDT, char const *const type, int setMsg)
int xData_init_1d_x(statusMessageReporting *smr, xData_element *element)
int xData_init_matrix(statusMessageReporting *smr, xData_element *element)
void * xData_get_smrUserInterfaceFromDocument(xData_document *doc)
int xData_numberOfElementsByTagName(statusMessageReporting *smr, xData_element *element, const char *tagName)
char const *const xData_matrix_ID
int xData_copyAttributionList(statusMessageReporting *smr, xData_attributionList *dest, xData_attributionList *src)
xData_attribute * xData_attributeByIndex(xData_attributionList *attributes, int index)
int(* xData_xDataTypeOk)(char const *name, xData_document *doc, void *userData)
int xData_stringTo_xData_Int(statusMessageReporting *smr, void *smrUserInterface, char const *c, xData_Int *value, char const *endings, char **e)
int xData_parseInitialize(statusMessageReporting *smr, xData_document *xData_doc, xData_xDataTypeOk func, void *userData)
enum xData_itemMode xData_getNextItem(xData_item *item)
const char * xData_getAttributesValueInElement(xData_element *element, const char *name)
int xData_releaseAttributionList(statusMessageReporting *smr, xData_attributionList *attributes)
char const *const xData_twod_xindex_y_ID
xData_element * xData_getOneElementByTagName(statusMessageReporting *smr, xData_element *element, char *name, int required)
int xData_addToAccessed(statusMessageReporting *smr, xData_element *element, int increment)
xData_document * xData_parseString(statusMessageReporting *smr, const char *str, xData_xDataTypeOk func, void *userData)
int xData_setFileName(statusMessageReporting *smr, xData_document *doc, char const *fileName)
int xData_xDataTypeConvertAttributes(statusMessageReporting *smr, xData_element *element)
void * xData_parseFree(statusMessageReporting *smr, xData_document *xData_doc)
xData_Int xData_convertAttributeTo_xData_Int(statusMessageReporting *smr, xData_element *element, const char *name, xData_Int *n)
xData_element * xData_getNextElement(xData_element *element)
xData_elementList * xData_getElementsByTagName(statusMessageReporting *smr, xData_element *element, const char *tagName)
struct xData_elementList_s xData_elementList
xData_element * xData_getDocumentsElement(xData_document *xData_doc)
xData_element * xData_getFirstElement(xData_element *element)
xData_document * xData_parseReadFile(statusMessageReporting *smr, const char *fileName, xData_xDataTypeOk func, void *userData)
int xData_getCommonData(statusMessageReporting *smr, xData_element *element, xData_Int *index, xData_Int *start, xData_Int *end, xData_Int *length)
@ xData_errXML_ParserCreate
char const *const xData_twod_xShared_yHistogram_ID
char * xData_getAttributesValue(xData_attributionList *attributes, const char *name)
int xData_parseEndOfXML(statusMessageReporting *smr, xData_document *xData_doc)
xData_document * xData_parseMalloc(statusMessageReporting *smr, xData_xDataTypeOk func, void *userData)
char const *const xData_twod_xy_ID
int xData_attributeListLength(xData_attributionList *attributes)
#define xData_malloc2(smr, size, zero, forItem)
char const *const xData_oned_x_ID
int xData_init_2d_xindex_y(statusMessageReporting *smr, xData_element *element)
#define xData_realloc2(smr, old, size, forItem)
xData_element * xData_getElements_xDataElement(statusMessageReporting *smr, xData_element *element)
int xData_parse(xData_document *xData_doc, const char *s)
int xData_parseIsError(xData_document *xData_doc)
int xData_init_2d_xy(statusMessageReporting *smr, xData_element *element)
XML_Size XMLCALL XML_GetCurrentColumnNumber(XML_Parser parser)
XML_Size XMLCALL XML_GetCurrentLineNumber(XML_Parser parser)