43#if defined __cplusplus
49 const char *evaluation,
const char *projectile,
const char *target );
50static char *_tpia_map_findTarget2(
statusMessageReporting *smr,
tpia_map *map,
const char *evaluation,
const char *projectile,
const char *target );
54static void _tpia_map_simpleWrite2( FILE *f,
tpia_map *map,
int level );
55static 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 );
348static 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 ) {
531static 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 );
562static 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
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_setMessageInfo(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
int smr_isOk(statusMessageReporting *smr)
enum tpia_mapEntry_type type
tpia_map_smr smrUserInterface
enum tpia_map_status status
tpia_mapEntry * mapEntries
smr_userInterface smrUserInterface
tpia_map * tpia_map_create(statusMessageReporting *smr)
char * tpia_map_toXMLString(statusMessageReporting *smr, tpia_map *map)
@ tpia_map_status_UnknownType
@ tpia_map_status_mapParsing
void tpia_map_simpleWrite(FILE *f, tpia_map *map)
int tpia_map_initialize(statusMessageReporting *smr, tpia_map *map)
char * tpia_map_getFullPath(statusMessageReporting *smr, tpia_map *map, const char *endPath)
tpia_mapEntry * tpia_map_getNextEntry(tpia_mapEntry *entry)
tpia_map * tpia_map_readFile(statusMessageReporting *smr, const char *basePath, const char *mapFileName)
char * tpia_map_findTarget(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName)
void tpia_map_release(statusMessageReporting *smr, tpia_map *map)
tpia_mapEntry * tpia_map_getFirstEntry(tpia_map *map)
int tpia_map_walkTree(statusMessageReporting *smr, tpia_map *map, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData)
tpia_map * tpia_map_findAllOfTarget(statusMessageReporting *smr, tpia_map *map, const char *projectile, const char *targetName)
int tpia_map_addTarget(statusMessageReporting *smr, tpia_map *map, const char *method, const char *path, const char *evaluation, const char *projectile, const char *targetName)
@ tpia_mapEntry_type_target
@ tpia_mapEntry_type_path
int tpia_map_addPath(statusMessageReporting *smr, tpia_map *map, const char *path, const char *projectile)
void * tpia_map_free(statusMessageReporting *smr, tpia_map *map)
void * xData_free(statusMessageReporting *smr, void *p)
const char * xData_getAttributesValueInElement(xData_element *element, const char *name)
void * xData_parseFree(statusMessageReporting *smr, xData_document *xData_doc)
xData_element * xData_getNextElement(xData_element *element)
xData_element * xData_getDocumentsElement(xData_document *xData_doc)
xData_element * xData_getFirstElement(xData_element *element)
xData_document * xData_parseReadFile(statusMessageReporting *smr, const char *fileName, xData_xDataTypeOk func, void *userData)
#define xData_malloc2(smr, size, zero, forItem)