===================================================================
@@ -37,10 +37,14 @@ extern "C" {
# define HAS_DRIVE_SPEC(f) HAS_DOS_DRIVE_SPEC (f)
# define IS_DIR_SEPARATOR(c) IS_DOS_DIR_SEPARATOR (c)
# define IS_ABSOLUTE_PATH(f) IS_DOS_ABSOLUTE_PATH (f)
+# define filename_dirchr_host(P) filename_dirchr (1, (P))
+# define filename_dirrchr_host(P) filename_dirrchr (1, (P))
#else /* not DOSish */
# define HAS_DRIVE_SPEC(f) (0)
# define IS_DIR_SEPARATOR(c) IS_UNIX_DIR_SEPARATOR (c)
# define IS_ABSOLUTE_PATH(f) IS_UNIX_ABSOLUTE_PATH (f)
+# define filename_dirchr_host(P) filename_dirchr (0, (P))
+# define filename_dirrchr_host(P) filename_dirrchr (0, (P))
#endif
#define IS_DIR_SEPARATOR_1(dos_based, c) \
@@ -76,6 +80,9 @@ extern int filename_cmp (const char *s1,
extern int filename_ncmp (const char *s1, const char *s2,
size_t n);
+extern char *filename_dirchr (int dos_based, const char *p);
+extern char *filename_dirrchr (int dos_based, const char *p);
+
#ifdef __cplusplus
}
#endif
===================================================================
@@ -296,6 +296,32 @@ and backward slashes are equal.
@end deftypefn
+@c filename_chr.c:32
+@deftypefn Extension int filename_dirchr (int @var{dos_based}, const char *@var{p})
+
+This function searchs for first occurance of a directory-separator character in
+the filename @var{p} from left to right direction.
+If argument @var{dos_based} is not zero, in addition to the UNIX-style slash
+also the DOS-style backslash is searched as directory separator.
+This function does not normalize file name. The result of this routine is
+@code{NULL} pointer, if no match was found. Otherwise it returns the pointer
+to the found match.
+
+@end deftypefn
+
+@c filename_chr.c:65
+@deftypefn Extension int filename_dirrchr (int @var{dos_based}, const char *@var{p})
+
+This function searchs for first occurance of a directory-separator character in
+the filename @var{p} from right to left direction.
+If argument @var{dos_based} is not zero, in addition to the UNIX-style slash
+also the DOS-style backslash is treated as directory separator.
+This function does not normalize file name. The result of this routine is
+@code{NULL} pointer, if no match was found. Otherwise it returns the pointer
+to the found match.
+
+@end deftypefn
+
@c filename_cmp.c:81
@deftypefn Extension int filename_ncmp (const char *@var{s1}, const char *@var{s2}, size_t @var{n})
===================================================================
@@ -127,8 +127,8 @@ CFILES = alloca.c argv.c asprintf.c atex
calloc.c choose-temp.c clock.c concat.c cp-demangle.c \
cp-demint.c cplus-dem.c crc32.c \
dyn-string.c \
- fdmatch.c ffs.c fibheap.c filename_cmp.c floatformat.c \
- fnmatch.c fopen_unlocked.c \
+ fdmatch.c ffs.c fibheap.c filename_chr.c filename_cmp.c \
+ floatformat.c fnmatch.c fopen_unlocked.c \
getcwd.c getopt.c getopt1.c getpagesize.c getpwd.c getruntime.c \
gettimeofday.c \
hashtab.c hex.c \
@@ -168,7 +168,8 @@ REQUIRED_OFILES = \
./choose-temp.$(objext) ./concat.$(objext) \
./cp-demint.$(objext) ./crc32.$(objext) ./dyn-string.$(objext) \
./fdmatch.$(objext) ./fibheap.$(objext) \
- ./filename_cmp.$(objext) ./floatformat.$(objext) \
+ ./filename_chr.$(objext) ./filename_cmp.$(objext) \
+ ./floatformat.$(objext) \
./fnmatch.$(objext) ./fopen_unlocked.$(objext) \
./getopt.$(objext) ./getopt1.$(objext) ./getpwd.$(objext) \
./getruntime.$(objext) ./hashtab.$(objext) ./hex.$(objext) \
@@ -646,6 +647,13 @@ $(CONFIGURED_OFILES): stamp-picdir
else true; fi
$(COMPILE.c) $(srcdir)/fibheap.c $(OUTPUT_OPTION)
+./filename_chr.$(objext): $(srcdir)/filename_chr.c config.h $(INCDIR)/filenames.h \
+ $(INCDIR)/safe-ctype.h
+ if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/filename_chr.c -o pic/$@; \
+ else true; fi
+ $(COMPILE.c) $(srcdir)/filename_chr.c $(OUTPUT_OPTION)
+
./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/filenames.h \
$(INCDIR)/safe-ctype.h
if [ x"$(PICFLAG)" != x ]; then \
===================================================================
@@ -0,0 +1,96 @@
+/* File name character searching routines.
+
+ Copyright (C) 2011 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include "filenames.h"
+#include "safe-ctype.h"
+
+/*
+
+@deftypefn Extension int filename_dirchr (int @var{dos_based}, const char *@var{p})
+
+This function searchs for first occurance of a directory-separator character in
+the filename @var{p} from left to right direction.
+If argument @var{dos_based} is not zero, in addition to the UNIX-style slash
+also the DOS-style backslash is searched as directory separator.
+This function does not normalize file name. The result of this routine is
+@code{NULL} pointer, if no match was found. Otherwise it returns the pointer
+to the found match.
+
+@end deftypefn
+
+*/
+
+char *
+filename_dirchr (int dos_based, const char *p)
+{
+ char *r;
+
+ if (!p)
+ return NULL;
+ r = strchr (p, '/');
+ if (dos_based)
+ {
+ char *r2 = strchr (p, '\\');
+ if (!r || (r2 && r2 < r))
+ r = r2;
+ }
+ return r;
+}
+
+/*
+
+@deftypefn Extension int filename_dirrchr (int @var{dos_based}, const char *@var{p})
+
+This function searchs for first occurance of a directory-separator character in
+the filename @var{p} from right to left direction.
+If argument @var{dos_based} is not zero, in addition to the UNIX-style slash
+also the DOS-style backslash is treated as directory separator.
+This function does not normalize file name. The result of this routine is
+@code{NULL} pointer, if no match was found. Otherwise it returns the pointer
+to the found match.
+
+@end deftypefn
+
+*/
+
+char *
+filename_dirrchr (int dos_based, const char *p)
+{
+ char *r;
+
+ if (!p)
+ return NULL;
+
+ r = strrchr (p, '/');
+ if (dos_based)
+ {
+ char *r2 = strrchr (p, '\\');
+
+ if (!r || (r2 && r2 > r))
+ r = r2;
+ }
+ return r;
+}