Commit e6cfbc9e by Mark Elbrecht Committed by Jeff Law

cccp.c (DIR_SEPARATOR): Move to the top of the file.

        * cccp.c (DIR_SEPARATOR): Move to the top of the file.
        (is_dir_separator): New function.
        (simplify_filename): Use it.
Last bit of the dir separator patches.

From-SVN: r26331
parent 9ee9f4f0
...@@ -13,6 +13,9 @@ Sat Apr 10 05:14:50 1999 Mark Elbrecht <snowball3@usa.net> ...@@ -13,6 +13,9 @@ Sat Apr 10 05:14:50 1999 Mark Elbrecht <snowball3@usa.net>
* i386/djgpp.h (SET_ASM_OP): Define. * i386/djgpp.h (SET_ASM_OP): Define.
* cccp.c (DIR_SEPARATOR): Move to the top of the file.
(is_dir_separator): New function.
(simplify_filename): Use it.
* collect2.c (find_a_file): Use HAVE_DOS_BASED_FILE_SYSTEM in place * collect2.c (find_a_file): Use HAVE_DOS_BASED_FILE_SYSTEM in place
of the DIR_SEPARATOR test. of the DIR_SEPARATOR test.
Consider any file starting with a drivename to be absolute. Consider any file starting with a drivename to be absolute.
......
...@@ -51,6 +51,11 @@ typedef unsigned char U_CHAR; ...@@ -51,6 +51,11 @@ typedef unsigned char U_CHAR;
# define PATH_SEPARATOR ':' # define PATH_SEPARATOR ':'
#endif #endif
/* By default, a slash separates directory names. */
#ifndef DIR_SEPARATOR
# define DIR_SEPARATOR '/'
#endif
/* By default, the suffix for object files is ".o". */ /* By default, the suffix for object files is ".o". */
#ifdef OBJECT_SUFFIX #ifdef OBJECT_SUFFIX
# define HAVE_OBJECT_SUFFIX # define HAVE_OBJECT_SUFFIX
...@@ -4782,6 +4787,20 @@ absolute_filename (filename) ...@@ -4782,6 +4787,20 @@ absolute_filename (filename)
return 0; return 0;
} }
/* Returns whether or not a given character is a directory separator.
Used by simplify_filename. */
static inline
int
is_dir_separator(ch)
char ch;
{
return (ch == DIR_SEPARATOR)
#if defined (DIR_SEPARATOR_2)
|| (ch == DIR_SEPARATOR_2)
#endif
;
}
/* Remove unnecessary characters from FILENAME in place, /* Remove unnecessary characters from FILENAME in place,
to avoid unnecessary filename aliasing. to avoid unnecessary filename aliasing.
Return the length of the resulting string. Return the length of the resulting string.
...@@ -4799,55 +4818,70 @@ simplify_filename (filename) ...@@ -4799,55 +4818,70 @@ simplify_filename (filename)
char *to0; char *to0;
/* Remove redundant initial /s. */ /* Remove redundant initial /s. */
if (*from == '/') { if (is_dir_separator (*from))
*to++ = '/'; {
if (*++from == '/') { *to++ = DIR_SEPARATOR;
if (*++from == '/') { if (is_dir_separator (*++from))
/* 3 or more initial /s are equivalent to 1 /. */ {
while (*++from == '/') if (is_dir_separator (*++from))
continue; {
} else { /* 3 or more initial /s are equivalent to 1 /. */
/* On some hosts // differs from /; Posix allows this. */ while (is_dir_separator (*++from))
static int slashslash_vs_slash; continue;
if (slashslash_vs_slash == 0) { }
struct stat s1, s2; else
slashslash_vs_slash = ((stat ("/", &s1) == 0 && stat ("//", &s2) == 0 {
&& INO_T_EQ (s1.st_ino, s2.st_ino) /* On some hosts // differs from /; Posix allows this. */
&& s1.st_dev == s2.st_dev) static int slashslash_vs_slash;
? 1 : -1); if (slashslash_vs_slash == 0)
} {
if (slashslash_vs_slash < 0) struct stat s1, s2;
*to++ = '/'; slashslash_vs_slash = ((stat ("/", &s1) == 0
} && stat ("//", &s2) == 0
&& INO_T_EQ (s1.st_ino, s2.st_ino)
&& s1.st_dev == s2.st_dev)
? 1 : -1);
}
if (slashslash_vs_slash < 0)
*to++ = DIR_SEPARATOR;
}
}
} }
}
to0 = to; to0 = to;
for (;;) { for (;;)
{
#ifndef VMS #ifndef VMS
if (from[0] == '.' && from[1] == '/') if (from[0] == '.' && from[1] == '/')
from += 2; from += 2;
else else
#endif #endif
{ {
/* Copy this component and trailing /, if any. */ /* Copy this component and trailing DIR_SEPARATOR, if any. */
while ((*to++ = *from++) != '/') { while (!is_dir_separator (*to++ = *from++))
if (!to[-1]) { {
/* Trim . component at end of nonempty name. */ if (!to[-1])
to -= filename <= to - 3 && to[-3] == '/' && to[-2] == '.'; {
/* Trim . component at end of nonempty name. */
/* Trim unnecessary trailing /s. */ to -= filename <= to - 3 && to[-3] == DIR_SEPARATOR && to[-2] == '.';
while (to0 < --to && to[-1] == '/')
continue; /* Trim unnecessary trailing /s. */
while (to0 < --to && to[-1] == DIR_SEPARATOR)
*to = 0; continue;
return to - filename;
} *to = 0;
} return to - filename;
} }
}
#if defined(DIR_SEPARATOR_2)
/* Simplify to one directory separator. */
to[-1] = DIR_SEPARATOR;
#endif
}
/* Skip /s after a /. */ /* Skip /s after a /. */
while (*from == '/') while (is_dir_separator (*from))
from++; from++;
} }
} }
...@@ -10322,10 +10356,6 @@ make_assertion (option, str) ...@@ -10322,10 +10356,6 @@ make_assertion (option, str)
--indepth; --indepth;
} }
#ifndef DIR_SEPARATOR
#define DIR_SEPARATOR '/'
#endif
/* The previous include prefix, if any, is PREV_FILE_NAME. /* The previous include prefix, if any, is PREV_FILE_NAME.
Translate any pathnames with COMPONENT. Translate any pathnames with COMPONENT.
Allocate a new include prefix whose name is the Allocate a new include prefix whose name is the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment