From ebd679dd57319ad3524e1f2dd176cf87a97a4274 Mon Sep 17 00:00:00 2001 From: uz Date: Fri, 28 May 2010 11:22:44 +0000 Subject: [PATCH] New functions PushSearchPath and PopSearchPath. git-svn-id: svn://svn.cc65.org/cc65/trunk@4671 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/searchpath.c | 52 ++++++++++++++++++++++++++++++----------- src/common/searchpath.h | 6 +++++ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/common/searchpath.c b/src/common/searchpath.c index c44a9c9a8..a91383460 100644 --- a/src/common/searchpath.c +++ b/src/common/searchpath.c @@ -57,29 +57,36 @@ -static void Add (SearchPath* P, const char* New) -/* Cleanup a new search path and add it to the list */ +static char* CleanupPath (const char* Path) +/* Prepare and return a clean copy of Path */ { - unsigned NewLen; + unsigned Len; char* NewPath; - /* Get the length of the new path */ - NewLen = strlen (New); + /* Get the length of the path */ + Len = strlen (Path); /* Check for a trailing path separator and remove it */ - if (NewLen > 0 && (New[NewLen-1] == '\\' || New[NewLen-1] == '/')) { - --NewLen; + if (Len > 0 && (Path[Len-1] == '\\' || Path[Len-1] == '/')) { + --Len; } /* Allocate memory for the new string */ - NewPath = (char*) xmalloc (NewLen + 1); + NewPath = (char*) xmalloc (Len + 1); - /* Copy the path and terminate it */ - memcpy (NewPath, New, NewLen); - NewPath [NewLen] = '\0'; + /* Copy the path and terminate it, then return the copy */ + memcpy (NewPath, Path, Len); + NewPath [Len] = '\0'; + return NewPath; +} - /* Add the path to the collection */ - CollAppend (P, NewPath); + + +static void Add (SearchPath* P, const char* New) +/* Cleanup a new search path and add it to the list */ +{ + /* Add a clean copy of the path to the collection */ + CollAppend (P, CleanupPath (New)); } @@ -149,6 +156,25 @@ void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* Sub +void PushSearchPath (SearchPath* P, const char* NewPath) +/* Add a new search path to the head of an existing search path list */ +{ + /* Insert a clean copy of the path at position 0 */ + CollInsert (P, CleanupPath (NewPath), 0); +} + + + +void PopSearchPath (SearchPath* P) +/* Remove a search path from the head of an existing search path list */ +{ + /* Remove the path at position 0 */ + xfree (CollAt (P, 0)); + CollDelete (P, 0); +} + + + void ForgetSearchPath (SearchPath* P) /* Forget all search paths in the given list */ { diff --git a/src/common/searchpath.h b/src/common/searchpath.h index fa833d139..6c4745e59 100644 --- a/src/common/searchpath.h +++ b/src/common/searchpath.h @@ -75,6 +75,12 @@ void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* Sub * the environment variable value. */ +void PushSearchPath (SearchPath* P, const char* NewPath); +/* Add a new search path to the head of an existing search path list */ + +void PopSearchPath (SearchPath* P); +/* Remove a search path from the head of an existing search path list */ + void ForgetSearchPath (SearchPath* P); /* Forget all search paths in the given list */