Skip to content

Commit

Permalink
Add support for absolute paths in #Append/PrependPath
Browse files Browse the repository at this point in the history
Unix: an absolute path starts with '/'.

Windows: an absolute path starts with '\\' or contains the drive letter
as a full path (like "C:\\foo"). Note that relative paths in different
drives (like "D:..\\foo") are unsupported and do not work correctly.
  • Loading branch information
tueda committed Mar 29, 2017
1 parent 29c1794 commit a4fd5e1
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions sources/pre.c
Original file line number Diff line number Diff line change
Expand Up @@ -6745,7 +6745,7 @@ static int DoAddPath(UBYTE *s, int bPrepend)
/* NOTE: this doesn't support some file systems, e.g., 0x5c with CP932. */

UBYTE *path, *path_end, *current_dir, *current_dir_end, *NewPath, *t;
int n;
int bRelative, n;

if ( AP.PreSwitchModes[AP.PreSwitchLevel] != EXECUTINGPRESWITCH ) return(0);
if ( AP.PreIfStack[AP.PreIfLevel] != EXECUTINGIF ) return(0);
Expand Down Expand Up @@ -6779,7 +6779,19 @@ static int DoAddPath(UBYTE *s, int bPrepend)
while ( *s == ' ' || *s == '\t' ) s++; /* skip spaces */
if ( *s ) goto ImproperPath; /* extra tokens found */

/* Get the current file directory. */
/* Check if the path is an absolute path. */
bRelative = 1;
if ( path[0] == SEPARATOR ) { /* starts with the directory separator */
bRelative = 0;
}
#ifdef WINDOWS
else if ( chartype[path[0]] == 0 && path[1] == ':' ) { /* starts with (drive letter): */
bRelative = 0;
}
#endif

/* Get the current file directory when a relative path is given. */
if ( bRelative ) {
if ( !AC.CurrentStream ) goto FileNameUnavailable;
if ( AC.CurrentStream->type != FILESTREAM && AC.CurrentStream->type != REVERSEFILESTREAM ) goto FileNameUnavailable;
if ( !AC.CurrentStream->name ) goto FileNameUnavailable;
Expand All @@ -6794,6 +6806,10 @@ static int DoAddPath(UBYTE *s, int bPrepend)
}
s++;
}
}
else {
current_dir = current_dir_end = NULL;
}

/* Allocate a buffer for new AM.Path. */
n = path_end - path;
Expand Down Expand Up @@ -6845,8 +6861,8 @@ static int DoAddPath(UBYTE *s, int bPrepend)
}

/**
* Appends the given path (relative to the current file directory) to
* the FORM path.
* Appends the given path (absolute or relative to the current file directory)
* to the FORM path.
*
* Syntax:
* #appendpath <path>
Expand All @@ -6862,8 +6878,8 @@ int DoPreAppendPath(UBYTE *s)
*/

/**
* Prepends the given path (relative to the current file directory) to
* the FORM path.
* Prepends the given path (absolute or relative to the current file directory)
* to the FORM path.
*
* Syntax:
* #prependpath <path>
Expand Down

0 comments on commit a4fd5e1

Please sign in to comment.