From: Akim Demaille Date: Tue, 8 Jan 2002 17:30:53 +0000 (+0000) Subject: * lib/basename.c, lib/dirname.h, lib/dirname.c, lib/memrchr.c, X-Git-Tag: BISON-1_30j~4 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/43cc2463d26364b13b776dd272170a809b2db800 * lib/basename.c, lib/dirname.h, lib/dirname.c, lib/memrchr.c, * lib/xstrndup.c, lib/strchr.c: New, stolen from the Fileutils 4.1. * lib/Makefile.am (libbison_a_SOURCES): Adjust. * configure.in: Check for the presence of memrchr, strchr, strnlen, and of their prototypes. Don't check for strndup: we no longer use it. * src/system.h: Adjust the prototypes. --- diff --git a/ChangeLog b/ChangeLog index 6aa84cc7..0adb9135 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2002-01-08 Akim Demaille + + * lib/basename.c, lib/dirname.h, lib/dirname.c, lib/memrchr.c, + * lib/xstrndup.c, lib/strchr.c: + New, stolen from the Fileutils 4.1. + * lib/Makefile.am (libbison_a_SOURCES): Adjust. + * configure.in: Check for the presence of memrchr, strchr, + strnlen, and of their prototypes. + Don't check for strndup: we no longer use it. + * src/system.h: Adjust the prototypes. + 2002-01-07 Akim Demaille * src/conflicts.c (count_rr_conflicts): The previous RR conflicts diff --git a/config.hin b/config.hin index 3fd84502..00959174 100644 --- a/config.hin +++ b/config.hin @@ -35,10 +35,18 @@ */ #undef HAVE_DECL_MEMCHR +/* Define to 1 if you have the declaration of `memrchr', and to 0 if you + don't. */ +#undef HAVE_DECL_MEMRCHR + /* Define to 1 if you have the declaration of `stpcpy', and to 0 if you don't. */ #undef HAVE_DECL_STPCPY +/* Define to 1 if you have the declaration of `strchr', and to 0 if you don't. + */ +#undef HAVE_DECL_STRCHR + /* Define to 1 if you have the declaration of `strerror', and to 0 if you don't. */ #undef HAVE_DECL_STRERROR @@ -47,14 +55,14 @@ don't. */ #undef HAVE_DECL_STRERROR_R -/* Define to 1 if you have the declaration of `strndup', and to 0 if you - don't. */ -#undef HAVE_DECL_STRNDUP - /* Define to 1 if you have the declaration of `strnlen', and to 0 if you don't. */ #undef HAVE_DECL_STRNLEN +/* Define to 1 if you have the declaration of `strspn', and to 0 if you don't. + */ +#undef HAVE_DECL_STRSPN + /* Define if the malloc check has been performed. */ #undef HAVE_DONE_WORKING_MALLOC_CHECK @@ -133,6 +141,9 @@ /* Define to 1 if you have the `mempcpy' function. */ #undef HAVE_MEMPCPY +/* Define to 1 if you have the `memrchr' function. */ +#undef HAVE_MEMRCHR + /* Define to 1 if you have the `mkstemp' function. */ #undef HAVE_MKSTEMP @@ -190,9 +201,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STRING_H -/* Define to 1 if you have the `strndup' function. */ -#undef HAVE_STRNDUP - /* Define to 1 if you have the `strnlen' function. */ #undef HAVE_STRNLEN @@ -241,6 +249,21 @@ /* Name of package */ #undef PACKAGE +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + /* Define if compiler has function prototypes */ #undef PROTOTYPES diff --git a/configure b/configure index 56634d58..d714936b 100755 --- a/configure +++ b/configure @@ -253,6 +253,13 @@ SHELL=${CONFIG_SHELL-/bin/sh} # only ac_max_sed_lines should be used. : ${ac_max_here_lines=38} +# Identity of this package. +PACKAGE_NAME='GNU Bison' +PACKAGE_TARNAME='bison' +PACKAGE_VERSION='1.30j' +PACKAGE_STRING='GNU Bison 1.30j' +PACKAGE_BUGREPORT='bug-bison@gnu.org' + # Factoring default headers for most tests. ac_includes_default="\ #include @@ -329,13 +336,6 @@ oldincludedir='/usr/include' infodir='${prefix}/info' mandir='${prefix}/man' -# Identity of this package. -PACKAGE_NAME='GNU Bison' -PACKAGE_TARNAME='bison' -PACKAGE_VERSION='1.30j' -PACKAGE_STRING='GNU Bison 1.30j' -PACKAGE_BUGREPORT='bug-bison@gnu.org' - ac_prev= for ac_option do @@ -1070,6 +1070,33 @@ rm -rf conftest* confdefs.h # AIX cpp loses on an empty file, so make sure it contains at least a newline. echo >confdefs.h +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + # Let the site file select an alternate cache file if it wants to. # Prefer explicitly selected file to automatically selected ones. if test -z "$CONFIG_SITE"; then @@ -1520,9 +1547,6 @@ ac_config_headers="$ac_config_headers config.h:config.hin" # Initialize the test suite. -ac_config_commands="$ac_config_commands tests/package.m4" - - ac_config_commands="$ac_config_commands tests/atconfig" @@ -5131,9 +5155,9 @@ _ACEOF fi -echo "$as_me:$LINENO: checking whether strndup is declared" >&5 -echo $ECHO_N "checking whether strndup is declared... $ECHO_C" >&6 -if test "${ac_cv_have_decl_strndup+set}" = set; then +echo "$as_me:$LINENO: checking whether strchr is declared" >&5 +echo $ECHO_N "checking whether strchr is declared... $ECHO_C" >&6 +if test "${ac_cv_have_decl_strchr+set}" = set; then echo $ECHO_N "(cached) $ECHO_C" >&6 else cat >conftest.$ac_ext <<_ACEOF @@ -5149,8 +5173,8 @@ $ac_includes_default int main () { -#ifndef strndup - char *p = (char *) strndup; +#ifndef strchr + char *p = (char *) strchr; #endif ; @@ -5169,26 +5193,88 @@ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); }; }; then - ac_cv_have_decl_strndup=yes + ac_cv_have_decl_strchr=yes else echo "$as_me: failed program was:" >&5 cat conftest.$ac_ext >&5 -ac_cv_have_decl_strndup=no +ac_cv_have_decl_strchr=no fi rm -f conftest.$ac_objext conftest.$ac_ext fi -echo "$as_me:$LINENO: result: $ac_cv_have_decl_strndup" >&5 -echo "${ECHO_T}$ac_cv_have_decl_strndup" >&6 -if test $ac_cv_have_decl_strndup = yes; then +echo "$as_me:$LINENO: result: $ac_cv_have_decl_strchr" >&5 +echo "${ECHO_T}$ac_cv_have_decl_strchr" >&6 +if test $ac_cv_have_decl_strchr = yes; then cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_STRNDUP 1 +#define HAVE_DECL_STRCHR 1 _ACEOF else cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_STRNDUP 0 +#define HAVE_DECL_STRCHR 0 +_ACEOF + + +fi +echo "$as_me:$LINENO: checking whether strspn is declared" >&5 +echo $ECHO_N "checking whether strspn is declared... $ECHO_C" >&6 +if test "${ac_cv_have_decl_strspn+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +$ac_includes_default +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +#ifndef strspn + char *p = (char *) strspn; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_have_decl_strspn=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_have_decl_strspn=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_have_decl_strspn" >&5 +echo "${ECHO_T}$ac_cv_have_decl_strspn" >&6 +if test $ac_cv_have_decl_strspn = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_STRSPN 1 +_ACEOF + + +else + cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_STRSPN 0 _ACEOF @@ -5317,14 +5403,77 @@ _ACEOF fi +echo "$as_me:$LINENO: checking whether memrchr is declared" >&5 +echo $ECHO_N "checking whether memrchr is declared... $ECHO_C" >&6 +if test "${ac_cv_have_decl_memrchr+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +#include "confdefs.h" +$ac_includes_default +#ifdef F77_DUMMY_MAIN +# ifdef __cplusplus + extern "C" +# endif + int F77_DUMMY_MAIN() { return 1; } +#endif +int +main () +{ +#ifndef memrchr + char *p = (char *) memrchr; +#endif + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_have_decl_memrchr=yes +else + echo "$as_me: failed program was:" >&5 +cat conftest.$ac_ext >&5 +ac_cv_have_decl_memrchr=no +fi +rm -f conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_have_decl_memrchr" >&5 +echo "${ECHO_T}$ac_cv_have_decl_memrchr" >&6 +if test $ac_cv_have_decl_memrchr = yes; then +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_MEMRCHR 1 +_ACEOF +else + cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_MEMRCHR 0 +_ACEOF + + +fi -for ac_func in stpcpy strndup strnlen strspn memchr + + + + + +for ac_func in stpcpy strchr strnlen strspn memchr memrchr do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -9304,12 +9453,6 @@ cat >>$CONFIG_STATUS <<_ACEOF # INIT-COMMANDS section. # -PACKAGE_NAME='$PACKAGE_NAME' -PACKAGE_TARNAME='$PACKAGE_TARNAME' -PACKAGE_VERSION='$PACKAGE_VERSION' -PACKAGE_STRING='$PACKAGE_STRING' -PACKAGE_BUGREPORT='$PACKAGE_BUGREPORT' - AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir" @@ -9333,7 +9476,6 @@ do "src/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/Makefile" ;; "doc/Makefile" ) CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; "m4/Makefile" ) CONFIG_FILES="$CONFIG_FILES m4/Makefile" ;; - "tests/package.m4" ) CONFIG_COMMANDS="$CONFIG_COMMANDS tests/package.m4" ;; "tests/atconfig" ) CONFIG_COMMANDS="$CONFIG_COMMANDS tests/atconfig" ;; "depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "default-1" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default-1" ;; @@ -9392,6 +9534,11 @@ if test -n "\$CONFIG_FILES"; then s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF s,@SHELL@,$SHELL,;t t s,@PATH_SEPARATOR@,$PATH_SEPARATOR,;t t +s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t +s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t +s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t +s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t +s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t s,@exec_prefix@,$exec_prefix,;t t s,@prefix@,$prefix,;t t s,@program_transform_name@,$program_transform_name,;t t @@ -9407,11 +9554,6 @@ s,@includedir@,$includedir,;t t s,@oldincludedir@,$oldincludedir,;t t s,@infodir@,$infodir,;t t s,@mandir@,$mandir,;t t -s,@PACKAGE_NAME@,$PACKAGE_NAME,;t t -s,@PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t -s,@PACKAGE_VERSION@,$PACKAGE_VERSION,;t t -s,@PACKAGE_STRING@,$PACKAGE_STRING,;t t -s,@PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t s,@build_alias@,$build_alias,;t t s,@host_alias@,$host_alias,;t t s,@target_alias@,$target_alias,;t t @@ -9971,15 +10113,6 @@ ac_abs_top_srcdir=`cd "$ac_dir" && cd $ac_top_srcdir && pwd` { echo "$as_me:$LINENO: executing $ac_dest commands" >&5 echo "$as_me: executing $ac_dest commands" >&6;} case $ac_dest in - tests/package.m4 ) cat >tests/package.m4 <tests/atconfig < alloca_.c || rm -f alloca_.c +basename_.c: basename.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/basename.c; then echo $(srcdir)/basename.c; else echo basename.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > basename_.c || rm -f basename_.c +dirname_.c: dirname.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/dirname.c; then echo $(srcdir)/dirname.c; else echo dirname.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > dirname_.c || rm -f dirname_.c error_.c: error.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/error.c; then echo $(srcdir)/error.c; else echo error.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > error_.c || rm -f error_.c getopt_.c: getopt.c $(ANSI2KNR) @@ -238,6 +248,8 @@ malloc_.c: malloc.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/malloc.c; then echo $(srcdir)/malloc.c; else echo malloc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > malloc_.c || rm -f malloc_.c memchr_.c: memchr.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/memchr.c; then echo $(srcdir)/memchr.c; else echo memchr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > memchr_.c || rm -f memchr_.c +memrchr_.c: memrchr.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/memrchr.c; then echo $(srcdir)/memrchr.c; else echo memrchr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > memrchr_.c || rm -f memrchr_.c obstack_.c: obstack.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/obstack.c; then echo $(srcdir)/obstack.c; else echo obstack.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > obstack_.c || rm -f obstack_.c quote_.c: quote.c $(ANSI2KNR) @@ -248,8 +260,8 @@ realloc_.c: realloc.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/realloc.c; then echo $(srcdir)/realloc.c; else echo realloc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > realloc_.c || rm -f realloc_.c stpcpy_.c: stpcpy.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/stpcpy.c; then echo $(srcdir)/stpcpy.c; else echo stpcpy.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > stpcpy_.c || rm -f stpcpy_.c -strndup_.c: strndup.c $(ANSI2KNR) - $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strndup.c; then echo $(srcdir)/strndup.c; else echo strndup.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strndup_.c || rm -f strndup_.c +strchr_.c: strchr.c $(ANSI2KNR) + $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strchr.c; then echo $(srcdir)/strchr.c; else echo strchr.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strchr_.c || rm -f strchr_.c strnlen_.c: strnlen.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strnlen.c; then echo $(srcdir)/strnlen.c; else echo strnlen.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strnlen_.c || rm -f strnlen_.c strspn_.c: strspn.c $(ANSI2KNR) @@ -258,11 +270,12 @@ xmalloc_.c: xmalloc.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xmalloc.c; then echo $(srcdir)/xmalloc.c; else echo xmalloc.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xmalloc_.c || rm -f xmalloc_.c xstrdup_.c: xstrdup.c $(ANSI2KNR) $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/xstrdup.c; then echo $(srcdir)/xstrdup.c; else echo xstrdup.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > xstrdup_.c || rm -f xstrdup_.c -alloca_.$(OBJEXT) error_.$(OBJEXT) getopt_.$(OBJEXT) getopt1_.$(OBJEXT) \ -malloc_.$(OBJEXT) memchr_.$(OBJEXT) obstack_.$(OBJEXT) quote_.$(OBJEXT) \ -quotearg_.$(OBJEXT) realloc_.$(OBJEXT) stpcpy_.$(OBJEXT) \ -strndup_.$(OBJEXT) strnlen_.$(OBJEXT) strspn_.$(OBJEXT) \ -xmalloc_.$(OBJEXT) xstrdup_.$(OBJEXT) : $(ANSI2KNR) +alloca_.$(OBJEXT) basename_.$(OBJEXT) dirname_.$(OBJEXT) \ +error_.$(OBJEXT) getopt_.$(OBJEXT) getopt1_.$(OBJEXT) malloc_.$(OBJEXT) \ +memchr_.$(OBJEXT) memrchr_.$(OBJEXT) obstack_.$(OBJEXT) \ +quote_.$(OBJEXT) quotearg_.$(OBJEXT) realloc_.$(OBJEXT) \ +stpcpy_.$(OBJEXT) strchr_.$(OBJEXT) strnlen_.$(OBJEXT) \ +strspn_.$(OBJEXT) xmalloc_.$(OBJEXT) xstrdup_.$(OBJEXT) : $(ANSI2KNR) uninstall-info-am: tags: TAGS diff --git a/lib/basename.c b/lib/basename.c new file mode 100644 index 00000000..36e0f62b --- /dev/null +++ b/lib/basename.c @@ -0,0 +1,71 @@ +/* basename.c -- return the last element in a path + Copyright (C) 1990, 1998, 1999, 2000, 2001 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#if HAVE_CONFIG_H +# include +#endif + +#include +#include + +#ifndef FILESYSTEM_PREFIX_LEN +# define FILESYSTEM_PREFIX_LEN(Filename) 0 +#endif + +#ifndef PARAMS +# if defined PROTOTYPES || (defined __STDC__ && __STDC__) +# define PARAMS(Args) Args +# else +# define PARAMS(Args) () +# endif +#endif + +#ifndef ISSLASH +# define ISSLASH(C) ((C) == '/') +#endif + +char *base_name PARAMS ((char const *name)); + +/* In general, we can't use the builtin `basename' function if available, + since it has different meanings in different environments. + In some environments the builtin `basename' modifies its argument. + If NAME is all slashes, be sure to return `/'. */ + +char * +base_name (char const *name) +{ + char const *base = name += FILESYSTEM_PREFIX_LEN (name); + int all_slashes = 1; + char const *p; + + for (p = name; *p; p++) + { + if (ISSLASH (*p)) + base = p + 1; + else + all_slashes = 0; + } + + /* If NAME is all slashes, arrange to return `/'. */ + if (*base == '\0' && ISSLASH (*name) && all_slashes) + --base; + + /* Make sure the last byte is not a slash. */ + assert (all_slashes || !ISSLASH (*(p - 1))); + + return (char *) base; +} diff --git a/lib/dirname.c b/lib/dirname.c new file mode 100644 index 00000000..94f8c893 --- /dev/null +++ b/lib/dirname.c @@ -0,0 +1,189 @@ +/* dirname.c -- return all but the last element in a path + Copyright (C) 1990, 1998, 2000 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#if HAVE_CONFIG_H +# include +#endif + +#ifdef STDC_HEADERS +# include +#else +char *malloc (); +#endif +#if defined STDC_HEADERS || defined HAVE_STRING_H +# include +#else +# include +# ifndef strrchr +# define strrchr rindex +# endif +#endif +#include + +#ifndef HAVE_DECL_MEMRCHR +"this configure-time declaration test was not run" +#endif +#if !HAVE_DECL_MEMRCHR +void *memrchr (); +#endif + +#include "dirname.h" + +#ifndef FILESYSTEM_PREFIX_LEN +# define FILESYSTEM_PREFIX_LEN(Filename) 0 +#endif + +#ifndef ISSLASH +# define ISSLASH(C) ((C) == '/') +#endif + +#define BACKSLASH_IS_PATH_SEPARATOR ISSLASH ('\\') + +/* Return the length of `dirname (PATH)' and set *RESULT to point + to PATH or to `"."', as appropriate. Works properly even if + there are trailing slashes (by effectively ignoring them). + WARNING: This function doesn't work for cwd-relative names like + `a:foo' that are specified with a drive-letter prefix. That case + is handled in the caller. */ +static size_t +dir_name_r (char const *path, char const **result) +{ + char const *slash; + size_t length; /* Length of result, not including NUL. */ + + slash = strrchr (path, '/'); + if (BACKSLASH_IS_PATH_SEPARATOR) + { + char const *b = strrchr (path, '\\'); + if (b && slash < b) + slash = b; + } + + /* If the last byte of PATH is a slash, decrement SLASH until it's + pointing at the leftmost in a sequence of trailing slashes. */ + if (slash && slash[1] == 0) + { + while (path < slash && ISSLASH (slash[-1])) + { + --slash; + } + + if (path < slash) + { + size_t len = slash - path; + slash = memrchr (path, '/', len); + if (BACKSLASH_IS_PATH_SEPARATOR) + { + char const *b = memrchr (path, '\\', len); + if (b && slash < b) + slash = b; + } + } + } + + if (slash == 0) + { + /* File is in the current directory. */ + + length = FILESYSTEM_PREFIX_LEN (path); + + if (length == 0) + { + path = "."; + length = 1; + } + } + else + { + /* Remove any trailing slashes from the result. If we have a + canonicalized "d:/path", leave alone the root case "d:/". */ + char const *lim = path + FILESYSTEM_PREFIX_LEN (path); + + while (lim < slash && ISSLASH (*slash)) + --slash; + + length = slash - path + 1; + } + + *result = path; + return length; +} + +/* Return the leading directories part of PATH, + allocated with malloc. If out of memory, return 0. + Works properly even if there are trailing slashes + (by effectively ignoring them). */ + +char * +dir_name (char const *path) +{ + char const *result; + size_t length = dir_name_r (path, &result); + int append_dot = (length && length == FILESYSTEM_PREFIX_LEN (newpath)); + char *newpath = (char *) malloc (length + append_dot + 1); + if (newpath == 0) + return 0; + strncpy (newpath, result, length); + /* If PATH is "d:foo", return "d:.", the CWD on drive d: */ + if (append_dot) + newpath[length++] = '.'; + newpath[length] = 0; + return newpath; +} + +#ifdef TEST_DIRNAME +/* + +Run the test like this (expect no output): + gcc -DHAVE_CONFIG_H -DTEST_DIRNAME -I.. -O -Wall memrchr.c dirname.c + sed -n '/^BEGIN-DATA$/,/^END-DATA$/p' dirname.c|grep -v DATA|./a.out + +BEGIN-DATA +foo//// . +bar/foo//// bar +foo/ . +/ / +. . +a . +END-DATA + +*/ + +# define MAX_BUFF_LEN 1024 +# include +# include + +int +main () +{ + char buff[MAX_BUFF_LEN + 1]; + + buff[MAX_BUFF_LEN] = 0; + while (fgets (buff, MAX_BUFF_LEN, stdin) && buff[0]) + { + char path[MAX_BUFF_LEN]; + char expected_result[MAX_BUFF_LEN]; + char const *result; + sscanf (buff, "%s %s", path, expected_result); + result = dir_name (path); + if (strcmp (result, expected_result)) + printf ("%s: got %s, expected %s\n", path, result, expected_result); + } + exit (0); + +} +#endif diff --git a/lib/dirname.h b/lib/dirname.h new file mode 100644 index 00000000..fc466996 --- /dev/null +++ b/lib/dirname.h @@ -0,0 +1,31 @@ +/* Copyright (C) 1998 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef DIRNAME_H_ +# define DIRNAME_H_ 1 + +# ifndef PARAMS +# if defined PROTOTYPES || (defined __STDC__ && __STDC__) +# define PARAMS(Args) Args +# else +# define PARAMS(Args) () +# endif +# endif + +char * +dir_name PARAMS ((const char *path)); + +#endif /* not DIRNAME_H_ */ diff --git a/lib/memrchr.c b/lib/memrchr.c new file mode 100644 index 00000000..4a3141e2 --- /dev/null +++ b/lib/memrchr.c @@ -0,0 +1,209 @@ +/* memrchr -- find the last occurrence of a byte in a memory block + Copyright (C) 1991, 93, 96, 97, 99, 2000 Free Software Foundation, Inc. + Based on strlen implementation by Torbjorn Granlund (tege@sics.se), + with help from Dan Sahlin (dan@sics.se) and + commentary by Jim Blandy (jimb@ai.mit.edu); + adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu), + and implemented by Roland McGrath (roland@ai.mit.edu). + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#undef __ptr_t +#if defined (__cplusplus) || (defined (__STDC__) && __STDC__) +# define __ptr_t void * +#else /* Not C++ or ANSI C. */ +# define __ptr_t char * +#endif /* C++ or ANSI C. */ + +#if defined (_LIBC) +# include +# include +#else +# define reg_char char +#endif + +#if defined (HAVE_LIMITS_H) || defined (_LIBC) +# include +#endif + +#define LONG_MAX_32_BITS 2147483647 + +#ifndef LONG_MAX +# define LONG_MAX LONG_MAX_32_BITS +#endif + +#include + +#undef __memrchr +#undef memrchr + +#ifndef weak_alias +# define __memrchr memrchr +#endif + +/* Search no more than N bytes of S for C. */ +__ptr_t +__memrchr (s, c_in, n) + const __ptr_t s; + int c_in; + size_t n; +{ + const unsigned char *char_ptr; + const unsigned long int *longword_ptr; + unsigned long int longword, magic_bits, charmask; + unsigned reg_char c; + + c = (unsigned char) c_in; + + /* Handle the last few characters by reading one character at a time. + Do this until CHAR_PTR is aligned on a longword boundary. */ + for (char_ptr = (const unsigned char *) s + n; + n > 0 && ((unsigned long int) char_ptr + & (sizeof (longword) - 1)) != 0; + --n) + if (*--char_ptr == c) + return (__ptr_t) char_ptr; + + /* All these elucidatory comments refer to 4-byte longwords, + but the theory applies equally well to 8-byte longwords. */ + + longword_ptr = (unsigned long int *) char_ptr; + + /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits + the "holes." Note that there is a hole just to the left of + each byte, with an extra at the end: + + bits: 01111110 11111110 11111110 11111111 + bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD + + The 1-bits make sure that carries propagate to the next 0-bit. + The 0-bits provide holes for carries to fall into. */ + + if (sizeof (longword) != 4 && sizeof (longword) != 8) + abort (); + +#if LONG_MAX <= LONG_MAX_32_BITS + magic_bits = 0x7efefeff; +#else + magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff; +#endif + + /* Set up a longword, each of whose bytes is C. */ + charmask = c | (c << 8); + charmask |= charmask << 16; +#if LONG_MAX > LONG_MAX_32_BITS + charmask |= charmask << 32; +#endif + + /* Instead of the traditional loop which tests each character, + we will test a longword at a time. The tricky part is testing + if *any of the four* bytes in the longword in question are zero. */ + while (n >= sizeof (longword)) + { + /* We tentatively exit the loop if adding MAGIC_BITS to + LONGWORD fails to change any of the hole bits of LONGWORD. + + 1) Is this safe? Will it catch all the zero bytes? + Suppose there is a byte with all zeros. Any carry bits + propagating from its left will fall into the hole at its + least significant bit and stop. Since there will be no + carry from its most significant bit, the LSB of the + byte to the left will be unchanged, and the zero will be + detected. + + 2) Is this worthwhile? Will it ignore everything except + zero bytes? Suppose every byte of LONGWORD has a bit set + somewhere. There will be a carry into bit 8. If bit 8 + is set, this will carry into bit 16. If bit 8 is clear, + one of bits 9-15 must be set, so there will be a carry + into bit 16. Similarly, there will be a carry into bit + 24. If one of bits 24-30 is set, there will be a carry + into bit 31, so all of the hole bits will be changed. + + The one misfire occurs when bits 24-30 are clear and bit + 31 is set; in this case, the hole at bit 31 is not + changed. If we had access to the processor carry flag, + we could close this loophole by putting the fourth hole + at bit 32! + + So it ignores everything except 128's, when they're aligned + properly. + + 3) But wait! Aren't we looking for C, not zero? + Good point. So what we do is XOR LONGWORD with a longword, + each of whose bytes is C. This turns each byte that is C + into a zero. */ + + longword = *--longword_ptr ^ charmask; + + /* Add MAGIC_BITS to LONGWORD. */ + if ((((longword + magic_bits) + + /* Set those bits that were unchanged by the addition. */ + ^ ~longword) + + /* Look at only the hole bits. If any of the hole bits + are unchanged, most likely one of the bytes was a + zero. */ + & ~magic_bits) != 0) + { + /* Which of the bytes was C? If none of them were, it was + a misfire; continue the search. */ + + const unsigned char *cp = (const unsigned char *) longword_ptr; + +#if LONG_MAX > 2147483647 + if (cp[7] == c) + return (__ptr_t) &cp[7]; + if (cp[6] == c) + return (__ptr_t) &cp[6]; + if (cp[5] == c) + return (__ptr_t) &cp[5]; + if (cp[4] == c) + return (__ptr_t) &cp[4]; +#endif + if (cp[3] == c) + return (__ptr_t) &cp[3]; + if (cp[2] == c) + return (__ptr_t) &cp[2]; + if (cp[1] == c) + return (__ptr_t) &cp[1]; + if (cp[0] == c) + return (__ptr_t) cp; + } + + n -= sizeof (longword); + } + + char_ptr = (const unsigned char *) longword_ptr; + + while (n-- > 0) + { + if (*--char_ptr == c) + return (__ptr_t) char_ptr; + } + + return 0; +} +#ifdef weak_alias +weak_alias (__memrchr, memrchr) +#endif diff --git a/lib/strchr.c b/lib/strchr.c new file mode 100644 index 00000000..2e897103 --- /dev/null +++ b/lib/strchr.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either version 2 of + the License, 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - + Suite 330, Boston, MA 02111-1307, USA. */ + +#if HAVE_CONFIG_H +# include +#endif + +#if HAVE_STRING_H +# include +#else +# include +#endif + +char * +strchr (const char *s, int c) +{ + return index (s, c); +} diff --git a/lib/strndup.c b/lib/strndup.c deleted file mode 100644 index 136e51c7..00000000 --- a/lib/strndup.c +++ /dev/null @@ -1,62 +0,0 @@ -/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc. - - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@prep.ai.mit.edu. - - 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#if defined _LIBC || defined STDC_HEADERS -# include -# include -#else -char *malloc (); -#endif - -#ifndef HAVE_DECL_STRNLEN -"this configure-time declaration test was not run" -#endif -#if !HAVE_DECL_STRNLEN -size_t strnlen (); -#endif - -#undef __strndup -#undef strndup - -#ifndef weak_alias -# define __strndup strndup -#endif - -char * -__strndup (const char *s, size_t n) -{ - size_t len = strnlen (s, n); - char *new = malloc (len + 1); - - if (new == NULL) - return NULL; - - new[len] = '\0'; - return (char *) memcpy (new, s, len); -} -#ifdef weak_alias -weak_alias (__strndup, strndup) -#endif diff --git a/lib/xstrndup.c b/lib/xstrndup.c new file mode 100644 index 00000000..594a6c9f --- /dev/null +++ b/lib/xstrndup.c @@ -0,0 +1,51 @@ +/* Copyright (C) 2001 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#if HAVE_CONFIG_H +# include +#endif + +#if STDC_HEADERS || HAVE_STRING_H +# include +#else +# include +#endif + +#include + +#include "xalloc.h" + +#ifndef HAVE_DECL_STRNLEN +"this configure-time declaration test was not run" +#endif +#if !HAVE_DECL_STRNLEN +size_t strnlen (); +#endif + +char *xstrndup (const char *s, size_t n); + +char * +xstrndup (const char *s, size_t n) +{ + size_t len = strnlen (s, n); + char *new = xmalloc (len + 1); + + if (new == NULL) + return NULL; + + new[len] = '\0'; + return (char *) memcpy (new, s, len); +} diff --git a/src/files.c b/src/files.c index 8dcf357f..2354acbe 100644 --- a/src/files.c +++ b/src/files.c @@ -384,7 +384,7 @@ compute_base_names (void) /* If the initial segment of extension contains a 'y' or a 'Y', I assume that it is a yacc or bison grammar file. */ if (ext_index) - ext_index = (strspn (infile + ext_index + 1, "yY")) ? ext_index : 0; + ext_index = strspn (infile + ext_index + 1, "yY") ? ext_index : 0; if (ext_index) compute_exts_from_gf (infile + ext_index); @@ -407,7 +407,7 @@ compute_base_names (void) /* If the initial segment of extension contains a 'y' or a 'Y', I assume that it is a yacc or bison grammar file. */ if (ext_index) - ext_index = (strspn (name_base + ext_index + 1, "yY")) ? ext_index : 0; + ext_index = strspn (name_base + ext_index + 1, "yY") ? ext_index : 0; if (ext_index) { base_length -= strlen (name_base + ext_index); diff --git a/src/system.h b/src/system.h index 04412d56..feffaee5 100644 --- a/src/system.h +++ b/src/system.h @@ -110,14 +110,26 @@ char *alloca (); char *stpcpy PARAMS ((char *dest, const char *src)); #endif -#if !HAVE_DECL_STRNDUP -char *strndup PARAMS ((const char *s, size_t size)); +#if !HAVE_DECL_STRCHR +char *strchr(const char *s, int c); +#endif + +#if !HAVE_DECL_STRSPN +size_t strspn(const char *s, const char *accept); #endif #if !HAVE_DECL_STRNLEN size_t strnlen PARAMS ((const char *s, size_t maxlen)); #endif +#if !HAVE_DECL_MEMCHR +void *memchr PARAMS ((const void *s, int c, size_t n)); +#endif + +#if !HAVE_DECL_MEMRCHR +void *memrchr PARAMS ((const void *s, int c, size_t n)); +#endif + /*-----------------.