Geant4  10.01.p03
tpia_map.cc
Go to the documentation of this file.
1 /*
2 # <<BEGIN-copyright>>
3 # Copyright (c) 2010, Lawrence Livermore National Security, LLC.
4 # Produced at the Lawrence Livermore National Laboratory
5 # Written by Bret R. Beck, beck6@llnl.gov.
6 # CODE-461393
7 # All rights reserved.
8 #
9 # This file is part of GIDI. For details, see nuclear.llnl.gov.
10 # Please also read the "Additional BSD Notice" at nuclear.llnl.gov.
11 #
12 # Redistribution and use in source and binary forms, with or without modification,
13 # are permitted provided that the following conditions are met:
14 #
15 # 1) Redistributions of source code must retain the above copyright notice,
16 # this list of conditions and the disclaimer below.
17 # 2) Redistributions in binary form must reproduce the above copyright notice,
18 # this list of conditions and the disclaimer (as noted below) in the
19 # documentation and/or other materials provided with the distribution.
20 # 3) Neither the name of the LLNS/LLNL nor the names of its contributors may be
21 # used to endorse or promote products derived from this software without
22 # specific prior written permission.
23 #
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
25 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 # SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
28 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33 # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # <<END-copyright>>
35 */
36 #include <string.h>
37 #include <limits.h>
38 #ifdef WIN32
39  #include <Shlwapi.h>
40 #endif
41 #include <tpia_map.h>
42 
43 #if defined __cplusplus
44 namespace GIDI {
45 using namespace GIDI;
46 #endif
47 
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),
53  void *userData );
54 static void _tpia_map_simpleWrite2( FILE *f, tpia_map *map, int level );
55 static int _tpia_map_smrUserInterface( void *userData, char **str );
56 /*
57 ************************************************************
58 */
59 tpia_map *tpia_map_create( statusMessageReporting *smr ) {
60 
61  tpia_map *map;
62 
63  //if( ( map = xData_malloc2( smr, sizeof( tpia_map ), 0, "map" ) ) == NULL ) return( NULL );
64  if( ( map = (tpia_map*) xData_malloc2( smr, sizeof( tpia_map ), 0, "map" ) ) == NULL ) return( NULL );
65  //if( tpia_map_initialize( smr, map ) ) map = tpia_map_free( NULL, map );
66  if( tpia_map_initialize( smr, map ) ) map = (tpia_map*) tpia_map_free( NULL, map );
67  return( map );
68 }
69 /*
70 ************************************************************
71 */
72 //int tpia_map_initialize( statusMessageReporting *smr, tpia_map *map ) {
73 int tpia_map_initialize( statusMessageReporting *, tpia_map *map ) {
74 
75  memset( map, 0, sizeof( tpia_map ) );
76  map->status = tpia_map_status_Ok;
77  map->smrUserInterface.smrUserInterface = _tpia_map_smrUserInterface;
78  map->smrUserInterface.map = map;
79  map->path = NULL;
80  map->mapFileName = NULL;
81  map->numberOfEntries = 0;
82  map->mapEntries = NULL;
83  return( 0 );
84 }
85 /*
86 ************************************************************
87 */
88 tpia_map *tpia_map_readFile( statusMessageReporting *smr, const char *basePath, const char *mapFileName ) {
89 /*
90 * If an error occurrs, map is freed and NULL is returned.
91 */
92  int n = 0;
93  xData_document *doc;
94  xData_element *element;
95  xData_element *child;
96  tpia_map *map;
97  const char *evaluation, *projectile, *targetName, *path, *schema;
98 #ifndef WIN32
99  char realPath[2 * ( PATH_MAX + 1 )], *p = &(realPath[PATH_MAX+1]);
100 #endif
101 #ifdef WIN32
102  char realPath[2 * ( _MAX_PATH + 1 )], *p = &(realPath[_MAX_PATH+1]);
103 #endif
104 
105  if( ( map = tpia_map_create( smr ) ) == NULL ) return( NULL );
106 
107  if( ( basePath == NULL ) || ( mapFileName[0] == '/' ) ) {
108  strcpy( realPath, mapFileName ); }
109  else {
110  strcpy( realPath, basePath );
111  strcat( realPath, "/" );
112  strcat( realPath, mapFileName );
113  }
114 #ifndef WIN32
115  if( realpath( realPath, p ) == NULL ) {
116  smr_setMessageError( smr, NULL, __FILE__, __LINE__, tpia_map_status_mapParsing, "No map file %s\n", mapFileName );
117  //return( tpia_map_free( NULL, map ) );
118  return( (tpia_map*) tpia_map_free( NULL, map ) );
119  }
120 #endif
121  n = strlen( p ) + 2;
122  //if( ( map->path = xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( tpia_map_free( NULL, map ) );
123  //if( ( map->path = (char*) xData_malloc2( smr, 2 * n, 0, "map->path" ) ) == NULL ) return( tpia_map_free( NULL, map ) );
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 ) {
129  *p = 0; }
130  else {
131  strcpy( map->path, "." );
132  }
133 
134  //if( ( doc = xData_parseReadFile( smr, map->mapFileName, NULL, NULL ) ) == NULL ) return( tpia_map_free( NULL, map ) );
135  if( ( doc = xData_parseReadFile( smr, map->mapFileName, NULL, NULL ) ) == NULL ) return( (tpia_map*) tpia_map_free( NULL, map ) );
136 
137  element = xData_getDocumentsElement( doc );
138  for( child = xData_getFirstElement( element ); child != NULL; child = xData_getNextElement( child ) ) {
139  if( !strcmp( child->name, "path" ) ) {
140  if( ( path = xData_getAttributesValueInElement( child , "path" ) ) == NULL ) {
141  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "path missing path attribute" );
142  break;
143  }
144  if( ( projectile = xData_getAttributesValueInElement( child , "projectile" ) ) == NULL ) {
145  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "path missing projectile attribute" );
146  break;
147  }
148  tpia_map_addPath( smr, map, path, projectile ); }
149  else if( !strcmp( child->name, "target" ) ) {
150  if( ( schema = xData_getAttributesValueInElement( child , "schema" ) ) == NULL ) {
151  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'schema' attribute" );
152  break;
153  }
154  if( ( path = xData_getAttributesValueInElement( child , "path" ) ) == NULL ) {
155  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'path' attribute" );
156  break;
157  }
158  if( ( evaluation = xData_getAttributesValueInElement( child , "evaluation" ) ) == NULL ) {
159  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'evaluation' attribute" );
160  break;
161  }
162  if( ( projectile = xData_getAttributesValueInElement( child , "projectile" ) ) == NULL ) {
163  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'projectile' attribute" );
164  break;
165  }
166  if( ( targetName = xData_getAttributesValueInElement( child , "target" ) ) == NULL ) {
167  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "target missing 'target' attribute" );
168  break;
169  }
170  tpia_map_addTarget( smr, map, schema, path, evaluation, projectile, targetName ); }
171  else {
172  smr_setMessageError( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_mapParsing, "invalid element = %s", child->name );
173  }
174  if( !smr_isOk( smr ) ) break;
175  }
176  xData_parseFree( smr, doc );
177  //if( !smr_isOk( smr ) ) map = tpia_map_free( NULL, map );
178  if( !smr_isOk( smr ) ) map = (tpia_map*) tpia_map_free( NULL, map );
179  return( map );
180 }
181 /*
182 ************************************************************
183 */
184 void *tpia_map_free( statusMessageReporting *smr, tpia_map *map ) {
185 
186  tpia_map_release( smr, map );
187  xData_free( smr, map );
188  return( NULL );
189 }
190 /*
191 ************************************************************
192 */
193 void tpia_map_release( statusMessageReporting *smr, tpia_map *map ) {
194 
195  tpia_mapEntry *entry, *next;
196 
197  if( map->path != NULL ) xData_free( NULL, map->path );
198  for( entry = map->mapEntries; entry != NULL; entry = next ) {
199  next = 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 );
205  if( entry->map != NULL ) tpia_map_free( smr, entry->map );
206  xData_free( NULL, entry );
207  }
208  map->numberOfEntries = 0;
209  map->mapEntries = NULL;
210  map->status = tpia_map_status_Ok;
211 }
212 /*
213 ************************************************************
214 */
215 tpia_mapEntry *tpia_map_getFirstEntry( tpia_map *map ) {
216 
217  return( map->mapEntries );
218 }
219 /*
220 ************************************************************
221 */
222 tpia_mapEntry *tpia_map_getNextEntry( tpia_mapEntry *entry ) {
223 
224  return( entry->next );
225 }
226 /*
227 ************************************************************
228 */
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 ) {
230 
231  return( _tpia_map_addEntry( smr, map, tpia_mapEntry_type_target, schema, path, evaluation, projectile, target ) != NULL );
232 }
233 /*
234 ************************************************************
235 */
236 int tpia_map_addPath( statusMessageReporting *smr, tpia_map *map, const char *path, const char *projectile ) {
237 
238  tpia_mapEntry *entry = _tpia_map_addEntry( smr, map, tpia_mapEntry_type_path, NULL, path, NULL, projectile, NULL );
239 
240  if( entry != NULL ) {
241  if( ( entry->map = tpia_map_readFile( smr, map->path, entry->path ) ) == NULL ) entry = NULL;
242  }
243  return( entry != NULL );
244 }
245 /*
246 ************************************************************
247 */
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 ) {
250 
251  tpia_mapEntry *p;
252  tpia_mapEntry *entry;
253 
254  //if( ( entry = xData_malloc2( smr, sizeof( tpia_mapEntry ), 1, "entry" ) ) == NULL ) return( NULL );
255  if( ( entry = (tpia_mapEntry*) xData_malloc2( smr, sizeof( tpia_mapEntry ), 1, "entry" ) ) == NULL ) return( NULL );
256  entry->next = NULL;
257  entry->type = type;
258  entry->path = NULL;
259  entry->map = NULL;
260  if( path != NULL ) {
261  //if( ( entry->path = xData_malloc2( smr, strlen( path ) + 1, 0, "path" ) ) == NULL ) {
262  if( ( entry->path = (char*) xData_malloc2( smr, strlen( path ) + 1, 0, "path" ) ) == NULL ) {
263  xData_free( smr, entry );
264  return( NULL );
265  }
266  strcpy( entry->path, path );
267  }
268  entry->evaluation = NULL;
269  if( evaluation != NULL ) {
270  //if( ( entry->evaluation = xData_malloc2( smr, strlen( evaluation ) + 1, 0, "evaluation" ) ) == NULL ) {
271  if( ( entry->evaluation = (char*) xData_malloc2( smr, strlen( evaluation ) + 1, 0, "evaluation" ) ) == NULL ) {
272  xData_free( smr, entry->path );
273  xData_free( smr, entry );
274  return( NULL );
275  }
276  strcpy( entry->evaluation, evaluation );
277  }
278  entry->projectile = NULL;
279  if( projectile != NULL ) {
280  //if( ( entry->projectile = xData_malloc2( smr, strlen( projectile ) + 1, 0, "projectile" ) ) == NULL ) {
281  if( ( entry->projectile = (char*) xData_malloc2( smr, strlen( projectile ) + 1, 0, "projectile" ) ) == NULL ) {
282  xData_free( smr, entry->evaluation );
283  xData_free( smr, entry->path );
284  xData_free( smr, entry );
285  return( NULL );
286  }
287  strcpy( entry->projectile, projectile );
288  }
289  entry->targetName = NULL;
290  if( targetName != NULL ) {
291  //if( ( entry->targetName = xData_malloc2( smr, strlen( targetName ) + 1, 0, "target" ) ) == NULL ) {
292  if( ( entry->targetName = (char*) xData_malloc2( smr, strlen( targetName ) + 1, 0, "target" ) ) == NULL ) {
293  xData_free( smr, entry->path );
294  xData_free( smr, entry->evaluation );
295  xData_free( smr, entry->projectile );
296  xData_free( smr, entry );
297  return( NULL );
298  }
299  strcpy( entry->targetName, targetName );
300  }
301  entry->schema = NULL;
302  if( schema != NULL ) {
303  //if( ( entry->schema = xData_malloc2( smr, strlen( schema ) + 1, 0, "schema" ) ) == NULL ) {
304  if( ( entry->schema = (char*) xData_malloc2( smr, strlen( schema ) + 1, 0, "schema" ) ) == NULL ) {
305  xData_free( smr, entry->path );
306  xData_free( smr, entry->evaluation );
307  xData_free( smr, entry->projectile );
308  xData_free( smr, entry->targetName );
309  xData_free( smr, entry );
310  return( NULL );
311  }
312  strcpy( entry->schema, schema );
313  }
314 
315  if( map->mapEntries == NULL ) {
316  map->mapEntries = entry; }
317  else {
318  for( p = map->mapEntries; p->next != NULL; p = p->next ){;}
319  p->next = entry;
320  }
321  map->numberOfEntries++;
322  return( entry );
323 }
324 /*
325 ************************************************************
326 */
327 char *tpia_map_findTarget( statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName ) {
328 /*
329 * Calling routine must free returned pointer.
330 */
331  char *path;
332 
333  if( map->status != tpia_map_status_Ok ) return( NULL );
334 
335  path = _tpia_map_findTarget2( smr, map, evaluation, projectile, targetName );
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 ); }
339  else {
340  smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, 1, "target %s for projectile %s and evaluation %s not found", targetName, projectile, evaluation );
341  }
342  }
343  return( path );
344 }
345 /*
346 ************************************************************
347 */
348 static char *_tpia_map_findTarget2( statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName ) {
349 
350  tpia_mapEntry *entry;
351  char *path = NULL;
352  int n, status;
353 
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 ) {
359  status = 1; }
360  else {
361  status = !strcmp( evaluation, entry->evaluation );
362  }
363  if( status ) {
364  n = strlen( map->path ) + 1 + strlen( entry->path ) + 1;
365  //if( ( path = xData_malloc2( smr, n, 0, "path" ) ) == NULL ) return( NULL );
366  if( ( path = (char*) xData_malloc2( smr, n, 0, "path" ) ) == NULL ) return( NULL );
367  strcpy( path, map->path );
368  strcat( path, "/" );
369  if( entry->path[0] == '/' ) {
370  strcpy( path, entry->path ); }
371  else {
372  strcat( path, entry->path );
373  }
374  return( path );
375  }
376  }
377  break;
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 );
381  }
382  break;
383  default :
384  smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, "unknown type = %d", entry->type );
385  return( NULL );
386  }
387  }
388  return( NULL );
389 }
390 /*
391 ************************************************************
392 */
393 tpia_map *tpia_map_findAllOfTarget( statusMessageReporting *smr, tpia_map *map, const char *projectile, const char *targetName ) {
394 /*
395 * Calling routine must free returned pointer.
396 */
397  int status;
398  tpia_map *mapAllOfTarget;
399 
400  if( map->status != tpia_map_status_Ok ) return( NULL );
401  if( ( mapAllOfTarget = tpia_map_create( smr ) ) == NULL ) return( NULL );
402  status = _tpia_map_findAllOfTarget2( smr, mapAllOfTarget, map, projectile, targetName );
403  //if( ( status != 0 ) ) mapAllOfTarget = tpia_map_free( smr, mapAllOfTarget );
404  if( ( status != 0 ) ) mapAllOfTarget = (tpia_map*) tpia_map_free( smr, mapAllOfTarget );
405  return( mapAllOfTarget );
406 }
407 /*
408 ************************************************************
409 */
410 static int _tpia_map_findAllOfTarget2( statusMessageReporting *smr, tpia_map *mapAllOfTarget, tpia_map *map, const char *projectile, const char *targetName ) {
411 
412  tpia_mapEntry *entry;
413 
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 );
420  }
421  break;
422  case tpia_mapEntry_type_path :
423  if( !strcmp( projectile, entry->projectile ) ) {
424  if( _tpia_map_findAllOfTarget2( smr, mapAllOfTarget, entry->map, projectile, targetName ) != 0 ) return( 1 );
425  }
426  break;
427  default :
428  smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, "unknown type = %d", entry->type );
429  return( 1 );
430  }
431  }
432  return( 0 );
433 }
434 /*
435 ************************************************************
436 */
437 char *tpia_map_getFullPath( statusMessageReporting *smr, tpia_map *map, const char *endPath ) {
438 
439  char *path;
440 
441  if( endPath[0] == '/' ) {
442  //if( ( path = xData_malloc2( smr, strlen( endPath ) + 1, 0, "path" ) ) == NULL ) return( NULL );
443  if( ( path = (char*) xData_malloc2( smr, strlen( endPath ) + 1, 0, "path" ) ) == NULL ) return( NULL );
444  path[0] = 0; }
445  else {
446  //if( ( path = xData_malloc2( smr, strlen( map->path ) + strlen( endPath ) + 2, 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 );
449  strcat( path, "/" );
450  }
451  strcat( path, endPath );
452  return( path );
453 }
454 /*
455 ************************************************************
456 */
457 int tpia_map_walkTree( statusMessageReporting *smr, tpia_map *map, int (*handler)( tpia_mapEntry *entry, int level, void *userData), void *userData ) {
458 
459  return( _tpia_map_walkTree2( smr, map, 0, handler, userData ) );
460 }
461 /*
462 ************************************************************
463 */
464 static int _tpia_map_walkTree2( statusMessageReporting *smr, tpia_map *map, int level, int (*handler)( tpia_mapEntry *entry, int level, void *userData),
465  void *userData ) {
466 
467  tpia_mapEntry *entry;
468 
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 );
472  }
473  return( 0 );
474 }
475 /*
476 ************************************************************
477 */
478 char *tpia_map_toXMLString( statusMessageReporting *smr, tpia_map *map ) {
479 
480  tpia_mapEntry *entry;
481  char *s, *p;
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;
488 
489  if( map->status != tpia_map_status_Ok ) return( NULL );
490 
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;
496  break;
497  case tpia_mapEntry_type_path :
498  n += strlen( entry->path ) + strlen( entry->projectile ) + nPath;
499  break;
500  default :
501  smr_setMessageInfo( smr, &(map->smrUserInterface), __FILE__, __LINE__, tpia_map_status_UnknownType, "unknown type = %d", entry->type );
502  return( NULL );
503  }
504  }
505 
506  if( ( s = (char *) xData_malloc2( smr, n, 0, "xml string" ) ) == NULL ) return( NULL );
507  p = s;
508  strcpy( p, start );
509  while( *p ) p++;
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 );
514  break;
515  case tpia_mapEntry_type_path :
516  sprintf( p, pathFormat, entry->projectile, entry->path );
517  break;
518  }
519  while( *p ) p++;
520  }
521  strcpy( p, end );
522  return( s );
523 }
524 /*
525 ************************************************************
526 */
527 void tpia_map_simpleWrite( FILE *f, tpia_map *map ) { _tpia_map_simpleWrite2( f, map, 0 ); }
528 /*
529 ************************************************************
530 */
531 static void _tpia_map_simpleWrite2( FILE *f, tpia_map *map, int level ) {
532 
533  tpia_mapEntry *entry;
534  char sLevel[] = " ";
535  int n = strlen( sLevel ) / 4;
536 
537  if( map->status != tpia_map_status_Ok ) {
538  fprintf( f, "Bad map status = %d\n", map->status );
539  return;
540  }
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 );
549  break;
550  case tpia_mapEntry_type_path :
551  fprintf( f, "%sType = path: projectile = %s: path = %s\n", sLevel, entry->projectile, entry->path );
552  _tpia_map_simpleWrite2( f, entry->map, level + 1 );
553  break;
554  default :
555  fprintf( f, "%sUnknown type = %d\n", sLevel, entry->type );
556  }
557  }
558 }
559 /*
560 ************************************************************
561 */
562 static int _tpia_map_smrUserInterface( void *userData, char **str ) {
563 
564  tpia_map_smr *smrUserInterface = (tpia_map_smr *) userData;
565  char fnl[] = "map file = ";
566  int size = strlen( fnl ) + strlen( smrUserInterface->map->mapFileName ) + 1;
567 
568  if( str != NULL ) {
569  //if( ( *str = xData_malloc2( NULL, size, 0, "mapFileName" ) ) == NULL ) return( -1 );
570  if( ( *str = (char*) xData_malloc2( NULL, size, 0, "mapFileName" ) ) == NULL ) return( -1 );
571  strcpy( *str, fnl );
572  strcat( *str, smrUserInterface->map->mapFileName );
573  }
574  return( size );
575 }
576 
577 #if defined __cplusplus
578 }
579 #endif
int tpia_map_walkTree(statusMessageReporting *smr, tpia_map *map, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData)
Definition: tpia_map.cc:457
tpia_map * tpia_map_readFile(statusMessageReporting *smr, const char *basePath, const char *mapFileName)
Definition: tpia_map.cc:88
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: tpia_map.cc:229
char * tpia_map_findTarget(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *targetName)
Definition: tpia_map.cc:327
xData_element * xData_getNextElement(xData_element *element)
Definition: xData.cc:478
xData_document * xData_parseReadFile(statusMessageReporting *smr, const char *fileName, xData_xDataTypeOk func, void *userData)
Definition: xData.cc:84
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)
Definition: xData.cc:546
#define userData
Definition: xmlparse.cc:555
xData_element * xData_getFirstElement(xData_element *element)
Definition: xData.cc:477
static const double s
Definition: G4SIunits.hh:150
tpia_map * tpia_map_create(statusMessageReporting *smr)
Definition: tpia_map.cc:59
xData_element * xData_getDocumentsElement(xData_document *doc)
Definition: xData.cc:476
void * xData_parseFree(statusMessageReporting *smr, xData_document *doc)
Definition: xData.cc:208
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)
Definition: tpia_map.cc:248
int smr_isOk(statusMessageReporting *smr)
char * tpia_map_toXMLString(statusMessageReporting *smr, tpia_map *map)
Definition: tpia_map.cc:478
static int _tpia_map_walkTree2(statusMessageReporting *smr, tpia_map *map, int level, int(*handler)(tpia_mapEntry *entry, int level, void *userData), void *userData)
Definition: tpia_map.cc:464
static void _tpia_map_simpleWrite2(FILE *f, tpia_map *map, int level)
Definition: tpia_map.cc:531
tpia_mapEntry * tpia_map_getNextEntry(tpia_mapEntry *entry)
Definition: tpia_map.cc:222
const G4int n
static char * _tpia_map_findTarget2(statusMessageReporting *smr, tpia_map *map, const char *evaluation, const char *projectile, const char *target)
Definition: tpia_map.cc:348
int tpia_map_addPath(statusMessageReporting *smr, tpia_map *map, const char *path, const char *projectile)
Definition: tpia_map.cc:236
void tpia_map_simpleWrite(FILE *f, tpia_map *map)
Definition: tpia_map.cc:527
tpia_map * tpia_map_findAllOfTarget(statusMessageReporting *smr, tpia_map *map, const char *projectile, const char *targetName)
Definition: tpia_map.cc:393
tpia_mapEntry * tpia_map_getFirstEntry(tpia_map *map)
Definition: tpia_map.cc:215
void * xData_free(statusMessageReporting *, void *p)
Definition: xDataMisc.cc:89
int tpia_map_initialize(statusMessageReporting *, tpia_map *map)
Definition: tpia_map.cc:73
char * tpia_map_getFullPath(statusMessageReporting *smr, tpia_map *map, const char *endPath)
Definition: tpia_map.cc:437
static int _tpia_map_smrUserInterface(void *userData, char **str)
Definition: tpia_map.cc:562
static int _tpia_map_findAllOfTarget2(statusMessageReporting *smr, tpia_map *mapAllOfTarget, tpia_map *map, const char *projectile, const char *targetName)
Definition: tpia_map.cc:410
void * tpia_map_free(statusMessageReporting *smr, tpia_map *map)
Definition: tpia_map.cc:184
void tpia_map_release(statusMessageReporting *smr, tpia_map *map)
Definition: tpia_map.cc:193
int smr_setMessageInfo(statusMessageReporting *smr, void *userInterface, const char *file, int line, int code, const char *fmt,...)