New functions PushSearchPath and PopSearchPath.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4671 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
64b597017a
commit
ebd679dd57
2 changed files with 45 additions and 13 deletions
|
@ -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 */
|
||||
{
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue