17#define realpath( a, b ) GetFullPathName( a, PATH_MAX, b, NULL )
20static int aliasesNeeded = 1;
22#if defined __cplusplus
28 const char *evaluation,
const char *projectile,
const char *target );
30 int projectile_PoPID,
int target_PoPID );
32 int projectile_PoPID,
int target_PoPID );
35static void _MCGIDI_map_simpleWrite2( FILE *f,
MCGIDI_map *map,
int level );
36static char *_MCGIDI_map_smrUserInterface(
void *
userData );
37#if defined __cplusplus
42#if defined __cplusplus
75 char const *aliases[] = {
"Co58m1",
"Ag110m1",
"Cd115m1",
"Te127m1",
"Te129m1",
"Pm148m1",
"Ho166m1",
"Am242m1",
"Am244m1",
"Es254m1" };
76 char const *targets[] = {
"Co58_e1",
"Ag110_e2",
"Cd115_e1",
"Te127_e2",
"Te129_e1",
"Pm148_e2",
"Ho166_e1",
"Am242_e2",
"Am244_e1",
"Es254_e2" };
77 int i1, n1 =
sizeof( aliases ) /
sizeof( aliases[1] );
80 for( i1 = 0; i1 < n1; i1++ ) {
102 const char *evaluation, *projectile, *targetName, *path, *schema;
107 if( ( basePath == NULL ) || ( mapFileName[0] ==
'/' ) ) {
108 strcpy( realPath, mapFileName ); }
110 strcpy( realPath, basePath );
111 strcat( realPath,
"/" );
112 strcat( realPath, mapFileName );
114 if( realpath( realPath, p ) == NULL ) {
118 n = (int) strlen( p ) + 2;
122 strcpy( map->
path, p );
123 if( ( p = strrchr( map->
path,
'/' ) ) != NULL ) {
126 strcpy( map->
path,
"." );
133 if( strcmp( child->
name,
"path" ) == 0 ) {
139 else if( strcmp( child->
name,
"target" ) == 0 ) {
187 for( entry = map->
mapEntries; entry != NULL; entry = next ) {
213 return( entry->
next );
229 if( entry != NULL ) {
232 return( entry != NULL );
238 const char *path,
const char *evaluation,
const char *projectile,
const char *targetName ) {
256 if( ( entry->
path = (
char *)
smr_malloc2( smr, strlen( path ) + 1, 0,
"path" ) ) == NULL )
goto err;
257 strcpy( entry->
path, path );
260 if( evaluation != NULL ) {
261 if( ( entry->
evaluation = (
char *)
smr_malloc2( smr, strlen( evaluation ) + 1, 0,
"evaluation" ) ) == NULL )
goto err;
265 if( projectile != NULL ) {
267 if( ( entry->
projectile = (
char *)
smr_malloc2( smr, strlen( projectile ) + 1, 0,
"projectile" ) ) == NULL )
goto err;
271 if( targetName != NULL ) {
273 if( ( entry->
targetName = (
char *)
smr_malloc2( smr, strlen( targetName ) + 1, 0,
"target" ) ) == NULL )
goto err;
277 if( schema != NULL ) {
278 if( ( entry->
schema = (
char *)
smr_malloc2( smr, strlen( schema ) + 1, 0,
"schema" ) ) == NULL )
goto err;
279 strcpy( entry->
schema, schema );
303 int projectile_PoPID,
int target_PoPID ) {
311 if( !
smr_isOk( smr ) )
return( NULL );
314 path = _MCGIDI_map_findTargetViaPoPIDs2( smr, map, evaluation, projectile_PoPID, target_PoPID );
315 if( ( path == NULL ) &&
smr_isOk( smr ) ) {
316 if( evaluation == NULL ) {
318 targetName, projectileName ); }
321 targetName, projectileName, evaluation );
330 int projectile_PoPID,
int target_PoPID ) {
336 if( evaluation != NULL ) {
337 if( strlen( evaluation ) == 0 ) evaluation = NULL;
340 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
341 switch( entry->
type ) {
344 if( evaluation == NULL ) {
347 status = strcmp( evaluation, entry->
evaluation ) == 0;
350 n = (int) strlen( map->
path ) + 1 + (int) strlen( entry->
path ) + 1;
351 if( ( path = (
char * )
smr_malloc2( smr, n, 0,
"path" ) ) == NULL )
return( NULL );
352 strcpy( path, map->
path );
354 if( entry->
path[0] ==
'/' ) {
355 strcpy( path, entry->
path ); }
357 strcat( path, entry->
path );
364 if( ( path = _MCGIDI_map_findTargetViaPoPIDs2( smr, entry->
map, evaluation, projectile_PoPID, target_PoPID ) ) != NULL )
return( path );
378 int projectile_PoPID, target_PoPID;
396 if( ( mapAllOfTarget =
MCGIDI_map_new( smr ) ) == NULL )
return( NULL );
397 status = _MCGIDI_map_findAllOfTargetViaPoPIDs2( smr, mapAllOfTarget, map, projectile_PoPID, target_PoPID );
399 return( mapAllOfTarget );
405 int projectile_PoPID,
int target_PoPID ) {
409 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
410 switch( entry->
type ) {
418 if( _MCGIDI_map_findAllOfTargetViaPoPIDs2( smr, mapAllOfTarget, entry->
map, projectile_PoPID, target_PoPID ) != 0 )
return( 1 );
432 int projectile_PoPID, target_PoPID;
445 if( endPath[0] ==
'/' ) {
446 if( ( path = (
char *)
smr_malloc2( smr, strlen( endPath ) + 1, 0,
"path" ) ) == NULL )
return( NULL );
449 if( ( path = (
char *)
smr_malloc2( smr, strlen( map->
path ) + strlen( endPath ) + 2, 0,
"path" ) ) == NULL )
return( NULL );
450 strcpy( path, map->
path );
453 strcat( path, endPath );
464 switch( target->
type ) {
485 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
486 if( handler( entry, level,
userData ) != 0 )
return( 1 );
496 return( _MCGIDI_map_walkTree2( smr, map, 0, handler,
userData ) );
505 char targetFormat[] =
"<target schema=\"%s\" evaluation=\"%s\" projectile=\"%s\" target=\"%s\" path=\"%s\"/>\n";
506 char pathFormat[] =
"<path projectile=\"%s\" path=\"%s\"/>\n";
507 char start[] =
"<map>\n";
508 char end[] =
"</map>";
509 int n = 0, nStart = (int) strlen( start ), nEnd = (int) strlen( end );
510 int nTarget = (int) strlen( targetFormat ) - 10, nPath = (int) strlen( pathFormat ) - 4;
514 n = nStart + nEnd + 1;
515 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
516 switch( entry->
type ) {
521 n += (int ) strlen( entry->
path ) + (int ) strlen( entry->
projectile ) + nPath;
529 if( ( s = (
char *)
smr_malloc2( smr, n, 0,
"xml string" ) ) == NULL )
return( NULL );
533 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
534 switch( entry->
type ) {
554static void _MCGIDI_map_simpleWrite2( FILE *f,
MCGIDI_map *map,
int level ) {
558 int n = (int ) strlen( sLevel ) / 4;
561 fprintf( f,
"Bad map status = %d\n", map->
status );
564 if( level < n ) sLevel[4 * level] = 0;
565 fprintf( f,
"%smap->path = %s\n", sLevel, map->
path );
566 fprintf( f,
"%smap->mapFileName = %s\n", sLevel, map->
mapFileName );
567 for( entry = map->
mapEntries; entry != NULL; entry = entry->
next ) {
568 switch( entry->
type ) {
570 fprintf( f,
"%sType = target: schema = %s: evaluation = %s: projectile = %s: target = %s: path = %s\n", sLevel, entry->
schema,
574 fprintf( f,
"%sType = path: path = %s\n", sLevel, entry->
path );
575 _MCGIDI_map_simpleWrite2( f, entry->
map, level + 1 );
578 fprintf( f,
"%sUnknown type = %d\n", sLevel, entry->
type );
585static char *_MCGIDI_map_smrUserInterface(
void *
userData ) {
592#if defined __cplusplus
int MCGIDI_map_addPath(statusMessageReporting *smr, MCGIDI_map *map, const char *path)
char * MCGIDI_map_getFullPath(statusMessageReporting *smr, MCGIDI_map *map, const char *endPath)
MCGIDI_map * MCGIDI_map_readFile(statusMessageReporting *smr, const char *basePath, const char *mapFileName)
int MCGIDI_map_walkTree(statusMessageReporting *smr, MCGIDI_map *map, int(*handler)(MCGIDI_mapEntry *entry, int level, void *userData), void *userData)
void * MCGIDI_map_free(statusMessageReporting *smr, MCGIDI_map *map)
char * MCGIDI_map_findTarget(statusMessageReporting *smr, MCGIDI_map *map, const char *evaluation, const char *projectile, const char *targetName)
MCGIDI_mapEntry * MCGIDI_map_getFirstEntry(MCGIDI_map *map)
@ MCGIDI_map_status_UnknownType
@ MCGIDI_map_status_mapParsing
MCGIDI_mapEntry * MCGIDI_map_getNextEntry(MCGIDI_mapEntry *entry)
MCGIDI_map * MCGIDI_map_findAllOfTargetViaPoPIDs(statusMessageReporting *smr, MCGIDI_map *map, int projectile_PoPID, int target_PoPID)
@ MCGIDI_mapEntry_type_target
@ MCGIDI_mapEntry_type_path
void MCGIDI_map_simpleWrite(FILE *f, MCGIDI_map *map)
char * MCGIDI_map_findTargetViaPoPIDs(statusMessageReporting *smr, MCGIDI_map *map, const char *evaluation, int projectile_PoPID, int target_PoPID)
int MCGIDI_map_addTarget(statusMessageReporting *smr, MCGIDI_map *map, const char *method, const char *path, const char *evaluation, const char *projectile, const char *targetName)
void MCGIDI_map_release(statusMessageReporting *smr, MCGIDI_map *map)
MCGIDI_map * MCGIDI_map_new(statusMessageReporting *smr)
char * MCGIDI_map_toXMLString(statusMessageReporting *smr, MCGIDI_map *map)
MCGIDI_map * MCGIDI_map_findAllOfTarget(statusMessageReporting *smr, MCGIDI_map *map, const char *projectile, const char *targetName)
int MCGIDI_map_initialize(statusMessageReporting *smr, MCGIDI_map *map)
char * MCGIDI_map_getTargetsFullPath(statusMessageReporting *smr, MCGIDI_mapEntry *target)
char const * PoPs_getName_atIndex(statusMessageReporting *smr, int index)
int lPoPs_addParticleIfNeeded(statusMessageReporting *smr, char const *name, char const *special)
PoP * PoPs_addAliasIfNeeded(statusMessageReporting *smr, char const *name, char const *alias)
#define smr_setReportInfo3(smr, userInterface, libraryID, code, fmt,...)
#define smr_setReportError2(smr, libraryID, code, fmt,...)
#define smr_setReportError3(smr, userInterface, libraryID, code, fmt,...)
#define smr_setReportInfo3p(smr, userInterface, libraryID, code, fmt)
void * smr_freeMemory(void **p)
#define smr_setReportError3p(smr, userInterface, libraryID, code, fmt)
int smr_isOk(statusMessageReporting *smr)
char * smr_allocateFormatMessage(char const *fmt,...)
#define smr_malloc2(smr, size, zero, forItem)
int globalPoPsIndexProjectile
int globalPoPsIndexTarget
enum MCGIDI_mapEntry_type type
enum MCGIDI_map_status status
MCGIDI_map_smr smrUserInterface
MCGIDI_mapEntry * mapEntries
smr_userInterface smrUserInterface
void * xDataXML_freeDoc(statusMessageReporting *smr, xDataXML_document *doc)
xDataXML_element * xDataXML_getNextElement(xDataXML_element *element)
xDataXML_element * xDataXML_getDocumentsElement(xDataXML_document *doc)
char const * xDataXML_getAttributesValueInElement(xDataXML_element *element, char const *name)
xDataXML_element * xDataXML_getFirstElement(xDataXML_element *element)
xDataXML_document * xDataXML_importFile2(statusMessageReporting *smr, char const *fileName)