15 #include "xDataTOM_private.h"
17 #if defined __cplusplus
22 #define nameValueLength 1024
24 static xDataTOM_element *
xDataTOM_getLinksElement2( statusMessageReporting *smr, xDataTOM_element *element,
char const *link,
char const *fullLink );
33 int n = (int) strlen( fileName ) + 1, nCwd = 0;
34 char *absPath, cwd[4 * 1024] =
"", *p, *needle;
36 if( fileName[0] !=
'/' ) {
39 if( getcwd( cwd,
sizeof( cwd ) ) == NULL ) {
43 nCwd = (int) strlen( cwd );
46 if( ( absPath = (
char *) smr_malloc2( smr, n, 0,
"absPath" ) ) == NULL )
return( NULL );
47 if( fileName[0] !=
'/' ) {
48 strcpy( absPath, cwd );
49 strcat( absPath,
"/" );
50 strcat( absPath, fileName ); }
52 strcpy( absPath, fileName );
56 if( ( needle = strstr( absPath,
"/./" ) ) == NULL )
break;
58 for( needle += 2; *needle; p++, needle++ ) *p = *needle;
63 if( ( needle = strstr( absPath,
"/../" ) ) == NULL )
break;
65 while( ( p > absPath ) && ( *p !=
'/' ) ) p--;
66 if( *p !=
'/' )
break;
67 if( p == absPath )
break;
68 for( needle += 3; *needle; p++, needle++ ) *p = *needle;
77 const char *fmt, ... ) {
81 va_start( args, fmt );
91 xDataTOM_element *linkedElement = NULL;
93 if( link[0] ==
'/' ) {
94 for( linkedElement = element; linkedElement->parent != NULL; ) linkedElement = linkedElement->parent;
97 smr_setReportError2( smr, smr_unknownID, 1,
"Only absolute link currently supported: requested link = '%s'", link );
99 return( linkedElement );
104 static xDataTOM_element *
xDataTOM_getLinksElement2( statusMessageReporting *smr, xDataTOM_element *element,
char const *link,
char const *fullLink ) {
106 int n = (int) strlen( link );
107 char const *slash = strchr( link,
'/' ), *bracket = strchr( link,
'[' ), *attributesValue;
109 xDataTOM_element *child;
111 if( bracket != NULL ) n = (int) ( bracket - link );
112 if( slash != NULL ) {
113 if( (
int) ( slash - link ) < n ) {
114 n = (int) ( slash - link );
118 for( child = element->children; child != NULL; child = child->next ) {
119 if( strncmp( link, child->name, n ) == 0 ) {
120 if( bracket != NULL ) {
121 if( bracket[1] !=
'@' ) {
122 smr_setReportError2( smr, smr_unknownID, 1,
"bad link info at '%s' of '%s'", bracket, fullLink );
127 if( strcmp( value, attributesValue ) )
continue;
129 if( slash == NULL )
return( child );
141 char const *equal = strchr( nameValue,
'=' ), *p;
144 if( equal == NULL ) {
145 smr_setReportError2( smr, smr_unknownID, 1,
"link qualifier missing '=' character at '%s' of '%s'", nameValue, fullLink );
148 n = (int) ( equal - nameValue );
150 smr_setReportError2( smr, smr_unknownID, 1,
"link's name qualifier too long at '%s' of '%s'", nameValue, fullLink );
153 strncpy( name, nameValue, n );
157 if( *equal != quote ) quote =
'"';
158 if( *equal != quote ) {
159 smr_setReportError2( smr, smr_unknownID, 1,
"link's name qualifier missing quote at '%s' of '%s'", nameValue, fullLink );
164 p = strchr( equal, quote );
166 smr_setReportError2( smr, smr_unknownID, 1,
"link's name qualifier missing end quote at '%s' of '%s'", nameValue, fullLink );
170 n = (int) ( p - equal );
172 smr_setReportError2( smr, smr_unknownID, 1,
"link's value qualifier too long at '%s' of '%s'", nameValue, fullLink );
175 strncpy( value, equal, n );
181 #if defined __cplusplus
int xDataTOM_setMessageError_ReturnInt(int value, statusMessageReporting *smr, void *userInterface, const char *packageName, int lineNumber, int code, const char *fmt,...)
int xDataTOM_smrLibraryID
char * xDataTOMMisc_getAbsPath(statusMessageReporting *smr, const char *fileName)
static xDataTOM_element * xDataTOM_getLinksElement2(statusMessageReporting *smr, xDataTOM_element *element, char const *link, char const *fullLink)
int smr_setReportError(statusMessageReporting *smr, void *userInterface, char const *file, int line, char const *function, int libraryID, int code, char const *fmt,...)
char const * xDataTOM_getAttributesValueInElement(xDataTOM_element *element, char const *name)
static int xDataTOM_getLinksElement3(statusMessageReporting *smr, char const *nameValue, char *name, char *value, char const *fullLink)
xDataTOM_element * xDataTOM_getLinksElement(statusMessageReporting *smr, xDataTOM_element *element, char const *link)