Restructured search path handling.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4662 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2010-05-09 10:54:15 +00:00
parent d95bb2e600
commit 05f7296369
20 changed files with 277 additions and 405 deletions

View File

@@ -33,43 +33,33 @@
/* common */
#include "searchpath.h"
/* ca65 */
#include "incpath.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
SearchPath* IncSearchPath; /* Standard include path */
SearchPath* BinSearchPath; /* Binary include path */
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void AddIncludePath (const char* NewPath, unsigned Where)
/* Add a new include path to the existing one */
{
AddSearchPath (NewPath, Where);
}
char* FindInclude (const char* Name, unsigned Where)
/* Find an include file. Return a pointer to a malloced area that contains
* the complete path, if found, return 0 otherwise.
*/
{
/* Search in the include directories */
return SearchFile (Name, Where);
}
void ForgetAllIncludePaths (void)
/* Remove all include search paths. */
{
ForgetAllSearchPaths (INC_STD | INC_BIN);
ForgetSearchPath (IncSearchPath);
ForgetSearchPath (BinSearchPath);
}
@@ -77,20 +67,24 @@ void ForgetAllIncludePaths (void)
void InitIncludePaths (void)
/* Initialize the include path search list */
{
/* Add some standard paths to the include search path */
AddSearchPath ("", INC_STD); /* Current directory */
AddSearchPath ("", INC_BIN);
/* Create the search path lists */
IncSearchPath = NewSearchPath ();
BinSearchPath = NewSearchPath ();
/* Add the current directory to the search paths */
AddSearchPath (IncSearchPath, "");
AddSearchPath (BinSearchPath, "");
/* Add some compiled in search paths if defined at compile time */
#ifdef CA65_INC
AddSearchPath (CA65_INC, INC_STD);
AddSearchPath (IncSearchPath, CA65_INC);
#endif
/* Add specific paths from the environment */
AddSearchPathFromEnv ("CA65_INC", INC_STD);
AddSearchPathFromEnv (IncSearchPath, "CA65_INC");
/* Add paths relative to a main directory defined in an env var */
AddSubSearchPathFromEnv ("CC65_HOME", "asminc", INC_STD);
AddSubSearchPathFromEnv (IncSearchPath, "CC65_HOME", "asminc");
}

View File

@@ -38,14 +38,19 @@
/* common */
#include "searchpath.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
#define INC_STD 0x0001U /* Add to standard include path */
#define INC_BIN 0x0002U /* Add to binary include path */
extern SearchPath* IncSearchPath; /* Standard include path */
extern SearchPath* BinSearchPath; /* Binary include path */
@@ -55,14 +60,6 @@
void AddIncludePath (const char* NewPath, unsigned Where);
/* Add a new include path to the existing one */
char* FindInclude (const char* Name, unsigned Where);
/* Find an include file. Return a pointer to a malloced area that contains
* the complete path, if found, return 0 otherwise.
*/
void ForgetAllIncludePaths (void);
/* Remove all include search paths. */

View File

@@ -360,8 +360,8 @@ static void OptAutoImport (const char* Opt attribute ((unused)),
static void OptBinIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
/* Add an include search path for binaries */
{
AddIncludePath (Arg, INC_BIN);
{
AddSearchPath (BinSearchPath, Arg);
}
@@ -450,7 +450,7 @@ static void OptIgnoreCase (const char* Opt attribute ((unused)),
static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
/* Add an include search path */
{
AddIncludePath (Arg, INC_STD);
AddSearchPath (IncSearchPath, Arg);
}
@@ -1025,8 +1025,8 @@ int main (int argc, char* argv [])
SegDump ();
}
/* If we didn't have any errors, create the object, listing and
* dependency files
/* If we didn't have any errors, create the object, listing and
* dependency files
*/
if (ErrorCount == 0) {
CreateObjFile ();

View File

@@ -1122,7 +1122,7 @@ static void DoIncBin (void)
if (F == 0) {
/* Search for the file in the binary include directory */
char* PathName = FindInclude (SB_GetConstBuf (&Name), INC_BIN);
char* PathName = SearchFile (BinSearchPath, SB_GetConstBuf (&Name));
if (PathName == 0 || (F = fopen (PathName, "rb")) == 0) {
/* Not found or cannot open, print an error and bail out */
ErrorSkip ("Cannot open include file `%m%p': %s", &Name, strerror (errno));
@@ -1148,7 +1148,7 @@ static void DoIncBin (void)
* while it was open. Since mtime and size are only used to check
* if a file has changed in the debugger, we will ignore this problem
* here.
*/
*/
SB_Terminate (&Name);
if (stat (SB_GetConstBuf (&Name), &StatBuf) != 0) {
Fatal ("Cannot stat input file `%m%p': %s", &Name, strerror (errno));

View File

@@ -456,7 +456,7 @@ int NewInputFile (const char* Name)
/* We are on include level. Search for the file in the include
* directories.
*/
PathName = FindInclude (Name, INC_STD);
PathName = SearchFile (IncSearchPath, Name);
if (PathName == 0 || (F = fopen (PathName, "r")) == 0) {
/* Not found or cannot open, print an error and bail out */
Error ("Cannot open include file `%s': %s", Name, strerror (errno));