mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-29 22:40:34 +02:00
Use string accessors in scm_basename and scm_dirname
* libguile/filesys.c (basename, dirname): don't unpack strings. Use string accessor functions.
This commit is contained in:
parent
43d5626ce7
commit
832bbc95a2
1 changed files with 39 additions and 21 deletions
|
@ -1573,31 +1573,39 @@ SCM_DEFINE (scm_dirname, "dirname", 1, 0, 0,
|
||||||
"component, @code{.} is returned.")
|
"component, @code{.} is returned.")
|
||||||
#define FUNC_NAME s_scm_dirname
|
#define FUNC_NAME s_scm_dirname
|
||||||
{
|
{
|
||||||
const char *s;
|
|
||||||
long int i;
|
long int i;
|
||||||
unsigned long int len;
|
unsigned long int len;
|
||||||
|
|
||||||
SCM_VALIDATE_STRING (1, filename);
|
SCM_VALIDATE_STRING (1, filename);
|
||||||
|
|
||||||
s = scm_i_string_chars (filename);
|
|
||||||
len = scm_i_string_length (filename);
|
len = scm_i_string_length (filename);
|
||||||
|
|
||||||
i = len - 1;
|
i = len - 1;
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
while (i >= 0 && (s[i] == '/' || s[i] == '\\')) --i;
|
while (i >= 0 && (scm_i_string_ref (filename, i) == '/'
|
||||||
while (i >= 0 && (s[i] != '/' && s[i] != '\\')) --i;
|
|| scm_i_string_ref (filename, i) == '\\'))
|
||||||
while (i >= 0 && (s[i] == '/' || s[i] == '\\')) --i;
|
--i;
|
||||||
|
while (i >= 0 && (scm_i_string_ref (filename, i) != '/'
|
||||||
|
&& scm_i_string_ref (filename, i) != '\\'))
|
||||||
|
--i;
|
||||||
|
while (i >= 0 && (scm_i_string_ref (filename, i) == '/'
|
||||||
|
|| scm_i_string_ref (filename, i) == '\\'))
|
||||||
|
--i;
|
||||||
#else
|
#else
|
||||||
while (i >= 0 && s[i] == '/') --i;
|
while (i >= 0 && scm_i_string_ref (filename, i) == '/')
|
||||||
while (i >= 0 && s[i] != '/') --i;
|
--i;
|
||||||
while (i >= 0 && s[i] == '/') --i;
|
while (i >= 0 && scm_i_string_ref (filename, i) != '/')
|
||||||
|
--i;
|
||||||
|
while (i >= 0 && scm_i_string_ref (filename, i) == '/')
|
||||||
|
--i;
|
||||||
#endif /* ndef __MINGW32__ */
|
#endif /* ndef __MINGW32__ */
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
{
|
{
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
if (len > 0 && (s[0] == '/' || s[0] == '\\'))
|
if (len > 0 && (scm_i_string_ref (filename, 0) == '/'
|
||||||
|
|| scm_i_string_ref (filename, 0) == '\\'))
|
||||||
#else
|
#else
|
||||||
if (len > 0 && s[0] == '/')
|
if (len > 0 && scm_i_string_ref (filename, 0) == '/')
|
||||||
#endif /* ndef __MINGW32__ */
|
#endif /* ndef __MINGW32__ */
|
||||||
return scm_c_substring (filename, 0, 1);
|
return scm_c_substring (filename, 0, 1);
|
||||||
else
|
else
|
||||||
|
@ -1616,11 +1624,9 @@ SCM_DEFINE (scm_basename, "basename", 1, 1, 0,
|
||||||
"@var{basename}, it is removed also.")
|
"@var{basename}, it is removed also.")
|
||||||
#define FUNC_NAME s_scm_basename
|
#define FUNC_NAME s_scm_basename
|
||||||
{
|
{
|
||||||
const char *f, *s = 0;
|
|
||||||
int i, j, len, end;
|
int i, j, len, end;
|
||||||
|
|
||||||
SCM_VALIDATE_STRING (1, filename);
|
SCM_VALIDATE_STRING (1, filename);
|
||||||
f = scm_i_string_chars (filename);
|
|
||||||
len = scm_i_string_length (filename);
|
len = scm_i_string_length (filename);
|
||||||
|
|
||||||
if (SCM_UNBNDP (suffix))
|
if (SCM_UNBNDP (suffix))
|
||||||
|
@ -1628,32 +1634,44 @@ SCM_DEFINE (scm_basename, "basename", 1, 1, 0,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SCM_VALIDATE_STRING (2, suffix);
|
SCM_VALIDATE_STRING (2, suffix);
|
||||||
s = scm_i_string_chars (suffix);
|
|
||||||
j = scm_i_string_length (suffix) - 1;
|
j = scm_i_string_length (suffix) - 1;
|
||||||
}
|
}
|
||||||
i = len - 1;
|
i = len - 1;
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
while (i >= 0 && (f[i] == '/' || f[i] == '\\')) --i;
|
while (i >= 0 && (scm_i_string_ref (filename, i) == '/'
|
||||||
|
|| scm_i_string_ref (filename, i) == '\\'))
|
||||||
|
--i;
|
||||||
#else
|
#else
|
||||||
while (i >= 0 && f[i] == '/') --i;
|
while (i >= 0 && scm_i_string_ref (filename, i) == '/')
|
||||||
|
--i;
|
||||||
#endif /* ndef __MINGW32__ */
|
#endif /* ndef __MINGW32__ */
|
||||||
end = i;
|
end = i;
|
||||||
while (i >= 0 && j >= 0 && f[i] == s[j]) --i, --j;
|
while (i >= 0 && j >= 0
|
||||||
|
&& (scm_i_string_ref (filename, i)
|
||||||
|
== scm_i_string_ref (suffix, j)))
|
||||||
|
{
|
||||||
|
--i;
|
||||||
|
--j;
|
||||||
|
}
|
||||||
if (j == -1)
|
if (j == -1)
|
||||||
end = i;
|
end = i;
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
while (i >= 0 && f[i] != '/' && f[i] != '\\') --i;
|
while (i >= 0 && (scm_i_string_ref (filename, i) != '/'
|
||||||
|
&& scm_i_string_ref (filename, i) != '\\'))
|
||||||
|
--i;
|
||||||
#else
|
#else
|
||||||
while (i >= 0 && f[i] != '/') --i;
|
while (i >= 0 && scm_i_string_ref (filename, i) != '/')
|
||||||
|
--i;
|
||||||
#endif /* ndef __MINGW32__ */
|
#endif /* ndef __MINGW32__ */
|
||||||
if (i == end)
|
if (i == end)
|
||||||
{
|
{
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
if (len > 0 && (f[0] == '/' || f[0] == '\\'))
|
if (len > 0 && (scm_i_string_ref (filename, 0) == '/'
|
||||||
|
|| scm_i_string_ref (filename, 0) == '\\'))
|
||||||
#else
|
#else
|
||||||
if (len > 0 && f[0] == '/')
|
if (len > 0 && scm_i_string_ref (filename, 0) == '/')
|
||||||
#endif /* ndef __MINGW32__ */
|
#endif /* ndef __MINGW32__ */
|
||||||
return scm_c_substring (filename, 0, 1);
|
return scm_c_substring (filename, 0, 1);
|
||||||
else
|
else
|
||||||
return scm_dot_string;
|
return scm_dot_string;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue