mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 04:43:03 +00:00
* 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.
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
||||
2002-01-08 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* 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 <akim@epita.fr>
|
||||
|
||||
* src/conflicts.c (count_rr_conflicts): The previous RR conflicts
|
||||
|
||||
37
config.hin
37
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 <string.h> 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
|
||||
|
||||
|
||||
221
configure
vendored
221
configure
vendored
@@ -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 <stdio.h>
|
||||
@@ -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,6 +5403,68 @@ _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
|
||||
|
||||
|
||||
|
||||
@@ -5324,7 +5472,8 @@ 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 <<ATEOF
|
||||
# Signature of the current package.
|
||||
m4_define([PACKAGE_NAME], [$PACKAGE_NAME])
|
||||
m4_define([PACKAGE_TARNAME], [$PACKAGE_TARNAME])
|
||||
m4_define([PACKAGE_VERSION], [$PACKAGE_VERSION])
|
||||
m4_define([PACKAGE_STRING], [$PACKAGE_STRING])
|
||||
m4_define([PACKAGE_BUGREPORT], [$PACKAGE_BUGREPORT])
|
||||
ATEOF
|
||||
;;
|
||||
tests/atconfig ) cat >tests/atconfig <<ATEOF
|
||||
# Configurable variable values for building test suites.
|
||||
# Generated by $0.
|
||||
|
||||
@@ -85,8 +85,8 @@ AC_FUNC_ALLOCA
|
||||
AC_FUNC_OBSTACK
|
||||
AC_FUNC_ERROR_AT_LINE
|
||||
AC_CHECK_FUNCS(mkstemp setlocale)
|
||||
AC_CHECK_DECLS([stpcpy, strndup, strnlen, memchr])
|
||||
AC_REPLACE_FUNCS(stpcpy strndup strnlen strspn memchr)
|
||||
AC_CHECK_DECLS([stpcpy, strchr, strspn, strnlen, memchr, memrchr])
|
||||
AC_REPLACE_FUNCS(stpcpy strchr strnlen strspn memchr memrchr)
|
||||
jm_FUNC_MALLOC
|
||||
jm_FUNC_REALLOC
|
||||
jm_PREREQ_QUOTEARG
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@set UPDATED 18 December 2001
|
||||
@set UPDATED-MONTH December 2001
|
||||
@set UPDATED 5 January 2002
|
||||
@set UPDATED-MONTH January 2002
|
||||
@set EDITION 1.30j
|
||||
@set VERSION 1.30j
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
## Copyright 2001 Free Software Foundation, Inc.
|
||||
## Copyright 2001, 2002 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
|
||||
@@ -29,6 +29,7 @@ INCLUDES = -I.. -I$(srcdir) -I../intl
|
||||
EXTRA_DIST = malloc.c realloc.c
|
||||
|
||||
libbison_a_SOURCES = \
|
||||
basename.c dirname.h dirname.c \
|
||||
getopt.h getopt.c getopt1.c \
|
||||
quote.h quote.c quotearg.h quotearg.c \
|
||||
xalloc.h xmalloc.c xstrdup.c
|
||||
|
||||
@@ -115,6 +115,7 @@ INCLUDES = -I.. -I$(srcdir) -I../intl
|
||||
EXTRA_DIST = malloc.c realloc.c
|
||||
|
||||
libbison_a_SOURCES = \
|
||||
basename.c dirname.h dirname.c \
|
||||
getopt.h getopt.c getopt1.c \
|
||||
quote.h quote.c quotearg.h quotearg.c \
|
||||
xalloc.h xmalloc.c xstrdup.c
|
||||
@@ -129,9 +130,9 @@ CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
|
||||
libbison_a_AR = $(AR) cru
|
||||
am_libbison_a_OBJECTS = getopt$U.$(OBJEXT) getopt1$U.$(OBJEXT) \
|
||||
quote$U.$(OBJEXT) quotearg$U.$(OBJEXT) xmalloc$U.$(OBJEXT) \
|
||||
xstrdup$U.$(OBJEXT)
|
||||
am_libbison_a_OBJECTS = basename$U.$(OBJEXT) dirname$U.$(OBJEXT) \
|
||||
getopt$U.$(OBJEXT) getopt1$U.$(OBJEXT) quote$U.$(OBJEXT) \
|
||||
quotearg$U.$(OBJEXT) xmalloc$U.$(OBJEXT) xstrdup$U.$(OBJEXT)
|
||||
libbison_a_OBJECTS = $(am_libbison_a_OBJECTS)
|
||||
|
||||
DEFS = @DEFS@
|
||||
@@ -140,22 +141,24 @@ CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
|
||||
@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/alloca.Po $(DEPDIR)/error.Po \
|
||||
@AMDEP_TRUE@DEP_FILES = $(DEPDIR)/alloca.Po $(DEPDIR)/basename$U.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/dirname$U.Po $(DEPDIR)/error.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/getopt$U.Po $(DEPDIR)/getopt1$U.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/malloc.Po $(DEPDIR)/memchr.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/obstack.Po $(DEPDIR)/quote$U.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/quotearg$U.Po $(DEPDIR)/realloc.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/stpcpy.Po $(DEPDIR)/strndup.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/strnlen.Po $(DEPDIR)/strspn.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/xmalloc$U.Po $(DEPDIR)/xstrdup$U.Po
|
||||
@AMDEP_TRUE@ $(DEPDIR)/memrchr.Po $(DEPDIR)/obstack.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/quote$U.Po $(DEPDIR)/quotearg$U.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/realloc.Po $(DEPDIR)/stpcpy.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/strchr.Po $(DEPDIR)/strnlen.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/strspn.Po $(DEPDIR)/xmalloc$U.Po \
|
||||
@AMDEP_TRUE@ $(DEPDIR)/xstrdup$U.Po
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
DIST_SOURCES = $(libbison_a_SOURCES)
|
||||
DIST_COMMON = Makefile.am Makefile.in alloca.c ansi2knr.1 ansi2knr.c \
|
||||
error.c error.h malloc.c memchr.c obstack.c obstack.h realloc.c \
|
||||
stpcpy.c strndup.c strnlen.c strspn.c
|
||||
error.c error.h malloc.c memchr.c memrchr.c obstack.c obstack.h \
|
||||
realloc.c stpcpy.c strchr.c strnlen.c strspn.c
|
||||
SOURCES = $(libbison_a_SOURCES)
|
||||
|
||||
all: all-am
|
||||
@@ -195,17 +198,20 @@ mostlyclean-kr:
|
||||
-test "$U" = "" || rm -f *_.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/alloca.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/basename$U.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/dirname$U.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/error.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt$U.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/getopt1$U.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/malloc.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/memchr.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/memrchr.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/obstack.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/quote$U.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/quotearg$U.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/realloc.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/stpcpy.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strndup.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strchr.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strnlen.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strspn.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/xmalloc$U.Po@am__quote@
|
||||
@@ -228,6 +234,10 @@ distclean-depend:
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
alloca_.c: alloca.c $(ANSI2KNR)
|
||||
$(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/alloca.c; then echo $(srcdir)/alloca.c; else echo alloca.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > 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
|
||||
|
||||
71
lib/basename.c
Normal file
71
lib/basename.c
Normal file
@@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
189
lib/dirname.c
Normal file
189
lib/dirname.c
Normal file
@@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#else
|
||||
char *malloc ();
|
||||
#endif
|
||||
#if defined STDC_HEADERS || defined HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
# ifndef strrchr
|
||||
# define strrchr rindex
|
||||
# endif
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
#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 <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
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
|
||||
31
lib/dirname.h
Normal file
31
lib/dirname.h
Normal file
@@ -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_ */
|
||||
209
lib/memrchr.c
Normal file
209
lib/memrchr.c
Normal file
@@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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 <string.h>
|
||||
# include <memcopy.h>
|
||||
#else
|
||||
# define reg_char char
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_LIMITS_H) || defined (_LIBC)
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#define LONG_MAX_32_BITS 2147483647
|
||||
|
||||
#ifndef LONG_MAX
|
||||
# define LONG_MAX LONG_MAX_32_BITS
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#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
|
||||
32
lib/strchr.c
Normal file
32
lib/strchr.c
Normal file
@@ -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 <config.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
char *
|
||||
strchr (const char *s, int c)
|
||||
{
|
||||
return index (s, c);
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
/* 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.
|
||||
/* 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
|
||||
@@ -17,20 +14,20 @@
|
||||
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"
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined _LIBC || defined STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
#if STDC_HEADERS || HAVE_STRING_H
|
||||
# include <string.h>
|
||||
#else
|
||||
char *malloc ();
|
||||
# include <strings.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "xalloc.h"
|
||||
|
||||
#ifndef HAVE_DECL_STRNLEN
|
||||
"this configure-time declaration test was not run"
|
||||
#endif
|
||||
@@ -38,18 +35,13 @@ char *malloc ();
|
||||
size_t strnlen ();
|
||||
#endif
|
||||
|
||||
#undef __strndup
|
||||
#undef strndup
|
||||
|
||||
#ifndef weak_alias
|
||||
# define __strndup strndup
|
||||
#endif
|
||||
char *xstrndup (const char *s, size_t n);
|
||||
|
||||
char *
|
||||
__strndup (const char *s, size_t n)
|
||||
xstrndup (const char *s, size_t n)
|
||||
{
|
||||
size_t len = strnlen (s, n);
|
||||
char *new = malloc (len + 1);
|
||||
char *new = xmalloc (len + 1);
|
||||
|
||||
if (new == NULL)
|
||||
return NULL;
|
||||
@@ -57,6 +49,3 @@ __strndup (const char *s, size_t n)
|
||||
new[len] = '\0';
|
||||
return (char *) memcpy (new, s, len);
|
||||
}
|
||||
#ifdef weak_alias
|
||||
weak_alias (__strndup, strndup)
|
||||
#endif
|
||||
@@ -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);
|
||||
|
||||
16
src/system.h
16
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
|
||||
|
||||
|
||||
|
||||
/*-----------------.
|
||||
|
||||
Reference in New Issue
Block a user