43 #if defined __cplusplus
49 const char *evaluation,
const char *projectile,
const char *
target );
54 static void _tpia_map_simpleWrite2( FILE *
f,
tpia_map *map,
int level );
55 static int _tpia_map_smrUserInterface(
void *
userData,
char **str );
75 memset( map, 0,
sizeof(
tpia_map ) );
97 const char *evaluation, *projectile, *targetName, *path, *schema;
99 char realPath[2 * ( PATH_MAX + 1 )], *
p = &(realPath[PATH_MAX+1]);
102 char realPath[2 * ( _MAX_PATH + 1 )], *
p = &(realPath[_MAX_PATH+1]);
107 if( ( basePath == NULL ) || ( mapFileName[0] ==
'/' ) ) {
108 strcpy( realPath, mapFileName ); }
110 strcpy( realPath, basePath );
111 strcat( realPath,
"/" );
112 strcat( realPath, mapFileName );
115 if( realpath( realPath,
p ) == NULL ) {
127 strcpy( map->
path,
p );
128 if( (
p = strrchr( map->
path,
'/' ) ) != NULL ) {
131 strcpy( map->
path,
"." );
139 if( !strcmp( child->
name,
"path" ) ) {
149 else if( !strcmp( child->
name,
"target" ) ) {
198 for( entry = map->
mapEntries; entry != NULL; entry = next ) {
224 return( entry->
next );
231 return( _tpia_map_addEntry( smr, map,
tpia_mapEntry_type_target, schema, path, evaluation, projectile, target ) != NULL );
240 if( entry != NULL ) {
243 return( entry != NULL );
249 const char *evaluation,
const char *projectile,
const char *targetName ) {
262 if( ( entry->
path = (
char*)
xData_malloc2( smr, strlen( path ) + 1, 0,
"path" ) ) == NULL ) {
266 strcpy( entry->
path, path );
269 if( evaluation != NULL ) {
271 if( ( entry->
evaluation = (
char*)
xData_malloc2( smr, strlen( evaluation ) + 1, 0,
"evaluation" ) ) == NULL ) {
279 if( projectile != NULL ) {
281 if( ( entry->
projectile = (
char*)
xData_malloc2( smr, strlen( projectile ) + 1, 0,
"projectile" ) ) == NULL ) {
290 if( targetName != NULL ) {
302 if( schema != NULL ) {
304 if( ( entry->
schema = (
char*)
xData_malloc2( smr, strlen( schema ) + 1, 0,
"schema" ) ) == NULL ) {
312 strcpy( entry->
schema, schema );
335 path = _tpia_map_findTarget2( smr, map, evaluation, projectile, targetName );
336 if( ( path == NULL ) &&
smr_isOk( smr ) ) {
337 if( evaluation == NULL ) {
340 smr_setMessageInfo( smr, &(map->
smrUserInterface), __FILE__, __LINE__, 1,
"target %s for projectile %s and evaluation %s not found", targetName, projectile, evaluation );
348 static char *_tpia_map_findTarget2(
statusMessageReporting *smr,
tpia_map *map,
const char *evaluation,
const char *projectile,
const char *targetName ) {
354 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
355 switch( entry->
type ) {
357 if( !strcmp( projectile, entry->
projectile ) && ( !strcmp( targetName, entry->
targetName ) ) ) {
358 if( evaluation == NULL ) {
361 status = !strcmp( evaluation, entry->
evaluation );
364 n = strlen( map->
path ) + 1 + strlen( entry->
path ) + 1;
366 if( ( path = (
char*)
xData_malloc2( smr, n, 0,
"path" ) ) == NULL )
return( NULL );
367 strcpy( path, map->
path );
369 if( entry->
path[0] ==
'/' ) {
370 strcpy( path, entry->
path ); }
372 strcat( path, entry->
path );
379 if( !strcmp( projectile, entry->
projectile ) ) {
380 if( ( path = _tpia_map_findTarget2( smr, entry->
map, evaluation, projectile, targetName ) ) != NULL )
return( path );
401 if( ( mapAllOfTarget =
tpia_map_create( smr ) ) == NULL )
return( NULL );
402 status = _tpia_map_findAllOfTarget2( smr, mapAllOfTarget, map, projectile, targetName );
405 return( mapAllOfTarget );
414 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
415 switch( entry->
type ) {
417 if( !strcmp( projectile, entry->
projectile ) && ( !strcmp( targetName, entry->
targetName ) ) ) {
423 if( !strcmp( projectile, entry->
projectile ) ) {
424 if( _tpia_map_findAllOfTarget2( smr, mapAllOfTarget, entry->
map, projectile, targetName ) != 0 )
return( 1 );
441 if( endPath[0] ==
'/' ) {
443 if( ( path = (
char*)
xData_malloc2( smr, strlen( endPath ) + 1, 0,
"path" ) ) == NULL )
return( NULL );
447 if( ( path = (
char*)
xData_malloc2( smr, strlen( map->
path ) + strlen( endPath ) + 2, 0,
"path" ) ) == NULL )
return( NULL );
448 strcpy( path, map->
path );
451 strcat( path, endPath );
459 return( _tpia_map_walkTree2( smr, map, 0, handler, userData ) );
469 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
470 if( handler( entry, level, userData ) != 0 )
return( 1 );
482 char targetFormat[] =
"<target schema=\"%s\" evaluation=\"%s\" projectile=\"%s\" target=\"%s\" path=\"%s\"/>\n";
483 char pathFormat[] =
"<path projectile=\"%s\" path=\"%s\"/>\n";
484 char start[] =
"<map>\n";
485 char end[] =
"</map>";
486 int n = 0, nStart = strlen( start ), nEnd = strlen( end );
487 int nTarget = strlen( targetFormat ) - 10, nPath = strlen( pathFormat ) - 4;
491 n = nStart + nEnd + 1;
492 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
493 switch( entry->
type ) {
506 if( ( s = (
char *)
xData_malloc2( smr, n, 0,
"xml string" ) ) == NULL )
return( NULL );
510 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
511 switch( entry->
type ) {
531 static void _tpia_map_simpleWrite2( FILE *
f,
tpia_map *map,
int level ) {
535 int n = strlen( sLevel ) / 4;
538 fprintf( f,
"Bad map status = %d\n", map->
status );
541 if( level < n ) sLevel[4 * level] = 0;
542 fprintf( f,
"%smap->path = %s\n", sLevel, map->
path );
543 fprintf( f,
"%smap->mapFileName = %s\n", sLevel, map->
mapFileName );
544 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
545 switch( entry->
type ) {
547 fprintf( f,
"%sType = target: schema = %s: evaluation = %s: projectile = %s: target = %s: path = %s\n", sLevel, entry->
schema,
551 fprintf( f,
"%sType = path: projectile = %s: path = %s\n", sLevel, entry->
projectile, entry->
path );
552 _tpia_map_simpleWrite2( f, entry->
map, level + 1 );
555 fprintf( f,
"%sUnknown type = %d\n", sLevel, entry->
type );
562 static int _tpia_map_smrUserInterface(
void *userData,
char **str ) {
565 char fnl[] =
"map file = ";
566 int size = strlen( fnl ) + strlen( smrUserInterface->
map->
mapFileName ) + 1;
570 if( ( *str = (
char*)
xData_malloc2( NULL, size, 0,
"mapFileName" ) ) == NULL )
return( -1 );
577 #if defined __cplusplus