]> git.sur5r.net Git - cc65/commitdiff
New function AddSubSearchPathFromEnv.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 22 Sep 2009 11:29:13 +0000 (11:29 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 22 Sep 2009 11:29:13 +0000 (11:29 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4208 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/common/searchpath.c
src/common/searchpath.h

index d0f194a60abac92f6b650d80f714acedaa154322..2f536388bca3ecd9c66d6c4273b06978aa34d4dd 100644 (file)
@@ -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. */
 {
index 053301651e9ff1e248643437c4685823f9e4183b..181560f4caa5812228117cf6de4e91c085415171 100644 (file)
@@ -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. */