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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /processes/hadronic/models/lend/src/xDataTOM_Misc.cc (Version 11.3.0) and /processes/hadronic/models/lend/src/xDataTOM_Misc.cc (Version 11.1)


  1 /*                                                  1 /*
  2 # <<BEGIN-copyright>>                               2 # <<BEGIN-copyright>>
  3 # <<END-copyright>>                                 3 # <<END-copyright>>
  4 */                                                  4 */
  5                                                     5 
  6 #include <stdlib.h>                                 6 #include <stdlib.h>
  7 #include <string.h>                                 7 #include <string.h>
  8 #include <ctype.h>                                  8 #include <ctype.h>
  9 #ifdef WIN32                                        9 #ifdef WIN32
 10 #include <direct.h>                                10 #include <direct.h>
 11 #else                                              11 #else
 12 #include <unistd.h>                                12 #include <unistd.h>
 13 #endif                                             13 #endif
 14                                                    14 
 15 #include "xDataTOM_private.h"                      15 #include "xDataTOM_private.h"
 16                                                    16 
 17 #if defined __cplusplus                            17 #if defined __cplusplus
 18 namespace GIDI {                                   18 namespace GIDI {
 19 using namespace GIDI;                              19 using namespace GIDI;
 20 #endif                                             20 #endif
 21                                                    21 
 22 #define nameValueLength 1024                       22 #define nameValueLength 1024
 23                                                    23 
 24 static xDataTOM_element *xDataTOM_getLinksElem     24 static xDataTOM_element *xDataTOM_getLinksElement2( statusMessageReporting *smr, xDataTOM_element *element, char const *link, char const *fullLink );
 25 static int xDataTOM_getLinksElement3( statusMe     25 static int xDataTOM_getLinksElement3( statusMessageReporting *smr, char const *nameValue, char *name, char *value, char const *fullLink );
 26 /*                                                 26 /*
 27 **********************************************     27 ************************************************************
 28 */                                                 28 */
 29 char *xDataTOMMisc_getAbsPath( statusMessageRe     29 char *xDataTOMMisc_getAbsPath( statusMessageReporting *smr, const char *fileName ) {
 30 /*                                                 30 /*
 31 *   User must free returned string.                31 *   User must free returned string.
 32 */                                                 32 */
 33     int n = (int) strlen( fileName ) + 1, nCwd     33     int n = (int) strlen( fileName ) + 1, nCwd = 0;
 34     char *absPath, cwd[4 * 1024] = "", *p, *ne     34     char *absPath, cwd[4 * 1024] = "", *p, *needle;
 35                                                    35 
 36     if( fileName[0] != '/' ) {                     36     if( fileName[0] != '/' ) {
 37         //if( getcwd( cwd, sizeof( cwd ) + 1 )     37         //if( getcwd( cwd, sizeof( cwd ) + 1 ) == NULL ) {
 38         //TK modified above line for compiler(     38         //TK modified above line for compiler(gcc.4.8) warning message
 39         if( getcwd( cwd, sizeof( cwd ) ) == NU     39         if( getcwd( cwd, sizeof( cwd ) ) == NULL ) {
 40             smr_setReportError2p( smr, xDataTO     40             smr_setReportError2p( smr, xDataTOM_smrLibraryID, -1, "hardwired cwd too small" );
 41             return( NULL );                        41             return( NULL );
 42         }                                          42         }
 43         nCwd = (int) strlen( cwd );                43         nCwd = (int) strlen( cwd );
 44         n += nCwd + 1;                             44         n += nCwd + 1;                                  /* cwd + '/'. */
 45     }                                              45     }
 46     if( ( absPath = (char *) smr_malloc2( smr,     46     if( ( absPath = (char *) smr_malloc2( smr, n, 0, "absPath" ) ) == NULL ) return( NULL );
 47     if( fileName[0] != '/' ) {                     47     if( fileName[0] != '/' ) {
 48         strcpy( absPath, cwd );                    48         strcpy( absPath, cwd );
 49         strcat( absPath, "/" );                    49         strcat( absPath, "/" );
 50         strcat( absPath, fileName ); }             50         strcat( absPath, fileName ); }
 51     else {                                         51     else {
 52         strcpy( absPath, fileName );               52         strcpy( absPath, fileName );
 53     }                                              53     }
 54                                                    54 
 55     while( 1 ) {                                   55     while( 1 ) {                                        /* Remove all ./ from path. */
 56         if( ( needle = strstr( absPath, "/./"      56         if( ( needle = strstr( absPath, "/./" ) ) == NULL ) break; 
 57         p = needle;                                57         p = needle;
 58         for( needle += 2; *needle; p++, needle     58         for( needle += 2; *needle; p++, needle++ ) *p = *needle;
 59         *p = 0;                                    59         *p = 0;
 60     } // Loop checking, 11.06.2015, T. Koi         60     } // Loop checking, 11.06.2015, T. Koi
 61                                                    61 
 62     while( 1 ) {                                   62     while( 1 ) {                                        /* Remove all ../ from path. */
 63         if( ( needle = strstr( absPath, "/../"     63         if( ( needle = strstr( absPath, "/../" ) ) == NULL ) break;
 64         p = needle - 1;                            64         p = needle - 1;
 65         while( ( p > absPath ) && ( *p != '/'      65         while( ( p > absPath ) && ( *p != '/' ) ) p--; // Loop checking, 11.06.2015, T. Koi
 66         if( *p != '/' ) break;                     66         if( *p != '/' ) break;                           /* This should not happen if path is legit, I think, and I do not know what to do so will leave it. */
 67         if( p == absPath ) break;                  67         if( p == absPath ) break;                       /* Ditto. */
 68         for( needle += 3; *needle; p++, needle     68         for( needle += 3; *needle; p++, needle++ ) *p = *needle;
 69         *p = 0;                                    69         *p = 0;
 70     } // Loop checking, 11.06.2015, T. Koi         70     } // Loop checking, 11.06.2015, T. Koi
 71     return( absPath );                             71     return( absPath );
 72 }                                                  72 }
 73 /*                                                 73 /*
 74 **********************************************     74 ************************************************************
 75 */                                                 75 */
 76 int xDataTOM_setMessageError_ReturnInt( int va     76 int xDataTOM_setMessageError_ReturnInt( int value, statusMessageReporting *smr, void *userInterface, const char *packageName, int lineNumber, int code, 
 77     const char *fmt, ... ) {                       77     const char *fmt, ... ) {
 78                                                    78 
 79     va_list args;                                  79     va_list args;
 80                                                    80 
 81     va_start( args, fmt );                         81     va_start( args, fmt );
 82     smr_setReportError( smr, userInterface, pa     82     smr_setReportError( smr, userInterface, packageName, lineNumber, __func__, xDataTOM_smrLibraryID, code, fmt, args );
 83     va_end( args );                                83     va_end( args );
 84     return( value );                               84     return( value );
 85 }                                                  85 }
 86 /*                                                 86 /*
 87 **********************************************     87 ************************************************************
 88 */                                                 88 */
 89 xDataTOM_element *xDataTOM_getLinksElement( st     89 xDataTOM_element *xDataTOM_getLinksElement( statusMessageReporting *smr, xDataTOM_element *element, char const *link ) {
 90                                                    90 
 91     xDataTOM_element *linkedElement = NULL;        91     xDataTOM_element *linkedElement = NULL;
 92                                                    92 
 93     if( link[0] == '/' ) {                         93     if( link[0] == '/' ) {
 94         for( linkedElement = element; linkedEl     94         for( linkedElement = element; linkedElement->parent != NULL;  ) linkedElement = linkedElement->parent;
 95         linkedElement = xDataTOM_getLinksEleme     95         linkedElement = xDataTOM_getLinksElement2( smr, linkedElement, &(link[1]), link ); }
 96     else {                                         96     else {
 97         smr_setReportError2( smr, smr_unknownI     97         smr_setReportError2( smr, smr_unknownID, 1, "Only absolute link currently supported: requested link = '%s'", link );
 98     }                                              98     }
 99     return( linkedElement );                       99     return( linkedElement );
100 }                                                 100 }
101 /*                                                101 /*
102 **********************************************    102 ************************************************************
103 */                                                103 */
104 static xDataTOM_element *xDataTOM_getLinksElem    104 static xDataTOM_element *xDataTOM_getLinksElement2( statusMessageReporting *smr, xDataTOM_element *element, char const *link, char const *fullLink ) {
105                                                   105 
106     int n = (int) strlen( link );                 106     int n = (int) strlen( link );
107     char const *slash = strchr( link, '/' ), *    107     char const *slash = strchr( link, '/' ), *bracket = strchr( link, '[' ), *attributesValue;
108     char name[nameValueLength], value[nameValu    108     char name[nameValueLength], value[nameValueLength];
109     xDataTOM_element *child;                      109     xDataTOM_element *child;
110                                                   110 
111     if( bracket != NULL ) n = (int) ( bracket     111     if( bracket != NULL ) n = (int) ( bracket - link );
112     if( slash != NULL ) {                         112     if( slash != NULL ) {
113         if( (int) ( slash - link ) < n ) {        113         if( (int) ( slash - link ) < n ) {
114             n = (int) ( slash - link );           114             n = (int) ( slash - link );
115             bracket = NULL;                       115             bracket = NULL;
116         }                                         116         }
117     }                                             117     }
118     for( child = element->children; child != N    118     for( child = element->children; child != NULL; child = child->next ) {
119         if( strncmp( link, child->name, n ) ==    119         if( strncmp( link, child->name, n ) == 0 ) {
120             if( bracket != NULL ) {               120             if( bracket != NULL ) {
121                 if( bracket[1] != '@' ) {         121                 if( bracket[1] != '@' ) {
122                     smr_setReportError2( smr,     122                     smr_setReportError2( smr, smr_unknownID, 1, "bad link info at '%s' of '%s'", bracket, fullLink );
123                     return( NULL );               123                     return( NULL );
124                 }                                 124                 }
125                 if( xDataTOM_getLinksElement3(    125                 if( xDataTOM_getLinksElement3( smr, &(bracket[2]), name, value, fullLink ) ) return( NULL );
126                 if( ( attributesValue = xDataT    126                 if( ( attributesValue = xDataTOM_getAttributesValueInElement( child, name ) ) == NULL ) continue;
127                 if( strcmp( value, attributesV    127                 if( strcmp( value, attributesValue ) ) continue;
128             }                                     128             }
129             if( slash == NULL ) return( child     129             if( slash == NULL ) return( child );
130             return( xDataTOM_getLinksElement2(    130             return( xDataTOM_getLinksElement2( smr, child, &(slash[1]), fullLink ) );
131         }                                         131         }
132     }                                             132     }
133     return( NULL );                               133     return( NULL );
134 }                                                 134 }
135 /*                                                135 /*
136 **********************************************    136 ************************************************************
137 */                                                137 */
138 static int xDataTOM_getLinksElement3( statusMe    138 static int xDataTOM_getLinksElement3( statusMessageReporting *smr, char const *nameValue, char *name, char *value, char const *fullLink ) {
139                                                   139 
140     int n;                                        140     int n;
141     char const *equal = strchr( nameValue, '='    141     char const *equal = strchr( nameValue, '=' ), *p;
142     char quote = '\'';                            142     char quote = '\'';
143                                                   143 
144     if( equal == NULL ) {                         144     if( equal == NULL ) {
145         smr_setReportError2( smr, smr_unknownI    145         smr_setReportError2( smr, smr_unknownID, 1, "link qualifier missing '=' character at '%s' of '%s'", nameValue, fullLink );
146         return( 1 );                              146         return( 1 );
147     }                                             147     }
148     n = (int) ( equal - nameValue );              148     n = (int) ( equal - nameValue );
149     if( n >= ( nameValueLength - 1 ) ) {          149     if( n >= ( nameValueLength - 1 ) ) {
150         smr_setReportError2( smr, smr_unknownI    150         smr_setReportError2( smr, smr_unknownID, 1, "link's name qualifier too long at '%s' of '%s'", nameValue, fullLink );
151         return( 1 );                              151         return( 1 );
152     }                                             152     }
153     strncpy( name, nameValue, n );                153     strncpy( name, nameValue, n );
154     name[n] = 0;                                  154     name[n] = 0;
155                                                   155 
156     equal++;                                      156     equal++;
157     if( *equal != quote ) quote = '"';            157     if( *equal != quote ) quote = '"';
158     if( *equal != quote ) {                       158     if( *equal != quote ) {
159         smr_setReportError2( smr, smr_unknownI    159         smr_setReportError2( smr, smr_unknownID, 1, "link's name qualifier missing quote at '%s' of '%s'", nameValue, fullLink );
160         return( 1 );                              160         return( 1 );
161     }                                             161     }
162                                                   162 
163     equal++;                                      163     equal++;
164     p = strchr( equal, quote );                   164     p = strchr( equal, quote );
165     if( p == NULL ) {                             165     if( p == NULL ) {
166         smr_setReportError2( smr, smr_unknownI    166         smr_setReportError2( smr, smr_unknownID, 1, "link's name qualifier missing end quote at '%s' of '%s'", nameValue, fullLink );
167         return( 1 );                              167         return( 1 );
168     }                                             168     }
169                                                   169 
170     n = (int) ( p - equal );                      170     n = (int) ( p - equal );
171     if( n >= ( nameValueLength - 1 ) ) {          171     if( n >= ( nameValueLength - 1 ) ) {
172         smr_setReportError2( smr, smr_unknownI    172         smr_setReportError2( smr, smr_unknownID, 1, "link's value qualifier too long at '%s' of '%s'", nameValue, fullLink );
173         return( 1 );                              173         return( 1 );
174     }                                             174     }
175     strncpy( value, equal, n );                   175     strncpy( value, equal, n );
176     value[n] = 0;                                 176     value[n] = 0;
177                                                   177 
178     return( 0 );                                  178     return( 0 );
179 }                                                 179 }
180                                                   180 
181 #if defined __cplusplus                           181 #if defined __cplusplus
182 }                                                 182 }
183 #endif                                            183 #endif
184                                                   184