44 #ifndef _SSIZE_T_DEFINED
46 #define _SSIZE_T_DEFINED
50 #include <sys/types.h>
57 #if defined __cplusplus
64 static void XMLCALL xData_parseStartElement(
void *
userData,
const char *
name,
const char **attris );
75 static int xData_elementList_defaultSorter(
void const *p1,
void const *p2 );
76 static int xData_elementList_indexSorter(
void const *p1,
void const *p2 );
77 static int xData_smrUserInterfaceInitialize(
xData_document *doc );
79 static int xData_smrUserInterface(
void *
userData,
char **smr );
80 static 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 );
260 static void XMLCALL xData_parseStartElement(
void *
userData,
const char *
name,
const char **attris ) {
265 xData_parseAddElementToRoot( doc->
smr, doc->
currentRoot, name, attris );
270 static void XMLCALL xData_parseEndElement(
void *userData,
const char *name ) {
276 if( !strcmp( name,
"xData" ) ) {
296 "Unsupported xData type = %s", value );
307 static void XMLCALL xData_parseCharacterData(
void *userData,
const XML_Char *
s,
int len ) {
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 ) {
880 static 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 ) );
891 static 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 );
959 static int xData_smrUserInterfaceInitialize(
xData_document *doc ) {
977 static 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 ) ); }
1094 static 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