Various stuff for tidying of paths

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4567 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-07-12 04:21:05 +00:00
parent eec272988c
commit 280d5afaef
5 changed files with 477 additions and 279 deletions

View file

@ -1,3 +1,10 @@
Mon Jul 12 5:00:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSString.m: Bugfixes in ([stringByStandardizingPath:])
as suggested by Pascal Bourguignon. Also fix to do substitutions
throughout path, also use realpath() for resolving links if possible.
* configure.in: Check for realpath()
Sat Jul 10 13:52:20 1999 Adam Fedor <fedor@ultra.doc.com>
* Makefile.postamble: Create Foundation link in Source directory

View file

@ -1,4 +1,4 @@
/* Source/include/config.h.in. Generated automatically from configure.in by autoheader. */
/* Headers/gnustep/base/config.h.in. Generated automatically from configure.in by autoheader. */
/* Define as __inline if that's what the C compiler calls it. */
#undef inline
@ -63,6 +63,9 @@
/* Define if you have the mmap function. */
#undef HAVE_MMAP
/* Define if you have the realpath function. */
#undef HAVE_REALPATH
/* Define if you have the setpgid function. */
#undef HAVE_SETPGID

View file

@ -1900,31 +1900,39 @@ handle_printf_atsign (FILE *stream,
#if defined(__WIN32__)
return self;
#else
NSString *first_half = self, * second_half = @"";
const int MAX_PATH_LEN = 1024;
#if HAVE_REALPATH
char new_buf[MAX_PATH_LEN];
const char * tmp_cpath;
const int MAX_PATH_LEN = 1024;
char tmp_buf[MAX_PATH_LEN];
int syscall_result;
struct stat tmp_stat;
if (realpath([self cString], new_buf) != 0)
return [NSString stringWithCString: new_buf];
else
return self;
#else
NSString *first_half = self;
NSString *second_half = @"";
const char *tmp_cpath;
char tmp_buf[MAX_PATH_LEN];
int syscall_result;
struct stat tmp_stat;
while (1)
{
tmp_cpath = [first_half cString];
syscall_result = lstat(tmp_cpath, &tmp_stat);
if (0 != syscall_result) return self ;
if (0 != syscall_result)
return self ;
if ((tmp_stat.st_mode & S_IFLNK) &&
((syscall_result = readlink(tmp_cpath, tmp_buf, MAX_PATH_LEN)) != -1))
if ((tmp_stat.st_mode & S_IFLNK)
&& ((syscall_result=readlink(tmp_cpath, tmp_buf, MAX_PATH_LEN)) != -1))
{
/*
* first half is a path to a symbolic link.
*/
tmp_buf[syscall_result] = '\0'; // Make a C string
second_half = [[NSString stringWithCString: tmp_buf]
stringByAppendingPathComponent: second_half];
second_half = [[NSString stringWithCString: tmp_buf]
stringByAppendingPathComponent: second_half];
first_half = [first_half stringByDeletingLastPathComponent];
}
else
@ -1939,27 +1947,30 @@ handle_printf_atsign (FILE *stream,
* first half is NOT a path to a symbolic link
*/
second_half = [[first_half lastPathComponent]
stringByAppendingPathComponent: second_half];
stringByAppendingPathComponent: second_half];
first_half = [first_half stringByDeletingLastPathComponent];
}
/* BREAK CONDITION */
if ([first_half length] == 0) break;
if ([first_half length] == 0)
break;
else if ([first_half length] == 1
&& [pathSeps() characterIsMember: [first_half characterAtIndex: 0]])
{
second_half = [pathSepString stringByAppendingPathComponent: second_half];
second_half = [pathSepString stringByAppendingPathComponent:
second_half];
break;
}
}
return second_half;
#endif
#endif /* (__WIN32__) */
}
- (NSString*) stringByStandardizingPath
{
NSMutableString *s;
NSRange r;
NSMutableString *s;
NSRange r;
/* Expand `~' in the path */
s = [[self stringByExpandingTildeInPath] mutableCopy];
@ -1969,39 +1980,72 @@ handle_printf_atsign (FILE *stream,
[s deleteCharactersInRange: ((NSRange){0,7})];
/* Condense `//' */
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
&& r.location + r.length < [s length]
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 1]])
[s deleteCharactersInRange: r];
/* Condense `/./' */
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
&& r.location + r.length < [s length] + 1
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 2]])
while ((r = [s rangeOfCharacterFromSet: pathSeps()
options: 0
range: r]).length)
{
r.length++;
[s deleteCharactersInRange: r];
if (r.location + r.length + 1 <= [s length]
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 1]])
[s deleteCharactersInRange: r];
else
r.location++;
if ((r.length = [s length]) > r.location)
r.length -= r.location;
else
break;
}
/* Condense `/../' */
while ((r = [s rangeOfCharacterFromSet: pathSeps()]).length
&& r.location + r.length < [s length] + 2
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
&& [s characterAtIndex: r.location + 2] == (unichar)'.'
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 3]])
/* Condense `/./' */
while ((r = [s rangeOfCharacterFromSet: pathSeps()
options: 0
range: r]).length)
{
if (r.location > 0)
if (r.location + r.length + 2 <= [s length]
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 2]])
{
NSRange r2 = {0, r.location};
r = [s rangeOfCharacterFromSet: pathSeps()
options: NSBackwardsSearch
range: r2];
if (r.length == 0)
r = r2;
r.length += 4; /* Add the `/../' */
r.length++;
[s deleteCharactersInRange: r];
}
[s deleteCharactersInRange: r];
else
r.location++;
if ((r.length = [s length]) > r.location)
r.length -= r.location;
else
break;
}
if ([s isAbsolutePath] == NO)
return s;
/* Condense `/../' */
while ((r = [s rangeOfCharacterFromSet: pathSeps()
options: 0
range: r]).length)
{
if (r.location + r.length + 3 <= [s length]
&& [s characterAtIndex: r.location + 1] == (unichar)'.'
&& [s characterAtIndex: r.location + 2] == (unichar)'.'
&& [pathSeps() characterIsMember: [s characterAtIndex: r.location + 3]])
{
if (r.location > 0)
{
NSRange r2 = {0, r.location};
r = [s rangeOfCharacterFromSet: pathSeps()
options: NSBackwardsSearch
range: r2];
if (r.length == 0)
r = r2;
r.length += 4; /* Add the `/../' */
}
[s deleteCharactersInRange: r];
}
else
r.location++;
if ((r.length = [s length]) > r.location)
r.length -= r.location;
else
break;
}
return s;

607
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -507,6 +507,11 @@ if test $register_printf = 1; then
fi
fi
#--------------------------------------------------------------------
# This function needed by NSString.
#--------------------------------------------------------------------
AC_CHECK_FUNCS(realpath)
#--------------------------------------------------------------------
# Tools for making a DLL.
#--------------------------------------------------------------------