43 #if defined __cplusplus 
   48 static tpia_mapEntry *
_tpia_map_addEntry( statusMessageReporting *smr, tpia_map *map, 
enum tpia_mapEntry_type type, 
const char *schema, 
const char *path,
 
   49     const char *evaluation, 
const char *projectile, 
const char *target );
 
   50 static char *
_tpia_map_findTarget2( statusMessageReporting *smr, tpia_map *map, 
const char *evaluation, 
const char *projectile, 
const char *target );
 
   51 static int _tpia_map_findAllOfTarget2( statusMessageReporting *smr, tpia_map *mapAllOfTarget, tpia_map *map, 
const char *projectile, 
const char *targetName );
 
   52 static int _tpia_map_walkTree2( statusMessageReporting *smr, tpia_map *map, 
int level, 
int (*handler)( tpia_mapEntry *entry, 
int level, 
void *
userData), 
 
   64     if( ( map = (tpia_map*) xData_malloc2( smr, 
sizeof( tpia_map ), 0, 
"map" ) ) == NULL ) 
return( NULL );
 
   75     memset( map, 0, 
sizeof( tpia_map ) );
 
   76     map->status = tpia_map_status_Ok;
 
   78     map->smrUserInterface.map = map;
 
   80     map->mapFileName = NULL;
 
   81     map->numberOfEntries = 0;
 
   82     map->mapEntries = NULL;
 
   88 tpia_map *
tpia_map_readFile( statusMessageReporting *smr, 
const char *basePath, 
const char *mapFileName ) {
 
   94     xData_element *element;
 
   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 ) {
 
  116         smr_setMessageError( smr, NULL, __FILE__, __LINE__, tpia_map_status_mapParsing, 
"No map file %s\n", mapFileName );
 
  124     if( ( map->path = (
char*) xData_malloc2( smr, 2 * n, 0, 
"map->path" ) ) == NULL ) 
return( (tpia_map*) 
tpia_map_free( NULL, map ) );
 
  125     map->mapFileName = &(map->path[n + 1]);
 
  126     strcpy( map->mapFileName, p );
 
  127     strcpy( map->path, p );
 
  128     if( ( p = strrchr( map->path, 
'/' ) ) != NULL ) {
 
  131         strcpy( map->path, 
"." );
 
  139         if( !strcmp( child->name, 
"path" ) ) {
 
  141                 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"path missing path attribute" );
 
  145                 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"path missing projectile attribute" );
 
  149         else if( !strcmp( child->name, 
"target" ) ) {
 
  151                 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"target missing 'schema' attribute" );
 
  155                 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"target missing 'path' attribute" );
 
  159                 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"target missing 'evaluation' attribute" );
 
  163                 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"target missing 'projectile' attribute" );
 
  167                 smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"target missing 'target' attribute" );
 
  172             smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, 
"invalid element = %s", child->name );
 
  195     tpia_mapEntry *entry, *next;
 
  197     if( map->path != NULL ) 
xData_free( NULL, map->path );
 
  198     for( entry = map->mapEntries; entry != NULL; entry = next ) {
 
  200         if( entry->schema != NULL ) 
xData_free( NULL, entry->schema );
 
  201         if( entry->path != NULL ) 
xData_free( NULL, entry->path );
 
  202         if( entry->evaluation != NULL ) 
xData_free( NULL, entry->evaluation );
 
  203         if( entry->projectile != NULL ) 
xData_free( NULL, entry->projectile );
 
  204         if( entry->targetName != NULL ) 
xData_free( NULL, entry->targetName );
 
  208     map->numberOfEntries = 0;
 
  209     map->mapEntries = NULL;
 
  210     map->status = tpia_map_status_Ok;
 
  217     return( map->mapEntries );
 
  224     return( entry->next );
 
  229 int tpia_map_addTarget( statusMessageReporting *smr, tpia_map *map, 
const char *schema, 
const char *path, 
const char *evaluation, 
const char *projectile, 
const char *target ) {
 
  231     return( 
_tpia_map_addEntry( smr, map, tpia_mapEntry_type_target, schema, path, evaluation, projectile, target ) != NULL );
 
  236 int tpia_map_addPath( statusMessageReporting *smr, tpia_map *map, 
const char *path, 
const char *projectile ) {
 
  238     tpia_mapEntry *entry = 
_tpia_map_addEntry( smr, map, tpia_mapEntry_type_path, NULL, path, NULL, projectile, NULL );
 
  240     if( entry != NULL ) {
 
  241         if( ( entry->map = 
tpia_map_readFile( smr, map->path, entry->path ) ) == NULL ) entry = NULL;
 
  243     return( entry != NULL );
 
  248 static tpia_mapEntry *
_tpia_map_addEntry( statusMessageReporting *smr, tpia_map *map, 
enum tpia_mapEntry_type type, 
const char *schema, 
const char *path, 
 
  249     const char *evaluation, 
const char *projectile, 
const char *targetName ) {
 
  252     tpia_mapEntry *entry;
 
  255     if( ( entry = (tpia_mapEntry*) xData_malloc2( smr, 
sizeof( tpia_mapEntry ), 1, 
"entry" ) ) == NULL ) 
return( NULL );
 
  262         if( ( entry->path = (
char*) xData_malloc2( smr, strlen( path ) + 1, 0, 
"path" ) ) == NULL ) {
 
  266         strcpy( entry->path, path );
 
  268     entry->evaluation = NULL;
 
  269     if( evaluation != NULL ) {
 
  271         if( ( entry->evaluation = (
char*) xData_malloc2( smr, strlen( evaluation ) + 1, 0, 
"evaluation" ) ) == NULL ) {
 
  276         strcpy( entry->evaluation, evaluation );
 
  278     entry->projectile = NULL;
 
  279     if( projectile != NULL ) {
 
  281         if( ( entry->projectile = (
char*) xData_malloc2( smr, strlen( projectile ) + 1, 0, 
"projectile" ) ) == NULL ) {
 
  287         strcpy( entry->projectile, projectile );
 
  289     entry->targetName = NULL;
 
  290     if( targetName != NULL ) {
 
  292         if( ( entry->targetName = (
char*) xData_malloc2( smr, strlen( targetName ) + 1, 0, 
"target" ) ) == NULL ) {
 
  299         strcpy( entry->targetName, targetName );
 
  301     entry->schema = NULL;
 
  302     if( schema != NULL ) {
 
  304         if( ( entry->schema = (
char*) xData_malloc2( smr, strlen( schema ) + 1, 0, 
"schema" ) ) == NULL ) {
 
  312         strcpy( entry->schema, schema );
 
  315     if( map->mapEntries == NULL ) {
 
  316         map->mapEntries = entry; }
 
  318         for( p = map->mapEntries; p->next != NULL; p = p->next ){;}
 
  321     map->numberOfEntries++;
 
  327 char *
tpia_map_findTarget( statusMessageReporting *smr, tpia_map *map, 
const char *evaluation, 
const char *projectile, 
const char *targetName ) {
 
  333     if( map->status != tpia_map_status_Ok ) 
return( NULL );
 
  336     if( ( path == NULL ) && 
smr_isOk( smr ) ) {
 
  337         if( evaluation == NULL ) {
 
  338             smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, 1, 
"target %s for projectile %s not found", targetName, projectile ); }
 
  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 ) {
 
  350     tpia_mapEntry *entry;
 
  354     for( entry = map->mapEntries; entry != NULL; entry = entry->next ) {
 
  355         switch( entry->type ) {
 
  356         case tpia_mapEntry_type_target :
 
  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 );
 
  378         case tpia_mapEntry_type_path :
 
  379             if( !strcmp( projectile, entry->projectile ) ) {
 
  380                 if( ( path = 
_tpia_map_findTarget2( smr, entry->map, evaluation, projectile, targetName ) ) != NULL ) 
return( path );
 
  384             smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, 
"unknown type = %d", entry->type );
 
  398     tpia_map *mapAllOfTarget;
 
  400     if( map->status != tpia_map_status_Ok ) 
return( NULL );
 
  401     if( ( mapAllOfTarget = 
tpia_map_create( smr ) ) == NULL ) 
return( NULL );
 
  404     if( ( status != 0 ) ) mapAllOfTarget = (tpia_map*) 
tpia_map_free( smr, mapAllOfTarget );
 
  405     return( mapAllOfTarget );
 
  410 static int _tpia_map_findAllOfTarget2( statusMessageReporting *smr, tpia_map *mapAllOfTarget, tpia_map *map, 
const char *projectile, 
const char *targetName ) {
 
  412     tpia_mapEntry *entry;
 
  414     for( entry = map->mapEntries; entry != NULL; entry = entry->next ) {
 
  415         switch( entry->type ) {
 
  416         case tpia_mapEntry_type_target :
 
  417             if( !strcmp( projectile, entry->projectile ) && ( !strcmp( targetName, entry->targetName ) ) ) {
 
  418                 if( 
_tpia_map_addEntry( smr, mapAllOfTarget, entry->type, entry->schema, entry->path, entry->evaluation, entry->projectile, 
 
  419                     entry->targetName ) == NULL ) 
return( 1 );
 
  422         case tpia_mapEntry_type_path :
 
  423             if( !strcmp( projectile, entry->projectile ) ) {
 
  428             smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, 
"unknown type = %d", entry->type );
 
  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 );
 
  457 int tpia_map_walkTree( statusMessageReporting *smr, tpia_map *map, 
int (*handler)( tpia_mapEntry *entry, 
int level, 
void *
userData), 
void *userData ) {
 
  464 static int _tpia_map_walkTree2( statusMessageReporting *smr, tpia_map *map, 
int level, 
int (*handler)( tpia_mapEntry *entry, 
int level, 
void *
userData), 
 
  467     tpia_mapEntry *entry;
 
  469     for( entry = map->mapEntries; entry != NULL; entry = entry->next ) {
 
  470         if( handler( entry, level, userData ) != 0 ) 
return( 1 );
 
  471         if( entry->type == tpia_mapEntry_type_path ) 
if( 
_tpia_map_walkTree2( smr, entry->map, level + 1, handler, userData ) != 0 ) 
return( 1 );
 
  480     tpia_mapEntry *entry;
 
  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;
 
  489     if( map->status != tpia_map_status_Ok ) 
return( NULL );
 
  491     n = nStart + nEnd + 1;
 
  492     for( entry = map->mapEntries; entry != NULL; entry = entry->next ) {
 
  493         switch( entry->type ) {
 
  494         case tpia_mapEntry_type_target :
 
  495             n += strlen( entry->schema ) + strlen( entry->path ) + strlen( entry->evaluation ) + strlen( entry->projectile ) + strlen( entry->targetName ) + nTarget;
 
  497         case tpia_mapEntry_type_path :
 
  498             n += strlen( entry->path ) + strlen( entry->projectile ) + nPath;
 
  501             smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, 
"unknown type = %d", 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 ) {
 
  512         case tpia_mapEntry_type_target :
 
  513             sprintf( p, targetFormat, entry->schema, entry->evaluation, entry->projectile, entry->targetName, entry->path );
 
  515         case tpia_mapEntry_type_path :
 
  516             sprintf( p, pathFormat, entry->projectile, entry->path );
 
  533     tpia_mapEntry *entry;
 
  535     int n = strlen( sLevel ) / 4;
 
  537     if( map->status != tpia_map_status_Ok ) {
 
  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 ) {
 
  546         case tpia_mapEntry_type_target :
 
  547             fprintf( f, 
"%sType = target: schema = %s: evaluation = %s: projectile = %s: target = %s: path = %s\n", sLevel, entry->schema, 
 
  548                 entry->evaluation, entry->projectile, entry->targetName, entry->path );
 
  550         case tpia_mapEntry_type_path :
 
  551             fprintf( f, 
"%sType =   path: projectile = %s: path = %s\n", sLevel, entry->projectile, entry->path );
 
  555             fprintf( f, 
"%sUnknown type = %d\n", sLevel, entry->type );
 
  564     tpia_map_smr *smrUserInterface = (tpia_map_smr *) userData;
 
  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 );
 
  572         strcat( *str, smrUserInterface->map->mapFileName );
 
  577 #if defined __cplusplus 
int tpia_map_walkTree(statusMessageReporting *smr, tpia_map *map, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData)
 
tpia_map * tpia_map_readFile(statusMessageReporting *smr, const char *basePath, const char *mapFileName)
 
int tpia_map_addTarget(statusMessageReporting *smr, tpia_map *map, const char *schema, const char *path, const char *evaluation, const char *projectile, const char *target)
 
char * tpia_map_findTarget(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName)
 
xData_element * xData_getNextElement(xData_element *element)
 
xData_document * xData_parseReadFile(statusMessageReporting *smr, const char *fileName, xData_xDataTypeOk func, void *userData)
 
int smr_setMessageError(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)
 
const char * xData_getAttributesValueInElement(xData_element *element, const char *name)
 
xData_element * xData_getFirstElement(xData_element *element)
 
tpia_map * tpia_map_create(statusMessageReporting *smr)
 
xData_element * xData_getDocumentsElement(xData_document *doc)
 
void * xData_parseFree(statusMessageReporting *smr, xData_document *doc)
 
static tpia_mapEntry * _tpia_map_addEntry(statusMessageReporting *smr, tpia_map *map, enum tpia_mapEntry_type type, const char *schema, const char *path, const char *evaluation, const char *projectile, const char *target)
 
int smr_isOk(statusMessageReporting *smr)
 
char * tpia_map_toXMLString(statusMessageReporting *smr, tpia_map *map)
 
static int _tpia_map_walkTree2(statusMessageReporting *smr, tpia_map *map, int level, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData)
 
static void _tpia_map_simpleWrite2(FILE *f, tpia_map *map, int level)
 
tpia_mapEntry * tpia_map_getNextEntry(tpia_mapEntry *entry)
 
static char * _tpia_map_findTarget2(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *target)
 
int tpia_map_addPath(statusMessageReporting *smr, tpia_map *map, const char *path, const char *projectile)
 
void tpia_map_simpleWrite(FILE *f, tpia_map *map)
 
tpia_map * tpia_map_findAllOfTarget(statusMessageReporting *smr, tpia_map *map, const char *projectile, const char *targetName)
 
tpia_mapEntry * tpia_map_getFirstEntry(tpia_map *map)
 
void * xData_free(statusMessageReporting *, void *p)
 
int tpia_map_initialize(statusMessageReporting *, tpia_map *map)
 
char * tpia_map_getFullPath(statusMessageReporting *smr, tpia_map *map, const char *endPath)
 
static int _tpia_map_smrUserInterface(void *userData, char **str)
 
static int _tpia_map_findAllOfTarget2(statusMessageReporting *smr, tpia_map *mapAllOfTarget, tpia_map *map, const char *projectile, const char *targetName)
 
void * tpia_map_free(statusMessageReporting *smr, tpia_map *map)
 
void tpia_map_release(statusMessageReporting *smr, tpia_map *map)
 
int smr_setMessageInfo(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)