-/* common */
-#include "searchpath.h"
-
/* ca65 */
#include "incpath.h"
/*****************************************************************************/
-/* Code */
+/* Data */
/*****************************************************************************/
-void AddIncludePath (const char* NewPath, unsigned Where)
-/* Add a new include path to the existing one */
-{
- AddSearchPath (NewPath, Where);
-}
+SearchPath* IncSearchPath; /* Standard include path */
+SearchPath* BinSearchPath; /* Binary include path */
-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);
-}
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
void ForgetAllIncludePaths (void)
/* Remove all include search paths. */
{
- ForgetAllSearchPaths (INC_STD | INC_BIN);
+ ForgetSearchPath (IncSearchPath);
+ ForgetSearchPath (BinSearchPath);
}
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");
}
+/* 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 */
-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. */
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);
}
static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
/* Add an include search path */
{
- AddIncludePath (Arg, INC_STD);
+ AddSearchPath (IncSearchPath, Arg);
}
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 ();
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));
* 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));
/* 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));
/* */
/* */
/* */
-/* (C) 2000-2009, Ullrich von Bassewitz */
+/* (C) 2000-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-/* common */
-#include "searchpath.h"
-
/* cc65 */
#include "incpath.h"
/*****************************************************************************/
-/* Code */
+/* Data */
/*****************************************************************************/
-void AddIncludePath (const char* NewPath, unsigned Where)
-/* Add a new include path to the existing one */
-{
- AddSearchPath (NewPath, Where);
-}
+SearchPath* SysIncSearchPath; /* System include path */
+SearchPath* UsrIncSearchPath; /* User include path */
-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.
- */
-{
- return SearchFile (Name, Where);
-}
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
void ForgetAllIncludePaths (void)
/* Remove all include search paths. */
{
- ForgetAllSearchPaths (INC_SYS | INC_USER);
+ ForgetSearchPath (SysIncSearchPath);
+ ForgetSearchPath (UsrIncSearchPath);
}
void InitIncludePaths (void)
/* Initialize the include path search list */
{
- /* Add some standard paths to the include search path */
- AddSearchPath ("", INC_USER); /* Current directory */
+ /* Create the search path lists */
+ SysIncSearchPath = NewSearchPath ();
+ UsrIncSearchPath = NewSearchPath ();
+
+ /* Add the current path to the user search path list */
+ AddSearchPath (UsrIncSearchPath, "");
/* Add some compiled in search paths if defined at compile time */
#ifdef CC65_INC
- AddSearchPath (CC65_INC, INC_SYS);
+ AddSearchPath (SysIncSearchPath, CC65_INC);
#endif
/* Add specific paths from the environment */
- AddSearchPathFromEnv ("CC65_INC", INC_SYS | INC_USER);
+ AddSearchPathFromEnv (SysIncSearchPath, "CC65_INC");
+ AddSearchPathFromEnv (UsrIncSearchPath, "CC65_INC");
/* Add paths relative to a main directory defined in an env var */
- AddSubSearchPathFromEnv ("CC65_HOME", "include", INC_SYS);
+ AddSubSearchPathFromEnv (SysIncSearchPath, "CC65_HOME", "include");
}
/* */
/* */
/* */
-/* (C) 2000-2009, Ullrich von Bassewitz */
+/* (C) 2000-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
+/* common */
+#include "searchpath.h"
+
+
+
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
-#define INC_SYS 0x0001 /* Add to system include path */
-#define INC_USER 0x0002 /* Add to user include path */
+extern SearchPath* SysIncSearchPath; /* System include path */
+extern SearchPath* UsrIncSearchPath; /* User include path */
-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. */
-/* An enum that describes different types of input files. The members are
- * choosen so that it is possible to combine them to bitsets
- */
-typedef enum {
- IT_MAIN = 0x01, /* Main input file */
- IT_SYSINC = 0x02, /* System include file (using <>) */
- IT_USERINC = 0x04, /* User include file (using "") */
-} InputType;
-
/* The current input line */
StrBuf* Line;
-void OpenIncludeFile (const char* Name, unsigned DirSpec)
+void OpenIncludeFile (const char* Name, InputType IT)
/* Open an include file and insert it into the tables. */
{
char* N;
}
/* Search for the file */
- N = FindInclude (Name, DirSpec);
+ N = SearchFile ((IT == IT_SYSINC)? SysIncSearchPath : UsrIncSearchPath, Name);
if (N == 0) {
PPError ("Include file `%s' not found", Name);
return;
*/
IF = FindFile (N);
if (IF == 0) {
- IF = NewIFile (N, (DirSpec == INC_SYS)? IT_SYSINC : IT_USERINC);
+ IF = NewIFile (N, IT);
}
/* We don't need N any longer, since we may now use IF->Name */
/* Create a dependency file with the given name and place dependencies for
* all files with the given types there.
*/
-{
+{
const char* Target;
/* Open the file */
{
if (SB_NotEmpty (&DepName)) {
CreateDepFile (SB_GetConstBuf (&DepName),
- IT_MAIN | IT_USERINC);
+ IT_MAIN | IT_USRINC);
}
if (SB_NotEmpty (&FullDepName)) {
CreateDepFile (SB_GetConstBuf (&FullDepName),
- IT_MAIN | IT_SYSINC | IT_USERINC);
+ IT_MAIN | IT_SYSINC | IT_USRINC);
}
}
+/* An enum that describes different types of input files. The members are
+ * choosen so that it is possible to combine them to bitsets
+ */
+typedef enum {
+ IT_MAIN = 0x01, /* Main input file */
+ IT_SYSINC = 0x02, /* System include file (using <>) */
+ IT_USRINC = 0x04, /* User include file (using "") */
+} InputType;
+
/* Forward for an IFile structure */
struct IFile;
void OpenMainFile (const char* Name);
/* Open the main file. Will call Fatal() in case of failures. */
-void OpenIncludeFile (const char* Name, unsigned DirSpec);
+void OpenIncludeFile (const char* Name, InputType IT);
/* Open an include file and insert it into the tables. */
void NextChar (void);
static void OptIncludeDir (const char* Opt attribute ((unused)), const char* Arg)
/* Add an include search path */
-{
- AddIncludePath (Arg, INC_SYS | INC_USER);
+{
+ AddSearchPath (SysIncSearchPath, Arg);
+ AddSearchPath (UsrIncSearchPath, Arg);
}
/* Open an include file. */
{
char RTerm;
- unsigned DirSpec;
+ InputType IT;
StrBuf Filename = STATIC_STRBUF_INITIALIZER;
case '\"':
RTerm = '\"';
- DirSpec = INC_USER;
+ IT = IT_USRINC;
break;
case '<':
RTerm = '>';
- DirSpec = INC_SYS;
+ IT = IT_SYSINC;
break;
default:
/* Check if we got a terminator */
if (CurC == RTerm) {
/* Open the include file */
- OpenIncludeFile (SB_GetConstBuf (&Filename), DirSpec);
+ OpenIncludeFile (SB_GetConstBuf (&Filename), IT);
} else if (CurC == '\0') {
/* No terminator found */
PPError ("#include expects \"FILENAME\" or <FILENAME>");
/* */
/* searchpath.h */
/* */
-/* Search path path handling for ld65 */
+/* Handling of search paths */
/* */
/* */
/* */
/*****************************************************************************/
-/* Data */
+/* Code */
/*****************************************************************************/
-/* A search path list is a collection containing path elements. We have
- * several of those.
- */
-static Collection SearchPaths[MAX_SEARCH_PATHS] = {
- STATIC_COLLECTION_INITIALIZER,
- STATIC_COLLECTION_INITIALIZER,
- STATIC_COLLECTION_INITIALIZER,
- STATIC_COLLECTION_INITIALIZER,
- STATIC_COLLECTION_INITIALIZER,
- STATIC_COLLECTION_INITIALIZER,
- STATIC_COLLECTION_INITIALIZER,
- STATIC_COLLECTION_INITIALIZER,
-};
-
-
-
-/*****************************************************************************/
-/* Code */
-/*****************************************************************************/
-
-
-
-static void Add (Collection* Paths, const char* New)
+static void Add (SearchPath* P, const char* New)
/* Cleanup a new search path and add it to the list */
{
unsigned NewLen;
NewPath [NewLen] = '\0';
/* Add the path to the collection */
- CollAppend (Paths, NewPath);
+ CollAppend (P, NewPath);
}
-static char* Find (const Collection* PathList, const char* File)
-/* Search for a file in a list of directories. If found, return the complete
- * name including the path in a malloced data area, if not found, return 0.
- */
-{
- char* Name = 0;
- StrBuf PathName = AUTO_STRBUF_INITIALIZER;
-
- /* Start the search */
- unsigned I;
- for (I = 0; I < CollCount (PathList); ++I) {
-
- /* Copy the next path element into the buffer */
- SB_CopyStr (&PathName, CollConstAt (PathList, I));
-
- /* Add a path separator and the filename */
- if (SB_NotEmpty (&PathName)) {
- SB_AppendChar (&PathName, '/');
- }
- SB_AppendStr (&PathName, File);
- SB_Terminate (&PathName);
-
- /* Check if this file exists */
- if (access (SB_GetBuf (&PathName), 0) == 0) {
- /* The file exists, we're done */
- Name = xstrdup (SB_GetBuf (&PathName));
- break;
- }
- }
-
- /* Cleanup and return the result of the search */
- SB_Done (&PathName);
- return Name;
+SearchPath* NewSearchPath (void)
+/* Create a new, empty search path list */
+{
+ return NewCollection ();
}
-void AddSearchPath (const char* NewPath, unsigned Where)
-/* Add a new search path to the existing one */
+void AddSearchPath (SearchPath* P, const char* NewPath)
+/* Add a new search path to the end of an existing list */
{
/* Allow a NULL path */
if (NewPath) {
- unsigned I;
- for (I = 0; I < MAX_SEARCH_PATHS; ++I) {
- if (Where & (0x01U << I)) {
- Add (&SearchPaths[I], NewPath);
- }
- }
+ Add (P, NewPath);
}
}
-void AddSearchPathFromEnv (const char* EnvVar, unsigned Where)
-/* Add a search path from an environment variable */
+void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar)
+/* Add a search path from an environment variable to the end of an existing
+ * list.
+ */
{
- AddSearchPath (getenv (EnvVar), Where);
+ AddSearchPath (P, getenv (EnvVar));
}
-void AddSubSearchPathFromEnv (const char* EnvVar, const char* SubDir, unsigned Where)
+void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* SubDir)
/* Add a search path from an environment variable, adding a subdirectory to
* the environment variable value.
*/
}
}
- /* Add the subdirectory */
+ /* Add the subdirectory and terminate the string */
SB_AppendStr (&Dir, SubDir);
-
- /* Terminate the string */
SB_Terminate (&Dir);
/* Add the search path */
- AddSearchPath (SB_GetConstBuf (&Dir), Where);
+ AddSearchPath (P, SB_GetConstBuf (&Dir));
/* Free the temp buffer */
SB_Done (&Dir);
-void ForgetAllSearchPaths (unsigned Where)
-/* Forget all search paths in the given lists. */
+void ForgetSearchPath (SearchPath* P)
+/* Forget all search paths in the given list */
{
unsigned I;
- for (I = 0; I < MAX_SEARCH_PATHS; ++I) {
- if (Where & (0x01U << I)) {
- unsigned J;
- Collection* P = &SearchPaths[I];
- for (J = 0; J < CollCount (P); ++J) {
- xfree (CollAt (P, J));
- }
- CollDeleteAll (P);
- }
+ for (I = 0; I < CollCount (P); ++I) {
+ xfree (CollAt (P, I));
}
+ CollDeleteAll (P);
}
-char* SearchFile (const char* Name, unsigned Where)
+char* SearchFile (const SearchPath* P, const char* File)
/* Search for a file in a list of directories. Return a pointer to a malloced
* area that contains the complete path, if found, return 0 otherwise.
*/
{
+ char* Name = 0;
+ StrBuf PathName = AUTO_STRBUF_INITIALIZER;
+
+ /* Start the search */
unsigned I;
- for (I = 0; I < MAX_SEARCH_PATHS; ++I) {
- if (Where & (0x01U << I)) {
- char* Path = Find (&SearchPaths[I], Name);
- if (Path) {
- /* Found the file */
- return Path;
- }
- }
+ for (I = 0; I < CollCount (P); ++I) {
+
+ /* Copy the next path element into the buffer */
+ SB_CopyStr (&PathName, CollConstAt (P, I));
+
+ /* Add a path separator and the filename */
+ if (SB_NotEmpty (&PathName)) {
+ SB_AppendChar (&PathName, '/');
+ }
+ SB_AppendStr (&PathName, File);
+ SB_Terminate (&PathName);
+
+ /* Check if this file exists */
+ if (access (SB_GetBuf (&PathName), 0) == 0) {
+ /* The file exists, we're done */
+ Name = xstrdup (SB_GetBuf (&PathName));
+ break;
+ }
}
- return 0;
+
+ /* Cleanup and return the result of the search */
+ SB_Done (&PathName);
+ return Name;
}
/* */
/* searchpath.h */
/* */
-/* Search path path handling for ld65 */
+/* Handling of search paths */
/* */
/* */
/* */
-/* (C) 2000-2009, Ullrich von Bassewitz */
+/* (C) 2000-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-/* Exports facilities to search files in a list of directories. 8 of these
- * lists are managed, and each list can contain an arbitrary number of
- * directories. The "Where" argument is actually a bitset, specifying which
- * of the search lists should be used when adding paths or searching files.
- */
+/* Exports facilities to search files in a list of directories. */
-/* Maximum number of search paths */
-#define MAX_SEARCH_PATHS 8
+/* A search path is a pointer to the list */
+typedef struct Collection SearchPath;
-void AddSearchPath (const char* NewPath, unsigned Where);
-/* Add a new search path to the existing one */
+SearchPath* NewSearchPath (void);
+/* Create a new, empty search path list */
+
+void AddSearchPath (SearchPath* P, const char* NewPath);
+/* Add a new search path to the end of an existing list */
-void AddSearchPathFromEnv (const char* EnvVar, unsigned Where);
-/* Add a search path from an environment variable */
+void AddSearchPathFromEnv (SearchPath* P, const char* EnvVar);
+/* Add a search path from an environment variable to the end of an existing
+ * list.
+ */
-void AddSubSearchPathFromEnv (const char* EnvVar, const char* SubDir, unsigned Where);
+void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* SubDir);
/* Add a search path from an environment variable, adding a subdirectory to
* the environment variable value.
*/
-void ForgetAllSearchPaths (unsigned Where);
-/* Forget all search paths in the given lists. */
+void ForgetSearchPath (SearchPath* P);
+/* Forget all search paths in the given list */
-char* SearchFile (const char* Name, unsigned Where);
+char* SearchFile (const SearchPath* P, const char* File);
/* Search for a file in a list of directories. Return a pointer to a malloced
* area that contains the complete path, if found, return 0 otherwise.
*/
/* */
/* */
/* */
-/* (C) 2003-2009, Ullrich von Bassewitz */
+/* (C) 2003-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
-/* common */
-#include "searchpath.h"
-
/* ld65 */
#include "filepath.h"
+/*****************************************************************************/
+/* Data */
+/*****************************************************************************/
+
+
+
+SearchPath* LibSearchPath; /* Library path */
+SearchPath* ObjSearchPath; /* Object file path */
+SearchPath* CfgSearchPath; /* Config file path */
+
+
+
/*****************************************************************************/
/* Code */
/*****************************************************************************/
void InitSearchPaths (void)
/* Initialize the path search list */
{
+ /* Create the search path lists */
+ LibSearchPath = NewSearchPath ();
+ ObjSearchPath = NewSearchPath ();
+ CfgSearchPath = NewSearchPath ();
+
/* Always search all stuff in the current directory */
- AddSearchPath ("", SEARCH_LIB | SEARCH_OBJ | SEARCH_CFG);
+ AddSearchPath (LibSearchPath, "");
+ AddSearchPath (ObjSearchPath, "");
+ AddSearchPath (CfgSearchPath, "");
/* Add some compiled in search paths if defined at compile time */
#if defined(LD65_LIB)
- AddSearchPath (LD65_LIB, SEARCH_LIB);
+ AddSearchPath (LibSearchPath, LD65_LIB);
#endif
#if defined(LD65_OBJ)
- AddSearchPath (LD65_OBJ, SEARCH_OBJ);
+ AddSearchPath (ObjSearchPath, LD65_OBJ);
#endif
#if defined(LD65_CFG)
- AddSearchPath (LD65_CFG, SEARCH_CFG);
+ AddSearchPath (CfgSearchPath, LD65_CFG);
#endif
/* Add specific paths from the environment */
- AddSearchPathFromEnv ("LD65_CFG", SEARCH_CFG);
- AddSearchPathFromEnv ("LD65_LIB", SEARCH_LIB);
- AddSearchPathFromEnv ("LD65_OBJ", SEARCH_OBJ);
+ AddSearchPathFromEnv (LibSearchPath, "LD65_LIB");
+ AddSearchPathFromEnv (ObjSearchPath, "LD65_OBJ");
+ AddSearchPathFromEnv (CfgSearchPath, "LD65_CFG");
/* Add paths relative to a main directory defined in an env var */
- AddSubSearchPathFromEnv ("CC65_HOME", "cfg", SEARCH_CFG);
- AddSubSearchPathFromEnv ("CC65_HOME", "lib", SEARCH_LIB);
- AddSubSearchPathFromEnv ("CC65_HOME", "obj", SEARCH_OBJ);
+ AddSubSearchPathFromEnv (LibSearchPath, "CC65_HOME", "lib");
+ AddSubSearchPathFromEnv (ObjSearchPath, "CC65_HOME", "obj");
+ AddSubSearchPathFromEnv (CfgSearchPath, "CC65_HOME", "cfg");
}
/* */
/* */
/* */
-/* (C) 2003 Ullrich von Bassewitz */
-/* Römerstrasse 52 */
-/* D-70794 Filderstadt */
-/* EMail: uz@cc65.org */
+/* (C) 2003-2010, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
#define FILEPATH_H
-
+
/* common */
#include "searchpath.h"
-#define SEARCH_LIB 0x0001U /* Library path */
-#define SEARCH_OBJ 0x0002U /* Object file path */
-#define SEARCH_CFG 0x0004U /* Config file path */
+extern SearchPath* LibSearchPath; /* Library path */
+extern SearchPath* ObjSearchPath; /* Object file path */
+extern SearchPath* CfgSearchPath; /* Config file path */
/* */
/* */
/* */
-/* (C) 1998-2009, Ullrich von Bassewitz */
+/* (C) 1998-2010, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
switch (Type) {
case FILETYPE_LIB:
- PathName = SearchFile (Name, SEARCH_LIB);
+ PathName = SearchFile (LibSearchPath, Name);
break;
case FILETYPE_OBJ:
- PathName = SearchFile (Name, SEARCH_OBJ);
+ PathName = SearchFile (ObjSearchPath, Name);
break;
default:
static void OptCfgPath (const char* Opt attribute ((unused)), const char* Arg)
/* Specify a config file search path */
{
- AddSearchPath (Arg, SEARCH_CFG);
+ AddSearchPath (CfgSearchPath, Arg);
}
Error ("Cannot use -C/-t twice");
}
/* Search for the file */
- PathName = SearchFile (Arg, SEARCH_CFG);
+ PathName = SearchFile (CfgSearchPath, Arg);
if (PathName == 0) {
Error ("Cannot find config file `%s'", Arg);
} else {
static void OptLibPath (const char* Opt attribute ((unused)), const char* Arg)
/* Specify a library file search path */
{
- AddSearchPath (Arg, SEARCH_LIB);
+ AddSearchPath (LibSearchPath, Arg);
}
static void OptObjPath (const char* Opt attribute ((unused)), const char* Arg)
/* Specify an object file search path */
{
- AddSearchPath (Arg, SEARCH_OBJ);
+ AddSearchPath (ObjSearchPath, Arg);
}
/* */
/* */
/* */
-/* (C) 2000-2002 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2000-2010, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
# include <unistd.h>
#endif
-/* common */
-#include "xmalloc.h"
-
/* sim65 */
#include "chippath.h"
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
-static char* ChipPath = 0;
+SearchPath* ChipSearchPath; /* Search paths for chip libs */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
-static char* Add (char* Orig, const char* New)
-/* Create a new path from Orig and New, delete Orig, return the result */
+void InitChipPaths (void)
+/* Initialize the chip search path list */
{
- unsigned OrigLen, NewLen;
- char* NewPath;
-
- /* Get the length of the original string */
- OrigLen = Orig? strlen (Orig) : 0;
-
- /* Get the length of the new path */
- NewLen = strlen (New);
-
- /* Check for a trailing path separator and remove it */
- if (NewLen > 0 && (New [NewLen-1] == '\\' || New [NewLen-1] == '/')) {
- --NewLen;
- }
-
- /* Allocate memory for the new string */
- NewPath = xmalloc (OrigLen + NewLen + 2);
+ /* Create the search path list */
+ ChipSearchPath = NewSearchPath ();
- /* Copy the strings */
- memcpy (NewPath, Orig, OrigLen);
- memcpy (NewPath+OrigLen, New, NewLen);
- NewPath [OrigLen+NewLen+0] = ';';
- NewPath [OrigLen+NewLen+1] = '\0';
+ /* Add the current directory to the search path */
+ AddSearchPath (ChipSearchPath, "");
- /* Delete the original path */
- xfree (Orig);
-
- /* Return the new path */
- return NewPath;
}
-static char* Find (const char* Path, const char* File)
-/* Search for a file in a list of directories. If found, return the complete
- * name including the path in a malloced data area, if not found, return 0.
- */
-{
- const char* P;
- int Max;
- char PathName [FILENAME_MAX];
-
- /* Initialize variables */
- Max = sizeof (PathName) - strlen (File) - 2;
- if (Max < 0) {
- return 0;
- }
- P = Path;
-
- /* Handle a NULL pointer as replacement for an empty string */
- if (P == 0) {
- P = "";
- }
-
- /* Start the search */
- while (*P) {
- /* Copy the next path element into the buffer */
- int Count = 0;
- while (*P != '\0' && *P != ';' && Count < Max) {
- PathName [Count++] = *P++;
- }
-
- /* Add a path separator and the filename */
- if (Count) {
- PathName [Count++] = '/';
- }
- strcpy (PathName + Count, File);
-
- /* Check if this file exists */
- if (access (PathName, 0) == 0) {
- /* The file exists */
- return xstrdup (PathName);
- }
-
- /* Skip a list separator if we have one */
- if (*P == ';') {
- ++P;
- }
- }
-
- /* Not found */
- return 0;
-}
-
-
-
-void AddChipPath (const char* NewPath)
-/* Add a search path for chips */
-{
- /* Allow a NULL path */
- if (NewPath) {
- ChipPath = Add (ChipPath, NewPath);
- }
-}
-
-
-
-char* FindChipLib (const char* LibName)
-/* Find a chip library. Return a pointer to a malloced area that contains
- * the complete path, if found, return 0 otherwise.
- */
-{
- /* Search in the include directories */
- return Find (ChipPath, LibName);
-}
-
/* */
/* */
/* */
-/* (C) 2000-2002 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (C) 2000-2010, Ullrich von Bassewitz */
+/* Roemerstrasse 52 */
+/* D-70794 Filderstadt */
+/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
+/* common */
+#include "searchpath.h"
+
+
+
/*****************************************************************************/
-/* Code */
+/* Data */
/*****************************************************************************/
-void AddChipPath (const char* NewPath);
-/* Add a search path for chips */
+extern SearchPath* ChipSearchPath; /* Search paths for chip libs */
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
-char* FindChipLib (const char* LibName);
-/* Find a chip library. Return a pointer to a malloced area that contains
- * the complete path, if found, return 0 otherwise.
- */
+void InitChipPaths (void);
+/* Initialize the chip search path list */
/* Initialize the cmdline module */
InitCmdLine (&argc, &argv, "sim65");
+ /* Initialize the chip library search paths */
+ InitChipPaths ();
+
/* Parse the command line */
I = 1;
while (I < ArgCount) {
/* Skip a token, print an error message if not found */
{
if (CfgTok != T) {
- CfgError (Msg);
+ CfgError ("%s", Msg);
}
CfgNextTok ();
}