Search current directory first for #include "".
Modified: trunk/reactos/tools/rbuild/automaticdependency.cpp
Modified: trunk/reactos/tools/rbuild/include.cpp
Modified: trunk/reactos/tools/rbuild/module.cpp
Modified: trunk/reactos/tools/rbuild/project.cpp
Modified: trunk/reactos/tools/rbuild/rbuild.h

Modified: trunk/reactos/tools/rbuild/automaticdependency.cpp
--- trunk/reactos/tools/rbuild/automaticdependency.cpp	2005-06-24 18:28:22 UTC (rev 16259)
+++ trunk/reactos/tools/rbuild/automaticdependency.cpp	2005-06-24 19:39:47 UTC (rev 16260)
@@ -85,6 +85,7 @@
 
 bool
 SourceFile::ReadInclude ( string& filename,
+                          bool& searchCurrentDirectory,
                           bool& includeNext)
 {
 	while ( p < end )
@@ -117,6 +118,7 @@
 						register char ch = *p;
 						if ( ch == '<' || ch == '"' )
 						{
+							searchCurrentDirectory = (ch == '"');
 							p++;
 							filename.resize ( MAX_PATH );
 							int i = 0;
@@ -138,6 +140,7 @@
 		p++;
 	}
 	filename = "";
+	searchCurrentDirectory = false;
 	includeNext = false;
 	return false;
 }
@@ -230,14 +233,17 @@
 	{
 		string includedFilename ( "" );
 		
+		bool searchCurrentDirectory;
 		bool includeNext;
 		while ( ReadInclude ( includedFilename,
+		                      searchCurrentDirectory,
 		                      includeNext ) )
 		{
 			string resolvedFilename ( "" );
 			bool locatedFile = automaticDependency->LocateIncludedFile ( this,
 			                                                             module,
 			                                                             includedFilename,
+			                                                             searchCurrentDirectory,
 			                                                             includeNext,
 			                                                             resolvedFilename );
 			if ( locatedFile )
@@ -321,8 +327,8 @@
 
 bool
 AutomaticDependency::LocateIncludedFile ( const string& directory,
-	                                      const string& includedFilename,
-	                                      string& resolvedFilename )
+                                          const string& includedFilename,
+                                          string& resolvedFilename )
 {
 	string normalizedFilename = NormalizeFilename ( directory + SSEP + includedFilename );
 	FILE* f = fopen ( normalizedFilename.c_str (), "rb" );
@@ -347,37 +353,44 @@
 		                         filename.length () - index - 1);
 }
 
+void
+AutomaticDependency::GetIncludeDirectories ( vector<Include*>& includes,
+                                             Module& module,
+                                             Include& currentDirectory,
+                                             bool searchCurrentDirectory )
+{
+	if ( searchCurrentDirectory )
+		includes.push_back( &currentDirectory );
+	for ( size_t i = 0; i < module.non_if_data.includes.size (); i++ )
+		includes.push_back( module.non_if_data.includes[i] );
+	for ( size_t i = 0; i < module.project.non_if_data.includes.size (); i++ )
+		includes.push_back( module.project.non_if_data.includes[i] );
+}
+
 bool
 AutomaticDependency::LocateIncludedFile ( SourceFile* sourceFile,
-	                                      Module& module,
-	                                      const string& includedFilename,
-	                                      bool includeNext,
-	                                      string& resolvedFilename )
+                                          Module& module,
+                                          const string& includedFilename,
+                                          bool searchCurrentDirectory,
+                                          bool includeNext,
+                                          string& resolvedFilename )
 {
-	size_t i, j;
-	const vector<Include*>* pincludes;
-	for ( i = 0; i < 2; i++ )
+	vector<Include*> includes;
+	Include currentDirectory ( module.project, ".", sourceFile->directoryPart );
+	GetIncludeDirectories ( includes, module, currentDirectory, searchCurrentDirectory );
+	for ( size_t j = 0; j < includes.size (); j++ )
 	{
-		if ( !i )
-			pincludes = &module.non_if_data.includes;
-		else
-			pincludes = &module.project.non_if_data.includes;
-		const vector<Include*>& includes = *pincludes;
-		for ( j = 0; j < includes.size (); j++ )
+		Include& include = *includes[j];
+		if ( LocateIncludedFile ( include.directory,
+		                          includedFilename,
+		                          resolvedFilename ) )
 		{
-			Include& include = *includes[j];
-			if ( LocateIncludedFile ( include.directory,
-									  includedFilename,
-									  resolvedFilename ) )
-			{
-				if ( includeNext && stricmp ( resolvedFilename.c_str (),
-											  sourceFile->filename.c_str () ) == 0 )
-					continue;
-				return true;
-			}
+			if ( includeNext && stricmp ( resolvedFilename.c_str (),
+			                              sourceFile->filename.c_str () ) == 0 )
+				continue;
+			return true;
 		}
 	}
-
 	resolvedFilename = "";
 	return false;
 }
@@ -422,15 +435,15 @@
 
 void
 AutomaticDependency::CheckAutomaticDependencies ( Module& module,
-	                                              bool verbose )
+                                                  bool verbose )
 {
 	CheckAutomaticDependencies ( module, verbose, true );
 }
 
 void
 AutomaticDependency::CheckAutomaticDependencies ( Module& module,
-	                                              bool verbose,
-	                                              bool parseFiles )
+                                                  bool verbose,
+                                                  bool parseFiles )
 {
 	if ( parseFiles )
 		ParseFiles ( module );

Modified: trunk/reactos/tools/rbuild/include.cpp
--- trunk/reactos/tools/rbuild/include.cpp	2005-06-24 18:28:22 UTC (rev 16259)
+++ trunk/reactos/tools/rbuild/include.cpp	2005-06-24 19:39:47 UTC (rev 16260)
@@ -6,31 +6,35 @@
 using std::string;
 using std::vector;
 
-Include::Include ( const Project& project_,
-                   const XMLElement& includeNode )
-	: project (project_),
-	  module (NULL),
-	  node (includeNode)
+Include::Include ( const Project& project,
+                   const XMLElement* includeNode )
+	: project ( project ),
+	  module ( NULL ),
+	  node ( includeNode )
 {
-	Initialize();
 }
 
-Include::Include ( const Project& project_,
-	               const Module* module_,
-	               const XMLElement& includeNode )
-	: project (project_),
-	  module (module_),
-	  node (includeNode)
+Include::Include ( const Project& project,
+                   const Module* module,
+                   const XMLElement* includeNode )
+	: project ( project ),
+	  module ( module ),
+	  node ( includeNode )
 {
-	Initialize();
 }
 
-Include::~Include ()
+Include::Include ( const Project& project,
+                   string directory,
+                   string basePath )
+	: project ( project ),
+	  module ( NULL ),
+	  node ( NULL )
 {
+	this->directory = NormalizeFilename ( basePath + SSEP + directory );
+	this->basePath = NormalizeFilename ( basePath );
 }
 
-void
-Include::Initialize()
+Include::~Include ()
 {
 }
 
@@ -38,13 +42,13 @@
 Include::ProcessXML()
 {
 	const XMLAttribute* att;
-	att = node.GetAttribute ( "base",
-	                          false );
+	att = node->GetAttribute ( "base",
+	                           false );
 	if ( att )
 	{
 		if ( !module )
 			throw InvalidBuildFileException (
-				node.location,
+				node->location,
 				"'base' attribute illegal from global <include>" );
 		bool referenceResolved = false;
 		if ( att->value == project.name )
@@ -63,11 +67,11 @@
 		}
 		if ( !referenceResolved )
 			throw InvalidBuildFileException (
-				node.location,
+				node->location,
 				"<include> attribute 'base' references non-existant project or module '%s'",
 				att->value.c_str() );
-		directory = FixSeparator ( basePath + "/" + node.value );
+		directory = NormalizeFilename ( basePath + SSEP + node->value );
 	}
 	else
-		directory = FixSeparator ( node.value );
+		directory = NormalizeFilename ( node->value );
 }

Modified: trunk/reactos/tools/rbuild/module.cpp
--- trunk/reactos/tools/rbuild/module.cpp	2005-06-24 18:28:22 UTC (rev 16259)
+++ trunk/reactos/tools/rbuild/module.cpp	2005-06-24 19:39:47 UTC (rev 16260)
@@ -367,7 +367,7 @@
 	}
 	else if ( e.name == "include" )
 	{
-		Include* include = new Include ( project, this, e );
+		Include* include = new Include ( project, this, &e );
 		if ( pIf )
 			pIf->data.includes.push_back ( include );
 		else

Modified: trunk/reactos/tools/rbuild/project.cpp
--- trunk/reactos/tools/rbuild/project.cpp	2005-06-24 18:28:22 UTC (rev 16259)
+++ trunk/reactos/tools/rbuild/project.cpp	2005-06-24 19:39:47 UTC (rev 16260)
@@ -290,7 +290,7 @@
 	}
 	else if ( e.name == "include" )
 	{
-		Include* include = new Include ( *this, e );
+		Include* include = new Include ( *this, &e );
 		if ( pIf )
 			pIf->data.includes.push_back ( include );
 		else

Modified: trunk/reactos/tools/rbuild/rbuild.h
--- trunk/reactos/tools/rbuild/rbuild.h	2005-06-24 18:28:22 UTC (rev 16259)
+++ trunk/reactos/tools/rbuild/rbuild.h	2005-06-24 19:39:47 UTC (rev 16260)
@@ -253,19 +253,21 @@
 public:
 	const Project& project;
 	const Module* module;
-	const XMLElement& node;
+	const XMLElement* node;
 	std::string directory;
 	std::string basePath;
 
 	Include ( const Project& project,
-	          const XMLElement& includeNode );
+	          const XMLElement* includeNode );
 	Include ( const Project& project,
 	          const Module* module,
-	          const XMLElement& includeNode );
+	          const XMLElement* includeNode );
+	Include ( const Project& project,
+	          std::string directory,
+	          std::string basePath );
 	~Include ();
 	void ProcessXML();
 private:
-	void Initialize();
 };
 
 
@@ -556,6 +558,7 @@
 	void Open ();
 	void SkipWhitespace ();
 	bool ReadInclude ( std::string& filename,
+	                   bool& searchCurrentDirectory,
 	                   bool& includeNext );
 	bool IsIncludedFrom ( const std::string& normalizedFilename );
 	SourceFile* GetParentSourceFile ();
@@ -583,6 +586,7 @@
 	bool LocateIncludedFile ( SourceFile* sourceFile,
 	                          Module& module,
 	                          const std::string& includedFilename,
+	                          bool searchCurrentDirectory,
 	                          bool includeNext,
 	                          std::string& resolvedFilename );
 	SourceFile* RetrieveFromCacheOrParse ( Module& module,
@@ -597,6 +601,10 @@
 	                                  bool parseFiles );
 	void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );
 private:
+	void GetIncludeDirectories ( std::vector<Include*>& includes,
+	                             Module& module,
+                                     Include& currentDirectory,
+                                     bool searchCurrentDirectory );
 	void GetModuleFiles ( Module& module,
                               std::vector<File*>& files ) const;
 	void ParseFiles ();