* Makefile.in (VPATH): Add regex directory.

(NM): new variable.
(OBSOLETE_FUNCTIONS): Ditto.
(NEW_FUNCTIONS): Ditto.
(install-headers): Install regex.h.
(install-man): New target.
(install): Use new target.
(DLL_OFILES): Add v8_reg* stuff.
(new-cygwin1.dll): Eliminate stamp-cygwin-lib creation.
(libcygwin.a): Remove obsolete functions from import lib.  Add new functions.
* configure.in: Detect 'nm' tool.
* configure: Regenerate.
* cygwin.din: Export posix_reg* functions.  Eliminate export of v8 reg*
functions.  This is now handled in object files themselves.
* regex/*: New files.
* regexp/v8_*.c: New files, renamed from non v8_ equivalents.
This commit is contained in:
Christopher Faylor 2001-12-20 02:55:11 +00:00
parent 1f93c55ff7
commit 48beacf6e4
28 changed files with 4869 additions and 75 deletions

View File

@ -1,3 +1,22 @@
2001-12-19 Christopher Faylor <cgf@redhat.com>
* Makefile.in (VPATH): Add regex directory.
(NM): new variable.
(OBSOLETE_FUNCTIONS): Ditto.
(NEW_FUNCTIONS): Ditto.
(install-headers): Install regex.h.
(install-man): New target.
(install): Use new target.
(DLL_OFILES): Add v8_reg* stuff.
(new-cygwin1.dll): Eliminate stamp-cygwin-lib creation.
(libcygwin.a): Remove obsolete functions from import lib. Add new functions.
* configure.in: Detect 'nm' tool.
* configure: Regenerate.
* cygwin.din: Export posix_reg* functions. Eliminate export of v8 reg* functions.
This is now handled in object files themselves.
* regex/*: New files.
* regexp/v8_*.c: New files, renamed from non v8_ equivalents.
2001-12-17 Corinna Vinschen <corinna@vinschen.de> 2001-12-17 Corinna Vinschen <corinna@vinschen.de>
* include/getopt.h: Don't define getopt_long() and friends when * include/getopt.h: Don't define getopt_long() and friends when

View File

@ -14,7 +14,7 @@ srcdir:=@srcdir@
objdir:=. objdir:=.
CONFIG_DIR:=$(srcdir)/config/@CONFIG_DIR@ CONFIG_DIR:=$(srcdir)/config/@CONFIG_DIR@
VPATH:=$(srcdir):$(CONFIG_DIR):$(srcdir)/regexp:$(srcdir)/lib VPATH:=$(srcdir):$(CONFIG_DIR):$(srcdir)/regex:$(srcdir)/regexp:$(srcdir)/lib
target_alias:=@target_alias@ target_alias:=@target_alias@
build_alias:=@build_alias@ build_alias:=@build_alias@
@ -44,8 +44,8 @@ INSTALL_PROGRAM:=@INSTALL_PROGRAM@
# #
# --enable options from configure # --enable options from configure
# #
MT_SAFE = @MT_SAFE@ MT_SAFE:=@MT_SAFE@
DEFS = @DEFS@ DEFS:=@DEFS@
CC:=@CC@ CC:=@CC@
# FIXME: Which is it, CC or CC_FOR_TARGET? # FIXME: Which is it, CC or CC_FOR_TARGET?
@ -65,7 +65,8 @@ LD:=@LD@
DLLTOOL:=@DLLTOOL@ DLLTOOL:=@DLLTOOL@
WINDRES:=@WINDRES@ WINDRES:=@WINDRES@
AS:=@AS@ AS:=@AS@
LDSCRIPT=cygwin.sc NM:=@NM@
LDSCRIPT:=cygwin.sc
# #
# Include common definitions for winsup directory # Include common definitions for winsup directory
@ -124,14 +125,21 @@ DLL_OFILES:=assert.o autoload.o cygheap.o dcrt0.o debug.o delqueue.o dir.o \
fhandler_tape.o fhandler_termios.o fhandler_tty.o fhandler_windows.o \ fhandler_tape.o fhandler_termios.o fhandler_tty.o fhandler_windows.o \
fhandler_zero.o fork.o glob.o grp.o heap.o init.o ioctl.o localtime.o \ fhandler_zero.o fork.o glob.o grp.o heap.o init.o ioctl.o localtime.o \
malloc.o miscfuncs.o mmap.o net.o ntea.o passwd.o path.o pinfo.o pipe.o \ malloc.o miscfuncs.o mmap.o net.o ntea.o passwd.o path.o pinfo.o pipe.o \
poll.o pthread.o regexp.o regerror.o regsub.o registry.o resource.o \ poll.o pthread.o regcomp.o regerror.o regexec.o regfree.o registry.o \
scandir.o sched.o sec_acl.o sec_helper.o security.o select.o shared.o \ resource.o scandir.o sched.o sec_acl.o sec_helper.o security.o \
shortcut.o signal.o sigproc.o smallprint.o spawn.o strace.o strsep.o \ select.o shared.o shortcut.o signal.o sigproc.o smallprint.o spawn.o \
sync.o syscalls.o sysconf.o syslog.o termios.o thread.o times.o tty.o \ strace.o strsep.o sync.o syscalls.o sysconf.o syslog.o termios.o \
uinfo.o uname.o wait.o wincap.o window.o \ thread.o times.o tty.o uinfo.o uname.o v8_regexp.o v8_regerror.o \
v8_regsub.o wait.o wincap.o window.o \
$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MALLOC_OFILES) $(MT_SAFE_OBJECTS) $(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MALLOC_OFILES) $(MT_SAFE_OBJECTS)
GMON_OFILES:= gmon.o mcount.o profil.o GMON_OFILES:=gmon.o mcount.o profil.o
OBSOLETE_FUNCTIONS:=regcomp regerror regexec regfree regsub
NEW_FUNCTIONS:=regcomp posix_regcomp \
regerror posix_regerror \
regexec posix_regexec \
regfree posix_regfree
.PHONY: all force dll_ofiles install all_target install_target all_host install_host \ .PHONY: all force dll_ofiles install all_target install_target all_host install_host \
install install_target install-libs install-headers install install_target install-libs install-headers
@ -150,7 +158,7 @@ all_host: new-$(LIB_NAME) cygrun.exe
force: force:
install: install-libs install-headers $(install_host) $(install_target) install: install-libs install-headers install-man $(install_host) $(install_target)
install-libs: $(LIB_NAME) install-libs: $(LIB_NAME)
$(INSTALL_DATA) new-$(DLL_NAME) $(bindir)/$(DLL_NAME); \ $(INSTALL_DATA) new-$(DLL_NAME) $(bindir)/$(DLL_NAME); \
@ -165,22 +173,48 @@ install-headers:
$(INSTALL_DATA) $$i $(tooldir)/$$sub/`basename $$i` ; \ $(INSTALL_DATA) $$i $(tooldir)/$$sub/`basename $$i` ; \
done ; \ done ; \
done ; \ done ; \
$(INSTALL_DATA) regexp/regexp.h $(tooldir)/include/regexp.h $(INSTALL_DATA) regex/regex.h $(tooldir)/include/regex.h
install-man:
cd $(srcdir); \
for i in `find . -type f -name '*.2'`; do \
$(INSTALL_DATA) $$i $(tooldir)/man/man2/`basename $$i` ; \
done; \
for i in `find . -type f -name '*.3'`; do \
$(INSTALL_DATA) $$i $(tooldir)/man/man3/`basename $$i` ; \
done; \
for i in `find . -type f -name '*.5'`; do \
$(INSTALL_DATA) $$i $(tooldir)/man/man5/`basename $$i` ; \
done; \
for i in `find . -type f -name '*.7'`; do \
$(INSTALL_DATA) $$i $(tooldir)/man/man7/`basename $$i` ; \
done
install_host: install_host:
clean: clean:
-rm -f *.o *.dll *.a *.exp junk *.base version.cc regexp/*.o winver_stamp *.exe *.d -rm -f *.o *.dll *.a *.exp junk *.base version.cc regexp/*.o winver_stamp *.exe *.d *stamp*
maintainer-clean realclean: clean maintainer-clean realclean: clean
@echo "This command is intended for maintainers to use;" @echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild." @echo "it deletes files that may require special tools to rebuild."
-rm -fr configure -rm -fr configure
# Rule to build cygwin.dll
new-$(DLL_NAME): $(LDSCRIPT) $(DLL_OFILES) $(DEF_FILE) $(DLL_IMPORTS) $(LIBC) $(LIBM) Makefile winver_stamp
$(CXX) $(CXXFLAGS) -nostdlib -Wl,-T$(firstword $^) -Wl,--out-implib,cygdll.a -shared -o $@ \
-e $(DLL_ENTRY) $(DEF_FILE) $(DLL_OFILES) version.o winver.o \
$(DLL_IMPORTS) $(MALLOC_OBJ) $(LIBM) $(LIBC) \
-lstdc++ -lgcc -lshell32 -luuid
# Rule to build libcygwin.a # Rule to build libcygwin.a
$(LIB_NAME): rmsym newsym new-$(DLL_NAME) $(LIBCOS)
/bin/sh ${word 1,$^} ./cygdll.a $(NM) $(AR) $(RANLIB) $(OBSOLETE_FUNCTIONS) || exit 0
/bin/sh ${word 2,$^} ./cygdll.a $(AS) $(AR) $(RANLIB) $(NEW_FUNCTIONS) || exit 0
(echo create $(LIB_NAME); echo addmod $(LIBCOS); echo addlib cygdll.a; echo save) | $(AR) -M
# Rule to make stub library used by testsuite # Rule to make stub library used by testsuite
# dependency set to $(LIB_NAME) to accommodate make -j2. # dependency set to $(LIB_NAME) to accommodate make -j2.
# Otherwise dlltool gets confused. cgf (11-16-2000) # Otherwise dlltool gets confused. cgf (11-16-2000)
new-$(LIB_NAME): $(LIB_NAME) new-$(LIB_NAME): $(LIB_NAME)
@ -188,21 +222,6 @@ new-$(LIB_NAME): $(LIB_NAME)
$(AR) rcv new-templib.a $(LIBCOS) $(AR) rcv new-templib.a $(LIBCOS)
mv new-templib.a new-$(LIB_NAME) mv new-templib.a new-$(LIB_NAME)
# Rule to build cygwin.dll
new-$(DLL_NAME): $(LDSCRIPT) $(DLL_OFILES) $(DEF_FILE) $(DLL_IMPORTS) $(LIBC) $(LIBM) Makefile winver_stamp
$(CXX) $(CXXFLAGS) -nostdlib -Wl,-T$(firstword $^) -Wl,--out-implib,cygdll.a -shared -o $@ \
-e $(DLL_ENTRY) $(DEF_FILE) $(DLL_OFILES) version.o winver.o \
$(DLL_IMPORTS) $(MALLOC_OBJ) $(LIBM) $(LIBC) \
-lstdc++ -lgcc -lshell32 -luuid
@rm -f stamp-cygwin-lib
$(LIB_NAME): new-$(DLL_NAME) $(LIBCOS) stamp-cygwin-lib
(echo create $(LIB_NAME); echo addlib cygdll.a; echo addmod $(LIBCOS); echo save) | $(AR) -M
stamp-cygwin-lib:
@touch stamp-cygwin-lib
dll_ofiles: $(DLL_OFILES) dll_ofiles: $(DLL_OFILES)
$(LIBGMON_A): $(GMON_OFILES) $(GMON_START) $(LIBGMON_A): $(GMON_OFILES) $(GMON_START)

View File

@ -1274,10 +1274,77 @@ else
fi fi
fi fi
# Extract the first word of "${ac_tool_prefix}nm", so it can be a program name with args.
set dummy ${ac_tool_prefix}nm; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
echo "configure:1281: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_NM'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$NM"; then
ac_cv_prog_NM="$NM" # Let the user override the test.
else
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
ac_dummy="$PATH"
for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_NM="${ac_tool_prefix}nm"
break
fi
done
IFS="$ac_save_ifs"
fi
fi
NM="$ac_cv_prog_NM"
if test -n "$NM"; then
echo "$ac_t""$NM" 1>&6
else
echo "$ac_t""no" 1>&6
fi
if test -z "$ac_cv_prog_NM"; then
if test -n "$ac_tool_prefix"; then
# Extract the first word of "nm", so it can be a program name with args.
set dummy nm; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
echo "configure:1313: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_NM'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test -n "$NM"; then
ac_cv_prog_NM="$NM" # Let the user override the test.
else
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
ac_dummy="$PATH"
for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
if test -f $ac_dir/$ac_word; then
ac_cv_prog_NM="nm"
break
fi
done
IFS="$ac_save_ifs"
test -z "$ac_cv_prog_NM" && ac_cv_prog_NM="nm"
fi
fi
NM="$ac_cv_prog_NM"
if test -n "$NM"; then
echo "$ac_t""$NM" 1>&6
else
echo "$ac_t""no" 1>&6
fi
else
NM="nm"
fi
fi
# Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args.
set dummy ${ac_tool_prefix}dlltool; ac_word=$2 set dummy ${ac_tool_prefix}dlltool; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
echo "configure:1281: checking for $ac_word" >&5 echo "configure:1348: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_DLLTOOL'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_prog_DLLTOOL'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
@ -1309,7 +1376,7 @@ if test -n "$ac_tool_prefix"; then
# Extract the first word of "dlltool", so it can be a program name with args. # Extract the first word of "dlltool", so it can be a program name with args.
set dummy dlltool; ac_word=$2 set dummy dlltool; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
echo "configure:1313: checking for $ac_word" >&5 echo "configure:1380: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_DLLTOOL'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_prog_DLLTOOL'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
@ -1344,7 +1411,7 @@ fi
# Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args. # Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args.
set dummy ${ac_tool_prefix}windres; ac_word=$2 set dummy ${ac_tool_prefix}windres; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
echo "configure:1348: checking for $ac_word" >&5 echo "configure:1415: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_WINDRES'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_prog_WINDRES'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
@ -1376,7 +1443,7 @@ if test -n "$ac_tool_prefix"; then
# Extract the first word of "windres", so it can be a program name with args. # Extract the first word of "windres", so it can be a program name with args.
set dummy windres; ac_word=$2 set dummy windres; ac_word=$2
echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
echo "configure:1380: checking for $ac_word" >&5 echo "configure:1447: checking for $ac_word" >&5
if eval "test \"`echo '$''{'ac_cv_prog_WINDRES'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_prog_WINDRES'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
@ -1410,7 +1477,7 @@ fi
echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
echo "configure:1414: checking how to run the C preprocessor" >&5 echo "configure:1481: checking how to run the C preprocessor" >&5
# On Suns, sometimes $CPP names a directory. # On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then if test -n "$CPP" && test -d "$CPP"; then
CPP= CPP=
@ -1425,13 +1492,13 @@ else
# On the NeXT, cc -E runs the code through the compiler's parser, # On the NeXT, cc -E runs the code through the compiler's parser,
# not just through cpp. # not just through cpp.
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1429 "configure" #line 1496 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <assert.h> #include <assert.h>
Syntax Error Syntax Error
EOF EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:1435: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } { (eval echo configure:1502: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then if test -z "$ac_err"; then
: :
@ -1442,13 +1509,13 @@ else
rm -rf conftest* rm -rf conftest*
CPP="${CC-cc} -E -traditional-cpp" CPP="${CC-cc} -E -traditional-cpp"
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1446 "configure" #line 1513 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <assert.h> #include <assert.h>
Syntax Error Syntax Error
EOF EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:1452: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } { (eval echo configure:1519: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then if test -z "$ac_err"; then
: :
@ -1459,13 +1526,13 @@ else
rm -rf conftest* rm -rf conftest*
CPP="${CC-cc} -nologo -E" CPP="${CC-cc} -nologo -E"
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1463 "configure" #line 1530 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <assert.h> #include <assert.h>
Syntax Error Syntax Error
EOF EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:1469: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } { (eval echo configure:1536: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then if test -z "$ac_err"; then
: :
@ -1492,19 +1559,19 @@ echo "$ac_t""$CPP" 1>&6
# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
# for constant arguments. Useless! # for constant arguments. Useless!
echo $ac_n "checking for working alloca.h""... $ac_c" 1>&6 echo $ac_n "checking for working alloca.h""... $ac_c" 1>&6
echo "configure:1496: checking for working alloca.h" >&5 echo "configure:1563: checking for working alloca.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1501 "configure" #line 1568 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <alloca.h> #include <alloca.h>
int main() { int main() {
char *p = alloca(2 * sizeof(int)); char *p = alloca(2 * sizeof(int));
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:1508: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then if { (eval echo configure:1575: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest* rm -rf conftest*
ac_cv_header_alloca_h=yes ac_cv_header_alloca_h=yes
else else
@ -1525,12 +1592,12 @@ EOF
fi fi
echo $ac_n "checking for alloca""... $ac_c" 1>&6 echo $ac_n "checking for alloca""... $ac_c" 1>&6
echo "configure:1529: checking for alloca" >&5 echo "configure:1596: checking for alloca" >&5
if eval "test \"`echo '$''{'ac_cv_func_alloca_works'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_func_alloca_works'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1534 "configure" #line 1601 "configure"
#include "confdefs.h" #include "confdefs.h"
#ifdef __GNUC__ #ifdef __GNUC__
@ -1558,7 +1625,7 @@ int main() {
char *p = (char *) alloca(1); char *p = (char *) alloca(1);
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:1562: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then if { (eval echo configure:1629: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest* rm -rf conftest*
ac_cv_func_alloca_works=yes ac_cv_func_alloca_works=yes
else else
@ -1590,12 +1657,12 @@ EOF
echo $ac_n "checking whether alloca needs Cray hooks""... $ac_c" 1>&6 echo $ac_n "checking whether alloca needs Cray hooks""... $ac_c" 1>&6
echo "configure:1594: checking whether alloca needs Cray hooks" >&5 echo "configure:1661: checking whether alloca needs Cray hooks" >&5
if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1599 "configure" #line 1666 "configure"
#include "confdefs.h" #include "confdefs.h"
#if defined(CRAY) && ! defined(CRAY2) #if defined(CRAY) && ! defined(CRAY2)
webecray webecray
@ -1620,12 +1687,12 @@ echo "$ac_t""$ac_cv_os_cray" 1>&6
if test $ac_cv_os_cray = yes; then if test $ac_cv_os_cray = yes; then
for ac_func in _getb67 GETB67 getb67; do for ac_func in _getb67 GETB67 getb67; do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:1624: checking for $ac_func" >&5 echo "configure:1691: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1629 "configure" #line 1696 "configure"
#include "confdefs.h" #include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes, /* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */ which can conflict with char $ac_func(); below. */
@ -1648,7 +1715,7 @@ $ac_func();
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:1652: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then if { (eval echo configure:1719: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest* rm -rf conftest*
eval "ac_cv_func_$ac_func=yes" eval "ac_cv_func_$ac_func=yes"
else else
@ -1675,7 +1742,7 @@ done
fi fi
echo $ac_n "checking stack direction for C alloca""... $ac_c" 1>&6 echo $ac_n "checking stack direction for C alloca""... $ac_c" 1>&6
echo "configure:1679: checking stack direction for C alloca" >&5 echo "configure:1746: checking stack direction for C alloca" >&5
if eval "test \"`echo '$''{'ac_cv_c_stack_direction'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_c_stack_direction'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
@ -1683,7 +1750,7 @@ else
ac_cv_c_stack_direction=0 ac_cv_c_stack_direction=0
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1687 "configure" #line 1754 "configure"
#include "confdefs.h" #include "confdefs.h"
find_stack_direction () find_stack_direction ()
{ {
@ -1702,7 +1769,7 @@ main ()
exit (find_stack_direction() < 0); exit (find_stack_direction() < 0);
} }
EOF EOF
if { (eval echo configure:1706: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null if { (eval echo configure:1773: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then then
ac_cv_c_stack_direction=1 ac_cv_c_stack_direction=1
else else
@ -1724,7 +1791,7 @@ EOF
fi fi
echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6 echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
echo "configure:1728: checking whether ${MAKE-make} sets \${MAKE}" >&5 echo "configure:1795: checking whether ${MAKE-make} sets \${MAKE}" >&5
set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'` set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
@ -1761,7 +1828,7 @@ ac_link='${CXX-g++} -o conftest${ac_exeext} $CXXFLAGS $CPPFLAGS $LDFLAGS conftes
cross_compiling=$ac_cv_prog_cxx_cross cross_compiling=$ac_cv_prog_cxx_cross
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1765 "configure" #line 1832 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <string.h> #include <string.h>
@ -1774,7 +1841,7 @@ int main() {
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:1778: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then if { (eval echo configure:1845: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest* rm -rf conftest*
use_builtin_memset=yes use_builtin_memset=yes
else else
@ -1899,7 +1966,7 @@ esac
echo $ac_n "checking if newlib is part of the build tree""... $ac_c" 1>&6 echo $ac_n "checking if newlib is part of the build tree""... $ac_c" 1>&6
echo "configure:1903: checking if newlib is part of the build tree" >&5 echo "configure:1970: checking if newlib is part of the build tree" >&5
EXE_LDFLAGS= EXE_LDFLAGS=
if test -d ../newlib if test -d ../newlib
@ -1914,9 +1981,9 @@ fi
if test x"$EXE_LDFLAGS" = x if test x"$EXE_LDFLAGS" = x
then then
echo $ac_n "checking if installed newlib needed""... $ac_c" 1>&6 echo $ac_n "checking if installed newlib needed""... $ac_c" 1>&6
echo "configure:1918: checking if installed newlib needed" >&5 echo "configure:1985: checking if installed newlib needed" >&5
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 1920 "configure" #line 1987 "configure"
#include "confdefs.h" #include "confdefs.h"
int main() { int main() {
@ -1924,7 +1991,7 @@ int main() {
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:1928: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then if { (eval echo configure:1995: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest* rm -rf conftest*
echo "$ac_t""no" 1>&6 echo "$ac_t""no" 1>&6
@ -2115,6 +2182,7 @@ s%@AR@%$AR%g
s%@AS@%$AS%g s%@AS@%$AS%g
s%@RANLIB@%$RANLIB%g s%@RANLIB@%$RANLIB%g
s%@LD@%$LD%g s%@LD@%$LD%g
s%@NM@%$NM%g
s%@DLLTOOL@%$DLLTOOL%g s%@DLLTOOL@%$DLLTOOL%g
s%@WINDRES@%$WINDRES%g s%@WINDRES@%$WINDRES%g
s%@CPP@%$CPP%g s%@CPP@%$CPP%g

View File

@ -91,6 +91,8 @@ AC_CHECK_TOOL(RANLIB, ranlib, ranlib)
dnl C_SUBST(RANLIB) dnl C_SUBST(RANLIB)
AC_CHECK_TOOL(LD, ld, ld) AC_CHECK_TOOL(LD, ld, ld)
dnl C_SUBST(LD) dnl C_SUBST(LD)
AC_CHECK_TOOL(NM, nm, nm)
dnl C_SUBST(NM)
AC_CHECK_TOOL(DLLTOOL, dlltool, dlltool) AC_CHECK_TOOL(DLLTOOL, dlltool, dlltool)
dnl C_SUBST(DLLTOOL) dnl C_SUBST(DLLTOOL)
AC_CHECK_TOOL(WINDRES, windres, windres) AC_CHECK_TOOL(WINDRES, windres, windres)

View File

@ -594,16 +594,10 @@ readv
_readv = readv _readv = readv
realloc = export_realloc realloc = export_realloc
_realloc = export_realloc _realloc = export_realloc
regcomp posix_regcomp
_regcomp = regcomp posix_regerror
regexec posix_regexec
_regexec = regexec posix_regfree
regerror
_regerror = regerror
regfree
_regfree = regfree
regsub
_regsub = regsub
remainder remainder
_remainder = remainder _remainder = remainder
remainderf remainderf
@ -910,6 +904,7 @@ wctomb
_wctomb = wctomb _wctomb = wctomb
write write
_write = write _write = write
barfly = write
writev writev
_writev = writev _writev = writev
y0 y0

24
winsup/cygwin/newsym Executable file
View File

@ -0,0 +1,24 @@
#!/bin/sh -x
lib=$1; shift
as=$1; shift
ar=$1; shift
ranlib=$1; shift
rm -rf newsym.dir
trap "rm -rf newsym.dir" 0 1 2 15
mkdir newsym.dir
while [ -n "$1" ]; do
newsym=$1; shift
oldsym=$1; shift
cat <<EOF > newsym.dir/$newsym.s
.section .idata$6
.extern __imp__$oldsym
.extern __head_cygwin1_dll
.section .text
.global _$newsym
_$newsym:
jmp *__imp__$oldsym
EOF
$as -o newsym.dir/$newsym.o newsym.dir/$newsym.s
done
$ar cru $lib newsym.dir/*.o
$ranlib $lib

View File

@ -0,0 +1,20 @@
Copyright 1992, 1993, 1994, 1997 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.

View File

@ -0,0 +1,31 @@
/* character-class table */
static struct cclass {
const char *name;
const char *chars;
const char *multis;
} cclasses[] = {
{"alnum", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789", ""},
{"alpha", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
""},
{"blank", " \t", ""},
{"cntrl", "\007\b\t\n\v\f\r\1\2\3\4\5\6\16\17\20\21\22\23\24\
\25\26\27\30\31\32\33\34\35\36\37\177", ""},
{"digit", "0123456789", ""},
{"graph", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
""},
{"lower", "abcdefghijklmnopqrstuvwxyz",
""},
{"print", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ",
""},
{"punct", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
""},
{"space", "\t\n\v\f\r ", ""},
{"upper", "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
""},
{"xdigit", "0123456789ABCDEFabcdef",
""},
{NULL, 0, ""}
};

102
winsup/cygwin/regex/cname.h Normal file
View File

@ -0,0 +1,102 @@
/* character-name table */
static struct cname {
const 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}
};

1019
winsup/cygwin/regex/engine.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
/* === engine.c === */
static int matcher(register struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
static char *dissect(register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
static char *backref(register struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev);
static char *fast(register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
static char *slow(register struct match *m, char *start, char *stop, sopno startst, sopno stopst);
static states step(register struct re_guts *g, sopno start, sopno stop, register states bef, int ch, register states aft);
#define BOL (OUT+1)
#define EOL (BOL+1)
#define BOLEOL (BOL+2)
#define NOTHING (BOL+3)
#define BOW (BOL+4)
#define EOW (BOL+5)
#define CODEMAX (BOL+5) /* highest code used */
#define NONCHAR(c) ((c) > CHAR_MAX)
#define NNONCHAR (CODEMAX-CHAR_MAX)
#ifdef REDEBUG
static void print(struct match *m, char *caption, states st, int ch, FILE *d);
#endif
#ifdef REDEBUG
static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst);
#endif
#ifdef REDEBUG
static char *pchar(int ch);
#endif
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */

76
winsup/cygwin/regex/mkh Executable file
View File

@ -0,0 +1,76 @@
#! /bin/sh
# mkh - pull headers out of C source
PATH=/bin:/usr/bin ; export PATH
# egrep pattern to pick out marked lines
egrep='^ =([ ]|$)'
# Sed program to process marked lines into lines for the header file.
# The markers have already been removed. Two things are done here: removal
# of backslashed newlines, and some fudging of comments. The first is done
# because -o needs to have prototypes on one line to strip them down.
# Getting comments into the output is tricky; we turn C++-style // comments
# into /* */ comments, after altering any existing */'s to avoid trouble.
peel=' /\\$/N
/\\\n[ ]*/s///g
/\/\//s;\*/;* /;g
/\/\//s;//\(.*\);/*\1 */;'
for a
do
case "$a" in
-o) # old (pre-function-prototype) compiler
# add code to comment out argument lists
peel="$peel
"'/^\([^#\/][^\/]*[a-zA-Z0-9_)]\)(\(.*\))/s;;\1(/*\2*/);'
shift
;;
-b) # funny Berkeley __P macro
peel="$peel
"'/^\([^#\/][^\/]*[a-zA-Z0-9_)]\)(\(.*\))/s;;\1 __P((\2));'
shift
;;
-s) # compiler doesn't like `static foo();'
# add code to get rid of the `static'
peel="$peel
"'/^static[ ][^\/]*[a-zA-Z0-9_)](.*)/s;static.;;'
shift
;;
-p) # private declarations
egrep='^ ==([ ]|$)'
shift
;;
-i) # wrap in #ifndef, argument is name
ifndef="$2"
shift ; shift
;;
*) break
;;
esac
done
if test " $ifndef" != " "
then
echo "#ifndef $ifndef"
echo "#define $ifndef /* never again */"
fi
echo "/* ========= begin header generated by $0 ========= */"
echo '#ifdef __cplusplus'
echo 'extern "C" {'
echo '#endif'
for f
do
echo
echo "/* === $f === */"
egrep "$egrep" $f | sed 's/^ ==*[ ]//;s/^ ==*$//' | sed "$peel"
echo
done
echo '#ifdef __cplusplus'
echo '}'
echo '#endif'
echo "/* ========= end header generated by $0 ========= */"
if test " $ifndef" != " "
then
echo "#endif"
fi
exit 0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,48 @@
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
/* === regcomp.c === */
static void p_ere(register struct parse *p, int stop);
static void p_ere_exp(register struct parse *p);
static void p_str(register struct parse *p);
static void p_bre(register struct parse *p, register int end1, register int end2);
static int p_simp_re(register struct parse *p, int starordinary);
static int p_count(register struct parse *p);
static void p_bracket(register struct parse *p);
static void p_b_term(register struct parse *p, register cset *cs);
static void p_b_cclass(register struct parse *p, register cset *cs);
static void p_b_eclass(register struct parse *p, register cset *cs);
static char p_b_symbol(register struct parse *p);
static char p_b_coll_elem(register struct parse *p, int endc);
static char othercase(int ch);
static void bothcases(register struct parse *p, int ch);
static void ordinary(register struct parse *p, register int ch);
static void nonnewline(register struct parse *p);
static void repeat(register struct parse *p, sopno start, int from, int to);
static int seterr(register struct parse *p, int e);
static cset *allocset(register struct parse *p);
static void freeset(register struct parse *p, register cset *cs);
static int freezeset(register struct parse *p, register cset *cs);
static int firstch(register struct parse *p, register cset *cs);
static int nch(register struct parse *p, register cset *cs);
static void mcadd(register struct parse *p, register cset *cs, register const char *cp);
static void mcinvert(register struct parse *p, register cset *cs);
static void mccase(register struct parse *p, register cset *cs);
static int isinsets(register struct re_guts *g, int c);
static int samesets(register struct re_guts *g, int c1, int c2);
static void categorize(struct parse *p, register struct re_guts *g);
static sopno dupl(register struct parse *p, sopno start, sopno finish);
static void doemit(register struct parse *p, sop op, size_t opnd);
static void doinsert(register struct parse *p, sop op, size_t opnd, sopno pos);
static void dofwd(register struct parse *p, sopno pos, sop value);
static void enlarge(register struct parse *p, sopno size);
static void stripsnug(register struct parse *p, register struct re_guts *g);
static void findmust(register struct parse *p, register struct re_guts *g);
static sopno pluscount(register struct parse *p, register struct re_guts *g);
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */

View File

@ -0,0 +1,127 @@
#include "winsup.h"
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include "regex.h"
#include "utils.h"
#include "regerror.ih"
/*
= #define REG_OKAY 0
= #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;
const char *name;
const char *explain;
} rerrs[] = {
{REG_OKAY, "REG_OKAY", "no errors detected"},
{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"},
{-1, "", "*** 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;
{
register struct rerr *r;
register size_t len;
register int target = errcode &~ REG_ITOA;
register const 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&REG_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 const char *
regatoi(preg, localbuf)
const regex_t *preg;
char *localbuf;
{
register 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);
}

View File

@ -0,0 +1,12 @@
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
/* === regerror.c === */
static const char *regatoi(const regex_t *preg, char *localbuf);
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */

509
winsup/cygwin/regex/regex.3 Normal file
View File

@ -0,0 +1,509 @@
.TH REGEX 3 "25 Sept 1997"
.BY "Henry Spencer"
.de ZR
.\" one other place knows this name: the SEE ALSO section
.IR regex (7) \\$1
..
.SH NAME
regcomp, regexec, regerror, regfree \- regular-expression library
.SH SYNOPSIS
.ft B
.\".na
#include <sys/types.h>
.br
#include <regex.h>
.HP 10
int regcomp(regex_t\ *preg, const\ char\ *pattern, int\ cflags);
.HP
int\ regexec(const\ regex_t\ *preg, const\ char\ *string,
size_t\ nmatch, regmatch_t\ pmatch[], int\ eflags);
.HP
size_t\ regerror(int\ errcode, const\ regex_t\ *preg,
char\ *errbuf, size_t\ errbuf_size);
.HP
void\ regfree(regex_t\ *preg);
.\".ad
.ft
.SH DESCRIPTION
These routines implement POSIX 1003.2 regular expressions (``RE''s);
see
.ZR .
.I Regcomp
compiles an RE written as a string into an internal form,
.I regexec
matches that internal form against a string and reports results,
.I regerror
transforms error codes from either into human-readable messages,
and
.I regfree
frees any dynamically-allocated storage used by the internal form
of an RE.
.PP
The header
.I <regex.h>
declares two structure types,
.I regex_t
and
.IR regmatch_t ,
the former for compiled internal forms and the latter for match reporting.
It also declares the four functions,
a type
.IR regoff_t ,
and a number of constants with names starting with ``REG_''.
.PP
.I Regcomp
compiles the regular expression contained in the
.I pattern
string,
subject to the flags in
.IR cflags ,
and places the results in the
.I regex_t
structure pointed to by
.IR preg .
.I Cflags
is the bitwise OR of zero or more of the following flags:
.IP REG_EXTENDED \w'REG_EXTENDED'u+2n
Compile modern (``extended'') REs,
rather than the obsolete (``basic'') REs that
are the default.
.IP REG_BASIC
This is a synonym for 0,
provided as a counterpart to REG_EXTENDED to improve readability.
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
.IP REG_NOSPEC
Compile with recognition of all special characters turned off.
All characters are thus considered ordinary,
so the ``RE'' is a literal string.
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
REG_EXTENDED and REG_NOSPEC may not be used
in the same call to
.IR regcomp .
.IP REG_ICASE
Compile for matching that ignores upper/lower case distinctions.
See
.ZR .
.IP REG_NOSUB
Compile for matching that need only report success or failure,
not what was matched.
.IP 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,
`[^' bracket expressions and `.' never match newline,
a `^' anchor matches the null string after any newline in the string
in addition to its normal function,
and the `$' anchor matches the null string before any newline in the
string in addition to its normal function.
.IP REG_PEND
The regular expression ends,
not at the first NUL,
but just before the character pointed to by the
.I re_endp
member of the structure pointed to by
.IR preg .
The
.I re_endp
member is of type
.IR 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 POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
.PP
When successful,
.I regcomp
returns 0 and fills in the structure pointed to by
.IR preg .
One member of that structure
(other than
.IR re_endp )
is publicized:
.IR re_nsub ,
of type
.IR size_t ,
contains the number of parenthesized subexpressions within the RE
(except that the value of this member is undefined if the
REG_NOSUB flag was used).
If
.I regcomp
fails, it returns a non-zero error code;
see DIAGNOSTICS.
.PP
.I Regexec
matches the compiled RE pointed to by
.I preg
against the
.IR string ,
subject to the flags in
.IR eflags ,
and reports results using
.IR nmatch ,
.IR pmatch ,
and the returned value.
The RE must have been compiled by a previous invocation of
.IR regcomp .
The compiled form is not altered during execution of
.IR regexec ,
so a single compiled RE can be used simultaneously by multiple threads.
.PP
By default,
the NUL-terminated string pointed to by
.I string
is considered to be the text of an entire line,
with the NUL indicating the end of the line.
(That is,
any other end-of-line marker is considered to have been removed
and replaced by the NUL.)
The
.I eflags
argument is the bitwise OR of zero or more of the following flags:
.IP REG_NOTBOL \w'REG_STARTEND'u+2n
The first character of
the string
is not the beginning of a line, so the `^' anchor should not match before it.
This does not affect the behavior of newlines under REG_NEWLINE.
.IP REG_NOTEOL
The NUL terminating
the string
does not end a line, so the `$' anchor should not match before it.
This does not affect the behavior of newlines under REG_NEWLINE.
.IP REG_STARTEND
The string is considered to start at
\fIstring\fR\ + \fIpmatch\fR[0].\fIrm_so\fR
and to have a terminating NUL located at
\fIstring\fR\ + \fIpmatch\fR[0].\fIrm_eo\fR
(there need not actually be a NUL at that location),
regardless of the value of
.IR nmatch .
See below for the definition of
.IR pmatch
and
.IR nmatch .
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
Note that a non-zero \fIrm_so\fR does not imply REG_NOTBOL;
REG_STARTEND affects only the location of the string,
not how it is matched.
.PP
See
.ZR
for a discussion of what is matched in situations where an RE or a
portion thereof could match any of several substrings of
.IR string .
.PP
Normally,
.I regexec
returns 0 for success and the non-zero code REG_NOMATCH for failure.
Other non-zero error codes may be returned in exceptional situations;
see DIAGNOSTICS.
.PP
If REG_NOSUB was specified in the compilation of the RE,
or if
.I nmatch
is 0,
.I regexec
ignores the
.I pmatch
argument (but see below for the case where REG_STARTEND is specified).
Otherwise,
.I pmatch
points to an array of
.I nmatch
structures of type
.IR regmatch_t .
Such a structure has at least the members
.I rm_so
and
.IR rm_eo ,
both of type
.I regoff_t
(a signed arithmetic type at least as large as an
.I off_t
and a
.IR 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
.I string
argument given to
.IR regexec .
An empty substring is denoted by equal offsets,
both indicating the character following the empty substring.
.PP
The 0th member of the
.I pmatch
array is filled in to indicate what substring of
.I string
was matched by the entire RE.
Remaining members report what substring was matched by parenthesized
subexpressions within the RE;
member
.I i
reports subexpression
.IR 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\(emcorresponding either to subexpressions that
did not participate in the match at all, or to subexpressions that do not
exist in the RE (that is, \fIi\fR\ > \fIpreg\fR\->\fIre_nsub\fR)\(emhave both
.I rm_so
and
.I 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 `(b*)+' matches `bbb',
the parenthesized subexpression matches the three `b's and then
an infinite number of empty strings following the last `b',
so the reported substring is one of the empties.)
.PP
If REG_STARTEND is specified,
.I pmatch
must point to at least one
.I regmatch_t
(even if
.I nmatch
is 0 or REG_NOSUB was specified),
to hold the input offsets for REG_STARTEND.
Use for output is still entirely controlled by
.IR nmatch ;
if
.I nmatch
is 0 or REG_NOSUB was specified,
the value of
.IR pmatch [0]
will not be changed by a successful
.IR regexec .
.PP
.I Regerror
maps a non-zero
.I errcode
from either
.I regcomp
or
.I regexec
to a human-readable, printable message.
If
.I preg
is non-NULL,
the error code should have arisen from use of
the
.I regex_t
pointed to by
.IR preg ,
and if the error code came from
.IR regcomp ,
it should have been the result from the most recent
.I regcomp
using that
.IR regex_t .
.RI ( Regerror
may be able to supply a more detailed message using information
from the
.IR regex_t .)
.I Regerror
places the NUL-terminated message into the buffer pointed to by
.IR errbuf ,
limiting the length (including the NUL) to at most
.I 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
.I errbuf_size
is 0,
.I errbuf
is ignored but the return value is still correct.
.PP
If the
.I errcode
given to
.I regerror
is first ORed with REG_ITOA,
the ``message'' that results is the printable name of the error code,
e.g. ``REG_NOMATCH'',
rather than an explanation thereof.
If
.I errcode
is REG_ATOI,
then
.I preg
shall be non-NULL and the
.I 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
.I errbuf
is the decimal digits of
the numeric value of the error code
(0 if the name is not recognized).
REG_ITOA and REG_ATOI are intended primarily as debugging facilities;
they are extensions,
compatible with but not specified by POSIX 1003.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
.I Regfree
frees any dynamically-allocated storage associated with the compiled RE
pointed to by
.IR preg .
The remaining
.I regex_t
is no longer a valid compiled RE
and the effect of supplying it to
.I regexec
or
.I 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 1003.2 leaves up to the implementor,
either by explicitly saying ``undefined'' or by virtue of them being
forbidden by the RE grammar.
This implementation treats them as follows.
.PP
See
.ZR
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 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 1003.2 (such magic meanings occur only in obsolete [``basic''] REs)
is taken as an ordinary character.
.PP
Any unmatched [ is a REG_EBRACK error.
.PP
Equivalence classes cannot begin or end bracket-expression ranges.
The endpoint of one range cannot begin another.
.PP
RE_DUP_MAX, the limit on repetition counts in bounded repetitions, is 255.
.PP
A repetition operator (?, *, +, or bounds) cannot follow another
repetition operator.
A repetition operator cannot begin an expression or subexpression
or follow `^' or `|'.
.PP
`|' cannot appear first or last in a (sub)expression or after another `|',
i.e. an operand of `|' cannot be an empty subexpression.
An empty parenthesized subexpression, `()', is legal and matches an
empty (sub)string.
An empty string is not a legal RE.
.PP
A `{' followed by a digit is considered the beginning of bounds for a
bounded repetition, which must then follow the syntax for bounds.
A `{' \fInot\fR followed by a digit is considered an ordinary character.
.PP
`^' and `$' beginning and ending subexpressions in obsolete (``basic'')
REs are anchors, not ordinary characters.
.SH SEE ALSO
grep(1), regex(7)
.PP
POSIX 1003.2, sections 2.8 (Regular Expression Notation)
and
B.5 (C Binding for Regular Expression Matching).
.SH DIAGNOSTICS
Non-zero error codes from
.I regcomp
and
.I regexec
include the following:
.PP
.nf
.ta \w'REG_ECOLLATE'u+3n
REG_NOMATCH regexec() failed to match
REG_BADPAT invalid regular expression
REG_ECOLLATE invalid collating element
REG_ECTYPE invalid character class
REG_EESCAPE \e applied to unescapable character
REG_ESUBREG invalid backreference number
REG_EBRACK brackets [ ] not balanced
REG_EPAREN parentheses ( ) not balanced
REG_EBRACE braces { } not balanced
REG_BADBR invalid repetition count(s) in { }
REG_ERANGE invalid character range in [ ]
REG_ESPACE ran out of memory
REG_BADRPT ?, *, or + operand invalid
REG_EMPTY empty (sub)expression
REG_ASSERT ``can't happen''\(emyou found a bug
REG_INVARG invalid argument, e.g. negative-length string
.fi
.SH HISTORY
Written by Henry Spencer,
henry@zoo.toronto.edu.
.SH BUGS
This is an alpha release with known defects.
Please report problems.
.PP
There is one known functionality bug.
The implementation of internationalization is incomplete:
the locale is always assumed to be the default one of 1003.2,
and only the collating elements etc. of that locale are available.
.PP
The back-reference code is subtle and doubts linger about its correctness
in complex cases.
.PP
.I Regexec
performance is poor.
This will improve with later releases.
.I Nmatch
exceeding 0 is expensive;
.I nmatch
exceeding 1 is worse.
.I Regexec
is largely insensitive to RE complexity \fIexcept\fR 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
.I 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,
`((((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 1003.2, things like `a)b' are legal REs because `)' is
a special character only in the presence of a previous unmatched `('.
This can't be fixed until the spec is fixed.
.PP
The standard's definition of back references is vague.
For example, does
`a\e(\e(b\e)*\e2\e)*d' match `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.

235
winsup/cygwin/regex/regex.7 Normal file
View File

@ -0,0 +1,235 @@
.TH REGEX 7 "25 Oct 1995"
.BY "Henry Spencer"
.SH NAME
regex \- POSIX 1003.2 regular expressions
.SH DESCRIPTION
Regular expressions (``RE''s),
as defined in POSIX 1003.2, come in two forms:
modern REs (roughly those of
.IR egrep ;
1003.2 calls these ``extended'' REs)
and obsolete REs (roughly those of
.IR ed ;
1003.2 ``basic'' REs).
Obsolete REs mostly exist for backward compatibility in some old programs;
they will be discussed at the end.
1003.2 leaves some aspects of RE syntax and semantics open;
`\(dg' marks decisions on these aspects that
may not be fully portable to other 1003.2 implementations.
.PP
A (modern) RE is one\(dg or more non-empty\(dg \fIbranches\fR,
separated by `|'.
It matches anything that matches one of the branches.
.PP
A branch is one\(dg or more \fIpieces\fR, concatenated.
It matches a match for the first, followed by a match for the second, etc.
.PP
A piece is an \fIatom\fR possibly followed
by a single\(dg `*', `+', `?', or \fIbound\fR.
An atom followed by `*' matches a sequence of 0 or more matches of the atom.
An atom followed by `+' matches a sequence of 1 or more matches of the atom.
An atom followed by `?' matches a sequence of 0 or 1 matches of the atom.
.PP
A \fIbound\fR is `{' followed by an unsigned decimal integer,
possibly followed by `,'
possibly followed by another unsigned decimal integer,
always followed by `}'.
The integers must lie between 0 and RE_DUP_MAX (255\(dg) inclusive,
and if there are two of them, the first may not exceed the second.
An atom followed by a bound containing one integer \fIi\fR
and no comma matches
a sequence of exactly \fIi\fR matches of the atom.
An atom followed by a bound
containing one integer \fIi\fR and a comma matches
a sequence of \fIi\fR or more matches of the atom.
An atom followed by a bound
containing two integers \fIi\fR and \fIj\fR matches
a sequence of \fIi\fR through \fIj\fR (inclusive) matches of the atom.
.PP
An atom is a regular expression enclosed in `()' (matching a match for the
regular expression),
an empty set of `()' (matching the null string)\(dg,
a \fIbracket expression\fR (see below), `.'
(matching any single character), `^' (matching the null string at the
beginning of a line), `$' (matching the null string at the
end of a line), a `\e' followed by one of the characters
`^.[$()|*+?{\e'
(matching that character taken as an ordinary character),
a `\e' followed by any other character\(dg
(matching that character taken as an ordinary character,
as if the `\e' had not been present\(dg),
or a single character with no other significance (matching that character).
A `{' followed by a character other than a digit is an ordinary
character, not the beginning of a bound\(dg.
It is illegal to end an RE with `\e'.
.PP
A \fIbracket expression\fR is a list of characters enclosed in `[]'.
It normally matches any single character from the list (but see below).
If the list begins with `^',
it matches any single character
(but see below) \fInot\fR from the rest of the list.
If two characters in the list are separated by `\-', this is shorthand
for the full \fIrange\fR of characters between those two (inclusive) in the
collating sequence,
e.g. `[0\-9]' in ASCII matches any decimal digit.
It is illegal\(dg for two ranges to share an
endpoint, e.g. `a\-c\-e'.
Ranges are very collating-sequence-dependent,
and portable programs should avoid relying on them.
.PP
To include a literal `]' in the list, make it the first character
(following a possible `^').
To include a literal `\-', make it the first or last character,
or the second endpoint of a range.
To use a literal `\-' as the first endpoint of a range,
enclose it in `[.' and `.]' to make it a collating element (see below).
With the exception of these and some combinations using `[' (see next
paragraphs), all other special characters, including `\e', lose their
special significance within a bracket expression.
.PP
Within a bracket expression, a collating element (a character,
a multi-character sequence that collates as if it were a single character,
or a collating-sequence name for either)
enclosed in `[.' and `.]' stands for the
sequence of characters of that collating element.
The sequence is a single element of the bracket expression's list.
A bracket expression containing a multi-character collating element
can thus match more than one character,
e.g. if the collating sequence includes a `ch' collating element,
then the RE `[[.ch.]]*c' matches the first five characters
of `chchcc'.
.PP
Within a bracket expression, a collating element enclosed in `[=' and
`=]' is an equivalence class, standing for the sequences of characters
of all collating elements equivalent to that one, including itself.
(If there are no other equivalent collating elements,
the treatment is as if the enclosing delimiters were `[.' and `.]'.)
For example, if o and \o'o^' are the members of an equivalence class,
then `[[=o=]]', `[[=\o'o^'=]]', and `[o\o'o^']' are all synonymous.
An equivalence class may not\(dg be an endpoint
of a range.
.PP
Within a bracket expression, the name of a \fIcharacter class\fR enclosed
in `[:' and `:]' stands for the list of all characters belonging to that
class.
Standard character class names are:
.PP
.RS
.nf
.ta 3c 6c 9c
alnum digit punct
alpha graph space
blank lower upper
cntrl print xdigit
.fi
.RE
.PP
These stand for the character classes defined in
.IR ctype (3).
A locale may provide others.
A character class may not be used as an endpoint of a range.
.PP
There are two special cases\(dg of bracket expressions:
the bracket expressions `[[:<:]]' and `[[:>:]]' match the null string at
the beginning and end of a word respectively.
A word is defined as a sequence of
word characters
which is neither preceded nor followed by
word characters.
A word character is an
.I alnum
character (as defined by
.IR ctype (3))
or an underscore.
This is an extension,
compatible with but not specified by POSIX 1003.2,
and should be used with
caution in software intended to be portable to other systems.
.PP
In the event that an RE could match more than one substring of a given
string,
the RE matches the one starting earliest in the string.
If the RE could match more than one substring starting at that point,
it matches the longest.
Subexpressions also match the longest possible substrings, subject to
the constraint that the whole match be as long as possible,
with subexpressions starting earlier in the RE taking priority over
ones starting later.
Note that higher-level subexpressions thus take priority over
their lower-level component subexpressions.
.PP
Match lengths are measured in characters, not collating elements.
A null string is considered longer than no match at all.
For example,
`bb*' matches the three middle characters of `abbbc',
`(wee|week)(knights|nights)' matches all ten characters of `weeknights',
when `(.*).*' is matched against `abc' the parenthesized subexpression
matches all three characters, and
when `(a*)*' is matched against `bc' both the whole RE and the parenthesized
subexpression match the null string.
.PP
If case-independent matching is specified,
the effect is much as if all case distinctions had vanished from the
alphabet.
When an alphabetic that exists in multiple cases appears as an
ordinary character outside a bracket expression, it is effectively
transformed into a bracket expression containing both cases,
e.g. `x' becomes `[xX]'.
When it appears inside a bracket expression, all case counterparts
of it are added to the bracket expression, so that (e.g.) `[x]'
becomes `[xX]' and `[^x]' becomes `[^xX]'.
.PP
No particular limit is imposed on the length of REs\(dg.
Programs intended to be portable should not employ REs longer
than 256 bytes,
as an implementation can refuse to accept such REs and remain
POSIX-compliant.
.PP
Obsolete (``basic'') regular expressions differ in several respects.
`|', `+', and `?' are ordinary characters and there is no equivalent
for their functionality.
The delimiters for bounds are `\e{' and `\e}',
with `{' and `}' by themselves ordinary characters.
The parentheses for nested subexpressions are `\e(' and `\e)',
with `(' and `)' by themselves ordinary characters.
`^' is an ordinary character except at the beginning of the
RE or\(dg the beginning of a parenthesized subexpression,
`$' is an ordinary character except at the end of the
RE or\(dg the end of a parenthesized subexpression,
and `*' is an ordinary character if it appears at the beginning of the
RE or the beginning of a parenthesized subexpression
(after a possible leading `^').
Finally, there is one new type of atom, a \fIback reference\fR:
`\e' followed by a non-zero decimal digit \fId\fR
matches the same sequence of characters
matched by the \fId\fRth parenthesized subexpression
(numbering subexpressions by the positions of their opening parentheses,
left to right),
so that (e.g.) `\e([bc]\e)\e1' matches `bb' or `cc' but not `bc'.
.SH SEE ALSO
regex(3)
.PP
POSIX 1003.2, section 2.8 (Regular Expression Notation).
.SH HISTORY
Written by Henry Spencer, based on the 1003.2 spec.
.SH BUGS
Having two kinds of REs is a botch.
.PP
The current 1003.2 spec says that `)' is an ordinary character in
the absence of an unmatched `(';
this was an unintentional result of a wording error,
and change is likely.
Avoid relying on it.
.PP
Back references are a dreadful botch,
posing major problems for efficient implementations.
They are also somewhat vaguely defined
(does
`a\e(\e(b\e)*\e2\e)*d' match `abbbd'?).
Avoid using them.
.PP
1003.2's specification of case-independent matching is vague.
The ``one case implies all cases'' definition given above
is current consensus among implementors as to the right interpretation.
.PP
The syntax for word boundaries is incredibly ugly.

View File

@ -0,0 +1,83 @@
#ifndef _REGEX_H_
#define _REGEX_H_ /* never again */
#include <sys/types.h>
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __INSIDE_CYGWIN__
#define regcomp posix_regcomp
#define regerror posix_regerror
#define regexec posix_regexec
#define regfree posix_regfree
#endif
/* === regex2.h === */
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;
/* === regcomp.c === */
extern int regcomp(regex_t *, const char *, int);
#define REG_BASIC 0000
#define REG_EXTENDED 0001
#define REG_ICASE 0002
#define REG_NOSUB 0004
#define REG_NEWLINE 0010
#define REG_NOSPEC 0020
#define REG_PEND 0040
#define REG_DUMP 0200
/* === regerror.c === */
#define REG_OKAY 0
#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 (!) */
extern size_t regerror(int, const regex_t *, char *, size_t);
/* === regexec.c === */
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 */
/* === regfree.c === */
extern void regfree(regex_t *);
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
#endif

View File

@ -0,0 +1,134 @@
/*
* 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 long sop; /* strip operator */
typedef long sopno;
#define OPRMASK 0x7c000000
#define OPDMASK 0x03ffffff
#define OPSHIFT (26)
#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 (1<<OPSHIFT) /* endmarker - */
#define OCHAR (2<<OPSHIFT) /* character unsigned char */
#define OBOL (3<<OPSHIFT) /* left anchor - */
#define OEOL (4<<OPSHIFT) /* right anchor - */
#define OANY (5<<OPSHIFT) /* . - */
#define OANYOF (6<<OPSHIFT) /* [...] set number */
#define OBACK_ (7<<OPSHIFT) /* begin \d paren number */
#define O_BACK (8<<OPSHIFT) /* end \d paren number */
#define OPLUS_ (9<<OPSHIFT) /* + prefix fwd to suffix */
#define O_PLUS (10<<OPSHIFT) /* + suffix back to prefix */
#define OQUEST_ (11<<OPSHIFT) /* ? prefix fwd to suffix */
#define O_QUEST (12<<OPSHIFT) /* ? suffix back to prefix */
#define OLPAREN (13<<OPSHIFT) /* ( fwd to ) */
#define ORPAREN (14<<OPSHIFT) /* ) back to ( */
#define OCH_ (15<<OPSHIFT) /* begin choice fwd to OOR2 */
#define OOR1 (16<<OPSHIFT) /* | pt. 1 back to OOR1 or OCH_ */
#define OOR2 (17<<OPSHIFT) /* | pt. 2 fwd to OOR2 or O_CH */
#define O_CH (18<<OPSHIFT) /* end choice back to OOR1 */
#define OBOW (19<<OPSHIFT) /* begin word - */
#define OEOW (20<<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 */
uch 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 += (c))
#define CHsub(cs, c) ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (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 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(c) || (c) == '_')

View File

@ -0,0 +1,141 @@
/*
* 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 "winsup.h"
#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"
#ifdef lint
static int nope = 0; /* for use in asserts; shuts lint up */
#endif
/* macros for manipulating states, small version */
#define states unsigned
#define states1 unsigned /* for later use in regexec() decision */
#define CLEAR(v) ((v) = 0)
#define SET0(v, n) ((v) &= ~((unsigned)1 << (n)))
#define SET1(v, n) ((v) |= (unsigned)1 << (n))
#define ISSET(v, n) ((v) & ((unsigned)1 << (n)))
#define ASSIGN(d, s) ((d) = (s))
#define EQ(a, b) ((a) == (b))
#define STATEVARS int dummy /* dummy version */
#define STATESETUP(m, n) /* nothing */
#define STATETEARDOWN(m) /* nothing */
#define SETUP(v) ((v) = 0)
#define onestate unsigned
#define INIT(o, n) ((o) = (unsigned)1 << (n))
#define INC(o) ((o) <<= 1)
#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) |= ((unsigned)(src)&(here)) << (n))
#define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n))
#define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n)))
/* 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 int 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 int
#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;
{
register 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&REG_LARGE))
return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
else
return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
}

View File

@ -0,0 +1,38 @@
#include "winsup.h"
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "regex.h"
#include "utils.h"
#include "regex2.h"
/*
- regfree - free everything
= extern void regfree(regex_t *);
*/
void
regfree(preg)
regex_t *preg;
{
register 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);
free((char *)g);
}

477
winsup/cygwin/regex/tests Normal file
View File

@ -0,0 +1,477 @@
# regular expression test set
# Lines are at least three fields, separated by one or more tabs. "" stands
# for an empty field. First field is an RE. Second field is flags. If
# C flag given, regcomp() is expected to fail, and the third field is the
# error name (minus the leading REG_).
#
# Otherwise it is expected to succeed, and the third field is the string to
# try matching it against. If there is no fourth field, the match is
# expected to fail. If there is a fourth field, it is the substring that
# the RE is expected to match. If there is a fifth field, it is a comma-
# separated list of what the subexpressions should match, with - indicating
# no match for that one. In both the fourth and fifth fields, a (sub)field
# starting with @ indicates that the (sub)expression is expected to match
# a null string followed by the stuff after the @; this provides a way to
# test where null strings match. The character `N' in REs and strings
# is newline, `S' is space, `T' is tab, `Z' is NUL.
#
# The full list of flags:
# - placeholder, does nothing
# b RE is a BRE, not an ERE
# & try it as both an ERE and a BRE
# C regcomp() error expected, third field is error name
# i REG_ICASE
# m ("mundane") REG_NOSPEC
# s REG_NOSUB (not really testable)
# n REG_NEWLINE
# ^ REG_NOTBOL
# $ REG_NOTEOL
# # REG_STARTEND (see below)
# p REG_PEND
#
# For REG_STARTEND, the start/end offsets are those of the substring
# enclosed in ().
# basics
a & a a
abc & abc abc
abc|de - abc abc
a|b|c - abc a
# parentheses and perversions thereof
a(b)c - abc abc
a\(b\)c b abc abc
a( C EPAREN
a( b a( a(
a\( - a( a(
a\( bC EPAREN
a\(b bC EPAREN
a(b C EPAREN
a(b b a(b a(b
# gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
a) - a) a)
) - ) )
# end gagging (in a just world, those *should* give EPAREN)
a) b a) a)
a\) bC EPAREN
\) bC EPAREN
a()b - ab ab
a\(\)b b ab ab
# anchoring and REG_NEWLINE
^abc$ & abc abc
a^b - a^b
a^b b a^b a^b
a$b - a$b
a$b b a$b a$b
^ & abc @abc
$ & abc @
^$ & "" @
$^ - "" @
\($\)\(^\) b "" @
# stop retching, those are legitimate (although disgusting)
^^ - "" @
$$ - "" @
b$ & abNc
b$ &n abNc b
^b$ & aNbNc
^b$ &n aNbNc b
^$ &n aNNb @Nb
^$ n abc
^$ n abcN @
$^ n aNNb @Nb
\($\)\(^\) bn aNNb @Nb
^^ n^ aNNb @Nb
$$ n aNNb @NN
^a ^ a
a$ $ a
^a ^n aNb
^b ^n aNb b
a$ $n bNa
b$ $n bNa b
a*(^b$)c* - b b
a*\(^b$\)c* b b b
# certain syntax errors and non-errors
| C EMPTY
| b | |
* C BADRPT
* b * *
+ C BADRPT
? C BADRPT
"" &C EMPTY
() - abc @abc
\(\) b abc @abc
a||b C EMPTY
|ab C EMPTY
ab| C EMPTY
(|a)b C EMPTY
(a|)b C EMPTY
(*a) C BADRPT
(+a) C BADRPT
(?a) C BADRPT
({1}a) C BADRPT
\(\{1\}a\) bC BADRPT
(a|*b) C BADRPT
(a|+b) C BADRPT
(a|?b) C BADRPT
(a|{1}b) C BADRPT
^* C BADRPT
^* b * *
^+ C BADRPT
^? C BADRPT
^{1} C BADRPT
^\{1\} bC BADRPT
# metacharacters, backslashes
a.c & abc abc
a[bc]d & abd abd
a\*c & a*c a*c
a\\b & a\b a\b
a\\\*b & a\*b a\*b
a\bc & abc abc
a\ &C EESCAPE
a\\bc & a\bc a\bc
\{ bC BADRPT
a\[b & a[b a[b
a[b &C EBRACK
# trailing $ is a peculiar special case for the BRE code
a$ & a a
a$ & a$
a\$ & a
a\$ & a$ a$
a\\$ & a
a\\$ & a$
a\\$ & a\$
a\\$ & a\ a\
# back references, ugh
a\(b\)\2c bC ESUBREG
a\(b\1\)c bC ESUBREG
a\(b*\)c\1d b abbcbbd abbcbbd bb
a\(b*\)c\1d b abbcbd
a\(b*\)c\1d b abbcbbbd
^\(.\)\1 b abc
a\([bc]\)\1d b abcdabbd abbd b
a\(\([bc]\)\2\)*d b abbccd abbccd
a\(\([bc]\)\2\)*d b abbcbd
# actually, this next one probably ought to fail, but the spec is unclear
a\(\(b\)*\2\)*d b abbbd abbbd
# here is a case that no NFA implementation does right
\(ab*\)[ab]*\1 b ababaaa ababaaa a
# check out normal matching in the presence of back refs
\(a\)\1bcd b aabcd aabcd
\(a\)\1bc*d b aabcd aabcd
\(a\)\1bc*d b aabd aabd
\(a\)\1bc*d b aabcccd aabcccd
\(a\)\1bc*[ce]d b aabcccd aabcccd
^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd
# ordinary repetitions
ab*c & abc abc
ab+c - abc abc
ab?c - abc abc
a\(*\)b b a*b a*b
a\(**\)b b ab ab
a\(***\)b bC BADRPT
*a b *a *a
**a b a a
***a bC BADRPT
# the dreaded bounded repetitions
{ & { {
{abc & {abc {abc
{1 C BADRPT
{1} C BADRPT
a{b & a{b a{b
a{1}b - ab ab
a\{1\}b b ab ab
a{1,}b - ab ab
a\{1,\}b b ab ab
a{1,2}b - aab aab
a\{1,2\}b b aab aab
a{1 C EBRACE
a\{1 bC EBRACE
a{1a C EBRACE
a\{1a bC EBRACE
a{1a} C BADBR
a\{1a\} bC BADBR
a{,2} - a{,2} a{,2}
a\{,2\} bC BADBR
a{,} - a{,} a{,}
a\{,\} bC BADBR
a{1,x} C BADBR
a\{1,x\} bC BADBR
a{1,x C EBRACE
a\{1,x bC EBRACE
a{300} C BADBR
a\{300\} bC BADBR
a{1,0} C BADBR
a\{1,0\} bC BADBR
ab{0,0}c - abcac ac
ab\{0,0\}c b abcac ac
ab{0,1}c - abcac abc
ab\{0,1\}c b abcac abc
ab{0,3}c - abbcac abbc
ab\{0,3\}c b abbcac abbc
ab{1,1}c - acabc abc
ab\{1,1\}c b acabc abc
ab{1,3}c - acabc abc
ab\{1,3\}c b acabc abc
ab{2,2}c - abcabbc abbc
ab\{2,2\}c b abcabbc abbc
ab{2,4}c - abcabbc abbc
ab\{2,4\}c b abcabbc abbc
((a{1,10}){1,10}){1,10} - a a a,a
# multiple repetitions
a** &C BADRPT
a++ C BADRPT
a?? C BADRPT
a*+ C BADRPT
a*? C BADRPT
a+* C BADRPT
a+? C BADRPT
a?* C BADRPT
a?+ C BADRPT
a{1}{1} C BADRPT
a*{1} C BADRPT
a+{1} C BADRPT
a?{1} C BADRPT
a{1}* C BADRPT
a{1}+ C BADRPT
a{1}? C BADRPT
a*{b} - a{b} a{b}
a\{1\}\{1\} bC BADRPT
a*\{1\} bC BADRPT
a\{1\}* bC BADRPT
# brackets, and numerous perversions thereof
a[b]c & abc abc
a[ab]c & abc abc
a[^ab]c & adc adc
a[]b]c & a]c a]c
a[[b]c & a[c a[c
a[-b]c & a-c a-c
a[^]b]c & adc adc
a[^-b]c & adc adc
a[b-]c & a-c a-c
a[b &C EBRACK
a[] &C EBRACK
a[1-3]c & a2c a2c
a[3-1]c &C ERANGE
a[1-3-5]c &C ERANGE
a[[.-.]--]c & a-c a-c
a[1- &C ERANGE
a[[. &C EBRACK
a[[.x &C EBRACK
a[[.x. &C EBRACK
a[[.x.] &C EBRACK
a[[.x.]] & ax ax
a[[.x,.]] &C ECOLLATE
a[[.one.]]b & a1b a1b
a[[.notdef.]]b &C ECOLLATE
a[[.].]]b & a]b a]b
a[[:alpha:]]c & abc abc
a[[:notdef:]]c &C ECTYPE
a[[: &C EBRACK
a[[:alpha &C EBRACK
a[[:alpha:] &C EBRACK
a[[:alpha,:] &C ECTYPE
a[[:]:]]b &C ECTYPE
a[[:-:]]b &C ECTYPE
a[[:alph:]] &C ECTYPE
a[[:alphabet:]] &C ECTYPE
[[:alnum:]]+ - -%@a0X- a0X
[[:alpha:]]+ - -%@aX0- aX
[[:blank:]]+ - aSSTb SST
[[:cntrl:]]+ - aNTb NT
[[:digit:]]+ - a019b 019
[[:graph:]]+ - Sa%bS a%b
[[:lower:]]+ - AabC ab
[[:print:]]+ - NaSbN aSb
[[:punct:]]+ - S%-&T %-&
[[:space:]]+ - aSNTb SNT
[[:upper:]]+ - aBCd BC
[[:xdigit:]]+ - p0f3Cq 0f3C
a[[=b=]]c & abc abc
a[[= &C EBRACK
a[[=b &C EBRACK
a[[=b= &C EBRACK
a[[=b=] &C EBRACK
a[[=b,=]] &C ECOLLATE
a[[=one=]]b & a1b a1b
# complexities
a(((b)))c - abc abc
a(b|(c))d - abd abd
a(b*|c)d - abbd abbd
# just gotta have one DFA-buster, of course
a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
# and an inline expansion in case somebody gets tricky
a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
# and in case somebody just slips in an NFA...
a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) - aaaaabaaaabaaaabaaaabweeknights aaaaabaaaabaaaabaaaabweeknights
# fish for anomalies as the number of states passes 32
12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
# and one really big one, beyond any plausible word width
1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
# fish for problems as brackets go past 8
[ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
[ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
[ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
[ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
# subtleties of matching
abc & xabcy abc
a\(b\)?c\1d b acd
aBc i Abc Abc
a[Bc]*d i abBCcd abBCcd
0[[:upper:]]1 &i 0a1 0a1
0[[:lower:]]1 &i 0A1 0A1
a[^b]c &i abc
a[^b]c &i aBc
a[^b]c &i adc adc
[a]b[c] - abc abc
[a]b[a] - aba aba
[abc]b[abc] - abc abc
[abc]b[abd] - abd abd
a(b?c)+d - accd accd
(wee|week)(knights|night) - weeknights weeknights
(we|wee|week|frob)(knights|night|day) - weeknights weeknights
a[bc]d - xyzaaabcaababdacd abd
a[ab]c - aaabc abc
abc s abc abc
a* & b @b
# Let's have some fun -- try to match a C comment.
# first the obvious, which looks okay at first glance...
/\*.*\*/ - /*x*/ /*x*/
# but...
/\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
# okay, we must not match */ inside; try to do that...
/\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
/\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
# but...
/\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
# and a still fancier version, which does it right (I think)...
/\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
/\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
/\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
/\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
/\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
/\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
# subexpressions
.* - abc abc -
a(b)(c)d - abcd abcd b,c
a(((b)))c - abc abc b,b,b
a(b|(c))d - abd abd b,-
a(b*|c|e)d - abbd abbd bb
a(b*|c|e)d - acd acd c
a(b*|c|e)d - ad ad @d
a(b?)c - abc abc b
a(b?)c - ac ac @c
a(b+)c - abc abc b
a(b+)c - abbbc abbbc bbb
a(b*)c - ac ac @c
(a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
# the regression tester only asks for 9 subexpressions
a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
a([bc]?)c - abc abc b
a([bc]?)c - ac ac @c
a([bc]+)c - abc abc b
a([bc]+)c - abcc abcc bc
a([bc]+)bc - abcbc abcbc bc
a(bb+|b)b - abb abb b
a(bbb+|bb+|b)b - abb abb b
a(bbb+|bb+|b)b - abbb abbb bb
a(bbb+|bb+|b)bb - abbb abbb b
(.*).* - abcdef abcdef abcdef
(a*)* - bc @b @b
# do we get the right subexpression when it is used more than once?
a(b|c)*d - ad ad -
a(b|c)*d - abcd abcd c
a(b|c)+d - abd abd b
a(b|c)+d - abcd abcd c
a(b|c?)+d - ad ad @d
a(b|c?)+d - abcd abcd @d
a(b|c){0,0}d - ad ad -
a(b|c){0,1}d - ad ad -
a(b|c){0,1}d - abd abd b
a(b|c){0,2}d - ad ad -
a(b|c){0,2}d - abcd abcd c
a(b|c){0,}d - ad ad -
a(b|c){0,}d - abcd abcd c
a(b|c){1,1}d - abd abd b
a(b|c){1,1}d - acd acd c
a(b|c){1,2}d - abd abd b
a(b|c){1,2}d - abcd abcd c
a(b|c){1,}d - abd abd b
a(b|c){1,}d - abcd abcd c
a(b|c){2,2}d - acbd acbd b
a(b|c){2,2}d - abcd abcd c
a(b|c){2,4}d - abcd abcd c
a(b|c){2,4}d - abcbd abcbd b
a(b|c){2,4}d - abcbcd abcbcd c
a(b|c){2,}d - abcd abcd c
a(b|c){2,}d - abcbd abcbd b
a(b+|((c)*))+d - abd abd @d,@d,-
a(b+|((c)*))+d - abcd abcd @d,@d,-
# check out the STARTEND option
[abc] &# a(b)c b
[abc] &# a(d)c
[abc] &# a(bc)d b
[abc] &# a(dc)d c
. &# a()c
b.*c &# b(bc)c bc
b.* &# b(bc)c bc
.*c &# b(bc)c bc
# plain strings, with the NOSPEC flag
abc m abc abc
abc m xabcy abc
abc m xyz
a*b m aba*b a*b
a*b m ab
"" mC EMPTY
# cases involving NULs
aZb & a a
aZb &p a
aZb &p# (aZb) aZb
aZ*b &p# (ab) ab
a.b &# (aZb) aZb
a.* &# (aZb)c aZb
# word boundaries (ick)
[[:<:]]a & a a
[[:<:]]a & ba
[[:<:]]a & -a a
a[[:>:]] & a a
a[[:>:]] & ab
a[[:>:]] & a- a
[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
[[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
[[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
[[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
[[:<:]]a_b[[:>:]] & x_a_b
# past problems, and suspected problems
(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
(ALAK)|(ALT[AB])|(CC[123]1)|(CM[123]1)|(GAMC)|(LC[23][EO ])|(SEM[1234])|(SL[ES][12])|(SLWW)|(SLF )|(SLDT)|(VWH[12])|(WH[34][EW])|(WP1[ESN]) - CC11 CC11
CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
a?b - ab ab
-\{0,1\}[0-9]*$ b -5 -5
a*a*a*a*a*a*a* & aaaaaa aaaaaa

View File

@ -0,0 +1,22 @@
/* utility definitions */
#ifdef _POSIX2_RE_DUP_MAX
#define DUPMAX _POSIX2_RE_DUP_MAX
#else
#define DUPMAX 255
#endif
#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

View File

@ -12,7 +12,7 @@ details. */
#include "regexp.h" #include "regexp.h"
#include <stdio.h> #include <stdio.h>
void void __declspec(dllexport)
regerror(const char *s __attribute__ ((unused))) regerror(const char *s __attribute__ ((unused)))
{ {
#ifdef ERRAVAIL #ifdef ERRAVAIL

View File

@ -204,7 +204,7 @@ STATIC int strcspn (char *, char *);
* Beware that the optimization-preparation code in here knows about some * Beware that the optimization-preparation code in here knows about some
* of the structure of the compiled regexp. * of the structure of the compiled regexp.
*/ */
regexp * regexp * __declspec(dllexport)
regcomp(exp) regcomp(exp)
const char *exp; const char *exp;
{ {
@ -788,7 +788,7 @@ STATIC char *regprop __P((char *));
/* /*
- regexec - match a regexp against a string - regexec - match a regexp against a string
*/ */
int int __declspec(dllexport)
regexec(prog, string) regexec(prog, string)
register const regexp *prog; register const regexp *prog;
register const char *string; register const char *string;

View File

@ -25,6 +25,7 @@ static char *rcsid = "$Id$";
#endif /* not lint */ #endif /* not lint */
#endif #endif
#include "winsup.h"
#include "regexp.h" #include "regexp.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -39,7 +40,7 @@ static char *rcsid = "$Id$";
/* /*
- regsub - perform substitutions after a regexp match - regsub - perform substitutions after a regexp match
*/ */
void void __declspec(dllexport)
regsub(prog, source, dest) regsub(prog, source, dest)
const regexp *prog; const regexp *prog;
const char *source; const char *source;

11
winsup/cygwin/rmsym Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
lib=$1; shift
nm=$1; shift
ar=$1; shift
ranlib=$1; shift
grepit=`echo $* | sed 's/ /|__imp__/g'`
[ -n "$grepit" ] && grepit="__imp__$grepit"
objs=`$nm $lib | awk -F: '/^d[0-9]*.o:/ {obj=$1} '"/$grepit/"'{print obj}'`
[ -n "$objs" ] || exit 1
$ar d $lib $objs
$ranlib $lib