* lib/strspn.c: New.

This commit is contained in:
Akim Demaille
2001-08-03 08:09:03 +00:00
parent d995fee754
commit 53b74c0c4c
8 changed files with 131 additions and 28 deletions

View File

@@ -129,7 +129,7 @@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CF
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
DIST_COMMON = Makefile.am Makefile.in alloca.c ansi2knr.1 ansi2knr.c \
memchr.c stpcpy.c strndup.c strnlen.c
memchr.c stpcpy.c strndup.c strnlen.c strspn.c
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
@@ -138,8 +138,8 @@ TAR = tar
GZIP_ENV = --best
DEP_FILES = .deps/alloca.P .deps/error.P .deps/getopt.P .deps/getopt1.P \
.deps/memchr.P .deps/obstack.P .deps/quote.P .deps/quotearg.P \
.deps/stpcpy.P .deps/strndup.P .deps/strnlen.P .deps/xmalloc.P \
.deps/xstrdup.P
.deps/stpcpy.P .deps/strndup.P .deps/strnlen.P .deps/strspn.P \
.deps/xmalloc.P .deps/xstrdup.P
SOURCES = $(libbison_a_SOURCES)
OBJECTS = $(libbison_a_OBJECTS)
@@ -227,13 +227,15 @@ strndup_.c: strndup.c $(ANSI2KNR)
$(CPP) $(DEFS) $(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
strnlen_.c: strnlen.c $(ANSI2KNR)
$(CPP) $(DEFS) $(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
strspn_.c: strspn.c $(ANSI2KNR)
$(CPP) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) `if test -f $(srcdir)/strspn.c; then echo $(srcdir)/strspn.c; else echo strspn.c; fi` | sed 's/^# \([0-9]\)/#line \1/' | $(ANSI2KNR) > strspn_.c
xmalloc_.c: xmalloc.c $(ANSI2KNR)
$(CPP) $(DEFS) $(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
xstrdup_.c: xstrdup.c $(ANSI2KNR)
$(CPP) $(DEFS) $(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
alloca_.o error_.o getopt_.o getopt1_.o memchr_.o obstack_.o quote_.o \
quotearg_.o stpcpy_.o strndup_.o strnlen_.o xmalloc_.o xstrdup_.o : \
$(ANSI2KNR)
quotearg_.o stpcpy_.o strndup_.o strnlen_.o strspn_.o xmalloc_.o \
xstrdup_.o : $(ANSI2KNR)
tags: TAGS

59
lib/strspn.c Normal file
View File

@@ -0,0 +1,59 @@
/* Copyright (C) 1991, 1997 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 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 defined _LIBC || HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
# ifndef strchr
# define strchr index
# endif
#endif
#undef strspn
/* Return the length of the maximum initial segment
of S which contains only characters in ACCEPT. */
size_t
strspn (s, accept)
const char *s;
const char *accept;
{
const char *p;
const char *a;
size_t count = 0;
for (p = s; *p != '\0'; ++p)
{
for (a = accept; *a != '\0'; ++a)
if (*p == *a)
break;
if (*a == '\0')
return count;
else
++count;
}
return count;
}