From patchwork Sat Mar 12 16:44:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 86527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0B05BB6F78 for ; Sun, 13 Mar 2011 03:45:04 +1100 (EST) Received: (qmail 11412 invoked by alias); 12 Mar 2011 16:44:59 -0000 Received: (qmail 11388 invoked by uid 22791); 12 Mar 2011 16:44:57 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-qw0-f47.google.com (HELO mail-qw0-f47.google.com) (209.85.216.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 12 Mar 2011 16:44:52 +0000 Received: by qwh5 with SMTP id 5so464900qwh.20 for ; Sat, 12 Mar 2011 08:44:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.130.93 with SMTP id r29mr8756492qcs.6.1299948290652; Sat, 12 Mar 2011 08:44:50 -0800 (PST) Received: by 10.229.89.197 with HTTP; Sat, 12 Mar 2011 08:44:50 -0800 (PST) In-Reply-To: <201103081941.p28Jf0Uq027041@greed.delorie.com> References: <83aah5h34g.fsf@gnu.org> <201103081941.p28Jf0Uq027041@greed.delorie.com> Date: Sat, 12 Mar 2011 17:44:50 +0100 Message-ID: Subject: Re: [patch libiberty include]: Add additional helper functions for directory-separator searching From: Kai Tietz To: DJ Delorie Cc: Eli Zaretskii , binutils@sourceware.org, gdb-patches@sourceware.org, gcc-patches@gcc.gnu.org X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 2011/3/8 DJ Delorie : > >> I think we don't need filename_dirchr, only filename_dirrchr. > > I see no harm in having both, for completeness, though.  One could > argue they should be in separate files, but they're trivial functions > on non-dos-fs systems. > > What bothers me about this patch is that we're adding yet another set > of functions that don't discriminate between the host filesystem, the > target filesystem, and the build filesystem. > Ok, I got the point about having here implementations which can handle both cases. So I added an additional argument to those functions to specify for which file-system flavor is searched. I don't see right now much use for this difference, but well, it won't harm to have this ability too. 2011-03-12 Kai Tietz * filename.h (filename_dirchr_host): New macro. (filename_dirrchr_host): New macro. (filename_dirchr): New prototype. (filename_dirrchr): New prototype. 2011-03-12 Kai Tietz * filename_chr.c: New file. * Makefile.in (CFILES): Add filename_chr.c file. (REQUIRED_OFILES): Add filename_chr.o (filename_chr.o): New rule. * functions.texi: Regenerated. Tested for x86_64-w64-mingw32, and x86_64-pc-linux-gnu. Ok for apply? Regards, Kai Index: gcc/include/filenames.h =================================================================== --- gcc.orig/include/filenames.h 2011-03-12 17:02:03.802364200 +0100 +++ gcc/include/filenames.h 2011-03-12 17:31:48.887339800 +0100 @@ -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 Index: gcc/libiberty/functions.texi =================================================================== --- gcc.orig/libiberty/functions.texi 2011-03-12 17:02:03.817364200 +0100 +++ gcc/libiberty/functions.texi 2011-03-12 17:33:02.731563500 +0100 @@ -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}) Index: gcc/libiberty/Makefile.in =================================================================== --- gcc.orig/libiberty/Makefile.in 2011-03-12 17:02:03.829364200 +0100 +++ gcc/libiberty/Makefile.in 2011-03-12 17:06:49.519580900 +0100 @@ -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 \ Index: gcc/libiberty/filename_chr.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ gcc/libiberty/filename_chr.c 2011-03-12 17:31:11.640209400 +0100 @@ -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 +#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; +}