2008-10-31 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/limits.h: Add ARG_MAX, PATH_MAX, and _POSIX2_RE_DUP_MAX. * libc/include/envlock.h: New file. * libc/include/fnmatch.h: Ditto. * libc/include/glob.h: Ditto. * libc/include/regex.h: Ditto. * libc/include/wordexp.h: Ditto. * libc/posix/Makefile.am: Add new files moved from libc/sys/linux/stdlib. * libc/posix/Makefile.in: Regenerated. * libc/posix/COPYRIGHT: New file moved from libc/sys/linux/stdlib. * libc/posix/cclass.h: Ditto. * libc/posix/cname.h: Ditto. * libc/posix/collate.c: Ditto. * libc/posix/collate.h: Ditto. * libc/posix/collcmp.c: Ditto. * libc/posix/engine.c: Ditto. * libc/posix/fnmatch.3: Ditto. * libc/posix/glob.3: Ditto. * libc/posix/fnmatch.c: Ditto. * libc/posix/glob.c: Ditto. * libc/posix/namespace.h: Ditto. * libc/posix/reallocf.c: Ditto. * libc/posix/regcomp.c: Ditto. * libc/posix/regerror.c: Ditto. * libc/posix/regex.3: Ditto. * libc/posix/regex2.h: Ditto. * libc/posix/regexec.c: Ditto. * libc/posix/regfree.c: Ditto. * libc/posix/rune.h: Ditto. * libc/posix/runetype.h: Ditto. * libc/posix/scandir.c: Remove advertising clause which is not in effect. * libc/posix/sysexits.h: Ditto. * libc/posix/un-namespace.h: Ditto. * libc/posix/utils.h: Ditto. * libc/posix/wordexp.c: Ditto. * libc/posix/wordfree.c: Ditto. * libc/posix/execl.c: Add !_NO_EXECVE flag check. * libc/posix/execle.c: Ditto. * libc/posix/execlp.c: Ditto. * libc/posix/execv.c: Ditto. * libc/posix/execve.c: Ditto. * libc/posix/execvp.c: Ditto. * libc/posix/popen.c: Add !_NO_POPEN flag check. * libc/sys/linux/configure: Regenerated. * libc/sys/linux/configure.in: Remove stdlib. * libc/sys/linux/include/limits.h: Add include of linux/limits.h. * libc/sys/linux/stdlib/Makefile.am: Removed. * libc/sys/linux/stdlib/Makefile.in: Ditto. * libc/sys/linux/stdlib/COPYRIGHT: Moved to libc/posix. * libc/sys/linux/stdlib/cclass.h: Ditto. * libc/sys/linux/stdlib/cname.h: Ditto. * libc/sys/linux/stdlib/collate.c: Ditto. * libc/sys/linux/stdlib/collate.h: Ditto. * libc/sys/linux/stdlib/collcmp.c: Ditto. * libc/sys/linux/stdlib/engine.c: Ditto. * libc/sys/linux/stdlib/fnmatch.3: Ditto. * libc/sys/linux/stdlib/fnmatch.c: Ditto. * libc/sys/linux/stdlib/glob.3: Ditto. * libc/sys/linux/stdlib/glob.c: Ditto. * libc/sys/linux/stdlib/reallocf.c: Ditto. * libc/sys/linux/stdlib/regcomp.c: Ditto. * libc/sys/linux/stdlib/regerror.c: Ditto. * libc/sys/linux/stdlib/regex.3: Ditto. * libc/sys/linux/stdlib/regex2.h: Ditto. * libc/sys/linux/stdlib/regexec.c: Ditto. * libc/sys/linux/stdlib/regfree.c: Ditto. * libc/sys/linux/stdlib/utils.h: Ditto. * libc/sys/linux/stdlib/wordexp.c: Ditto. * libc/sys/linux/stdlib/wordfree.c: Ditto.
This commit is contained in:
34
newlib/libc/sys/linux/configure
vendored
34
newlib/libc/sys/linux/configure
vendored
@ -460,7 +460,7 @@ ac_includes_default="\
|
||||
|
||||
ac_subdirs_all="$ac_subdirs_all machine"
|
||||
ac_subdirs_all="$ac_subdirs_all linuxthreads"
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAY_SUPPLY_SYSCALLS_TRUE MAY_SUPPLY_SYSCALLS_FALSE newlib_basedir build build_cpu build_vendor build_os host host_cpu host_vendor host_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar CC DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE AS ac_ct_AS AR ac_ct_AR RANLIB ac_ct_RANLIB READELF ac_ct_READELF MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT CCAS CCASFLAGS NEWLIB_CFLAGS LDFLAGS ELIX_LEVEL_0_TRUE ELIX_LEVEL_0_FALSE ELIX_LEVEL_1_TRUE ELIX_LEVEL_1_FALSE ELIX_LEVEL_2_TRUE ELIX_LEVEL_2_FALSE ELIX_LEVEL_3_TRUE ELIX_LEVEL_3_FALSE ELIX_LEVEL_4_TRUE ELIX_LEVEL_4_FALSE USE_LIBTOOL_TRUE USE_LIBTOOL_FALSE OBJEXT oext aext lpfx libm_machine_dir machine_dir sys_dir SED DLLTOOL ac_ct_DLLTOOL OBJDUMP ac_ct_OBJDUMP LIBTOOL CFLAGS CPPFLAGS ac_ct_CC EXEEXT EGREP FGREP GREP LD DUMPBIN ac_ct_DUMPBIN NM LN_S lt_ECHO DSYMUTIL ac_ct_DSYMUTIL NMEDIT ac_ct_NMEDIT LIPO ac_ct_LIPO OTOOL ac_ct_OTOOL OTOOL64 ac_ct_OTOOL64 CPP LINUX_MACH_LIB subdirs EXTRA_SUBDIRS EXTRA_SUBLIBS LIBOBJS LTLIBOBJS'
|
||||
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS MAY_SUPPLY_SYSCALLS_TRUE MAY_SUPPLY_SYSCALLS_FALSE newlib_basedir build build_cpu build_vendor build_os host host_cpu host_vendor host_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar CC DEPDIR am__include am__quote AMDEP_TRUE AMDEP_FALSE AMDEPBACKSLASH CCDEPMODE am__fastdepCC_TRUE am__fastdepCC_FALSE AS ac_ct_AS AR ac_ct_AR RANLIB ac_ct_RANLIB READELF ac_ct_READELF MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT CCAS CCASFLAGS NEWLIB_CFLAGS LDFLAGS ELIX_LEVEL_0_TRUE ELIX_LEVEL_0_FALSE ELIX_LEVEL_1_TRUE ELIX_LEVEL_1_FALSE ELIX_LEVEL_2_TRUE ELIX_LEVEL_2_FALSE ELIX_LEVEL_3_TRUE ELIX_LEVEL_3_FALSE ELIX_LEVEL_4_TRUE ELIX_LEVEL_4_FALSE USE_LIBTOOL_TRUE USE_LIBTOOL_FALSE OBJEXT oext aext lpfx libm_machine_dir machine_dir sys_dir SED DLLTOOL ac_ct_DLLTOOL OBJDUMP ac_ct_OBJDUMP LIBTOOL CFLAGS CPPFLAGS ac_ct_CC EXEEXT EGREP FGREP GREP LD DUMPBIN ac_ct_DUMPBIN NM LN_S lt_ECHO DSYMUTIL ac_ct_DSYMUTIL NMEDIT ac_ct_NMEDIT LIPO ac_ct_LIPO OTOOL ac_ct_OTOOL OTOOL64 ac_ct_OTOOL64 CPP subdirs LINUX_MACH_LIB EXTRA_SUBDIRS EXTRA_SUBLIBS LIBOBJS LTLIBOBJS'
|
||||
ac_subst_files=''
|
||||
|
||||
# Initialize some variables set by options.
|
||||
@ -11371,6 +11371,18 @@ CC="$lt_save_CC"
|
||||
|
||||
fi
|
||||
|
||||
|
||||
|
||||
subdirs="$subdirs machine"
|
||||
|
||||
|
||||
if test "${newlib_multithread}" = "yes"; then
|
||||
|
||||
|
||||
subdirs="$subdirs linuxthreads"
|
||||
|
||||
fi
|
||||
|
||||
LINUX_MACH_LIB=
|
||||
if test -n "${machine_dir}"; then
|
||||
if test "${use_libtool}" = "yes"; then
|
||||
@ -11384,28 +11396,17 @@ fi
|
||||
EXTRA_SUBDIRS=
|
||||
EXTRA_SUBLIBS=
|
||||
|
||||
|
||||
|
||||
subdirs="$subdirs machine"
|
||||
|
||||
|
||||
if test "${newlib_multithread}" = "yes"; then
|
||||
|
||||
|
||||
subdirs="$subdirs linuxthreads"
|
||||
|
||||
fi
|
||||
if test "x${newlib_elix_level}" = "x1"; then
|
||||
EXTRA_SUBDIRS=linuxthreads net
|
||||
else
|
||||
EXTRA_SUBDIRS="linuxthreads net intl stdlib iconv dl"
|
||||
EXTRA_SUBLIBS="net/libnet.la intl/libintl.la stdlib/libstdlib.la iconv/libiconv.la dl/libdl.la"
|
||||
EXTRA_SUBDIRS="linuxthreads net intl iconv dl"
|
||||
EXTRA_SUBLIBS="net/libnet.la intl/libintl.la iconv/libiconv.la dl/libdl.la"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files Makefile intl/Makefile net/Makefile stdlib/Makefile iconv/Makefile dl/Makefile cmath/Makefile argp/Makefile"
|
||||
ac_config_files="$ac_config_files Makefile intl/Makefile net/Makefile iconv/Makefile dl/Makefile cmath/Makefile argp/Makefile"
|
||||
|
||||
cat >confcache <<\_ACEOF
|
||||
# This file is a shell script that caches the results of configure
|
||||
@ -12304,7 +12305,6 @@ do
|
||||
"Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||
"intl/Makefile" ) CONFIG_FILES="$CONFIG_FILES intl/Makefile" ;;
|
||||
"net/Makefile" ) CONFIG_FILES="$CONFIG_FILES net/Makefile" ;;
|
||||
"stdlib/Makefile" ) CONFIG_FILES="$CONFIG_FILES stdlib/Makefile" ;;
|
||||
"iconv/Makefile" ) CONFIG_FILES="$CONFIG_FILES iconv/Makefile" ;;
|
||||
"dl/Makefile" ) CONFIG_FILES="$CONFIG_FILES dl/Makefile" ;;
|
||||
"cmath/Makefile" ) CONFIG_FILES="$CONFIG_FILES cmath/Makefile" ;;
|
||||
@ -12502,8 +12502,8 @@ s,@ac_ct_OTOOL@,$ac_ct_OTOOL,;t t
|
||||
s,@OTOOL64@,$OTOOL64,;t t
|
||||
s,@ac_ct_OTOOL64@,$ac_ct_OTOOL64,;t t
|
||||
s,@CPP@,$CPP,;t t
|
||||
s,@LINUX_MACH_LIB@,$LINUX_MACH_LIB,;t t
|
||||
s,@subdirs@,$subdirs,;t t
|
||||
s,@LINUX_MACH_LIB@,$LINUX_MACH_LIB,;t t
|
||||
s,@EXTRA_SUBDIRS@,$EXTRA_SUBDIRS,;t t
|
||||
s,@EXTRA_SUBLIBS@,$EXTRA_SUBLIBS,;t t
|
||||
s,@LIBOBJS@,$LIBOBJS,;t t
|
||||
|
@ -20,6 +20,12 @@ AC_LIBTOOL_WIN32_DLL
|
||||
AM_PROG_LIBTOOL
|
||||
fi
|
||||
|
||||
AC_CONFIG_SUBDIRS(machine)
|
||||
|
||||
if test "${newlib_multithread}" = "yes"; then
|
||||
AC_CONFIG_SUBDIRS(linuxthreads)
|
||||
fi
|
||||
|
||||
LINUX_MACH_LIB=
|
||||
if test -n "${machine_dir}"; then
|
||||
if test "${use_libtool}" = "yes"; then
|
||||
@ -33,20 +39,15 @@ AC_SUBST(LINUX_MACH_LIB)
|
||||
EXTRA_SUBDIRS=
|
||||
EXTRA_SUBLIBS=
|
||||
|
||||
AC_CONFIG_SUBDIRS(machine)
|
||||
|
||||
if test "${newlib_multithread}" = "yes"; then
|
||||
AC_CONFIG_SUBDIRS(linuxthreads)
|
||||
fi
|
||||
if test "x${newlib_elix_level}" = "x1"; then
|
||||
EXTRA_SUBDIRS=linuxthreads net
|
||||
else
|
||||
EXTRA_SUBDIRS="linuxthreads net intl stdlib iconv dl"
|
||||
EXTRA_SUBLIBS="net/libnet.la intl/libintl.la stdlib/libstdlib.la iconv/libiconv.la dl/libdl.la"
|
||||
EXTRA_SUBDIRS="linuxthreads net intl iconv dl"
|
||||
EXTRA_SUBLIBS="net/libnet.la intl/libintl.la iconv/libiconv.la dl/libdl.la"
|
||||
fi
|
||||
|
||||
AC_SUBST(EXTRA_SUBDIRS)
|
||||
AC_SUBST(EXTRA_SUBLIBS)
|
||||
|
||||
AC_CONFIG_FILES([Makefile intl/Makefile net/Makefile stdlib/Makefile iconv/Makefile dl/Makefile cmath/Makefile argp/Makefile])
|
||||
AC_CONFIG_FILES([Makefile intl/Makefile net/Makefile iconv/Makefile dl/Makefile cmath/Makefile argp/Makefile])
|
||||
AC_OUTPUT
|
||||
|
@ -139,6 +139,8 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <linux/limits.h>
|
||||
|
||||
#ifdef __USE_POSIX
|
||||
/* POSIX adds things to <limits.h>. */
|
||||
# include <bits/posix1_lim.h>
|
||||
@ -151,3 +153,4 @@
|
||||
#ifdef __USE_XOPEN
|
||||
# include <bits/xopen_lim.h>
|
||||
#endif
|
||||
|
||||
|
@ -1,56 +0,0 @@
|
||||
Copyright 1992, 1993, 1994 Henry Spencer. All rights reserved.
|
||||
This software is not subject to any license of the American Telephone
|
||||
and Telegraph Company or of the Regents of the University of California.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose on
|
||||
any computer system, and to alter it and redistribute it, subject
|
||||
to the following restrictions:
|
||||
|
||||
1. The author is not responsible for the consequences of use of this
|
||||
software, no matter how awful, even if they arise from flaws in it.
|
||||
|
||||
2. The origin of this software must not be misrepresented, either by
|
||||
explicit claim or by omission. Since few users ever read sources,
|
||||
credits must appear in the documentation.
|
||||
|
||||
3. Altered versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software. Since few users
|
||||
ever read sources, credits must appear in the documentation.
|
||||
|
||||
4. This notice may not be removed or altered.
|
||||
|
||||
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
/*-
|
||||
* Copyright (c) 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)COPYRIGHT 8.1 (Berkeley) 3/16/94
|
||||
*/
|
@ -1,41 +0,0 @@
|
||||
## Process this file with automake to generate Makefile.in
|
||||
|
||||
AUTOMAKE_OPTIONS = cygnus
|
||||
|
||||
INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
|
||||
|
||||
GENERAL_SOURCES = \
|
||||
fnmatch.c glob.c regcomp.c regerror.c regex2.h \
|
||||
regexec.c regfree.c collate.h collate.c collcmp.c \
|
||||
reallocf.c
|
||||
|
||||
ELIX_3_SOURCES = \
|
||||
wordexp.c \
|
||||
wordfree.c
|
||||
|
||||
if ELIX_LEVEL_1
|
||||
ELIX_SOURCES =
|
||||
else
|
||||
if ELIX_LEVEL_2
|
||||
ELIX_SOURCES =
|
||||
else
|
||||
ELIX_SOURCES = $(ELIX_3_SOURCES)
|
||||
endif
|
||||
endif
|
||||
|
||||
libstdlib_la_LDFLAGS = -Xcompiler -nostdlib
|
||||
|
||||
if USE_LIBTOOL
|
||||
noinst_LTLIBRARIES = libstdlib.la
|
||||
libstdlib_la_SOURCES = $(GENERAL_SOURCES) $(ELIX_SOURCES)
|
||||
noinst_DATA = objectlist.awk.in
|
||||
else
|
||||
noinst_LIBRARIES = lib.a
|
||||
lib_a_SOURCES = $(GENERAL_SOURCES) $(ELIX_SOURCES)
|
||||
lib_a_CFLAGS = $(AM_CFLAGS)
|
||||
noinst_DATA =
|
||||
endif # USE_LIBTOOL
|
||||
|
||||
AM_CFLAGS = -D_GNU_SOURCE
|
||||
|
||||
include $(srcdir)/../../../../Makefile.shared
|
@ -1,550 +0,0 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
DIST_COMMON = $(srcdir)/../../../../Makefile.shared \
|
||||
$(srcdir)/Makefile.in $(srcdir)/Makefile.am
|
||||
subdir = stdlib
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/../../../../libtool.m4 \
|
||||
$(top_srcdir)/../../../../ltoptions.m4 \
|
||||
$(top_srcdir)/../../../../ltsugar.m4 \
|
||||
$(top_srcdir)/../../../../ltversion.m4 \
|
||||
$(top_srcdir)/../../../../lt~obsolete.m4 \
|
||||
$(top_srcdir)/../../../acinclude.m4 \
|
||||
$(top_srcdir)/../../../confsubdir.m4 \
|
||||
$(top_srcdir)/configure.in
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/../../../../mkinstalldirs
|
||||
CONFIG_CLEAN_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
ARFLAGS = cru
|
||||
lib_a_AR = $(AR) $(ARFLAGS)
|
||||
lib_a_LIBADD =
|
||||
am__objects_1 = lib_a-fnmatch.$(OBJEXT) lib_a-glob.$(OBJEXT) \
|
||||
lib_a-regcomp.$(OBJEXT) lib_a-regerror.$(OBJEXT) \
|
||||
lib_a-regexec.$(OBJEXT) lib_a-regfree.$(OBJEXT) \
|
||||
lib_a-collate.$(OBJEXT) lib_a-collcmp.$(OBJEXT) \
|
||||
lib_a-reallocf.$(OBJEXT)
|
||||
am__objects_2 = lib_a-wordexp.$(OBJEXT) lib_a-wordfree.$(OBJEXT)
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@am__objects_3 = \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@ $(am__objects_2)
|
||||
@USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
|
||||
@USE_LIBTOOL_FALSE@ $(am__objects_3)
|
||||
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
|
||||
LTLIBRARIES = $(noinst_LTLIBRARIES)
|
||||
libstdlib_la_LIBADD =
|
||||
am__objects_4 = fnmatch.lo glob.lo regcomp.lo regerror.lo regexec.lo \
|
||||
regfree.lo collate.lo collcmp.lo reallocf.lo
|
||||
am__objects_5 = wordexp.lo wordfree.lo
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@am__objects_6 = \
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@ $(am__objects_5)
|
||||
@USE_LIBTOOL_TRUE@am_libstdlib_la_OBJECTS = $(am__objects_4) \
|
||||
@USE_LIBTOOL_TRUE@ $(am__objects_6)
|
||||
libstdlib_la_OBJECTS = $(am_libstdlib_la_OBJECTS)
|
||||
@USE_LIBTOOL_TRUE@am_libstdlib_la_rpath =
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir)
|
||||
depcomp =
|
||||
am__depfiles_maybe =
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = $(lib_a_SOURCES) $(libstdlib_la_SOURCES)
|
||||
DATA = $(noinst_DATA)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AS = @AS@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCAS = @CCAS@
|
||||
CCASFLAGS = @CCASFLAGS@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
ELIX_LEVEL_0_FALSE = @ELIX_LEVEL_0_FALSE@
|
||||
ELIX_LEVEL_0_TRUE = @ELIX_LEVEL_0_TRUE@
|
||||
ELIX_LEVEL_1_FALSE = @ELIX_LEVEL_1_FALSE@
|
||||
ELIX_LEVEL_1_TRUE = @ELIX_LEVEL_1_TRUE@
|
||||
ELIX_LEVEL_2_FALSE = @ELIX_LEVEL_2_FALSE@
|
||||
ELIX_LEVEL_2_TRUE = @ELIX_LEVEL_2_TRUE@
|
||||
ELIX_LEVEL_3_FALSE = @ELIX_LEVEL_3_FALSE@
|
||||
ELIX_LEVEL_3_TRUE = @ELIX_LEVEL_3_TRUE@
|
||||
ELIX_LEVEL_4_FALSE = @ELIX_LEVEL_4_FALSE@
|
||||
ELIX_LEVEL_4_TRUE = @ELIX_LEVEL_4_TRUE@
|
||||
EXEEXT = @EXEEXT@
|
||||
EXTRA_SUBDIRS = @EXTRA_SUBDIRS@
|
||||
EXTRA_SUBLIBS = @EXTRA_SUBLIBS@
|
||||
FGREP = @FGREP@
|
||||
GREP = @GREP@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LD = @LD@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LINUX_MACH_LIB = @LINUX_MACH_LIB@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAINT = @MAINT@
|
||||
MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@
|
||||
MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MAY_SUPPLY_SYSCALLS_FALSE = @MAY_SUPPLY_SYSCALLS_FALSE@
|
||||
MAY_SUPPLY_SYSCALLS_TRUE = @MAY_SUPPLY_SYSCALLS_TRUE@
|
||||
NEWLIB_CFLAGS = @NEWLIB_CFLAGS@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OTOOL = @OTOOL@
|
||||
OTOOL64 = @OTOOL64@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
RANLIB = @RANLIB@
|
||||
READELF = @READELF@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
USE_LIBTOOL_FALSE = @USE_LIBTOOL_FALSE@
|
||||
USE_LIBTOOL_TRUE = @USE_LIBTOOL_TRUE@
|
||||
VERSION = @VERSION@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
ac_ct_AS = @ac_ct_AS@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_DLLTOOL = @ac_ct_DLLTOOL@
|
||||
ac_ct_DSYMUTIL = @ac_ct_DSYMUTIL@
|
||||
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
|
||||
ac_ct_LIPO = @ac_ct_LIPO@
|
||||
ac_ct_NMEDIT = @ac_ct_NMEDIT@
|
||||
ac_ct_OBJDUMP = @ac_ct_OBJDUMP@
|
||||
ac_ct_OTOOL = @ac_ct_OTOOL@
|
||||
ac_ct_OTOOL64 = @ac_ct_OTOOL64@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_READELF = @ac_ct_READELF@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
aext = @aext@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
datadir = @datadir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
libm_machine_dir = @libm_machine_dir@
|
||||
localstatedir = @localstatedir@
|
||||
lpfx = @lpfx@
|
||||
lt_ECHO = @lt_ECHO@
|
||||
machine_dir = @machine_dir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
newlib_basedir = @newlib_basedir@
|
||||
oext = @oext@
|
||||
oldincludedir = @oldincludedir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
subdirs = @subdirs@
|
||||
sys_dir = @sys_dir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
AUTOMAKE_OPTIONS = cygnus
|
||||
INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
|
||||
GENERAL_SOURCES = \
|
||||
fnmatch.c glob.c regcomp.c regerror.c regex2.h \
|
||||
regexec.c regfree.c collate.h collate.c collcmp.c \
|
||||
reallocf.c
|
||||
|
||||
ELIX_3_SOURCES = \
|
||||
wordexp.c \
|
||||
wordfree.c
|
||||
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@ELIX_SOURCES = $(ELIX_3_SOURCES)
|
||||
@ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_TRUE@ELIX_SOURCES =
|
||||
@ELIX_LEVEL_1_TRUE@ELIX_SOURCES =
|
||||
libstdlib_la_LDFLAGS = -Xcompiler -nostdlib
|
||||
@USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = libstdlib.la
|
||||
@USE_LIBTOOL_TRUE@libstdlib_la_SOURCES = $(GENERAL_SOURCES) $(ELIX_SOURCES)
|
||||
@USE_LIBTOOL_FALSE@noinst_DATA =
|
||||
@USE_LIBTOOL_TRUE@noinst_DATA = objectlist.awk.in
|
||||
@USE_LIBTOOL_FALSE@noinst_LIBRARIES = lib.a
|
||||
@USE_LIBTOOL_FALSE@lib_a_SOURCES = $(GENERAL_SOURCES) $(ELIX_SOURCES)
|
||||
@USE_LIBTOOL_FALSE@lib_a_CFLAGS = $(AM_CFLAGS)
|
||||
AM_CFLAGS = -D_GNU_SOURCE
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(srcdir)/../../../../Makefile.shared $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --cygnus stdlib/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --cygnus stdlib/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
clean-noinstLIBRARIES:
|
||||
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
|
||||
lib.a: $(lib_a_OBJECTS) $(lib_a_DEPENDENCIES)
|
||||
-rm -f lib.a
|
||||
$(lib_a_AR) lib.a $(lib_a_OBJECTS) $(lib_a_LIBADD)
|
||||
$(RANLIB) lib.a
|
||||
|
||||
clean-noinstLTLIBRARIES:
|
||||
-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
|
||||
@list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
|
||||
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
|
||||
test "$$dir" != "$$p" || dir=.; \
|
||||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
libstdlib.la: $(libstdlib_la_OBJECTS) $(libstdlib_la_DEPENDENCIES)
|
||||
$(LINK) $(am_libstdlib_la_rpath) $(libstdlib_la_LDFLAGS) $(libstdlib_la_OBJECTS) $(libstdlib_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.c.obj:
|
||||
$(COMPILE) -c `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
$(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
lib_a-fnmatch.o: fnmatch.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fnmatch.o `test -f 'fnmatch.c' || echo '$(srcdir)/'`fnmatch.c
|
||||
|
||||
lib_a-fnmatch.obj: fnmatch.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fnmatch.obj `if test -f 'fnmatch.c'; then $(CYGPATH_W) 'fnmatch.c'; else $(CYGPATH_W) '$(srcdir)/fnmatch.c'; fi`
|
||||
|
||||
lib_a-glob.o: glob.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-glob.o `test -f 'glob.c' || echo '$(srcdir)/'`glob.c
|
||||
|
||||
lib_a-glob.obj: glob.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-glob.obj `if test -f 'glob.c'; then $(CYGPATH_W) 'glob.c'; else $(CYGPATH_W) '$(srcdir)/glob.c'; fi`
|
||||
|
||||
lib_a-regcomp.o: regcomp.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regcomp.o `test -f 'regcomp.c' || echo '$(srcdir)/'`regcomp.c
|
||||
|
||||
lib_a-regcomp.obj: regcomp.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regcomp.obj `if test -f 'regcomp.c'; then $(CYGPATH_W) 'regcomp.c'; else $(CYGPATH_W) '$(srcdir)/regcomp.c'; fi`
|
||||
|
||||
lib_a-regerror.o: regerror.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regerror.o `test -f 'regerror.c' || echo '$(srcdir)/'`regerror.c
|
||||
|
||||
lib_a-regerror.obj: regerror.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regerror.obj `if test -f 'regerror.c'; then $(CYGPATH_W) 'regerror.c'; else $(CYGPATH_W) '$(srcdir)/regerror.c'; fi`
|
||||
|
||||
lib_a-regexec.o: regexec.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regexec.o `test -f 'regexec.c' || echo '$(srcdir)/'`regexec.c
|
||||
|
||||
lib_a-regexec.obj: regexec.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regexec.obj `if test -f 'regexec.c'; then $(CYGPATH_W) 'regexec.c'; else $(CYGPATH_W) '$(srcdir)/regexec.c'; fi`
|
||||
|
||||
lib_a-regfree.o: regfree.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regfree.o `test -f 'regfree.c' || echo '$(srcdir)/'`regfree.c
|
||||
|
||||
lib_a-regfree.obj: regfree.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-regfree.obj `if test -f 'regfree.c'; then $(CYGPATH_W) 'regfree.c'; else $(CYGPATH_W) '$(srcdir)/regfree.c'; fi`
|
||||
|
||||
lib_a-collate.o: collate.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-collate.o `test -f 'collate.c' || echo '$(srcdir)/'`collate.c
|
||||
|
||||
lib_a-collate.obj: collate.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-collate.obj `if test -f 'collate.c'; then $(CYGPATH_W) 'collate.c'; else $(CYGPATH_W) '$(srcdir)/collate.c'; fi`
|
||||
|
||||
lib_a-collcmp.o: collcmp.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-collcmp.o `test -f 'collcmp.c' || echo '$(srcdir)/'`collcmp.c
|
||||
|
||||
lib_a-collcmp.obj: collcmp.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-collcmp.obj `if test -f 'collcmp.c'; then $(CYGPATH_W) 'collcmp.c'; else $(CYGPATH_W) '$(srcdir)/collcmp.c'; fi`
|
||||
|
||||
lib_a-reallocf.o: reallocf.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-reallocf.o `test -f 'reallocf.c' || echo '$(srcdir)/'`reallocf.c
|
||||
|
||||
lib_a-reallocf.obj: reallocf.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-reallocf.obj `if test -f 'reallocf.c'; then $(CYGPATH_W) 'reallocf.c'; else $(CYGPATH_W) '$(srcdir)/reallocf.c'; fi`
|
||||
|
||||
lib_a-wordexp.o: wordexp.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wordexp.o `test -f 'wordexp.c' || echo '$(srcdir)/'`wordexp.c
|
||||
|
||||
lib_a-wordexp.obj: wordexp.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wordexp.obj `if test -f 'wordexp.c'; then $(CYGPATH_W) 'wordexp.c'; else $(CYGPATH_W) '$(srcdir)/wordexp.c'; fi`
|
||||
|
||||
lib_a-wordfree.o: wordfree.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wordfree.o `test -f 'wordfree.c' || echo '$(srcdir)/'`wordfree.c
|
||||
|
||||
lib_a-wordfree.obj: wordfree.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wordfree.obj `if test -f 'wordfree.c'; then $(CYGPATH_W) 'wordfree.c'; else $(CYGPATH_W) '$(srcdir)/wordfree.c'; fi`
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
distclean-libtool:
|
||||
-rm -f libtool
|
||||
uninstall-info-am:
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | \
|
||||
$(AWK) ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& cd $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) $$here
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
check-am:
|
||||
check: check-am
|
||||
all-am: Makefile $(LIBRARIES) $(LTLIBRARIES) $(DATA)
|
||||
installdirs:
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \
|
||||
clean-noinstLTLIBRARIES mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am:
|
||||
|
||||
install-exec-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am:
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libtool clean-noinstLIBRARIES clean-noinstLTLIBRARIES \
|
||||
ctags distclean distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags dvi dvi-am html html-am info \
|
||||
info-am install install-am install-data install-data-am \
|
||||
install-exec install-exec-am install-info install-info-am \
|
||||
install-man install-strip installcheck installcheck-am \
|
||||
installdirs maintainer-clean maintainer-clean-generic \
|
||||
mostlyclean mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
|
||||
uninstall-am uninstall-info-am
|
||||
|
||||
objectlist.awk.in: $(noinst_LTLIBRARIES)
|
||||
-rm -f objectlist.awk.in
|
||||
for i in `ls *.lo` ; \
|
||||
do \
|
||||
echo $$i `pwd`/$$i >> objectlist.awk.in ; \
|
||||
done
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
@ -1,63 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)cclass.h 8.3 (Berkeley) 3/20/94
|
||||
* $FreeBSD: src/lib/libc/regex/cclass.h,v 1.4 2002/03/22 23:41:56 obrien Exp $
|
||||
*/
|
||||
|
||||
|
||||
typedef enum {CALNUM, CALPHA, CBLANK, CCNTRL, CDIGIT, CGRAPH,
|
||||
CLOWER, CPRINT, CPUNCT, CSPACE, CUPPER, CXDIGIT} citype;
|
||||
|
||||
/* character-class table */
|
||||
static struct cclass {
|
||||
char *name;
|
||||
citype fidx;
|
||||
} cclasses[] = {
|
||||
{"alnum", CALNUM},
|
||||
{"alpha", CALPHA},
|
||||
{"blank", CBLANK},
|
||||
{"cntrl", CCNTRL},
|
||||
{"digit", CDIGIT},
|
||||
{"graph", CGRAPH},
|
||||
{"lower", CLOWER},
|
||||
{"print", CPRINT},
|
||||
{"punct", CPUNCT},
|
||||
{"space", CSPACE},
|
||||
{"upper", CUPPER},
|
||||
{"xdigit", CXDIGIT},
|
||||
{NULL, }
|
||||
};
|
@ -1,142 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)cname.h 8.3 (Berkeley) 3/20/94
|
||||
* $FreeBSD: src/lib/libc/regex/cname.h,v 1.3 2002/03/22 23:41:56 obrien Exp $
|
||||
*/
|
||||
|
||||
/* character-name table */
|
||||
static struct cname {
|
||||
char *name;
|
||||
char code;
|
||||
} cnames[] = {
|
||||
{"NUL", '\0'},
|
||||
{"SOH", '\001'},
|
||||
{"STX", '\002'},
|
||||
{"ETX", '\003'},
|
||||
{"EOT", '\004'},
|
||||
{"ENQ", '\005'},
|
||||
{"ACK", '\006'},
|
||||
{"BEL", '\007'},
|
||||
{"alert", '\007'},
|
||||
{"BS", '\010'},
|
||||
{"backspace", '\b'},
|
||||
{"HT", '\011'},
|
||||
{"tab", '\t'},
|
||||
{"LF", '\012'},
|
||||
{"newline", '\n'},
|
||||
{"VT", '\013'},
|
||||
{"vertical-tab", '\v'},
|
||||
{"FF", '\014'},
|
||||
{"form-feed", '\f'},
|
||||
{"CR", '\015'},
|
||||
{"carriage-return", '\r'},
|
||||
{"SO", '\016'},
|
||||
{"SI", '\017'},
|
||||
{"DLE", '\020'},
|
||||
{"DC1", '\021'},
|
||||
{"DC2", '\022'},
|
||||
{"DC3", '\023'},
|
||||
{"DC4", '\024'},
|
||||
{"NAK", '\025'},
|
||||
{"SYN", '\026'},
|
||||
{"ETB", '\027'},
|
||||
{"CAN", '\030'},
|
||||
{"EM", '\031'},
|
||||
{"SUB", '\032'},
|
||||
{"ESC", '\033'},
|
||||
{"IS4", '\034'},
|
||||
{"FS", '\034'},
|
||||
{"IS3", '\035'},
|
||||
{"GS", '\035'},
|
||||
{"IS2", '\036'},
|
||||
{"RS", '\036'},
|
||||
{"IS1", '\037'},
|
||||
{"US", '\037'},
|
||||
{"space", ' '},
|
||||
{"exclamation-mark", '!'},
|
||||
{"quotation-mark", '"'},
|
||||
{"number-sign", '#'},
|
||||
{"dollar-sign", '$'},
|
||||
{"percent-sign", '%'},
|
||||
{"ampersand", '&'},
|
||||
{"apostrophe", '\''},
|
||||
{"left-parenthesis", '('},
|
||||
{"right-parenthesis", ')'},
|
||||
{"asterisk", '*'},
|
||||
{"plus-sign", '+'},
|
||||
{"comma", ','},
|
||||
{"hyphen", '-'},
|
||||
{"hyphen-minus", '-'},
|
||||
{"period", '.'},
|
||||
{"full-stop", '.'},
|
||||
{"slash", '/'},
|
||||
{"solidus", '/'},
|
||||
{"zero", '0'},
|
||||
{"one", '1'},
|
||||
{"two", '2'},
|
||||
{"three", '3'},
|
||||
{"four", '4'},
|
||||
{"five", '5'},
|
||||
{"six", '6'},
|
||||
{"seven", '7'},
|
||||
{"eight", '8'},
|
||||
{"nine", '9'},
|
||||
{"colon", ':'},
|
||||
{"semicolon", ';'},
|
||||
{"less-than-sign", '<'},
|
||||
{"equals-sign", '='},
|
||||
{"greater-than-sign", '>'},
|
||||
{"question-mark", '?'},
|
||||
{"commercial-at", '@'},
|
||||
{"left-square-bracket", '['},
|
||||
{"backslash", '\\'},
|
||||
{"reverse-solidus", '\\'},
|
||||
{"right-square-bracket",']'},
|
||||
{"circumflex", '^'},
|
||||
{"circumflex-accent", '^'},
|
||||
{"underscore", '_'},
|
||||
{"low-line", '_'},
|
||||
{"grave-accent", '`'},
|
||||
{"left-brace", '{'},
|
||||
{"left-curly-bracket", '{'},
|
||||
{"vertical-line", '|'},
|
||||
{"right-brace", '}'},
|
||||
{"right-curly-bracket", '}'},
|
||||
{"tilde", '~'},
|
||||
{"DEL", '\177'},
|
||||
{NULL, 0}
|
||||
};
|
@ -1,214 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
|
||||
* at Electronni Visti IA, Kiev, Ukraine.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include "namespace.h"
|
||||
#include <rune.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sysexits.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "collate.h"
|
||||
#include "setlocale.h"
|
||||
|
||||
extern char *_PathLocale;
|
||||
int __collate_load_error = 1;
|
||||
int __collate_substitute_nontrivial;
|
||||
char __collate_version[STR_LEN];
|
||||
u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
|
||||
struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
|
||||
struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE];
|
||||
|
||||
#define FREAD(a, b, c, d) \
|
||||
do { \
|
||||
if (fread(a, b, c, d) != c) { \
|
||||
fclose(d); \
|
||||
return -1; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
void __collate_err(int ex, const char *f);
|
||||
|
||||
int
|
||||
__collate_load_tables(encoding)
|
||||
char *encoding;
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
FILE *fp;
|
||||
int i, save_load_error;
|
||||
|
||||
save_load_error = __collate_load_error;
|
||||
__collate_load_error = 1;
|
||||
if (!encoding) {
|
||||
__collate_load_error = save_load_error;
|
||||
return -1;
|
||||
}
|
||||
if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX"))
|
||||
return 0;
|
||||
if (!_PathLocale) {
|
||||
__collate_load_error = save_load_error;
|
||||
return -1;
|
||||
}
|
||||
/* Range checking not needed, encoding has fixed size */
|
||||
(void) strcpy(buf, _PathLocale);
|
||||
(void) strcat(buf, "/");
|
||||
(void) strcat(buf, encoding);
|
||||
(void) strcat(buf, "/LC_COLLATE");
|
||||
if ((fp = fopen(buf, "r")) == NULL) {
|
||||
__collate_load_error = save_load_error;
|
||||
return -1;
|
||||
}
|
||||
FREAD(__collate_version, sizeof(__collate_version), 1, fp);
|
||||
if (strcmp(__collate_version, COLLATE_VERSION) != 0) {
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
FREAD(__collate_substitute_table, sizeof(__collate_substitute_table),
|
||||
1, fp);
|
||||
FREAD(__collate_char_pri_table, sizeof(__collate_char_pri_table), 1,
|
||||
fp);
|
||||
FREAD(__collate_chain_pri_table, sizeof(__collate_chain_pri_table), 1,
|
||||
fp);
|
||||
fclose(fp);
|
||||
__collate_load_error = 0;
|
||||
|
||||
__collate_substitute_nontrivial = 0;
|
||||
for (i = 0; i < UCHAR_MAX + 1; i++) {
|
||||
if (__collate_substitute_table[i][0] != i ||
|
||||
__collate_substitute_table[i][1] != 0) {
|
||||
__collate_substitute_nontrivial = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
u_char *
|
||||
__collate_substitute(s)
|
||||
const u_char *s;
|
||||
{
|
||||
int dest_len, len, nlen;
|
||||
int delta = strlen(s);
|
||||
u_char *dest_str = NULL;
|
||||
|
||||
if(s == NULL || *s == '\0')
|
||||
return __collate_strdup("");
|
||||
delta += delta / 8;
|
||||
dest_str = malloc(dest_len = delta);
|
||||
if(dest_str == NULL)
|
||||
__collate_err(EX_OSERR, __FUNCTION__);
|
||||
len = 0;
|
||||
while(*s) {
|
||||
nlen = len + strlen(__collate_substitute_table[*s]);
|
||||
if (dest_len <= nlen) {
|
||||
dest_str = reallocf(dest_str, dest_len = nlen + delta);
|
||||
if(dest_str == NULL)
|
||||
__collate_err(EX_OSERR, __FUNCTION__);
|
||||
}
|
||||
strcpy(dest_str + len, __collate_substitute_table[*s++]);
|
||||
len = nlen;
|
||||
}
|
||||
return dest_str;
|
||||
}
|
||||
|
||||
void
|
||||
__collate_lookup(t, len, prim, sec)
|
||||
const u_char *t;
|
||||
int *len, *prim, *sec;
|
||||
{
|
||||
struct __collate_st_chain_pri *p2;
|
||||
|
||||
*len = 1;
|
||||
*prim = *sec = 0;
|
||||
for(p2 = __collate_chain_pri_table; p2->str[0]; p2++) {
|
||||
if(strncmp(t, p2->str, strlen(p2->str)) == 0) {
|
||||
*len = strlen(p2->str);
|
||||
*prim = p2->prim;
|
||||
*sec = p2->sec;
|
||||
return;
|
||||
}
|
||||
}
|
||||
*prim = __collate_char_pri_table[*t].prim;
|
||||
*sec = __collate_char_pri_table[*t].sec;
|
||||
}
|
||||
|
||||
u_char *
|
||||
__collate_strdup(s)
|
||||
u_char *s;
|
||||
{
|
||||
u_char *t = strdup(s);
|
||||
|
||||
if (t == NULL)
|
||||
__collate_err(EX_OSERR, __FUNCTION__);
|
||||
return t;
|
||||
}
|
||||
|
||||
void
|
||||
__collate_err(int ex, const char *f)
|
||||
{
|
||||
const char *s = strdup("collate_error");
|
||||
int serrno = errno;
|
||||
|
||||
write(STDERR_FILENO, s, strlen(s));
|
||||
write(STDERR_FILENO, ": ", 2);
|
||||
free(s);
|
||||
s = f;
|
||||
write(STDERR_FILENO, s, strlen(s));
|
||||
write(STDERR_FILENO, ": ", 2);
|
||||
s = strerror(serrno);
|
||||
write(STDERR_FILENO, s, strlen(s));
|
||||
write(STDERR_FILENO, "\n", 1);
|
||||
exit(ex);
|
||||
}
|
||||
|
||||
#ifdef COLLATE_DEBUG
|
||||
void
|
||||
__collate_print_tables()
|
||||
{
|
||||
int i;
|
||||
struct __collate_st_chain_pri *p2;
|
||||
|
||||
printf("Substitute table:\n");
|
||||
for (i = 0; i < UCHAR_MAX + 1; i++)
|
||||
if (i != *__collate_substitute_table[i])
|
||||
printf("\t'%c' --> \"%s\"\n", i,
|
||||
__collate_substitute_table[i]);
|
||||
printf("Chain priority table:\n");
|
||||
for (p2 = __collate_chain_pri_table; p2->str[0]; p2++)
|
||||
printf("\t\"%s\" : %d %d\n\n", p2->str, p2->prim, p2->sec);
|
||||
printf("Char priority table:\n");
|
||||
for (i = 0; i < UCHAR_MAX + 1; i++)
|
||||
printf("\t'%c' : %d %d\n", i, __collate_char_pri_table[i].prim,
|
||||
__collate_char_pri_table[i].sec);
|
||||
}
|
||||
#endif
|
@ -1,67 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
|
||||
* at Electronni Visti IA, Kiev, Ukraine.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD: src/lib/libc/locale/collate.h,v 1.11 2002/03/21 22:46:54 obrien Exp $
|
||||
*/
|
||||
|
||||
#ifndef _COLLATE_H_
|
||||
#define _COLLATE_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define STR_LEN 10
|
||||
#define TABLE_SIZE 100
|
||||
#define COLLATE_VERSION "1.0\n"
|
||||
|
||||
struct __collate_st_char_pri {
|
||||
int prim, sec;
|
||||
};
|
||||
struct __collate_st_chain_pri {
|
||||
u_char str[STR_LEN];
|
||||
int prim, sec;
|
||||
};
|
||||
|
||||
extern int __collate_load_error;
|
||||
extern int __collate_substitute_nontrivial;
|
||||
extern char __collate_version[STR_LEN];
|
||||
extern u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN];
|
||||
extern struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
|
||||
extern struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE];
|
||||
|
||||
__BEGIN_DECLS
|
||||
u_char *__collate_strdup(u_char *);
|
||||
u_char *__collate_substitute(const u_char *);
|
||||
int __collate_load_tables(char *);
|
||||
void __collate_lookup(const u_char *, int *, int *, int *);
|
||||
int __collate_range_cmp(int, int);
|
||||
#ifdef COLLATE_DEBUG
|
||||
void __collate_print_tables(void);
|
||||
#endif
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_COLLATE_H_ */
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#define ASCII_COMPATIBLE_COLLATE /* see share/colldef */
|
||||
|
||||
#include <string.h>
|
||||
#include "collate.h"
|
||||
#ifndef ASCII_COMPATIBLE_COLLATE
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compare two characters converting collate information
|
||||
* into ASCII-compatible range, it allows to handle
|
||||
* "[a-z]"-type ranges with national characters.
|
||||
*/
|
||||
|
||||
int __collate_range_cmp (c1, c2)
|
||||
int c1, c2;
|
||||
{
|
||||
static char s1[2], s2[2];
|
||||
int ret;
|
||||
#ifndef ASCII_COMPATIBLE_COLLATE
|
||||
int as1, as2, al1, al2;
|
||||
#endif
|
||||
|
||||
c1 &= UCHAR_MAX;
|
||||
c2 &= UCHAR_MAX;
|
||||
if (c1 == c2)
|
||||
return (0);
|
||||
|
||||
#ifndef ASCII_COMPATIBLE_COLLATE
|
||||
as1 = isascii(c1);
|
||||
as2 = isascii(c2);
|
||||
al1 = isalpha(c1);
|
||||
al2 = isalpha(c2);
|
||||
|
||||
if (as1 || as2 || al1 || al2) {
|
||||
if ((as1 && as2) || (!al1 && !al2))
|
||||
return (c1 - c2);
|
||||
if (al1 && !al2) {
|
||||
if (isupper(c1))
|
||||
return ('A' - c2);
|
||||
else
|
||||
return ('a' - c2);
|
||||
} else if (al2 && !al1) {
|
||||
if (isupper(c2))
|
||||
return (c1 - 'A');
|
||||
else
|
||||
return (c1 - 'a');
|
||||
}
|
||||
}
|
||||
#endif
|
||||
s1[0] = c1;
|
||||
s2[0] = c2;
|
||||
if ((ret = strcoll(s1, s2)) != 0)
|
||||
return (ret);
|
||||
return (c1 - c2);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,151 +0,0 @@
|
||||
.\" Copyright (c) 1989, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Guido van Rossum.
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)fnmatch.3 8.3 (Berkeley) 4/28/95
|
||||
.\" $FreeBSD: src/lib/libc/gen/fnmatch.3,v 1.12 2001/10/01 16:08:50 ru Exp $
|
||||
.\"
|
||||
.Dd April 28, 1995
|
||||
.Dt FNMATCH 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm fnmatch
|
||||
.Nd match filename or pathname
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In fnmatch.h
|
||||
.Ft int
|
||||
.Fn fnmatch "const char *pattern" "const char *string" "int flags"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn fnmatch
|
||||
function
|
||||
matches patterns according to the rules used by the shell.
|
||||
It checks the string specified by the
|
||||
.Fa string
|
||||
argument to see if it matches the pattern specified by the
|
||||
.Fa pattern
|
||||
argument.
|
||||
.Pp
|
||||
The
|
||||
.Fa flags
|
||||
argument modifies the interpretation of
|
||||
.Fa pattern
|
||||
and
|
||||
.Fa string .
|
||||
The value of
|
||||
.Fa flags
|
||||
is the bitwise inclusive
|
||||
.Tn OR
|
||||
of any of the following
|
||||
constants, which are defined in the include file
|
||||
.Pa fnmatch.h .
|
||||
.Bl -tag -width FNM_PATHNAME
|
||||
.It Dv FNM_NOESCAPE
|
||||
Normally, every occurrence of a backslash
|
||||
.Pq Ql \e
|
||||
followed by a character in
|
||||
.Fa pattern
|
||||
is replaced by that character.
|
||||
This is done to negate any special meaning for the character.
|
||||
If the
|
||||
.Dv FNM_NOESCAPE
|
||||
flag is set, a backslash character is treated as an ordinary character.
|
||||
.It Dv FNM_PATHNAME
|
||||
Slash characters in
|
||||
.Fa string
|
||||
must be explicitly matched by slashes in
|
||||
.Fa pattern .
|
||||
If this flag is not set, then slashes are treated as regular characters.
|
||||
.It Dv FNM_PERIOD
|
||||
Leading periods in
|
||||
.Fa string
|
||||
must be explicitly matched by periods in
|
||||
.Fa pattern .
|
||||
If this flag is not set, then leading periods are treated as regular
|
||||
characters.
|
||||
The definition of
|
||||
.Dq leading
|
||||
is related to the specification of
|
||||
.Dv FNM_PATHNAME .
|
||||
A period is always
|
||||
.Dq leading
|
||||
if it is the first character in
|
||||
.Ar string .
|
||||
Additionally, if
|
||||
.Dv FNM_PATHNAME
|
||||
is set,
|
||||
a period is
|
||||
leading
|
||||
if it immediately follows a slash.
|
||||
.It Dv FNM_LEADING_DIR
|
||||
Ignore
|
||||
.Nm /*
|
||||
rest after successful
|
||||
.Fa pattern
|
||||
matching.
|
||||
.It Dv FNM_CASEFOLD
|
||||
Ignore case distinctions in both the
|
||||
.Fa pattern
|
||||
and the
|
||||
.Fa string .
|
||||
.El
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn fnmatch
|
||||
function returns zero if
|
||||
.Fa string
|
||||
matches the pattern specified by
|
||||
.Fa pattern ,
|
||||
otherwise, it returns the value
|
||||
.Dv FNM_NOMATCH .
|
||||
.Sh SEE ALSO
|
||||
.Xr sh 1 ,
|
||||
.Xr glob 3 ,
|
||||
.Xr regex 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn fnmatch
|
||||
function conforms to
|
||||
.St -p1003.2 .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn fnmatch
|
||||
function first appeared in
|
||||
.Bx 4.4 .
|
||||
.Sh BUGS
|
||||
The pattern
|
||||
.Ql *
|
||||
matches the empty string, even if
|
||||
.Dv FNM_PATHNAME
|
||||
is specified.
|
@ -1,232 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Guido van Rossum.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/*
|
||||
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
|
||||
* Compares a filename or pathname to a pattern.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <fnmatch.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "collate.h"
|
||||
|
||||
#define EOS '\0'
|
||||
|
||||
#define RANGE_MATCH 1
|
||||
#define RANGE_NOMATCH 0
|
||||
#define RANGE_ERROR (-1)
|
||||
|
||||
static int rangematch(const char *, char, int, char **);
|
||||
|
||||
int
|
||||
fnmatch(pattern, string, flags)
|
||||
const char *pattern, *string;
|
||||
int flags;
|
||||
{
|
||||
const char *stringstart;
|
||||
char *newp;
|
||||
char c, test;
|
||||
|
||||
for (stringstart = string;;)
|
||||
switch (c = *pattern++) {
|
||||
case EOS:
|
||||
if ((flags & FNM_LEADING_DIR) && *string == '/')
|
||||
return (0);
|
||||
return (*string == EOS ? 0 : FNM_NOMATCH);
|
||||
case '?':
|
||||
if (*string == EOS)
|
||||
return (FNM_NOMATCH);
|
||||
if (*string == '/' && (flags & FNM_PATHNAME))
|
||||
return (FNM_NOMATCH);
|
||||
if (*string == '.' && (flags & FNM_PERIOD) &&
|
||||
(string == stringstart ||
|
||||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
|
||||
return (FNM_NOMATCH);
|
||||
++string;
|
||||
break;
|
||||
case '*':
|
||||
c = *pattern;
|
||||
/* Collapse multiple stars. */
|
||||
while (c == '*')
|
||||
c = *++pattern;
|
||||
|
||||
if (*string == '.' && (flags & FNM_PERIOD) &&
|
||||
(string == stringstart ||
|
||||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
|
||||
return (FNM_NOMATCH);
|
||||
|
||||
/* Optimize for pattern with * at end or before /. */
|
||||
if (c == EOS)
|
||||
if (flags & FNM_PATHNAME)
|
||||
return ((flags & FNM_LEADING_DIR) ||
|
||||
strchr(string, '/') == NULL ?
|
||||
0 : FNM_NOMATCH);
|
||||
else
|
||||
return (0);
|
||||
else if (c == '/' && flags & FNM_PATHNAME) {
|
||||
if ((string = strchr(string, '/')) == NULL)
|
||||
return (FNM_NOMATCH);
|
||||
break;
|
||||
}
|
||||
|
||||
/* General case, use recursion. */
|
||||
while ((test = *string) != EOS) {
|
||||
if (!fnmatch(pattern, string, flags & ~FNM_PERIOD))
|
||||
return (0);
|
||||
if (test == '/' && flags & FNM_PATHNAME)
|
||||
break;
|
||||
++string;
|
||||
}
|
||||
return (FNM_NOMATCH);
|
||||
case '[':
|
||||
if (*string == EOS)
|
||||
return (FNM_NOMATCH);
|
||||
if (*string == '/' && (flags & FNM_PATHNAME))
|
||||
return (FNM_NOMATCH);
|
||||
if (*string == '.' && (flags & FNM_PERIOD) &&
|
||||
(string == stringstart ||
|
||||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
|
||||
return (FNM_NOMATCH);
|
||||
|
||||
switch (rangematch(pattern, *string, flags, &newp)) {
|
||||
case RANGE_ERROR:
|
||||
goto norm;
|
||||
case RANGE_MATCH:
|
||||
pattern = newp;
|
||||
break;
|
||||
case RANGE_NOMATCH:
|
||||
return (FNM_NOMATCH);
|
||||
}
|
||||
++string;
|
||||
break;
|
||||
case '\\':
|
||||
if (!(flags & FNM_NOESCAPE)) {
|
||||
if ((c = *pattern++) == EOS) {
|
||||
c = '\\';
|
||||
--pattern;
|
||||
}
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
norm:
|
||||
if (c == *string)
|
||||
;
|
||||
else if ((flags & FNM_CASEFOLD) &&
|
||||
(tolower((unsigned char)c) ==
|
||||
tolower((unsigned char)*string)))
|
||||
;
|
||||
else
|
||||
return (FNM_NOMATCH);
|
||||
string++;
|
||||
break;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static int
|
||||
rangematch(pattern, test, flags, newp)
|
||||
const char *pattern;
|
||||
char test;
|
||||
int flags;
|
||||
char **newp;
|
||||
{
|
||||
int negate, ok;
|
||||
char c, c2;
|
||||
|
||||
/*
|
||||
* A bracket expression starting with an unquoted circumflex
|
||||
* character produces unspecified results (IEEE 1003.2-1992,
|
||||
* 3.13.2). This implementation treats it like '!', for
|
||||
* consistency with the regular expression syntax.
|
||||
* J.T. Conklin (conklin@ngai.kaleida.com)
|
||||
*/
|
||||
if ( (negate = (*pattern == '!' || *pattern == '^')) )
|
||||
++pattern;
|
||||
|
||||
if (flags & FNM_CASEFOLD)
|
||||
test = tolower((unsigned char)test);
|
||||
|
||||
/*
|
||||
* A right bracket shall lose its special meaning and represent
|
||||
* itself in a bracket expression if it occurs first in the list.
|
||||
* -- POSIX.2 2.8.3.2
|
||||
*/
|
||||
ok = 0;
|
||||
c = *pattern++;
|
||||
do {
|
||||
if (c == '\\' && !(flags & FNM_NOESCAPE))
|
||||
c = *pattern++;
|
||||
if (c == EOS)
|
||||
return (RANGE_ERROR);
|
||||
|
||||
if (c == '/' && (flags & FNM_PATHNAME))
|
||||
return (RANGE_NOMATCH);
|
||||
|
||||
if (flags & FNM_CASEFOLD)
|
||||
c = tolower((unsigned char)c);
|
||||
|
||||
if (*pattern == '-'
|
||||
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
|
||||
pattern += 2;
|
||||
if (c2 == '\\' && !(flags & FNM_NOESCAPE))
|
||||
c2 = *pattern++;
|
||||
if (c2 == EOS)
|
||||
return (RANGE_ERROR);
|
||||
|
||||
if (flags & FNM_CASEFOLD)
|
||||
c2 = tolower((unsigned char)c2);
|
||||
|
||||
if (__collate_load_error ?
|
||||
c <= test && test <= c2 :
|
||||
__collate_range_cmp(c, test) <= 0
|
||||
&& __collate_range_cmp(test, c2) <= 0
|
||||
)
|
||||
ok = 1;
|
||||
} else if (c == test)
|
||||
ok = 1;
|
||||
} while ((c = *pattern++) != ']');
|
||||
|
||||
*newp = (char *)pattern;
|
||||
return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH);
|
||||
}
|
@ -1,466 +0,0 @@
|
||||
.\" Copyright (c) 1989, 1991, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Guido van Rossum.
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)glob.3 8.3 (Berkeley) 4/16/94
|
||||
.\" $FreeBSD: src/lib/libc/gen/glob.3,v 1.20 2001/10/01 16:08:51 ru Exp $
|
||||
.\"
|
||||
.Dd April 16, 1994
|
||||
.Dt GLOB 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm glob ,
|
||||
.Nm globfree
|
||||
.Nd generate pathnames matching a pattern
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In glob.h
|
||||
.Ft int
|
||||
.Fn glob "const char *pattern" "int flags" "int (*errfunc)(const char *, int)" "glob_t *pglob"
|
||||
.Ft void
|
||||
.Fn globfree "glob_t *pglob"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn glob
|
||||
function
|
||||
is a pathname generator that implements the rules for file name pattern
|
||||
matching used by the shell.
|
||||
.Pp
|
||||
The include file
|
||||
.Pa glob.h
|
||||
defines the structure type
|
||||
.Fa glob_t ,
|
||||
which contains at least the following fields:
|
||||
.Bd -literal
|
||||
typedef struct {
|
||||
int gl_pathc; /* count of total paths so far */
|
||||
int gl_matchc; /* count of paths matching pattern */
|
||||
int gl_offs; /* reserved at beginning of gl_pathv */
|
||||
int gl_flags; /* returned flags */
|
||||
char **gl_pathv; /* list of paths matching pattern */
|
||||
} glob_t;
|
||||
.Ed
|
||||
.Pp
|
||||
The argument
|
||||
.Fa pattern
|
||||
is a pointer to a pathname pattern to be expanded.
|
||||
The
|
||||
.Fn glob
|
||||
argument
|
||||
matches all accessible pathnames against the pattern and creates
|
||||
a list of the pathnames that match.
|
||||
In order to have access to a pathname,
|
||||
.Fn glob
|
||||
requires search permission on every component of a path except the last
|
||||
and read permission on each directory of any filename component of
|
||||
.Fa pattern
|
||||
that contains any of the special characters
|
||||
.Ql * ,
|
||||
.Ql ?\&
|
||||
or
|
||||
.Ql \&[ .
|
||||
.Pp
|
||||
The
|
||||
.Fn glob
|
||||
argument
|
||||
stores the number of matched pathnames into the
|
||||
.Fa gl_pathc
|
||||
field, and a pointer to a list of pointers to pathnames into the
|
||||
.Fa gl_pathv
|
||||
field.
|
||||
The first pointer after the last pathname is
|
||||
.Dv NULL .
|
||||
If the pattern does not match any pathnames, the returned number of
|
||||
matched paths is set to zero.
|
||||
.Pp
|
||||
It is the caller's responsibility to create the structure pointed to by
|
||||
.Fa pglob .
|
||||
The
|
||||
.Fn glob
|
||||
function allocates other space as needed, including the memory pointed
|
||||
to by
|
||||
.Fa gl_pathv .
|
||||
.Pp
|
||||
The argument
|
||||
.Fa flags
|
||||
is used to modify the behavior of
|
||||
.Fn glob .
|
||||
The value of
|
||||
.Fa flags
|
||||
is the bitwise inclusive
|
||||
.Tn OR
|
||||
of any of the following
|
||||
values defined in
|
||||
.Pa glob.h :
|
||||
.Bl -tag -width GLOB_ALTDIRFUNC
|
||||
.It Dv GLOB_APPEND
|
||||
Append pathnames generated to the ones from a previous call (or calls)
|
||||
to
|
||||
.Fn glob .
|
||||
The value of
|
||||
.Fa gl_pathc
|
||||
will be the total matches found by this call and the previous call(s).
|
||||
The pathnames are appended to, not merged with the pathnames returned by
|
||||
the previous call(s).
|
||||
Between calls, the caller must not change the setting of the
|
||||
.Dv GLOB_DOOFFS
|
||||
flag, nor change the value of
|
||||
.Fa gl_offs
|
||||
when
|
||||
.Dv GLOB_DOOFFS
|
||||
is set, nor (obviously) call
|
||||
.Fn globfree
|
||||
for
|
||||
.Fa pglob .
|
||||
.It Dv GLOB_DOOFFS
|
||||
Make use of the
|
||||
.Fa gl_offs
|
||||
field.
|
||||
If this flag is set,
|
||||
.Fa gl_offs
|
||||
is used to specify how many
|
||||
.Dv NULL
|
||||
pointers to prepend to the beginning
|
||||
of the
|
||||
.Fa gl_pathv
|
||||
field.
|
||||
In other words,
|
||||
.Fa gl_pathv
|
||||
will point to
|
||||
.Fa gl_offs
|
||||
.Dv NULL
|
||||
pointers,
|
||||
followed by
|
||||
.Fa gl_pathc
|
||||
pathname pointers, followed by a
|
||||
.Dv NULL
|
||||
pointer.
|
||||
.It Dv GLOB_ERR
|
||||
Causes
|
||||
.Fn glob
|
||||
to return when it encounters a directory that it cannot open or read.
|
||||
Ordinarily,
|
||||
.Fn glob
|
||||
continues to find matches.
|
||||
.It Dv GLOB_MARK
|
||||
Each pathname that is a directory that matches
|
||||
.Fa pattern
|
||||
has a slash
|
||||
appended.
|
||||
.It Dv GLOB_NOCHECK
|
||||
If
|
||||
.Fa pattern
|
||||
does not match any pathname, then
|
||||
.Fn glob
|
||||
returns a list
|
||||
consisting of only
|
||||
.Fa pattern ,
|
||||
with the number of total pathnames is set to 1, and the number of matched
|
||||
pathnames set to 0.
|
||||
If
|
||||
.Dv GLOB_QUOTE
|
||||
is set, its effect is present in the pattern returned.
|
||||
.It Dv GLOB_NOSORT
|
||||
By default, the pathnames are sorted in ascending
|
||||
.Tn ASCII
|
||||
order;
|
||||
this flag prevents that sorting (speeding up
|
||||
.Fn glob ) .
|
||||
.El
|
||||
.Pp
|
||||
The following values may also be included in
|
||||
.Fa flags ,
|
||||
however, they are non-standard extensions to
|
||||
.St -p1003.2 .
|
||||
.Bl -tag -width GLOB_ALTDIRFUNC
|
||||
.It Dv GLOB_ALTDIRFUNC
|
||||
The following additional fields in the pglob structure have been
|
||||
initialized with alternate functions for glob to use to open, read,
|
||||
and close directories and to get stat information on names found
|
||||
in those directories.
|
||||
.Bd -literal
|
||||
void *(*gl_opendir)(const char * name);
|
||||
struct dirent *(*gl_readdir)(void *);
|
||||
void (*gl_closedir)(void *);
|
||||
int (*gl_lstat)(const char *name, struct stat *st);
|
||||
int (*gl_stat)(const char *name, struct stat *st);
|
||||
.Ed
|
||||
.Pp
|
||||
This extension is provided to allow programs such as
|
||||
.Xr restore 8
|
||||
to provide globbing from directories stored on tape.
|
||||
.It Dv GLOB_BRACE
|
||||
Pre-process the pattern string to expand
|
||||
.Ql {pat,pat,...}
|
||||
strings like
|
||||
.Xr csh 1 .
|
||||
The pattern
|
||||
.Ql {}
|
||||
is left unexpanded for historical reasons (and
|
||||
.Xr csh 1
|
||||
does the same thing to
|
||||
ease typing
|
||||
of
|
||||
.Xr find 1
|
||||
patterns).
|
||||
.It Dv GLOB_MAGCHAR
|
||||
Set by the
|
||||
.Fn glob
|
||||
function if the pattern included globbing characters.
|
||||
See the description of the usage of the
|
||||
.Fa gl_matchc
|
||||
structure member for more details.
|
||||
.It Dv GLOB_NOMAGIC
|
||||
Is the same as
|
||||
.Dv GLOB_NOCHECK
|
||||
but it only appends the
|
||||
.Fa pattern
|
||||
if it does not contain any of the special characters ``*'', ``?'' or ``[''.
|
||||
.Dv GLOB_NOMAGIC
|
||||
is provided to simplify implementing the historic
|
||||
.Xr csh 1
|
||||
globbing behavior and should probably not be used anywhere else.
|
||||
.It Dv GLOB_QUOTE
|
||||
Use the backslash
|
||||
.Pq Ql \e
|
||||
character for quoting: every occurrence of
|
||||
a backslash followed by a character in the pattern is replaced by that
|
||||
character, avoiding any special interpretation of the character.
|
||||
.It Dv GLOB_TILDE
|
||||
Expand patterns that start with
|
||||
.Ql ~
|
||||
to user name home directories.
|
||||
.It Dv GLOB_LIMIT
|
||||
Limit the total number of returned pathnames to the value provided in
|
||||
.Fa gl_matchc
|
||||
(default
|
||||
.Dv ARG_MAX ) .
|
||||
This option should be set for programs
|
||||
that can be coerced into a denial of service attack
|
||||
via patterns that expand to a very large number of matches,
|
||||
such as a long string of
|
||||
.Ql */../*/.. .
|
||||
.El
|
||||
.Pp
|
||||
If, during the search, a directory is encountered that cannot be opened
|
||||
or read and
|
||||
.Fa errfunc
|
||||
is
|
||||
.Pf non- Dv NULL ,
|
||||
.Fn glob
|
||||
calls
|
||||
.Fa \*(lp*errfunc\*(rp Ns ( Fa path , errno ) .
|
||||
This may be unintuitive: a pattern like
|
||||
.Ql */Makefile
|
||||
will try to
|
||||
.Xr stat 2
|
||||
.Ql foo/Makefile
|
||||
even if
|
||||
.Ql foo
|
||||
is not a directory, resulting in a
|
||||
call to
|
||||
.Fa errfunc .
|
||||
The error routine can suppress this action by testing for
|
||||
.Er ENOENT
|
||||
and
|
||||
.Er ENOTDIR ;
|
||||
however, the
|
||||
.Dv GLOB_ERR
|
||||
flag will still cause an immediate
|
||||
return when this happens.
|
||||
.Pp
|
||||
If
|
||||
.Fa errfunc
|
||||
returns non-zero,
|
||||
.Fn glob
|
||||
stops the scan and returns
|
||||
.Dv GLOB_ABEND
|
||||
after setting
|
||||
.Fa gl_pathc
|
||||
and
|
||||
.Fa gl_pathv
|
||||
to reflect any paths already matched.
|
||||
This also happens if an error is encountered and
|
||||
.Dv GLOB_ERR
|
||||
is set in
|
||||
.Fa flags ,
|
||||
regardless of the return value of
|
||||
.Fa errfunc ,
|
||||
if called.
|
||||
If
|
||||
.Dv GLOB_ERR
|
||||
is not set and either
|
||||
.Fa errfunc
|
||||
is
|
||||
.Dv NULL
|
||||
or
|
||||
.Fa errfunc
|
||||
returns zero, the error is ignored.
|
||||
.Pp
|
||||
The
|
||||
.Fn globfree
|
||||
function frees any space associated with
|
||||
.Fa pglob
|
||||
from a previous call(s) to
|
||||
.Fn glob .
|
||||
.Sh RETURN VALUES
|
||||
On successful completion,
|
||||
.Fn glob
|
||||
returns zero.
|
||||
In addition the fields of
|
||||
.Fa pglob
|
||||
contain the values described below:
|
||||
.Bl -tag -width GLOB_NOCHECK
|
||||
.It Fa gl_pathc
|
||||
contains the total number of matched pathnames so far.
|
||||
This includes other matches from previous invocations of
|
||||
.Fn glob
|
||||
if
|
||||
.Dv GLOB_APPEND
|
||||
was specified.
|
||||
.It Fa gl_matchc
|
||||
contains the number of matched pathnames in the current invocation of
|
||||
.Fn glob .
|
||||
.It Fa gl_flags
|
||||
contains a copy of the
|
||||
.Fa flags
|
||||
parameter with the bit
|
||||
.Dv GLOB_MAGCHAR
|
||||
set if
|
||||
.Fa pattern
|
||||
contained any of the special characters ``*'', ``?'' or ``['', cleared
|
||||
if not.
|
||||
.It Fa gl_pathv
|
||||
contains a pointer to a
|
||||
.Dv NULL Ns -terminated
|
||||
list of matched pathnames.
|
||||
However, if
|
||||
.Fa gl_pathc
|
||||
is zero, the contents of
|
||||
.Fa gl_pathv
|
||||
are undefined.
|
||||
.El
|
||||
.Pp
|
||||
If
|
||||
.Fn glob
|
||||
terminates due to an error, it sets errno and returns one of the
|
||||
following non-zero constants, which are defined in the include
|
||||
file
|
||||
.Aq Pa glob.h :
|
||||
.Bl -tag -width GLOB_NOCHECK
|
||||
.It Dv GLOB_NOSPACE
|
||||
An attempt to allocate memory failed, or if
|
||||
.Fa errno
|
||||
was 0
|
||||
.Dv GLOB_LIMIT
|
||||
was specified in the flags and
|
||||
.Fa pglob\->gl_matchc
|
||||
or more patterns were matched.
|
||||
.It Dv GLOB_ABEND
|
||||
The scan was stopped because an error was encountered and either
|
||||
.Dv GLOB_ERR
|
||||
was set or
|
||||
.Fa \*(lp*errfunc\*(rp\*(lp\*(rp
|
||||
returned non-zero.
|
||||
.El
|
||||
.Pp
|
||||
The arguments
|
||||
.Fa pglob\->gl_pathc
|
||||
and
|
||||
.Fa pglob\->gl_pathv
|
||||
are still set as specified above.
|
||||
.Sh EXAMPLES
|
||||
A rough equivalent of
|
||||
.Ql "ls -l *.c *.h"
|
||||
can be obtained with the
|
||||
following code:
|
||||
.Bd -literal -offset indent
|
||||
glob_t g;
|
||||
|
||||
g.gl_offs = 2;
|
||||
glob("*.c", GLOB_DOOFFS, NULL, &g);
|
||||
glob("*.h", GLOB_DOOFFS | GLOB_APPEND, NULL, &g);
|
||||
g.gl_pathv[0] = "ls";
|
||||
g.gl_pathv[1] = "-l";
|
||||
execvp("ls", g.gl_pathv);
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr sh 1 ,
|
||||
.Xr fnmatch 3 ,
|
||||
.Xr regexp 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn glob
|
||||
function is expected to be
|
||||
.St -p1003.2
|
||||
compatible with the exception
|
||||
that the flags
|
||||
.Dv GLOB_ALTDIRFUNC ,
|
||||
.Dv GLOB_BRACE ,
|
||||
.Dv GLOB_LIMIT ,
|
||||
.Dv GLOB_MAGCHAR ,
|
||||
.Dv GLOB_NOMAGIC ,
|
||||
.Dv GLOB_QUOTE ,
|
||||
and
|
||||
.Dv GLOB_TILDE ,
|
||||
and the fields
|
||||
.Fa gl_matchc
|
||||
and
|
||||
.Fa gl_flags
|
||||
should not be used by applications striving for strict
|
||||
.Tn POSIX
|
||||
conformance.
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn glob
|
||||
and
|
||||
.Fn globfree
|
||||
functions first appeared in
|
||||
.Bx 4.4 .
|
||||
.Sh BUGS
|
||||
Patterns longer than
|
||||
.Dv MAXPATHLEN
|
||||
may cause unchecked errors.
|
||||
.Pp
|
||||
The
|
||||
.Fn glob
|
||||
argument
|
||||
may fail and set errno for any of the errors specified for the
|
||||
library routines
|
||||
.Xr stat 2 ,
|
||||
.Xr closedir 3 ,
|
||||
.Xr opendir 3 ,
|
||||
.Xr readdir 3 ,
|
||||
.Xr malloc 3 ,
|
||||
and
|
||||
.Xr free 3 .
|
@ -1,910 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Guido van Rossum.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/*
|
||||
* glob(3) -- a superset of the one defined in POSIX 1003.2.
|
||||
*
|
||||
* The [!...] convention to negate a range is supported (SysV, Posix, ksh).
|
||||
*
|
||||
* Optional extra services, controlled by flags not defined by POSIX:
|
||||
*
|
||||
* GLOB_QUOTE:
|
||||
* Escaping convention: \ inhibits any special meaning the following
|
||||
* character might have (except \ at end of string is retained).
|
||||
* GLOB_MAGCHAR:
|
||||
* Set in gl_flags if pattern contained a globbing character.
|
||||
* GLOB_NOMAGIC:
|
||||
* Same as GLOB_NOCHECK, but it will only append pattern if it did
|
||||
* not contain any magic characters. [Used in csh style globbing]
|
||||
* GLOB_ALTDIRFUNC:
|
||||
* Use alternately specified directory access functions.
|
||||
* GLOB_TILDE:
|
||||
* expand ~user/foo to the /home/dir/of/user/foo
|
||||
* GLOB_BRACE:
|
||||
* expand {1,2}{a,b} to 1a 1b 2a 2b
|
||||
* gl_matchc:
|
||||
* Number of matches in the current invocation of glob.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
#include "collate.h"
|
||||
|
||||
#define DOLLAR '$'
|
||||
#define DOT '.'
|
||||
#define EOS '\0'
|
||||
#define LBRACKET '['
|
||||
#define NOT '!'
|
||||
#define QUESTION '?'
|
||||
#define QUOTE '\\'
|
||||
#define RANGE '-'
|
||||
#define RBRACKET ']'
|
||||
#define SEP '/'
|
||||
#define STAR '*'
|
||||
#define TILDE '~'
|
||||
#define UNDERSCORE '_'
|
||||
#define LBRACE '{'
|
||||
#define RBRACE '}'
|
||||
#define SLASH '/'
|
||||
#define COMMA ','
|
||||
|
||||
#ifndef DEBUG
|
||||
|
||||
#define M_QUOTE 0x8000
|
||||
#define M_PROTECT 0x4000
|
||||
#define M_MASK 0xffff
|
||||
#define M_ASCII 0x00ff
|
||||
|
||||
typedef u_short Char;
|
||||
|
||||
#else
|
||||
|
||||
#define M_QUOTE 0x80
|
||||
#define M_PROTECT 0x40
|
||||
#define M_MASK 0xff
|
||||
#define M_ASCII 0x7f
|
||||
|
||||
typedef char Char;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define CHAR(c) ((Char)((c)&M_ASCII))
|
||||
#define META(c) ((Char)((c)|M_QUOTE))
|
||||
#define M_ALL META('*')
|
||||
#define M_END META(']')
|
||||
#define M_NOT META('!')
|
||||
#define M_ONE META('?')
|
||||
#define M_RNG META('-')
|
||||
#define M_SET META('[')
|
||||
#define ismeta(c) (((c)&M_QUOTE) != 0)
|
||||
|
||||
|
||||
static int compare(const void *, const void *);
|
||||
static int g_Ctoc(const Char *, char *, u_int);
|
||||
static int g_lstat(Char *, struct stat *, glob_t *);
|
||||
static DIR *g_opendir(Char *, glob_t *);
|
||||
static Char *g_strchr(Char *, int);
|
||||
#ifdef notdef
|
||||
static Char *g_strcat(Char *, const Char *);
|
||||
#endif
|
||||
static int g_stat(Char *, struct stat *, glob_t *);
|
||||
static int glob0(const Char *, glob_t *, int *);
|
||||
static int glob1(Char *, glob_t *, int *);
|
||||
static int glob2(Char *, Char *, Char *, Char *, glob_t *, int *);
|
||||
static int glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, int *);
|
||||
static int globextend(const Char *, glob_t *, int *);
|
||||
static const Char *
|
||||
globtilde(const Char *, Char *, size_t, glob_t *);
|
||||
static int globexp1(const Char *, glob_t *, int *);
|
||||
static int globexp2(const Char *, const Char *, glob_t *, int *, int *);
|
||||
static int match(Char *, Char *, Char *);
|
||||
#ifdef DEBUG
|
||||
static void qprintf(const char *, Char *);
|
||||
#endif
|
||||
|
||||
int
|
||||
glob(pattern, flags, errfunc, pglob)
|
||||
const char *pattern;
|
||||
int flags, (*errfunc)(const char *, int);
|
||||
glob_t *pglob;
|
||||
{
|
||||
const u_char *patnext;
|
||||
int c, limit;
|
||||
Char *bufnext, *bufend, patbuf[MAXPATHLEN];
|
||||
|
||||
patnext = (u_char *) pattern;
|
||||
if (!(flags & GLOB_APPEND)) {
|
||||
pglob->gl_pathc = 0;
|
||||
pglob->gl_pathv = NULL;
|
||||
if (!(flags & GLOB_DOOFFS))
|
||||
pglob->gl_offs = 0;
|
||||
}
|
||||
if (flags & GLOB_LIMIT) {
|
||||
limit = pglob->gl_matchc;
|
||||
if (limit == 0)
|
||||
limit = ARG_MAX;
|
||||
} else
|
||||
limit = 0;
|
||||
pglob->gl_flags = flags & ~GLOB_MAGCHAR;
|
||||
pglob->gl_errfunc = errfunc;
|
||||
pglob->gl_matchc = 0;
|
||||
|
||||
bufnext = patbuf;
|
||||
bufend = bufnext + MAXPATHLEN - 1;
|
||||
if (flags & GLOB_QUOTE) {
|
||||
/* Protect the quoted characters. */
|
||||
while (bufnext < bufend && (c = *patnext++) != EOS)
|
||||
if (c == QUOTE) {
|
||||
if ((c = *patnext++) == EOS) {
|
||||
c = QUOTE;
|
||||
--patnext;
|
||||
}
|
||||
*bufnext++ = c | M_PROTECT;
|
||||
}
|
||||
else
|
||||
*bufnext++ = c;
|
||||
}
|
||||
else
|
||||
while (bufnext < bufend && (c = *patnext++) != EOS)
|
||||
*bufnext++ = c;
|
||||
*bufnext = EOS;
|
||||
|
||||
if (flags & GLOB_BRACE)
|
||||
return globexp1(patbuf, pglob, &limit);
|
||||
else
|
||||
return glob0(patbuf, pglob, &limit);
|
||||
}
|
||||
|
||||
/*
|
||||
* Expand recursively a glob {} pattern. When there is no more expansion
|
||||
* invoke the standard globbing routine to glob the rest of the magic
|
||||
* characters
|
||||
*/
|
||||
static int
|
||||
globexp1(pattern, pglob, limit)
|
||||
const Char *pattern;
|
||||
glob_t *pglob;
|
||||
int *limit;
|
||||
{
|
||||
const Char* ptr = pattern;
|
||||
int rv;
|
||||
|
||||
/* Protect a single {}, for find(1), like csh */
|
||||
if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS)
|
||||
return glob0(pattern, pglob, limit);
|
||||
|
||||
while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL)
|
||||
if (!globexp2(ptr, pattern, pglob, &rv, limit))
|
||||
return rv;
|
||||
|
||||
return glob0(pattern, pglob, limit);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Recursive brace globbing helper. Tries to expand a single brace.
|
||||
* If it succeeds then it invokes globexp1 with the new pattern.
|
||||
* If it fails then it tries to glob the rest of the pattern and returns.
|
||||
*/
|
||||
static int
|
||||
globexp2(ptr, pattern, pglob, rv, limit)
|
||||
const Char *ptr, *pattern;
|
||||
glob_t *pglob;
|
||||
int *rv, *limit;
|
||||
{
|
||||
int i;
|
||||
Char *lm, *ls;
|
||||
const Char *pe, *pm, *pl;
|
||||
Char patbuf[MAXPATHLEN];
|
||||
|
||||
/* copy part up to the brace */
|
||||
for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++)
|
||||
continue;
|
||||
*lm = EOS;
|
||||
ls = lm;
|
||||
|
||||
/* Find the balanced brace */
|
||||
for (i = 0, pe = ++ptr; *pe; pe++)
|
||||
if (*pe == LBRACKET) {
|
||||
/* Ignore everything between [] */
|
||||
for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++)
|
||||
continue;
|
||||
if (*pe == EOS) {
|
||||
/*
|
||||
* We could not find a matching RBRACKET.
|
||||
* Ignore and just look for RBRACE
|
||||
*/
|
||||
pe = pm;
|
||||
}
|
||||
}
|
||||
else if (*pe == LBRACE)
|
||||
i++;
|
||||
else if (*pe == RBRACE) {
|
||||
if (i == 0)
|
||||
break;
|
||||
i--;
|
||||
}
|
||||
|
||||
/* Non matching braces; just glob the pattern */
|
||||
if (i != 0 || *pe == EOS) {
|
||||
*rv = glob0(patbuf, pglob, limit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0, pl = pm = ptr; pm <= pe; pm++)
|
||||
switch (*pm) {
|
||||
case LBRACKET:
|
||||
/* Ignore everything between [] */
|
||||
for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++)
|
||||
continue;
|
||||
if (*pm == EOS) {
|
||||
/*
|
||||
* We could not find a matching RBRACKET.
|
||||
* Ignore and just look for RBRACE
|
||||
*/
|
||||
pm = pl;
|
||||
}
|
||||
break;
|
||||
|
||||
case LBRACE:
|
||||
i++;
|
||||
break;
|
||||
|
||||
case RBRACE:
|
||||
if (i) {
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case COMMA:
|
||||
if (i && *pm == COMMA)
|
||||
break;
|
||||
else {
|
||||
/* Append the current string */
|
||||
for (lm = ls; (pl < pm); *lm++ = *pl++)
|
||||
continue;
|
||||
/*
|
||||
* Append the rest of the pattern after the
|
||||
* closing brace
|
||||
*/
|
||||
for (pl = pe + 1; (*lm++ = *pl++) != EOS;)
|
||||
continue;
|
||||
|
||||
/* Expand the current pattern */
|
||||
#ifdef DEBUG
|
||||
qprintf("globexp2:", patbuf);
|
||||
#endif
|
||||
*rv = globexp1(patbuf, pglob, limit);
|
||||
|
||||
/* move after the comma, to the next string */
|
||||
pl = pm + 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*rv = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* expand tilde from the passwd file.
|
||||
*/
|
||||
static const Char *
|
||||
globtilde(pattern, patbuf, patbuf_len, pglob)
|
||||
const Char *pattern;
|
||||
Char *patbuf;
|
||||
size_t patbuf_len;
|
||||
glob_t *pglob;
|
||||
{
|
||||
struct passwd *pwd;
|
||||
char *h;
|
||||
const Char *p;
|
||||
Char *b, *eb;
|
||||
|
||||
if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
|
||||
return pattern;
|
||||
|
||||
/*
|
||||
* Copy up to the end of the string or /
|
||||
*/
|
||||
eb = &patbuf[patbuf_len - 1];
|
||||
for (p = pattern + 1, h = (char *) patbuf;
|
||||
h < (char *)eb && *p && *p != SLASH; *h++ = *p++)
|
||||
continue;
|
||||
|
||||
*h = EOS;
|
||||
|
||||
if (((char *) patbuf)[0] == EOS) {
|
||||
/*
|
||||
* handle a plain ~ or ~/ by expanding $HOME first (iff
|
||||
* we're not running setuid or setgid) and then trying
|
||||
* the password file
|
||||
*/
|
||||
if (
|
||||
#ifndef __NETBSD_SYSCALLS
|
||||
issetugid() != 0 ||
|
||||
#endif
|
||||
(h = getenv("HOME")) == NULL) {
|
||||
/* If we are not EL/IX level 4, we cannot use getpwxxx interfaces */
|
||||
#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 4
|
||||
if (((h = getlogin()) != NULL &&
|
||||
(pwd = getpwnam(h)) != NULL) ||
|
||||
(pwd = getpwuid(getuid())) != NULL)
|
||||
h = pwd->pw_dir;
|
||||
else
|
||||
#endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 4 */
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* Expand a ~user
|
||||
*/
|
||||
|
||||
#if !defined(_ELIX_LEVEL) || _ELIX_LEVEL >= 4
|
||||
if ((pwd = getpwnam((char*) patbuf)) != NULL)
|
||||
h = pwd->pw_dir;
|
||||
else
|
||||
#endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 4 */
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/* Copy the home directory */
|
||||
for (b = patbuf; b < eb && *h; *b++ = *h++)
|
||||
continue;
|
||||
|
||||
/* Append the rest of the pattern */
|
||||
while (b < eb && (*b++ = *p++) != EOS)
|
||||
continue;
|
||||
*b = EOS;
|
||||
|
||||
return patbuf;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The main glob() routine: compiles the pattern (optionally processing
|
||||
* quotes), calls glob1() to do the real pattern matching, and finally
|
||||
* sorts the list (unless unsorted operation is requested). Returns 0
|
||||
* if things went well, nonzero if errors occurred. It is not an error
|
||||
* to find no matches.
|
||||
*/
|
||||
static int
|
||||
glob0(pattern, pglob, limit)
|
||||
const Char *pattern;
|
||||
glob_t *pglob;
|
||||
int *limit;
|
||||
{
|
||||
const Char *qpatnext;
|
||||
int c, err, oldpathc;
|
||||
Char *bufnext, patbuf[MAXPATHLEN];
|
||||
|
||||
qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob);
|
||||
oldpathc = pglob->gl_pathc;
|
||||
bufnext = patbuf;
|
||||
|
||||
/* We don't need to check for buffer overflow any more. */
|
||||
while ((c = *qpatnext++) != EOS) {
|
||||
switch (c) {
|
||||
case LBRACKET:
|
||||
c = *qpatnext;
|
||||
if (c == NOT)
|
||||
++qpatnext;
|
||||
if (*qpatnext == EOS ||
|
||||
g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) {
|
||||
*bufnext++ = LBRACKET;
|
||||
if (c == NOT)
|
||||
--qpatnext;
|
||||
break;
|
||||
}
|
||||
*bufnext++ = M_SET;
|
||||
if (c == NOT)
|
||||
*bufnext++ = M_NOT;
|
||||
c = *qpatnext++;
|
||||
do {
|
||||
*bufnext++ = CHAR(c);
|
||||
if (*qpatnext == RANGE &&
|
||||
(c = qpatnext[1]) != RBRACKET) {
|
||||
*bufnext++ = M_RNG;
|
||||
*bufnext++ = CHAR(c);
|
||||
qpatnext += 2;
|
||||
}
|
||||
} while ((c = *qpatnext++) != RBRACKET);
|
||||
pglob->gl_flags |= GLOB_MAGCHAR;
|
||||
*bufnext++ = M_END;
|
||||
break;
|
||||
case QUESTION:
|
||||
pglob->gl_flags |= GLOB_MAGCHAR;
|
||||
*bufnext++ = M_ONE;
|
||||
break;
|
||||
case STAR:
|
||||
pglob->gl_flags |= GLOB_MAGCHAR;
|
||||
/* collapse adjacent stars to one,
|
||||
* to avoid exponential behavior
|
||||
*/
|
||||
if (bufnext == patbuf || bufnext[-1] != M_ALL)
|
||||
*bufnext++ = M_ALL;
|
||||
break;
|
||||
default:
|
||||
*bufnext++ = CHAR(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*bufnext = EOS;
|
||||
#ifdef DEBUG
|
||||
qprintf("glob0:", patbuf);
|
||||
#endif
|
||||
|
||||
if ((err = glob1(patbuf, pglob, limit)) != 0)
|
||||
return(err);
|
||||
|
||||
/*
|
||||
* If there was no match we are going to append the pattern
|
||||
* if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
|
||||
* and the pattern did not contain any magic characters
|
||||
* GLOB_NOMAGIC is there just for compatibility with csh.
|
||||
*/
|
||||
if (pglob->gl_pathc == oldpathc &&
|
||||
((pglob->gl_flags & GLOB_NOCHECK) ||
|
||||
((pglob->gl_flags & GLOB_NOMAGIC) &&
|
||||
!(pglob->gl_flags & GLOB_MAGCHAR))))
|
||||
return(globextend(pattern, pglob, limit));
|
||||
else if (!(pglob->gl_flags & GLOB_NOSORT))
|
||||
qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc,
|
||||
pglob->gl_pathc - oldpathc, sizeof(char *), compare);
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int
|
||||
compare(p, q)
|
||||
const void *p, *q;
|
||||
{
|
||||
return(strcmp(*(char **)p, *(char **)q));
|
||||
}
|
||||
|
||||
static int
|
||||
glob1(pattern, pglob, limit)
|
||||
Char *pattern;
|
||||
glob_t *pglob;
|
||||
int *limit;
|
||||
{
|
||||
Char pathbuf[MAXPATHLEN];
|
||||
|
||||
/* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */
|
||||
if (*pattern == EOS)
|
||||
return(0);
|
||||
return(glob2(pathbuf, pathbuf, pathbuf + MAXPATHLEN - 1,
|
||||
pattern, pglob, limit));
|
||||
}
|
||||
|
||||
/*
|
||||
* The functions glob2 and glob3 are mutually recursive; there is one level
|
||||
* of recursion for each segment in the pattern that contains one or more
|
||||
* meta characters.
|
||||
*/
|
||||
static int
|
||||
glob2(pathbuf, pathend, pathend_last, pattern, pglob, limit)
|
||||
Char *pathbuf, *pathend, *pathend_last, *pattern;
|
||||
glob_t *pglob;
|
||||
int *limit;
|
||||
{
|
||||
struct stat sb;
|
||||
Char *p, *q;
|
||||
int anymeta;
|
||||
|
||||
/*
|
||||
* Loop over pattern segments until end of pattern or until
|
||||
* segment with meta character found.
|
||||
*/
|
||||
for (anymeta = 0;;) {
|
||||
if (*pattern == EOS) { /* End of pattern? */
|
||||
*pathend = EOS;
|
||||
if (g_lstat(pathbuf, &sb, pglob))
|
||||
return(0);
|
||||
|
||||
if (((pglob->gl_flags & GLOB_MARK) &&
|
||||
pathend[-1] != SEP) && (S_ISDIR(sb.st_mode)
|
||||
|| (S_ISLNK(sb.st_mode) &&
|
||||
(g_stat(pathbuf, &sb, pglob) == 0) &&
|
||||
S_ISDIR(sb.st_mode)))) {
|
||||
if (pathend + 1 > pathend_last)
|
||||
return (1);
|
||||
*pathend++ = SEP;
|
||||
*pathend = EOS;
|
||||
}
|
||||
++pglob->gl_matchc;
|
||||
return(globextend(pathbuf, pglob, limit));
|
||||
}
|
||||
|
||||
/* Find end of next segment, copy tentatively to pathend. */
|
||||
q = pathend;
|
||||
p = pattern;
|
||||
while (*p != EOS && *p != SEP) {
|
||||
if (ismeta(*p))
|
||||
anymeta = 1;
|
||||
if (q + 1 > pathend_last)
|
||||
return (1);
|
||||
*q++ = *p++;
|
||||
}
|
||||
|
||||
if (!anymeta) { /* No expansion, do next segment. */
|
||||
pathend = q;
|
||||
pattern = p;
|
||||
while (*pattern == SEP) {
|
||||
if (pathend + 1 > pathend_last)
|
||||
return (1);
|
||||
*pathend++ = *pattern++;
|
||||
}
|
||||
} else /* Need expansion, recurse. */
|
||||
return(glob3(pathbuf, pathend, pathend_last, pattern, p,
|
||||
pglob, limit));
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static int
|
||||
glob3(pathbuf, pathend, pathend_last, pattern, restpattern, pglob, limit)
|
||||
Char *pathbuf, *pathend, *pathend_last, *pattern, *restpattern;
|
||||
glob_t *pglob;
|
||||
int *limit;
|
||||
{
|
||||
struct dirent *dp;
|
||||
DIR *dirp;
|
||||
int err;
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
/*
|
||||
* The readdirfunc declaration can't be prototyped, because it is
|
||||
* assigned, below, to two functions which are prototyped in glob.h
|
||||
* and dirent.h as taking pointers to differently typed opaque
|
||||
* structures.
|
||||
*/
|
||||
struct dirent *(*readdirfunc)();
|
||||
|
||||
if (pathend > pathend_last)
|
||||
return (1);
|
||||
*pathend = EOS;
|
||||
errno = 0;
|
||||
|
||||
if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
|
||||
/* TODO: don't call for ENOENT or ENOTDIR? */
|
||||
if (pglob->gl_errfunc) {
|
||||
if (g_Ctoc(pathbuf, buf, sizeof(buf)))
|
||||
return (GLOB_ABEND);
|
||||
if (pglob->gl_errfunc(buf, errno) ||
|
||||
pglob->gl_flags & GLOB_ERR)
|
||||
return (GLOB_ABEND);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
err = 0;
|
||||
|
||||
/* Search directory for matching names. */
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
readdirfunc = pglob->gl_readdir;
|
||||
else
|
||||
readdirfunc = readdir;
|
||||
while ((dp = (*readdirfunc)(dirp))) {
|
||||
u_char *sc;
|
||||
Char *dc;
|
||||
|
||||
/* Initial DOT must be matched literally. */
|
||||
if (dp->d_name[0] == DOT && *pattern != DOT)
|
||||
continue;
|
||||
dc = pathend;
|
||||
sc = (u_char *) dp->d_name;
|
||||
while (dc < pathend_last && (*dc++ = *sc++) != EOS)
|
||||
;
|
||||
if (!match(pathend, pattern, restpattern)) {
|
||||
*pathend = EOS;
|
||||
continue;
|
||||
}
|
||||
err = glob2(pathbuf, --dc, pathend_last, restpattern,
|
||||
pglob, limit);
|
||||
if (err)
|
||||
break;
|
||||
}
|
||||
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
(*pglob->gl_closedir)(dirp);
|
||||
else
|
||||
closedir(dirp);
|
||||
return(err);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Extend the gl_pathv member of a glob_t structure to accomodate a new item,
|
||||
* add the new item, and update gl_pathc.
|
||||
*
|
||||
* This assumes the BSD realloc, which only copies the block when its size
|
||||
* crosses a power-of-two boundary; for v7 realloc, this would cause quadratic
|
||||
* behavior.
|
||||
*
|
||||
* Return 0 if new item added, error code if memory couldn't be allocated.
|
||||
*
|
||||
* Invariant of the glob_t structure:
|
||||
* Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and
|
||||
* gl_pathv points to (gl_offs + gl_pathc + 1) items.
|
||||
*/
|
||||
static int
|
||||
globextend(path, pglob, limit)
|
||||
const Char *path;
|
||||
glob_t *pglob;
|
||||
int *limit;
|
||||
{
|
||||
char **pathv;
|
||||
int i;
|
||||
u_int newsize, len;
|
||||
char *copy;
|
||||
const Char *p;
|
||||
|
||||
if (*limit && pglob->gl_pathc > *limit) {
|
||||
errno = 0;
|
||||
return (GLOB_NOSPACE);
|
||||
}
|
||||
|
||||
newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
|
||||
pathv = pglob->gl_pathv ?
|
||||
realloc((char *)pglob->gl_pathv, newsize) :
|
||||
malloc(newsize);
|
||||
if (pathv == NULL) {
|
||||
if (pglob->gl_pathv) {
|
||||
free(pglob->gl_pathv);
|
||||
pglob->gl_pathv = NULL;
|
||||
}
|
||||
return(GLOB_NOSPACE);
|
||||
}
|
||||
|
||||
if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) {
|
||||
/* first time around -- clear initial gl_offs items */
|
||||
pathv += pglob->gl_offs;
|
||||
for (i = pglob->gl_offs; --i >= 0; )
|
||||
*--pathv = NULL;
|
||||
}
|
||||
pglob->gl_pathv = pathv;
|
||||
|
||||
for (p = path; *p++;)
|
||||
continue;
|
||||
len = (size_t)(p - path);
|
||||
if ((copy = malloc(len)) != NULL) {
|
||||
if (g_Ctoc(path, copy, len)) {
|
||||
free(copy);
|
||||
return (GLOB_NOSPACE);
|
||||
}
|
||||
pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
|
||||
}
|
||||
pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
|
||||
return(copy == NULL ? GLOB_NOSPACE : 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* pattern matching function for filenames. Each occurrence of the *
|
||||
* pattern causes a recursion level.
|
||||
*/
|
||||
static int
|
||||
match(name, pat, patend)
|
||||
Char *name, *pat, *patend;
|
||||
{
|
||||
int ok, negate_range;
|
||||
Char c, k;
|
||||
|
||||
while (pat < patend) {
|
||||
c = *pat++;
|
||||
switch (c & M_MASK) {
|
||||
case M_ALL:
|
||||
if (pat == patend)
|
||||
return(1);
|
||||
do
|
||||
if (match(name, pat, patend))
|
||||
return(1);
|
||||
while (*name++ != EOS);
|
||||
return(0);
|
||||
case M_ONE:
|
||||
if (*name++ == EOS)
|
||||
return(0);
|
||||
break;
|
||||
case M_SET:
|
||||
ok = 0;
|
||||
if ((k = *name++) == EOS)
|
||||
return(0);
|
||||
if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS)
|
||||
++pat;
|
||||
while (((c = *pat++) & M_MASK) != M_END)
|
||||
if ((*pat & M_MASK) == M_RNG) {
|
||||
if (__collate_load_error ?
|
||||
CHAR(c) <= CHAR(k) && CHAR(k) <= CHAR(pat[1]) :
|
||||
__collate_range_cmp(CHAR(c), CHAR(k)) <= 0
|
||||
&& __collate_range_cmp(CHAR(k), CHAR(pat[1])) <= 0
|
||||
)
|
||||
ok = 1;
|
||||
pat += 2;
|
||||
} else if (c == k)
|
||||
ok = 1;
|
||||
if (ok == negate_range)
|
||||
return(0);
|
||||
break;
|
||||
default:
|
||||
if (*name++ != c)
|
||||
return(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(*name == EOS);
|
||||
}
|
||||
|
||||
/* Free allocated data belonging to a glob_t structure. */
|
||||
void
|
||||
globfree(pglob)
|
||||
glob_t *pglob;
|
||||
{
|
||||
int i;
|
||||
char **pp;
|
||||
|
||||
if (pglob->gl_pathv != NULL) {
|
||||
pp = pglob->gl_pathv + pglob->gl_offs;
|
||||
for (i = pglob->gl_pathc; i--; ++pp)
|
||||
if (*pp)
|
||||
free(*pp);
|
||||
free(pglob->gl_pathv);
|
||||
pglob->gl_pathv = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static DIR *
|
||||
g_opendir(str, pglob)
|
||||
Char *str;
|
||||
glob_t *pglob;
|
||||
{
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
if (!*str)
|
||||
strcpy(buf, ".");
|
||||
else {
|
||||
if (g_Ctoc(str, buf, sizeof(buf)))
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
return((*pglob->gl_opendir)(buf));
|
||||
|
||||
return(opendir(buf));
|
||||
}
|
||||
|
||||
static int
|
||||
g_lstat(fn, sb, pglob)
|
||||
Char *fn;
|
||||
struct stat *sb;
|
||||
glob_t *pglob;
|
||||
{
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
if (g_Ctoc(fn, buf, sizeof(buf))) {
|
||||
errno = ENAMETOOLONG;
|
||||
return (-1);
|
||||
}
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
return((*pglob->gl_lstat)(buf, sb));
|
||||
return(lstat(buf, sb));
|
||||
}
|
||||
|
||||
static int
|
||||
g_stat(fn, sb, pglob)
|
||||
Char *fn;
|
||||
struct stat *sb;
|
||||
glob_t *pglob;
|
||||
{
|
||||
char buf[MAXPATHLEN];
|
||||
|
||||
if (g_Ctoc(fn, buf, sizeof(buf))) {
|
||||
errno = ENAMETOOLONG;
|
||||
return (-1);
|
||||
}
|
||||
if (pglob->gl_flags & GLOB_ALTDIRFUNC)
|
||||
return((*pglob->gl_stat)(buf, sb));
|
||||
return(stat(buf, sb));
|
||||
}
|
||||
|
||||
static Char *
|
||||
g_strchr(str, ch)
|
||||
Char *str;
|
||||
int ch;
|
||||
{
|
||||
do {
|
||||
if (*str == ch)
|
||||
return (str);
|
||||
} while (*str++);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
g_Ctoc(str, buf, len)
|
||||
const Char *str;
|
||||
char *buf;
|
||||
u_int len;
|
||||
{
|
||||
|
||||
while (len--) {
|
||||
if ((*buf++ = *str++) == '\0')
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
qprintf(str, s)
|
||||
const char *str;
|
||||
Char *s;
|
||||
{
|
||||
Char *p;
|
||||
|
||||
(void)printf("%s:\n", str);
|
||||
for (p = s; *p; p++)
|
||||
(void)printf("%c", CHAR(*p));
|
||||
(void)printf("\n");
|
||||
for (p = s; *p; p++)
|
||||
(void)printf("%c", *p & M_PROTECT ? '"' : ' ');
|
||||
(void)printf("\n");
|
||||
for (p = s; *p; p++)
|
||||
(void)printf("%c", ismeta(*p) ? '_' : ' ');
|
||||
(void)printf("\n");
|
||||
}
|
||||
#endif
|
@ -1,40 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1998, M. Warner Losh <imp@freebsd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void *
|
||||
reallocf(void *ptr, size_t size)
|
||||
{
|
||||
void *nptr;
|
||||
|
||||
nptr = realloc(ptr, size);
|
||||
if (!nptr && ptr)
|
||||
free(ptr);
|
||||
return (nptr);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,178 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)regerror.c 8.4 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
/* ========= begin header generated by ./mkh ========= */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* === regerror.c === */
|
||||
static char *regatoi(const regex_t *preg, char *localbuf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/* ========= end header generated by ./mkh ========= */
|
||||
/*
|
||||
= #define REG_NOMATCH 1
|
||||
= #define REG_BADPAT 2
|
||||
= #define REG_ECOLLATE 3
|
||||
= #define REG_ECTYPE 4
|
||||
= #define REG_EESCAPE 5
|
||||
= #define REG_ESUBREG 6
|
||||
= #define REG_EBRACK 7
|
||||
= #define REG_EPAREN 8
|
||||
= #define REG_EBRACE 9
|
||||
= #define REG_BADBR 10
|
||||
= #define REG_ERANGE 11
|
||||
= #define REG_ESPACE 12
|
||||
= #define REG_BADRPT 13
|
||||
= #define REG_EMPTY 14
|
||||
= #define REG_ASSERT 15
|
||||
= #define REG_INVARG 16
|
||||
= #define REG_ATOI 255 // convert name to number (!)
|
||||
= #define REG_ITOA 0400 // convert number to name (!)
|
||||
*/
|
||||
static struct rerr {
|
||||
int code;
|
||||
char *name;
|
||||
char *explain;
|
||||
} rerrs[] = {
|
||||
{REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match"},
|
||||
{REG_BADPAT, "REG_BADPAT", "invalid regular expression"},
|
||||
{REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element"},
|
||||
{REG_ECTYPE, "REG_ECTYPE", "invalid character class"},
|
||||
{REG_EESCAPE, "REG_EESCAPE", "trailing backslash (\\)"},
|
||||
{REG_ESUBREG, "REG_ESUBREG", "invalid backreference number"},
|
||||
{REG_EBRACK, "REG_EBRACK", "brackets ([ ]) not balanced"},
|
||||
{REG_EPAREN, "REG_EPAREN", "parentheses not balanced"},
|
||||
{REG_EBRACE, "REG_EBRACE", "braces not balanced"},
|
||||
{REG_BADBR, "REG_BADBR", "invalid repetition count(s)"},
|
||||
{REG_ERANGE, "REG_ERANGE", "invalid character range"},
|
||||
{REG_ESPACE, "REG_ESPACE", "out of memory"},
|
||||
{REG_BADRPT, "REG_BADRPT", "repetition-operator operand invalid"},
|
||||
{REG_EMPTY, "REG_EMPTY", "empty (sub)expression"},
|
||||
{REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug"},
|
||||
{REG_INVARG, "REG_INVARG", "invalid argument to regex routine"},
|
||||
{0, "", "*** unknown regexp error code ***"}
|
||||
};
|
||||
|
||||
/*
|
||||
- regerror - the interface to error numbers
|
||||
= extern size_t regerror(int, const regex_t *, char *, size_t);
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
size_t
|
||||
regerror(errcode, preg, errbuf, errbuf_size)
|
||||
int errcode;
|
||||
const regex_t *preg;
|
||||
char *errbuf;
|
||||
size_t errbuf_size;
|
||||
{
|
||||
struct rerr *r;
|
||||
size_t len;
|
||||
int target = errcode &~ REG_ITOA;
|
||||
char *s;
|
||||
char convbuf[50];
|
||||
|
||||
if (errcode == REG_ATOI)
|
||||
s = regatoi(preg, convbuf);
|
||||
else {
|
||||
for (r = rerrs; r->code != 0; r++)
|
||||
if (r->code == target)
|
||||
break;
|
||||
|
||||
if (errcode®_ITOA) {
|
||||
if (r->code != 0)
|
||||
(void) strcpy(convbuf, r->name);
|
||||
else
|
||||
sprintf(convbuf, "REG_0x%x", target);
|
||||
assert(strlen(convbuf) < sizeof(convbuf));
|
||||
s = convbuf;
|
||||
} else
|
||||
s = r->explain;
|
||||
}
|
||||
|
||||
len = strlen(s) + 1;
|
||||
if (errbuf_size > 0) {
|
||||
if (errbuf_size > len)
|
||||
(void) strcpy(errbuf, s);
|
||||
else {
|
||||
(void) strncpy(errbuf, s, errbuf_size-1);
|
||||
errbuf[errbuf_size-1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return(len);
|
||||
}
|
||||
|
||||
/*
|
||||
- regatoi - internal routine to implement REG_ATOI
|
||||
== static char *regatoi(const regex_t *preg, char *localbuf);
|
||||
*/
|
||||
static char *
|
||||
regatoi(preg, localbuf)
|
||||
const regex_t *preg;
|
||||
char *localbuf;
|
||||
{
|
||||
struct rerr *r;
|
||||
|
||||
for (r = rerrs; r->code != 0; r++)
|
||||
if (strcmp(r->name, preg->re_endp) == 0)
|
||||
break;
|
||||
if (r->code == 0)
|
||||
return("0");
|
||||
|
||||
sprintf(localbuf, "%d", r->code);
|
||||
return(localbuf);
|
||||
}
|
@ -1,701 +0,0 @@
|
||||
.\" Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
.\" Copyright (c) 1992, 1993, 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Henry Spencer.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. All advertising materials mentioning features or use of this software
|
||||
.\" must display the following acknowledgement:
|
||||
.\" This product includes software developed by the University of
|
||||
.\" California, Berkeley and its contributors.
|
||||
.\" 4. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)regex.3 8.4 (Berkeley) 3/20/94
|
||||
.\" $FreeBSD: src/lib/libc/regex/regex.3,v 1.9 2001/10/01 16:08:58 ru Exp $
|
||||
.\"
|
||||
.Dd March 20, 1994
|
||||
.Dt REGEX 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm regcomp ,
|
||||
.Nm regexec ,
|
||||
.Nm regerror ,
|
||||
.Nm regfree
|
||||
.Nd regular-expression library
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In sys/types.h
|
||||
.In regex.h
|
||||
.Ft int
|
||||
.Fn regcomp "regex_t *preg" "const char *pattern" "int cflags"
|
||||
.Ft int
|
||||
.Fo regexec
|
||||
.Fa "const regex_t *preg" "const char *string"
|
||||
.Fa "size_t nmatch" "regmatch_t pmatch[]" "int eflags"
|
||||
.Fc
|
||||
.Ft size_t
|
||||
.Fo regerror
|
||||
.Fa "int errcode" "const regex_t *preg"
|
||||
.Fa "char *errbuf" "size_t errbuf_size"
|
||||
.Fc
|
||||
.Ft void
|
||||
.Fn regfree "regex_t *preg"
|
||||
.Sh DESCRIPTION
|
||||
These routines implement
|
||||
.St -p1003.2
|
||||
regular expressions
|
||||
.Pq Do RE Dc Ns s ;
|
||||
see
|
||||
.Xr re_format 7 .
|
||||
.Fn Regcomp
|
||||
compiles an RE written as a string into an internal form,
|
||||
.Fn regexec
|
||||
matches that internal form against a string and reports results,
|
||||
.Fn regerror
|
||||
transforms error codes from either into human-readable messages,
|
||||
and
|
||||
.Fn regfree
|
||||
frees any dynamically-allocated storage used by the internal form
|
||||
of an RE.
|
||||
.Pp
|
||||
The header
|
||||
.Aq Pa regex.h
|
||||
declares two structure types,
|
||||
.Ft regex_t
|
||||
and
|
||||
.Ft regmatch_t ,
|
||||
the former for compiled internal forms and the latter for match reporting.
|
||||
It also declares the four functions,
|
||||
a type
|
||||
.Ft regoff_t ,
|
||||
and a number of constants with names starting with
|
||||
.Dq Dv REG_ .
|
||||
.Pp
|
||||
.Fn Regcomp
|
||||
compiles the regular expression contained in the
|
||||
.Fa pattern
|
||||
string,
|
||||
subject to the flags in
|
||||
.Fa cflags ,
|
||||
and places the results in the
|
||||
.Ft regex_t
|
||||
structure pointed to by
|
||||
.Fa preg .
|
||||
.Fa Cflags
|
||||
is the bitwise OR of zero or more of the following flags:
|
||||
.Bl -tag -width REG_EXTENDED
|
||||
.It Dv REG_EXTENDED
|
||||
Compile modern
|
||||
.Pq Dq extended
|
||||
REs,
|
||||
rather than the obsolete
|
||||
.Pq Dq basic
|
||||
REs that
|
||||
are the default.
|
||||
.It Dv REG_BASIC
|
||||
This is a synonym for 0,
|
||||
provided as a counterpart to
|
||||
.Dv REG_EXTENDED
|
||||
to improve readability.
|
||||
.It Dv REG_NOSPEC
|
||||
Compile with recognition of all special characters turned off.
|
||||
All characters are thus considered ordinary,
|
||||
so the
|
||||
.Dq RE
|
||||
is a literal string.
|
||||
This is an extension,
|
||||
compatible with but not specified by
|
||||
.St -p1003.2 ,
|
||||
and should be used with
|
||||
caution in software intended to be portable to other systems.
|
||||
.Dv REG_EXTENDED
|
||||
and
|
||||
.Dv REG_NOSPEC
|
||||
may not be used
|
||||
in the same call to
|
||||
.Fn regcomp .
|
||||
.It Dv REG_ICASE
|
||||
Compile for matching that ignores upper/lower case distinctions.
|
||||
See
|
||||
.Xr re_format 7 .
|
||||
.It Dv REG_NOSUB
|
||||
Compile for matching that need only report success or failure,
|
||||
not what was matched.
|
||||
.It Dv REG_NEWLINE
|
||||
Compile for newline-sensitive matching.
|
||||
By default, newline is a completely ordinary character with no special
|
||||
meaning in either REs or strings.
|
||||
With this flag,
|
||||
.Ql [^
|
||||
bracket expressions and
|
||||
.Ql .\&
|
||||
never match newline,
|
||||
a
|
||||
.Ql ^\&
|
||||
anchor matches the null string after any newline in the string
|
||||
in addition to its normal function,
|
||||
and the
|
||||
.Ql $\&
|
||||
anchor matches the null string before any newline in the
|
||||
string in addition to its normal function.
|
||||
.It Dv REG_PEND
|
||||
The regular expression ends,
|
||||
not at the first NUL,
|
||||
but just before the character pointed to by the
|
||||
.Va re_endp
|
||||
member of the structure pointed to by
|
||||
.Fa preg .
|
||||
The
|
||||
.Va re_endp
|
||||
member is of type
|
||||
.Ft "const char *" .
|
||||
This flag permits inclusion of NULs in the RE;
|
||||
they are considered ordinary characters.
|
||||
This is an extension,
|
||||
compatible with but not specified by
|
||||
.St -p1003.2 ,
|
||||
and should be used with
|
||||
caution in software intended to be portable to other systems.
|
||||
.El
|
||||
.Pp
|
||||
When successful,
|
||||
.Fn regcomp
|
||||
returns 0 and fills in the structure pointed to by
|
||||
.Fa preg .
|
||||
One member of that structure
|
||||
(other than
|
||||
.Va re_endp )
|
||||
is publicized:
|
||||
.Va re_nsub ,
|
||||
of type
|
||||
.Ft size_t ,
|
||||
contains the number of parenthesized subexpressions within the RE
|
||||
(except that the value of this member is undefined if the
|
||||
.Dv REG_NOSUB
|
||||
flag was used).
|
||||
If
|
||||
.Fn regcomp
|
||||
fails, it returns a non-zero error code;
|
||||
see
|
||||
.Sx DIAGNOSTICS .
|
||||
.Pp
|
||||
.Fn Regexec
|
||||
matches the compiled RE pointed to by
|
||||
.Fa preg
|
||||
against the
|
||||
.Fa string ,
|
||||
subject to the flags in
|
||||
.Fa eflags ,
|
||||
and reports results using
|
||||
.Fa nmatch ,
|
||||
.Fa pmatch ,
|
||||
and the returned value.
|
||||
The RE must have been compiled by a previous invocation of
|
||||
.Fn regcomp .
|
||||
The compiled form is not altered during execution of
|
||||
.Fn regexec ,
|
||||
so a single compiled RE can be used simultaneously by multiple threads.
|
||||
.Pp
|
||||
By default,
|
||||
the NUL-terminated string pointed to by
|
||||
.Fa string
|
||||
is considered to be the text of an entire line, minus any terminating
|
||||
newline.
|
||||
The
|
||||
.Fa eflags
|
||||
argument is the bitwise OR of zero or more of the following flags:
|
||||
.Bl -tag -width REG_STARTEND
|
||||
.It Dv REG_NOTBOL
|
||||
The first character of
|
||||
the string
|
||||
is not the beginning of a line, so the
|
||||
.Ql ^\&
|
||||
anchor should not match before it.
|
||||
This does not affect the behavior of newlines under
|
||||
.Dv REG_NEWLINE .
|
||||
.It Dv REG_NOTEOL
|
||||
The NUL terminating
|
||||
the string
|
||||
does not end a line, so the
|
||||
.Ql $\&
|
||||
anchor should not match before it.
|
||||
This does not affect the behavior of newlines under
|
||||
.Dv REG_NEWLINE .
|
||||
.It Dv REG_STARTEND
|
||||
The string is considered to start at
|
||||
.Fa string
|
||||
+
|
||||
.Fa pmatch Ns [0]. Ns Va rm_so
|
||||
and to have a terminating NUL located at
|
||||
.Fa string
|
||||
+
|
||||
.Fa pmatch Ns [0]. Ns Va rm_eo
|
||||
(there need not actually be a NUL at that location),
|
||||
regardless of the value of
|
||||
.Fa nmatch .
|
||||
See below for the definition of
|
||||
.Fa pmatch
|
||||
and
|
||||
.Fa nmatch .
|
||||
This is an extension,
|
||||
compatible with but not specified by
|
||||
.St -p1003.2 ,
|
||||
and should be used with
|
||||
caution in software intended to be portable to other systems.
|
||||
Note that a non-zero
|
||||
.Va rm_so
|
||||
does not imply
|
||||
.Dv REG_NOTBOL ;
|
||||
.Dv REG_STARTEND
|
||||
affects only the location of the string,
|
||||
not how it is matched.
|
||||
.El
|
||||
.Pp
|
||||
See
|
||||
.Xr re_format 7
|
||||
for a discussion of what is matched in situations where an RE or a
|
||||
portion thereof could match any of several substrings of
|
||||
.Fa string .
|
||||
.Pp
|
||||
Normally,
|
||||
.Fn regexec
|
||||
returns 0 for success and the non-zero code
|
||||
.Dv REG_NOMATCH
|
||||
for failure.
|
||||
Other non-zero error codes may be returned in exceptional situations;
|
||||
see
|
||||
.Sx DIAGNOSTICS .
|
||||
.Pp
|
||||
If
|
||||
.Dv REG_NOSUB
|
||||
was specified in the compilation of the RE,
|
||||
or if
|
||||
.Fa nmatch
|
||||
is 0,
|
||||
.Fn regexec
|
||||
ignores the
|
||||
.Fa pmatch
|
||||
argument (but see below for the case where
|
||||
.Dv REG_STARTEND
|
||||
is specified).
|
||||
Otherwise,
|
||||
.Fa pmatch
|
||||
points to an array of
|
||||
.Fa nmatch
|
||||
structures of type
|
||||
.Ft regmatch_t .
|
||||
Such a structure has at least the members
|
||||
.Va rm_so
|
||||
and
|
||||
.Va rm_eo ,
|
||||
both of type
|
||||
.Ft regoff_t
|
||||
(a signed arithmetic type at least as large as an
|
||||
.Ft off_t
|
||||
and a
|
||||
.Ft ssize_t ) ,
|
||||
containing respectively the offset of the first character of a substring
|
||||
and the offset of the first character after the end of the substring.
|
||||
Offsets are measured from the beginning of the
|
||||
.Fa string
|
||||
argument given to
|
||||
.Fn regexec .
|
||||
An empty substring is denoted by equal offsets,
|
||||
both indicating the character following the empty substring.
|
||||
.Pp
|
||||
The 0th member of the
|
||||
.Fa pmatch
|
||||
array is filled in to indicate what substring of
|
||||
.Fa string
|
||||
was matched by the entire RE.
|
||||
Remaining members report what substring was matched by parenthesized
|
||||
subexpressions within the RE;
|
||||
member
|
||||
.Va i
|
||||
reports subexpression
|
||||
.Va i ,
|
||||
with subexpressions counted (starting at 1) by the order of their opening
|
||||
parentheses in the RE, left to right.
|
||||
Unused entries in the array (corresponding either to subexpressions that
|
||||
did not participate in the match at all, or to subexpressions that do not
|
||||
exist in the RE (that is,
|
||||
.Va i
|
||||
>
|
||||
.Fa preg Ns -> Ns Va re_nsub ) )
|
||||
have both
|
||||
.Va rm_so
|
||||
and
|
||||
.Va rm_eo
|
||||
set to -1.
|
||||
If a subexpression participated in the match several times,
|
||||
the reported substring is the last one it matched.
|
||||
(Note, as an example in particular, that when the RE
|
||||
.Ql "(b*)+"
|
||||
matches
|
||||
.Ql bbb ,
|
||||
the parenthesized subexpression matches each of the three
|
||||
.So Li b Sc Ns s
|
||||
and then
|
||||
an infinite number of empty strings following the last
|
||||
.Ql b ,
|
||||
so the reported substring is one of the empties.)
|
||||
.Pp
|
||||
If
|
||||
.Dv REG_STARTEND
|
||||
is specified,
|
||||
.Fa pmatch
|
||||
must point to at least one
|
||||
.Ft regmatch_t
|
||||
(even if
|
||||
.Fa nmatch
|
||||
is 0 or
|
||||
.Dv REG_NOSUB
|
||||
was specified),
|
||||
to hold the input offsets for
|
||||
.Dv REG_STARTEND .
|
||||
Use for output is still entirely controlled by
|
||||
.Fa nmatch ;
|
||||
if
|
||||
.Fa nmatch
|
||||
is 0 or
|
||||
.Dv REG_NOSUB
|
||||
was specified,
|
||||
the value of
|
||||
.Fa pmatch Ns [0]
|
||||
will not be changed by a successful
|
||||
.Fn regexec .
|
||||
.Pp
|
||||
.Fn Regerror
|
||||
maps a non-zero
|
||||
.Fa errcode
|
||||
from either
|
||||
.Fn regcomp
|
||||
or
|
||||
.Fn regexec
|
||||
to a human-readable, printable message.
|
||||
If
|
||||
.Fa preg
|
||||
is
|
||||
.No non\- Ns Dv NULL ,
|
||||
the error code should have arisen from use of
|
||||
the
|
||||
.Ft regex_t
|
||||
pointed to by
|
||||
.Fa preg ,
|
||||
and if the error code came from
|
||||
.Fn regcomp ,
|
||||
it should have been the result from the most recent
|
||||
.Fn regcomp
|
||||
using that
|
||||
.Ft regex_t .
|
||||
.No ( Fn Regerror
|
||||
may be able to supply a more detailed message using information
|
||||
from the
|
||||
.Ft regex_t . )
|
||||
.Fn Regerror
|
||||
places the NUL-terminated message into the buffer pointed to by
|
||||
.Fa errbuf ,
|
||||
limiting the length (including the NUL) to at most
|
||||
.Fa errbuf_size
|
||||
bytes.
|
||||
If the whole message won't fit,
|
||||
as much of it as will fit before the terminating NUL is supplied.
|
||||
In any case,
|
||||
the returned value is the size of buffer needed to hold the whole
|
||||
message (including terminating NUL).
|
||||
If
|
||||
.Fa errbuf_size
|
||||
is 0,
|
||||
.Fa errbuf
|
||||
is ignored but the return value is still correct.
|
||||
.Pp
|
||||
If the
|
||||
.Fa errcode
|
||||
given to
|
||||
.Fn regerror
|
||||
is first ORed with
|
||||
.Dv REG_ITOA ,
|
||||
the
|
||||
.Dq message
|
||||
that results is the printable name of the error code,
|
||||
e.g.\&
|
||||
.Dq Dv REG_NOMATCH ,
|
||||
rather than an explanation thereof.
|
||||
If
|
||||
.Fa errcode
|
||||
is
|
||||
.Dv REG_ATOI ,
|
||||
then
|
||||
.Fa preg
|
||||
shall be
|
||||
.No non\- Ns Dv NULL
|
||||
and the
|
||||
.Va re_endp
|
||||
member of the structure it points to
|
||||
must point to the printable name of an error code;
|
||||
in this case, the result in
|
||||
.Fa errbuf
|
||||
is the decimal digits of
|
||||
the numeric value of the error code
|
||||
(0 if the name is not recognized).
|
||||
.Dv REG_ITOA
|
||||
and
|
||||
.Dv REG_ATOI
|
||||
are intended primarily as debugging facilities;
|
||||
they are extensions,
|
||||
compatible with but not specified by
|
||||
.St -p1003.2 ,
|
||||
and should be used with
|
||||
caution in software intended to be portable to other systems.
|
||||
Be warned also that they are considered experimental and changes are possible.
|
||||
.Pp
|
||||
.Fn Regfree
|
||||
frees any dynamically-allocated storage associated with the compiled RE
|
||||
pointed to by
|
||||
.Fa preg .
|
||||
The remaining
|
||||
.Ft regex_t
|
||||
is no longer a valid compiled RE
|
||||
and the effect of supplying it to
|
||||
.Fn regexec
|
||||
or
|
||||
.Fn regerror
|
||||
is undefined.
|
||||
.Pp
|
||||
None of these functions references global variables except for tables
|
||||
of constants;
|
||||
all are safe for use from multiple threads if the arguments are safe.
|
||||
.Sh IMPLEMENTATION CHOICES
|
||||
There are a number of decisions that
|
||||
.St -p1003.2
|
||||
leaves up to the implementor,
|
||||
either by explicitly saying
|
||||
.Dq undefined
|
||||
or by virtue of them being
|
||||
forbidden by the RE grammar.
|
||||
This implementation treats them as follows.
|
||||
.Pp
|
||||
See
|
||||
.Xr re_format 7
|
||||
for a discussion of the definition of case-independent matching.
|
||||
.Pp
|
||||
There is no particular limit on the length of REs,
|
||||
except insofar as memory is limited.
|
||||
Memory usage is approximately linear in RE size, and largely insensitive
|
||||
to RE complexity, except for bounded repetitions.
|
||||
See
|
||||
.Sx BUGS
|
||||
for one short RE using them
|
||||
that will run almost any system out of memory.
|
||||
.Pp
|
||||
A backslashed character other than one specifically given a magic meaning
|
||||
by
|
||||
.St -p1003.2
|
||||
(such magic meanings occur only in obsolete
|
||||
.Bq Dq basic
|
||||
REs)
|
||||
is taken as an ordinary character.
|
||||
.Pp
|
||||
Any unmatched
|
||||
.Ql [\&
|
||||
is a
|
||||
.Dv REG_EBRACK
|
||||
error.
|
||||
.Pp
|
||||
Equivalence classes cannot begin or end bracket-expression ranges.
|
||||
The endpoint of one range cannot begin another.
|
||||
.Pp
|
||||
.Dv RE_DUP_MAX ,
|
||||
the limit on repetition counts in bounded repetitions, is 255.
|
||||
.Pp
|
||||
A repetition operator
|
||||
.Ql ( ?\& ,
|
||||
.Ql *\& ,
|
||||
.Ql +\& ,
|
||||
or bounds)
|
||||
cannot follow another
|
||||
repetition operator.
|
||||
A repetition operator cannot begin an expression or subexpression
|
||||
or follow
|
||||
.Ql ^\&
|
||||
or
|
||||
.Ql |\& .
|
||||
.Pp
|
||||
.Ql |\&
|
||||
cannot appear first or last in a (sub)expression or after another
|
||||
.Ql |\& ,
|
||||
i.e. an operand of
|
||||
.Ql |\&
|
||||
cannot be an empty subexpression.
|
||||
An empty parenthesized subexpression,
|
||||
.Ql "()" ,
|
||||
is legal and matches an
|
||||
empty (sub)string.
|
||||
An empty string is not a legal RE.
|
||||
.Pp
|
||||
A
|
||||
.Ql {\&
|
||||
followed by a digit is considered the beginning of bounds for a
|
||||
bounded repetition, which must then follow the syntax for bounds.
|
||||
A
|
||||
.Ql {\&
|
||||
.Em not
|
||||
followed by a digit is considered an ordinary character.
|
||||
.Pp
|
||||
.Ql ^\&
|
||||
and
|
||||
.Ql $\&
|
||||
beginning and ending subexpressions in obsolete
|
||||
.Pq Dq basic
|
||||
REs are anchors, not ordinary characters.
|
||||
.Sh SEE ALSO
|
||||
.Xr grep 1 ,
|
||||
.Xr re_format 7
|
||||
.Pp
|
||||
.St -p1003.2 ,
|
||||
sections 2.8 (Regular Expression Notation)
|
||||
and
|
||||
B.5 (C Binding for Regular Expression Matching).
|
||||
.Sh DIAGNOSTICS
|
||||
Non-zero error codes from
|
||||
.Fn regcomp
|
||||
and
|
||||
.Fn regexec
|
||||
include the following:
|
||||
.Pp
|
||||
.Bl -tag -width REG_ECOLLATE -compact
|
||||
.It Dv REG_NOMATCH
|
||||
.Fn regexec
|
||||
failed to match
|
||||
.It Dv REG_BADPAT
|
||||
invalid regular expression
|
||||
.It Dv REG_ECOLLATE
|
||||
invalid collating element
|
||||
.It Dv REG_ECTYPE
|
||||
invalid character class
|
||||
.It Dv REG_EESCAPE
|
||||
.Ql \e
|
||||
applied to unescapable character
|
||||
.It Dv REG_ESUBREG
|
||||
invalid backreference number
|
||||
.It Dv REG_EBRACK
|
||||
brackets
|
||||
.Ql "[ ]"
|
||||
not balanced
|
||||
.It Dv REG_EPAREN
|
||||
parentheses
|
||||
.Ql "( )"
|
||||
not balanced
|
||||
.It Dv REG_EBRACE
|
||||
braces
|
||||
.Ql "{ }"
|
||||
not balanced
|
||||
.It Dv REG_BADBR
|
||||
invalid repetition count(s) in
|
||||
.Ql "{ }"
|
||||
.It Dv REG_ERANGE
|
||||
invalid character range in
|
||||
.Ql "[ ]"
|
||||
.It Dv REG_ESPACE
|
||||
ran out of memory
|
||||
.It Dv REG_BADRPT
|
||||
.Ql ?\& ,
|
||||
.Ql *\& ,
|
||||
or
|
||||
.Ql +\&
|
||||
operand invalid
|
||||
.It Dv REG_EMPTY
|
||||
empty (sub)expression
|
||||
.It Dv REG_ASSERT
|
||||
can't happen - you found a bug
|
||||
.It Dv REG_INVARG
|
||||
invalid argument, e.g. negative-length string
|
||||
.El
|
||||
.Sh HISTORY
|
||||
Originally written by
|
||||
.An Henry Spencer .
|
||||
Altered for inclusion in the
|
||||
.Bx 4.4
|
||||
distribution.
|
||||
.Sh BUGS
|
||||
This is an alpha release with known defects.
|
||||
Please report problems.
|
||||
.Pp
|
||||
The back-reference code is subtle and doubts linger about its correctness
|
||||
in complex cases.
|
||||
.Pp
|
||||
.Fn Regexec
|
||||
performance is poor.
|
||||
This will improve with later releases.
|
||||
.Fa Nmatch
|
||||
exceeding 0 is expensive;
|
||||
.Fa nmatch
|
||||
exceeding 1 is worse.
|
||||
.Fn Regexec
|
||||
is largely insensitive to RE complexity
|
||||
.Em except
|
||||
that back
|
||||
references are massively expensive.
|
||||
RE length does matter; in particular, there is a strong speed bonus
|
||||
for keeping RE length under about 30 characters,
|
||||
with most special characters counting roughly double.
|
||||
.Pp
|
||||
.Fn Regcomp
|
||||
implements bounded repetitions by macro expansion,
|
||||
which is costly in time and space if counts are large
|
||||
or bounded repetitions are nested.
|
||||
An RE like, say,
|
||||
.Ql "((((a{1,100}){1,100}){1,100}){1,100}){1,100}"
|
||||
will (eventually) run almost any existing machine out of swap space.
|
||||
.Pp
|
||||
There are suspected problems with response to obscure error conditions.
|
||||
Notably,
|
||||
certain kinds of internal overflow,
|
||||
produced only by truly enormous REs or by multiply nested bounded repetitions,
|
||||
are probably not handled well.
|
||||
.Pp
|
||||
Due to a mistake in
|
||||
.St -p1003.2 ,
|
||||
things like
|
||||
.Ql "a)b"
|
||||
are legal REs because
|
||||
.Ql )\&
|
||||
is
|
||||
a special character only in the presence of a previous unmatched
|
||||
.Ql (\& .
|
||||
This can't be fixed until the spec is fixed.
|
||||
.Pp
|
||||
The standard's definition of back references is vague.
|
||||
For example, does
|
||||
.Ql "a\e(\e(b\e)*\e2\e)*d"
|
||||
match
|
||||
.Ql "abbbd" ?
|
||||
Until the standard is clarified,
|
||||
behavior in such cases should not be relied on.
|
||||
.Pp
|
||||
The implementation of word-boundary matching is a bit of a kludge,
|
||||
and bugs may lurk in combinations of word-boundary matching and anchoring.
|
@ -1,177 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)regex2.h 8.4 (Berkeley) 3/20/94
|
||||
* $FreeBSD: src/lib/libc/regex/regex2.h,v 1.6 2002/03/22 23:41:56 obrien Exp $
|
||||
*/
|
||||
|
||||
/*
|
||||
* First, the stuff that ends up in the outside-world include file
|
||||
= typedef off_t regoff_t;
|
||||
= typedef struct {
|
||||
= int re_magic;
|
||||
= size_t re_nsub; // number of parenthesized subexpressions
|
||||
= const char *re_endp; // end pointer for REG_PEND
|
||||
= struct re_guts *re_g; // none of your business :-)
|
||||
= } regex_t;
|
||||
= typedef struct {
|
||||
= regoff_t rm_so; // start of match
|
||||
= regoff_t rm_eo; // end of match
|
||||
= } regmatch_t;
|
||||
*/
|
||||
/*
|
||||
* internals of regex_t
|
||||
*/
|
||||
#define MAGIC1 ((('r'^0200)<<8) | 'e')
|
||||
|
||||
/*
|
||||
* The internal representation is a *strip*, a sequence of
|
||||
* operators ending with an endmarker. (Some terminology etc. is a
|
||||
* historical relic of earlier versions which used multiple strips.)
|
||||
* Certain oddities in the representation are there to permit running
|
||||
* the machinery backwards; in particular, any deviation from sequential
|
||||
* flow must be marked at both its source and its destination. Some
|
||||
* fine points:
|
||||
*
|
||||
* - OPLUS_ and O_PLUS are *inside* the loop they create.
|
||||
* - OQUEST_ and O_QUEST are *outside* the bypass they create.
|
||||
* - OCH_ and O_CH are *outside* the multi-way branch they create, while
|
||||
* OOR1 and OOR2 are respectively the end and the beginning of one of
|
||||
* the branches. Note that there is an implicit OOR2 following OCH_
|
||||
* and an implicit OOR1 preceding O_CH.
|
||||
*
|
||||
* In state representations, an operator's bit is on to signify a state
|
||||
* immediately *preceding* "execution" of that operator.
|
||||
*/
|
||||
typedef unsigned long sop; /* strip operator */
|
||||
typedef long sopno;
|
||||
#define OPRMASK 0xf8000000L
|
||||
#define OPDMASK 0x07ffffffL
|
||||
#define OPSHIFT ((unsigned)27)
|
||||
#define OP(n) ((n)&OPRMASK)
|
||||
#define OPND(n) ((n)&OPDMASK)
|
||||
#define SOP(op, opnd) ((op)|(opnd))
|
||||
/* operators meaning operand */
|
||||
/* (back, fwd are offsets) */
|
||||
#define OEND (1L<<OPSHIFT) /* endmarker - */
|
||||
#define OCHAR (2L<<OPSHIFT) /* character unsigned char */
|
||||
#define OBOL (3L<<OPSHIFT) /* left anchor - */
|
||||
#define OEOL (4L<<OPSHIFT) /* right anchor - */
|
||||
#define OANY (5L<<OPSHIFT) /* . - */
|
||||
#define OANYOF (6L<<OPSHIFT) /* [...] set number */
|
||||
#define OBACK_ (7L<<OPSHIFT) /* begin \d paren number */
|
||||
#define O_BACK (8L<<OPSHIFT) /* end \d paren number */
|
||||
#define OPLUS_ (9L<<OPSHIFT) /* + prefix fwd to suffix */
|
||||
#define O_PLUS (10L<<OPSHIFT) /* + suffix back to prefix */
|
||||
#define OQUEST_ (11L<<OPSHIFT) /* ? prefix fwd to suffix */
|
||||
#define O_QUEST (12L<<OPSHIFT) /* ? suffix back to prefix */
|
||||
#define OLPAREN (13L<<OPSHIFT) /* ( fwd to ) */
|
||||
#define ORPAREN (14L<<OPSHIFT) /* ) back to ( */
|
||||
#define OCH_ (15L<<OPSHIFT) /* begin choice fwd to OOR2 */
|
||||
#define OOR1 (16L<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
|
||||
#define OOR2 (17L<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
|
||||
#define O_CH (18L<<OPSHIFT) /* end choice back to OOR1 */
|
||||
#define OBOW (19L<<OPSHIFT) /* begin word - */
|
||||
#define OEOW (20L<<OPSHIFT) /* end word - */
|
||||
|
||||
/*
|
||||
* Structure for [] character-set representation. Character sets are
|
||||
* done as bit vectors, grouped 8 to a byte vector for compactness.
|
||||
* The individual set therefore has both a pointer to the byte vector
|
||||
* and a mask to pick out the relevant bit of each byte. A hash code
|
||||
* simplifies testing whether two sets could be identical.
|
||||
*
|
||||
* This will get trickier for multicharacter collating elements. As
|
||||
* preliminary hooks for dealing with such things, we also carry along
|
||||
* a string of multi-character elements, and decide the size of the
|
||||
* vectors at run time.
|
||||
*/
|
||||
typedef struct {
|
||||
uch *ptr; /* -> uch [csetsize] */
|
||||
uch mask; /* bit within array */
|
||||
short hash; /* hash code */
|
||||
size_t smultis;
|
||||
char *multis; /* -> char[smulti] ab\0cd\0ef\0\0 */
|
||||
} cset;
|
||||
/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
|
||||
#define CHadd(cs, c) ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (uch)(c))
|
||||
#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (uch)(c))
|
||||
#define CHIN(cs, c) ((cs)->ptr[(uch)(c)] & (cs)->mask)
|
||||
#define MCadd(p, cs, cp) mcadd(p, cs, cp) /* regcomp() internal fns */
|
||||
#define MCsub(p, cs, cp) mcsub(p, cs, cp)
|
||||
#define MCin(p, cs, cp) mcin(p, cs, cp)
|
||||
|
||||
/* stuff for character categories */
|
||||
typedef unsigned char cat_t;
|
||||
|
||||
/*
|
||||
* main compiled-expression structure
|
||||
*/
|
||||
struct re_guts {
|
||||
int magic;
|
||||
# define MAGIC2 ((('R'^0200)<<8)|'E')
|
||||
sop *strip; /* malloced area for strip */
|
||||
int csetsize; /* number of bits in a cset vector */
|
||||
int ncsets; /* number of csets in use */
|
||||
cset *sets; /* -> cset [ncsets] */
|
||||
uch *setbits; /* -> uch[csetsize][ncsets/CHAR_BIT] */
|
||||
int cflags; /* copy of regcomp() cflags argument */
|
||||
sopno nstates; /* = number of sops */
|
||||
sopno firststate; /* the initial OEND (normally 0) */
|
||||
sopno laststate; /* the final OEND */
|
||||
int iflags; /* internal flags */
|
||||
# define USEBOL 01 /* used ^ */
|
||||
# define USEEOL 02 /* used $ */
|
||||
# define BAD 04 /* something wrong */
|
||||
int nbol; /* number of ^ used */
|
||||
int neol; /* number of $ used */
|
||||
int ncategories; /* how many character categories */
|
||||
cat_t *categories; /* ->catspace[-CHAR_MIN] */
|
||||
char *must; /* match must contain this string */
|
||||
int moffset; /* latest point at which must may be located */
|
||||
int *charjump; /* Boyer-Moore char jump table */
|
||||
int *matchjump; /* Boyer-Moore match jump table */
|
||||
int mlen; /* length of must */
|
||||
size_t nsub; /* copy of re_nsub */
|
||||
int backrefs; /* does it use back references? */
|
||||
sopno nplus; /* how deep does it nest +s? */
|
||||
/* catspace must be last */
|
||||
cat_t catspace[1]; /* actually [NC] */
|
||||
};
|
||||
|
||||
/* misc utilities */
|
||||
#define OUT (CHAR_MAX+1) /* a non-character value */
|
||||
#define ISWORD(c) (isalnum((uch)(c)) || (c) == '_')
|
@ -1,182 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)regexec.c 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
/*
|
||||
* the outer shell of regexec()
|
||||
*
|
||||
* This file includes engine.c *twice*, after muchos fiddling with the
|
||||
* macros that code uses. This lets the same code operate on two different
|
||||
* representations for state sets.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "regex2.h"
|
||||
|
||||
static int nope = 0; /* for use in asserts; shuts lint up */
|
||||
|
||||
/* macros for manipulating states, small version */
|
||||
#define states long
|
||||
#define states1 states /* for later use in regexec() decision */
|
||||
#define CLEAR(v) ((v) = 0)
|
||||
#define SET0(v, n) ((v) &= ~((unsigned long)1 << (n)))
|
||||
#define SET1(v, n) ((v) |= (unsigned long)1 << (n))
|
||||
#define ISSET(v, n) (((v) & ((unsigned long)1 << (n))) != 0)
|
||||
#define ASSIGN(d, s) ((d) = (s))
|
||||
#define EQ(a, b) ((a) == (b))
|
||||
#define STATEVARS long dummy /* dummy version */
|
||||
#define STATESETUP(m, n) /* nothing */
|
||||
#define STATETEARDOWN(m) /* nothing */
|
||||
#define SETUP(v) ((v) = 0)
|
||||
#define onestate long
|
||||
#define INIT(o, n) ((o) = (unsigned long)1 << (n))
|
||||
#define INC(o) ((o) <<= 1)
|
||||
#define ISSTATEIN(v, o) (((v) & (o)) != 0)
|
||||
/* some abbreviations; note that some of these know variable names! */
|
||||
/* do "if I'm here, I can also be there" etc without branches */
|
||||
#define FWD(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) << (n))
|
||||
#define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n))
|
||||
#define ISSETBACK(v, n) (((v) & ((unsigned long)here >> (n))) != 0)
|
||||
/* function names */
|
||||
#define SNAMES /* engine.c looks after details */
|
||||
|
||||
#include "engine.c"
|
||||
|
||||
/* now undo things */
|
||||
#undef states
|
||||
#undef CLEAR
|
||||
#undef SET0
|
||||
#undef SET1
|
||||
#undef ISSET
|
||||
#undef ASSIGN
|
||||
#undef EQ
|
||||
#undef STATEVARS
|
||||
#undef STATESETUP
|
||||
#undef STATETEARDOWN
|
||||
#undef SETUP
|
||||
#undef onestate
|
||||
#undef INIT
|
||||
#undef INC
|
||||
#undef ISSTATEIN
|
||||
#undef FWD
|
||||
#undef BACK
|
||||
#undef ISSETBACK
|
||||
#undef SNAMES
|
||||
|
||||
/* macros for manipulating states, large version */
|
||||
#define states char *
|
||||
#define CLEAR(v) memset(v, 0, m->g->nstates)
|
||||
#define SET0(v, n) ((v)[n] = 0)
|
||||
#define SET1(v, n) ((v)[n] = 1)
|
||||
#define ISSET(v, n) ((v)[n])
|
||||
#define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
|
||||
#define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
|
||||
#define STATEVARS long vn; char *space
|
||||
#define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
|
||||
if ((m)->space == NULL) return(REG_ESPACE); \
|
||||
(m)->vn = 0; }
|
||||
#define STATETEARDOWN(m) { free((m)->space); }
|
||||
#define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
|
||||
#define onestate long
|
||||
#define INIT(o, n) ((o) = (n))
|
||||
#define INC(o) ((o)++)
|
||||
#define ISSTATEIN(v, o) ((v)[o])
|
||||
/* some abbreviations; note that some of these know variable names! */
|
||||
/* do "if I'm here, I can also be there" etc without branches */
|
||||
#define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
|
||||
#define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
|
||||
#define ISSETBACK(v, n) ((v)[here - (n)])
|
||||
/* function names */
|
||||
#define LNAMES /* flag */
|
||||
|
||||
#include "engine.c"
|
||||
|
||||
/*
|
||||
- regexec - interface for matching
|
||||
= extern int regexec(const regex_t *, const char *, size_t, \
|
||||
= regmatch_t [], int);
|
||||
= #define REG_NOTBOL 00001
|
||||
= #define REG_NOTEOL 00002
|
||||
= #define REG_STARTEND 00004
|
||||
= #define REG_TRACE 00400 // tracing of execution
|
||||
= #define REG_LARGE 01000 // force large representation
|
||||
= #define REG_BACKR 02000 // force use of backref code
|
||||
*
|
||||
* We put this here so we can exploit knowledge of the state representation
|
||||
* when choosing which matcher to call. Also, by this point the matchers
|
||||
* have been prototyped.
|
||||
*/
|
||||
int /* 0 success, REG_NOMATCH failure */
|
||||
regexec(preg, string, nmatch, pmatch, eflags)
|
||||
const regex_t *preg;
|
||||
const char *string;
|
||||
size_t nmatch;
|
||||
regmatch_t pmatch[];
|
||||
int eflags;
|
||||
{
|
||||
struct re_guts *g = preg->re_g;
|
||||
#ifdef REDEBUG
|
||||
# define GOODFLAGS(f) (f)
|
||||
#else
|
||||
# define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
|
||||
#endif
|
||||
|
||||
if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
|
||||
return(REG_BADPAT);
|
||||
assert(!(g->iflags&BAD));
|
||||
if (g->iflags&BAD) /* backstop for no-debug case */
|
||||
return(REG_BADPAT);
|
||||
eflags = GOODFLAGS(eflags);
|
||||
|
||||
if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE))
|
||||
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
|
||||
else
|
||||
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)regfree.c 8.3 (Berkeley) 3/20/94
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "regex2.h"
|
||||
|
||||
/*
|
||||
- regfree - free everything
|
||||
= extern void regfree(regex_t *);
|
||||
*/
|
||||
void
|
||||
regfree(preg)
|
||||
regex_t *preg;
|
||||
{
|
||||
struct re_guts *g;
|
||||
|
||||
if (preg->re_magic != MAGIC1) /* oops */
|
||||
return; /* nice to complain, but hard */
|
||||
|
||||
g = preg->re_g;
|
||||
if (g == NULL || g->magic != MAGIC2) /* oops again */
|
||||
return;
|
||||
preg->re_magic = 0; /* mark it invalid */
|
||||
g->magic = 0; /* mark it invalid */
|
||||
|
||||
if (g->strip != NULL)
|
||||
free((char *)g->strip);
|
||||
if (g->sets != NULL)
|
||||
free((char *)g->sets);
|
||||
if (g->setbits != NULL)
|
||||
free((char *)g->setbits);
|
||||
if (g->must != NULL)
|
||||
free(g->must);
|
||||
if (g->charjump != NULL)
|
||||
free(&g->charjump[CHAR_MIN]);
|
||||
if (g->matchjump != NULL)
|
||||
free(g->matchjump);
|
||||
free((char *)g);
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993, 1994 Henry Spencer.
|
||||
* Copyright (c) 1992, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Henry Spencer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)utils.h 8.3 (Berkeley) 3/20/94
|
||||
* $FreeBSD: src/lib/libc/regex/utils.h,v 1.2 2002/03/22 23:41:56 obrien Exp $
|
||||
*/
|
||||
|
||||
/* utility definitions */
|
||||
#define DUPMAX _POSIX2_RE_DUP_MAX /* xxx is this right? */
|
||||
#define INFINITY (DUPMAX + 1)
|
||||
#define NC (CHAR_MAX - CHAR_MIN + 1)
|
||||
typedef unsigned char uch;
|
||||
|
||||
/* switch off assertions (if not already off) if no REDEBUG */
|
||||
#ifndef REDEBUG
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG /* no assertions please */
|
||||
#endif
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
/* for old systems with bcopy() but no memmove() */
|
||||
#ifdef USEBCOPY
|
||||
#define memmove(d, s, c) bcopy(s, d, c)
|
||||
#endif
|
@ -1,186 +0,0 @@
|
||||
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <wordexp.h>
|
||||
|
||||
#define MAXLINELEN 500
|
||||
|
||||
/* Note: This implementation of wordexp requires a version of bash
|
||||
that supports the --wordexp and --protected arguments to be present
|
||||
on the system. It does not support the WRDE_UNDEF flag. */
|
||||
int
|
||||
wordexp(const char *words, wordexp_t *pwordexp, int flags)
|
||||
{
|
||||
FILE *f;
|
||||
FILE *f_err;
|
||||
char tmp[MAXLINELEN];
|
||||
int i = 0;
|
||||
int offs = 0;
|
||||
char *iter;
|
||||
pid_t pid;
|
||||
int num_words = 0;
|
||||
int num_bytes = 0;
|
||||
int fd[2];
|
||||
int fd_err[2];
|
||||
int err = 0;
|
||||
|
||||
if (pwordexp == NULL)
|
||||
{
|
||||
return WRDE_NOSPACE;
|
||||
}
|
||||
|
||||
if (flags & WRDE_REUSE)
|
||||
wordfree(pwordexp);
|
||||
|
||||
if ((flags & WRDE_APPEND) == 0)
|
||||
{
|
||||
pwordexp->we_wordc = 0;
|
||||
pwordexp->we_wordv = NULL;
|
||||
}
|
||||
|
||||
if (flags & WRDE_DOOFFS)
|
||||
{
|
||||
offs = pwordexp->we_offs;
|
||||
|
||||
if(!(pwordexp->we_wordv = (char **)realloc(pwordexp->we_wordv, (pwordexp->we_wordc + offs + 1) * sizeof(char *))))
|
||||
return WRDE_NOSPACE;
|
||||
|
||||
for (i = 0; i < offs; i++)
|
||||
pwordexp->we_wordv[i] = NULL;
|
||||
}
|
||||
|
||||
pipe(fd);
|
||||
pipe(fd_err);
|
||||
pid = fork();
|
||||
|
||||
if (pid > 0)
|
||||
{
|
||||
/* In parent process. */
|
||||
|
||||
/* Close write end of parent's pipe. */
|
||||
close(fd[1]);
|
||||
close(fd_err[1]);
|
||||
|
||||
/* f_err is the standard error from the shell command. */
|
||||
f_err = fdopen(fd_err[0], "r");
|
||||
|
||||
/* Check for errors. */
|
||||
if (fgets(tmp, MAXLINELEN, f_err))
|
||||
{
|
||||
if (strstr(tmp, "EOF"))
|
||||
err = WRDE_SYNTAX;
|
||||
else if (strstr(tmp, "`\n'") || strstr(tmp, "`|'")
|
||||
|| strstr(tmp, "`&'") || strstr(tmp, "`;'")
|
||||
|| strstr(tmp, "`<'") || strstr(tmp, "`>'")
|
||||
|| strstr(tmp, "`('") || strstr(tmp, "`)'")
|
||||
|| strstr(tmp, "`{'") || strstr(tmp, "`}'"))
|
||||
err = WRDE_BADCHAR;
|
||||
else if (strstr(tmp, "command substitution"))
|
||||
err = WRDE_CMDSUB;
|
||||
else
|
||||
err = WRDE_SYNTAX;
|
||||
|
||||
if (flags & WRDE_SHOWERR)
|
||||
{
|
||||
fprintf(stderr, tmp);
|
||||
while(fgets(tmp, MAXLINELEN, f_err))
|
||||
fprintf(stderr, tmp);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/* f is the standard output from the shell command. */
|
||||
f = fdopen(fd[0], "r");
|
||||
|
||||
/* Get number of words expanded by shell. */
|
||||
fgets(tmp, MAXLINELEN, f);
|
||||
|
||||
if((iter = strchr(tmp, '\n')))
|
||||
*iter = '\0';
|
||||
|
||||
num_words = atoi(tmp);
|
||||
|
||||
if(!(pwordexp->we_wordv = (char **)realloc(pwordexp->we_wordv,
|
||||
(pwordexp->we_wordc + num_words + offs + 1) * sizeof(char *))))
|
||||
return WRDE_NOSPACE;
|
||||
|
||||
/* Get number of bytes required for storage of num_words words. */
|
||||
fgets(tmp, MAXLINELEN, f);
|
||||
|
||||
if((iter = strchr(tmp, '\n')))
|
||||
*iter = '\0';
|
||||
|
||||
num_bytes = atoi(tmp) + pwordexp->we_wordc;
|
||||
|
||||
/* Get each expansion from the shell output, and store each in
|
||||
pwordexp's we_wordv vector. */
|
||||
for(i = 0; i < num_words; i++)
|
||||
{
|
||||
fgets(tmp, MAXLINELEN, f);
|
||||
|
||||
if((iter = strchr(tmp, '\n')))
|
||||
*iter = '\0';
|
||||
|
||||
pwordexp->we_wordv[pwordexp->we_wordc + offs + i] = strdup(tmp);
|
||||
}
|
||||
|
||||
pwordexp->we_wordv[pwordexp->we_wordc + offs + i] = NULL;
|
||||
pwordexp->we_wordc += num_words;
|
||||
|
||||
close(fd[0]);
|
||||
close(fd_err[0]);
|
||||
|
||||
/* Wait for child to finish. */
|
||||
waitpid (pid, NULL, 0);
|
||||
|
||||
return WRDE_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* In child process. */
|
||||
|
||||
/* Close read end of child's pipe. */
|
||||
close(fd[0]);
|
||||
close(fd_err[0]);
|
||||
|
||||
/* Pipe standard output to parent process via fd. */
|
||||
if (fd[1] != STDOUT_FILENO)
|
||||
{
|
||||
dup2(fd[1], STDOUT_FILENO);
|
||||
/* fd[1] no longer required. */
|
||||
close(fd[1]);
|
||||
}
|
||||
|
||||
/* Pipe standard error to parent process via fd_err. */
|
||||
if (fd_err[1] != STDERR_FILENO)
|
||||
{
|
||||
dup2(fd_err[1], STDERR_FILENO);
|
||||
/* fd_err[1] no longer required. */
|
||||
close(fd_err[1]);
|
||||
}
|
||||
|
||||
if (flags & WRDE_NOCMD)
|
||||
execl("/bin/bash", "bash", "--protected", "--wordexp", words, (char *)0);
|
||||
else
|
||||
execl("/bin/bash", "bash", "--wordexp", words, (char *)0);
|
||||
}
|
||||
return WRDE_SUCCESS;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* is freely granted, provided that this notice is preserved.
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wordexp.h>
|
||||
|
||||
void
|
||||
wordfree(wordexp_t *pwordexp)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (pwordexp == NULL)
|
||||
return;
|
||||
|
||||
if (pwordexp->we_wordv == NULL)
|
||||
return;
|
||||
|
||||
for(i = 0; i < pwordexp->we_wordc; i++)
|
||||
free(pwordexp->we_wordv[i]);
|
||||
|
||||
free(pwordexp->we_wordv);
|
||||
pwordexp->we_wordv = NULL;
|
||||
}
|
Reference in New Issue
Block a user