From a9e46e245aa7b5c914c95b3314c21548ccb77f75 Mon Sep 17 00:00:00 2001 From: uz Date: Tue, 22 Sep 2009 11:29:13 +0000 Subject: [PATCH] New function AddSubSearchPathFromEnv. git-svn-id: svn://svn.cc65.org/cc65/trunk@4208 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/searchpath.c | 50 ++++++++++++++++++++++++++++++++++++----- src/common/searchpath.h | 15 ++++++++----- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/common/searchpath.c b/src/common/searchpath.c index d0f194a60..2f536388b 100644 --- a/src/common/searchpath.c +++ b/src/common/searchpath.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000-2008 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2000-2009, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -132,7 +132,7 @@ static char* Find (const char* Path, const char* File) SB_AppendChar (&PathName, '/'); } SB_AppendStr (&PathName, File); - SB_Terminate (&PathName); + SB_Terminate (&PathName); /* Check if this file exists */ if (access (SB_GetBuf (&PathName), 0) == 0) { @@ -173,13 +173,51 @@ void AddSearchPath (const char* NewPath, unsigned Where) void AddSearchPathFromEnv (const char* EnvVar, unsigned Where) -/* Add a search from an environment variable */ +/* Add a search path from an environment variable */ { AddSearchPath (getenv (EnvVar), Where); } +void AddSubSearchPathFromEnv (const char* EnvVar, const char* SubDir, unsigned Where) +/* Add a search path from an environment variable, adding a subdirectory to + * the environment variable value. + */ +{ + StrBuf Dir = AUTO_STRBUF_INITIALIZER; + + const char* EnvVal = getenv (EnvVar); + if (EnvVal == 0) { + /* Not found */ + return; + } + + /* Copy the environment variable to the buffer */ + SB_CopyStr (&Dir, EnvVal); + + /* Add a path separator if necessary */ + if (SB_NotEmpty (&Dir)) { + if (SB_LookAtLast (&Dir) != '\\' && SB_LookAtLast (&Dir) != '/') { + SB_AppendChar (&Dir, '/'); + } + } + + /* Add the subdirectory */ + SB_AppendStr (&Dir, SubDir); + + /* Terminate the string */ + SB_Terminate (&Dir); + + /* Add the search path */ + AddSearchPath (SB_GetConstBuf (&Dir), Where); + + /* Free the temp buffer */ + SB_Done (&Dir); +} + + + void ForgetAllSearchPaths (unsigned Where) /* Forget all search paths in the given lists. */ { diff --git a/src/common/searchpath.h b/src/common/searchpath.h index 053301651..181560f4c 100644 --- a/src/common/searchpath.h +++ b/src/common/searchpath.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000-2003 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2000-2009, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -67,7 +67,12 @@ void AddSearchPath (const char* NewPath, unsigned Where); /* Add a new search path to the existing one */ void AddSearchPathFromEnv (const char* EnvVar, unsigned Where); -/* Add a search from an environment variable */ +/* Add a search path from an environment variable */ + +void AddSubSearchPathFromEnv (const char* EnvVar, const char* SubDir, unsigned Where); +/* 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. */ -- 2.39.5