[cig-commits] r5015 - in long/3D/Gale/trunk/src/StGermain: . Base/IO/src Base/IO/tests

walter at geodynamics.org walter at geodynamics.org
Sat Oct 14 11:09:20 PDT 2006


Author: walter
Date: 2006-10-14 11:09:20 -0700 (Sat, 14 Oct 2006)
New Revision: 5015

Modified:
   long/3D/Gale/trunk/src/StGermain/
   long/3D/Gale/trunk/src/StGermain/Base/IO/src/PathUtils.c
   long/3D/Gale/trunk/src/StGermain/Base/IO/src/XML_IO_Handler.c
   long/3D/Gale/trunk/src/StGermain/Base/IO/tests/testIO_Handler-normal.0of1.expected
Log:
 r3042 at earth:  boo | 2006-10-14 11:07:47 -0700
  r3030 at earth (orig r3850):  AlanLo | 2006-10-12 00:26:48 -0700
  
  Adding multiple search levels to opening an input xml file.
  
  Upon selecting an input file, it will always attempt:
   1. Current directory 
   2. XML, searched paths (current behaviour)
   3. Environment Variable STG_MODULE_PATH of ':' delimited paths to search
   4. Default STG_MODULE_PATH which is build/lib/StGermain
      (This is compiled into the binary)
  
  
  
  
 



Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
   - 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2944
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3848
   + 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:3042
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3850

Modified: long/3D/Gale/trunk/src/StGermain/Base/IO/src/PathUtils.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/IO/src/PathUtils.c	2006-10-14 18:07:03 UTC (rev 5014)
+++ long/3D/Gale/trunk/src/StGermain/Base/IO/src/PathUtils.c	2006-10-14 18:09:20 UTC (rev 5015)
@@ -70,7 +70,7 @@
 		Index ii;
 
 		for ( ii = 0; ii < searchPathsSize; ++ii ) {
-			sprintf( fullPath, "%s%s", searchPaths[ii], filename );
+			sprintf( fullPath, "%s/%s", searchPaths[ii], filename );
 			fileTester = xmlParserInputBufferCreateFilename( fullPath, XML_CHAR_ENCODING_NONE );
 			if ( fileTester ) {
 				xmlFreeParserInputBuffer( fileTester );

Modified: long/3D/Gale/trunk/src/StGermain/Base/IO/src/XML_IO_Handler.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/IO/src/XML_IO_Handler.c	2006-10-14 18:07:03 UTC (rev 5014)
+++ long/3D/Gale/trunk/src/StGermain/Base/IO/src/XML_IO_Handler.c	2006-10-14 18:09:20 UTC (rev 5015)
@@ -445,28 +445,71 @@
 }
 
 
+#include <mpi.h>
+
 /** Read all parameters from a file implementation. See IO_Handler_ReadAllFromFile(). It will first check if the file
  * exists, and contains valid XML. */
 Bool _XML_IO_Handler_ReadAllFromFile( void* xml_io_handler, const char* filename, Dictionary* dictionary ) {
 	XML_IO_Handler* self = (XML_IO_Handler*) xml_io_handler;
 	xmlNodePtr cur = NULL;
-	
+int rank;	
 	Journal_DPrintf( Journal_Register( Debug_Type, XML_IO_Handler_Type ), "XML_IO_Handler called to read file %s.\n", filename );
 	
 	assert( self && filename && dictionary );
-	
+MPI_Comm_rank( MPI_COMM_WORLD, &rank );	
 	/* set the current dictionary to the one being read */
 	self->currDictionary = dictionary;
-	
-	/* setup initial search path (currPath) */
-	if( self->currPath )
+
+	/* Order of search*/
+	/* 1. Current directory */
+	/* 2. XML, searched paths */
+	/* 3. Environment Variable */
+	/* 4. Default STG_MODULE_PATH */
+
+	/* 1. Current directory */
+	{
+		// $PWD does not work for all ranks, in all mpi implementations
+		// "./" however does so far.
+		//    char* pwd = getenv( "PWD" );
+		char* pwd = "./";
+		if ( pwd != NULL ) {
+			_XML_IO_Handler_AddSearchPath( self, pwd );
+		}
+	}
+
+	/* 2. XML, searched paths */
+	if( self->currPath ) /* setup initial search path (currPath) */
 		_XML_IO_Handler_AddSearchPath( self, self->currPath );
 	else
 		_XML_IO_Handler_AddSearchPath( self, "./" );
-	
+
+	/* 3. Environment Variable */
+	{
+		char* envValue;
+
+		envValue = getenv( "STG_MODULE_PATH" );
+		if ( envValue != NULL ) {
+			char* envCopy; 
+			char* token;
+
+			envCopy = StG_Strdup( envValue );
+			token = strtok( envCopy, ":" );
+			while ( token != NULL ) {
+				_XML_IO_Handler_AddSearchPath( self, token );
+				token = strtok( NULL, ":" );
+			}
+
+			Memory_Free( envCopy );
+		}
+	}
+
+	/* 4. Default STG_MODULE_PATH */
+	#ifdef STG_MODULE_PATH
+		_XML_IO_Handler_AddSearchPath( self, STG_MODULE_PATH );
+	#endif
+
 	/* open the file and check syntax */
 	if ( !(cur = _XML_IO_Handler_OpenCheckFile( self, filename )) ) {
-		xmlCleanupParser();
 		return False;
 	}	
 	
@@ -545,14 +588,26 @@
  * \return a pointer to the root node if the file is valid, NULL otherwise. */
 static xmlNodePtr _XML_IO_Handler_OpenCheckFile( XML_IO_Handler* self, const char* filename )
 {
-	_XML_IO_Handler_OpenFile( self, filename );
-	if ( self->currDoc == NULL ) {
-		return NULL;
+	xmlChar absolute[1024];
+
+	if ( FindFileInPathList(
+		(char*)absolute,
+		(char*)filename,
+		self->searchPaths,
+		self->searchPathsSize ) )
+	{
+		_XML_IO_Handler_OpenFile( self, absolute );
 	}
 
+	Journal_Firewall( self->currDoc != NULL,
+		Journal_Register( Error_Type, XML_IO_Handler_Type ),
+		"Error: File %s doesn't exist, not readable, or not valid.\n",
+		filename );
+
 	return _XML_IO_Handler_Check( self );
-}	
- 
+	 
+}
+
 static xmlNodePtr _XML_IO_Handler_OpenCheckBuffer( XML_IO_Handler* self, const char* buffer ) {
 	_XML_IO_Handler_OpenBuffer( self, buffer );
 	if ( self->currDoc == NULL ) {
@@ -565,11 +620,9 @@
 	/* open an XML file and build an XML tree from it. */
 	/* TODO: validate against simple dtd? */
 	self->currDoc = xmlParseFile( filename );
-	Journal_Firewall( self->currDoc != NULL,
-		Journal_Register( Error_Type, XML_IO_Handler_Type ),
-		"Error: File %s doesn't exist, not readable, or not valid.\n",
-		filename );
-
+	if ( self->currDoc == NULL ) {
+		xmlCleanupParser();
+	}
 	if ( self->resource ) {
 		Memory_Free( self->resource );
 	}
@@ -618,7 +671,7 @@
 	if ( cur == NULL ) {
 		Journal_Printf( 
 			Journal_Register( Info_Type, XML_IO_Handler_Type ),
-			"Error: no children nodes in resource %s. Not parsing.\n",
+			"Error: no children nodes in resource (path)%s. Not parsing.\n",
 			self->resource );
 	}
 	

Modified: long/3D/Gale/trunk/src/StGermain/Base/IO/tests/testIO_Handler-normal.0of1.expected
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Base/IO/tests/testIO_Handler-normal.0of1.expected	2006-10-14 18:07:03 UTC (rev 5014)
+++ long/3D/Gale/trunk/src/StGermain/Base/IO/tests/testIO_Handler-normal.0of1.expected	2006-10-14 18:09:20 UTC (rev 5015)
@@ -1,6 +1,6 @@
 
 test of reading normal xml file:
-Error: no children nodes in resource data/empty.xml. Not parsing.
+Error: no children nodes in resource (path)/home/alan/Codes/QuickFix/StGermain/Base/IO/tests/data//empty.xml. Not parsing.
 Warning: Failed to parse file empty.xml from include command.
 
 dictionary now contains:
@@ -29,7 +29,7 @@
 		leadingspace: "the main bit"
 		trailingspace: "the main bit"
 		leadingtrailingspace: "the main bit"
-		someVCs: "./data/./subdir/another/someVCs.in"
+		someVCs: "./data/./subdir/another//someVCs.in"
 		someBCs: "./data/someBCs.in"
 	}
 



More information about the cig-commits mailing list