#include <string.h>
#include <limits.h>
#include <tpia_map.h>
Go to the source code of this file.
Functions | |
tpia_map * | tpia_map_create (statusMessageReporting *smr) |
int | tpia_map_initialize (statusMessageReporting *, tpia_map *map) |
tpia_map * | tpia_map_readFile (statusMessageReporting *smr, const char *basePath, const char *mapFileName) |
void * | tpia_map_free (statusMessageReporting *smr, tpia_map *map) |
void | tpia_map_release (statusMessageReporting *smr, tpia_map *map) |
tpia_mapEntry * | tpia_map_getFirstEntry (tpia_map *map) |
tpia_mapEntry * | tpia_map_getNextEntry (tpia_mapEntry *entry) |
int | tpia_map_addTarget (statusMessageReporting *smr, tpia_map *map, const char *schema, const char *path, const char *evaluation, const char *projectile, const char *target) |
int | tpia_map_addPath (statusMessageReporting *smr, tpia_map *map, const char *path, const char *projectile) |
char * | tpia_map_findTarget (statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName) |
tpia_map * | tpia_map_findAllOfTarget (statusMessageReporting *smr, tpia_map *map, const char *projectile, const char *targetName) |
char * | tpia_map_getFullPath (statusMessageReporting *smr, tpia_map *map, const char *endPath) |
int | tpia_map_walkTree (statusMessageReporting *smr, tpia_map *map, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData) |
char * | tpia_map_toXMLString (statusMessageReporting *smr, tpia_map *map) |
void | tpia_map_simpleWrite (FILE *f, tpia_map *map) |
int tpia_map_addPath | ( | statusMessageReporting * | smr, | |
tpia_map * | map, | |||
const char * | path, | |||
const char * | projectile | |||
) |
Definition at line 236 of file tpia_map.cc.
References tpia_map_readFile().
Referenced by tpia_map_readFile().
00236 { 00237 00238 tpia_mapEntry *entry = _tpia_map_addEntry( smr, map, tpia_mapEntry_type_path, NULL, path, NULL, projectile, NULL ); 00239 00240 if( entry != NULL ) { 00241 if( ( entry->map = tpia_map_readFile( smr, map->path, entry->path ) ) == NULL ) entry = NULL; 00242 } 00243 return( entry != NULL ); 00244 }
int tpia_map_addTarget | ( | statusMessageReporting * | smr, | |
tpia_map * | map, | |||
const char * | schema, | |||
const char * | path, | |||
const char * | evaluation, | |||
const char * | projectile, | |||
const char * | target | |||
) |
Definition at line 229 of file tpia_map.cc.
Referenced by tpia_map_readFile().
00229 { 00230 00231 return( _tpia_map_addEntry( smr, map, tpia_mapEntry_type_target, schema, path, evaluation, projectile, target ) != NULL ); 00232 }
tpia_map* tpia_map_create | ( | statusMessageReporting * | smr | ) |
Definition at line 59 of file tpia_map.cc.
References tpia_map_free(), and tpia_map_initialize().
Referenced by tpia_map_findAllOfTarget(), and tpia_map_readFile().
00059 { 00060 00061 tpia_map *map; 00062 00063 //if( ( map = xData_malloc2( smr, sizeof( tpia_map ), 0, "map" ) ) == NULL ) return( NULL ); 00064 if( ( map = (tpia_map*) xData_malloc2( smr, sizeof( tpia_map ), 0, "map" ) ) == NULL ) return( NULL ); 00065 //if( tpia_map_initialize( smr, map ) ) map = tpia_map_free( NULL, map ); 00066 if( tpia_map_initialize( smr, map ) ) map = (tpia_map*) tpia_map_free( NULL, map ); 00067 return( map ); 00068 }
tpia_map* tpia_map_findAllOfTarget | ( | statusMessageReporting * | smr, | |
tpia_map * | map, | |||
const char * | projectile, | |||
const char * | targetName | |||
) |
Definition at line 393 of file tpia_map.cc.
References tpia_map_create(), and tpia_map_free().
00393 { 00394 /* 00395 * Calling routine must free returned pointer. 00396 */ 00397 int status; 00398 tpia_map *mapAllOfTarget; 00399 00400 if( map->status != tpia_map_status_Ok ) return( NULL ); 00401 if( ( mapAllOfTarget = tpia_map_create( smr ) ) == NULL ) return( NULL ); 00402 status = _tpia_map_findAllOfTarget2( smr, mapAllOfTarget, map, projectile, targetName ); 00403 //if( ( status != 0 ) ) mapAllOfTarget = tpia_map_free( smr, mapAllOfTarget ); 00404 if( ( status != 0 ) ) mapAllOfTarget = (tpia_map*) tpia_map_free( smr, mapAllOfTarget ); 00405 return( mapAllOfTarget ); 00406 }
char* tpia_map_findTarget | ( | statusMessageReporting * | smr, | |
tpia_map * | map, | |||
const char * | evaluation, | |||
const char * | projectile, | |||
const char * | targetName | |||
) |
Definition at line 327 of file tpia_map.cc.
References smr_isOk(), and smr_setMessageInfo().
Referenced by tpia_target_createReadFromMap(), and tpia_target_readFromMap().
00327 { 00328 /* 00329 * Calling routine must free returned pointer. 00330 */ 00331 char *path; 00332 00333 if( map->status != tpia_map_status_Ok ) return( NULL ); 00334 00335 path = _tpia_map_findTarget2( smr, map, evaluation, projectile, targetName ); 00336 if( ( path == NULL ) && smr_isOk( smr ) ) { 00337 if( evaluation == NULL ) { 00338 smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, 1, "target %s for projectile %s not found", targetName, projectile ); } 00339 else { 00340 smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, 1, "target %s for projectile %s and evaluation %s not found", targetName, projectile, evaluation ); 00341 } 00342 } 00343 return( path ); 00344 }
void* tpia_map_free | ( | statusMessageReporting * | smr, | |
tpia_map * | map | |||
) |
Definition at line 184 of file tpia_map.cc.
References tpia_map_release(), and xData_free().
Referenced by tpia_depot_freeMap(), tpia_depot_release(), tpia_map_create(), tpia_map_findAllOfTarget(), tpia_map_readFile(), tpia_map_release(), and G4GIDI_map::~G4GIDI_map().
00184 { 00185 00186 tpia_map_release( smr, map ); 00187 xData_free( smr, map ); 00188 return( NULL ); 00189 }
tpia_mapEntry* tpia_map_getFirstEntry | ( | tpia_map * | map | ) |
char* tpia_map_getFullPath | ( | statusMessageReporting * | smr, | |
tpia_map * | map, | |||
const char * | endPath | |||
) |
Definition at line 437 of file tpia_map.cc.
00437 { 00438 00439 char *path; 00440 00441 if( endPath[0] == '/' ) { 00442 //if( ( path = xData_malloc2( smr, strlen( endPath ) + 1, 0, "path" ) ) == NULL ) return( NULL ); 00443 if( ( path = (char*) xData_malloc2( smr, strlen( endPath ) + 1, 0, "path" ) ) == NULL ) return( NULL ); 00444 path[0] = 0; } 00445 else { 00446 //if( ( path = xData_malloc2( smr, strlen( map->path ) + strlen( endPath ) + 2, 0, "path" ) ) == NULL ) return( NULL ); 00447 if( ( path = (char*) xData_malloc2( smr, strlen( map->path ) + strlen( endPath ) + 2, 0, "path" ) ) == NULL ) return( NULL ); 00448 strcpy( path, map->path ); 00449 strcat( path, "/" ); 00450 } 00451 strcat( path, endPath ); 00452 return( path ); 00453 }
tpia_mapEntry* tpia_map_getNextEntry | ( | tpia_mapEntry * | entry | ) |
int tpia_map_initialize | ( | statusMessageReporting * | , | |
tpia_map * | map | |||
) |
Definition at line 73 of file tpia_map.cc.
Referenced by tpia_map_create().
00073 { 00074 00075 memset( map, 0, sizeof( tpia_map ) ); 00076 map->status = tpia_map_status_Ok; 00077 map->smrUserInterface.smrUserInterface = _tpia_map_smrUserInterface; 00078 map->smrUserInterface.map = map; 00079 map->path = NULL; 00080 map->mapFileName = NULL; 00081 map->numberOfEntries = 0; 00082 map->mapEntries = NULL; 00083 return( 0 ); 00084 }
tpia_map* tpia_map_readFile | ( | statusMessageReporting * | smr, | |
const char * | basePath, | |||
const char * | mapFileName | |||
) |
Definition at line 88 of file tpia_map.cc.
References CLHEP::detail::n, smr_isOk(), smr_setMessageError(), tpia_map_addPath(), tpia_map_addTarget(), tpia_map_create(), tpia_map_free(), xData_getAttributesValueInElement(), xData_getDocumentsElement(), xData_getFirstElement(), xData_getNextElement(), xData_parseFree(), and xData_parseReadFile().
Referenced by tpia_depot_setMapFromFilename(), and tpia_map_addPath().
00088 { 00089 /* 00090 * If an error occurrs, map is freed and NULL is returned. 00091 */ 00092 int n = 0; 00093 xData_document *doc; 00094 xData_element *element; 00095 xData_element *child; 00096 tpia_map *map; 00097 const char *evaluation, *projectile, *targetName, *path, *schema; 00098 #ifndef WIN32 00099 char realPath[2 * ( PATH_MAX + 1 )], *p = &(realPath[PATH_MAX+1]); 00100 #endif 00101 #ifdef WIN32 00102 char realPath[2 * ( _MAX_PATH + 1 )], *p = &(realPath[_MAX_PATH+1]); 00103 #endif 00104 00105 if( ( map = tpia_map_create( smr ) ) == NULL ) return( NULL ); 00106 00107 if( ( basePath == NULL ) || ( mapFileName[0] == '/' ) ) { 00108 strcpy( realPath, mapFileName ); } 00109 else { 00110 strcpy( realPath, basePath ); 00111 strcat( realPath, "/" ); 00112 strcat( realPath, mapFileName ); 00113 } 00114 #ifndef WIN32 00115 if( realpath( realPath, p ) == NULL ) { 00116 smr_setMessageError( smr, NULL, __FILE__, __LINE__, tpia_map_status_mapParsing, "No map file %s\n", mapFileName ); 00117 //return( tpia_map_free( NULL, map ) ); 00118 return( (tpia_map*) tpia_map_free( NULL, map ) ); 00119 } 00120 #endif 00121 n = strlen( p ) + 2; 00122 //if( ( map->path = xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( tpia_map_free( NULL, map ) ); 00123 //if( ( map->path = (char*) xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( tpia_map_free( NULL, map ) ); 00124 if( ( map->path = (char*) xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( (tpia_map*) tpia_map_free( NULL, map ) ); 00125 map->mapFileName = &(map->path[n + 1]); 00126 strcpy( map->mapFileName, p ); 00127 strcpy( map->path, p ); 00128 if( ( p = strrchr( map->path, '/' ) ) != NULL ) { 00129 *p = 0; } 00130 else { 00131 strcpy( map->path, "." ); 00132 } 00133 00134 //if( ( doc = xData_parseReadFile( smr, map->mapFileName, NULL, NULL ) ) == NULL ) return( tpia_map_free( NULL, map ) ); 00135 if( ( doc = xData_parseReadFile( smr, map->mapFileName, NULL, NULL ) ) == NULL ) return( (tpia_map*) tpia_map_free( NULL, map ) ); 00136 00137 element = xData_getDocumentsElement( doc ); 00138 for( child = xData_getFirstElement( element ); child != NULL; child = xData_getNextElement( child ) ) { 00139 if( !strcmp( child->name, "path" ) ) { 00140 if( ( path = xData_getAttributesValueInElement( child , "path" ) ) == NULL ) { 00141 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "path missing path attribute" ); 00142 break; 00143 } 00144 if( ( projectile = xData_getAttributesValueInElement( child , "projectile" ) ) == NULL ) { 00145 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "path missing projectile attribute" ); 00146 break; 00147 } 00148 tpia_map_addPath( smr, map, path, projectile ); } 00149 else if( !strcmp( child->name, "target" ) ) { 00150 if( ( schema = xData_getAttributesValueInElement( child , "schema" ) ) == NULL ) { 00151 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'schema' attribute" ); 00152 break; 00153 } 00154 if( ( path = xData_getAttributesValueInElement( child , "path" ) ) == NULL ) { 00155 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'path' attribute" ); 00156 break; 00157 } 00158 if( ( evaluation = xData_getAttributesValueInElement( child , "evaluation" ) ) == NULL ) { 00159 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'evaluation' attribute" ); 00160 break; 00161 } 00162 if( ( projectile = xData_getAttributesValueInElement( child , "projectile" ) ) == NULL ) { 00163 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'projectile' attribute" ); 00164 break; 00165 } 00166 if( ( targetName = xData_getAttributesValueInElement( child , "target" ) ) == NULL ) { 00167 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'target' attribute" ); 00168 break; 00169 } 00170 tpia_map_addTarget( smr, map, schema, path, evaluation, projectile, targetName ); } 00171 else { 00172 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "invalid element = %s", child->name ); 00173 } 00174 if( !smr_isOk( smr ) ) break; 00175 } 00176 xData_parseFree( smr, doc ); 00177 //if( !smr_isOk( smr ) ) map = tpia_map_free( NULL, map ); 00178 if( !smr_isOk( smr ) ) map = (tpia_map*) tpia_map_free( NULL, map ); 00179 return( map ); 00180 }
void tpia_map_release | ( | statusMessageReporting * | smr, | |
tpia_map * | map | |||
) |
Definition at line 193 of file tpia_map.cc.
References tpia_map_free(), and xData_free().
Referenced by tpia_map_free().
00193 { 00194 00195 tpia_mapEntry *entry, *next; 00196 00197 if( map->path != NULL ) xData_free( NULL, map->path ); 00198 for( entry = map->mapEntries; entry != NULL; entry = next ) { 00199 next = entry->next; 00200 if( entry->schema != NULL ) xData_free( NULL, entry->schema ); 00201 if( entry->path != NULL ) xData_free( NULL, entry->path ); 00202 if( entry->evaluation != NULL ) xData_free( NULL, entry->evaluation ); 00203 if( entry->projectile != NULL ) xData_free( NULL, entry->projectile ); 00204 if( entry->targetName != NULL ) xData_free( NULL, entry->targetName ); 00205 if( entry->map != NULL ) tpia_map_free( smr, entry->map ); 00206 xData_free( NULL, entry ); 00207 } 00208 map->numberOfEntries = 0; 00209 map->mapEntries = NULL; 00210 map->status = tpia_map_status_Ok; 00211 }
void tpia_map_simpleWrite | ( | FILE * | f, | |
tpia_map * | map | |||
) |
char* tpia_map_toXMLString | ( | statusMessageReporting * | smr, | |
tpia_map * | map | |||
) |
Definition at line 478 of file tpia_map.cc.
References smr_setMessageInfo().
00478 { 00479 00480 tpia_mapEntry *entry; 00481 char *s, *p; 00482 char targetFormat[] = "<target schema=\"%s\" evaluation=\"%s\" projectile=\"%s\" target=\"%s\" path=\"%s\"/>\n"; 00483 char pathFormat[] = "<path projectile=\"%s\" path=\"%s\"/>\n"; 00484 char start[] = "<map>\n"; 00485 char end[] = "</map>"; 00486 int n = 0, nStart = strlen( start ), nEnd = strlen( end ); 00487 int nTarget = strlen( targetFormat ) - 10, nPath = strlen( pathFormat ) - 4; 00488 00489 if( map->status != tpia_map_status_Ok ) return( NULL ); 00490 00491 n = nStart + nEnd + 1; 00492 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 00493 switch( entry->type ) { 00494 case tpia_mapEntry_type_target : 00495 n += strlen( entry->schema ) + strlen( entry->path ) + strlen( entry->evaluation ) + strlen( entry->projectile ) + strlen( entry->targetName ) + nTarget; 00496 break; 00497 case tpia_mapEntry_type_path : 00498 n += strlen( entry->path ) + strlen( entry->projectile ) + nPath; 00499 break; 00500 default : 00501 smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, "unknown type = %d", entry->type ); 00502 return( NULL ); 00503 } 00504 } 00505 00506 if( ( s = (char *) xData_malloc2( smr, n, 0, "xml string" ) ) == NULL ) return( NULL ); 00507 p = s; 00508 strcpy( p, start ); 00509 while( *p ) p++; 00510 for( entry = map->mapEntries; entry != NULL; entry = entry->next ) { 00511 switch( entry->type ) { 00512 case tpia_mapEntry_type_target : 00513 sprintf( p, targetFormat, entry->schema, entry->evaluation, entry->projectile, entry->targetName, entry->path ); 00514 break; 00515 case tpia_mapEntry_type_path : 00516 sprintf( p, pathFormat, entry->projectile, entry->path ); 00517 break; 00518 } 00519 while( *p ) p++; 00520 } 00521 strcpy( p, end ); 00522 return( s ); 00523 }
int tpia_map_walkTree | ( | statusMessageReporting * | smr, | |
tpia_map * | map, | |||
int(*)(tpia_mapEntry *entry, int level, void *userData) | handler, | |||
void * | userData | |||
) |
Definition at line 457 of file tpia_map.cc.
Referenced by G4GIDI::getNamesOfAvailableTargets().
00457 { 00458 00459 return( _tpia_map_walkTree2( smr, map, 0, handler, userData ) ); 00460 }