summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2012-02-08 11:48:08 +0100
committerAndy Wingo <wingo@pobox.com>2012-02-08 11:48:08 +0100
commit0858753e829fd399b55700688b4b2cb9c3ea6908 (patch)
tree55f97b3c1db7a33a181314663cb4e4750077fc3f
parent0aed71aa51e89e714de2392c2a5f44694dca77ea (diff)
parent817307ccac5027fd784798bbbf6ffb52e0a5d751 (diff)
Merge remote-tracking branch 'origin/stable-2.0'
Conflicts: GUILE-VERSION libguile/gc-malloc.c libguile/ports.c
-rw-r--r--NEWS19
-rw-r--r--acinclude.m43
-rw-r--r--configure.ac40
-rw-r--r--doc/ref/api-compound.texi110
-rw-r--r--doc/ref/api-control.texi42
-rw-r--r--doc/ref/api-data.texi189
-rw-r--r--doc/ref/api-debug.texi12
-rw-r--r--doc/ref/api-evaluation.texi24
-rw-r--r--doc/ref/api-foreign.texi12
-rw-r--r--doc/ref/api-io.texi58
-rw-r--r--doc/ref/api-macros.texi10
-rw-r--r--doc/ref/api-memory.texi2
-rw-r--r--doc/ref/api-modules.texi10
-rw-r--r--doc/ref/api-procedures.texi43
-rw-r--r--doc/ref/api-regex.texi4
-rw-r--r--doc/ref/api-scheduling.texi87
-rw-r--r--doc/ref/api-smobs.texi10
-rw-r--r--doc/ref/api-utility.texi8
-rw-r--r--doc/ref/compiler.texi4
-rw-r--r--doc/ref/goops.texi71
-rw-r--r--doc/ref/match.texi20
-rw-r--r--doc/ref/misc-modules.texi55
-rw-r--r--doc/ref/posix.texi96
-rw-r--r--doc/ref/r6rs.texi35
-rw-r--r--doc/ref/scheme-using.texi10
-rw-r--r--doc/ref/srfi-modules.texi255
-rw-r--r--doc/ref/sxml-match.texi6
-rw-r--r--doc/ref/vm.texi6
-rw-r--r--doc/ref/web.texi8
-rw-r--r--doc/sources/ChangeLog-20085
-rw-r--r--doc/sources/Makefile.am7
-rw-r--r--doc/sources/contributors.texi80
-rw-r--r--doc/sources/debug-c.texi2
-rw-r--r--doc/sources/debug-scheme.texi2
-rw-r--r--doc/sources/env.texi1165
-rw-r--r--doc/sources/format.texi434
-rw-r--r--doc/sources/guile-slib.texi2
-rw-r--r--doc/sources/jimb-org.texi131
-rw-r--r--doc/sources/libguile-overview.texi30
-rw-r--r--doc/sources/libguile-tools.texi191
-rw-r--r--doc/sources/new-types.texi2
-rw-r--r--doc/sources/old-intro.texi290
-rw-r--r--doc/sources/sample-APIs.texi6
-rw-r--r--doc/sources/scheme-concepts.texi249
-rw-r--r--doc/sources/scm-ref.texi4
-rw-r--r--doc/sources/strings.texi45
-rw-r--r--doc/sources/tk.texi5
-rw-r--r--doc/sources/unix-other.texi132
-rw-r--r--doc/sources/unix.texi622
-rw-r--r--lib/Makefile.am184
-rw-r--r--lib/btowc.c39
-rw-r--r--lib/langinfo.in.h177
-rw-r--r--lib/mbrtowc.c396
-rw-r--r--lib/mbsinit.c61
-rw-r--r--lib/mbtowc-impl.h44
-rw-r--r--lib/mbtowc.c26
-rw-r--r--lib/nl_langinfo.c271
-rw-r--r--lib/regcomp.c3876
-rw-r--r--lib/regex.c72
-rw-r--r--lib/regex.h675
-rw-r--r--lib/regex_internal.c1741
-rw-r--r--lib/regex_internal.h866
-rw-r--r--lib/regexec.c4417
-rw-r--r--lib/strcasecmp.c63
-rw-r--r--lib/streq.h176
-rw-r--r--lib/strings.in.h123
-rw-r--r--lib/strncasecmp.c63
-rw-r--r--lib/wcrtomb.c53
-rw-r--r--lib/wctype.in.h499
-rw-r--r--libguile/alist.c4
-rw-r--r--libguile/array-map.c27
-rw-r--r--libguile/arrays.c37
-rw-r--r--libguile/bitvectors.c2
-rw-r--r--libguile/continuations.c35
-rw-r--r--libguile/control.c35
-rw-r--r--libguile/error.c7
-rw-r--r--libguile/filesys.c49
-rw-r--r--libguile/foreign.c15
-rw-r--r--libguile/foreign.h6
-rw-r--r--libguile/gc-malloc.c87
-rw-r--r--libguile/generalized-arrays.c7
-rw-r--r--libguile/hashtab.c10
-rw-r--r--libguile/i18n.c41
-rw-r--r--libguile/init.c9
-rw-r--r--libguile/ioext.c10
-rw-r--r--libguile/load.c28
-rw-r--r--libguile/net_db.c15
-rw-r--r--libguile/numbers.c4
-rw-r--r--libguile/ports.c26
-rw-r--r--libguile/posix.c40
-rw-r--r--libguile/print.c2
-rw-r--r--libguile/procprop.c2
-rw-r--r--libguile/promises.c4
-rw-r--r--libguile/regex-posix.c18
-rw-r--r--libguile/simpos.c2
-rw-r--r--libguile/socket.c8
-rw-r--r--libguile/srfi-1.c8
-rw-r--r--libguile/srfi-13.c6
-rw-r--r--libguile/srfi-14.c6
-rw-r--r--libguile/srfi-14.i.c958
-rw-r--r--libguile/stacks.c6
-rw-r--r--libguile/stime.c17
-rw-r--r--libguile/strings.c2
-rw-r--r--libguile/struct.c24
-rw-r--r--libguile/symbols.c9
-rw-r--r--libguile/threads.c17
-rw-r--r--m4/btowc.m4116
-rw-r--r--m4/gnulib-cache.m44
-rw-r--r--m4/gnulib-comp.m498
-rw-r--r--m4/langinfo_h.m4105
-rw-r--r--m4/locale-fr.m4246
-rw-r--r--m4/locale-ja.m4136
-rw-r--r--m4/locale-zh.m4130
-rw-r--r--m4/mbrtowc.m4572
-rw-r--r--m4/mbsinit.m451
-rw-r--r--m4/mbstate_t.m441
-rw-r--r--m4/mbtowc.m419
-rw-r--r--m4/nl_langinfo.m450
-rw-r--r--m4/regex.m4223
-rw-r--r--m4/strcase.m445
-rw-r--r--m4/strings_h.m452
-rw-r--r--m4/wcrtomb.m4112
-rw-r--r--m4/wctype_h.m4211
-rw-r--r--meta/guile-2.2-uninstalled.pc.in5
-rw-r--r--module/ice-9/boot-9.scm2
-rw-r--r--module/ice-9/format.scm21
-rw-r--r--module/ice-9/i18n.scm45
-rw-r--r--module/ice-9/popen.scm4
-rw-r--r--module/ice-9/pretty-print.scm2
-rw-r--r--module/ice-9/r4rs.scm10
-rw-r--r--module/language/tree-il/analyze.scm8
-rw-r--r--module/rnrs/io/ports.scm2
-rw-r--r--module/texinfo/string-utils.scm4
-rw-r--r--module/web/http.scm2
-rw-r--r--module/web/request.scm2
-rw-r--r--module/web/response.scm2
-rw-r--r--test-suite/lib.scm16
-rw-r--r--test-suite/standalone/test-loose-ends.c17
-rw-r--r--test-suite/tests/format.test28
-rw-r--r--test-suite/tests/gc.test46
-rw-r--r--test-suite/tests/i18n.test73
-rw-r--r--test-suite/tests/net-db.test10
-rw-r--r--test-suite/tests/srfi-14.test4
-rw-r--r--test-suite/tests/srfi-42.test4
-rw-r--r--test-suite/tests/threads.test11
-rw-r--r--test-suite/tests/tree-il.test26
-rw-r--r--test-suite/vm/run-vm-tests.scm2
147 files changed, 17939 insertions, 4676 deletions
diff --git a/NEWS b/NEWS
index 0edcef75c..c1589a145 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,13 @@ See the end for copying conditions.
Please send Guile bug reports to bug-guile@gnu.org.
+Changes in 2.0.5 (since 2.0.4):
+
+This release fixes the binary interface information (SONAME) of
+libguile, which was incorrect in 2.0.4. It does not contain other
+changes.
+
+
Changes in 2.0.4 (since 2.0.3):
* Notable changes
@@ -124,6 +131,11 @@ This procedure initializes a random seed using good random sources
available on your platform, such as /dev/urandom. See "Random Number
Generation" in the manual, for more.
+** Warn about unsupported `simple-format' options.
+
+The `-Wformat' compilation option now reports unsupported format options
+passed to `simple-format'.
+
** Manual updates
Besides the sections already mentioned, the following manual sections
@@ -158,7 +170,6 @@ Search the manual for these identifiers and modules, for more.
** Add deprecated shim for `scm_display_error' with stack as first argument.
** Add warnings for unsupported `simple-format' options.
** Allow overlapping regions to be passed to `bytevector-copy!'.
-** Avoid calling `u32_conv_from_encoding' on the null string.
** Better function prologue disassembly
** Compiler: fix miscompilation of (values foo ...) in some contexts.
** Compiler: fix serialization of #nil-terminated lists.
@@ -168,12 +179,10 @@ Search the manual for these identifiers and modules, for more.
** Don't leak file descriptors when mmaping objcode.
** Empty substrings no longer reference the original stringbuf.
** FFI: Fix `set-pointer-finalizer!' to leave the type cell unchanged.
-** FFI: Fix signed/unsigned pointer mismatches in implementation.
** FFI: Hold a weak reference to the CIF made by `procedure->pointer'.
** FFI: Hold a weak reference to the procedure passed to `procedure->pointer'.
** FFI: Properly unpack small integer return values in closure call.
** Fix R6RS `fold-left' so the accumulator is the first argument.
-** Fix `validate-target' in (system base target).
** Fix bit-set*! bug from 2005.
** Fix bug in `make-repl' when `lang' is actually a <language>.
** Fix bugs related to mutation, the null string, and shared substrings.
@@ -188,19 +197,17 @@ Search the manual for these identifiers and modules, for more.
** HTTP: Permit non-date values for Expires header.
** HTTP: `write-request-line' writes absolute paths, not absolute URIs.
** Hack the port-column of current-output-port after printing a prompt.
-** Have `cpu-word-size' error out on unknown CPUs; add support for MIPSEL.
** Make sure `regexp-quote' tests use Unicode-capable string ports.
** Peval: Fix bugs in the new optimizer.
-** Peval: fold (values FOO) to FOO in more cases
** Statistically unique marks and labels, for robust hygiene across sessions.
** Web: Allow URIs with empty authorities, like "file:///etc/hosts".
** `,language' at REPL sets the current-language fluid.
** `primitive-load' returns the value(s) of the last expression.
** `scm_from_stringn' always returns unique strings.
** `scm_i_substring_copy' tries to narrow the substring.
-** guile-readline: Clean `.go' files.
** i18n: Fix gc_malloc/free mismatch on non-GNU systems.
+
Changes in 2.0.3 (since 2.0.2):
* Speed improvements
diff --git a/acinclude.m4 b/acinclude.m4
index f9603d97d..0edd4b8b2 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -614,7 +614,8 @@ AC_DEFUN([gl_CLOCK_TIME],
AC_SEARCH_LIBS([clock_getcpuclockid], [rt posix4],
[test "$ac_cv_search_clock_getcpuclockid" = "none required" \
|| LIB_CLOCK_GETTIME=$ac_cv_search_clock_getcpuclockid],
- [LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime])
+ [test "$ac_cv_search_clock_gettime" = "none required" \
+ || LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime])
else
LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime
fi])
diff --git a/configure.ac b/configure.ac
index 697761fc8..3a5fd0e35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,7 +5,7 @@ dnl
define(GUILE_CONFIGURE_COPYRIGHT,[[
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
This file is part of GUILE
@@ -652,24 +652,13 @@ AC_SUBST([SCM_I_GSC_HAVE_STRUCT_DIRENT64])
# machine/fpu.h - on Tru64 5.1b, the declaration of fesetround(3) is in
# this file instead of <fenv.h>
# process.h - mingw specific
-# langinfo.h, nl_types.h - SuS v2
# sched.h - missing on MinGW
#
AC_CHECK_HEADERS([complex.h fenv.h io.h libc.h limits.h memory.h process.h string.h \
-regex.h rxposix.h rx/rxposix.h sys/dir.h sys/ioctl.h sys/select.h \
+sys/dir.h sys/ioctl.h sys/select.h \
sys/time.h sys/timeb.h sys/times.h sys/stdtypes.h sys/types.h \
sys/utime.h time.h unistd.h utime.h pwd.h grp.h sys/utsname.h \
-direct.h langinfo.h nl_types.h machine/fpu.h poll.h sched.h])
-
-# Reasons for testing:
-# nl_item - lacking on Cygwin
-AC_CHECK_TYPES([nl_item], [], [],
- [[#ifdef HAVE_LANGINFO_H
- # include <langinfo.h>
- #endif
- #ifdef HAVE_NL_TYPES_H
- # include <nl_types.h>
- #endif]])
+direct.h machine/fpu.h poll.h sched.h])
# "complex double" is new in C99, and "complex" is only a keyword if
# <complex.h> is included
@@ -764,11 +753,10 @@ AC_CHECK_HEADERS([assert.h crt_externs.h])
# isblank - available as a GNU extension or in C99
# _NSGetEnviron - Darwin specific
# strcoll_l, newlocale - GNU extensions (glibc), also available on Darwin
-# nl_langinfo - X/Open, not available on Windows.
# utimensat: posix.1-2008
# sched_getaffinity, sched_setaffinity: GNU extensions (glibc)
#
-AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid fesetround ftime ftruncate fchown getcwd geteuid getsid gettimeofday gmtime_r ioctl lstat mkdir mknod nice pipe _pipe poll readdir_r readdir64_r readlink rename rmdir select setegid seteuid setlocale setpgid setsid sigaction siginterrupt stat64 strftime strptime symlink sync sysconf tcgetpgrp tcsetpgrp times uname waitpid strdup system usleep atexit on_exit chown link fcntl ttyname getpwent getgrent kill getppid getpgrp fork setitimer getitimer strchr strcmp index bcopy memcpy rindex truncate unsetenv isblank _NSGetEnviron strcoll strcoll_l newlocale nl_langinfo utimensat sched_getaffinity sched_setaffinity])
+AC_CHECK_FUNCS([DINFINITY DQNAN cexp chsize clog clog10 ctermid fesetround ftime ftruncate fchown getcwd geteuid getsid gettimeofday gmtime_r ioctl lstat mkdir mknod nice pipe _pipe poll readdir_r readdir64_r readlink rename rmdir select setegid seteuid setlocale setpgid setsid sigaction siginterrupt stat64 strftime strptime symlink sync sysconf tcgetpgrp tcsetpgrp times uname waitpid strdup system usleep atexit on_exit chown link fcntl ttyname getpwent getgrent kill getppid getpgrp fork setitimer getitimer strchr strcmp index bcopy memcpy rindex truncate unsetenv isblank _NSGetEnviron strcoll strcoll_l newlocale utimensat sched_getaffinity sched_setaffinity])
# Reasons for testing:
# netdb.h - not in mingw
@@ -1112,24 +1100,8 @@ if test $guile_cv_localtime_cache = yes; then
fi
if test "$enable_regex" = yes; then
- if test "$ac_cv_header_regex_h" = yes ||
- test "$ac_cv_header_rxposix_h" = yes ||
- test "$ac_cv_header_rx_rxposix_h" = yes; then
- GUILE_NAMED_CHECK_FUNC(regcomp, norx, [AC_LIBOBJ([regex-posix])],
- [AC_CHECK_LIB(rx, main)
- GUILE_NAMED_CHECK_FUNC(regcomp, rx, [AC_LIBOBJ([regex-posix])],
- [AC_CHECK_LIB(regex, main)
- GUILE_NAMED_CHECK_FUNC(regcomp, regex, [AC_LIBOBJ([regex-posix])])])]
- )
- dnl The following should not be necessary, but for some reason
- dnl autoheader misses it if we don't include it!
- if test "$ac_cv_func_regcomp_norx" = yes ||
- test "$ac_cv_func_regcomp_regex" = yes ||
- test "$ac_cv_func_regcomp_rx" = yes; then
- AC_DEFINE([HAVE_REGCOMP], 1,
- [This is included as part of a workaround for a autoheader bug.])
- fi
- fi
+ AC_LIBOBJ([regex-posix])
+ AC_DEFINE([ENABLE_REGEX], 1, [Define when regex support is enabled.])
fi
AC_REPLACE_FUNCS([strerror memmove mkstemp])
diff --git a/doc/ref/api-compound.texi b/doc/ref/api-compound.texi
index 03891fac4..6fc5b2e46 100644
--- a/doc/ref/api-compound.texi
+++ b/doc/ref/api-compound.texi
@@ -326,7 +326,7 @@ the last pair of the list.
@c no-op since it does nothing but return the list the caller must
@c have already created.
@c
-@deffn {Scheme Procedure} list elem1 @dots{} elemN
+@deffn {Scheme Procedure} list elem @dots{}
@deffnx {C Function} scm_list_1 (elem1)
@deffnx {C Function} scm_list_2 (elem1, elem2)
@deffnx {C Function} scm_list_3 (elem1, elem2, elem3)
@@ -334,11 +334,11 @@ the last pair of the list.
@deffnx {C Function} scm_list_5 (elem1, elem2, elem3, elem4, elem5)
@deffnx {C Function} scm_list_n (elem1, @dots{}, elemN, @nicode{SCM_UNDEFINED})
@rnindex list
-Return a new list containing elements @var{elem1} to @var{elemN}.
+Return a new list containing elements @var{elem} @enddots{}.
@code{scm_list_n} takes a variable number of arguments, terminated by
the special @code{SCM_UNDEFINED}. That final @code{SCM_UNDEFINED} is
-not included in the list. None of @var{elem1} to @var{elemN} can
+not included in the list. None of @var{elem} @dots{} can
themselves be @code{SCM_UNDEFINED}, or @code{scm_list_n} will
terminate at that point.
@end deffn
@@ -430,12 +430,14 @@ pairs. This is why you should be careful when using the side-effecting
variants.
@rnindex append
-@deffn {Scheme Procedure} append lst1 @dots{} lstN
-@deffnx {Scheme Procedure} append! lst1 @dots{} lstN
+@deffn {Scheme Procedure} append lst @dots{} obj
+@deffnx {Scheme Procedure} append
+@deffnx {Scheme Procedure} append! lst @dots{} obj
+@deffnx {Scheme Procedure} append!
@deffnx {C Function} scm_append (lstlst)
@deffnx {C Function} scm_append_x (lstlst)
-Return a list comprising all the elements of lists @var{lst1} to
-@var{lstN}.
+Return a list comprising all the elements of lists @var{lst} @dots{}
+@var{obj}. If called with no arguments, return the empty list.
@lisp
(append '(x) '(y)) @result{} (x y)
@@ -443,7 +445,7 @@ Return a list comprising all the elements of lists @var{lst1} to
(append '(a (b)) '((c))) @result{} (a (b) (c))
@end lisp
-The last argument @var{lstN} may actually be any object; an improper
+The last argument @var{obj} may actually be any object; an improper
list results if the last argument is not a proper list.
@lisp
@@ -452,11 +454,11 @@ list results if the last argument is not a proper list.
@end lisp
@code{append} doesn't modify the given lists, but the return may share
-structure with the final @var{lstN}. @code{append!} modifies the
+structure with the final @var{obj}. @code{append!} modifies the
given lists to form its return.
For @code{scm_append} and @code{scm_append_x}, @var{lstlst} is a list
-of the list operands @var{lst1} @dots{} @var{lstN}. That @var{lstlst}
+of the list operands @var{lst} @dots{} @var{obj}. That @var{lstlst}
itself is not modified or used in the return.
@end deffn
@@ -709,7 +711,7 @@ thus created is determined implicitly by the number of arguments given.
@rnindex vector
@rnindex list->vector
-@deffn {Scheme Procedure} vector . l
+@deffn {Scheme Procedure} vector arg @dots{}
@deffnx {Scheme Procedure} list->vector l
@deffnx {C Function} scm_vector (l)
Return a newly allocated vector composed of the
@@ -775,19 +777,19 @@ in the vector.
@rnindex vector-length
@deffn {Scheme Procedure} vector-length vector
-@deffnx {C Function} scm_vector_length vector
+@deffnx {C Function} scm_vector_length (vector)
Return the number of elements in @var{vector} as an exact integer.
@end deffn
-@deftypefn {C Function} size_t scm_c_vector_length (SCM v)
-Return the number of elements in @var{vector} as a @code{size_t}.
+@deftypefn {C Function} size_t scm_c_vector_length (SCM vec)
+Return the number of elements in @var{vec} as a @code{size_t}.
@end deftypefn
@rnindex vector-ref
-@deffn {Scheme Procedure} vector-ref vector k
-@deffnx {C Function} scm_vector_ref vector k
-Return the contents of position @var{k} of @var{vector}.
-@var{k} must be a valid index of @var{vector}.
+@deffn {Scheme Procedure} vector-ref vec k
+@deffnx {C Function} scm_vector_ref (vec, k)
+Return the contents of position @var{k} of @var{vec}.
+@var{k} must be a valid index of @var{vec}.
@lisp
(vector-ref '#(1 1 2 3 5 8 13 21) 5) @result{} 8
(vector-ref '#(1 1 2 3 5 8 13 21)
@@ -798,9 +800,9 @@ Return the contents of position @var{k} of @var{vector}.
@end lisp
@end deffn
-@deftypefn {C Function} SCM scm_c_vector_ref (SCM v, size_t k)
+@deftypefn {C Function} SCM scm_c_vector_ref (SCM vec, size_t k)
Return the contents of position @var{k} (a @code{size_t}) of
-@var{vector}.
+@var{vec}.
@end deftypefn
A vector created by one of the dynamic vector constructor procedures
@@ -813,10 +815,10 @@ considered as constants. Currently, however, Guile does not detect this
error.
@rnindex vector-set!
-@deffn {Scheme Procedure} vector-set! vector k obj
-@deffnx {C Function} scm_vector_set_x vector k obj
-Store @var{obj} in position @var{k} of @var{vector}.
-@var{k} must be a valid index of @var{vector}.
+@deffn {Scheme Procedure} vector-set! vec k obj
+@deffnx {C Function} scm_vector_set_x (vec, k, obj)
+Store @var{obj} in position @var{k} of @var{vec}.
+@var{k} must be a valid index of @var{vec}.
The value returned by @samp{vector-set!} is unspecified.
@lisp
(let ((vec (vector 0 '(2 2 2 2) "Anna")))
@@ -825,14 +827,14 @@ The value returned by @samp{vector-set!} is unspecified.
@end lisp
@end deffn
-@deftypefn {C Function} void scm_c_vector_set_x (SCM v, size_t k, SCM obj)
-Store @var{obj} in position @var{k} (a @code{size_t}) of @var{v}.
+@deftypefn {C Function} void scm_c_vector_set_x (SCM vec, size_t k, SCM obj)
+Store @var{obj} in position @var{k} (a @code{size_t}) of @var{vec}.
@end deftypefn
@rnindex vector-fill!
-@deffn {Scheme Procedure} vector-fill! v fill
-@deffnx {C Function} scm_vector_fill_x (v, fill)
-Store @var{fill} in every position of @var{vector}. The value
+@deffn {Scheme Procedure} vector-fill! vec fill
+@deffnx {C Function} scm_vector_fill_x (vec, fill)
+Store @var{fill} in every position of @var{vec}. The value
returned by @code{vector-fill!} is unspecified.
@end deffn
@@ -1010,7 +1012,7 @@ Like @code{scm_make_bitvector}, but the length is given as a
@code{size_t}.
@end deftypefn
-@deffn {Scheme Procedure} bitvector . bits
+@deffn {Scheme Procedure} bitvector bit @dots{}
@deffnx {C Function} scm_bitvector (bits)
Create a new bitvector with the arguments as elements.
@end deffn
@@ -1031,7 +1033,7 @@ Return the element at index @var{idx} of the bitvector
@var{vec}.
@end deffn
-@deftypefn {C Function} SCM scm_c_bitvector_ref (SCM obj, size_t idx)
+@deftypefn {C Function} SCM scm_c_bitvector_ref (SCM vec, size_t idx)
Return the element at index @var{idx} of the bitvector
@var{vec}.
@end deftypefn
@@ -1042,7 +1044,7 @@ Set the element at index @var{idx} of the bitvector
@var{vec} when @var{val} is true, else clear it.
@end deffn
-@deftypefn {C Function} SCM scm_c_bitvector_set_x (SCM obj, size_t idx, SCM val)
+@deftypefn {C Function} SCM scm_c_bitvector_set_x (SCM vec, size_t idx, SCM val)
Set the element at index @var{idx} of the bitvector
@var{vec} when @var{val} is true, else clear it.
@end deftypefn
@@ -1427,8 +1429,8 @@ stored in the variable @code{*unspecified*} so that for example
@code{(make-typed-array 'u32 *unspecified* 4)} creates a uninitialized
@code{u32} vector of length 4.
-Each @var{bound} may be a positive non-zero integer @var{N}, in which
-case the index for that dimension can range from 0 through @var{N-1}; or
+Each @var{bound} may be a positive non-zero integer @var{n}, in which
+case the index for that dimension can range from 0 through @var{n}-1; or
an explicit index range specifier in the form @code{(LOWER UPPER)},
where both @var{lower} and @var{upper} are integers, possibly less than
zero, and possibly the same number (however, @var{lower} cannot be
@@ -1512,8 +1514,8 @@ For example,
@end example
@end deffn
-@deffn {Scheme Procedure} array-rank obj
-@deffnx {C Function} scm_array_rank (obj)
+@deffn {Scheme Procedure} array-rank array
+@deffnx {C Function} scm_array_rank (array)
Return the rank of @var{array}.
@end deffn
@@ -1546,7 +1548,7 @@ is unspecified.
@end deffn
@c begin (texi-doc-string "guile" "array-equal?")
-@deffn {Scheme Procedure} array-equal? array1 array2 @dots{}
+@deffn {Scheme Procedure} array-equal? array @dots{}
Return @code{#t} if all arguments are arrays with the same shape, the
same type, and have corresponding elements which are either
@code{equal?} or @code{array-equal?}. This function differs from
@@ -1563,7 +1565,7 @@ same type, and have corresponding elements which are either
@c at least vaguely matches array-map!, but is it meant to be a
@c documented feature?
-@deffn {Scheme Procedure} array-map! dst proc src1 @dots{} srcN
+@deffn {Scheme Procedure} array-map! dst proc src @dots{}
@deffnx {Scheme Procedure} array-map-in-order! dst proc src1 @dots{} srcN
@deffnx {C Function} scm_array_map_x (dst, proc, srclist)
Set each element of the @var{dst} array to values obtained from calls
@@ -1580,10 +1582,10 @@ range in @var{dst}. This ensures all @var{dst} indices are valid in
each @var{src}.
@end deffn
-@deffn {Scheme Procedure} array-for-each proc src1 @dots{} srcN
+@deffn {Scheme Procedure} array-for-each proc src1 src2 @dots{}
@deffnx {C Function} scm_array_for_each (proc, src1, srclist)
-Apply @var{proc} to each tuple of elements of @var{src1} @dots{}
-@var{srcN}, in row-major order. The value returned is unspecified.
+Apply @var{proc} to each tuple of elements of @var{src1} @var{src2}
+@dots{}, in row-major order. The value returned is unspecified.
@end deffn
@deffn {Scheme Procedure} array-index-map! dst proc
@@ -1625,10 +1627,10 @@ $\left(\matrix{%
@deffn {Scheme Procedure} uniform-array-read! ra [port_or_fd [start [end]]]
@deffnx {C Function} scm_uniform_array_read_x (ra, port_or_fd, start, end)
-Attempt to read all elements of @var{ura}, in lexicographic order, as
-binary objects from @var{port-or-fdes}.
+Attempt to read all elements of array @var{ra}, in lexicographic order, as
+binary objects from @var{port_or_fd}.
If an end of file is encountered,
-the objects up to that point are put into @var{ura}
+the objects up to that point are put into @var{ra}
(starting at the beginning) and the remainder of the array is
unchanged.
@@ -1637,21 +1639,21 @@ a specified region of a vector (or linearized array) to be read,
leaving the remainder of the vector unchanged.
@code{uniform-array-read!} returns the number of objects read.
-@var{port-or-fdes} may be omitted, in which case it defaults to the value
+@var{port_or_fd} may be omitted, in which case it defaults to the value
returned by @code{(current-input-port)}.
@end deffn
-@deffn {Scheme Procedure} uniform-array-write v [port_or_fd [start [end]]]
-@deffnx {C Function} scm_uniform_array_write (v, port_or_fd, start, end)
-Writes all elements of @var{ura} as binary objects to
-@var{port-or-fdes}.
+@deffn {Scheme Procedure} uniform-array-write ra [port_or_fd [start [end]]]
+@deffnx {C Function} scm_uniform_array_write (ra, port_or_fd, start, end)
+Writes all elements of @var{ra} as binary objects to
+@var{port_or_fd}.
The optional arguments @var{start}
and @var{end} allow
a specified region of a vector (or linearized array) to be written.
The number of objects actually written is returned.
-@var{port-or-fdes} may be
+@var{port_or_fd} may be
omitted, in which case it defaults to the value returned by
@code{(current-output-port)}.
@end deffn
@@ -1663,7 +1665,7 @@ omitted, in which case it defaults to the value returned by
@deffnx {C Function} scm_make_shared_array (oldarray, mapfunc, boundlist)
Return a new array which shares the storage of @var{oldarray}.
Changes made through either affect the same underlying storage. The
-@var{bound@dots{}} arguments are the shape of the new array, the same
+@var{bound} @dots{} arguments are the shape of the new array, the same
as @code{make-array} (@pxref{Array Procedures}).
@var{mapfunc} translates coordinates from the new array to the
@@ -1793,7 +1795,7 @@ be returned only if its elements are stored internally contiguous in
memory.
@end deffn
-@deffn {Scheme Procedure} transpose-array array dim1 @dots{}
+@deffn {Scheme Procedure} transpose-array array dim1 dim2 @dots{}
@deffnx {C Function} scm_transpose_array (array, dimlist)
Return an array sharing contents with @var{array}, but with
dimensions arranged in a different order. There must be one
@@ -2235,7 +2237,7 @@ Return a new vlist, as for SRFI-1 @code{unfold} and @code{unfold-right}
(@pxref{SRFI-1, @code{unfold}}).
@end deffn
-@deffn {Scheme Procedure} vlist-append vlists ...
+@deffn {Scheme Procedure} vlist-append vlist @dots{}
Append the given vlists and return the resulting vlist.
@end deffn
@@ -2465,7 +2467,7 @@ This section describes the basic procedures for working with
structures. @code{make-struct} creates a structure, and
@code{struct-ref} and @code{struct-set!} access write fields.
-@deffn {Scheme Procedure} make-struct vtable tail-size [init...]
+@deffn {Scheme Procedure} make-struct vtable tail-size init @dots{}
@deffnx {C Function} scm_make_struct (vtable, tail_size, init_list)
Create a new structure, with layout per the given @var{vtable}
(@pxref{Vtables}).
diff --git a/doc/ref/api-control.texi b/doc/ref/api-control.texi
index 7935d5633..fc5935070 100644
--- a/doc/ref/api-control.texi
+++ b/doc/ref/api-control.texi
@@ -44,7 +44,7 @@ If the test is true, we want to display ``greater'' to the current
output port, then display a newline. We use @code{begin} to form a
compound expression out of this sequence of sub-expressions.
-@deffn syntax begin expr1 expr2 @dots{}
+@deffn syntax begin expr @dots{}
The expression(s) are evaluated in left-to-right order and the value of
the last expression is returned as the value of the
@code{begin}-expression. This expression type is used when the
@@ -277,7 +277,7 @@ Scheme programs is normally expressed using recursion. Nevertheless,
R5RS defines a construct for programming loops, calling @code{do}. In
addition, Guile has an explicit looping syntax called @code{while}.
-@deffn syntax do ((variable init [step]) @dots{}) (test [expr @dots{}]) body @dots{}
+@deffn syntax do ((variable init [step]) @dots{}) (test expr @dots{}) body @dots{}
Bind @var{variable}s and evaluate @var{body} until @var{test} is true.
The return value is the last @var{expr} after @var{test}, if given. A
simple example will illustrate the basic form,
@@ -348,7 +348,7 @@ Run a loop executing the @var{body} forms while @var{cond} is true.
Within @code{while}, two extra bindings are provided, they can be used
from both @var{cond} and @var{body}.
-@deffn {Scheme Procedure} break break-arg...
+@deffn {Scheme Procedure} break break-arg @dots{}
Break out of the @code{while} form.
@end deffn
@@ -487,7 +487,7 @@ tag allows some useful prompt and abort idioms, discussed in the next
section.
@end deffn
-@deffn {Scheme Procedure} abort-to-prompt tag val ...
+@deffn {Scheme Procedure} abort-to-prompt tag val1 val2 @dots{}
Unwind the dynamic and control context to the nearest prompt named @var{tag},
also passing the given values.
@end deffn
@@ -599,8 +599,9 @@ The @code{%} symbol is chosen because it looks like a prompt.
Likewise there is an abbreviation for @code{abort-to-prompt}, which
assumes the default prompt tag:
-@deffn {Scheme Procedure} abort val...
-Abort to the default prompt tag, passing @var{val...} to the handler.
+@deffn {Scheme Procedure} abort val1 val2 @dots{}
+Abort to the default prompt tag, passing @var{val1} @var{val2} @dots{}
+to the handler.
@end deffn
As mentioned before, @code{(ice-9 control)} also provides other
@@ -627,19 +628,22 @@ If both continuation and handler implicitly add prompts, then the
operator is @dfn{+F+}. @code{shift} and @code{reset} are such
operators.
-@deffn {Scheme Syntax} reset body...
-Establish a prompt, and evaluate @var{body...} within that prompt.
+@deffn {Scheme Syntax} reset body1 body2 @dots{}
+Establish a prompt, and evaluate @var{body1} @var{body2} @dots{} within
+that prompt.
The prompt handler is designed to work with @code{shift}, described
below.
@end deffn
-@deffn {Scheme Syntax} shift cont body...
-Abort to the nearest @code{reset}, and evaluate @var{body...} in a
-context in which the captured continuation is bound to @var{cont}.
+@deffn {Scheme Syntax} shift cont body1 body2 @dots{}
+Abort to the nearest @code{reset}, and evaluate @var{body1} @var{body2}
+@dots{} in a context in which the captured continuation is bound to
+@var{cont}.
-As mentioned above, both the @var{body...} expression and invocations of
-@var{cont} implicitly establish a prompt.
+As mentioned above, taken together, the @var{body1} @var{body2} @dots{}
+expressions and the invocations of @var{cont} implicitly establish a
+prompt.
@end deffn
Interested readers are invited to explore Oleg Kiselyov's wonderful web
@@ -803,7 +807,7 @@ multiple values with a procedure which accepts these values as
parameters.
@rnindex values
-@deffn {Scheme Procedure} values arg1 @dots{} argN
+@deffn {Scheme Procedure} values arg @dots{}
@deffnx {C Function} scm_values (args)
Delivers all of its arguments to its continuation. Except for
continuations created by the @code{call-with-values} procedure,
@@ -1220,10 +1224,10 @@ depends on the exception type. The documentation for each possible type
of exception should specify the additional arguments that are expected
for that kind of exception.
-@deffn {Scheme Procedure} throw key . args
+@deffn {Scheme Procedure} throw key arg @dots{}
@deffnx {C Function} scm_throw (key, args)
-Invoke the catch form matching @var{key}, passing @var{args} to the
-@var{handler}.
+Invoke the catch form matching @var{key}, passing @var{arg} @dots{} to
+the @var{handler}.
@var{key} is a symbol. It will match catches of the same symbol or of
@code{#t}.
@@ -1312,9 +1316,9 @@ Guile provides a set of convenience procedures for signaling error
conditions that are implemented on top of the exception primitives just
described.
-@deffn {Scheme Procedure} error msg args @dots{}
+@deffn {Scheme Procedure} error msg arg @dots{}
Raise an error with key @code{misc-error} and a message constructed by
-displaying @var{msg} and writing @var{args}.
+displaying @var{msg} and writing @var{arg} @enddots{}.
@end deffn
@deffn {Scheme Procedure} scm-error key subr message args data
diff --git a/doc/ref/api-data.texi b/doc/ref/api-data.texi
index bcfbae365..4fc11c81d 100644
--- a/doc/ref/api-data.texi
+++ b/doc/ref/api-data.texi
@@ -695,10 +695,10 @@ value, including the special values @samp{+nan.0}, @samp{+inf.0} and
@deffn {Scheme Procedure} complex? z
@deffnx {C Function} scm_complex_p (z)
-Return @code{#t} if @var{x} is a complex number, @code{#f}
+Return @code{#t} if @var{z} is a complex number, @code{#f}
otherwise. Note that the sets of real, rational and integer
values form subsets of the set of complex numbers, i.e.@: the
-predicate will also be fulfilled if @var{x} is a real,
+predicate will also be fulfilled if @var{z} is a real,
rational or integer number.
@end deffn
@@ -2324,22 +2324,22 @@ Return @code{#t} if @var{obj} is a character set, @code{#f}
otherwise.
@end deffn
-@deffn {Scheme Procedure} char-set= . char_sets
+@deffn {Scheme Procedure} char-set= char_set @dots{}
@deffnx {C Function} scm_char_set_eq (char_sets)
Return @code{#t} if all given character sets are equal.
@end deffn
-@deffn {Scheme Procedure} char-set<= . char_sets
+@deffn {Scheme Procedure} char-set<= char_set @dots{}
@deffnx {C Function} scm_char_set_leq (char_sets)
-Return @code{#t} if every character set @var{cs}i is a subset
-of character set @var{cs}i+1.
+Return @code{#t} if every character set @var{char_set}i is a subset
+of character set @var{char_set}i+1.
@end deffn
@deffn {Scheme Procedure} char-set-hash cs [bound]
@deffnx {C Function} scm_char_set_hash (cs, bound)
Compute a hash value for the character set @var{cs}. If
@var{bound} is given and non-zero, it restricts the
-returned value to the range 0 @dots{} @var{bound - 1}.
+returned value to the range 0 @dots{} @var{bound} - 1.
@end deffn
@c ===================================================================
@@ -2443,8 +2443,8 @@ Return a newly allocated character set containing all
characters in @var{cs}.
@end deffn
-@deffn {Scheme Procedure} char-set . rest
-@deffnx {C Function} scm_char_set (rest)
+@deffn {Scheme Procedure} char-set chr @dots{}
+@deffnx {C Function} scm_char_set (chrs)
Return a character set containing all given characters.
@end deffn
@@ -2607,26 +2607,26 @@ such as union, complement, intersection etc. All of these procedures
provide side-effecting variants, which modify their character set
argument(s).
-@deffn {Scheme Procedure} char-set-adjoin cs . rest
-@deffnx {C Function} scm_char_set_adjoin (cs, rest)
+@deffn {Scheme Procedure} char-set-adjoin cs chr @dots{}
+@deffnx {C Function} scm_char_set_adjoin (cs, chrs)
Add all character arguments to the first argument, which must
be a character set.
@end deffn
-@deffn {Scheme Procedure} char-set-delete cs . rest
-@deffnx {C Function} scm_char_set_delete (cs, rest)
+@deffn {Scheme Procedure} char-set-delete cs chr @dots{}
+@deffnx {C Function} scm_char_set_delete (cs, chrs)
Delete all character arguments from the first argument, which
must be a character set.
@end deffn
-@deffn {Scheme Procedure} char-set-adjoin! cs . rest
-@deffnx {C Function} scm_char_set_adjoin_x (cs, rest)
+@deffn {Scheme Procedure} char-set-adjoin! cs chr @dots{}
+@deffnx {C Function} scm_char_set_adjoin_x (cs, chrs)
Add all character arguments to the first argument, which must
be a character set.
@end deffn
-@deffn {Scheme Procedure} char-set-delete! cs . rest
-@deffnx {C Function} scm_char_set_delete_x (cs, rest)
+@deffn {Scheme Procedure} char-set-delete! cs chr @dots{}
+@deffnx {C Function} scm_char_set_delete_x (cs, chrs)
Delete all character arguments from the first argument, which
must be a character set.
@end deffn
@@ -2642,28 +2642,28 @@ characters). It may be helpful to modify the output of
@code{char-set-complement} by computing its intersection with the set
of designated code points, @code{char-set:designated}.
-@deffn {Scheme Procedure} char-set-union . rest
-@deffnx {C Function} scm_char_set_union (rest)
+@deffn {Scheme Procedure} char-set-union cs @dots{}
+@deffnx {C Function} scm_char_set_union (char_sets)
Return the union of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-intersection . rest
-@deffnx {C Function} scm_char_set_intersection (rest)
+@deffn {Scheme Procedure} char-set-intersection cs @dots{}
+@deffnx {C Function} scm_char_set_intersection (char_sets)
Return the intersection of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-difference cs1 . rest
-@deffnx {C Function} scm_char_set_difference (cs1, rest)
+@deffn {Scheme Procedure} char-set-difference cs1 cs @dots{}
+@deffnx {C Function} scm_char_set_difference (cs1, char_sets)
Return the difference of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-xor . rest
-@deffnx {C Function} scm_char_set_xor (rest)
+@deffn {Scheme Procedure} char-set-xor cs @dots{}
+@deffnx {C Function} scm_char_set_xor (char_sets)
Return the exclusive-or of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-diff+intersection cs1 . rest
-@deffnx {C Function} scm_char_set_diff_plus_intersection (cs1, rest)
+@deffn {Scheme Procedure} char-set-diff+intersection cs1 cs @dots{}
+@deffnx {C Function} scm_char_set_diff_plus_intersection (cs1, char_sets)
Return the difference and the intersection of all argument
character sets.
@end deffn
@@ -2673,28 +2673,28 @@ character sets.
Return the complement of the character set @var{cs}.
@end deffn
-@deffn {Scheme Procedure} char-set-union! cs1 . rest
-@deffnx {C Function} scm_char_set_union_x (cs1, rest)
+@deffn {Scheme Procedure} char-set-union! cs1 cs @dots{}
+@deffnx {C Function} scm_char_set_union_x (cs1, char_sets)
Return the union of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-intersection! cs1 . rest
-@deffnx {C Function} scm_char_set_intersection_x (cs1, rest)
+@deffn {Scheme Procedure} char-set-intersection! cs1 cs @dots{}
+@deffnx {C Function} scm_char_set_intersection_x (cs1, char_sets)
Return the intersection of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-difference! cs1 . rest
-@deffnx {C Function} scm_char_set_difference_x (cs1, rest)
+@deffn {Scheme Procedure} char-set-difference! cs1 cs @dots{}
+@deffnx {C Function} scm_char_set_difference_x (cs1, char_sets)
Return the difference of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-xor! cs1 . rest
-@deffnx {C Function} scm_char_set_xor_x (cs1, rest)
+@deffn {Scheme Procedure} char-set-xor! cs1 cs @dots{}
+@deffnx {C Function} scm_char_set_xor_x (cs1, char_sets)
Return the exclusive-or of all argument character sets.
@end deffn
-@deffn {Scheme Procedure} char-set-diff+intersection! cs1 cs2 . rest
-@deffnx {C Function} scm_char_set_diff_plus_intersection_x (cs1, cs2, rest)
+@deffn {Scheme Procedure} char-set-diff+intersection! cs1 cs2 cs @dots{}
+@deffnx {C Function} scm_char_set_diff_plus_intersection_x (cs1, cs2, char_sets)
Return the difference and the intersection of all argument
character sets.
@end deffn
@@ -2714,7 +2714,7 @@ useful, several predefined character set variables exist.
These character sets are locale independent and are not recomputed
upon a @code{setlocale} call. They contain characters from the whole
range of Unicode code points. For instance, @code{char-set:letter}
-contains about 94,000 characters.
+contains about 100,000 characters.
@defvr {Scheme Variable} char-set:lower-case
@defvrx {C Variable} scm_char_set_lower_case
@@ -3099,7 +3099,7 @@ reverse order.
Return a newly allocated string of
length @var{k}. If @var{chr} is given, then all elements of
the string are initialized to @var{chr}, otherwise the contents
-of the @var{string} are unspecified.
+of the string are unspecified.
@end deffn
@deftypefn {C Function} SCM scm_c_make_string (size_t len, SCM chr)
@@ -3118,7 +3118,7 @@ produce the corresponding string element. The order in which
@deffn {Scheme Procedure} string-join ls [delimiter [grammar]]
@deffnx {C Function} scm_string_join (ls, delimiter, grammar)
Append the string in the string list @var{ls}, using the string
-@var{delim} as a delimiter between the elements of @var{ls}.
+@var{delimiter} as a delimiter between the elements of @var{ls}.
@var{grammar} is a symbol which specifies how the delimiter is
placed between the strings, and defaults to the symbol
@code{infix}.
@@ -3279,7 +3279,7 @@ Return all but the last @var{n} characters of @var{s}.
@deffnx {C Function} scm_string_pad (s, len, chr, start, end)
@deffnx {C Function} scm_string_pad_right (s, len, chr, start, end)
Take characters @var{start} to @var{end} from the string @var{s} and
-either pad with @var{char} or truncate them to give @var{len}
+either pad with @var{chr} or truncate them to give @var{len}
characters.
@code{string-pad} pads or truncates on the left, so for example
@@ -3404,11 +3404,11 @@ comparison. See @xref{Text Collation, the @code{(ice-9
i18n)} module}, for locale-dependent string comparison.
@rnindex string=?
-@deffn {Scheme Procedure} string=? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string=? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_equal_p (s1, s2, rest)
-Lexicographic equality predicate; return @code{#t} if the two
-strings are the same length and contain the same characters in
-the same positions, otherwise return @code{#f}.
+Lexicographic equality predicate; return @code{#t} if all strings are
+the same length and contain the same characters in the same positions,
+otherwise return @code{#f}.
The procedure @code{string-ci=?} treats upper and lower case
letters as though they were the same character, but
@@ -3417,72 +3417,80 @@ characters.
@end deffn
@rnindex string<?
-@deffn {Scheme Procedure} string<? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string<? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_less_p (s1, s2, rest)
-Lexicographic ordering predicate; return @code{#t} if @var{s1}
-is lexicographically less than @var{s2}.
+Lexicographic ordering predicate; return @code{#t} if, for every pair of
+consecutive string arguments @var{str_i} and @var{str_i+1}, @var{str_i} is
+lexicographically less than @var{str_i+1}.
@end deffn
@rnindex string<=?
-@deffn {Scheme Procedure} string<=? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string<=? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_leq_p (s1, s2, rest)
-Lexicographic ordering predicate; return @code{#t} if @var{s1}
-is lexicographically less than or equal to @var{s2}.
+Lexicographic ordering predicate; return @code{#t} if, for every pair of
+consecutive string arguments @var{str_i} and @var{str_i+1}, @var{str_i} is
+lexicographically less than or equal to @var{str_i+1}.
@end deffn
@rnindex string>?
-@deffn {Scheme Procedure} string>? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string>? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_gr_p (s1, s2, rest)
-Lexicographic ordering predicate; return @code{#t} if @var{s1}
-is lexicographically greater than @var{s2}.
+Lexicographic ordering predicate; return @code{#t} if, for every pair of
+consecutive string arguments @var{str_i} and @var{str_i+1}, @var{str_i} is
+lexicographically greater than @var{str_i+1}.
@end deffn
@rnindex string>=?
-@deffn {Scheme Procedure} string>=? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string>=? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_geq_p (s1, s2, rest)
-Lexicographic ordering predicate; return @code{#t} if @var{s1}
-is lexicographically greater than or equal to @var{s2}.
+Lexicographic ordering predicate; return @code{#t} if, for every pair of
+consecutive string arguments @var{str_i} and @var{str_i+1}, @var{str_i} is
+lexicographically greater than or equal to @var{str_i+1}.
@end deffn
@rnindex string-ci=?
-@deffn {Scheme Procedure} string-ci=? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string-ci=? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_ci_equal_p (s1, s2, rest)
Case-insensitive string equality predicate; return @code{#t} if
-the two strings are the same length and their component
+all strings are the same length and their component
characters match (ignoring case) at each position; otherwise
return @code{#f}.
@end deffn
@rnindex string-ci<?
-@deffn {Scheme Procedure} string-ci<? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string-ci<? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_ci_less_p (s1, s2, rest)
-Case insensitive lexicographic ordering predicate; return
-@code{#t} if @var{s1} is lexicographically less than @var{s2}
+Case insensitive lexicographic ordering predicate; return @code{#t} if,
+for every pair of consecutive string arguments @var{str_i} and
+@var{str_i+1}, @var{str_i} is lexicographically less than @var{str_i+1}
regardless of case.
@end deffn
@rnindex string<=?
-@deffn {Scheme Procedure} string-ci<=? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string-ci<=? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_ci_leq_p (s1, s2, rest)
-Case insensitive lexicographic ordering predicate; return
-@code{#t} if @var{s1} is lexicographically less than or equal
-to @var{s2} regardless of case.
+Case insensitive lexicographic ordering predicate; return @code{#t} if,
+for every pair of consecutive string arguments @var{str_i} and
+@var{str_i+1}, @var{str_i} is lexicographically less than or equal to
+@var{str_i+1} regardless of case.
@end deffn
@rnindex string-ci>?
-@deffn {Scheme Procedure} string-ci>? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string-ci>? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_ci_gr_p (s1, s2, rest)
-Case insensitive lexicographic ordering predicate; return
-@code{#t} if @var{s1} is lexicographically greater than
-@var{s2} regardless of case.
+Case insensitive lexicographic ordering predicate; return @code{#t} if,
+for every pair of consecutive string arguments @var{str_i} and
+@var{str_i+1}, @var{str_i} is lexicographically greater than
+@var{str_i+1} regardless of case.
@end deffn
@rnindex string-ci>=?
-@deffn {Scheme Procedure} string-ci>=? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string-ci>=? s1 s2 s3 @dots{}
@deffnx {C Function} scm_i_string_ci_geq_p (s1, s2, rest)
-Case insensitive lexicographic ordering predicate; return
-@code{#t} if @var{s1} is lexicographically greater than or
-equal to @var{s2} regardless of case.
+Case insensitive lexicographic ordering predicate; return @code{#t} if,
+for every pair of consecutive string arguments @var{str_i} and
+@var{str_i+1}, @var{str_i} is lexicographically greater than or equal to
+@var{str_i+1} regardless of case.
@end deffn
@deffn {Scheme Procedure} string-compare s1 s2 proc_lt proc_eq proc_gt [start1 [end1 [start2 [end2]]]]
@@ -3587,12 +3595,12 @@ case-insensitively.
@deffn {Scheme Procedure} string-hash s [bound [start [end]]]
@deffnx {C Function} scm_substring_hash (s, bound, start, end)
-Compute a hash value for @var{S}. The optional argument @var{bound} is a non-negative exact integer specifying the range of the hash function. A positive value restricts the return value to the range [0,bound).
+Compute a hash value for @var{s}. The optional argument @var{bound} is a non-negative exact integer specifying the range of the hash function. A positive value restricts the return value to the range [0,bound).
@end deffn
@deffn {Scheme Procedure} string-hash-ci s [bound [start [end]]]
@deffnx {C Function} scm_substring_hash_ci (s, bound, start, end)
-Compute a hash value for @var{S}. The optional argument @var{bound} is a non-negative exact integer specifying the range of the hash function. A positive value restricts the return value to the range [0,bound).
+Compute a hash value for @var{s}. The optional argument @var{bound} is a non-negative exact integer specifying the range of the hash function. A positive value restricts the return value to the range [0,bound).
@end deffn
Because the same visual appearance of an abstract Unicode character can
@@ -3934,10 +3942,10 @@ operate on. The return value is unspecified.
@end deffn
@rnindex string-append
-@deffn {Scheme Procedure} string-append . args
+@deffn {Scheme Procedure} string-append arg @dots{}
@deffnx {C Function} scm_string_append (args)
Return a newly allocated string whose characters form the
-concatenation of the given strings, @var{args}.
+concatenation of the given strings, @var{arg} @enddots{}.
@example
(let ((h "hello "))
@@ -3946,17 +3954,16 @@ concatenation of the given strings, @var{args}.
@end example
@end deffn
-@deffn {Scheme Procedure} string-append/shared . rest
-@deffnx {C Function} scm_string_append_shared (rest)
+@deffn {Scheme Procedure} string-append/shared arg @dots{}
+@deffnx {C Function} scm_string_append_shared (args)
Like @code{string-append}, but the result may share memory
with the argument strings.
@end deffn
@deffn {Scheme Procedure} string-concatenate ls
@deffnx {C Function} scm_string_concatenate (ls)
-Append the elements of @var{ls} (which must be strings)
-together into a single string. Guaranteed to return a freshly
-allocated string.
+Append the elements (which must be strings) of @var{ls} together into a
+single string. Guaranteed to return a freshly allocated string.
@end deffn
@deffn {Scheme Procedure} string-concatenate-reverse ls [final_string [end]]
@@ -5181,9 +5188,9 @@ Return a newly allocated symbol made from a list of characters.
@end deffn
@rnindex symbol-append
-@deffn {Scheme Procedure} symbol-append . args
+@deffn {Scheme Procedure} symbol-append arg @dots{}
Return a newly allocated symbol whose characters form the
-concatenation of the given symbols, @var{args}.
+concatenation of the given symbols, @var{arg} @enddots{}.
@example
(let ((h 'hello))
@@ -5253,15 +5260,15 @@ When you want to do more from C, you should convert between symbols
and strings using @code{scm_symbol_to_string} and
@code{scm_string_to_symbol} and work with the strings.
-@deffn {C Function} scm_from_latin1_symbol (const char *name)
-@deffnx {C Function} scm_from_utf8_symbol (const char *name)
+@deftypefn {C Function} scm_from_latin1_symbol (const char *name)
+@deftypefnx {C Function} scm_from_utf8_symbol (const char *name)
Construct and return a Scheme symbol whose name is specified by the
null-terminated C string @var{name}. These are appropriate when
the C string is hard-coded in the source code.
-@end deffn
+@end deftypefn
-@deffn {C Function} scm_from_locale_symbol (const char *name)
-@deffnx {C Function} scm_from_locale_symboln (const char *name, size_t len)
+@deftypefn {C Function} scm_from_locale_symbol (const char *name)
+@deftypefnx {C Function} scm_from_locale_symboln (const char *name, size_t len)
Construct and return a Scheme symbol whose name is specified by
@var{name}. For @code{scm_from_locale_symbol}, @var{name} must be null
terminated; for @code{scm_from_locale_symboln} the length of @var{name} is
@@ -5271,7 +5278,7 @@ Note that these functions should @emph{not} be used when @var{name} is a
C string constant, because there is no guarantee that the current locale
will match that of the source code. In such cases, use
@code{scm_from_latin1_symbol} or @code{scm_from_utf8_symbol}.
-@end deffn
+@end deftypefn
@deftypefn {C Function} SCM scm_take_locale_symbol (char *str)
@deftypefnx {C Function} SCM scm_take_locale_symboln (char *str, size_t len)
diff --git a/doc/ref/api-debug.texi b/doc/ref/api-debug.texi
index 2083daab6..cf9ea5aca 100644
--- a/doc/ref/api-debug.texi
+++ b/doc/ref/api-debug.texi
@@ -80,15 +80,15 @@ describes the Scheme stack at that point.
Use @code{start-stack} to limit the stack extent captured by future
@code{make-stack} calls.
-@deffn {Scheme Procedure} make-stack obj . args
+@deffn {Scheme Procedure} make-stack obj arg @dots{}
@deffnx {C Function} scm_make_stack (obj, args)
Create a new stack. If @var{obj} is @code{#t}, the current
evaluation stack is used for creating the stack frames,
otherwise the frames are taken from @var{obj} (which must be
a continuation or a frame object).
-@var{args} should be a list containing any combination of
-integer, procedure, prompt tag and @code{#t} values.
+@var{arg} @dots{} can be any combination of integer, procedure, prompt
+tag and @code{#t} values.
These values specify various ways of cutting away uninteresting
stack frames from the top and bottom of the stack that
@@ -96,7 +96,7 @@ stack frames from the top and bottom of the stack that
@code{(@var{inner_cut_1} @var{outer_cut_1} @var{inner_cut_2}
@var{outer_cut_2} @dots{})}.
-Each @var{inner_cut_N} can be @code{#t}, an integer, a prompt
+Each @var{inner_cut_i} can be @code{#t}, an integer, a prompt
tag, or a procedure. @code{#t} means to cut away all frames up
to but excluding the first user module frame. An integer means
to cut away exactly that number of frames. A prompt tag means
@@ -105,14 +105,14 @@ tag. A procedure means to cut away all frames up to but
excluding the application frame whose procedure matches the
specified one.
-Each @var{outer_cut_N} can be an integer, a prompt tag, or a
+Each @var{outer_cut_i} can be an integer, a prompt tag, or a
procedure. An integer means to cut away that number of frames.
A prompt tag means to cut away all frames that are outside a
prompt with the given tag. A procedure means to cut away
frames down to but excluding the application frame whose
procedure matches the specified one.
-If the @var{outer_cut_N} of the last pair is missing, it is
+If the @var{outer_cut_i} of the last pair is missing, it is
taken as 0.
@end deffn
diff --git a/doc/ref/api-evaluation.texi b/doc/ref/api-evaluation.texi
index 8c41d1efd..611283225 100644
--- a/doc/ref/api-evaluation.texi
+++ b/doc/ref/api-evaluation.texi
@@ -444,10 +444,10 @@ it as code.
@deffn {Scheme Procedure} eval exp module_or_state
@deffnx {C Function} scm_eval (exp, module_or_state)
Evaluate @var{exp}, a list representing a Scheme expression,
-in the top-level environment specified by @var{module}.
+in the top-level environment specified by @var{module_or_state}.
While @var{exp} is evaluated (using @code{primitive-eval}),
-@var{module} is made the current module. The current module
-is reset to its previous value when @var{eval} returns.
+@var{module_or_state} is made the current module. The current module
+is reset to its previous value when @code{eval} returns.
XXX - dynamic states.
Example: (eval '(+ 1 2) (interaction-environment))
@end deffn
@@ -504,23 +504,22 @@ eval-string)}, evaluating within @var{module} or the current module.
of an @code{SCM}.
@end deftypefn
-@deffn {Scheme Procedure} apply proc arg1 @dots{} argN arglst
+@deffn {Scheme Procedure} apply proc arg @dots{} arglst
@deffnx {C Function} scm_apply_0 (proc, arglst)
@deffnx {C Function} scm_apply_1 (proc, arg1, arglst)
@deffnx {C Function} scm_apply_2 (proc, arg1, arg2, arglst)
@deffnx {C Function} scm_apply_3 (proc, arg1, arg2, arg3, arglst)
@deffnx {C Function} scm_apply (proc, arg, rest)
@rnindex apply
-Call @var{proc} with arguments @var{arg1} @dots{} @var{argN} plus the
+Call @var{proc} with arguments @var{arg} @dots{} and the
elements of the @var{arglst} list.
@code{scm_apply} takes parameters corresponding to a Scheme level
-@code{(lambda (proc arg . rest) ...)}. So @var{arg} and all but the
-last element of the @var{rest} list make up
-@var{arg1}@dots{}@var{argN} and the last element of @var{rest} is the
-@var{arglst} list. Or if @var{rest} is the empty list @code{SCM_EOL}
-then there's no @var{arg1}@dots{}@var{argN} and @var{arg} is the
-@var{arglst}.
+@code{(lambda (proc arg1 . rest) ...)}. So @var{arg1} and all but the
+last element of the @var{rest} list make up @var{arg} @dots{}, and the
+last element of @var{rest} is the @var{arglst} list. Or if @var{rest}
+is the empty list @code{SCM_EOL} then there's no @var{arg} @dots{}, and
+(@var{arg1}) is the @var{arglst}.
@var{arglst} is not modified, but the @var{rest} list passed to
@code{scm_apply} is modified.
@@ -645,6 +644,7 @@ name is as for @code{compile-file} (see below).
@item -W @var{warning}
@itemx --warn=@var{warning}
+@cindex warnings, compiler
Emit warnings of type @var{warning}; use @code{--warn=help} for a list
of available warnings and their description. Currently recognized
warnings include @code{unused-variable}, @code{unused-toplevel},
@@ -1012,7 +1012,7 @@ by @code{file-encoding}, if any, again by using
@code{set-port-encoding!}. Then the code can be read as normal.
@deffn {Scheme Procedure} file-encoding port
-@deffnx {C Function} scm_file_encoding port
+@deffnx {C Function} scm_file_encoding (port)
Scan the port for an Emacs-like character coding declaration near the
top of the contents of a port with random-accessible contents
(@pxref{Recognize Coding, how Emacs recognizes file encoding,, emacs,
diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi
index 6ece7f8ed..2e60d8a22 100644
--- a/doc/ref/api-foreign.texi
+++ b/doc/ref/api-foreign.texi
@@ -540,7 +540,7 @@ A value returned by @code{dynamic-pointer} is a Scheme wrapper for a C
pointer.
@deffn {Scheme Procedure} pointer-address pointer
-@deffnx {C Function} scm_pointer_address pointer
+@deffnx {C Function} scm_pointer_address (pointer)
Return the numerical value of @var{pointer}.
@example
@@ -594,7 +594,7 @@ module contains procedures that can be used to convert byte sequences to
Scheme objects such as strings, floating point numbers, or integers.
@deffn {Scheme Procedure} pointer->bytevector pointer len [offset [uvec_type]]
-@deffnx {C Function} scm_foreign_to_bytevector pointer len offset uvec_type
+@deffnx {C Function} scm_foreign_to_bytevector (pointer, len, offset, uvec_type)
Return a bytevector aliasing the @var{len} bytes pointed to by
@var{pointer}.
@@ -614,7 +614,7 @@ Mutating the returned bytevector mutates the memory pointed to by
@end deffn
@deffn {Scheme Procedure} bytevector->pointer bv [offset]
-@deffnx {C Function} scm_bytevector_to_pointer bv offset
+@deffnx {C Function} scm_bytevector_to_pointer (bv, offset)
Return a pointer pointer aliasing the memory pointed to by @var{bv} or
@var{offset} bytes after @var{bv} when @var{offset} is passed.
@end deffn
@@ -740,7 +740,7 @@ its type, offset, and alignment. Guile has some primitives to support
this.
@deffn {Scheme Procedure} sizeof type
-@deffnx {C Function} scm_sizeof type
+@deffnx {C Function} scm_sizeof (type)
Return the size of @var{type}, in bytes.
@var{type} should be a valid C type, like @code{int}.
@@ -751,7 +751,7 @@ also be a list of types, in which case the size of a
@end deffn
@deffn {Scheme Procedure} alignof type
-@deffnx {C Function} scm_alignof type
+@deffnx {C Function} scm_alignof (type)
Return the alignment of @var{type}, in bytes.
@var{type} should be a valid C type, like @code{int}.
@@ -801,7 +801,7 @@ Of course, the land of C is not all nouns and no verbs: there are
functions too, and Guile allows you to call them.
@deffn {Scheme Procedure} pointer->procedure return_type func_ptr arg_types
-@deffnx {C Procedure} scm_pointer_to_procedure return_type func_ptr arg_types
+@deffnx {C Procedure} scm_pointer_to_procedure (return_type, func_ptr, arg_types)
Make a foreign function.
Given the foreign void pointer @var{func_ptr}, its argument and
diff --git a/doc/ref/api-io.texi b/doc/ref/api-io.texi
index 9799c31d5..24c2706df 100644
--- a/doc/ref/api-io.texi
+++ b/doc/ref/api-io.texi
@@ -129,7 +129,7 @@ this fluid otherwise.
@end defvr
@deffn {Scheme Procedure} port-encoding port
-@deffnx {C Function} scm_port_encoding
+@deffnx {C Function} scm_port_encoding (port)
Returns, as a string, the character encoding that @var{port} uses to interpret
its input and output. The value @code{#f} is equivalent to @code{"ISO-8859-1"}.
@end deffn
@@ -251,7 +251,7 @@ sequence when the error is raised.
@deffn {Scheme Procedure} unread-char cobj [port]
@deffnx {C Function} scm_unread_char (cobj, port)
-Place @var{char} in @var{port} so that it will be read by the
+Place character @var{cobj} in @var{port} so that it will be read by the
next read operation. If called multiple times, the unread characters
will be read again in last-in first-out order. If @var{port} is
not supplied, the current input port is used.
@@ -343,7 +343,7 @@ the current output port.
@var{message} can contain @code{~A} (was @code{%s}) and
@code{~S} (was @code{%S}) escapes. When printed,
the escapes are replaced with corresponding members of
-@var{ARGS}:
+@var{args}:
@code{~A} formats using @code{display} and @code{~S} formats
using @code{write}.
If @var{destination} is @code{#t}, then use the current output
@@ -426,7 +426,7 @@ open.
@deffn {Scheme Procedure} seek fd_port offset whence
@deffnx {C Function} scm_seek (fd_port, offset, whence)
-Sets the current position of @var{fd/port} to the integer
+Sets the current position of @var{fd_port} to the integer
@var{offset}, which is interpreted according to the value of
@var{whence}.
@@ -441,7 +441,7 @@ Seek from the current position.
@defvar SEEK_END
Seek from the end of the file.
@end defvar
-If @var{fd/port} is a file descriptor, the underlying system
+If @var{fd_port} is a file descriptor, the underlying system
call is @code{lseek}. @var{port} may be a string port.
The value returned is the new position in the file. This means
@@ -454,7 +454,7 @@ that the current position of a port can be obtained using:
@deffn {Scheme Procedure} ftell fd_port
@deffnx {C Function} scm_ftell (fd_port)
Return an integer representing the current position of
-@var{fd/port}, measured from the beginning. Equivalent to:
+@var{fd_port}, measured from the beginning. Equivalent to:
@lisp
(seek port 0 SEEK_CUR)
@@ -922,7 +922,7 @@ of the respective current port is restored.
The current port setting is managed with @code{dynamic-wind}, so the
previous value is restored no matter how @var{thunk} exits (eg.@: an
exception), and if @var{thunk} is re-entered (via a captured
-continuation) then it's set again to the @var{FILENAME} port.
+continuation) then it's set again to the @var{filename} port.
The port is closed when @var{thunk} returns normally, but not when
exited via an exception or new continuation. This ensures it's still
@@ -1414,7 +1414,7 @@ This condition type could be defined by
An exception with this type is raised when one of the operations for
textual output to a port encounters a character that cannot be
translated into bytes by the output direction of the port's transcoder.
-@var{Char} is the character that could not be encoded.
+@var{char} is the character that could not be encoded.
@end deffn
@deffn {Scheme Syntax} error-handling-mode @var{error-handling-mode-symbol}
@@ -1430,7 +1430,7 @@ symbol acceptable as a @var{handling-mode} argument to
raised.
@quotation Note
- Only the name of @var{error-handling-style-symbol} is significant.
+ Only the name of @var{error-handling-mode-symbol} is significant.
@end quotation
The error-handling mode of a transcoder specifies the behavior
@@ -1470,7 +1470,7 @@ symbol; and @var{handling-mode}, if present, an error-handling-mode
symbol.
@var{eol-style} may be omitted, in which case it defaults to the native
-end-of-line style of the underlying platform. @var{Handling-mode} may
+end-of-line style of the underlying platform. @var{handling-mode} may
be omitted, in which case it defaults to @code{replace}. The result is
a transcoder with the behavior specified by its arguments.
@end deffn
@@ -1566,11 +1566,11 @@ encoding. Likewise, Guile does not prevent use of
@end deffn
@deffn {Scheme Procedure} textual-port? port
-Always return @var{#t}, as all ports can be used for textual I/O in
+Always return @code{#t}, as all ports can be used for textual I/O in
Guile.
@end deffn
-@deffn {Scheme Procedure} transcoded-port obj
+@deffn {Scheme Procedure} transcoded-port binary-port transcoder
The @code{transcoded-port} procedure
returns a new textual port with the specified @var{transcoder}.
Otherwise the new textual port's state is largely the same as
@@ -1629,12 +1629,12 @@ of @var{proc}. Return the return values of @var{proc}.
@node R6RS Input Ports
@subsubsection Input Ports
-@deffn {Scheme Procedure} input-port? obj@
+@deffn {Scheme Procedure} input-port? obj
Returns @code{#t} if the argument is an input port (or a combined input
and output port), and returns @code{#f} otherwise.
@end deffn
-@deffn {Scheme Procedure} port-eof? port
+@deffn {Scheme Procedure} port-eof? input-port
Returns @code{#t}
if the @code{lookahead-u8} procedure (if @var{input-port} is a binary port)
or the @code{lookahead-char} procedure (if @var{input-port} is a textual port)
@@ -1648,7 +1648,7 @@ but the port cannot be determined to be at end of file.
@deffnx {Scheme Procedure} open-file-input-port filename file-options
@deffnx {Scheme Procedure} open-file-input-port filename file-options buffer-mode
@deffnx {Scheme Procedure} open-file-input-port filename file-options buffer-mode maybe-transcoder
-@var{Maybe-transcoder} must be either a transcoder or @code{#f}.
+@var{maybe-transcoder} must be either a transcoder or @code{#f}.
The @code{open-file-input-port} procedure returns an
input port for the named file. The @var{file-options} and
@@ -1718,13 +1718,13 @@ indicating the number of bytes read, or @code{0} to indicate the
end-of-file.
Optionally, if @var{get-position} is not @code{#f}, it must be a thunk
-that will be called when @var{port-position} is invoked on the custom
+that will be called when @code{port-position} is invoked on the custom
binary port and should return an integer indicating the position within
the underlying data stream; if @var{get-position} was not supplied, the
-returned port does not support @var{port-position}.
+returned port does not support @code{port-position}.
Likewise, if @var{set-position!} is not @code{#f}, it should be a
-one-argument procedure. When @var{set-port-position!} is invoked on the
+one-argument procedure. When @code{set-port-position!} is invoked on the
custom binary input port, @var{set-position!} is passed an integer
indicating the position of the next byte is to read.
@@ -1806,7 +1806,7 @@ end-of-file object (if no data were available).
@node R6RS Textual Input
@subsubsection Textual Input
-@deffn {Scheme Procedure} get-char port
+@deffn {Scheme Procedure} get-char textual-input-port
Reads from @var{textual-input-port}, blocking as necessary, until a
complete character is available from @var{textual-input-port},
or until an end of file is reached.
@@ -1817,14 +1817,14 @@ point past the character. If an end of file is reached before any
character is read, @code{get-char} returns the end-of-file object.
@end deffn
-@deffn {Scheme Procedure} lookahead-char port
+@deffn {Scheme Procedure} lookahead-char textual-input-port
The @code{lookahead-char} procedure is like @code{get-char}, but it does
not update @var{textual-input-port} to point past the character.
@end deffn
-@deffn {Scheme Procedure} get-string-n port count
+@deffn {Scheme Procedure} get-string-n textual-input-port count
-@var{Count} must be an exact, non-negative integer object, representing
+@var{count} must be an exact, non-negative integer object, representing
the number of characters to be read.
The @code{get-string-n} procedure reads from @var{textual-input-port},
@@ -1840,11 +1840,11 @@ to point just past the characters read. If no characters can be read
before an end of file, the end-of-file object is returned.
@end deffn
-@deffn {Scheme Procedure} get-string-n! port string start count
+@deffn {Scheme Procedure} get-string-n! textual-input-port string start count
-@var{Start} and @var{count} must be exact, non-negative integer objects,
+@var{start} and @var{count} must be exact, non-negative integer objects,
with @var{count} representing the number of characters to be read.
-@var{String} must be a string with at least $@var{start} + @var{count}$
+@var{string} must be a string with at least $@var{start} + @var{count}$
characters.
The @code{get-string-n!} procedure reads from @var{textual-input-port}
@@ -1858,7 +1858,7 @@ exact integer object. If no characters can be read before an end of
file, the end-of-file object is returned.
@end deffn
-@deffn {Scheme Procedure} get-string-all port count
+@deffn {Scheme Procedure} get-string-all textual-input-port count
Reads from @var{textual-input-port} until an end of file, decoding
characters in the same manner as @code{get-string-n} and
@code{get-string-n!}.
@@ -1868,7 +1868,7 @@ all the characters decoded from that data are returned. If no character
precedes the end of file, the end-of-file object is returned.
@end deffn
-@deffn {Scheme Procedure} get-line port
+@deffn {Scheme Procedure} get-line textual-input-port
Reads from @var{textual-input-port} up to and including the linefeed
character or end of file, decoding characters in the same manner as
@code{get-string-n} and @code{get-string-n!}.
@@ -1887,7 +1887,7 @@ any characters are read, the end-of-file object is returned.
@end quotation
@end deffn
-@deffn {Scheme Procedure} get-datum port count
+@deffn {Scheme Procedure} get-datum textual-input-port count
Reads an external representation from @var{textual-input-port} and returns the
datum it represents. The @code{get-datum} procedure returns the next
datum that can be parsed from the given @var{textual-input-port}, updating
@@ -2048,7 +2048,7 @@ Writes @var{char} to the port. The @code{put-char} procedure returns
@code{put-string} procedure returns an unspecified value.
@end deffn
-@deffn {Scheme Procedure} put-datum port datum
+@deffn {Scheme Procedure} put-datum textual-output-port datum
@var{datum} should be a datum value. The @code{put-datum} procedure
writes an external representation of @var{datum} to
@var{textual-output-port}. The specific external representation is
diff --git a/doc/ref/api-macros.texi b/doc/ref/api-macros.texi
index f6a03bc32..347d02589 100644
--- a/doc/ref/api-macros.texi
+++ b/doc/ref/api-macros.texi
@@ -81,8 +81,9 @@ source code will invoke the syntax transformer defined by @var{transformer}.
One can also establish local syntactic bindings with @code{let-syntax}.
-@deffn {Syntax} let-syntax ((keyword transformer) ...) exp...
-Bind @var{keyword...} to @var{transformer...} while expanding @var{exp...}.
+@deffn {Syntax} let-syntax ((keyword transformer) @dots{}) exp1 exp2 @dots{}
+Bind each @var{keyword} to its corresponding @var{transformer} while
+expanding @var{exp1} @var{exp2} @enddots{}.
A @code{let-syntax} binding only exists at expansion-time.
@@ -104,8 +105,9 @@ top-level, or locally. Just as a local @code{define} expands out to an instance
of @code{letrec}, a local @code{define-syntax} expands out to
@code{letrec-syntax}.
-@deffn {Syntax} letrec-syntax ((keyword transformer) ...) exp...
-Bind @var{keyword...} to @var{transformer...} while expanding @var{exp...}.
+@deffn {Syntax} letrec-syntax ((keyword transformer) @dots{}) exp1 exp2 @dots{}
+Bind each @var{keyword} to its corresponding @var{transformer} while
+expanding @var{exp1} @var{exp2} @enddots{}.
In the spirit of @code{letrec} versus @code{let}, an expansion produced by
@var{transformer} may reference a @var{keyword} bound by the
diff --git a/doc/ref/api-memory.texi b/doc/ref/api-memory.texi
index 6dca7a270..ff202e00e 100644
--- a/doc/ref/api-memory.texi
+++ b/doc/ref/api-memory.texi
@@ -398,7 +398,7 @@ set to @var{fill}. The default value for @var{fill} is the
empty list.
@end deffn
-@deffn {Scheme Procedure} weak-vector . l
+@deffn {Scheme Procedure} weak-vector elem @dots{}
@deffnx {Scheme Procedure} list->weak-vector l
@deffnx {C Function} scm_weak_vector (l)
Construct a weak vector from a list: @code{weak-vector} uses
diff --git a/doc/ref/api-modules.texi b/doc/ref/api-modules.texi
index b9f975864..c91c2d409 100644
--- a/doc/ref/api-modules.texi
+++ b/doc/ref/api-modules.texi
@@ -250,7 +250,7 @@ Export all bindings which should be in the public interface, either
by using @code{define-public} or @code{export} (both documented below).
@end itemize
-@deffn syntax define-module module-name [options @dots{}]
+@deffn syntax define-module module-name option @dots{}
@var{module-name} is a list of one or more symbols.
@lisp
@@ -260,8 +260,8 @@ by using @code{define-public} or @code{export} (both documented below).
@code{define-module} makes this module available to Guile programs under
the given @var{module-name}.
-The @var{options} are keyword/value pairs which specify more about the
-defined module. The recognized options and their meaning is shown in
+@var{option} @dots{} are keyword/value pairs which specify more about the
+defined module. The recognized options and their meaning are shown in
the following table.
@table @code
@@ -962,7 +962,7 @@ SCM my_eval_string (SCM str)
Like @code{scm_public_lookup} or @code{scm_private_lookup}, but
additionally dereferences the variable. If the variable object is
unbound, signals an error. Returns the value bound to @var{name} in
-@var{module}.
+@var{module_name}.
@end deftypefn
In addition, there are a number of other lookup-related procedures. We
@@ -1009,7 +1009,7 @@ module is used instead of the current one.
@end deftypefn
@deftypefn {C Function} SCM scm_module_reverse_lookup (SCM @var{module}, SCM @var{variable})
-Find the symbol that is bound to @var{variable} in @var{module}. When no such binding is found, return @var{#f}.
+Find the symbol that is bound to @var{variable} in @var{module}. When no such binding is found, return @code{#f}.
@end deftypefn
@deftypefn {C Function} SCM scm_c_define_module ({const char *}@var{name}, void (*@var{init})(void *), void *@var{data})
diff --git a/doc/ref/api-procedures.texi b/doc/ref/api-procedures.texi
index 1cecadf10..0e0ad15f2 100644
--- a/doc/ref/api-procedures.texi
+++ b/doc/ref/api-procedures.texi
@@ -103,7 +103,7 @@ useful mechanism, combining the process of registration
(@code{scm_c_make_gsubr}) and definition (@code{scm_define}).
@deftypefun SCM scm_c_make_gsubr (const char *name, int req, int opt, int rst, fcn)
-Register a C procedure @var{FCN} as a ``subr'' --- a primitive
+Register a C procedure @var{fcn} as a ``subr'' --- a primitive
subroutine that can be called from Scheme. It will be associated with
the given @var{name} but no environment binding will be created. The
arguments @var{req}, @var{opt} and @var{rst} specify the number of
@@ -115,7 +115,7 @@ to @var{fcn}, but may not exceed 10. The number of rest arguments should be 0 o
@end deftypefun
@deftypefun SCM scm_c_define_gsubr (const char *name, int req, int opt, int rst, fcn)
-Register a C procedure @var{FCN}, as for @code{scm_c_make_gsubr}
+Register a C procedure @var{fcn}, as for @code{scm_c_make_gsubr}
above, and additionally create a top-level Scheme binding for the
procedure in the ``current environment'' using @code{scm_define}.
@code{scm_c_define_gsubr} returns a handle for the procedure in the
@@ -418,8 +418,8 @@ elements. @code{let-optional} binds all variables simultaneously, while
@code{let-optional*} binds them sequentially, consistent with @code{let}
and @code{let*} (@pxref{Local Bindings}).
-@deffn {library syntax} let-optional rest-arg (binding @dots{}) expr @dots{}
-@deffnx {library syntax} let-optional* rest-arg (binding @dots{}) expr @dots{}
+@deffn {library syntax} let-optional rest-arg (binding @dots{}) body1 body2 @dots{}
+@deffnx {library syntax} let-optional* rest-arg (binding @dots{}) body1 body2 @dots{}
These two macros give you an optional argument interface that is very
@dfn{Schemey} and introduces no fancy syntax. They are compatible with
the scsh macros of the same name, but are slightly extended. Each of
@@ -431,22 +431,22 @@ runs out, the remaining vars are bound either to the default values or
@code{#f} if no default value was specified. @var{rest-arg} remains
bound to whatever may have been left of @var{rest-arg}.
-After binding the variables, the expressions @var{expr} @dots{} are
-evaluated in order.
+After binding the variables, the expressions @var{body1} @var{body2} @dots{}
+are evaluated in order.
@end deffn
Similarly, @code{let-keywords} and @code{let-keywords*} extract values
from keyword style argument lists, binding local variables to those
values or to defaults.
-@deffn {library syntax} let-keywords args allow-other-keys? (binding @dots{}) body @dots{}
-@deffnx {library syntax} let-keywords* args allow-other-keys? (binding @dots{}) body @dots{}
+@deffn {library syntax} let-keywords args allow-other-keys? (binding @dots{}) body1 body2 @dots{}
+@deffnx {library syntax} let-keywords* args allow-other-keys? (binding @dots{}) body1 body2 @dots{}
@var{args} is evaluated and should give a list of the form
@code{(#:keyword1 value1 #:keyword2 value2 @dots{})}. The
-@var{binding}s are variables and default expressions, with the
-variables to be set (by name) from the keyword values. The @var{body}
-forms are then evaluated and the last is the result. An example will
-make the syntax clearest,
+@var{binding}s are variables and default expressions, with the variables
+to be set (by name) from the keyword values. The @var{body1}
+@var{body2} @dots{} forms are then evaluated and the last is the
+result. An example will make the syntax clearest,
@example
(define args '(#:xyzzy "hello" #:foo "world"))
@@ -478,12 +478,12 @@ exist for defining macros with the improved argument list handling
possibilities. The @code{-public} versions not only define the
procedures/macros, but also export them from the current module.
-@deffn {library syntax} define*-public formals body
+@deffn {library syntax} define*-public formals body1 body2 @dots{}
Like a mix of @code{define*} and @code{define-public}.
@end deffn
-@deffn {library syntax} defmacro* name formals body
-@deffnx {library syntax} defmacro*-public name formals body
+@deffn {library syntax} defmacro* name formals body1 body2 @dots{}
+@deffnx {library syntax} defmacro*-public name formals body1 body2 @dots{}
These are just like @code{defmacro} and @code{defmacro-public} except that they
take @code{lambda*}-style extended parameter lists, where @code{#:optional},
@code{#:key}, @code{#:allow-other-keys} and @code{#:rest} are allowed with the usual
@@ -611,10 +611,11 @@ Return a procedure with the same arity as @var{proc} that returns the
@end lisp
@end deffn
-@deffn {Scheme Procedure} compose proc rest ...
-Compose @var{proc} with the procedures in @var{rest}, such that the last
-one in @var{rest} is applied first and @var{proc} last, and return the
-resulting procedure. The given procedures must have compatible arity.
+@deffn {Scheme Procedure} compose proc1 proc2 @dots{}
+Compose @var{proc1} with the procedures @var{proc2} @dots{} such that
+the last @var{proc} argument is applied first and @var{proc1} last, and
+return the resulting procedure. The given procedures must have
+compatible arity.
@lisp
(procedure? (compose 1+ 1-)) @result{} #t
@@ -835,9 +836,9 @@ making large procedures inlinable will probably result in an increase in
code size. Additionally, the elimination of the call overhead rarely
matters for large procedures.
-@deffn {Scheme Syntax} define-inlinable (name parameter ...) body ...
+@deffn {Scheme Syntax} define-inlinable (name parameter @dots{}) body1 body2 @dots{}
Define @var{name} as a procedure with parameters @var{parameter}s and
-body @var{body}.
+bodies @var{body1}, @var{body2}, @enddots{}.
@end deffn
@c Local Variables:
diff --git a/doc/ref/api-regex.texi b/doc/ref/api-regex.texi
index 1435aeb05..11a31fca0 100644
--- a/doc/ref/api-regex.texi
+++ b/doc/ref/api-regex.texi
@@ -228,7 +228,7 @@ and replace them with the contents of another string. The following
functions are convenient ways to do this.
@c begin (scm-doc-string "regex.scm" "regexp-substitute")
-@deffn {Scheme Procedure} regexp-substitute port match [item@dots{}]
+@deffn {Scheme Procedure} regexp-substitute port match item @dots{}
Write to @var{port} selected parts of the match structure @var{match}.
Or if @var{port} is @code{#f} then form a string from those parts and
return that.
@@ -276,7 +276,7 @@ re-ordering and hyphenating the fields.
@c begin (scm-doc-string "regex.scm" "regexp-substitute")
-@deffn {Scheme Procedure} regexp-substitute/global port regexp target [item@dots{}]
+@deffn {Scheme Procedure} regexp-substitute/global port regexp target item@dots{}
@cindex search and replace
Write to @var{port} selected parts of matches of @var{regexp} in
@var{target}. If @var{port} is @code{#f} then form a string from
diff --git a/doc/ref/api-scheduling.texi b/doc/ref/api-scheduling.texi
index 6b0ed22bc..a30166394 100644
--- a/doc/ref/api-scheduling.texi
+++ b/doc/ref/api-scheduling.texi
@@ -316,15 +316,15 @@ Higher level thread procedures are available by loading the
@code{(ice-9 threads)} module. These provide standardized
thread creation.
-@deffn macro make-thread proc [args@dots{}]
-Apply @var{proc} to @var{args} in a new thread formed by
+@deffn macro make-thread proc arg @dots{}
+Apply @var{proc} to @var{arg} @dots{} in a new thread formed by
@code{call-with-new-thread} using a default error handler that display
-the error to the current error port. The @var{args@dots{}}
+the error to the current error port. The @var{arg} @dots{}
expressions are evaluated in the new thread.
@end deffn
-@deffn macro begin-thread first [rest@dots{}]
-Evaluate forms @var{first} and @var{rest} in a new thread formed by
+@deffn macro begin-thread expr1 expr2 @dots{}
+Evaluate forms @var{expr1} @var{expr2} @dots{} in a new thread formed by
@code{call-with-new-thread} using a default error handler that display
the error to the current error port.
@end deffn
@@ -353,10 +353,10 @@ Acquiring requisite mutexes in a fixed order (like always A before B)
in all threads is one way to avoid such problems.
@sp 1
-@deffn {Scheme Procedure} make-mutex . flags
+@deffn {Scheme Procedure} make-mutex flag @dots{}
@deffnx {C Function} scm_make_mutex ()
@deffnx {C Function} scm_make_mutex_with_flags (SCM flags)
-Return a new mutex. It is initially unlocked. If @var{flags} is
+Return a new mutex. It is initially unlocked. If @var{flag} @dots{} is
specified, it must be a list of symbols specifying configuration flags
for the newly-created mutex. The supported flags are:
@table @code
@@ -523,25 +523,25 @@ available from
(use-modules (ice-9 threads))
@end example
-@deffn macro with-mutex mutex [body@dots{}]
-Lock @var{mutex}, evaluate the @var{body} forms, then unlock
-@var{mutex}. The return value is the return from the last @var{body}
-form.
+@deffn macro with-mutex mutex body1 body2 @dots{}
+Lock @var{mutex}, evaluate the body @var{body1} @var{body2} @dots{},
+then unlock @var{mutex}. The return value is that returned by the last
+body form.
The lock, body and unlock form the branches of a @code{dynamic-wind}
(@pxref{Dynamic Wind}), so @var{mutex} is automatically unlocked if an
-error or new continuation exits @var{body}, and is re-locked if
-@var{body} is re-entered by a captured continuation.
+error or new continuation exits the body, and is re-locked if
+the body is re-entered by a captured continuation.
@end deffn
-@deffn macro monitor body@dots{}
-Evaluate the @var{body} forms, with a mutex locked so only one thread
-can execute that code at any one time. The return value is the return
-from the last @var{body} form.
+@deffn macro monitor body1 body2 @dots{}
+Evaluate the body form @var{body1} @var{body2} @dots{} with a mutex
+locked so only one thread can execute that code at any one time. The
+return value is the return from the last body form.
Each @code{monitor} form has its own private mutex and the locking and
evaluation is as per @code{with-mutex} above. A standard mutex
-(@code{make-mutex}) is used, which means @var{body} must not
+(@code{make-mutex}) is used, which means the body must not
recursively re-enter the @code{monitor} form.
The term ``monitor'' comes from operating system theory, where it
@@ -751,12 +751,12 @@ set/restored when control enter or leaves the established dynamic
extent.
@end deffn
-@deffn {Scheme Macro} with-fluids ((fluid value) ...) body...
-Execute @var{body...} while each @var{fluid} is set to the
-corresponding @var{value}. Both @var{fluid} and @var{value} are
-evaluated and @var{fluid} must yield a fluid. @var{body...} is
-executed inside a @code{dynamic-wind} and the fluids are set/restored
-when control enter or leaves the established dynamic extent.
+@deffn {Scheme Macro} with-fluids ((fluid value) @dots{}) body1 body2 @dots{}
+Execute body @var{body1} @var{body2} @dots{} while each @var{fluid} is
+set to the corresponding @var{value}. Both @var{fluid} and @var{value}
+are evaluated and @var{fluid} must yield a fluid. The body is executed
+inside a @code{dynamic-wind} and the fluids are set/restored when
+control enter or leaves the established dynamic extent.
@end deffn
@deftypefn {C Function} SCM scm_c_with_fluids (SCM fluids, SCM vals, SCM (*cproc)(void *), void *data)
@@ -890,11 +890,11 @@ canonical form. For example,
@end example
@end defun
-@deffn {Scheme Syntax} parameterize ((param value) @dots{}) body @dots{}
+@deffn {library syntax} parameterize ((param value) @dots{}) body1 body2 @dots{}
Establish a new dynamic scope with the given @var{param}s bound to new
-locations and set to the given @var{value}s. @var{body} is evaluated
-in that environment, the result is the return from the last form in
-@var{body}.
+locations and set to the given @var{value}s. @var{body1} @var{body2}
+@dots{} is evaluated in that environment. The value returned is that of
+last body form.
Each @var{param} is an expression which is evaluated to get the
parameter object. Often this will just be the name of a variable
@@ -1043,33 +1043,32 @@ are implemented in terms of futures (@pxref{Futures}). Thus they are
relatively cheap as they re-use existing threads, and portable, since
they automatically use one thread per available CPU core.
-@deffn syntax parallel expr1 @dots{} exprN
+@deffn syntax parallel expr @dots{}
Evaluate each @var{expr} expression in parallel, each in its own thread.
-Return the results as a set of @var{N} multiple values
-(@pxref{Multiple Values}).
+Return the results of @var{n} expressions as a set of @var{n} multiple
+values (@pxref{Multiple Values}).
@end deffn
-@deffn syntax letpar ((var1 expr1) @dots{} (varN exprN)) body@dots{}
+@deffn syntax letpar ((var expr) @dots{}) body1 body2 @dots{}
Evaluate each @var{expr} in parallel, each in its own thread, then bind
-the results to the corresponding @var{var} variables and evaluate
-@var{body}.
+the results to the corresponding @var{var} variables, and then evaluate
+@var{body1} @var{body2} @enddots{}
@code{letpar} is like @code{let} (@pxref{Local Bindings}), but all the
expressions for the bindings are evaluated in parallel.
@end deffn
-@deffn {Scheme Procedure} par-map proc lst1 @dots{} lstN
-@deffnx {Scheme Procedure} par-for-each proc lst1 @dots{} lstN
+@deffn {Scheme Procedure} par-map proc lst1 lst2 @dots{}
+@deffnx {Scheme Procedure} par-for-each proc lst1 lst2 @dots{}
Call @var{proc} on the elements of the given lists. @code{par-map}
returns a list comprising the return values from @var{proc}.
@code{par-for-each} returns an unspecified value, but waits for all
calls to complete.
-The @var{proc} calls are @code{(@var{proc} @var{elem1} @dots{}
-@var{elemN})}, where each @var{elem} is from the corresponding
-@var{lst}. Each @var{lst} must be the same length. The calls are
-potentially made in parallel, depending on the number of CPU cores
-available.
+The @var{proc} calls are @code{(@var{proc} @var{elem1} @var{elem2}
+@dots{})}, where each @var{elem} is from the corresponding @var{lst} .
+Each @var{lst} must be the same length. The calls are potentially made
+in parallel, depending on the number of CPU cores available.
These functions are like @code{map} and @code{for-each} (@pxref{List
Mapping}), but make their @var{proc} calls in parallel.
@@ -1085,8 +1084,8 @@ completion, which makes them quite expensive.
Therefore, they should be avoided.
-@deffn {Scheme Procedure} n-par-map n proc lst1 @dots{} lstN
-@deffnx {Scheme Procedure} n-par-for-each n proc lst1 @dots{} lstN
+@deffn {Scheme Procedure} n-par-map n proc lst1 lst2 @dots{}
+@deffnx {Scheme Procedure} n-par-for-each n proc lst1 lst2 @dots{}
Call @var{proc} on the elements of the given lists, in the same way as
@code{par-map} and @code{par-for-each} above, but use no more than
@var{n} threads at any one time. The order in which calls are
@@ -1098,7 +1097,7 @@ a dual-CPU system for instance @math{@var{n}=4} might be enough to
keep the CPUs utilized, and not consume too much memory.
@end deffn
-@deffn {Scheme Procedure} n-for-each-par-map n sproc pproc lst1 @dots{} lstN
+@deffn {Scheme Procedure} n-for-each-par-map n sproc pproc lst1 lst2 @dots{}
Apply @var{pproc} to the elements of the given lists, and apply
@var{sproc} to each result returned by @var{pproc}. The final return
value is unspecified, but all calls will have been completed before
diff --git a/doc/ref/api-smobs.texi b/doc/ref/api-smobs.texi
index db8161cdd..6b042367e 100644
--- a/doc/ref/api-smobs.texi
+++ b/doc/ref/api-smobs.texi
@@ -22,8 +22,8 @@ If @var{size} is 0, the default @emph{free} function will do nothing.
If @var{size} is not 0, the default @emph{free} function will
deallocate the memory block pointed to by @code{SCM_SMOB_DATA} with
-@code{scm_gc_free}. The @var{WHAT} parameter in the call to
-@code{scm_gc_free} will be @var{NAME}.
+@code{scm_gc_free}. The @var{what} parameter in the call to
+@code{scm_gc_free} will be @var{name}.
Default values are provided for the @emph{mark}, @emph{free},
@emph{print}, and @emph{equalp} functions, as described in
@@ -43,7 +43,7 @@ a @dfn{finalizer}) for the smob type specified by the tag
@var{tc}. @var{tc} is the tag returned by @code{scm_make_smob_type}.
The @var{free} procedure must deallocate all resources that are
-directly associated with the smob instance @var{OBJ}. It must assume
+directly associated with the smob instance @var{obj}. It must assume
that all @code{SCM} values that it references have already been freed
and are thus invalid.
@@ -107,14 +107,14 @@ with @code{scm_display}, @code{scm_write}, @code{scm_simple_format},
and @code{scm_puts}.
@end deftypefn
-@deftypefn {C Function} void scm_set_smob_equalp (scm_t_bits tc, SCM (*equalp) (SCM obj1, SCM obj1))
+@deftypefn {C Function} void scm_set_smob_equalp (scm_t_bits tc, SCM (*equalp) (SCM obj1, SCM obj2))
This function sets the smob equality-testing predicate for the smob
type specified by the tag @var{tc}. @var{tc} is the tag returned by
@code{scm_make_smob_type}.
The @var{equalp} procedure should return @code{SCM_BOOL_T} when
@var{obj1} is @code{equal?} to @var{obj2}. Else it should return
-@var{SCM_BOOL_F}. Both @var{obj1} and @var{obj2} are instances of the
+@code{SCM_BOOL_F}. Both @var{obj1} and @var{obj2} are instances of the
smob type @var{tc}.
@end deftypefn
diff --git a/doc/ref/api-utility.texi b/doc/ref/api-utility.texi
index ba6139f8c..9ab1eeea5 100644
--- a/doc/ref/api-utility.texi
+++ b/doc/ref/api-utility.texi
@@ -583,11 +583,11 @@ value of this procedure is not specified.
Convert the procedure list of @var{hook} to a list.
@end deffn
-@deffn {Scheme Procedure} run-hook hook . args
+@deffn {Scheme Procedure} run-hook hook arg @dots{}
@deffnx {C Function} scm_run_hook (hook, args)
-Apply all procedures from the hook @var{hook} to the arguments
-@var{args}. The order of the procedure application is first to
-last. The return value of this procedure is not specified.
+Apply all procedures from the hook @var{hook} to the arguments @var{arg}
+@enddots{}. The order of the procedure application is first to last.
+The return value of this procedure is not specified.
@end deffn
If, in C code, you are certain that you have a hook object and well
diff --git a/doc/ref/compiler.texi b/doc/ref/compiler.texi
index 3d6dbf327..692cb3684 100644
--- a/doc/ref/compiler.texi
+++ b/doc/ref/compiler.texi
@@ -437,9 +437,9 @@ any, then the rest argument if any, then all of the keyword arguments.
@var{body} is the body of the clause. If the procedure is called with
an appropriate number of arguments, @var{body} is evaluated in tail
-position. Otherwise, if there is a @var{consequent}, it should be a
+position. Otherwise, if there is an @var{alternate}, it should be a
@code{<lambda-case>} expression, representing the next clause to try.
-If there is no @var{consequent}, a wrong-number-of-arguments error is
+If there is no @var{alternate}, a wrong-number-of-arguments error is
signaled.
@end deftp
@deftp {Scheme Variable} <let> src names gensyms vals exp
diff --git a/doc/ref/goops.texi b/doc/ref/goops.texi
index 10192eb3b..bc04985cf 100644
--- a/doc/ref/goops.texi
+++ b/doc/ref/goops.texi
@@ -97,11 +97,12 @@ Class options, slot descriptions and inheritance are discussed more
below.
@cindex slot
-@deffn syntax define-class name (super @dots{}) slot-definition @dots{} . options
+@deffn syntax define-class name (super @dots{}) @
+ slot-definition @dots{} class-option @dots{}
Define a class called @var{name} that inherits from @var{super}s, with
-direct slots defined by @var{slot-definition}s and class options
-@var{options}. The newly created class is bound to the variable name
-@var{name} in the current environment.
+direct slots defined by @var{slot-definition}s and @var{class-option}s.
+The newly created class is bound to the variable name @var{name} in the
+current environment.
Each @var{slot-definition} is either a symbol that names the slot or a
list,
@@ -115,8 +116,7 @@ list with an even number of elements. The even-numbered elements of
@var{slot-options} (counting from zero) are slot option keywords; the
odd-numbered elements are the corresponding values for those keywords.
-@var{options} is a similarly structured list containing class option
-keywords and corresponding values.
+Each @var{class-option} is an option keyword and corresponding value.
@end deffn
As an example, let us define a type for representing a complex number
@@ -183,13 +183,13 @@ creates a new @code{<my-complex>} object and binds it to the Scheme
variable @code{c}.
@deffn generic make
-@deffnx method make (class <class>) . initargs
+@deffnx method make (class <class>) initarg @dots{}
Create and return a new instance of class @var{class}, initialized using
-@var{initargs}.
+@var{initarg} @enddots{}.
-In theory, @var{initargs} can have any structure that is understood by
-whatever methods get applied when the @code{initialize} generic function
-is applied to the newly allocated instance.
+In theory, @var{initarg} @dots{} can have any structure that is
+understood by whatever methods get applied when the @code{initialize}
+generic function is applied to the newly allocated instance.
In practice, specialized @code{initialize} methods would normally call
@code{(next-method)}, and so eventually the standard GOOPS
@@ -206,7 +206,7 @@ instance's class. Any unprocessed keyword value pairs are ignored.
@end deffn
@deffn generic make-instance
-@deffnx method make-instance (class <class>) . initargs
+@deffnx method make-instance (class <class>) initarg @dots{}
@code{make-instance} is an alias for @code{make}.
@end deffn
@@ -674,9 +674,9 @@ setter). Any other previous value, including an existing generic
function, is discarded and replaced by a new, empty generic function.
@end deffn
-@deffn syntax define-method (generic parameter @dots{}) . body
+@deffn syntax define-method (generic parameter @dots{}) body @dots{}
Define a method for the generic function or accessor @var{generic} with
-parameters @var{parameter}s and body @var{body}.
+parameters @var{parameter}s and body @var{body} @enddots{}.
@var{generic} is a generic function. If @var{generic} is a variable
which is not yet bound to a generic function object, the expansion of
@@ -688,12 +688,12 @@ generic-with-setter object, the expansion will include a call to
Each @var{parameter} must be either a symbol or a two-element list
@code{(@var{symbol} @var{class})}. The symbols refer to variables in
-the @var{body} that will be bound to the parameters supplied by the
+the body forms that will be bound to the parameters supplied by the
caller when calling this method. The @var{class}es, if present,
specify the possible combinations of parameters to which this method
can be applied.
-@var{body} is the body of the method definition.
+@var{body} @dots{} are the bodies of the method definition.
@end deffn
@code{define-method} expressions look a little like Scheme procedure
@@ -1698,10 +1698,10 @@ If you customize these functions for particular classes or metaclasses,
you may still want to use @code{goops-error} to signal any error
conditions that you detect.
-@deffn procedure goops-error format-string . args
+@deffn procedure goops-error format-string arg @dots{}
Raise an error with key @code{goops-error} and error message constructed
-from @var{format-string} and @var{args}. Error message formatting is
-as done by @code{scm-error}.
+from @var{format-string} and @var{arg} @enddots{}. Error message
+formatting is as done by @code{scm-error}.
@end deffn
@@ -2228,11 +2228,12 @@ handles the redefinition by invoking @code{class-redefinition}
(@pxref{Redefining a Class}).
@end itemize
-@deffn syntax class name (super @dots{}) slot-definition @dots{} . options
+@deffn syntax class name (super @dots{}) @
+ slot-definition @dots{} class-option @dots{}
Return a newly created class that inherits from @var{super}s, with
-direct slots defined by @var{slot-definition}s and class options
-@var{options}. For the format of @var{slot-definition}s and
-@var{options}, see @ref{Class Definition,, define-class}.
+direct slots defined by @var{slot-definition}s and @var{class-option}s.
+For the format of @var{slot-definition}s and @var{class-option}s, see
+@ref{Class Definition,, define-class}.
@end deffn
@noindent @code{class} expands to an expression which
@@ -2250,13 +2251,12 @@ calls @code{make-class} to create the class with the processed and
evaluated parameters.
@end itemize
-@deffn procedure make-class supers slots . options
+@deffn procedure make-class supers slots class-option @dots{}
Return a newly created class that inherits from @var{supers}, with
-direct slots defined by @var{slots} and class options @var{options}.
-For the format of @var{slots} and @var{options}, see @ref{Class
+direct slots defined by @var{slots} and @var{class-option}s. For the
+format of @var{slots} and @var{class-option}s, see @ref{Class
Definition,, define-class}, except note that for @code{make-class},
-@var{slots} and @var{options} are separate list parameters: @var{slots}
-here is a list of slot definitions.
+@var{slots} is a separate list of slot definitions.
@end deffn
@noindent @code{make-class}
@@ -2307,18 +2307,19 @@ has to be created once.
The @code{env} parameter is ignored.
@end deffn
-@deffn generic make metaclass @dots{}
+@deffn generic make metaclass initarg @dots{}
@var{metaclass} is the metaclass of the class being defined, either
taken from the @code{#:metaclass} class option or computed by
@code{ensure-metaclass}. The applied method must create and return the
fully initialized class metaobject for the new class definition.
@end deffn
-The @code{(make @var{metaclass} @dots{})} invocation is a particular
-case of the instance creation protocol covered in the previous section.
-It will create an class metaobject with metaclass @var{metaclass}. By
-default, this metaobject will be initialized by the @code{initialize}
-method that is specialized for instances of type @code{<class>}.
+The @code{(make @var{metaclass} @var{initarg} @dots{})} invocation is a
+particular case of the instance creation protocol covered in the
+previous section. It will create an class metaobject with metaclass
+@var{metaclass}. By default, this metaobject will be initialized by the
+@code{initialize} method that is specialized for instances of type
+@code{<class>}.
The @code{initialize} method for classes (signature @code{(initialize
<class> initargs)}) calls the following generic functions.
@@ -2565,7 +2566,7 @@ calls @code{add-method!} to add this method to the relevant generic
function.
@end itemize
-@deffn syntax method (parameter @dots{}) . body
+@deffn syntax method (parameter @dots{}) body @dots{}
Make a method whose specializers are defined by the classes in
@var{parameter}s and whose procedure definition is constructed from the
@var{parameter} symbols and @var{body} forms.
diff --git a/doc/ref/match.texi b/doc/ref/match.texi
index d1618ce6e..40b5be899 100644
--- a/doc/ref/match.texi
+++ b/doc/ref/match.texi
@@ -64,16 +64,16 @@ bound to, respectively, the first and second element of @var{l}.
The pattern matcher is defined as follows:
-@deffn {Scheme Syntax} match exp clause ...
-Match object @var{exp} against the patterns in the given @var{clause}s,
-in the order in which they appear. Return the value produced by the
-first matching clause. If no @var{clause} matches, throw an exception
-with key @code{match-error}.
-
-Each @var{clause} has the form @code{(pattern body)}. Each
-@var{pattern} must follow the syntax described below. Each @var{body}
-is an arbitrary Scheme expression, possibly referring to pattern
-variables of @var{pattern}.
+@deffn {Scheme Syntax} match exp clause1 clause2 @dots{}
+Match object @var{exp} against the patterns in @var{clause1}
+@var{clause2} @dots{} in the order in which they appear. Return the
+value produced by the first matching clause. If no clause matches,
+throw an exception with key @code{match-error}.
+
+Each clause has the form @code{(pattern body1 body2 @dots{})}. Each
+@var{pattern} must follow the syntax described below. Each body is an
+arbitrary Scheme expression, possibly referring to pattern variables of
+@var{pattern}.
@end deffn
@c FIXME: Document other forms:
diff --git a/doc/ref/misc-modules.texi b/doc/ref/misc-modules.texi
index 00354ac73..cf1e0e49f 100644
--- a/doc/ref/misc-modules.texi
+++ b/doc/ref/misc-modules.texi
@@ -90,13 +90,13 @@ dots.}, or in the worst case, displayed as @nicode{#}.
@deffn {Scheme Procedure} truncated-print obj [port] [keyword-options]
Print @var{obj}, truncating the output, if necessary, to make it fit
-into @var{width} characters. By default, @var{x} will be printed using
+into @var{width} characters. By default, @var{obj} will be printed using
@code{write}, though that behavior can be overridden via the
@var{display?} keyword argument.
The default behaviour is to print depth-first, meaning that the entire
-remaining width will be available to each sub-expression of @var{x} --
-e.g., if @var{x} is a vector, each member of @var{x}. One can attempt to
+remaining width will be available to each sub-expression of @var{obj} --
+e.g., if @var{obj} is a vector, each member of @var{obj}. One can attempt to
``ration'' the available width, trying to allocate it equally to each
sub-expression, via the @var{breadth-first?} keyword argument.
@@ -156,7 +156,7 @@ C programmers will note the similarity between @code{format} and
instead of @nicode{%}, and are more powerful.
@sp 1
-@deffn {Scheme Procedure} format dest fmt [args@dots{}]
+@deffn {Scheme Procedure} format dest fmt arg @dots{}
Write output specified by the @var{fmt} string to @var{dest}.
@var{dest} can be an output port, @code{#t} for
@code{current-output-port} (@pxref{Default Ports}), or @code{#f} to
@@ -269,7 +269,7 @@ Integer. Parameters: @var{minwidth}, @var{padchar}, @var{commachar},
@var{commawidth}.
Output an integer argument as a decimal, hexadecimal, octal or binary
-integer (respectively).
+integer (respectively), in a locale-independent way.
@example
(format #t "~d" 123) @print{} 123
@@ -297,7 +297,9 @@ minimum), it's padded on the left with the @var{padchar} parameter
@end example
@nicode{~:d} adds commas (or the @var{commachar} parameter) every
-three digits (or the @var{commawidth} parameter many).
+three digits (or the @var{commawidth} parameter many). However, when
+your intent is to write numbers in a way that follows typographical
+conventions, using @nicode{~h} is recommended.
@example
(format #t "~:d" 1234567) @print{} 1,234,567
@@ -404,6 +406,29 @@ printed instead of the value.
(format #t "~5,,,'xf" 12345) @print{} xxxxx
@end example
+@item @nicode{~h}
+Localized number@footnote{The @nicode{~h} format specifier first
+appeared in Guile version 2.0.6.}. Parameters: @var{width},
+@var{decimals}, @var{padchar}.
+
+Like @nicode{~f}, output an exact or floating point number, but do so
+according to the current locale, or according to the given locale object
+when the @code{:} modifier is used (@pxref{Number Input and Output,
+@code{number->locale-string}}).
+
+@example
+(format #t "~h" 12345.5678) ; with "C" as the current locale
+@print{} 12345.5678
+
+(format #t "~14,,'*:h" 12345.5678
+ (make-locale LC_ALL "en_US"))
+@print{} ***12,345.5678
+
+(format #t "~,2:h" 12345.5678
+ (make-locale LC_NUMERIC "fr_FR"))
+@print{} 12 345,56
+@end example
+
@item @nicode{~e}
Exponential float. Parameters: @var{width}, @var{mantdigits},
@var{expdigits}, @var{intdigits}, @var{overflowchar}, @var{padchar},
@@ -1670,35 +1695,35 @@ secondly the number of elements in that list.
Return a vector which is the entire contents of @var{stream}.
@end deffn
-@deffn {Scheme Procedure} stream-fold proc init stream0 @dots{} streamN
+@defun stream-fold proc init stream1 stream2 @dots{}
Apply @var{proc} successively over the elements of the given streams,
from first to last until the end of the shortest stream is reached.
Return the result from the last @var{proc} call.
-Each call is @code{(@var{proc} elem0 @dots{} elemN prev)}, where each
+Each call is @code{(@var{proc} elem1 elem2 @dots{} prev)}, where each
@var{elem} is from the corresponding @var{stream}. @var{prev} is the
return from the previous @var{proc} call, or the given @var{init} for
the first call.
-@end deffn
+@end defun
-@deffn {Scheme Procedure} stream-for-each proc stream0 @dots{} streamN
+@defun stream-for-each proc stream1 stream2 @dots{}
Call @var{proc} on the elements from the given @var{stream}s. The
return value is unspecified.
-Each call is @code{(@var{proc} elem0 @dots{} elemN)}, where each
+Each call is @code{(@var{proc} elem1 elem2 @dots{})}, where each
@var{elem} is from the corresponding @var{stream}.
@code{stream-for-each} stops when it reaches the end of the shortest
@var{stream}.
-@end deffn
+@end defun
-@deffn {Scheme Procedure} stream-map proc stream0 @dots{} streamN
+@defun stream-map proc stream1 stream2 @dots{}
Return a new stream which is the results of applying @var{proc} to the
elements of the given @var{stream}s.
-Each call is @code{(@var{proc} elem0 @dots{} elemN)}, where each
+Each call is @code{(@var{proc} elem1 elem2 @dots{})}, where each
@var{elem} is from the corresponding @var{stream}. The new stream
ends when the end of the shortest given @var{stream} is reached.
-@end deffn
+@end defun
@node Buffered Input
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index 1dc5a80e8..0a688e92d 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -1,7 +1,7 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
-@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011
-@c Free Software Foundation, Inc.
+@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007,
+@c 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@node POSIX
@@ -211,8 +211,8 @@ initialized to zero. The @var{modes} string is the same as that
accepted by @code{open-file} (@pxref{File Ports, open-file}).
@end deffn
-@deffn {Scheme Procedure} fdes->ports fd
-@deffnx {C Function} scm_fdes_to_ports (fd)
+@deffn {Scheme Procedure} fdes->ports fdes
+@deffnx {C Function} scm_fdes_to_ports (fdes)
Return a list of existing ports which have @var{fdes} as an
underlying file descriptor, without changing their revealed
counts.
@@ -230,8 +230,8 @@ descriptor, if one exists, and increments its revealed count.
Otherwise, returns a new output port with a revealed count of 1.
@end deffn
-@deffn {Scheme Procedure} primitive-move->fdes port fd
-@deffnx {C Function} scm_primitive_move_to_fdes (port, fd)
+@deffn {Scheme Procedure} primitive-move->fdes port fdes
+@deffnx {C Function} scm_primitive_move_to_fdes (port, fdes)
Moves the underlying file descriptor for @var{port} to the integer
value @var{fdes} without changing the revealed count of @var{port}.
Any other ports already using this descriptor will be automatically
@@ -252,10 +252,10 @@ The return value is unspecified.
Decrements the revealed count for a port.
@end deffn
-@deffn {Scheme Procedure} fsync object
-@deffnx {C Function} scm_fsync (object)
+@deffn {Scheme Procedure} fsync port_or_fd
+@deffnx {C Function} scm_fsync (port_or_fd)
Copies any unwritten data for the specified output file descriptor to disk.
-If @var{port/fd} is a port, its buffer is flushed before the underlying
+If @var{port_or_fd} is a port, its buffer is flushed before the underlying
file descriptor is fsync'd.
The return value is unspecified.
@end deffn
@@ -402,11 +402,11 @@ port.
This procedure is equivalent to @code{(dup->port @var{port} @var{modes})}.
@end deffn
-@deffn {Scheme Procedure} redirect-port old new
-@deffnx {C Function} scm_redirect_port (old, new)
+@deffn {Scheme Procedure} redirect-port old_port new_port
+@deffnx {C Function} scm_redirect_port (old_port, new_port)
This procedure takes two ports and duplicates the underlying file
-descriptor from @var{old-port} into @var{new-port}. The
-current file descriptor in @var{new-port} will be closed.
+descriptor from @var{old_port} into @var{new_port}. The
+current file descriptor in @var{new_port} will be closed.
After the redirection the two ports will share a file position
and file status flags.
@@ -648,7 +648,7 @@ The GNU C Library Reference Manual}.
@deffn {Scheme Procedure} stat object
@deffnx {C Function} scm_stat (object)
Return an object containing various information about the file
-determined by @var{obj}. @var{obj} can be a string containing
+determined by @var{object}. @var{object} can be a string containing
a file name or a port or integer file descriptor which is open
on a file (in which case @code{fstat} is used as the underlying
system call).
@@ -728,8 +728,8 @@ An integer representing the access permission bits.
@end deffn
@end deffn
-@deffn {Scheme Procedure} lstat str
-@deffnx {C Function} scm_lstat (str)
+@deffn {Scheme Procedure} lstat path
+@deffnx {C Function} scm_lstat (path)
Similar to @code{stat}, but does not follow symbolic links, i.e.,
it will return information about a symbolic link itself, not the
file it points to. @var{path} must be a string.
@@ -762,8 +762,8 @@ as @code{-1}, then that ID is not changed.
@findex fchmod
@deffn {Scheme Procedure} chmod object mode
@deffnx {C Function} scm_chmod (object, mode)
-Changes the permissions of the file referred to by @var{obj}.
-@var{obj} can be a string containing a file name or a port or integer file
+Changes the permissions of the file referred to by @var{object}.
+@var{object} can be a string containing a file name or a port or integer file
descriptor which is open on a file (in which case @code{fchmod} is used
as the underlying system call).
@var{mode} specifies
@@ -774,7 +774,7 @@ The return value is unspecified.
@deffn {Scheme Procedure} utime pathname [actime [modtime [actimens [modtimens [flags]]]]]
@deffnx {C Function} scm_utime (pathname, actime, modtime, actimens, modtimens, flags)
@code{utime} sets the access and modification times for the
-file named by @var{path}. If @var{actime} or @var{modtime} is
+file named by @var{pathname}. If @var{actime} or @var{modtime} is
not supplied, then the current time is used. @var{actime} and
@var{modtime} must be integer time values as returned by the
@code{current-time} procedure.
@@ -953,7 +953,7 @@ which is usual for ordinary file creation,
@end deffn
@deffn {Scheme Procedure} tmpfile
-@deffnx {C Function} scm_tmpfile
+@deffnx {C Function} scm_tmpfile ()
Return an input/output port to a unique temporary file
named using the path prefix @code{P_tmpdir} defined in
@file{stdio.h}.
@@ -1055,7 +1055,7 @@ stream. Otherwise, close the stream. The @code{setpwent} and
@deffn {Scheme Procedure} getpw [user]
@deffnx {C Function} scm_getpwuid (user)
-Look up an entry in the user database. @var{obj} can be an integer,
+Look up an entry in the user database. @var{user} can be an integer,
a string, or omitted, giving the behaviour of getpwuid, getpwnam
or getpwent respectively.
@end deffn
@@ -1108,9 +1108,9 @@ stream. Otherwise, close the stream. The @code{setgrent} and
@code{endgrent} procedures are implemented on top of this.
@end deffn
-@deffn {Scheme Procedure} getgr [name]
-@deffnx {C Function} scm_getgrgid (name)
-Look up an entry in the group database. @var{obj} can be an integer,
+@deffn {Scheme Procedure} getgr [group]
+@deffnx {C Function} scm_getgrgid (group)
+Look up an entry in the group database. @var{group} can be an integer,
a string, or omitted, giving the behaviour of getgrgid, getgrnam
or getgrent respectively.
@end deffn
@@ -1284,7 +1284,7 @@ names are from the current locale and in the locale character set.
@cindex time parsing
Performs the reverse action to @code{strftime}, parsing
@var{string} according to the specification supplied in
-@var{template}. The interpretation of month and day names is
+@var{format}. The interpretation of month and day names is
dependent on the current locale. The value returned is a pair.
The @acronym{CAR} has an object with time components
in the form returned by @code{localtime} or @code{gmtime},
@@ -1411,8 +1411,8 @@ The given strings are all copied, so the C data is not accessed again
once @code{scm_set_program_arguments} returns.
@end deftypefn
-@deffn {Scheme Procedure} getenv nam
-@deffnx {C Function} scm_getenv (nam)
+@deffn {Scheme Procedure} getenv name
+@deffnx {C Function} scm_getenv (name)
@cindex environment
Looks up the string @var{name} in the current environment. The return
value is @code{#f} unless a string of the form @code{NAME=VALUE} is
@@ -1442,8 +1442,8 @@ If @var{env} is omitted, return the current environment (in the
Unix sense) as a list of strings. Otherwise set the current
environment, which is also the default environment for child
processes, to the supplied list of strings. Each member of
-@var{env} should be of the form @var{NAME}=@var{VALUE} and values of
-@var{NAME} should not be duplicated. If @var{env} is supplied
+@var{env} should be of the form @var{name}=@var{value} and values of
+@var{name} should not be duplicated. If @var{env} is supplied
then the return value is unspecified.
@end deffn
@@ -1452,11 +1452,11 @@ then the return value is unspecified.
Modifies the environment of the current process, which is
also the default environment inherited by child processes.
-If @var{string} is of the form @code{NAME=VALUE} then it will be written
+If @var{str} is of the form @code{NAME=VALUE} then it will be written
directly into the environment, replacing any existing environment string
with
-name matching @code{NAME}. If @var{string} does not contain an equal
-sign, then any existing string with name matching @var{string} will
+name matching @code{NAME}. If @var{str} does not contain an equal
+sign, then any existing string with name matching @var{str} will
be removed.
The return value is unspecified.
@@ -1472,7 +1472,7 @@ The return value is unspecified.
@deffn {Scheme Procedure} chdir str
@deffnx {C Function} scm_chdir (str)
@cindex current directory
-Change the current working directory to @var{path}.
+Change the current working directory to @var{str}.
The return value is unspecified.
@end deffn
@@ -1698,12 +1698,12 @@ If @code{system} is called without arguments, return a boolean
indicating whether the command processor is available.
@end deffn
-@deffn {Scheme Procedure} system* . args
+@deffn {Scheme Procedure} system* arg1 arg2 @dots{}
@deffnx {C Function} scm_system_star (args)
-Execute the command indicated by @var{args}. The first element must
-be a string indicating the command to be executed, and the remaining
-items must be strings representing each of the arguments to that
-command.
+Execute the command indicated by @var{arg1} @var{arg2} @enddots{}. The
+first element must be a string indicating the command to be executed,
+and the remaining items must be strings representing each of the
+arguments to that command.
This function returns the exit status of the command as provided by
@code{waitpid}. This value can be handled with @code{status:exit-val}
@@ -1743,22 +1743,22 @@ in the child would upset the protocol in the parent, so
@code{primitive-_exit} should be used to exit without that.
@end deffn
-@deffn {Scheme Procedure} execl filename . args
+@deffn {Scheme Procedure} execl filename arg @dots{}
@deffnx {C Function} scm_execl (filename, args)
-Executes the file named by @var{path} as a new process image.
+Executes the file named by @var{filename} as a new process image.
The remaining arguments are supplied to the process; from a C program
they are accessible as the @code{argv} argument to @code{main}.
-Conventionally the first @var{arg} is the same as @var{path}.
+Conventionally the first @var{arg} is the same as @var{filename}.
All arguments must be strings.
-If @var{arg} is missing, @var{path} is executed with a null
+If @var{arg} is missing, @var{filename} is executed with a null
argument list, which may have system-dependent side-effects.
This procedure is currently implemented using the @code{execv} system
call, but we call it @code{execl} because of its Scheme calling interface.
@end deffn
-@deffn {Scheme Procedure} execlp filename . args
+@deffn {Scheme Procedure} execlp filename arg @dots{}
@deffnx {C Function} scm_execlp (filename, args)
Similar to @code{execl}, however if
@var{filename} does not contain a slash
@@ -1769,7 +1769,7 @@ This procedure is currently implemented using the @code{execvp} system
call, but we call it @code{execlp} because of its Scheme calling interface.
@end deffn
-@deffn {Scheme Procedure} execle filename env . args
+@deffn {Scheme Procedure} execle filename env arg @dots{}
@deffnx {C Function} scm_execle (filename, env, args)
Similar to @code{execl}, but the environment of the new process is
specified by @var{env}, which must be a list of strings as returned by the
@@ -2502,9 +2502,9 @@ Either @var{name} does not resolve for the supplied parameters,
or neither @var{name} nor @var{service} were supplied.
@item EAI_NODATA
-This non-POSIX error code can be returned on GNU systems when a
-request was actually made but returned no data, meaning
-that no address is associated with @var{name}. Error handling
+This non-POSIX error code can be returned on some systems (GNU
+and Darwin, at least), for example when @var{name} is known
+but requests that were made turned out no data. Error handling
code should be prepared to handle it when it is defined.
@item EAI_SERVICE
@@ -2841,7 +2841,7 @@ created with,
@deffn {Scheme Procedure} make-socket-address AF_INET ipv4addr port
@deffnx {Scheme Procedure} make-socket-address AF_INET6 ipv6addr port [flowinfo [scopeid]]
@deffnx {Scheme Procedure} make-socket-address AF_UNIX path
-@deffnx {C Function} scm_make_socket_address family address arglist
+@deffnx {C Function} scm_make_socket_address (family, address, arglist)
Return a new socket address object. The first argument is the address
family, one of the @code{AF} constants, then the arguments vary
according to the family.
diff --git a/doc/ref/r6rs.texi b/doc/ref/r6rs.texi
index df14cc050..f9bc9e977 100644
--- a/doc/ref/r6rs.texi
+++ b/doc/ref/r6rs.texi
@@ -273,8 +273,10 @@ grouped below by the existing manual sections to which they correspond.
@end deffn
@deffn {Scheme Syntax} define-syntax keyword expression
-@deffnx {Scheme Syntax} let-syntax ((keyword transformer) ...) exp ...
-@deffnx {Scheme Syntax} letrec-syntax ((keyword transformer) ...) exp ...
+@deffnx {Scheme Syntax} let-syntax ((keyword transformer) @dots{})
+ exp1 exp2 @dots{}
+@deffnx {Scheme Syntax} letrec-syntax ((keyword transformer) @dots{})
+ exp1 exp2 @dots{}
@xref{Defining Macros}, for documentation.
@end deffn
@@ -403,7 +405,7 @@ grouped below by the existing manual sections to which they correspond.
@xref{SRFI-1 Fold and Map}, for documentation.
@end deffn
-@deffn {Scheme Procedure} list elem1 ... elemN
+@deffn {Scheme Procedure} list elem @dots{}
@xref{List Constructors}, for documentation.
@end deffn
@@ -413,7 +415,8 @@ grouped below by the existing manual sections to which they correspond.
@xref{List Selection}, for documentation.
@end deffn
-@deffn {Scheme Procedure} append lst1 ... lstN
+@deffn {Scheme Procedure} append lst @dots{} obj
+@deffnx {Scheme Procedure} append
@deffnx {Scheme Procedure} reverse lst
@xref{Append/Reverse}, for documentation.
@end deffn
@@ -440,15 +443,15 @@ grouped below by the existing manual sections to which they correspond.
@xref{String Selection}, for documentation.
@end deffn
-@deffn {Scheme Procedure} string=? [s1 [s2 . rest]]
-@deffnx {Scheme Procedure} string<? [s1 [s2 . rest]]
-@deffnx {Scheme Procedure} string>? [s1 [s2 . rest]]
-@deffnx {Scheme Procedure} string<=? [s1 [s2 . rest]]
-@deffnx {Scheme Procedure} string>=? [s1 [s2 . rest]]
+@deffn {Scheme Procedure} string=? s1 s2 s3 @dots{}
+@deffnx {Scheme Procedure} string<? s1 s2 s3 @dots{}
+@deffnx {Scheme Procedure} string>? s1 s2 s3 @dots{}
+@deffnx {Scheme Procedure} string<=? s1 s2 s3 @dots{}
+@deffnx {Scheme Procedure} string>=? s1 s2 s3 @dots{}
@xref{String Comparison}, for documentation.
@end deffn
-@deffn {Scheme Procedure} string-append . args
+@deffn {Scheme Procedure} string-append arg @dots{}
@xref{Reversing and Appending Strings}, for documentation.
@end deffn
@@ -579,7 +582,7 @@ These procedures implement the @code{map} and @code{for-each} contracts
over vectors.
@end deffn
-@deffn {Scheme Procedure} vector . l
+@deffn {Scheme Procedure} vector arg @dots{}
@deffnx {Scheme Procedure} vector? obj
@deffnx {Scheme Procedure} make-vector len
@deffnx {Scheme Procedure} make-vector len fill
@@ -600,7 +603,7 @@ over vectors.
@xref{Continuations}, for documentation.
@end deffn
-@deffn {Scheme Procedure} values arg1 ... argN
+@deffn {Scheme Procedure} values arg @dots{}
@deffnx {Scheme Procedure} call-with-values producer consumer
@xref{Multiple Values}, for documentation.
@end deffn
@@ -609,7 +612,7 @@ over vectors.
@xref{Dynamic Wind}, for documentation.
@end deffn
-@deffn {Scheme Procedure} apply proc arg1 ... argN arglst
+@deffn {Scheme Procedure} apply proc arg @dots{} arglst
@xref{Fly Evaluation}, for documentation.
@end deffn
@@ -717,8 +720,8 @@ These procedures are identical to the ones provided by SRFI-1.
@xref{SRFI-1 Filtering and Partitioning}, for @code{partition}.
@end deffn
-@deffn {Scheme Procedure} fold-left combine nil list1 list2 ... listn
-@deffnx {Scheme Procedure} fold-right combine nil list1 list2 ... listn
+@deffn {Scheme Procedure} fold-left combine nil list1 list2 @dots{}
+@deffnx {Scheme Procedure} fold-right combine nil list1 list2 @dots{}
These procedures are identical to the @code{fold} and @code{fold-right}
procedures provided by SRFI-1. @xref{SRFI-1 Fold and Map}, for
documentation.
@@ -903,7 +906,7 @@ compatible with either.
The @code{(rnrs records syntactic (6))} library exports the syntactic
API for working with R6RS records.
-@deffn {Scheme Syntax} define-record-type name-spec record-clause*
+@deffn {Scheme Syntax} define-record-type name-spec record-clause @dots{}
Defines a new record type, introducing bindings for a record-type
descriptor, a record constructor descriptor, a constructor procedure,
a record predicate, and accessor and mutator procedures for the new
diff --git a/doc/ref/scheme-using.texi b/doc/ref/scheme-using.texi
index ae608d70a..3d439132b 100644
--- a/doc/ref/scheme-using.texi
+++ b/doc/ref/scheme-using.texi
@@ -230,7 +230,7 @@ Show description/documentation.
Change modules / Show current module.
@end deffn
-@deffn {REPL Command} import [module ...]
+@deffn {REPL Command} import module @dots{}
Import modules / List those imported.
@end deffn
@@ -247,7 +247,7 @@ List current bindings.
@end deffn
@deffn {REPL Command} in module expression
-@deffnx {REPL Command} in module command [args ...]
+@deffnx {REPL Command} in module command arg @dots{}
Evaluate an expression, or alternatively, execute another meta-command
in the context of a module. For example, @samp{,in (foo bar) ,binding}
will show the bindings in the module @code{(foo bar)}.
@@ -311,7 +311,7 @@ they do not work at the top level.
@deffn {REPL Command} backtrace [count] [#:width w] [#:full? f]
Print a backtrace.
-Print a backtrace of all stack frames, or innermost @var{COUNT} frames.
+Print a backtrace of all stack frames, or innermost @var{count} frames.
If @var{count} is negative, the last @var{count} frames will be shown.
@end deffn
@@ -406,11 +406,11 @@ reenter the REPL.
@node Inspect Commands
@subsubsection Inspect Commands
-@deffn {REPL Command} inspect EXP
+@deffn {REPL Command} inspect exp
Inspect the result(s) of evaluating @var{exp}.
@end deffn
-@deffn {REPL Command} pretty-print EXP
+@deffn {REPL Command} pretty-print exp
Pretty-print the result(s) of evaluating @var{exp}.
@end deffn
diff --git a/doc/ref/srfi-modules.texi b/doc/ref/srfi-modules.texi
index 09b93ac39..44e7928bc 100644
--- a/doc/ref/srfi-modules.texi
+++ b/doc/ref/srfi-modules.texi
@@ -475,15 +475,14 @@ first containing the first elements of each lists and the second
containing the second elements of each lists, and so on.
@end deffn
-@deffn {Scheme Procedure} count pred lst1 @dots{} lstN
+@deffn {Scheme Procedure} count pred lst1 lst2 @dots{}
Return a count of the number of times @var{pred} returns true when
called on elements from the given lists.
@var{pred} is called with @var{N} parameters @code{(@var{pred}
-@var{elem1} @dots{} @var{elemN})}, each element being from the
-corresponding @var{lst1} @dots{} @var{lstN}. The first call is with
-the first element of each list, the second with the second element
-from each, and so on.
+@var{elem1} @dots{} @var{elemN} )}, each element being from the
+corresponding list. The first call is with the first element of each
+list, the second with the second element from each, and so on.
Counting stops when the end of the shortest list is reached. At least
one list must be non-circular.
@@ -497,14 +496,14 @@ one list must be non-circular.
@c FIXME::martin: Review me!
-@deffn {Scheme Procedure} fold proc init lst1 @dots{} lstN
-@deffnx {Scheme Procedure} fold-right proc init lst1 @dots{} lstN
-Apply @var{proc} to the elements of @var{lst1} @dots{} @var{lstN} to
+@deffn {Scheme Procedure} fold proc init lst1 lst2 @dots{}
+@deffnx {Scheme Procedure} fold-right proc init lst1 lst2 @dots{}
+Apply @var{proc} to the elements of @var{lst1} @var{lst2} @dots{} to
build a result, and return that result.
-Each @var{proc} call is @code{(@var{proc} @var{elem1} @dots{}
-@var{elemN} @var{previous})}, where @var{elem1} is from @var{lst1},
-through @var{elemN} from @var{lstN}. @var{previous} is the return
+Each @var{proc} call is @code{(@var{proc} @var{elem1} @var{elem2}
+@dots{} @var{previous})}, where @var{elem1} is from @var{lst1},
+@var{elem2} is from @var{lst2}, and so on. @var{previous} is the return
from the previous call to @var{proc}, or the given @var{init} for the
first call. If any list is empty, just @var{init} is returned.
@@ -534,11 +533,11 @@ string, and the last among equal longest,
@result{} "xyz"
@end example
-If @var{lst1} through @var{lstN} have different lengths, @code{fold}
+If @var{lst1} @var{lst2} @dots{} have different lengths, @code{fold}
stops when the end of the shortest is reached; @code{fold-right}
-commences at the last element of the shortest. Ie.@: elements past
-the length of the shortest are ignored in the other @var{lst}s. At
-least one @var{lst} must be non-circular.
+commences at the last element of the shortest. Ie.@: elements past the
+length of the shortest are ignored in the other @var{lst}s. At least
+one @var{lst} must be non-circular.
@code{fold} should be preferred over @code{fold-right} if the order of
processing doesn't matter, or can be arranged either way, since
@@ -567,8 +566,8 @@ a variable in which to build the result, but a self-contained
@code{for-each} would have to be written out each time.
@end deffn
-@deffn {Scheme Procedure} pair-fold proc init lst1 @dots{} lstN
-@deffnx {Scheme Procedure} pair-fold-right proc init lst1 @dots{} lstN
+@deffn {Scheme Procedure} pair-fold proc init lst1 lst2 @dots{}
+@deffnx {Scheme Procedure} pair-fold-right proc init lst1 lst2 @dots{}
The same as @code{fold} and @code{fold-right}, but apply @var{proc} to
the pairs of the lists instead of the list elements.
@end deffn
@@ -839,48 +838,51 @@ wanting to use @code{break} from within a @code{while} loop will need
to make a new define under a different name.
@end deffn
-@deffn {Scheme Procedure} any pred lst1 lst2 @dots{} lstN
-Test whether any set of elements from @var{lst1} @dots{} lstN
-satisfies @var{pred}. If so the return value is the return from the
-successful @var{pred} call, or if not the return is @code{#f}.
+@deffn {Scheme Procedure} any pred lst1 lst2 @dots{}
+Test whether any set of elements from @var{lst1} @var{lst2} @dots{}
+satisfies @var{pred}. If so, the return value is the return value from
+the successful @var{pred} call, or if not, the return value is
+@code{#f}.
-Each @var{pred} call is @code{(@var{pred} @var{elem1} @dots{}
-@var{elemN})} taking an element from each @var{lst}. The calls are
-made successively for the first, second, etc elements of the lists,
-stopping when @var{pred} returns non-@code{#f}, or when the end of the
-shortest list is reached.
+If there are n list arguments, then @var{pred} must be a predicate
+taking n arguments. Each @var{pred} call is @code{(@var{pred}
+@var{elem1} @var{elem2} @dots{} )} taking an element from each
+@var{lst}. The calls are made successively for the first, second, etc.
+elements of the lists, stopping when @var{pred} returns non-@code{#f},
+or when the end of the shortest list is reached.
-The @var{pred} call on the last set of elements (ie.@: when the end of
+The @var{pred} call on the last set of elements (i.e., when the end of
the shortest list has been reached), if that point is reached, is a
tail call.
@end deffn
-@deffn {Scheme Procedure} every pred lst1 lst2 @dots{} lstN
-Test whether every set of elements from @var{lst1} @dots{} lstN
-satisfies @var{pred}. If so the return value is the return from the
-final @var{pred} call, or if not the return is @code{#f}.
+@deffn {Scheme Procedure} every pred lst1 lst2 @dots{}
+Test whether every set of elements from @var{lst1} @var{lst2} @dots{}
+satisfies @var{pred}. If so, the return value is the return from the
+final @var{pred} call, or if not, the return value is @code{#f}.
-Each @var{pred} call is @code{(@var{pred} @var{elem1} @dots{}
-@var{elemN})} taking an element from each @var{lst}. The calls are
-made successively for the first, second, etc elements of the lists,
-stopping if @var{pred} returns @code{#f}, or when the end of any of
-the lists is reached.
+If there are n list arguments, then @var{pred} must be a predicate
+taking n arguments. Each @var{pred} call is @code{(@var{pred}
+@var{elem1} @var{elem2 @dots{}})} taking an element from each
+@var{lst}. The calls are made successively for the first, second, etc.
+elements of the lists, stopping if @var{pred} returns @code{#f}, or when
+the end of any of the lists is reached.
-The @var{pred} call on the last set of elements (ie.@: when the end of
+The @var{pred} call on the last set of elements (i.e., when the end of
the shortest list has been reached) is a tail call.
-If one of @var{lst1} @dots{} @var{lstN} is empty then no calls to
-@var{pred} are made, and the return is @code{#t}.
+If one of @var{lst1} @var{lst2} @dots{}is empty then no calls to
+@var{pred} are made, and the return value is @code{#t}.
@end deffn
-@deffn {Scheme Procedure} list-index pred lst1 @dots{} lstN
+@deffn {Scheme Procedure} list-index pred lst1 lst2 @dots{}
Return the index of the first set of elements, one from each of
-@var{lst1}@dots{}@var{lstN}, which satisfies @var{pred}.
+@var{lst1} @var{lst2} @dots{}, which satisfies @var{pred}.
-@var{pred} is called as @code{(@var{pred} elem1 @dots{} elemN)}.
+@var{pred} is called as @code{(@var{elem1} @var{elem2 @dots{}})}.
Searching stops when the end of the shortest @var{lst} is reached.
The return index starts from 0 for the first set of elements. If no
-set of elements pass then the return is @code{#f}.
+set of elements pass, then the return value is @code{#f}.
@example
(list-index odd? '(2 4 6 9)) @result{} 3
@@ -1045,11 +1047,11 @@ sameness. This predicate must be consistent with @code{eq?}
@code{eq?} then they must also be equal under the predicate. This
simply means a given object must be equal to itself.
-@deffn {Scheme Procedure} lset<= = list1 list2 @dots{}
+@deffn {Scheme Procedure} lset<= = list @dots{}
Return @code{#t} if each list is a subset of the one following it.
-Ie.@: @var{list1} a subset of @var{list2}, @var{list2} a subset of
-@var{list3}, etc, for as many lists as given. If only one list or no
-lists are given then the return is @code{#t}.
+I.e., @var{list1} is a subset of @var{list2}, @var{list2} is a subset of
+@var{list3}, etc., for as many lists as given. If only one list or no
+lists are given, the return value is @code{#t}.
A list @var{x} is a subset of @var{y} if each element of @var{x} is
equal to some element in @var{y}. Elements are compared using the
@@ -1062,11 +1064,11 @@ given @var{=} procedure, called as @code{(@var{=} xelem yelem)}.
@end example
@end deffn
-@deffn {Scheme Procedure} lset= = list1 list2 @dots{}
+@deffn {Scheme Procedure} lset= = list @dots{}
Return @code{#t} if all argument lists are set-equal. @var{list1} is
-compared to @var{list2}, @var{list2} to @var{list3}, etc, for as many
-lists as given. If only one list or no lists are given then the
-return is @code{#t}.
+compared to @var{list2}, @var{list2} to @var{list3}, etc., for as many
+lists as given. If only one list or no lists are given, the return
+value is @code{#t}.
Two lists @var{x} and @var{y} are set-equal if each element of @var{x}
is equal to some element of @var{y} and conversely each element of
@@ -1082,14 +1084,14 @@ yelem)}, but exactly which calls are made is unspecified.
@end example
@end deffn
-@deffn {Scheme Procedure} lset-adjoin = list elem1 @dots{}
-Add to @var{list} any of the given @var{elem}s not already in the
-list. @var{elem}s are @code{cons}ed onto the start of @var{list} (so
-the return shares a common tail with @var{list}), but the order
-they're added is unspecified.
+@deffn {Scheme Procedure} lset-adjoin = list elem @dots{}
+Add to @var{list} any of the given @var{elem}s not already in the list.
+@var{elem}s are @code{cons}ed onto the start of @var{list} (so the
+return value shares a common tail with @var{list}), but the order that
+the @var{elem}s are added is unspecified.
The given @var{=} procedure is used for comparing elements, called as
-@code{(@var{=} listelem elem)}, ie.@: the second argument is one of
+@code{(@var{=} listelem elem)}, i.e., the second argument is one of
the given @var{elem} parameters.
@example
@@ -1097,11 +1099,11 @@ the given @var{elem} parameters.
@end example
@end deffn
-@deffn {Scheme Procedure} lset-union = list1 list2 @dots{}
-@deffnx {Scheme Procedure} lset-union! = list1 list2 @dots{}
+@deffn {Scheme Procedure} lset-union = list @dots{}
+@deffnx {Scheme Procedure} lset-union! = list @dots{}
Return the union of the argument list sets. The result is built by
taking the union of @var{list1} and @var{list2}, then the union of
-that with @var{list3}, etc, for as many lists as given. For one list
+that with @var{list3}, etc., for as many lists as given. For one list
argument that list itself is the result, for no list arguments the
result is the empty list.
@@ -1197,8 +1199,8 @@ a tail with @var{list1}. @code{lset-diff+intersection!} may modify
@var{list1} to form its results.
@end deffn
-@deffn {Scheme Procedure} lset-xor = list1 list2 @dots{}
-@deffnx {Scheme Procedure} lset-xor! = list1 list2 @dots{}
+@deffn {Scheme Procedure} lset-xor = list @dots{}
+@deffnx {Scheme Procedure} lset-xor! = list @dots{}
Return an XOR of the argument lists. For two lists this means those
elements which are in exactly one of the lists. For more than two
lists it means those elements which appear in an odd number of the
@@ -1461,18 +1463,18 @@ indicated type.
@deffnx {Scheme Procedure} make-f64vector n [value]
@deffnx {Scheme Procedure} make-c32vector n [value]
@deffnx {Scheme Procedure} make-c64vector n [value]
-@deffnx {C Function} scm_make_u8vector n [value]
-@deffnx {C Function} scm_make_s8vector n [value]
-@deffnx {C Function} scm_make_u16vector n [value]
-@deffnx {C Function} scm_make_s16vector n [value]
-@deffnx {C Function} scm_make_u32vector n [value]
-@deffnx {C Function} scm_make_s32vector n [value]
-@deffnx {C Function} scm_make_u64vector n [value]
-@deffnx {C Function} scm_make_s64vector n [value]
-@deffnx {C Function} scm_make_f32vector n [value]
-@deffnx {C Function} scm_make_f64vector n [value]
-@deffnx {C Function} scm_make_c32vector n [value]
-@deffnx {C Function} scm_make_c64vector n [value]
+@deffnx {C Function} scm_make_u8vector (n, value)
+@deffnx {C Function} scm_make_s8vector (n, value)
+@deffnx {C Function} scm_make_u16vector (n, value)
+@deffnx {C Function} scm_make_s16vector (n, value)
+@deffnx {C Function} scm_make_u32vector (n, value)
+@deffnx {C Function} scm_make_s32vector (n, value)
+@deffnx {C Function} scm_make_u64vector (n, value)
+@deffnx {C Function} scm_make_s64vector (n, value)
+@deffnx {C Function} scm_make_f32vector (n, value)
+@deffnx {C Function} scm_make_f64vector (n, value)
+@deffnx {C Function} scm_make_c32vector (n, value)
+@deffnx {C Function} scm_make_c64vector (n, value)
Return a newly allocated homogeneous numeric vector holding @var{n}
elements of the indicated type. If @var{value} is given, the vector
is initialized with that value, otherwise the contents are
@@ -1547,18 +1549,18 @@ Return the number of elements in @var{vec}.
@deffnx {Scheme Procedure} f64vector-ref vec i
@deffnx {Scheme Procedure} c32vector-ref vec i
@deffnx {Scheme Procedure} c64vector-ref vec i
-@deffnx {C Function} scm_u8vector_ref (vec i)
-@deffnx {C Function} scm_s8vector_ref (vec i)
-@deffnx {C Function} scm_u16vector_ref (vec i)
-@deffnx {C Function} scm_s16vector_ref (vec i)
-@deffnx {C Function} scm_u32vector_ref (vec i)
-@deffnx {C Function} scm_s32vector_ref (vec i)
-@deffnx {C Function} scm_u64vector_ref (vec i)
-@deffnx {C Function} scm_s64vector_ref (vec i)
-@deffnx {C Function} scm_f32vector_ref (vec i)
-@deffnx {C Function} scm_f64vector_ref (vec i)
-@deffnx {C Function} scm_c32vector_ref (vec i)
-@deffnx {C Function} scm_c64vector_ref (vec i)
+@deffnx {C Function} scm_u8vector_ref (vec, i)
+@deffnx {C Function} scm_s8vector_ref (vec, i)
+@deffnx {C Function} scm_u16vector_ref (vec, i)
+@deffnx {C Function} scm_s16vector_ref (vec, i)
+@deffnx {C Function} scm_u32vector_ref (vec, i)
+@deffnx {C Function} scm_s32vector_ref (vec, i)
+@deffnx {C Function} scm_u64vector_ref (vec, i)
+@deffnx {C Function} scm_s64vector_ref (vec, i)
+@deffnx {C Function} scm_f32vector_ref (vec, i)
+@deffnx {C Function} scm_f64vector_ref (vec, i)
+@deffnx {C Function} scm_c32vector_ref (vec, i)
+@deffnx {C Function} scm_c64vector_ref (vec, i)
Return the element at index @var{i} in @var{vec}. The first element
in @var{vec} is index 0.
@end deffn
@@ -1575,18 +1577,18 @@ in @var{vec} is index 0.
@deffnx {Scheme Procedure} f64vector-set! vec i value
@deffnx {Scheme Procedure} c32vector-set! vec i value
@deffnx {Scheme Procedure} c64vector-set! vec i value
-@deffnx {C Function} scm_u8vector_set_x (vec i value)
-@deffnx {C Function} scm_s8vector_set_x (vec i value)
-@deffnx {C Function} scm_u16vector_set_x (vec i value)
-@deffnx {C Function} scm_s16vector_set_x (vec i value)
-@deffnx {C Function} scm_u32vector_set_x (vec i value)
-@deffnx {C Function} scm_s32vector_set_x (vec i value)
-@deffnx {C Function} scm_u64vector_set_x (vec i value)
-@deffnx {C Function} scm_s64vector_set_x (vec i value)
-@deffnx {C Function} scm_f32vector_set_x (vec i value)
-@deffnx {C Function} scm_f64vector_set_x (vec i value)
-@deffnx {C Function} scm_c32vector_set_x (vec i value)
-@deffnx {C Function} scm_c64vector_set_x (vec i value)
+@deffnx {C Function} scm_u8vector_set_x (vec, i, value)
+@deffnx {C Function} scm_s8vector_set_x (vec, i, value)
+@deffnx {C Function} scm_u16vector_set_x (vec, i, value)
+@deffnx {C Function} scm_s16vector_set_x (vec, i, value)
+@deffnx {C Function} scm_u32vector_set_x (vec, i, value)
+@deffnx {C Function} scm_s32vector_set_x (vec, i, value)
+@deffnx {C Function} scm_u64vector_set_x (vec, i, value)
+@deffnx {C Function} scm_s64vector_set_x (vec, i, value)
+@deffnx {C Function} scm_f32vector_set_x (vec, i, value)
+@deffnx {C Function} scm_f64vector_set_x (vec, i, value)
+@deffnx {C Function} scm_c32vector_set_x (vec, i, value)
+@deffnx {C Function} scm_c64vector_set_x (vec, i, value)
Set the element at index @var{i} in @var{vec} to @var{value}. The
first element in @var{vec} is index 0. The return value is
unspecified.
@@ -1734,13 +1736,13 @@ Return the number of elements in @var{vec}.
@end deffn
@deffn {Scheme Procedure} uniform-vector-ref vec i
-@deffnx {C Function} scm_uniform_vector_ref (vec i)
+@deffnx {C Function} scm_uniform_vector_ref (vec, i)
Return the element at index @var{i} in @var{vec}. The first element
in @var{vec} is index 0.
@end deffn
@deffn {Scheme Procedure} uniform-vector-set! vec i value
-@deffnx {C Function} scm_uniform_vector_set_x (vec i value)
+@deffnx {C Function} scm_uniform_vector_set_x (vec, i, value)
Set the element at index @var{i} in @var{vec} to @var{value}. The
first element in @var{vec} is index 0. The return value is
unspecified.
@@ -2322,7 +2324,7 @@ any) will be stored for later retrieval via a call to
Wait for @var{thread} to terminate and return its exit value. When a
time value @var{timeout} is given, it specifies a point in time where
the waiting should be aborted. When the waiting is aborted,
-@var{timeoutval} is returned if it is specified; otherwise, a
+@var{timeout-val} is returned if it is specified; otherwise, a
@code{join-timeout-exception} exception is raised
(@pxref{SRFI-18 Exceptions}). Exceptions may also be raised if the
thread was terminated by a call to @code{thread-terminate!}
@@ -2430,8 +2432,8 @@ replaces a procedure of the same name in the core library.
@end defun
@defun condition-variable-name condition-variable
-Returns the name assigned to @var{thread} at the time of its creation,
-or @code{#f} if it was not given a name.
+Returns the name assigned to @var{condition-variable} at the time of its
+creation, or @code{#f} if it was not given a name.
@end defun
@defun condition-variable-specific condition-variable
@@ -3156,10 +3158,10 @@ parameters of a function. It can be used with,
(use-modules (srfi srfi-26))
@end example
-@deffn {library syntax} cut slot @dots{}
-@deffnx {library syntax} cute slot @dots{}
-Return a new procedure which will make a call (@var{slot} @dots{}) but
-with selected parameters specialized to given expressions.
+@deffn {library syntax} cut slot1 slot2 @dots{}
+@deffnx {library syntax} cute slot1 slot2 @dots{}
+Return a new procedure which will make a call (@var{slot1} @var{slot2}
+@dots{}) but with selected parameters specialized to given expressions.
An example will illustrate the idea. The following is a
specialization of @code{write}, sending output to
@@ -3517,7 +3519,7 @@ values as in the following example:
Note that all fields of @var{type} and its supertypes must be specified.
@end deffn
-@deffn {Scheme Procedure} make-compound-condition . conditions
+@deffn {Scheme Procedure} make-compound-condition condition1 condition2 @dots{}
Return a new compound condition composed of @var{conditions}. The
returned condition has the type of each condition of @var{conditions}
(per @code{condition-has-type?}).
@@ -3533,7 +3535,7 @@ Return the value of the field named @var{field-name} from condition @var{c}.
If @var{c} is a compound condition and several underlying condition
types contain a field named @var{field-name}, then the value of the
first such field is returned, using the order in which conditions were
-passed to @var{make-compound-condition}.
+passed to @code{make-compound-condition}.
@end deffn
@deffn {Scheme Procedure} extract-condition c type
@@ -3569,13 +3571,14 @@ The example below defines condition type @code{&foo}, inheriting from
@end lisp
@end deffn
-@deffn {library syntax} condition type-field-bindings...
-Return a new condition, or compound condition, initialized according to
-@var{type-field-bindings}. Each @var{type-field-binding} must have the
-form @code{(type field-specs...)}, where @var{type} is the name of a
-variable bound to condition type; each @var{field-spec} must have the
-form @code{(field-name value)} where @var{field-name} is a symbol
-denoting the field being initialized to @var{value}. As for
+@deffn {library syntax} condition type-field-binding1 type-field-binding2 @dots{}
+Return a new condition or compound condition, initialized according to
+@var{type-field-binding1} @var{type-field-binding2} @enddots{}. Each
+@var{type-field-binding} must have the form @code{(type
+field-specs...)}, where @var{type} is the name of a variable bound to a
+condition type; each @var{field-spec} must have the form
+@code{(field-name value)} where @var{field-name} is a symbol denoting
+the field being initialized to @var{value}. As for
@code{make-condition}, all fields must be specified.
The following example returns a simple condition:
@@ -3703,12 +3706,12 @@ Return the specified field of @var{opt}, an option object, as
described above for @code{option}.
@end deffn
-@deffn {Scheme Procedure} args-fold args options unrecognized-option-proc operand-proc seeds @dots{}
-Process @var{args}, a list of program arguments such as that returned
-by @code{(cdr (program-arguments))}, in order against @var{options}, a
-list of option objects as described above. All functions called take
-the ``seeds'', or the last multiple-values as multiple arguments,
-starting with @var{seeds}, and must return the new seeds. Return the
+@deffn {Scheme Procedure} args-fold args options unrecognized-option-proc operand-proc seed @dots{}
+Process @var{args}, a list of program arguments such as that returned by
+@code{(cdr (program-arguments))}, in order against @var{options}, a list
+of option objects as described above. All functions called take the
+``seeds'', or the last multiple-values as multiple arguments, starting
+with @var{seed} @dots{}, and must return the new seeds. Return the
final seeds.
Call @code{unrecognized-option-proc}, which is like an option object's
@@ -3858,7 +3861,7 @@ This is a Guile-specific addition to the SRFI, similar to the core
@defun with-parameters* param-list value-list thunk
Establish a new dynamic scope, as per @code{parameterize} above,
taking parameters from @var{param-list} and corresponding values from
-@var{values-list}. A call @code{(@var{thunk})} is made in the new
+@var{value-list}. A call @code{(@var{thunk})} is made in the new
scope and the result from that @var{thunk} is the return from
@code{with-parameters*}.
@end defun
@@ -4021,9 +4024,9 @@ SRFI-55 provides @code{require-extension} which is a portable
mechanism to load selected SRFI modules. This is implemented in the
Guile core, there's no module needed to get SRFI-55 itself.
-@deffn {library syntax} require-extension clause@dots{}
-Require each of the given @var{clause} features, throwing an error if
-any are unavailable.
+@deffn {library syntax} require-extension clause1 clause2 @dots{}
+Require the features of @var{clause1} @var{clause2} @dots{} , throwing
+an error if any are unavailable.
A @var{clause} is of the form @code{(@var{identifier} arg...)}. The
only @var{identifier} currently supported is @code{srfi} and the
diff --git a/doc/ref/sxml-match.texi b/doc/ref/sxml-match.texi
index 7b82e1177..7a1a9ac7c 100644
--- a/doc/ref/sxml-match.texi
+++ b/doc/ref/sxml-match.texi
@@ -64,7 +64,7 @@ Dybvig at Indiana University.
@code{sxml-match} provides @code{case}-like form for pattern matching of XML
nodes.
-@deffn {Scheme Syntax} sxml-match input-expression clause ...
+@deffn {Scheme Syntax} sxml-match input-expression clause1 clause2 @dots{}
Match @var{input-expression}, an SXML tree, according to the given @var{clause}s
(one or more), each consisting of a pattern and one or more expressions to be
evaluated if the pattern match succeeds. Optionally, each @var{clause} within
@@ -356,8 +356,8 @@ transformation that formats a ``TV Guide'' into HTML.
@unnumberedsubsec @code{sxml-match-let} and @code{sxml-match-let*}
-@deffn {Scheme Syntax} sxml-match-let ((pat expr) ...) expression0 expression ...)
-@deffnx {Scheme Syntax} sxml-match-let* ((pat expr) ...) expression0 expression ...)
+@deffn {Scheme Syntax} sxml-match-let ((pat expr) ...) expression0 expression ...
+@deffnx {Scheme Syntax} sxml-match-let* ((pat expr) ...) expression0 expression ...
These forms generalize the @code{let} and @code{let*} forms of Scheme to allow
an XML pattern in the binding position, rather than a simple variable.
@end deffn
diff --git a/doc/ref/vm.texi b/doc/ref/vm.texi
index 398129e2b..c5b80761c 100644
--- a/doc/ref/vm.texi
+++ b/doc/ref/vm.texi
@@ -432,7 +432,7 @@ then @code{local-set}, used when binding boxed variables.
@end deffn
@deffn Instruction empty-box index
-Set the @var{indext}h local variable to a box containing a variable
+Set the @var{index}th local variable to a box containing a variable
whose value is unbound. Used when compiling some @code{letrec}
expressions.
@end deffn
@@ -918,13 +918,13 @@ Jump to @var{offset} if the object on the stack is false.
@deffn Instruction br-if-eq offset
Jump to @var{offset} if the two objects located on the stack are
-equal in the sense of @var{eq?}. Note that, for this instruction, the
+equal in the sense of @code{eq?}. Note that, for this instruction, the
stack pointer is decremented by two Scheme objects instead of only
one.
@end deffn
@deffn Instruction br-if-not-eq offset
-Same as @var{br-if-eq} for non-@code{eq?} objects.
+Same as @code{br-if-eq} for non-@code{eq?} objects.
@end deffn
@deffn Instruction br-if-null offset
diff --git a/doc/ref/web.texi b/doc/ref/web.texi
index a08cd2cce..81c77dd0b 100644
--- a/doc/ref/web.texi
+++ b/doc/ref/web.texi
@@ -1116,7 +1116,7 @@ if there was no request body.
@end deffn
@deffn {Scheme Procedure} write-request-body r bv
-Write @var{body}, a bytevector, to the port corresponding to the HTTP
+Write @var{bv}, a bytevector, to the port corresponding to the HTTP
request @var{r}.
@end deffn
@@ -1212,7 +1212,7 @@ As a side effect, sets the encoding on @var{port} to ISO-8859-1
discussion of character sets in @ref{Responses}, for more information.
@end deffn
-@deffn {Scheme Procedure} build-response [#:version='(1 . 1)] [#:code=200] [#:reason-phrase=#f] [#:headers='()] [#:port=#f] [#:validate-headers=#t]
+@deffn {Scheme Procedure} build-response [#:version='(1 . 1)] [#:code=200] [#:reason-phrase=#f] [#:headers='()] [#:port=#f] [#:validate-headers?=#t]
Construct an HTTP response object. If @var{validate-headers?} is true,
the headers are each run through their respective validators.
@end deffn
@@ -1241,7 +1241,7 @@ if there was no response body.
@end deffn
@deffn {Scheme Procedure} write-response-body r bv
-Write @var{body}, a bytevector, to the port corresponding to the HTTP
+Write @var{bv}, a bytevector, to the port corresponding to the HTTP
response @var{r}.
@end deffn
@@ -1291,7 +1291,7 @@ the lower-level HTTP, request, and response modules.
@deffn {Scheme Procedure} open-socket-for-uri uri
@end deffn
-@deffn {Scheme Procedure} http-get uri [#:port=(open-socket-for-uri uri)] [#:version='(1 . 1)] [#:keep-alive?=#f] [#:extra-headers='()] [#:decode-body=#t]
+@deffn {Scheme Procedure} http-get uri [#:port=(open-socket-for-uri uri)] [#:version='(1 . 1)] [#:keep-alive?=#f] [#:extra-headers='()] [#:decode-body?=#t]
Connect to the server corresponding to @var{uri} and ask for the
resource, using the @code{GET} method. If you already have a port open,
pass it as @var{port}. The port will be closed at the end of the
diff --git a/doc/sources/ChangeLog-2008 b/doc/sources/ChangeLog-2008
deleted file mode 100644
index 1df00138b..000000000
--- a/doc/sources/ChangeLog-2008
+++ /dev/null
@@ -1,5 +0,0 @@
-2001-08-27 Neil Jerram <neil@ossau.uklinux.net>
-
- The change log for files in this directory continues backwards
- from 2001-08-27 in ../ChangeLog, as all the Guile documentation
- prior to this date was contained in a single directory.
diff --git a/doc/sources/Makefile.am b/doc/sources/Makefile.am
deleted file mode 100644
index 253d4b31d..000000000
--- a/doc/sources/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-# -*- Makefile -*-
-
-EXTRA_DIST = libguile-overview.texi snarf.texi contributors.texi \
- libguile-tools.texi strings.texi data-rep.texi new-types.texi tk.texi \
- debug-c.texi old-intro.texi unix-other.texi debug-scheme.texi \
- sample-APIs.texi unix.texi guile-slib.texi scheme-concepts.texi \
- jimb-org.texi scm-ref.texi ChangeLog-2008
diff --git a/doc/sources/contributors.texi b/doc/sources/contributors.texi
deleted file mode 100644
index 578c358f7..000000000
--- a/doc/sources/contributors.texi
+++ /dev/null
@@ -1,80 +0,0 @@
-@node Contributors to Guile
-@appendix Contributors to Guile
-
-This Guile Manual was written by Mark Galassi, Jim Blandy and Gary
-Houston.
-
-Guile was developed over many years by the following people:
-
-@table @strong
-@item George Carrette
-Wrote files present in Siod version 2.3, released in December of 1989.
-
-@item Aubrey Jaffer
-Wrote substantial portions of guile.texi, and surely others.
-Changes to: eval.c, ioext.c, posix.c, gscm.c, scm.h, socket.c,
-gsubr.c, sys.c, test.scm, stime.c, and unif.c.
-
-@item Gary Houston
-changes to many files in libguile.
-
-wrote: libguile/socket.c, ice-9/expect.scm
-
-@item Tom Lord
-Many changes throughout.
-In the subdirectory ctax, wrote:
- Makefile.in configure.in hashtabs.scm macros.scm scm-ops.scm
- c-ops.scm grammar.scm lexer.scm reader.scm
-In the subdirectory gtcltk-lib, wrote:
- Makefile.in guile-tcl.c guile-tk.c
- configure.in guile-tcl.h guile-tk.h
-In the subdirectory guile, wrote:
- Makefile.in getopt.c getopt1.c
- configure.in getopt.h guile.c
-In the subdirectory ice-9, wrote:
- Makefile.in configure.in lineio.scm poe.scm
- boot-9.scm hcons.scm mapping.scm
-In the subdirectory lang, wrote:
- Makefile.in grammar.scm lr0.scm pp.scm
- configure.in lex.scm lr1.scm
-In the subdirectory rx, wrote:
- Makefile.in runtests.c rxbitset.h rxnfa.c rxspencer.c
- TESTS rx.c rxcontext.h rxnfa.h rxspencer.h
- TESTS2C.sed rx.h rxcset.c rxnode.c rxstr.c
- _rx.h rxall.h rxcset.h rxnode.h rxstr.h
- configure.in rxanal.c rxdbug.c rxposix.c rxsuper.c
- hashrexp.c rxanal.h rxgnucomp.c rxposix.h rxsuper.h
- inst-rxposix.h rxbasic.c rxgnucomp.h rxproto.h rxunfa.c
- rgx.c rxbasic.h rxhash.c rxsimp.c rxunfa.h
- rgx.h rxbitset.c rxhash.h rxsimp.h testcases.h
-In the subdirectory doc, wrote:
- ctax.texi gtcltk.texi in.texi lang.texi
-and portions of guile.texi.
-
-@item Anthony Green
-wrote the original code in the 'threads' directory, and
-ice-9/threads.scm.
-
-@item Mikael Djurfeldt
-@example
-In the subdirectory libguile, wrote:
- backtrace.c debug.c options.c root.c srcprop.c stacks.c
- backtrace.h debug.h options.h root.h srcprop.h stacks.h
-In the subdirectory threads, rewrote:
- coop-threads.c coop.c mit-pthreads.c threads.c
- coop-threads.h fsu-pthreads.h mit-pthreads.h threads.h
-Many other changes throughout.
-@end example
-
-@item Mark Galassi
-@example
-Designed and implemented the high-level libguile API (the @code{gh_}
-interface), based largely on the defunct @code{gscm_} interface. In the
-subdirectory gh, wrote:
-gh.c gh_eval.c gh_io.c gh_test_c.c
-gh.h gh_funcs.c gh_list.c gh_test_repl.c
-gh_data.c gh_init.c gh_predicates.c
-@end example
-
-
-@end table
diff --git a/doc/sources/debug-c.texi b/doc/sources/debug-c.texi
deleted file mode 100644
index 77d02f440..000000000
--- a/doc/sources/debug-c.texi
+++ /dev/null
@@ -1,2 +0,0 @@
-@node Debugging libguile
-@chapter Debugging libguile
diff --git a/doc/sources/debug-scheme.texi b/doc/sources/debug-scheme.texi
deleted file mode 100644
index 35340f943..000000000
--- a/doc/sources/debug-scheme.texi
+++ /dev/null
@@ -1,2 +0,0 @@
-@node Debugging Scheme programs
-@chapter Debugging Scheme programs
diff --git a/doc/sources/env.texi b/doc/sources/env.texi
deleted file mode 100644
index 7a37b768b..000000000
--- a/doc/sources/env.texi
+++ /dev/null
@@ -1,1165 +0,0 @@
-\input texinfo @c -*-texinfo-*-
-@c %**start of header
-@setfilename env.info
-@settitle Top-level Environments in Guile
-@c %**end of header
-
-@setchapternewpage odd
-
-@c Changes since Jost's implementation:
-@c "finite environments" -> "leaf environments"
-@c "scm_foo_internal" -> "scm_c_foo"
-
-@c To do:
-@c add spec for soft environments
-
-@c When merged into the main manual, add cross-references for:
-@c weak references
-@c smobs (esp. module's mark and free functions)
-
-
-[[add refs for all conditions signalled]]
-
-@ifinfo
-Copyright 1999, 2006, 2012 Free Software Foundation, Inc.
-@end ifinfo
-
-@titlepage
-@sp 10
-@comment The title is printed in a large font.
-@center @titlefont{Top-level Environments in Guile}
-
-@c The following two commands start the copyright page.
-@page
-@vskip 0pt plus 1filll
-Copyright @copyright{} 1999, 2006 Free Software Foundation, Inc.
-@end titlepage
-
-@node Top, Motivation, (dir), (dir)
-
-@menu
-* Motivation::
-* Top-Level Environments in Guile::
-* Modules::
-@end menu
-
-@node Motivation, Top-Level Environments in Guile, Top, Top
-@chapter Motivation
-
-@example
-$Id: env.texi,v 1.2 2006-04-16 23:05:07 kryde Exp $
-@end example
-
-This is a draft proposal for a new datatype for representing top-level
-environments in Guile. Upon completion, this proposal will be posted to
-the mailing list @samp{guile@@cygnus.com} for discussion, revised in
-light of whatever insights that may produce, and eventually implemented.
-
-Note that this is @emph{not} a proposal for a module system; rather, it
-is a proposal for a data structure which encapsulates the ideas one
-needs when writing a module system, and, most importantly, a fixed
-interface which insulates the interpreter from the details of the module
-system. Using these environments, one could implement any module system
-one pleased, without changing the interpreter.
-
-I hope this text will eventually become a chapter of the Guile manual;
-thus, the description of environments in written in the present tense,
-as if it were already implemented, not in the future tense. However,
-this text does not actually describe the present state of Guile.
-
-I'm especially interested in improving the vague, rambling presentation
-of environments in the section "Modules and Environments". I'm trying
-to orient the user for the discussion that follows, but I wonder if I'm
-just confusing the issue. I would appreciate suggestions if they are
-concrete --- please provide new wording.
-
-Note also: I'm trying out a convention I'm considering for use in the
-manual. When a Scheme procedure which is directly implemented by a C
-procedure, and both are useful to call from their respective languages,
-we document the Scheme procedure only, and call it a "Primitive". If a
-Scheme function is marked as a primitive, you can derive the name of the
-corresponding C function by changing @code{-} to @code{_}, @code{!} to
-@code{_x}, @code{?} to @code{_p}, and prepending @code{scm_}. The C
-function's arguments will be all of the Scheme procedure's arguments,
-both required and optional; if the Scheme procedure takes a ``rest''
-argument, that will be a final argument to the C function. The C
-function's arguments, as well as its return type, will be @code{SCM}.
-Thus, a procedure documented like this:
-@deffn Primitive set-car! pair value
-@end deffn
-
-has a corresponding C function which would be documented like this:
-@deftypefn {Libguile function} SCM scm_set_car_x (SCM @var{pair}, SCM @var{value})
-@end deftypefn
-
-The hope is that this will be an uncluttered way to document both the C
-and Scheme interfaces, without unduly confusing users interested only in
-the Scheme level.
-
-When there is a C function which provides the same functionality as a
-primitive, but with a different interface tailored for C's needs, it
-usually has the same name as the primitive's C function, but with the
-prefix @code{scm_c_} instead of simply @code{scm_}. Thus,
-@code{scm_c_environment_ref} is almost identical to
-@code{scm_environment_ref}, except that it indicates an unbound variable
-in a manner friendlier to C code.
-
-
-
-@node Top-Level Environments in Guile, Modules, Motivation, Top
-@chapter Top-Level Environments in Guile
-
-In Guile, an environment is a mapping from symbols onto variables, and
-a variable is a location containing a value. Guile uses the datatype
-described here to represent its top-level environments.
-
-
-@menu
-* Modules and Environments:: Modules are environments, with bookkeeping.
-* Common Environment Operations:: Looking up bindings, creating bindings, etc.
-* Standard Environment Types:: Guile has some fundamental environment types.
-* Implementing Environments:: You can extend Guile with new kinds of
- environments.
-* Switching to Environments:: Changes needed to today's Guile to
- implement the features described here.
-@end menu
-
-@node Modules and Environments, Common Environment Operations, Top-Level Environments in Guile, Top-Level Environments in Guile
-@section Modules and Environments
-
-Guile distinguishes between environments and modules. A module is a
-unit of code sharing; it has a name, like @code{(math random)}, an
-implementation (e.g., Scheme source code, a dynamically linked library,
-or a set of primitives built into Guile), and finally, an environment
-containing the definitions which the module exports for its users.
-
-An environment, by contrast, is simply an abstract data type
-representing a mapping from symbols onto variables which the Guile
-interpreter uses to look up top-level definitions. The @code{eval}
-procedure interprets its first argument, an expression, in the context
-of its second argument, an environment.
-
-Guile uses environments to implement its module system. A module
-created by loading Scheme code might be built from several environments.
-In addition to the environment of exported definitions, such a module
-might have an internal top-level environment, containing both exported
-and private definitions, and perhaps environments for imported
-definitions alone and local definitions alone.
-
-The interface described here includes a full set of functions for
-mutating environments, and the system goes to some length to maintain
-its consistency as environments' bindings change. This is necessary
-because Guile is an interactive system. The user may create new
-definitions or modify and reload modules while Guile is running; the
-system should handle these changes in a consistent and predictable way.
-
-A typical Guile system will have several distinct top-level
-environments. (This is why we call them ``top-level'', and not
-``global''.) For example, consider the following fragment of an
-interactive Guile session:
-
-@example
-guile> (use-modules (ice-9 regex))
-guile> (define pattern "^(..+)\\1+$")
-guile> (string-match pattern "xxxx")
-#("xxxx" (0 . 4) (0 . 2))
-guile> (string-match pattern "xxxxx")
-#f
-guile>
-@end example
-@noindent
-Guile evaluates the expressions the user types in a top-level
-environment reserved for that purpose; the definition of @code{pattern}
-goes there. That environment is distinct from the one holding the
-private definitions of the @code{(ice-9 regex)} module. At the Guile
-prompt, the user does not see the module's private definitions, and the
-module is unaffected by definitions the user makes at the prompt. The
-@code{use-modules} form copies the module's public bindings into the
-user's environment.
-
-All Scheme evaluation takes place with respect to some top-level
-environment. Just as the procedure created by a @code{lambda} form
-closes over any local scopes surrounding that form, it also closes over
-the surrounding top-level environment. Thus, since the
-@code{string-match} procedure is defined in the @code{(ice-9 regex)}
-module, it closes over that module's top-level environment. Thus, when
-the user calls @code{string-match} from the Guile prompt, any free
-variables in @code{string-match}'s definition are resolved with respect
-to the module's top-level environment, not the user's.
-
-Although the Guile interaction loop maintains a ``current'' top-level
-environment in which it evaluates the user's input, it would be
-misleading to extend the concept of a ``current top-level environment''
-to the system as a whole. Each procedure closes over its own top-level
-environment, in which that procedure will find bindings for its free
-variables. Thus, the top-level environment in force at any given time
-depends on the procedure Guile happens to be executing. The global
-``current'' environment is a figment of the interaction loop's
-imagination.
-
-Since environments provide all the operations the Guile interpreter
-needs to evaluate code, they effectively insulate the interpreter from
-the details of the module system. Without changing the interpreter, you
-can implement any module system you like, as long as its efforts produce
-an environment object the interpreter can consult.
-
-Finally, environments may prove a convenient way for Guile to access the
-features of other systems. For example, one might export The GIMP's
-Procedural Database to Guile as a custom environment type; this
-environment could create Scheme procedure objects corresponding to GIMP
-procedures, as the user referenced them.
-
-
-@node Common Environment Operations, Standard Environment Types, Modules and Environments, Top-Level Environments in Guile
-@section Common Environment Operations
-
-This section describes the common set of operations that all environment
-objects support. To create an environment object, or to perform an
-operation specific to a particular kind of environment, see
-@ref{Standard Environment Types}.
-
-In this section, the following names for formal parameters imply that
-the actual parameters must have a certain type:
-
-@table @var
-
-@item env
-an environment
-
-@item symbol
-a symbol
-
-@item proc
-a procedure
-
-@item value
-@itemx object
-an arbitrary Scheme value
-
-@end table
-
-
-@menu
-* Examining Environments::
-* Changing Environments::
-* Caching Environment Lookups::
-* Observing Changes to Environments ::
-* Environment Errors::
-@end menu
-
-@node Examining Environments, Changing Environments, Common Environment Operations, Common Environment Operations
-@subsection Examining Environments
-
-@deffn Primitive environment? object
-Return @code{#t} if @var{object} is an environment, or @code{#f} otherwise.
-@end deffn
-
-@deffn Primitive environment-ref env symbol
-Return the value of the location bound to @var{symbol} in @var{env}.
-If @var{symbol} is unbound in @var{env}, signal an @code{environment:unbound}
-error (@pxref{Environment Errors}).
-@end deffn
-
-@deffn Primitive environment-bound? env symbol
-Return @code{#t} if @var{symbol} is bound in @var{env}, or @code{#f}
-otherwise.
-@end deffn
-
-@deffn Primitive environment-fold env proc init
-Iterate over all the bindings in an environment, accumulating some value.
-
-For each binding in @var{env}, apply @var{proc} to the symbol bound, its
-value, and the result from the previous application of @var{proc}. Use
-@var{init} as @var{proc}'s third argument the first time @var{proc} is
-applied.
-
-If @var{env} contains no bindings, this function simply returns @var{init}.
-
-If @var{env} binds the symbol @var{sym1} to the value @var{val1},
-@var{sym2} to @var{val2}, and so on, then this procedure computes:
-@example
-(@var{proc} @var{sym1} @var{val1}
- (@var{proc} @var{sym2} @var{val2}
- ...
- (@var{proc} @var{symn} @var{valn}
- @var{init})))
-@end example
-
-Each binding in @var{env} is processed at most once.
-@code{environment-fold} makes no guarantees about the order in which the
-bindings are processed.
-
-If @var{env} is not modified while the iteration is taking place,
-@code{environment-fold} will apply @var{proc} to each binding in
-@var{env} exactly once.
-
-If @var{env} is modified while the iteration is taking place, we need to
-be more subtle in describing @code{environment-fold}'s behavior.
-@code{environment-fold} repeatedly applies @var{proc} to a binding which
-was present in @var{env} when @code{environment-fold} was invoked and is
-still present in @var{env}, until there are no such bindings remaining.
-(If no mutations take place, this definition is equivalent to the
-simpler one given above.) By this definition, bindings added during the
-iteration will not be passed to @var{proc}.
-
-Here is a function which, given an environment, constructs an
-association list representing that environment's bindings, using
-@code{environment-fold}:
-@example
-(define (environment->alist env)
- (environment-fold env
- (lambda (sym val tail)
- (cons (cons sym val) tail))
- '()))
-@end example
-@end deffn
-
-@deftypefn {Libguile macro} int SCM_ENVP (@var{object})
-Return non-zero if @var{object} is an environment.
-@end deftypefn
-
-@deftypefn {Libguile function} SCM scm_c_environment_ref (SCM @var{env}, SCM @var{symbol})
-This C function is identical to @code{environment-ref}, except that if
-@var{symbol} is unbound in @var{env}, it returns the value
-@code{SCM_UNDEFINED}, instead of signalling an error.
-@end deftypefn
-
-@deftypefn {Libguile function} SCM scm_c_environment_fold (SCM @var{env}, scm_environment_folder *@var{proc}, SCM @var{data}, SCM @var{init})
-This is the C-level analog of @code{environment-fold}. For each binding in
-@var{env}, make the call:
-@example
-(*@var{proc}) (@var{data}, @var{symbol}, @var{value}, @var{previous})
-@end example
-@noindent
-where @var{previous} is the value returned from the last call to
-@code{*@var{proc}}, or @var{init} for the first call. If @var{env}
-contains no bindings, return @var{init}.
-@end deftypefn
-
-@deftp {Libguile data type} scm_environment_folder SCM (SCM @var{data}, SCM @var{symbol}, SCM @var{value}, SCM @var{tail})
-The type of a folding function to pass to @code{scm_c_environment_fold}.
-@end deftp
-
-
-@node Changing Environments, Caching Environment Lookups, Examining Environments, Common Environment Operations
-@subsection Changing Environments
-
-Here are functions for changing symbols' bindings and values.
-
-Although it is common to say that an environment binds a symbol to a
-value, this is not quite accurate; an environment binds a symbol to a
-location, and the location contains a value. In the descriptions below,
-we will try to make clear how each function affects bindings and
-locations.
-
-Note that some environments may contain some immutable bindings, or may
-bind symbols to immutable locations. If you attempt to change an
-immutable binding or value, these functions will signal an
-@code{environment:immutable-binding} or
-@code{environment:immutable-location} error. However, simply because a
-binding cannot be changed via these functions does @emph{not} imply that
-it is constant. Mechanisms outside the scope of this section (say,
-re-loading a module's source code) may change a binding or value which
-is immutable via these functions.
-
-@deffn Primitive environment-define env symbol value
-Bind @var{symbol} to a new location containing @var{value} in @var{env}.
-If @var{symbol} is already bound to another location in @var{env}, that
-binding is replaced. The new binding and location are both mutable.
-The return value is unspecified.
-
-If @var{symbol} is already bound in @var{env}, and the binding is
-immutable, signal an @code{environment:immutable-binding} error.
-@end deffn
-
-@deffn Primitive environment-undefine env symbol
-Remove any binding for @var{symbol} from @var{env}. If @var{symbol} is
-unbound in @var{env}, do nothing. The return value is unspecified.
-
-If @var{symbol} is already bound in @var{env}, and the binding is
-immutable, signal an @code{environment:immutable-binding} error.
-@end deffn
-
-@deffn Primitive environment-set! env symbol value
-If @var{env} binds @var{symbol} to some location, change that location's
-value to @var{value}. The return value is unspecified.
-
-If @var{symbol} is not bound in @var{env}, signal an
-@code{environment:unbound} error. If @var{env} binds @var{symbol} to an
-immutable location, signal an @code{environment:immutable-location}
-error.
-@end deffn
-
-
-@node Caching Environment Lookups, Observing Changes to Environments , Changing Environments, Common Environment Operations
-@subsection Caching Environment Lookups
-
-Some applications refer to variables' values so frequently that the
-overhead of @code{environment-ref} and @code{environment-set!} is
-unacceptable. For example, variable reference speed is a critical
-factor in the performance of the Guile interpreter itself. If an
-application can tolerate some additional complexity, the
-@code{environment-cell} function described here can provide very
-efficient access to variable values.
-
-In the Guile interpreter, most variables are represented by pairs; the
-@sc{cdr} of the pair holds the variable's value. Thus, a variable
-reference corresponds to taking the @sc{cdr} of one of these pairs, and
-setting a variable corresponds to a @code{set-cdr!} operation. A pair
-used to represent a variable's value in this manner is called a
-@dfn{value cell}. Value cells represent the ``locations'' to which
-environments bind symbols.
-
-The @code{environment-cell} function returns the value cell bound to a
-symbol. For example, an interpreter might make the call
-@code{(environment-cell @var{env} @var{symbol} #t)} to find the value
-cell which @var{env} binds to @var{symbol}, and then use @code{cdr} and
-@code{set-cdr!} to reference and assign to that variable, instead of
-calling @code{environment-ref} or @var{environment-set!} for each
-variable reference.
-
-There are a few caveats that apply here:
-
-@itemize @bullet
-
-@item
-Environments are not required to represent variables' values using value
-cells. An environment is free to return @code{#f} in response to a
-request for a symbol's value cell; in this case, the caller must use
-@code{environment-ref} and @code{environment-set!} to manipulate the
-variable.
-
-@item
-An environment's binding for a symbol may change. For example, the user
-could override an imported variable with a local definition, associating
-a new value cell with that symbol. If an interpreter has used
-@code{environment-cell} to obtain the variable's value cell, it no
-longer needs to use @code{environment-ref} and @code{environment-set!}
-to access the variable, and it may not see the new binding.
-
-Thus, code which uses @code{environment-cell} should almost always use
-@code{environment-observe} to track changes to the symbol's binding;
-this is the additional complexity hinted at above. @xref{Observing
-Changes to Environments}.
-
-@item
-Some variables should be immutable. If a program uses
-@code{environment-cell} to obtain the value cell of such a variable,
-then it is impossible for the environment to prevent the program from
-changing the variable's value, using @code{set-cdr!}. However, this is
-discouraged; it is probably better to redesign the interface than to
-disregard such a request. To make it easy for programs to honor the
-immutability of a variable, @code{environment-cell} takes an argument
-indicating whether the caller intends to mutate the cell's value; if
-this argument is true, then @code{environment-cell} signals an
-@code{environment:immutable-location} error.
-
-Programs should therefore make separate calls to @code{environment-cell}
-to obtain value cells for reference and for assignment. It is incorrect
-for a program to call @code{environment-cell} once to obtain a value
-cell, and then use that cell for both reference and mutation.
-
-@end itemize
-
-@deffn Primitive environment-cell env symbol for-write
-Return the value cell which @var{env} binds to @var{symbol}, or
-@code{#f} if the binding does not live in a value cell.
-
-The argument @var{for-write} indicates whether the caller intends to
-modify the variable's value by mutating the value cell. If the variable
-is immutable, then @code{environment-cell} signals an
-@code{environment:immutable-location} error.
-
-If @var{symbol} is unbound in @var{env}, signal an @code{environment:unbound}
-error.
-
-If you use this function, you should consider using
-@code{environment-observe}, to be notified when @code{symbol} gets
-re-bound to a new value cell, or becomes undefined.
-@end deffn
-
-@deftypefn {Libguile function} SCM scm_c_environment_cell (SCM @var{env}, SCM @var{symbol}, int for_write)
-This C function is identical to @code{environment-cell}, except that if
-@var{symbol} is unbound in @var{env}, it returns the value
-@code{SCM_UNDEFINED}, instead of signalling an error.
-@end deftypefn
-
-[[After we have some experience using this, we may find that we want to
-be able to explicitly ask questions like, "Is this variable mutable?"
-without the annoyance of error handling. But maybe this is fine.]]
-
-
-@node Observing Changes to Environments , Environment Errors, Caching Environment Lookups, Common Environment Operations
-@subsection Observing Changes to Environments
-
-The procedures described here allow you to add and remove @dfn{observing
-procedures} for an environment.
-
-
-@menu
-* Registering Observing Procedures::
-* Observations and Garbage Collection::
-* Observing Environments from C Code::
-@end menu
-
-@node Registering Observing Procedures, Observations and Garbage Collection, Observing Changes to Environments , Observing Changes to Environments
-@subsubsection Registering Observing Procedures
-
-A program may register an @dfn{observing procedure} for an environment,
-which will be called whenever a binding in a particular environment
-changes. For example, if the user changes a module's source code and
-re-loads the module, other parts of the system may want to throw away
-information they have cached about the bindings of the older version of
-the module. To support this, each environment retains a set of
-observing procedures which it will invoke whenever its bindings change.
-We say that these procedures @dfn{observe} the environment's bindings.
-You can register new observing procedures for an environment using
-@code{environment-observe}.
-
-@deffn Primitive environment-observe env proc
-Whenever @var{env}'s bindings change, apply @var{proc} to @var{env}.
-
-This function returns an object, @var{token}, which you can pass to
-@code{environment-unobserve} to remove @var{proc} from the set of
-procedures observing @var{env}. The type and value of @var{token} is
-unspecified.
-@end deffn
-
-@deffn Primitive environment-unobserve token
-Cancel the observation request which returned the value @var{token}.
-The return value is unspecified.
-
-If a call @code{(environment-observe @var{env} @var{proc})} returns
-@var{token}, then the call @code{(environment-unobserve @var{token})}
-will cause @var{proc} to no longer be called when @var{env}'s bindings
-change.
-@end deffn
-
-There are some limitations on observation:
-@itemize @bullet
-@item
-These procedures do not allow you to observe specific bindings; you
-can only observe an entire environment.
-@item
-These procedures observe bindings, not locations. There is no way
-to receive notification when a location's value changes, using these
-procedures.
-@item
-These procedures do not promise to call the observing procedure for each
-individual binding change. However, if multiple bindings do change
-between calls to the observing procedure, those changes will appear
-atomic to the entire system, not just to a few observing procedures.
-@item
-Since a single environment may have several procedures observing it, a
-correct design obviously may not assume that nothing else in the system
-has yet observed a given change.
-@end itemize
-
-(One weakness of this observation architecture is that observing
-procedures make no promises to the observer. That's fine if you're just
-trying to implement an accurate cache, but too weak to implement things
-that walk the environment tree.)
-
-@node Observations and Garbage Collection, Observing Environments from C Code, Registering Observing Procedures, Observing Changes to Environments
-@subsubsection Observations and Garbage Collection
-
-When writing observing procedures, pay close attention to garbage
-collection issues. If you use @code{environment-observe} to register
-observing procedures for an environment, the environment will hold a
-reference to those procedures; while that environment is alive, its
-observing procedures will live, as will any data they close over. If
-this is not appropriate, you can use the @code{environment-observe-weak}
-procedure to create a weak reference from the environment to the
-observing procedure.
-
-For example, suppose an interpreter uses @code{environment-cell} to
-reference variables efficiently, as described above in @ref{Caching
-Environment Lookups}. That interpreter must register observing
-procedures to track changes to the environment. If those procedures
-retain any reference to the data structure representing the program
-being interpreted, then that structure cannot be collected as long as
-the observed environment lives. This is almost certainly incorrect ---
-if there are no other references to the structure, it can never be
-invoked, so it should be collected. In this case, the interpreter
-should register its observing procedure using
-@code{environment-observe-weak}, and retain a pointer to it from the
-code it updates. Thus, when the code is no longer referenced elsewhere
-in the system, the weak link will be broken, and Guile will collect the
-code (and its observing procedure).
-
-@deffn Primitive environment-observe-weak env proc
-This function is the same as @code{environment-observe}, except that the
-reference @var{env} retains to @var{proc} is a weak reference. This
-means that, if there are no other live, non-weak references to
-@var{proc}, it will be garbage-collected, and dropped from @var{env}'s
-list of observing procedures.
-@end deffn
-
-
-@node Observing Environments from C Code, , Observations and Garbage Collection, Observing Changes to Environments
-@subsubsection Observing Environments from C Code
-
-It is also possible to write code that observes an environment in C.
-The @code{scm_c_environment_observe} function registers a C
-function to observe an environment. The typedef
-@code{scm_environment_observer} is the type a C observer function must
-have.
-
-@deftypefn {Libguile function} SCM scm_c_environment_observe (SCM @var{env}, scm_environment_observer *proc, SCM @var{data}, int weak_p)
-This is the C-level analog of the Scheme function
-@code{environment-observe}. Whenever @var{env}'s bindings change, call
-the function @var{proc}, passing it @var{env} and @var{data}. If
-@var{weak_p} is non-zero, @var{env} will retain only a weak reference to
-@var{data}, and if @var{data} is garbage collected, the entire
-observation will be dropped.
-
-This function returns a token, with the same meaning as those returned
-by @code{environment-observe}.
-@end deftypefn
-
-@deftp {Libguile data type} scm_environment_observer void (SCM @var{env}, SCM @var{data})
-The type for observing functions written in C. A function meant to be
-passed to @code{scm_c_environment_observe} should have the type
-@code{scm_environment_observer}.
-@end deftp
-
-Note that, like all other primitives, @code{environment-observe} is also
-available from C, under the name @code{scm_environment_observe}.
-
-
-@node Environment Errors, , Observing Changes to Environments , Common Environment Operations
-@subsection Environment Errors
-
-Here are the error conditions signalled by the environment routines
-described above. In these conditions, @var{func} is a string naming a
-particular procedure.
-
-@deffn Condition environment:unbound func message args env symbol
-By calling @var{func}, the program attempted to retrieve the value of
-@var{symbol} in @var{env}, but @var{symbol} is unbound in @var{env}.
-@end deffn
-
-@deffn Condition environment:immutable-binding func message args env symbol
-By calling @var{func}, the program attempted to change the binding of
-@var{symbol} in @var{env}, but that binding is immutable.
-@end deffn
-
-@deffn Condition environment:immutable-location func message args env symbol
-By calling @var{func}, the program attempted to change the value of
-the location to which @var{symbol} is bound in @var{env}, but that
-location is immutable.
-@end deffn
-
-
-@node Standard Environment Types, Implementing Environments, Common Environment Operations, Top-Level Environments in Guile
-@section Standard Environment Types
-
-Guile supports several different kinds of environments. The operations
-described above are actually only the common functionality provided by
-all the members of a family of environment types, each designed for a
-separate purpose.
-
-Each environment type has a constructor procedure for building elements
-of that type, and extends the set of common operations with its own
-procedures, providing specialized functions. For an example of how
-these environment types work together, see @ref{Modules of Interpreted
-Scheme Code}.
-
-Guile allows users to define their own environment types. Given a set
-of procedures that implement the common environment operations, Guile
-will construct a new environment object based on those procedures.
-
-@menu
-* Leaf Environments:: A simple set of bindings.
-* Eval Environments:: Local definitions, shadowing
- imported definitions.
-* Import Environments:: The union of a list of environments.
-* Export Environments:: A selected subset of an environment.
-* General Environments:: Environments implemented by user
- functions.
-@end menu
-
-@node Leaf Environments, Eval Environments, Standard Environment Types, Standard Environment Types
-@subsection Leaf Environments
-
-A @dfn{leaf} environment is simply a mutable set of definitions. A mutable
-environment supports no operations beyond the common set.
-
-@deffn Primitive make-leaf-environment
-Create a new leaf environment, containing no bindings. All bindings
-and locations in the new environment are mutable.
-@end deffn
-
-@deffn Primitive leaf-environment? object
-Return @code{#t} if @var{object} is a leaf environment, or @var{#f}
-otherwise.
-@end deffn
-
-
-In Guile, each module of interpreted Scheme code uses a leaf
-environment to hold the definitions made in that module.
-
-Leaf environments are so named because their bindings are not computed
-from the contents of other environments. Most other environment types
-have no bindings of their own, but compute their binding sets based on
-those of their operand environments. Thus, the environments in a
-running Guile system form a tree, with interior nodes computing their
-contents from their child nodes. Leaf environments are the leaves of
-such trees.
-
-
-@node Eval Environments, Import Environments, Leaf Environments, Standard Environment Types
-@subsection Eval Environments
-
-A module's source code refers to definitions imported from other
-modules, and definitions made within itself. An @dfn{eval} environment
-combines two environments --- a @dfn{local} environment and an
-@dfn{imported} environment --- to produce a new environment in which
-both sorts of references can be resolved.
-
-@deffn Primitive make-eval-environment local imported
-Return a new environment object @var{eval} whose bindings are the union
-of the bindings in the environments @var{local} and @var{imported}, with
-bindings from @var{local} taking precedence. Definitions made in
-@var{eval} are placed in @var{local}.
-
-Applying @code{environment-define} or @code{environment-undefine} to
-@var{eval} has the same effect as applying the procedure to @var{local}.
-This means that applying @code{environment-undefine} to a symbol bound
-in @var{imported} and free in @var{local} has no effect on the bindings
-visible in @var{eval}, which may be surprising.
-
-Note that @var{eval} incorporates @var{local} and @var{imported}
-@emph{by reference} --- if, after creating @var{eval}, the program
-changes the bindings of @var{local} or @var{imported}, those changes
-will be visible in @var{eval}.
-
-Since most Scheme evaluation takes place in @var{eval} environments,
-they transparently cache the bindings received from @var{local} and
-@var{imported}. Thus, the first time the program looks up a symbol in
-@var{eval}, @var{eval} may make calls to @var{local} or @var{imported}
-to find their bindings, but subsequent references to that symbol will be
-as fast as references to bindings in leaf environments.
-
-In typical use, @var{local} will be a leaf environment, and
-@var{imported} will be an import environment, described below.
-@end deffn
-
-@deffn Primitive eval-environment? object
-Return @code{#t} if @var{object} is an eval environment, or @code{#f}
-otherwise.
-@end deffn
-
-@deffn Primitive eval-environment-local env
-@deffnx Primitive eval-environment-imported env
-Return the @var{local} or @var{imported} environment of @var{env};
-@var{env} must be an eval environment.
-@end deffn
-
-
-@node Import Environments, Export Environments, Eval Environments, Standard Environment Types
-@subsection Import Environments
-
-An @dfn{import} environment combines the bindings of a set of
-argument environments, and checks for naming clashes.
-
-@deffn Primitive make-import-environment imports conflict-proc
-Return a new environment @var{imp} whose bindings are the union of the
-bindings from the environments in @var{imports}; @var{imports} must be a
-list of environments. That is, @var{imp} binds @var{symbol} to
-@var{location} when some element of @var{imports} does.
-
-If two different elements of @var{imports} have a binding for the same
-symbol, apply @var{conflict-proc} to the two environments. If the bindings
-of any of the @var{imports} ever changes, check for conflicts again.
-
-All bindings in @var{imp} are immutable. If you apply
-@code{environment-define} or @code{environment-undefine} to @var{imp},
-Guile will signal an @code{environment:immutable-binding} error.
-However, notice that the set of bindings in @var{imp} may still change,
-if one of its imported environments changes.
-@end deffn
-
-@deffn Primitive import-environment? object
-Return @code{#t} if @var{object} is an import environment, or @code{#f}
-otherwise.
-@end deffn
-
-@deffn Primitive import-environment-imports env
-Return the list of @var{env}'s imported environments; @var{env} must be
-an import env.
-@end deffn
-
-@deffn Primitive import-environment-set-imports! env imports
-Change @var{env}'s list of imported environments to @var{imports}, and
-check for conflicts.
-@end deffn
-
-I'm not at all sure about the way @var{conflict-proc} works. I think
-module systems should warn you if it seems you're likely to get the
-wrong binding, but exactly how and when those warnings should be
-generated, I don't know.
-
-
-@node Export Environments, General Environments, Import Environments, Standard Environment Types
-@subsection Export Environments
-
-An export environment restricts an environment a specified set of
-bindings.
-
-@deffn Primitive make-export-environment private signature
-Return a new environment @var{exp} containing only those bindings in
-@var{private} whose symbols are present in @var{signature}. The
-@var{private} argument must be an environment.
-
-The environment @var{exp} binds @var{symbol} to @var{location} when
-@var{env} does, and @var{symbol} is exported by @var{signature}.
-
-@var{Signature} is a list specifying which of the bindings in
-@var{private} should be visible in @var{exp}. Each element of
-@var{signature} should be a list of the form:
-@example
-(@var{symbol} @var{attribute} ...)
-@end example
-@noindent
-where each @var{attribute} is one of the following:
-@table @asis
-@item the symbol @code{mutable-location}
-@var{exp} should treat the location bound to @var{symbol} as mutable.
-That is, @var{exp} will pass calls to @var{env-set!} or
-@code{environment-cell} directly through to @var{private}.
-
-@item the symbol @code{immutable-location}
-@var{exp} should treat the location bound to @var{symbol} as immutable.
-If the program applies @code{environment-set!} to @var{exp} and
-@var{symbol}, or calls @code{environment-cell} to obtain a writable
-value cell, @code{environment-set!} will signal an
-@code{environment:immutable-location} error.
-
-Note that, even if an export environment treats a location as immutable,
-the underlying environment may treat it as mutable, so its value may
-change.
-@end table
-
-It is an error for an element of @var{signature} to specify both
-@code{mutable-location} and @code{immutable-location}. If neither is
-specified, @code{immutable-location} is assumed.
-
-As a special case, if an element of @var{signature} is a lone symbol
-@var{sym}, it is equivalent to an element of the form
-@code{(@var{sym})}.
-
-All bindings in @var{exp} are immutable. If you apply
-@code{environment-define} or @code{environment-undefine} to @var{exp},
-Guile will signal an @code{environment:immutable-binding} error.
-However, notice that the set of bindings in @var{exp} may still change,
-if the bindings in @var{private} change.
-@end deffn
-
-@deffn Primitive export-environment? object
-Return @code{#t} if @var{object} is an export environment, or @code{#f}
-otherwise.
-@end deffn
-
-@deffn Primitive export-environment-private env
-@deffnx Primitive export-environment-set-private! env
-@deffnx Primitive export-environment-signature env
-@deffnx Primitive export-environment-set-signature! env
-Accessors and mutators for the private environment and signature of
-@var{env}; @var{env} must be an export environment.
-@end deffn
-
-
-@node General Environments, , Export Environments, Standard Environment Types
-@subsection General Environments
-
-[[user provides the procedures]]
-[[A observers B and C; B observes C; C changes; A should only be
-notified once, right?]]
-[[observation loops?]]
-
-@node Implementing Environments, Switching to Environments, Standard Environment Types, Top-Level Environments in Guile
-@section Implementing Environments
-
-This section describes how to implement new environment types in Guile.
-
-Guile's internal representation of environments allows you to extend
-Guile with new kinds of environments without modifying Guile itself.
-Every environment object carries a pointer to a structure of pointers to
-functions implementing the common operations for that environment. The
-procedures @code{environment-ref}, @code{environment-set!}, etc. simply
-find this structure and invoke the appropriate function.
-
-[[It would be nice to have an example around here. How about a
-persistent environment, bound to a directory, where ref and set actually
-access files? Ref on a directory would return another
-environment... Hey, let's import my home directory!]]
-
-
-@menu
-* Environment Function Tables::
-* Environment Data::
-* Environment Example::
-@end menu
-
-
-@node Environment Function Tables, Environment Data, Implementing Environments, Implementing Environments
-@subsection Environment Function Tables
-
-An environment object is a smob whose @sc{cdr} is a pointer to a pointer
-to a @code{struct environment_funcs}:
-@example
-struct environment_funcs @{
- SCM (*ref) (SCM self, SCM symbol);
- SCM (*fold) (SCM self, scm_environment_folder *proc, SCM data, SCM init);
- void (*define) (SCM self, SCM symbol, SCM value);
- void (*undefine) (SCM self, SCM symbol);
- void (*set) (SCM self, SCM symbol, SCM value);
- SCM (*cell) (SCM self, SCM symbol, int for_write);
- SCM (*observe) (SCM self, scm_environment_observer *proc, SCM data, int weak_p);
- void (*unobserve) (SCM self, SCM token);
- SCM (*mark) (SCM self);
- scm_sizet (*free) (SCM self);
- int (*print) (SCM self, SCM port, scm_print_state *pstate);
-@};
-@end example
-
-You can use the following macro to access an environment's function table:
-
-@deftypefn {Libguile macro} struct environment_funcs *SCM_ENVIRONMENT_FUNCS (@var{env})
-Return a pointer to the @code{struct environment_func} for the environment
-@var{env}. If @var{env} is not an environment object, the behavior of
-this macro is undefined.
-@end deftypefn
-
-Here is what each element of @var{env_funcs} must do to correctly
-implement an environment. In all of these calls, @var{self} is the
-environment whose function is being invoked.
-
-@table @code
-
-@item SCM ref (SCM @var{self}, SCM @var{symbol});
-This function must have the effect described above for the C call:
-@example
-scm_c_environment_ref (@var{self}, @var{symbol})
-@end example
-@xref{Examining Environments}.
-
-Note that the @code{ref} element of a @code{struct environment_funcs}
-may be zero if a @code{cell} function is provided.
-
-@item SCM fold (SCM self, scm_environment_folder *proc, SCM data, SCM init);
-This function must have the effect described above for the C call:
-@example
-scm_c_environment_fold (@var{self}, @var{proc}, @var{data}, @var{init})
-@end example
-@xref{Examining Environments}.
-
-@item void define (SCM self, SCM symbol, SCM value);
-This function must have the effect described above for the Scheme call:
-@example
-(environment-define @var{self} @var{symbol} @var{value})
-@end example
-@xref{Changing Environments}.
-
-@item void undefine (SCM self, SCM symbol);
-This function must have the effect described above for the Scheme call:
-@example
-(environment-undefine @var{self} @var{symbol})
-@end example
-@xref{Changing Environments}.
-
-@item void set (SCM self, SCM symbol, SCM value);
-This function must have the effect described above for the Scheme call:
-@example
-(environment-set! @var{self} @var{symbol} @var{value})
-@end example
-@xref{Changing Environments}.
-
-Note that the @code{set} element of a @code{struct environment_funcs}
-may be zero if a @code{cell} function is provided.
-
-@item SCM cell (SCM self, SCM symbol, int for_write);
-This function must have the effect described above for the C call:
-@example
-scm_c_environment_cell (@var{self}, @var{symbol})
-@end example
-@xref{Caching Environment Lookups}.
-
-@item SCM observe (SCM self, scm_environment_observer *proc, SCM data, int weak_p);
-This function must have the effect described above for the C call:
-@example
-scm_c_environment_observe (@var{env}, @var{proc}, @var{data}, @var{weak_p})
-@end example
-@xref{Observing Changes to Environments}.
-
-@item void unobserve (SCM self, SCM token);
-Cancel the request to observe @var{self} that returned @var{token}.
-@xref{Observing Changes to Environments}.
-
-@item SCM mark (SCM self);
-Set the garbage collection mark all Scheme cells referred to by
-@var{self}. Assume that @var{self} itself is already marked. Return a
-final object to be marked recursively.
-
-@item scm_sizet free (SCM self);
-Free all non-cell storage associated with @var{self}; return the number
-of bytes freed that were obtained using @code{scm_must_malloc} or
-@code{scm_must_realloc}.
-
-@item SCM print (SCM self, SCM port, scm_print_state *pstate);
-Print an external representation of @var{self} on @var{port}, passing
-@var{pstate} to any recursive calls to the object printer.
-
-@end table
-
-
-@node Environment Data, Environment Example, Environment Function Tables, Implementing Environments
-@subsection Environment Data
-
-When you implement a new environment type, you will likely want to
-associate some data of your own design with each environment object.
-Since ANSI C promises that casts will safely convert between a pointer
-to a structure and a pointer to its first element, you can have the
-@sc{cdr} of an environment smob point to your structure, as long as your
-structure's first element is a pointer to a @code{struct
-environment_funcs}. Then, your code can use the macro below to retrieve
-a pointer to the structure, and cast it to the appropriate type.
-
-@deftypefn {Libguile macro} struct environment_funcs **SCM_ENVIRONMENT_DATA (@var{env})
-Return the @sc{cdr} of @var{env}, as a pointer to a pointer to an
-@code{environment_funcs} structure.
-@end deftypefn
-
-@node Environment Example, , Environment Data, Implementing Environments
-@subsection Environment Example
-
-[[perhaps a simple environment based on association lists]]
-
-
-@node Switching to Environments, , Implementing Environments, Top-Level Environments in Guile
-@section Switching to Environments
-
-Here's what we'd need to do to today's Guile to install the system
-described above. This work would probably be done on a branch, because
-it involves crippling Guile while a lot of work gets done. Also, it
-could change the default set of bindings available pretty drastically,
-so the next minor release should not contain these changes.
-
-After each step here, we should have a Guile that we can at least
-interact with, perhaps with some limitations.
-
-@itemize @bullet
-
-@item
-For testing purposes, make an utterly minimal version of
-@file{boot-9.scm}: no module system, no R5RS, nothing. I think a simple
-REPL is all we need.
-
-@item
-Implement the environment datatypes in libguile, and test them using
-this utterly minimal system.
-
-@item
-Change the interpreter to use the @code{environment-cell} and
-@code{environment-observe} instead of the symbol value slots,
-first-class variables, etc. Modify the rest of libguile as necessary to
-register all the primitives in a single environment. We'll segregate
-them into modules later.
-
-@item
-Reimplement the current module system in terms of environments. It
-should still be in Scheme.
-
-@item
-Reintegrate the rest of @file{boot-9.scm}. This might be a good point
-to move it into modules.
-
-@item
-Do some profiling and optimization.
-
-@end itemize
-
-Once this is done, we can make the following simplifications to Guile:
-
-@itemize @bullet
-
-@item
-A good portion of symbols.c can go away. Symbols no longer need value
-slots. The mishmash of @code{scm_sym2ovcell},
-@code{scm_intern_obarray_soft}, etc. can go away. @code{intern} becomes
-simpler.
-
-@item
-Remove first-class variables: @file{variables.c} and @file{variables.h}.
-
-@item
-Organize the primitives into environments.
-
-@item
-The family of environment types is clearly an abstract class/concrete
-subclass arrangement. We should provide GOOPS classes/metaclasses that
-make defining new environment types easy and consistent.
-
-@end itemize
-
-
-
-@node Modules, , Top-Level Environments in Guile, Top
-@chapter Modules
-
-The material here is just a sketch. Don't take it too seriously. The
-point is that environments allow us to experiment without getting
-tangled up with the interpreter.
-
-@menu
-* Modules of Guile Primitives::
-* Modules of Interpreted Scheme Code::
-@end menu
-
-@node Modules of Guile Primitives, Modules of Interpreted Scheme Code, Modules, Modules
-@section Modules of Guile Primitives
-
-@node Modules of Interpreted Scheme Code, , Modules of Guile Primitives, Modules
-@section Modules of Interpreted Scheme Code
-
-If a module is implemented by interpreted Scheme code, Guile represents
-it using several environments:
-
-@table @asis
-
-@item the @dfn{local} environment
-This environment holds all the definitions made locally by the module,
-both public and private.
-
-@item the @dfn{import} environment
-This environment holds all the definitions this module imports from
-other modules.
-
-@item the @dfn{evaluation} environment
-This is the environment in which the module's code is actually
-evaluated, and the one closed over by the module's procedures, both
-public and private. Its bindings are the union of the @var{local} and
-@var{import} environments, with local bindings taking precedence.
-
-@item the @dfn{exported} environment
-This environment holds the module's public definitions. This is the
-only environment that the module's users have access to. It is the
-@var{evaluation} environment, restricted to the set of exported
-definitions.
-
-@end table
-
-Each of these environments is implemented using a separate environment
-type. Some of these types, like the evaluation and import environments,
-actually just compute their bindings by consulting other environments;
-they have no bindings in their own right. They implement operations
-like @code{environment-ref} and @code{environment-define} by passing
-them through to the environments from which they are derived. For
-example, the evaluation environment will pass definitions through to the
-local environment, and search for references and assignments first in
-the local environment, and then in the import environment.
-
-
-
-@bye
diff --git a/doc/sources/format.texi b/doc/sources/format.texi
deleted file mode 100644
index 122e0453d..000000000
--- a/doc/sources/format.texi
+++ /dev/null
@@ -1,434 +0,0 @@
-
-@menu
-* Format Interface::
-* Format Specification::
-@end menu
-
-@node Format Interface, Format Specification, Format, Format
-@subsection Format Interface
-
-@defun format destination format-string . arguments
-An almost complete implementation of Common LISP format description
-according to the CL reference book @cite{Common LISP} from Guy L.
-Steele, Digital Press. Backward compatible to most of the available
-Scheme format implementations.
-
-Returns @code{#t}, @code{#f} or a string; has side effect of printing
-according to @var{format-string}. If @var{destination} is @code{#t},
-the output is to the current output port and @code{#t} is returned. If
-@var{destination} is @code{#f}, a formatted string is returned as the
-result of the call. NEW: If @var{destination} is a string,
-@var{destination} is regarded as the format string; @var{format-string} is
-then the first argument and the output is returned as a string. If
-@var{destination} is a number, the output is to the current error port
-if available by the implementation. Otherwise @var{destination} must be
-an output port and @code{#t} is returned.@refill
-
-@var{format-string} must be a string. In case of a formatting error
-format returns @code{#f} and prints a message on the current output or
-error port. Characters are output as if the string were output by the
-@code{display} function with the exception of those prefixed by a tilde
-(~). For a detailed description of the @var{format-string} syntax
-please consult a Common LISP format reference manual. For a test suite
-to verify this format implementation load @file{formatst.scm}. Please
-send bug reports to @code{lutzeb@@cs.tu-berlin.de}.
-
-Note: @code{format} is not reentrant, i.e. only one @code{format}-call
-may be executed at a time.
-
-@end defun
-
-@node Format Specification, , Format Interface, Format
-@subsection Format Specification (Format version 3.0)
-
-Please consult a Common LISP format reference manual for a detailed
-description of the format string syntax. For a demonstration of the
-implemented directives see @file{formatst.scm}.@refill
-
-This implementation supports directive parameters and modifiers
-(@code{:} and @code{@@} characters). Multiple parameters must be
-separated by a comma (@code{,}). Parameters can be numerical parameters
-(positive or negative), character parameters (prefixed by a quote
-character (@code{'}), variable parameters (@code{v}), number of rest
-arguments parameter (@code{#}), empty and default parameters. Directive
-characters are case independent. The general form of a directive
-is:@refill
-
-@noindent
-@var{directive} ::= ~@{@var{directive-parameter},@}[:][@@]@var{directive-character}
-
-@noindent
-@var{directive-parameter} ::= [ [-|+]@{0-9@}+ | '@var{character} | v | # ]
-
-
-@subsubsection Implemented CL Format Control Directives
-
-Documentation syntax: Uppercase characters represent the corresponding
-control directive characters. Lowercase characters represent control
-directive parameter descriptions.
-
-@table @asis
-@item @code{~A}
-Any (print as @code{display} does).
-@table @asis
-@item @code{~@@A}
-left pad.
-@item @code{~@var{mincol},@var{colinc},@var{minpad},@var{padchar}A}
-full padding.
-@end table
-@item @code{~S}
-S-expression (print as @code{write} does).
-@table @asis
-@item @code{~@@S}
-left pad.
-@item @code{~@var{mincol},@var{colinc},@var{minpad},@var{padchar}S}
-full padding.
-@end table
-@item @code{~D}
-Decimal.
-@table @asis
-@item @code{~@@D}
-print number sign always.
-@item @code{~:D}
-print comma separated.
-@item @code{~@var{mincol},@var{padchar},@var{commachar}D}
-padding.
-@end table
-@item @code{~X}
-Hexadecimal.
-@table @asis
-@item @code{~@@X}
-print number sign always.
-@item @code{~:X}
-print comma separated.
-@item @code{~@var{mincol},@var{padchar},@var{commachar}X}
-padding.
-@end table
-@item @code{~O}
-Octal.
-@table @asis
-@item @code{~@@O}
-print number sign always.
-@item @code{~:O}
-print comma separated.
-@item @code{~@var{mincol},@var{padchar},@var{commachar}O}
-padding.
-@end table
-@item @code{~B}
-Binary.
-@table @asis
-@item @code{~@@B}
-print number sign always.
-@item @code{~:B}
-print comma separated.
-@item @code{~@var{mincol},@var{padchar},@var{commachar}B}
-padding.
-@end table
-@item @code{~@var{n}R}
-Radix @var{n}.
-@table @asis
-@item @code{~@var{n},@var{mincol},@var{padchar},@var{commachar}R}
-padding.
-@end table
-@item @code{~@@R}
-print a number as a Roman numeral.
-@item @code{~:@@R}
-print a number as an ``old fashioned'' Roman numeral.
-@item @code{~:R}
-print a number as an ordinal English number.
-@item @code{~:@@R}
-print a number as a cardinal English number.
-@item @code{~P}
-Plural.
-@table @asis
-@item @code{~@@P}
-prints @code{y} and @code{ies}.
-@item @code{~:P}
-as @code{~P but jumps 1 argument backward.}
-@item @code{~:@@P}
-as @code{~@@P but jumps 1 argument backward.}
-@end table
-@item @code{~C}
-Character.
-@table @asis
-@item @code{~@@C}
-prints a character as the reader can understand it (i.e. @code{#\} prefixing).
-@item @code{~:C}
-prints a character as emacs does (eg. @code{^C} for ASCII 03).
-@end table
-@item @code{~F}
-Fixed-format floating-point (prints a flonum like @var{mmm.nnn}).
-@table @asis
-@item @code{~@var{width},@var{digits},@var{scale},@var{overflowchar},@var{padchar}F}
-@item @code{~@@F}
-If the number is positive a plus sign is printed.
-@end table
-@item @code{~E}
-Exponential floating-point (prints a flonum like @var{mmm.nnn}@code{E}@var{ee}).
-@table @asis
-@item @code{~@var{width},@var{digits},@var{exponentdigits},@var{scale},@var{overflowchar},@var{padchar},@var{exponentchar}E}
-@item @code{~@@E}
-If the number is positive a plus sign is printed.
-@end table
-@item @code{~G}
-General floating-point (prints a flonum either fixed or exponential).
-@table @asis
-@item @code{~@var{width},@var{digits},@var{exponentdigits},@var{scale},@var{overflowchar},@var{padchar},@var{exponentchar}G}
-@item @code{~@@G}
-If the number is positive a plus sign is printed.
-@end table
-@item @code{~$}
-Dollars floating-point (prints a flonum in fixed with signs separated).
-@table @asis
-@item @code{~@var{digits},@var{scale},@var{width},@var{padchar}$}
-@item @code{~@@$}
-If the number is positive a plus sign is printed.
-@item @code{~:@@$}
-A sign is always printed and appears before the padding.
-@item @code{~:$}
-The sign appears before the padding.
-@end table
-@item @code{~%}
-Newline.
-@table @asis
-@item @code{~@var{n}%}
-print @var{n} newlines.
-@end table
-@item @code{~&}
-print newline if not at the beginning of the output line.
-@table @asis
-@item @code{~@var{n}&}
-prints @code{~&} and then @var{n-1} newlines.
-@end table
-@item @code{~|}
-Page Separator.
-@table @asis
-@item @code{~@var{n}|}
-print @var{n} page separators.
-@end table
-@item @code{~~}
-Tilde.
-@table @asis
-@item @code{~@var{n}~}
-print @var{n} tildes.
-@end table
-@item @code{~}<newline>
-Continuation Line.
-@table @asis
-@item @code{~:}<newline>
-newline is ignored, white space left.
-@item @code{~@@}<newline>
-newline is left, white space ignored.
-@end table
-@item @code{~T}
-Tabulation.
-@table @asis
-@item @code{~@@T}
-relative tabulation.
-@item @code{~@var{colnum,colinc}T}
-full tabulation.
-@end table
-@item @code{~?}
-Indirection (expects indirect arguments as a list).
-@table @asis
-@item @code{~@@?}
-extracts indirect arguments from format arguments.
-@end table
-@item @code{~(@var{str}~)}
-Case conversion (converts by @code{string-downcase}).
-@table @asis
-@item @code{~:(@var{str}~)}
-converts by @code{string-capitalize}.
-@item @code{~@@(@var{str}~)}
-converts by @code{string-capitalize-first}.
-@item @code{~:@@(@var{str}~)}
-converts by @code{string-upcase}.
-@end table
-@item @code{~*}
-Argument Jumping (jumps 1 argument forward).
-@table @asis
-@item @code{~@var{n}*}
-jumps @var{n} arguments forward.
-@item @code{~:*}
-jumps 1 argument backward.
-@item @code{~@var{n}:*}
-jumps @var{n} arguments backward.
-@item @code{~@@*}
-jumps to the 0th argument.
-@item @code{~@var{n}@@*}
-jumps to the @var{n}th argument (beginning from 0)
-@end table
-@item @code{~[@var{str0}~;@var{str1}~;...~;@var{strn}~]}
-Conditional Expression (numerical clause conditional).
-@table @asis
-@item @code{~@var{n}[}
-take argument from @var{n}.
-@item @code{~@@[}
-true test conditional.
-@item @code{~:[}
-if-else-then conditional.
-@item @code{~;}
-clause separator.
-@item @code{~:;}
-default clause follows.
-@end table
-@item @code{~@{@var{str}~@}}
-Iteration (args come from the next argument (a list)).
-@table @asis
-@item @code{~@var{n}@{}
-at most @var{n} iterations.
-@item @code{~:@{}
-args from next arg (a list of lists).
-@item @code{~@@@{}
-args from the rest of arguments.
-@item @code{~:@@@{}
-args from the rest args (lists).
-@end table
-@item @code{~^}
-Up and out.
-@table @asis
-@item @code{~@var{n}^}
-aborts if @var{n} = 0
-@item @code{~@var{n},@var{m}^}
-aborts if @var{n} = @var{m}
-@item @code{~@var{n},@var{m},@var{k}^}
-aborts if @var{n} <= @var{m} <= @var{k}
-@end table
-@end table
-
-
-@subsubsection Not Implemented CL Format Control Directives
-
-@table @asis
-@item @code{~:A}
-print @code{#f} as an empty list (see below).
-@item @code{~:S}
-print @code{#f} as an empty list (see below).
-@item @code{~<~>}
-Justification.
-@item @code{~:^}
-(sorry I don't understand its semantics completely)
-@end table
-
-
-@subsubsection Extended, Replaced and Additional Control Directives
-
-@table @asis
-@item @code{~@var{mincol},@var{padchar},@var{commachar},@var{commawidth}D}
-@item @code{~@var{mincol},@var{padchar},@var{commachar},@var{commawidth}X}
-@item @code{~@var{mincol},@var{padchar},@var{commachar},@var{commawidth}O}
-@item @code{~@var{mincol},@var{padchar},@var{commachar},@var{commawidth}B}
-@item @code{~@var{n},@var{mincol},@var{padchar},@var{commachar},@var{commawidth}R}
-@var{commawidth} is the number of characters between two comma characters.
-@end table
-
-@table @asis
-@item @code{~I}
-print an R5RS complex number as @code{~F~@@Fi} with passed parameters for
-@code{~F}.
-@item @code{~Y}
-Pretty print formatting of an argument for scheme code lists.
-@item @code{~K}
-Same as @code{~?.}
-@item @code{~!}
-Flushes the output if format @var{destination} is a port.
-@item @code{~_}
-Print a @code{#\space} character
-@table @asis
-@item @code{~@var{n}_}
-print @var{n} @code{#\space} characters.
-@end table
-@item @code{~/}
-Print a @code{#\tab} character
-@table @asis
-@item @code{~@var{n}/}
-print @var{n} @code{#\tab} characters.
-@end table
-@item @code{~@var{n}C}
-Takes @var{n} as an integer representation for a character. No arguments
-are consumed. @var{n} is converted to a character by
-@code{integer->char}. @var{n} must be a positive decimal number.@refill
-@item @code{~:S}
-Print out readproof. Prints out internal objects represented as
-@code{#<...>} as strings @code{"#<...>"} so that the format output can always
-be processed by @code{read}.
-@refill
-@item @code{~:A}
-Print out readproof. Prints out internal objects represented as
-@code{#<...>} as strings @code{"#<...>"} so that the format output can always
-be processed by @code{read}.
-@item @code{~Q}
-Prints information and a copyright notice on the format implementation.
-@table @asis
-@item @code{~:Q}
-prints format version.
-@end table
-@refill
-@item @code{~F, ~E, ~G, ~$}
-may also print number strings, i.e. passing a number as a string and
-format it accordingly.
-@end table
-
-@subsubsection Configuration Variables
-
-Format has some configuration variables at the beginning of
-@file{format.scm} to suit the systems and users needs. There should be
-no modification necessary for the configuration that comes with SLIB.
-If modification is desired the variable should be set after the format
-code is loaded. Format detects automatically if the running scheme
-system implements floating point numbers and complex numbers.
-
-@table @asis
-
-@item @var{format:symbol-case-conv}
-Symbols are converted by @code{symbol->string} so the case type of the
-printed symbols is implementation dependent.
-@code{format:symbol-case-conv} is a one arg closure which is either
-@code{#f} (no conversion), @code{string-upcase}, @code{string-downcase}
-or @code{string-capitalize}. (default @code{#f})
-
-@item @var{format:iobj-case-conv}
-As @var{format:symbol-case-conv} but applies for the representation of
-implementation internal objects. (default @code{#f})
-
-@item @var{format:expch}
-The character prefixing the exponent value in @code{~E} printing. (default
-@code{#\E})
-
-@end table
-
-@subsubsection Compatibility With Other Format Implementations
-
-@table @asis
-@item SLIB format 2.x:
-See @file{format.doc}.
-
-@item SLIB format 1.4:
-Downward compatible except for padding support and @code{~A}, @code{~S},
-@code{~P}, @code{~X} uppercase printing. SLIB format 1.4 uses C-style
-@code{printf} padding support which is completely replaced by the CL
-@code{format} padding style.
-
-@item MIT C-Scheme 7.1:
-Downward compatible except for @code{~}, which is not documented
-(ignores all characters inside the format string up to a newline
-character). (7.1 implements @code{~a}, @code{~s},
-~@var{newline}, @code{~~}, @code{~%}, numerical and variable
-parameters and @code{:/@@} modifiers in the CL sense).@refill
-
-@item Elk 1.5/2.0:
-Downward compatible except for @code{~A} and @code{~S} which print in
-uppercase. (Elk implements @code{~a}, @code{~s}, @code{~~}, and
-@code{~%} (no directive parameters or modifiers)).@refill
-
-@item Scheme->C 01nov91:
-Downward compatible except for an optional destination parameter: S2C
-accepts a format call without a destination which returns a formatted
-string. This is equivalent to a #f destination in S2C. (S2C implements
-@code{~a}, @code{~s}, @code{~c}, @code{~%}, and @code{~~} (no directive
-parameters or modifiers)).@refill
-
-@end table
-
-This implementation of format is solely useful in the SLIB context
-because it requires other components provided by SLIB.@refill
diff --git a/doc/sources/guile-slib.texi b/doc/sources/guile-slib.texi
deleted file mode 100644
index c8f07d1b2..000000000
--- a/doc/sources/guile-slib.texi
+++ /dev/null
@@ -1,2 +0,0 @@
-@node Guile and SLIB
-@chapter Guile and SLIB
diff --git a/doc/sources/jimb-org.texi b/doc/sources/jimb-org.texi
deleted file mode 100644
index c4ad9ea41..000000000
--- a/doc/sources/jimb-org.texi
+++ /dev/null
@@ -1,131 +0,0 @@
-@menu
-Preliminary
-
-* Introduction::
-* Using Guile::
-
-
-
-@bye
-
->You can actually put any English text to break up the menu, so you
->could put the "Part n" headings in it.
-
-
-
-Introduction
- --- Explains Guile's goals, and gives brief examples of how to use
- Guile interactively (show off repl), as a script interpreter,
- and as an embedded interpreter.
-
-Part I: Guile Scheme
- R4RS Scheme as a Starting Point
- --- Here we refer to R4RS, and explain that we're only
- describing differences.
- Block comments and interpreter triggers
- Symbol case
- Keywords
- Exceptions
- Modules
- --- the preceding three come first, because we need them
- in order to explain the behavior of some things later
- Exception Handling
- --- mention that repls usually establish default exception handlers
- Dynamic Wind
- Records
- Structures
- Arrays
- Binary Numeric Operations
- Shared and Read-Only Strings
- Object Properties
- Association Lists and Hash Tables
- (Dictionaries In General)
- association lists
- hash tables (Hash Values)
- Input/Output ports
- file ports
- soft ports
- string ports
- extended I/O (fseek; line read/write)
- Garbage Collection
- Threads and Dynamic Roots
- Reflection
- eval
- Tag Values
- Weak references
- Regular Expressions
- SLIB
- POSIX system calls and networking
- --- I think people will generally know whether they're looking
- for a system call or not, so this should be an okay category.
- conventions (includes error handling)
- ports vs. file descriptors
- file system (mknod goes here, no?)
- user database
- time (includes gettimeofday or whatever, strftime, strptime)
- processes
- terminals and pseudo-terminals
- pipes
- networking (includes databases, address conversion, and sockets)
- system identification (uname)
- locales (setlocale)
- --- Note that there is no more 'misc'. It's better to have
- small sections than unhelpful names.
- SCSH
- --- includes info on how to get SCSH features (open this
- module), but mostly just a pointer to the SCSH manual.
- This should not be under POSIX. SCSH includes plenty of
- high-level stuff for starting processes and string
- processing. SCSH is not a subset of POSIX, nor the
- reverse.
- Tcl/Tk interface
- Module internals
- first-class variables
- first-class modules
- internal debugging interface
- --- The name of this chapter needs to clearly distinguish it
- from the appendix describing the debugger UI. The intro
- should have a pointer to the UI appendix.
-
-Part II: Using Scheme with C --- a Portable Interface
- --- We cover gh in a completely separate section. Why? I admit
- I'm on shaky ground, but here's my reasoning: People who want
- to write portable C code need to restrict themselves to only
- using GH, and GH's semantics are (necessarily) well-defined
- without reference to Guile's particulars. This makes life
- more difficult for folks who just prefer to use the GH
- interface when they can, but I really think the SCM interface
- is not so bad, once you're used to it. A *lot* of GH
- functions are just wrappers for SCM functions.
- --- We cover repls here too, since GH has repl functions.
-
-Part III: Using Scheme with C --- Guile's Interface
- Scheme data representation
- Relationship between Scheme and C functions
- --- this is where we explain that all the functions marked as
- "Primitive Functions" are also accessible from C, and how
- to derive the C interface given the Scheme interface, when
- we don't spell it out.
- ... I think there's other stuff needed here ...
- I/O internals
- linking Guile with your code
- --- Mark's "Tools to automate adding libraries" is not a
- well-defined concept. I think this is closer to what we
- want to cover for now.
- snarfing
-
-Appendices:
- Obtaining and Installing Guile
- Invoking Guile
- --- mentions read-eval-print loops
- --- both the SCSH and GAWK manuals relegate invocation details
- to an appendix. We can give examples in the introduction.
- debugger user interface
- --- The title and introduction of this appendix need to
- distinguish this clearly from the chapter on the internal
- debugging interface.
-
-Indices:
- --- At the top of the function/variable index, remind people
- to look for functions under their Scheme names as well as
- their C names.
diff --git a/doc/sources/libguile-overview.texi b/doc/sources/libguile-overview.texi
deleted file mode 100644
index 96a4a76ce..000000000
--- a/doc/sources/libguile-overview.texi
+++ /dev/null
@@ -1,30 +0,0 @@
-@node Libguile overview
-@chapter Libguile overview
-@cindex libguile - overview
-
-Extension languages, like Guile, Python and Tcl, can be embedded into a
-C program, @footnote{Or a C++ or Fortran or Pascal program if you want.}
-and thus allow the user to @emph{extend} the C program.
-
-The way this is done is by providing a C language library with a well
-defined interface. The interface consists of a set of public and
-documented C-callable routines that offer the full interpreter
-functionality, and allow the conversion of data between C and the
-extension language.
-
-@menu
-* An example of libguile functionality::
-* What can be done with libguile::
-* Schizofrenia -- two APIs::
-@end menu
-
-@node An example of libguile functionality
-@section An example of libguile functionality
-
-[Two examples: using strings and using data conversion.]
-
-@node What can be done with libguile
-@section What can be done with libguile
-
-@node Schizofrenia -- two APIs
-@section Schizofrenia -- two APIs
diff --git a/doc/sources/libguile-tools.texi b/doc/sources/libguile-tools.texi
deleted file mode 100644
index d434406e9..000000000
--- a/doc/sources/libguile-tools.texi
+++ /dev/null
@@ -1,191 +0,0 @@
-@node Tools to automate adding libraries
-@chapter Tools to automate adding libraries
-
-You want to ...
-
-The chapters @ref{Libguile -- high level interface} and @ref{Libguile --
-SCM interface} showed how to make C libraries available from Scheme.
-Here I will describe some automated tools that the Guile team has made
-available. Some have been written especially for Guile (the Guile Magic
-Snarfer), and some are also in use with other languages (Python, Perl,
-...)
-
-@menu
-* By hand with gh_::
-* By hand with Guile Magic Snarfer::
-* Automatically using libtool::
-* Automatically using SWIG::
-@end menu
-
-@node By hand with gh_
-@section By hand with gh_
-
-@node By hand with Guile Magic Snarfer
-@section By hand with Guile Magic Snarfer
-
-When writing C code for use with Guile, you typically define a set of C
-functions, and then make some of them visible to the Scheme world by
-calling the @code{scm_make_gsubr} function; a C functions published in
-this way is called a @dfn{subr}. If you have many subrs to publish, it
-can sometimes be annoying to keep the list of calls to
-@code{scm_make_gsubr} in sync with the list of function definitions.
-Frequently, a programmer will define a new subr in C, recompile his
-application, and then discover that the Scheme interpreter cannot see
-the subr, because he forgot to call @code{scm_make_gsubr}.
-
-Guile provides the @code{guile-snarf} command to manage this problem.
-Using this tool, you can keep all the information needed to define the
-subr alongside the function definition itself; @code{guile-snarf} will
-extract this information from your source code, and automatically
-generate a file of calls to @code{scm_make_gsubr} which you can
-@code{#include} into an initialization function. (The command name
-comes from the verb ``to snarf'', here meaning ``to unceremoniously
-extract information from a somewhat unwilling source.'')
-
-@menu
-* How guile-snarf works:: Using the @code{guile-snarf} command.
-* Macros guile-snarf recognizes:: How to mark up code for @code{guile-snarf}.
-@end menu
-
-@node How guile-snarf works
-@subsection How @code{guile-snarf} works
-
-For example, here is how you might define a new subr called
-@code{clear-image}, implemented by the C function @code{clear_image}:
-
-@example
-@group
-#include <libguile.h>
-
-@dots{}
-
-SCM_PROC (s_clear_image, "clear-image", 1, 0, 0, clear_image);
-
-SCM
-clear_image (SCM image_smob)
-@{
- @dots{}
-@}
-
-@dots{}
-
-void
-init_image_type ()
-@{
-#include "image-type.x"
-@}
-@end group
-@end example
-
-The @code{SCM_PROC} declaration says that the C function
-@code{clear_image} implements a Scheme subr called @code{clear-image},
-which takes one required argument, no optional arguments, and no tail
-argument. @code{SCM_PROC} also declares a static array of characters
-named @code{s_clear_image}, initialized to the string
-@code{"clear-image"}. The body of @code{clear_image} may use the array
-in error messages, instead of writing out the literal string; this may
-save string space on some systems.
-
-Assuming the text above lives in a file named @file{image-type.c}, you will
-need to execute the following command to compile this file:
-@example
-guile-snarf image-type.c > image-type.x
-@end example
-@noindent This scans @file{image-type.c} for @code{SCM_PROC}
-declarations, and sends the following output to the file
-@file{image-type.x}:
-@example
-scm_make_gsubr (s_clear_image, 1, 0, 0, clear_image);
-@end example
-When compiled normally, @code{SCM_PROC} is a macro which expands to a
-declaration of the @code{s_clear_image} string.
-
-In other words, @code{guile-snarf} scans source code looking for uses of
-the @code{SCM_PROC} macro, and generates C code to define the
-appropriate subrs. You need to provide all the same information you
-would if you were using @code{scm_make_gsubr} yourself, but you can
-place the information near the function definition itself, so it is less
-likely to become incorrect or out-of-date.
-
-If you have many files that @code{guile-snarf} must process, you should
-consider using a rule like the following in your Makefile:
-@example
-.SUFFIXES: .x
-.c.x:
- ./guile-snarf $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $< > $@
-@end example
-This tells make to run @code{guile-snarf} to produce each needed
-@file{.x} file from the corresponding @file{.c} file.
-
-@code{guile-snarf} passes all its command-line arguments directly to the
-C preprocessor, which it uses to extract the information it needs from
-the source code. this means you can pass normal compilation flags to
-@code{guile-snarf} to define preprocessor symbols, add header file
-directories, and so on.
-
-
-
-@node Macros guile-snarf recognizes
-@subsection Macros @code{guile-snarf} recognizes
-
-Here are the macros you can use in your source code from which
-@code{guile-snarf} can construct initialization code:
-
-
-@defmac SCM_PROC (@var{namestr}, @var{name}, @var{req}, @var{opt}, @var{tail}, @var{c_func})
-Declare a new Scheme primitive function, or @dfn{subr}. The new subr
-will be named @var{name} in Scheme code, and be implemented by the C
-function @var{c_func}. The subr will take @var{req} required arguments
-and @var{opt} optional arguments. If @var{tail} is non-zero, the
-function will accept any remaining arguments as a list.
-
-Use this macro outside all function bodies, preferably above the
-definition of @var{c_func} itself. When compiled, the @code{SCM_PROC}
-declaration will expand to a definition for the @var{namestr} array,
-initialized to @var{name}. The @code{guile-snarf} command uses this
-declaration to automatically generate initialization code to create the
-subr and bind it in the top-level environment. @xref{How guile-snarf
-works}, for more info.
-
-@xref{Subrs}, for details on argument passing and how to write
-@var{c_func}.
-@end defmac
-
-
-@defmac SCM_GLOBAL (@var{var}, @var{scheme_name})
-Declare a global Scheme variable named @var{scheme_name}, and a static C
-variable named @var{var} to point to it. The value of the Scheme
-variable lives in the @sc{cdr} of the cell @var{var} points to.
-Initialize the variable to @code{#f}.
-
-Use this macro outside all function bodies. When compiled, the
-@code{SCM_GLOBAL} macro will expand to a definition for the variable
-@var{var}, initialized to an innocuous value. The @code{guile-snarf}
-command will use this declaration to automatically generate code to
-create a global variable named @var{scheme_name}, and store a pointer to
-its cell in @var{var}.
-@end defmac
-
-
-@defmac SCM_CONST_LONG (@var{var}, @var{scheme_name}, @var{value})
-Like @code{SCM_GLOBAL}, but initialize the variable to @var{value},
-which must be an integer.
-@end defmac
-
-
-@defmac SCM_SYMBOL (@var{var}, @var{name})
-Declare a C variable of type @code{SCM} named @var{var}, and initialize
-it to the Scheme symbol object whose name is @var{name}.
-
-Use this macro outside all function bodies. When compiled, the
-@code{SCM_SYMBOL} macro will expand to a definition for the variable
-@var{var}, initialized to an innocuous value. The @code{guile-snarf}
-command will use this declaration to automatically generate code to
-create a symbol named @var{name}, and store it in @var{var}.
-@end defmac
-
-@node Automatically using libtool
-@section Automatically using libtool
-
-@node Automatically using SWIG
-@section Automatically using SWIG
diff --git a/doc/sources/new-types.texi b/doc/sources/new-types.texi
deleted file mode 100644
index 1840b214f..000000000
--- a/doc/sources/new-types.texi
+++ /dev/null
@@ -1,2 +0,0 @@
-@node Adding types to Guile
-@chapter Adding types to Guile
diff --git a/doc/sources/old-intro.texi b/doc/sources/old-intro.texi
deleted file mode 100644
index 0774f64d4..000000000
--- a/doc/sources/old-intro.texi
+++ /dev/null
@@ -1,290 +0,0 @@
-@node Introduction
-@chapter Introduction
-
-Guile is an interpreter for Scheme, a clean, economical programming
-language in the Lisp family. You can invoke Guile from the shell to
-evaluate Scheme expressions interactively, or use it as an interpreter
-for script files. However, Guile is also packaged as a library, to be
-embedded as an extension language into other applications. The
-application can supplement the base language with special-purpose
-functions and datatypes, allowing the user to customize and extend it by
-writing Scheme code.
-
-In its simplest form, Guile is an ordinary interpreter. The
-@code{guile} program can read and evaluate Scheme expressions entered
-from the terminal. Here is a sample interaction between Guile and a
-user; the user's input appears after the @code{$} and @code{guile>}
-prompts:
-
-@example
-$ guile
-guile> (+ 1 2 3) ; add some numbers
-6
-guile> (define (factorial n) ; define a function
- (if (zero? n) 1 (* n (factorial (- n 1)))))
-guile> (factorial 20)
-2432902008176640000
-guile> (getpwnam "jimb") ; find my entry in /etc/passwd
-#("jimb" ".0krIpK2VqNbU" 4008 10 "Jim Blandy" "/u/jimb"
- "/usr/local/bin/bash")
-guile> @kbd{C-d}
-$
-@end example
-
-Guile can also interpret script files. For example, here is a Guile script
-containing a script which displays the
-
-
-application can
-supplement the base language with its own functions, datatypes and
-syntax, allowing the user to extend and
-
-
- Guile interpret
-
-. An
-application the Guile interpreter to allow
-
-
-, allowing
-applications to incorporate the Scheme interpreter for customization
-
-[[interactive]]
-[[script interpreter]]
-[[embedded]]
-
-[[other languages]]
-The concept of an extension language library does not originate with
-Guile. However, Guile is the first to offer users a choice of languages
-to program in.
-
-
-Guile currently supports Scheme and Ctax , and we expect to support Emacs Lisp in the near future.
-
-
-Scheme is powerful enough that other languages can be
-conveniently translated into it,
-
-However, unlike other extension packages, Guile gives users a choice of
-languages to program in. Guile can
-
-
-In this sense, Guile resembles the Tcl and Python packages, providing
-both an ordinary interpreter and an extension language library.
-However, unlike those packages, Guile supports more than one programming
-language.
-
-; users can
-write Scheme code to control and customize applications which
-incorporate Guile
-
-, adding their own functions,
-datatypes, and syntax, to allow the user to programm
-
-
-link it into your own programs to make them
-
-
-
-Guile is a library containing an interpreter for Scheme, a complete but
-economical programming language, which the developer can customize to
-suit the application at hand by adding new functions, data types, and
-control structures. These may be implemented in C, and then
-``exported'' for use by the interpreted code. Because Guile already
-provides a full-featured interpreter, the developer need not neglect the
-language's design in order to concentrate on code relevant to the task.
-In this way, Guile provides a framework for the construction of
-domain-specific languages.
-
-Guile provides first-class functions, a rich set of data types,
-exception handling, a module system, and a powerful macro facility.
-Guile also supports dynamic linking and direct access to Unix system
-calls. Releases in the near future will support a source-level
-debugger and bindings for the Tk user interface toolkit.
-
-
-
-Guile is a framework for writing applications controlled by specialized
-languages. In its simplest form, Guile is an interpreter for Scheme, a
-clean, economical programming language in the Lisp family. However,
-Guile is packaged as a library, allowing applications to link against it
-and use Scheme as their extension language. The application can add
-primitive functions to the language, implement new data types, and even
-adjust the language's syntax.
-
-
-
-[the introduction is probably not what Jim has in mind; I just took the
-one I had in earlier, since the file had the same name intro.texi]
-
-Guile is an implementation of the Scheme programming language, but, like
-other modern implementations of Scheme, it adds many features that the
-community of Scheme programmers considers necessary for an ``industrial
-strength'' language.
-
-Examples of extensions to Scheme are the module system
-(@pxref{Modules}), the Unix system programming tools (@pxref{POSIX
-system calls and networking} and @pxref{The Scheme shell (scsh)}), an
-interface to @emph{libtool} to make it easier to add C libraries as
-primitives (@pxref{Linking Guile with your code}), and (FIXME add more).
-
-On top of these extensions, which many other Scheme implementations
-provide, Guile also offers the possibility of writing routines in other
-languages and running them simultaneously with Scheme. The desire to
-implement other languages (in particular Emacs Lisp) on top of Scheme is
-responsible for Guile's only deviation from the R4RS @footnote{R4RS is
-the Revised^4 Report on the Algorithmic Language Scheme, the closest
-thing to a standard Scheme specification today} Scheme standard
-(@cite{r4rs}): Guile is case sensitive, whereas ``standard'' Scheme is
-not.
-
-But even more fundamentally, Guile is meant to be an @emph{embeddable}
-Scheme interpreter. This means that a lot of work has gone into
-packaging the interpreter as a C library (@pxref{A Portable C to Scheme Interface} and @pxref{Scheme data representation}).
-
-This reference manual is mainly driven by the need to document all the
-features that go beyond standard Scheme.
-
-@menu
-* Getting started::
-* Guile feature list::
-* What you need to use Guile::
-* Roadmap to the Manual::
-* Motivation for Guile::
-* History of Guile::
-@end menu
-
-@node Getting started
-@section Getting started
-
-We assume that you know how to program in Scheme, although we do not
-assume advanced knowledge. If you don't know Scheme, there are many
-good books on Scheme at all levels, and the Guile Tutorial might give
-you a good enough feel for the language. We also assume that you know
-how to program in C, since there will be many examples of how to program
-in C using Guile as a library.
-
-Many diverse topics from the world of Unix hacking will be covered here,
-such as shared libraries, socket programming, garbage collection, and so
-forth. If at any time you feel you don't have enough background on a
-given topic, just go up a level or two in the manual, and you will find
-that the chapter begins with a few paragraphs that introduce the topic.
-If you are still lost, read through the Guile tutorial and then come
-back to this reference manual.
-
-To run the core Guile interpreter and extension library you need no more
-than a basically configured GNU/Unix system and the Guile sources. You
-should download and install the Guile sources (@pxref{Obtaining and
-Installing Guile}).
-
-
-@node Guile feature list
-@section Guile feature list
-
-In a reductionist view, Guile could be regarded as:
-@itemize @bullet
-@item
-An R4RS-compliant Scheme interpreter.
-
-@item
-Some Scheme features that go beyond the R4RS standard, notably a module
-system, exception handling primitives and an interface to Aubrey
-Jaffer's SLIB.
-
-@item
-A symbolic debugger for Scheme, and gdb extensions to facilitate
-debugging libguile programs.
-
-@item
-An embeddable version of the same interpreter, called @emph{libguile}.
-
-@item
-A portable high level API on top of libguile (the @code{gh_} interface).
-
-@item
-A collection of bundled C libraries with a Guile API. As we write, this
-list includes:
-
-@table @strong
-@item Rx
-a regular expression library.
-
-@item Unix
-a low-level interface to the POSIX system calls, socket library
-and other Unix system services.
-
-@item Tk
-an interface to John Ousterhout's Tk toolkit.
-
-@end table
-
-@item
-A set of tools for implementing other languages @emph{on top of Scheme},
-and an example implementation of a language called @emph{Ctax}.
-
-
-@end itemize
-
-
-@node What you need to use Guile
-@section What you need to use Guile
-
-
-@node Roadmap to the Manual
-@section Roadmap to the Manual
-
-@node Motivation for Guile
-@section Motivation for Guile
-
-@node History of Guile
-@section History of Guile
-
-@page
-@node Using Guile
-@chapter Using Guile
-
-[I think that this might go in the appendix in Jim's view of the manual]
-
-@page
-@node Invoking Guile
-@appendix Invoking Guile
- --- mentions read-eval-print loops
- --- both the SCSH and GAWK manuals relegate invocation details
- to an appendix. We can give examples in the introduction.
-
-@table @samp
-@item -h
-@itemx --help
-Display a helpful message.
-@item -v
-@item --version
-Display the current version.
-@item --emacs
-To be used for emacs editing support.
-@item -s @var{file}
-Process @var{file} as a script then quit. This is a terminating option:
-any further command line arguments can be accessed by the script using
-the @code{(program-arguments)} procedure.
-
-An executable script can start with the following:
-
-@smallexample
-#!/usr/bin/guile -s
-!#
-@end smallexample
-
-Note the @code{!#} token on the second line. It is very important
-to include this token when writing Guile scripts. Guile and SCSH,
-the Scheme shell, share the convention that @code{#!} and
-@code{!#} may be used to mark block comments (@pxref{Block
-comments and interpreter triggers}). If the closing @code{!#}
-token is not included, then Guile will consider the block comment
-to be unclosed, and the script will probably not compile
-correctly.
-
-It is also important to include the @samp{-s} option at the
-beginning of the Guile script, so that Guile knows not to behave
-in an interactive fashion.
-
-@end table
-
diff --git a/doc/sources/sample-APIs.texi b/doc/sources/sample-APIs.texi
deleted file mode 100644
index c8c4b8e72..000000000
--- a/doc/sources/sample-APIs.texi
+++ /dev/null
@@ -1,6 +0,0 @@
-@node Examples of adding libraries
-@chapter Examples of adding libraries
-
-Should contain examples of brute-force gh_, Guile magic snarfer,
-libtool, SWIG on a dummy API, followed by some real examples of how
-libraries are added.
diff --git a/doc/sources/scheme-concepts.texi b/doc/sources/scheme-concepts.texi
deleted file mode 100644
index 0e9ae6cf8..000000000
--- a/doc/sources/scheme-concepts.texi
+++ /dev/null
@@ -1,249 +0,0 @@
-@node Guile Scheme concepts
-@chapter Guile Scheme concepts
-
-Most Scheme implementations go beyond what is specified in the R4RS
-document @footnote{Remember? R4RS is the Revised^4 report on the
-Algorithmic Language Scheme}, mostly because R4RS does not give
-specifications (or even recommendations) regarding some issues that are
-quite important in practical programming.
-
-Here is a list of how Guile implements some of these much-needed Scheme
-extensions; other Scheme implementations do so quite similarly.
-
-@menu
-* Scheme slang::
-* Read-eval-print loops::
-* Extra data types::
-* Miscellaneous features::
-@end menu
-
-@node Scheme slang
-@section Scheme slang
-@cindex slang
-
-Even if you read some of the nice books on Scheme, or the R4RS report,
-you might not find some of the terms frequently used by Scheme hackers,
-both in the manual and in the @url{news:comp.lang.scheme} newsgroup.
-
-Here is a glossary of some of the terms that make Scheme beginners and
-intermediate users say ``huh?''
-
-@table @strong
-@item thunk
-@cindex thunk
-A Scheme procedure that takes no arguments. In this example,
-@code{thunk} and @code{another-thunk} are both thunks:
-@lisp
-(define (thunk)
- (display "Dude, I'm a thunk!")
- (newline))
-(define another-thunk
- (lambda ()
- (display "Me too!\n")
- (newline)))
-@end lisp
-
-@item closure
-@cindex closure
-A closure is a procedure. However, the term emphasizes the fact that a
-Scheme procedure remembers (or @dfn{closes over}) the variables that
-were visible when the @code{lambda} expression was
-evaluated.
-
-In the example below, we might refer to @code{q} as a closure, because
-it has closed over the value of @code{x}:
-@lisp
-(define p
- (lambda (x)
- (lambda (y)
- (+ x y))))
-(define q (p 5.7))
-
-(q 10)
-@result{} 15.7
-@end lisp
-
-However, strictly speaking, every Scheme procedure is really a closure,
-since it closes over the top-level environment.
-
-@item alist
-@itemx association list
-
-@item plist
-@itemx property list
-
-@end table
-
-
-@node Read-eval-print loops
-@section Read-eval-print loops
-@cindex Read-eval-print loop
-@cindex REPL
-
-To explicitly mention the Scheme read-eval-print loop (REPL) seems weird
-because we are all accustomed to firing up an interpreter and having it
-read and execute commands.
-
-But the REPL is not specified in R4RS; rather, it is proposed by the
-Scheme Bible @cite{Structure and Interpretation of Computer Programs}
-(also known as @emph{SICP}), and implemented in some form in all Scheme
-interpreters.
-@cindex Structure and Interpretation of Computer Programs
-@cindex SICP
-
-[FIXME: Someone needs to tell me what needs to be said about Guile's
-REPL.]
-
-@node Extra data types
-@section Extra data types
-
-The fundamental Scheme data types specified in R4RS are @emph{numbers}
-(both exact and inexact), @emph{characters}, @emph{strings},
-@emph{symbols}, @emph{vectors}, @emph{pairs} and @emph{lists} [FIXME: is
-this complete?].
-
-Many Scheme interpreters offer more types, and Guile is no exception.
-Guile is based on Aubrey Jaffer's SCM interpreter, and thus inherits
-@emph{uniform arrays}, [FIXME: any others? How about records?].
-
-On top of that, Guile allows you to add extra types, but that is covered
-in @ref{Adding types to Guile}. Here I will simply document all the
-extra Scheme types shipped with Guile.
-
-@menu
-* Conventional arrays::
-* Uniform arrays::
-* Bit vectors::
-* Complex numbers::
-@end menu
-
-@node Conventional arrays
-@subsection Conventional arrays
-
-@node Uniform arrays
-@subsection Uniform arrays
-@cindex arrays - uniform
-
-The motivation for uniform arrays in Scheme is performance. A vector
-provides a performance increase over lists when you want a fixed-size
-indexable list. But the elements in a vector can be of different types,
-and this makes for larger storage requirements and slightly lower
-performance.
-
-A uniform array is similar to a vector, but all elements have to be of
-the same type.
-
-arrays, uniform arrays, bit vectors:
-
-@deffn procedure array-fill ra fill
-@end deffn
-@deffn procedure serial-array-copy! src dst
-@end deffn
-@deffn procedure serial-array-map ra0 proc [lra]
-@end deffn
-@deffn procedure array-map ra0 proc [lra]
-@end deffn
-@deffn procedure array-for-each proc ra0 [lra]
-@end deffn
-@deffn procedure array-index-map! ra proc
-@end deffn
-@deffn procedure array-copy! src dst
-@end deffn
-@deffn procedure array-copy! src dst
-@end deffn
-@deffn procedure array-copy! src dst
-@end deffn
-@deffn procedure array-copy! src dst
-@end deffn
-@deffn procedure array-copy! src dst
-@end deffn
-@deffn procedure array? ra [prot]
-@end deffn
-@deffn procedure array-rank ra
-@end deffn
-@deffn procedure array-dimensions ra
-@end deffn
-@deffn procedure dimensions->uniform-array dims prot fill ...
-@end deffn
-@deffn procedure make-shared-array ra mapfunc dims ...
-@end deffn
-@deffn procedure transpose-array arg ...
-@end deffn
-@deffn procedure enclose-array axes ...
-@end deffn
-@deffn procedure array-in-bounds? arg ...
-@end deffn
-@deffn procedure array-ref ra arg ..
-@end deffn
-@deffn procedure uniform-vector-ref vec pos
-@end deffn
-@deffn procedure array-set! ra obj arg ...
-@end deffn
-@deffn procedure uniform-array-set1! ua obj arg
-@end deffn
-@deffn procedure array-contents ra [strict]
-@end deffn
-@deffn procedure uniform-array-read! ra [port-or-fd] [start] [end]
-@end deffn
-@deffn procedure uniform-array-write! ra [port-or-fd] [start] [end]
-@end deffn
-@deffn procedure bit-count item seq
-@end deffn
-@deffn procedure bit-position item v k
-@end deffn
-@deffn procedure bit-set! v kv obj
-@end deffn
-@deffn procedure bit-count* v kv obj
-@end deffn
-@deffn procedure bit-invert v
-@end deffn
-@deffn procedure array->list ra
-@end deffn
-@deffn procedure list->uniform-array ndim prot list
-@end deffn
-@deffn procedure array-prototype ra
-@end deffn
-
-Uniform arrays can be written and read, but @code{read} won't recognize
-them unless the optional @code{read-sharp} parameter is supplied,
-e.g,
-@smalllisp
-(read port #t read-sharp)
-@end smalllisp
-
-where @code{read-sharp} is the default procedure for parsing extended
-sharp notations.
-
-Reading an array is not very efficient at present, since it's implemented
-by reading a list and converting the list to an array.
-
-@c FIXME: must use @deftp, but its generation of TeX code is buggy.
-@c Must fix it when TeXinfo gets fixed.
-@deftp {Scheme type} {uniform array}
-
-@end deftp
-
-@node Bit vectors
-@subsection Bit vectors
-
-@node Complex numbers
-@subsection Complex numbers
-
-@c FIXME: must use @deftp, but its generation of TeX code is buggy.
-@c Must fix it when TeXinfo gets fixed.
-@deftp {Scheme type} complex
-Standard complex numbers.
-@end deftp
-
-@node Miscellaneous features
-@section Miscellaneous features
-
-@defun defined? symbol
-Returns @code{#t} if a symbol is bound to a value, @code{#f} otherwise.
-This kind of procedure is not specified in R4RS because @c FIXME: finish
-this thought
-@end defun
-
-@defun object-properties OBJ
-and so forth
-@end defun
diff --git a/doc/sources/scm-ref.texi b/doc/sources/scm-ref.texi
deleted file mode 100644
index eca672580..000000000
--- a/doc/sources/scm-ref.texi
+++ /dev/null
@@ -1,4 +0,0 @@
-@node Libguile -- SCM interface
-@chapter Libguile -- SCM interface
-
-
diff --git a/doc/sources/strings.texi b/doc/sources/strings.texi
deleted file mode 100644
index 9a1ddc952..000000000
--- a/doc/sources/strings.texi
+++ /dev/null
@@ -1,45 +0,0 @@
-@node Strings
-@chapter Facilities for string manipulation
-
-@deffn procedure string? string
-@end deffn
-@deffn procedure read-only-string? string
-@end deffn
-@deffn procedure list->string list
-@end deffn
-@deffn procedure make-string length [char]
-@end deffn
-@deffn procedure string-length string
-@end deffn
-@deffn procedure string-ref string [index]
-@end deffn
-@deffn procedure string-set! string index char
-@end deffn
-@deffn procedure substring string start [end]
-@end deffn
-@deffn procedure string-append arg ...
-@end deffn
-@deffn procedure make-shared-substring string [from] [to]
-@end deffn
-@deffn procedure string-set! string index char
-@end deffn
-@deffn procedure string-index string char [from] [to]
-@end deffn
-@deffn procedure string-rindex string char [from] [to]
-@end deffn
-@deffn procedure substring-move-left! string1 start1 [end1] [string2] [start2]
-@end deffn
-@deffn procedure substring-move-right! string1 start1 [end1] [string2] [start2]
-@end deffn
-@deffn procedure substring-fill! string start [end] [fill]
-@end deffn
-@deffn procedure string-null? string
-@end deffn
-@deffn procedure string->list string
-@end deffn
-@deffn procedure string-copy string
-@end deffn
-@deffn procedure string-upcase! string
-@end deffn
-@deffn procedure string-downcase! string
-@end deffn
diff --git a/doc/sources/tk.texi b/doc/sources/tk.texi
deleted file mode 100644
index 176c8c7b8..000000000
--- a/doc/sources/tk.texi
+++ /dev/null
@@ -1,5 +0,0 @@
-@node Tk interface
-@chapter Tk interface
-
-For now Guile has no well-specified Tk interface. It is an important part
-of Guile, though, and will be documented here when it is written.
diff --git a/doc/sources/unix-other.texi b/doc/sources/unix-other.texi
deleted file mode 100644
index 7b810d5d6..000000000
--- a/doc/sources/unix-other.texi
+++ /dev/null
@@ -1,132 +0,0 @@
-@node Other Unix
-@chapter Other Unix-specific facilities
-
-@menu
-* Expect:: Expect, for pattern matching from a port.
-@end menu
-
-@node Expect
-@section Expect: Pattern Matching from a Port
-
-@code{expect} is a macro for selecting actions based on the output from
-a port. The name comes from a tool of similar functionality by Don Libes.
-Actions can be taken when a particular string is matched, when a timeout
-occurs, or when end-of-file is seen on the port. The @code{expect} macro
-is described below; @code{expect-strings} is a front-end to @code{expect}
-based on regexec @xref{Regular expressions}.
-
-Using these macros requires for now:
-@smalllisp
-(load-from-path "ice-9/expect")
-@end smalllisp
-
-@defun expect-strings clause @dots{}
-By default, @code{expect-strings} will read from the current input port.
-The first term in each clause consists of an expression evaluating to
-a string pattern (regular expression). As characters
-are read one-by-one from the port, they are accumulated in a buffer string
-which is matched against each of the patterns. When a
-pattern matches, the remaining expression(s) in
-the clause are evaluated and the value of the last is returned. For example:
-
-@smalllisp
-(with-input-from-file "/etc/passwd"
- (lambda ()
- (expect-strings
- ("^nobody" (display "Got a nobody user.\n")
- (display "That's no problem.\n"))
- ("^daemon" (display "Got a daemon user.\n")))))
-@end smalllisp
-
-The regular expression is compiled with the @code{REG_NEWLINE} flag, so
-that the @code{^} and @code{$} anchors will match at any newline, not
-just at the start
-and end of the string.
-
-There are two other ways to write a clause:
-
-The expression(s) to evaluate on a match
-can be omitted, in which case the result of the match
-(converted to strings, as obtained from regexec with @var{match-pick}
-set to @code{""}) will be returned if the pattern matches.
-
-The symbol @code{=>} can be used to indicate that there is a single
-expression to evaluate on a match, which must be a
-procedure which will accept the result of a successful match (converted
-to strings, as obtained from regexec with @var{match-pick} set to
-@code{""}). E.g.,
-
-@smalllisp
-("^daemon" => write)
-("^d\\(aemon\\)" => (lambda args (map write args)))
-("^da\\(em\\)on" => (lambda (all sub)
- (write all)
- (write sub)))
-@end smalllisp
-
-The order of the substrings corresponds to the order in which the
-opening brackets occur in the regular expression.
-
-A number of variables can be used to control the behaviour
-of @code{expect} (and @code{expect-strings}).
-By default they are all bound at the top level to
-the value @code{#f}, which produces the default behaviour.
-They can be redefined at the
-top level or locally bound in a form enclosing the @code{expect} expression.
-
-@table @code
-@item expect-port
-A port to read characters from, instead of the current input port.
-@item expect-timeout
-@code{expect} will terminate after this number of
-seconds, returning @code{#f} or the value returned by
-@code{expect-timeout-proc}.
-@item expect-timeout-proc
-A procedure called if timeout occurs. The procedure takes a single argument:
-the accumulated string.
-@item expect-eof-proc
-A procedure called if end-of-file is detected on the input port. The
-procedure takes a single argument: the accumulated string.
-@item expect-char-proc
-A procedure to be called every time a character is read from the
-port. The procedure takes a single argument: the character which was read.
-@end table
-
-Here's an example using all of the variables:
-
-@smalllisp
-(let ((expect-port (open-input-file "/etc/passwd"))
- (expect-timeout 1)
- (expect-timeout-proc
- (lambda (s) (display "Times up!\n")))
- (expect-eof-proc
- (lambda (s) (display "Reached the end of the file!\n")))
- (expect-char-proc display))
- (expect-strings
- ("^nobody" (display "Got a nobody user\n"))))
-@end smalllisp
-@end defun
-
-@defun expect clause @dots{}
-@code{expect} is used in the same way as @code{expect-strings},
-but tests are specified not as patterns, but as procedures. The
-procedures are called in turn after each character is read from the
-port, with the value of the accumulated string as the argument. The
-test is successful if the procedure returns a non-false value.
-
-If the @code{=>} syntax is used, then if the test succeeds it must return
-a list containing the arguments to be provided to the corresponding
-expression.
-
-In the following example, a string will only be matched at the beginning
-of the file:
-@smalllisp
-(let ((expect-port (open-input-file "/etc/passwd")))
- (expect
- ((lambda (s) (string=? s "fnord!"))
- (display "Got a nobody user!\n"))))
-@end smalllisp
-
-The control variables described for @code{expect-strings} can also
-be used with @code{expect}.
-@end defun
diff --git a/doc/sources/unix.texi b/doc/sources/unix.texi
deleted file mode 100644
index b8bf2cdb3..000000000
--- a/doc/sources/unix.texi
+++ /dev/null
@@ -1,622 +0,0 @@
-@node Low level Unix
-@chapter Low level Unix interfaces
-
-The low level Unix interfaces are currently available by
-default in the Guile top level. However in the future they will probably
-be placed in a module and @code{use-modules} or something similar will
-be required to make them available.
-
-@menu
-* Unix conventions:: Conventions followed by the low level Unix
- interfaces.
-* Ports and descriptors:: Ports, file descriptors and how they
- interact.
-* Extended I/O:: Reading and writing to ports.
-* File system:: Working in a hierarchical file system.
-* User database:: Information about users from system databases.
-* Processes:: Information and control of Unix processes.
-* Terminals:: Terminals and pseudo-terminals.
-* Network databases:: Network address conversion and information
- from system databases.
-* Network sockets:: An interface to the BSD socket library.
-* Miscellaneous Unix:: Miscellaneous Unix interfaces.
-@end menu
-
-@node Unix conventions
-@section Low level Unix conventions
-
-The low-level interfaces are designed to give Scheme programs
-access to as much functionality as possible from the underlying
-Unix system. They can be used to implement higher level
-interfaces such as the Scheme shell @ref{scsh}.
-
-Generally there is a single procedure for each corresponding Unix
-facility. However some of the procedures are implemented for
-speed and convenience in Scheme and have no Unix equivalent
-(e.g., @code{read-delimited}, @code{copy-file}.)
-
-This interface is intended as far as possible to be portable across
-different versions of Unix, so that Scheme programmers don't need to be
-concerned with implementation differences. In some cases procedures
-which can't be implemented (or reimplemented) on particular systems may
-become no-ops, or perform limited actions. In other cases they may
-throw errors. It should be possible to use the feature system to
-determine what functionality is available.
-
-General naming conventions are as follows:
-
-@itemize @bullet
-@item
-The Scheme name is often identical to the name of the underlying Unix
-facility.
-@item
-Underscores in Unix names are converted to hyphens.
-@item
-Procedures which destructively modify Scheme data gain appended
-exclamation marks, e.g., @code{recv!}.
-@item
-Predicates have question marks appended, e.g., @code{access?}.
-@item
-Some names are changed to avoid conflict with dissimilar interfaces
-defined by scsh.
-@item
-Unix preprocessor names such as @code{EPERM} or @code{R_OK} are converted
-to Scheme variables of the same name (underscores are not replaced
-with hyphens)
-@end itemize
-
-Most of the Unix interface procedures can be relied on to return a
-well-specified value. Unexpected conditions are handled by raising
-exceptions.
-
-There are a few procedures which return a special
-value if they don't succeed, e.g., @code{getenv} returns @code{#f}
-if it the requested string is not found in the environment. These
-cases will be noted in the documentation.
-
-For ways to deal with exceptions, @ref{Exceptions}.
-
-Errors which the C-library would report by returning a NULL
-pointer or through some other means cause a @code{system-error} exception
-to be raised. The value of the Unix @code{errno} variable is available
-in the data passed by the exception, so there is no need to access the
-global errno value (doing so would be unreliable in the presence of
-continuations or multiple threads).
-
-@deffn procedure errno [n]
-@end deffn
-@deffn procedure perror string
-@end deffn
-
-@node Ports and descriptors
-@section Ports and file descriptors
-
-@deffn procedure move->fdes port fd
-@end deffn
-@deffn procedure release-port-handle port
-@end deffn
-@deffn procedure set-port-revealed! @var{port} count
-@end deffn
-@deffn procedure fdes->ports fdes
-@end deffn
-@deffn procedure fileno port
-@end deffn
-@deffn procedure fdopen fdes modes
-@end deffn
-@deffn procedure duplicate-port port modes
-@end deffn
-@deffn procedure redirect-port into-port from-port
-@end deffn
-@deffn procedure freopen filename modes port
-@end deffn
-
-@node Extended I/O
-@section Extended I/O
-
-Extended I/O procedures are available which read or write lines of text,
-read text delimited by a specified set of characters, or report or
-set the current position of a port.
-
-@findex fwrite
-@findex fread
-Interfaces to @code{read}/@code{fread} and @code{write}/@code{fwrite} are
-also available, as @code{uniform-array-read!} and @code{uniform-array-write!},
-@ref{Uniform arrays}.
-
-@deffn procedure read-line [port] [handle-delim]
-Return a line of text from @var{port} if specified, otherwise from the
-value returned by @code{(current-input-port)}. Under Unix, a line of text
-is terminated by the first end-of-line character or by end-of-file.
-
-If @var{handle-delim} is specified, it should be one of the following
-symbols:
-@table @code
-@item trim
-Discard the terminating delimiter. This is the default, but it will
-be impossible to tell whether the read terminated with a delimiter or
-end-of-file.
-@item concat
-Append the terminating delimiter (if any) to the returned string.
-@item peek
-Push the terminating delimiter (if any) back on to the port.
-@item split
-Return a pair containing the string read from the port and the
-terminating delimiter or end-of-file object.
-
-NOTE: if the scsh module is loaded then
-multiple values are returned instead of a pair.
-@end table
-@end deffn
-@deffn procedure read-line! buf [port]
-Read a line of text into the supplied string @var{buf} and return the
-number of characters added to @var{buf}. If @var{buf} is filled, then
-@code{#f} is returned.
-Read from @var{port} if
-specified, otherwise from the value returned by @code{(current-input-port)}.
-@end deffn
-@deffn procedure read-delimited delims [port] [handle-delim]
-Read text until one of the characters in the string @var{delims} is found
-or end-of-file is reached. Read from @var{port} if supplied, otherwise
-from the value returned by @code{(current-input-port)}.
-@var{handle-delim} takes the same values as described for @code{read-line}.
-
-NOTE: if the scsh module is loaded then @var{delims} must be an scsh
-char-set, not a string.
-@end deffn
-@deffn procedure read-delimited! delims buf [port] [handle-delim] [start] [end]
-Read text into the supplied string @var{buf} and return the number of
-characters added to @var{buf} (subject to @var{handle-delim}, which takes
-the same values specified for @code{read-line}. If @var{buf} is filled,
-@code{#f} is returned for both the number of characters read and the
-delimiter. Also terminates if one of the characters in the string
-@var{delims} is found
-or end-of-file is reached. Read from @var{port} if supplied, otherwise
-from the value returned by @code{(current-input-port)}.
-
-NOTE: if the scsh module is loaded then @var{delims} must be an scsh
-char-set, not a string.
-@end deffn
-@deffn procedure write-line obj [port]
-Display @var{obj} and a new-line character to @var{port} if specified,
-otherwise to the
-value returned by @code{(current-output-port)}; equivalent to:
-
-@smalllisp
-(display obj [port])
-(newline [port])
-@end smalllisp
-@end deffn
-@deffn procedure ftell port
-Returns an integer representing the current position of @var{port},
-measured from the beginning.
-@end deffn
-@deffn procedure fseek port offset whence
-Sets the current position of @var{port} to the integer @var{offset},
-which is interpreted according to the value of @var{whence}.
-
-One of the following variables should be supplied
-for @var{whence}:
-@defvar SEEK_SET
-Seek from the beginning of the file.
-@end defvar
-@defvar SEEK_CUR
-Seek from the current position.
-@end defvar
-@defvar SEEK_END
-Seek from the end of the file.
-@end defvar
-@end deffn
-
-@node File system
-@section File system
-
-These procedures query and set file system attributes (such as owner,
-permissions, sizes and types of files); deleting, copying, renaming and
-linking files; creating and removing directories and querying their
-contents; and the @code{sync} interface.
-
-@deffn procedure access? path how
-Evaluates to @code{#t} if @var{path} corresponds to an existing
-file and the current process
-has the type of access specified by @var{how}, otherwise
-@code{#f}.
-@var{how} should be specified
-using the values of the variables listed below. Multiple values can
-be combined using a bitwise or, in which case @code{#t} will only
-be returned if all accesses are granted.
-
-Permissions are checked using the real id of the current process,
-not the effective id, although it's the effective id which determines
-whether the access would actually be granted.
-
-@defvar R_OK
-test for read permission.
-@end defvar
-@defvar W_OK
-test for write permission.
-@end defvar
-@defvar X_OK
-test for execute permission.
-@end defvar
-@defvar F_OK
-test for existence of the file.
-@end defvar
-@end deffn
-@findex fstat
-@deffn procedure stat obj
-Evaluates to an object containing various information
-about the file determined by @var{obj}.
-@var{obj} can be a string containing a file name or a port or file
-descriptor which is open on a file (in which case @code{fstat} is used
-as the underlying system call).
-
-The object returned by @code{stat} can be passed as a single parameter
-to the following procedures, all of which return integers:
-
-@table @r
-@item stat:dev
-The device containing the file.
-@item stat:ino
-The file serial number, which distinguishes this file from all other
-files on the same device.
-@item stat:mode
-The mode of the file. This includes file type information
-and the file permission bits. See @code{stat:type} and @code{stat:perms}
-below.
-@item stat:nlink
-The number of hard links to the file.
-@item stat:uid
-The user ID of the file's owner.
-@item stat:gid
-The group ID of the file.
-@item stat:rdev
-Device ID; this entry is defined only for character or block
-special files.
-@item stat:size
-The size of a regular file in bytes.
-@item stat:atime
-The last access time for the file.
-@item stat:mtime
-The last modification time for the file.
-@item stat:ctime
-The last modification time for the attributes of the file.
-@item stat:blksize
-The optimal block size for reading or writing the file, in bytes.
-@item stat:blocks
-The amount of disk space that the file occupies measured in units of
-512 byte blocks.
-@end table
-
-In addition, the following procedures return the information
-from stat:mode in a more convenient form:
-
-@table @r
-@item stat:type
-A symbol representing the type of file. Possible values are
-currently: regular, directory, symlink, block-special, char-special,
-fifo, socket, unknown
-@item stat:perms
-An integer representing the access permission bits.
-@end table
-@end deffn
-@deffn procedure lstat path
-Similar to @code{stat}, but does not follow symbolic links, i.e.,
-it will return information about a symbolic link itself, not the
-file it points to. @var{path} must be a string.
-@end deffn
-@deffn procedure readlink path
-@end deffn
-@deffn procedure chown path owner group
-@end deffn
-@deffn procedure chmod port-or-path mode
-@end deffn
-@deffn procedure utime path [actime] [modtime]
-@end deffn
-@deffn procedure delete-file path
-@end deffn
-@deffn procedure copy-file path-from path-to
-@end deffn
-@deffn procedure rename-file path-from path-to
-@end deffn
-@deffn procedure link path-from path-to
-@end deffn
-@deffn procedure symlink path-from path-to
-@end deffn
-@deffn procedure mkdir path [mode]
-@end deffn
-@deffn procedure rmdir path
-@end deffn
-@deffn procedure opendir path
-@end deffn
-@deffn procedure readdir port
-@end deffn
-@deffn procedure rewinddir port
-@end deffn
-@deffn procedure closedir port
-@end deffn
-@deffn procedure sync
-@end deffn
-
-@node User database
-@section User database
-
-@deffn procedure getpwuid uid
-@end deffn
-@deffn procedure getpwnam name
-@end deffn
-@deffn procedure getpwent
-@end deffn
-@deffn procedure setpwent port
-@end deffn
-@deffn procedure endpwent
-@end deffn
-@deffn procedure getgrgid uid
-@end deffn
-@deffn procedure getgrnam name
-@end deffn
-@deffn procedure getgrent
-@end deffn
-@deffn procedure setgrent port
-@end deffn
-@deffn procedure endgrent
-@end deffn
-
-@node Processes
-@section Processes
-
-@deffn procedure chdir path
-@end deffn
-@deffn procedure getcwd
-@end deffn
-@deffn procedure umask [mode]
-@end deffn
-@deffn procedure getpid
-@end deffn
-@deffn procedure getgroups
-@end deffn
-@deffn procedure kill pid sig
-
-@var{sig} should be specified using a variable corresponding to
-the Unix symbolic name, e.g,
-@defvar SIGHUP
-Hang-up signal.
-@end defvar
-@defvar SIGINT
-Interrupt signal.
-@end defvar
-@end deffn
-@deffn procedure waitpid pid options
-@defvar WAIT_ANY
-@end defvar
-@defvar WAIT_MYPGRP
-@end defvar
-@defvar WNOHANG
-@end defvar
-@defvar WUNTRACED
-@end defvar
-@end deffn
-@deffn procedure getppid
-@end deffn
-@deffn procedure getuid
-@end deffn
-@deffn procedure getgid
-@end deffn
-@deffn procedure geteuid
-@end deffn
-@deffn procedure getegid
-@end deffn
-@deffn procedure setuid id
-@end deffn
-@deffn procedure setgid id
-@end deffn
-@deffn procedure seteuid id
-@end deffn
-@deffn procedure setegid id
-@end deffn
-@deffn procedure getpgrp
-@end deffn
-@deffn procedure setpgid pid pgid
-@end deffn
-@deffn procedure setsid
-@end deffn
-@deffn procedure execl arg ...
-@end deffn
-@deffn procedure execlp arg ...
-@end deffn
-@deffn procedure primitive-fork
-@end deffn
-@deffn procedure environ [env]
-@end deffn
-@deffn procedure putenv string
-@end deffn
-@deffn procedure nice incr
-@end deffn
-
-@node Terminals
-@section Terminals and pseudo-terminals
-
-@deffn procedure isatty? port
-@end deffn
-@deffn procedure ttyname port
-@end deffn
-@deffn procedure ctermid
-@end deffn
-@deffn procedure tcgetpgrp port
-@end deffn
-@deffn procedure tcsetpgrp port pgid
-@end deffn
-
-@node Network databases
-@section Network address conversion and system databases
-
-@deffn procedure inet-aton address
-@end deffn
-@deffn procedure inet-ntoa number
-@end deffn
-@deffn procedure inet-netof address
-@end deffn
-@deffn procedure inet-lnaof address
-@end deffn
-@deffn procedure inet-makeaddr net lna
-@end deffn
-@deffn procedure gethostbyname name
-@end deffn
-@deffn procedure gethostbyaddr address
-@end deffn
-@deffn procedure gethostent
-@end deffn
-@deffn procedure sethostent port
-@end deffn
-@deffn procedure endhostent
-@end deffn
-@deffn procedure getnetbyname name
-@end deffn
-@deffn procedure getnetbyaddr address
-@end deffn
-@deffn procedure getnetent
-@end deffn
-@deffn procedure setnetent port
-@end deffn
-@deffn procedure endnetent
-@end deffn
-@deffn procedure getprotobyname name
-@end deffn
-@deffn procedure getprotobynumber number
-@end deffn
-@deffn procedure getprotoent
-@end deffn
-@deffn procedure setprotoent port
-@end deffn
-@deffn procedure endprotoent
-@end deffn
-@deffn procedure getservbyname name protocol
-@end deffn
-@deffn procedure getservbyport port protocol
-@end deffn
-@deffn procedure getservent
-@end deffn
-@deffn procedure setservent port
-@end deffn
-@deffn procedure endservent
-@end deffn
-
-@node Network sockets
-@section BSD socket library interface
-
-@deffn procedure socket family style protocol
-@end deffn
-@deffn procedure socketpair family style protocol
-@end deffn
-@deffn procedure getsockopt socket level optname
-@end deffn
-@deffn procedure setsockopt socket level optname value
-@end deffn
-@deffn procedure shutdown socket how
-@end deffn
-@deffn procedure connect socket family address arg ...
-@end deffn
-@deffn procedure bind socket family address arg ...
-@end deffn
-@deffn procedure listen socket backlog
-@end deffn
-@deffn procedure accept socket
-@end deffn
-@deffn procedure getsockname socket
-@end deffn
-@deffn procedure getpeername socket
-@end deffn
-@deffn procedure recv! socket buf [flags]
-@end deffn
-@deffn procedure send socket message [flags]
-@end deffn
-@deffn procedure recvfrom! socket buf [flags] [start] [end]
-@end deffn
-@deffn procedure sendto socket message family address args ... [flags]
-@end deffn
-
-@node Miscellaneous Unix
-@section Miscellaneous Unix interfaces
-
-Things which haven't been classified elsewhere (yet?).
-
-@deffn procedure open path flags [mode]
-@defvar O_RDONLY
-@end defvar
-@defvar O_WRONLY
-@end defvar
-@defvar O_RDWR
-@end defvar
-@defvar O_CREAT
-@end defvar
-@defvar O_EXCL
-@end defvar
-@defvar O_NOCTTY
-@end defvar
-@defvar O_TRUNC
-@end defvar
-@defvar O_APPEND
-@end defvar
-@defvar O_NONBLOCK
-@end defvar
-@defvar O_NDELAY
-@end defvar
-@defvar O_SYNC
-@end defvar
-@end deffn
-@deffn procedure select reads writes excepts secs msecs
-@end deffn
-@deffn procedure uname
-@end deffn
-@deffn procedure pipe
-@end deffn
-@deffn procedure open-pipe command modes
-@end deffn
-@deffn procedure open-input-pipe command
-@end deffn
-@deffn procedure open-output-pipe command
-@end deffn
-@deffn procedure setlocale category [locale]
-@defvar LC_COLLATE
-@end defvar
-@defvar LC_CTYPE
-@end defvar
-@defvar LC_MONETARY
-@end defvar
-@defvar LC_NUMERIC
-@end defvar
-@defvar LC_TIME
-@end defvar
-@defvar LC_MESSAGES
-@end defvar
-@defvar LC_ALL
-@end defvar
-@end deffn
-@deffn procedure strftime format stime
-@end deffn
-@deffn procedure strptime format string
-@end deffn
-@deffn procedure mknod
-@end deffn
-
-@node scsh
-@chapter The Scheme shell (scsh)
-
-Guile includes an incomplete port of the Scheme shell (scsh) 0.4.4.
-
-For information about scsh on the Web see
-@url{http://www-swiss.ai.mit.edu/scsh/scsh.html}.
-The original scsh is available by ftp from
-@url{ftp://swiss-ftp.ai.mit.edu:/pub/su}.
-
-This port of scsh does not currently use the Guile module system, but
-can be initialized using:
-@smalllisp
-(load-from-path "scsh/init")
-@end smalllisp
-
-Note that SLIB must be installed before scsh can be initialized, see
-@ref{SLIB} for details.
-
-@node Threads
-@chapter Programming Threads.
-
diff --git a/lib/Makefile.am b/lib/Makefile.am
index a4a996039..ab5f2d12e 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -21,7 +21,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nproc open pipe2 putenv recv recvfrom rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nl_langinfo nproc open pipe2 putenv recv recvfrom regex rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects
@@ -165,6 +165,15 @@ EXTRA_libgnu_la_SOURCES += bind.c
## end gnulib module bind
+## begin gnulib module btowc
+
+
+EXTRA_DIST += btowc.c
+
+EXTRA_libgnu_la_SOURCES += btowc.c
+
+## end gnulib module btowc
+
## begin gnulib module byteswap
BUILT_SOURCES += $(BYTESWAP_H)
@@ -755,6 +764,39 @@ EXTRA_libgnu_la_SOURCES += isnan.c isnanl.c
## end gnulib module isnanl
+## begin gnulib module langinfo
+
+BUILT_SOURCES += langinfo.h
+
+# We need the following in order to create an empty placeholder for
+# <langinfo.h> when the system doesn't have one.
+langinfo.h: langinfo.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+ $(AM_V_GEN)rm -f $@-t $@ && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+ -e 's|@''HAVE_LANGINFO_H''@|$(HAVE_LANGINFO_H)|g' \
+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+ -e 's|@''NEXT_LANGINFO_H''@|$(NEXT_LANGINFO_H)|g' \
+ -e 's/@''GNULIB_NL_LANGINFO''@/$(GNULIB_NL_LANGINFO)/g' \
+ -e 's|@''HAVE_LANGINFO_CODESET''@|$(HAVE_LANGINFO_CODESET)|g' \
+ -e 's|@''HAVE_LANGINFO_T_FMT_AMPM''@|$(HAVE_LANGINFO_T_FMT_AMPM)|g' \
+ -e 's|@''HAVE_LANGINFO_ERA''@|$(HAVE_LANGINFO_ERA)|g' \
+ -e 's|@''HAVE_LANGINFO_YESEXPR''@|$(HAVE_LANGINFO_YESEXPR)|g' \
+ -e 's|@''HAVE_NL_LANGINFO''@|$(HAVE_NL_LANGINFO)|g' \
+ -e 's|@''REPLACE_NL_LANGINFO''@|$(REPLACE_NL_LANGINFO)|g' \
+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+ < $(srcdir)/langinfo.in.h; \
+ } > $@-t && \
+ mv $@-t $@
+MOSTLYCLEANFILES += langinfo.h langinfo.h-t
+
+EXTRA_DIST += langinfo.in.h
+
+## end gnulib module langinfo
+
## begin gnulib module lib-symbol-visibility
# The value of $(CFLAG_VISIBILITY) needs to be added to the CFLAGS for the
@@ -1106,6 +1148,33 @@ EXTRA_DIST += math.in.h
## end gnulib module math
+## begin gnulib module mbrtowc
+
+
+EXTRA_DIST += mbrtowc.c
+
+EXTRA_libgnu_la_SOURCES += mbrtowc.c
+
+## end gnulib module mbrtowc
+
+## begin gnulib module mbsinit
+
+
+EXTRA_DIST += mbsinit.c
+
+EXTRA_libgnu_la_SOURCES += mbsinit.c
+
+## end gnulib module mbsinit
+
+## begin gnulib module mbtowc
+
+
+EXTRA_DIST += mbtowc-impl.h mbtowc.c
+
+EXTRA_libgnu_la_SOURCES += mbtowc.c
+
+## end gnulib module mbtowc
+
## begin gnulib module memchr
@@ -1198,6 +1267,15 @@ EXTRA_DIST += netinet_in.in.h
## end gnulib module netinet_in
+## begin gnulib module nl_langinfo
+
+
+EXTRA_DIST += nl_langinfo.c
+
+EXTRA_libgnu_la_SOURCES += nl_langinfo.c
+
+## end gnulib module nl_langinfo
+
## begin gnulib module nproc
libgnu_la_SOURCES += nproc.c
@@ -1282,6 +1360,15 @@ EXTRA_libgnu_la_SOURCES += recvfrom.c
## end gnulib module recvfrom
+## begin gnulib module regex
+
+
+EXTRA_DIST += regcomp.c regex.c regex.h regex_internal.c regex_internal.h regexec.c
+
+EXTRA_libgnu_la_SOURCES += regcomp.c regex.c regex_internal.c regexec.c
+
+## end gnulib module regex
+
## begin gnulib module rename
@@ -1921,6 +2008,22 @@ EXTRA_DIST += stdlib.in.h
## end gnulib module stdlib
+## begin gnulib module strcase
+
+
+EXTRA_DIST += strcasecmp.c strncasecmp.c
+
+EXTRA_libgnu_la_SOURCES += strcasecmp.c strncasecmp.c
+
+## end gnulib module strcase
+
+## begin gnulib module streq
+
+
+EXTRA_DIST += streq.h
+
+## end gnulib module streq
+
## begin gnulib module strftime
libgnu_la_SOURCES += strftime.c
@@ -2040,6 +2143,37 @@ EXTRA_DIST += string.in.h
## end gnulib module string
+## begin gnulib module strings
+
+BUILT_SOURCES += strings.h
+
+# We need the following in order to create <strings.h> when the system
+# doesn't have one that works with the given compiler.
+strings.h: strings.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
+ $(AM_V_GEN)rm -f $@-t $@ && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+ sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+ -e 's|@''HAVE_STRINGS_H''@|$(HAVE_STRINGS_H)|g' \
+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+ -e 's|@''NEXT_STRINGS_H''@|$(NEXT_STRINGS_H)|g' \
+ -e 's|@''GNULIB_FFS''@|$(GNULIB_FFS)|g' \
+ -e 's|@''HAVE_FFS''@|$(HAVE_FFS)|g' \
+ -e 's|@''HAVE_STRCASECMP''@|$(HAVE_STRCASECMP)|g' \
+ -e 's|@''HAVE_DECL_STRNCASECMP''@|$(HAVE_DECL_STRNCASECMP)|g' \
+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+ < $(srcdir)/strings.in.h; \
+ } > $@-t && \
+ mv $@-t $@
+MOSTLYCLEANFILES += strings.h strings.h-t
+
+EXTRA_DIST += strings.in.h
+
+## end gnulib module strings
+
## begin gnulib module sys_file
BUILT_SOURCES += sys/file.h
@@ -2704,6 +2838,54 @@ EXTRA_DIST += wchar.in.h
## end gnulib module wchar
+## begin gnulib module wcrtomb
+
+
+EXTRA_DIST += wcrtomb.c
+
+EXTRA_libgnu_la_SOURCES += wcrtomb.c
+
+## end gnulib module wcrtomb
+
+## begin gnulib module wctype-h
+
+BUILT_SOURCES += wctype.h
+
+# We need the following in order to create <wctype.h> when the system
+# doesn't have one that works with the given compiler.
+wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H)
+ $(AM_V_GEN)rm -f $@-t $@ && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+ -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \
+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+ -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \
+ -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \
+ -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \
+ -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \
+ -e 's/@''GNULIB_WCTRANS''@/$(GNULIB_WCTRANS)/g' \
+ -e 's/@''GNULIB_TOWCTRANS''@/$(GNULIB_TOWCTRANS)/g' \
+ -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \
+ -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \
+ -e 's/@''HAVE_WCTYPE_T''@/$(HAVE_WCTYPE_T)/g' \
+ -e 's/@''HAVE_WCTRANS_T''@/$(HAVE_WCTRANS_T)/g' \
+ -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \
+ -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \
+ -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \
+ -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \
+ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+ < $(srcdir)/wctype.in.h; \
+ } > $@-t && \
+ mv $@-t $@
+MOSTLYCLEANFILES += wctype.h wctype.h-t
+
+EXTRA_DIST += wctype.in.h
+
+## end gnulib module wctype-h
+
## begin gnulib module write
diff --git a/lib/btowc.c b/lib/btowc.c
new file mode 100644
index 000000000..485e99554
--- /dev/null
+++ b/lib/btowc.c
@@ -0,0 +1,39 @@
+/* Convert unibyte character to wide character.
+ Copyright (C) 2008, 2010-2012 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+wint_t
+btowc (int c)
+{
+ if (c != EOF)
+ {
+ char buf[1];
+ wchar_t wc;
+
+ buf[0] = c;
+ if (mbtowc (&wc, buf, 1) >= 0)
+ return wc;
+ }
+ return WEOF;
+}
diff --git a/lib/langinfo.in.h b/lib/langinfo.in.h
new file mode 100644
index 000000000..807b245d2
--- /dev/null
+++ b/lib/langinfo.in.h
@@ -0,0 +1,177 @@
+/* Substitute for and wrapper around <langinfo.h>.
+ Copyright (C) 2009-2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/*
+ * POSIX <langinfo.h> for platforms that lack it or have an incomplete one.
+ * <http://www.opengroup.org/onlinepubs/9699919799/basedefs/langinfo.h.html>
+ */
+
+#ifndef _@GUARD_PREFIX@_LANGINFO_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* The include_next requires a split double-inclusion guard. */
+#if @HAVE_LANGINFO_H@
+# @INCLUDE_NEXT@ @NEXT_LANGINFO_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_LANGINFO_H
+#define _@GUARD_PREFIX@_LANGINFO_H
+
+
+#if !@HAVE_LANGINFO_H@
+
+/* A platform that lacks <langinfo.h>. */
+
+/* Assume that it also lacks <nl_types.h> and the nl_item type. */
+# if !GNULIB_defined_nl_item
+typedef int nl_item;
+# define GNULIB_defined_nl_item 1
+# endif
+
+/* nl_langinfo items of the LC_CTYPE category */
+# define CODESET 10000
+/* nl_langinfo items of the LC_NUMERIC category */
+# define RADIXCHAR 10001
+# define THOUSEP 10002
+/* nl_langinfo items of the LC_TIME category */
+# define D_T_FMT 10003
+# define D_FMT 10004
+# define T_FMT 10005
+# define T_FMT_AMPM 10006
+# define AM_STR 10007
+# define PM_STR 10008
+# define DAY_1 10009
+# define DAY_2 (DAY_1 + 1)
+# define DAY_3 (DAY_1 + 2)
+# define DAY_4 (DAY_1 + 3)
+# define DAY_5 (DAY_1 + 4)
+# define DAY_6 (DAY_1 + 5)
+# define DAY_7 (DAY_1 + 6)
+# define ABDAY_1 10016
+# define ABDAY_2 (ABDAY_1 + 1)
+# define ABDAY_3 (ABDAY_1 + 2)
+# define ABDAY_4 (ABDAY_1 + 3)
+# define ABDAY_5 (ABDAY_1 + 4)
+# define ABDAY_6 (ABDAY_1 + 5)
+# define ABDAY_7 (ABDAY_1 + 6)
+# define MON_1 10023
+# define MON_2 (MON_1 + 1)
+# define MON_3 (MON_1 + 2)
+# define MON_4 (MON_1 + 3)
+# define MON_5 (MON_1 + 4)
+# define MON_6 (MON_1 + 5)
+# define MON_7 (MON_1 + 6)
+# define MON_8 (MON_1 + 7)
+# define MON_9 (MON_1 + 8)
+# define MON_10 (MON_1 + 9)
+# define MON_11 (MON_1 + 10)
+# define MON_12 (MON_1 + 11)
+# define ABMON_1 10035
+# define ABMON_2 (ABMON_1 + 1)
+# define ABMON_3 (ABMON_1 + 2)
+# define ABMON_4 (ABMON_1 + 3)
+# define ABMON_5 (ABMON_1 + 4)
+# define ABMON_6 (ABMON_1 + 5)
+# define ABMON_7 (ABMON_1 + 6)
+# define ABMON_8 (ABMON_1 + 7)
+# define ABMON_9 (ABMON_1 + 8)
+# define ABMON_10 (ABMON_1 + 9)
+# define ABMON_11 (ABMON_1 + 10)
+# define ABMON_12 (ABMON_1 + 11)
+# define ERA 10047
+# define ERA_D_FMT 10048
+# define ERA_D_T_FMT 10049
+# define ERA_T_FMT 10050
+# define ALT_DIGITS 10051
+/* nl_langinfo items of the LC_MONETARY category */
+# define CRNCYSTR 10052
+/* nl_langinfo items of the LC_MESSAGES category */
+# define YESEXPR 10053
+# define NOEXPR 10054
+
+#else
+
+/* A platform that has <langinfo.h>. */
+
+# if !@HAVE_LANGINFO_CODESET@
+# define CODESET 10000
+# define GNULIB_defined_CODESET 1
+# endif
+
+# if !@HAVE_LANGINFO_T_FMT_AMPM@
+# define T_FMT_AMPM 10006
+# define GNULIB_defined_T_FMT_AMPM 1
+# endif
+
+# if !@HAVE_LANGINFO_ERA@
+# define ERA 10047
+# define ERA_D_FMT 10048
+# define ERA_D_T_FMT 10049
+# define ERA_T_FMT 10050
+# define ALT_DIGITS 10051
+# define GNULIB_defined_ERA 1
+# endif
+
+# if !@HAVE_LANGINFO_YESEXPR@
+# define YESEXPR 10053
+# define NOEXPR 10054
+# define GNULIB_defined_YESEXPR 1
+# endif
+
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+
+/* Declare overridden functions. */
+
+
+/* Return a piece of locale dependent information.
+ Note: The difference between nl_langinfo (CODESET) and locale_charset ()
+ is that the latter normalizes the encoding names to GNU conventions. */
+
+#if @GNULIB_NL_LANGINFO@
+# if @REPLACE_NL_LANGINFO@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef nl_langinfo
+# define nl_langinfo rpl_nl_langinfo
+# endif
+_GL_FUNCDECL_RPL (nl_langinfo, char *, (nl_item item));
+_GL_CXXALIAS_RPL (nl_langinfo, char *, (nl_item item));
+# else
+# if !@HAVE_NL_LANGINFO@
+_GL_FUNCDECL_SYS (nl_langinfo, char *, (nl_item item));
+# endif
+_GL_CXXALIAS_SYS (nl_langinfo, char *, (nl_item item));
+# endif
+_GL_CXXALIASWARN (nl_langinfo);
+#elif defined GNULIB_POSIXCHECK
+# undef nl_langinfo
+# if HAVE_RAW_DECL_NL_LANGINFO
+_GL_WARN_ON_USE (nl_langinfo, "nl_langinfo is not portable - "
+ "use gnulib module nl_langinfo for portability");
+# endif
+#endif
+
+
+#endif /* _@GUARD_PREFIX@_LANGINFO_H */
+#endif /* _@GUARD_PREFIX@_LANGINFO_H */
diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c
new file mode 100644
index 000000000..05fb14847
--- /dev/null
+++ b/lib/mbrtowc.c
@@ -0,0 +1,396 @@
+/* Convert multibyte character to wide character.
+ Copyright (C) 1999-2002, 2005-2012 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+#if GNULIB_defined_mbstate_t
+/* Implement mbrtowc() on top of mbtowc(). */
+
+# include <errno.h>
+# include <stdlib.h>
+
+# include "localcharset.h"
+# include "streq.h"
+# include "verify.h"
+
+
+verify (sizeof (mbstate_t) >= 4);
+
+static char internal_state[4];
+
+size_t
+mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+ char *pstate = (char *)ps;
+
+ if (s == NULL)
+ {
+ pwc = NULL;
+ s = "";
+ n = 1;
+ }
+
+ if (n == 0)
+ return (size_t)(-2);
+
+ /* Here n > 0. */
+
+ if (pstate == NULL)
+ pstate = internal_state;
+
+ {
+ size_t nstate = pstate[0];
+ char buf[4];
+ const char *p;
+ size_t m;
+
+ switch (nstate)
+ {
+ case 0:
+ p = s;
+ m = n;
+ break;
+ case 3:
+ buf[2] = pstate[3];
+ /*FALLTHROUGH*/
+ case 2:
+ buf[1] = pstate[2];
+ /*FALLTHROUGH*/
+ case 1:
+ buf[0] = pstate[1];
+ p = buf;
+ m = nstate;
+ buf[m++] = s[0];
+ if (n >= 2 && m < 4)
+ {
+ buf[m++] = s[1];
+ if (n >= 3 && m < 4)
+ buf[m++] = s[2];
+ }
+ break;
+ default:
+ errno = EINVAL;
+ return (size_t)(-1);
+ }
+
+ /* Here m > 0. */
+
+# if __GLIBC__ || defined __UCLIBC__
+ /* Work around bug <http://sourceware.org/bugzilla/show_bug.cgi?id=9674> */
+ mbtowc (NULL, NULL, 0);
+# endif
+ {
+ int res = mbtowc (pwc, p, m);
+
+ if (res >= 0)
+ {
+ if (pwc != NULL && ((*pwc == 0) != (res == 0)))
+ abort ();
+ if (nstate >= (res > 0 ? res : 1))
+ abort ();
+ res -= nstate;
+ pstate[0] = 0;
+ return res;
+ }
+
+ /* mbtowc does not distinguish between invalid and incomplete multibyte
+ sequences. But mbrtowc needs to make this distinction.
+ There are two possible approaches:
+ - Use iconv() and its return value.
+ - Use built-in knowledge about the possible encodings.
+ Given the low quality of implementation of iconv() on the systems that
+ lack mbrtowc(), we use the second approach.
+ The possible encodings are:
+ - 8-bit encodings,
+ - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS,
+ - UTF-8.
+ Use specialized code for each. */
+ if (m >= 4 || m >= MB_CUR_MAX)
+ goto invalid;
+ /* Here MB_CUR_MAX > 1 and 0 < m < 4. */
+ {
+ const char *encoding = locale_charset ();
+
+ if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0))
+ {
+ /* Cf. unistr/u8-mblen.c. */
+ unsigned char c = (unsigned char) p[0];
+
+ if (c >= 0xc2)
+ {
+ if (c < 0xe0)
+ {
+ if (m == 1)
+ goto incomplete;
+ }
+ else if (c < 0xf0)
+ {
+ if (m == 1)
+ goto incomplete;
+ if (m == 2)
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if ((c2 ^ 0x80) < 0x40
+ && (c >= 0xe1 || c2 >= 0xa0)
+ && (c != 0xed || c2 < 0xa0))
+ goto incomplete;
+ }
+ }
+ else if (c <= 0xf4)
+ {
+ if (m == 1)
+ goto incomplete;
+ else /* m == 2 || m == 3 */
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if ((c2 ^ 0x80) < 0x40
+ && (c >= 0xf1 || c2 >= 0x90)
+ && (c < 0xf4 || (c == 0xf4 && c2 < 0x90)))
+ {
+ if (m == 2)
+ goto incomplete;
+ else /* m == 3 */
+ {
+ unsigned char c3 = (unsigned char) p[2];
+
+ if ((c3 ^ 0x80) < 0x40)
+ goto incomplete;
+ }
+ }
+ }
+ }
+ }
+ goto invalid;
+ }
+
+ /* As a reference for this code, you can use the GNU libiconv
+ implementation. Look for uses of the RET_TOOFEW macro. */
+
+ if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f)
+ goto incomplete;
+ }
+ if (m == 2)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c == 0x8f)
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if (c2 >= 0xa1 && c2 < 0xff)
+ goto incomplete;
+ }
+ }
+ goto invalid;
+ }
+ if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+ || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0)
+ || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c >= 0xa1 && c < 0xff)
+ goto incomplete;
+ }
+ goto invalid;
+ }
+ if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0xa1 && c < 0xff) || c == 0x8e)
+ goto incomplete;
+ }
+ else /* m == 2 || m == 3 */
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c == 0x8e)
+ goto incomplete;
+ }
+ goto invalid;
+ }
+ if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe))
+ goto incomplete;
+ }
+ else /* m == 2 || m == 3 */
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if (c >= 0x90 && c <= 0xe3)
+ {
+ unsigned char c2 = (unsigned char) p[1];
+
+ if (c2 >= 0x30 && c2 <= 0x39)
+ {
+ if (m == 2)
+ goto incomplete;
+ else /* m == 3 */
+ {
+ unsigned char c3 = (unsigned char) p[2];
+
+ if (c3 >= 0x81 && c3 <= 0xfe)
+ goto incomplete;
+ }
+ }
+ }
+ }
+ goto invalid;
+ }
+ if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0))
+ {
+ if (m == 1)
+ {
+ unsigned char c = (unsigned char) p[0];
+
+ if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)
+ || (c >= 0xf0 && c <= 0xf9))
+ goto incomplete;
+ }
+ goto invalid;
+ }
+
+ /* An unknown multibyte encoding. */
+ goto incomplete;
+ }
+
+ incomplete:
+ {
+ size_t k = nstate;
+ /* Here 0 <= k < m < 4. */
+ pstate[++k] = s[0];
+ if (k < m)
+ {
+ pstate[++k] = s[1];
+ if (k < m)
+ pstate[++k] = s[2];
+ }
+ if (k != m)
+ abort ();
+ }
+ pstate[0] = m;
+ return (size_t)(-2);
+
+ invalid:
+ errno = EILSEQ;
+ /* The conversion state is undefined, says POSIX. */
+ return (size_t)(-1);
+ }
+ }
+}
+
+#else
+/* Override the system's mbrtowc() function. */
+
+# undef mbrtowc
+
+size_t
+rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+# if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG
+ if (s == NULL)
+ {
+ pwc = NULL;
+ s = "";
+ n = 1;
+ }
+# endif
+
+# if MBRTOWC_RETVAL_BUG
+ {
+ static mbstate_t internal_state;
+
+ /* Override mbrtowc's internal state. We cannot call mbsinit() on the
+ hidden internal state, but we can call it on our variable. */
+ if (ps == NULL)
+ ps = &internal_state;
+
+ if (!mbsinit (ps))
+ {
+ /* Parse the rest of the multibyte character byte for byte. */
+ size_t count = 0;
+ for (; n > 0; s++, n--)
+ {
+ wchar_t wc;
+ size_t ret = mbrtowc (&wc, s, 1, ps);
+
+ if (ret == (size_t)(-1))
+ return (size_t)(-1);
+ count++;
+ if (ret != (size_t)(-2))
+ {
+ /* The multibyte character has been completed. */
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == 0 ? 0 : count);
+ }
+ }
+ return (size_t)(-2);
+ }
+ }
+# endif
+
+# if MBRTOWC_NUL_RETVAL_BUG
+ {
+ wchar_t wc;
+ size_t ret = mbrtowc (&wc, s, n, ps);
+
+ if (ret != (size_t)(-1) && ret != (size_t)(-2))
+ {
+ if (pwc != NULL)
+ *pwc = wc;
+ if (wc == 0)
+ ret = 0;
+ }
+ return ret;
+ }
+# else
+ {
+# if MBRTOWC_NULL_ARG1_BUG
+ wchar_t dummy;
+
+ if (pwc == NULL)
+ pwc = &dummy;
+# endif
+
+ return mbrtowc (pwc, s, n, ps);
+ }
+# endif
+}
+
+#endif
diff --git a/lib/mbsinit.c b/lib/mbsinit.c
new file mode 100644
index 000000000..79278d452
--- /dev/null
+++ b/lib/mbsinit.c
@@ -0,0 +1,61 @@
+/* Test for initial conversion state.
+ Copyright (C) 2008-2012 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+#include "verify.h"
+
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+
+/* On native Windows, 'mbstate_t' is defined as 'int'. */
+
+int
+mbsinit (const mbstate_t *ps)
+{
+ return ps == NULL || *ps == 0;
+}
+
+#else
+
+/* Platforms that lack mbsinit() also lack mbrlen(), mbrtowc(), mbsrtowcs()
+ and wcrtomb(), wcsrtombs().
+ We assume that
+ - sizeof (mbstate_t) >= 4,
+ - only stateless encodings are supported (such as UTF-8 and EUC-JP, but
+ not ISO-2022 variants),
+ - for each encoding, the number of bytes for a wide character is <= 4.
+ (This maximum is attained for UTF-8, GB18030, EUC-TW.)
+ We define the meaning of mbstate_t as follows:
+ - In mb -> wc direction, mbstate_t's first byte contains the number of
+ buffered bytes (in the range 0..3), followed by up to 3 buffered bytes.
+ - In wc -> mb direction, mbstate_t contains no information. In other
+ words, it is always in the initial state. */
+
+verify (sizeof (mbstate_t) >= 4);
+
+int
+mbsinit (const mbstate_t *ps)
+{
+ const char *pstate = (const char *)ps;
+
+ return pstate == NULL || pstate[0] == 0;
+}
+
+#endif
diff --git a/lib/mbtowc-impl.h b/lib/mbtowc-impl.h
new file mode 100644
index 000000000..3183f918a
--- /dev/null
+++ b/lib/mbtowc-impl.h
@@ -0,0 +1,44 @@
+/* Convert multibyte character to wide character.
+ Copyright (C) 2011-2012 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* We don't need a static internal state, because the encoding is not state
+ dependent, and when mbrtowc returns (size_t)(-2). we throw the result
+ away. */
+
+int
+mbtowc (wchar_t *pwc, const char *s, size_t n)
+{
+ if (s == NULL)
+ return 0;
+ else
+ {
+ mbstate_t state;
+ wchar_t wc;
+ size_t result;
+
+ memset (&state, 0, sizeof (mbstate_t));
+ result = mbrtowc (&wc, s, n, &state);
+ if (result == (size_t)-1 || result == (size_t)-2)
+ {
+ errno = EILSEQ;
+ return -1;
+ }
+ if (pwc != NULL)
+ *pwc = wc;
+ return (wc == 0 ? 0 : result);
+ }
+}
diff --git a/lib/mbtowc.c b/lib/mbtowc.c
new file mode 100644
index 000000000..e48b2f276
--- /dev/null
+++ b/lib/mbtowc.c
@@ -0,0 +1,26 @@
+/* Convert multibyte character to wide character.
+ Copyright (C) 2011-2012 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2011.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#include <errno.h>
+#include <string.h>
+#include <wchar.h>
+
+#include "mbtowc-impl.h"
diff --git a/lib/nl_langinfo.c b/lib/nl_langinfo.c
new file mode 100644
index 000000000..4b9bdbe1b
--- /dev/null
+++ b/lib/nl_langinfo.c
@@ -0,0 +1,271 @@
+/* nl_langinfo() replacement: query locale dependent information.
+
+ Copyright (C) 2007-2012 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <langinfo.h>
+
+#if REPLACE_NL_LANGINFO
+
+/* Override nl_langinfo with support for added nl_item values. */
+
+# include <locale.h>
+# include <string.h>
+
+# undef nl_langinfo
+
+char *
+rpl_nl_langinfo (nl_item item)
+{
+ switch (item)
+ {
+# if GNULIB_defined_CODESET
+ case CODESET:
+ {
+ const char *locale;
+ static char buf[2 + 10 + 1];
+
+ locale = setlocale (LC_CTYPE, NULL);
+ if (locale != NULL && locale[0] != '\0')
+ {
+ /* If the locale name contains an encoding after the dot, return
+ it. */
+ const char *dot = strchr (locale, '.');
+
+ if (dot != NULL)
+ {
+ const char *modifier;
+
+ dot++;
+ /* Look for the possible @... trailer and remove it, if any. */
+ modifier = strchr (dot, '@');
+ if (modifier == NULL)
+ return dot;
+ if (modifier - dot < sizeof (buf))
+ {
+ memcpy (buf, dot, modifier - dot);
+ buf [modifier - dot] = '\0';
+ return buf;
+ }
+ }
+ }
+ return "";
+ }
+# endif
+# if GNULIB_defined_T_FMT_AMPM
+ case T_FMT_AMPM:
+ return "%I:%M:%S %p";
+# endif
+# if GNULIB_defined_ERA
+ case ERA:
+ /* The format is not standardized. In glibc it is a sequence of strings
+ of the form "direction:offset:start_date:end_date:era_name:era_format"
+ with an empty string at the end. */
+ return "";
+ case ERA_D_FMT:
+ /* The %Ex conversion in strftime behaves like %x if the locale does not
+ have an alternative time format. */
+ item = D_FMT;
+ break;
+ case ERA_D_T_FMT:
+ /* The %Ec conversion in strftime behaves like %c if the locale does not
+ have an alternative time format. */
+ item = D_T_FMT;
+ break;
+ case ERA_T_FMT:
+ /* The %EX conversion in strftime behaves like %X if the locale does not
+ have an alternative time format. */
+ item = T_FMT;
+ break;
+ case ALT_DIGITS:
+ /* The format is not standardized. In glibc it is a sequence of 10
+ strings, appended in memory. */
+ return "\0\0\0\0\0\0\0\0\0\0";
+# endif
+# if GNULIB_defined_YESEXPR || !FUNC_NL_LANGINFO_YESEXPR_WORKS
+ case YESEXPR:
+ return "^[yY]";
+ case NOEXPR:
+ return "^[nN]";
+# endif
+ default:
+ break;
+ }
+ return nl_langinfo (item);
+}
+
+#else
+
+/* Provide nl_langinfo from scratch. */
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Native Windows platforms. */
+
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+
+# include <stdio.h>
+
+# else
+
+/* An old Unix platform without locales, such as Linux libc5 or BeOS. */
+
+# endif
+
+# include <locale.h>
+
+char *
+nl_langinfo (nl_item item)
+{
+ switch (item)
+ {
+ /* nl_langinfo items of the LC_CTYPE category */
+ case CODESET:
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+ {
+ static char buf[2 + 10 + 1];
+
+ /* The Windows API has a function returning the locale's codepage as
+ a number. */
+ sprintf (buf, "CP%u", GetACP ());
+ return buf;
+ }
+# elif defined __BEOS__
+ return "UTF-8";
+# else
+ return "ISO-8859-1";
+# endif
+ /* nl_langinfo items of the LC_NUMERIC category */
+ case RADIXCHAR:
+ return localeconv () ->decimal_point;
+ case THOUSEP:
+ return localeconv () ->thousands_sep;
+ /* nl_langinfo items of the LC_TIME category.
+ TODO: Really use the locale. */
+ case D_T_FMT:
+ case ERA_D_T_FMT:
+ return "%a %b %e %H:%M:%S %Y";
+ case D_FMT:
+ case ERA_D_FMT:
+ return "%m/%d/%y";
+ case T_FMT:
+ case ERA_T_FMT:
+ return "%H:%M:%S";
+ case T_FMT_AMPM:
+ return "%I:%M:%S %p";
+ case AM_STR:
+ return "AM";
+ case PM_STR:
+ return "PM";
+ case DAY_1:
+ return "Sunday";
+ case DAY_2:
+ return "Monday";
+ case DAY_3:
+ return "Tuesday";
+ case DAY_4:
+ return "Wednesday";
+ case DAY_5:
+ return "Thursday";
+ case DAY_6:
+ return "Friday";
+ case DAY_7:
+ return "Saturday";
+ case ABDAY_1:
+ return "Sun";
+ case ABDAY_2:
+ return "Mon";
+ case ABDAY_3:
+ return "Tue";
+ case ABDAY_4:
+ return "Wed";
+ case ABDAY_5:
+ return "Thu";
+ case ABDAY_6:
+ return "Fri";
+ case ABDAY_7:
+ return "Sat";
+ case MON_1:
+ return "January";
+ case MON_2:
+ return "February";
+ case MON_3:
+ return "March";
+ case MON_4:
+ return "April";
+ case MON_5:
+ return "May";
+ case MON_6:
+ return "June";
+ case MON_7:
+ return "July";
+ case MON_8:
+ return "August";
+ case MON_9:
+ return "September";
+ case MON_10:
+ return "October";
+ case MON_11:
+ return "November";
+ case MON_12:
+ return "December";
+ case ABMON_1:
+ return "Jan";
+ case ABMON_2:
+ return "Feb";
+ case ABMON_3:
+ return "Mar";
+ case ABMON_4:
+ return "Apr";
+ case ABMON_5:
+ return "May";
+ case ABMON_6:
+ return "Jun";
+ case ABMON_7:
+ return "Jul";
+ case ABMON_8:
+ return "Aug";
+ case ABMON_9:
+ return "Sep";
+ case ABMON_10:
+ return "Oct";
+ case ABMON_11:
+ return "Nov";
+ case ABMON_12:
+ return "Dec";
+ case ERA:
+ return "";
+ case ALT_DIGITS:
+ return "\0\0\0\0\0\0\0\0\0\0";
+ /* nl_langinfo items of the LC_MONETARY category
+ TODO: Really use the locale. */
+ case CRNCYSTR:
+ return "-";
+ /* nl_langinfo items of the LC_MESSAGES category
+ TODO: Really use the locale. */
+ case YESEXPR:
+ return "^[yY]";
+ case NOEXPR:
+ return "^[nN]";
+ default:
+ return "";
+ }
+}
+
+#endif
diff --git a/lib/regcomp.c b/lib/regcomp.c
new file mode 100644
index 000000000..ac1330779
--- /dev/null
+++ b/lib/regcomp.c
@@ -0,0 +1,3876 @@
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern,
+ size_t length, reg_syntax_t syntax);
+static void re_compile_fastmap_iter (regex_t *bufp,
+ const re_dfastate_t *init_state,
+ char *fastmap);
+static reg_errcode_t init_dfa (re_dfa_t *dfa, size_t pat_len);
+#ifdef RE_ENABLE_I18N
+static void free_charset (re_charset_t *cset);
+#endif /* RE_ENABLE_I18N */
+static void free_workarea_compile (regex_t *preg);
+static reg_errcode_t create_initial_state (re_dfa_t *dfa);
+#ifdef RE_ENABLE_I18N
+static void optimize_utf8 (re_dfa_t *dfa);
+#endif
+static reg_errcode_t analyze (regex_t *preg);
+static reg_errcode_t preorder (bin_tree_t *root,
+ reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra);
+static reg_errcode_t postorder (bin_tree_t *root,
+ reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra);
+static reg_errcode_t optimize_subexps (void *extra, bin_tree_t *node);
+static reg_errcode_t lower_subexps (void *extra, bin_tree_t *node);
+static bin_tree_t *lower_subexp (reg_errcode_t *err, regex_t *preg,
+ bin_tree_t *node);
+static reg_errcode_t calc_first (void *extra, bin_tree_t *node);
+static reg_errcode_t calc_next (void *extra, bin_tree_t *node);
+static reg_errcode_t link_nfa_nodes (void *extra, bin_tree_t *node);
+static Idx duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint);
+static Idx search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
+ unsigned int constraint);
+static reg_errcode_t calc_eclosure (re_dfa_t *dfa);
+static reg_errcode_t calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa,
+ Idx node, bool root);
+static reg_errcode_t calc_inveclosure (re_dfa_t *dfa);
+static Idx fetch_number (re_string_t *input, re_token_t *token,
+ reg_syntax_t syntax);
+static int peek_token (re_token_t *token, re_string_t *input,
+ reg_syntax_t syntax) internal_function;
+static bin_tree_t *parse (re_string_t *regexp, regex_t *preg,
+ reg_syntax_t syntax, reg_errcode_t *err);
+static bin_tree_t *parse_reg_exp (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_branch (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_expression (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_sub_exp (re_string_t *regexp, regex_t *preg,
+ re_token_t *token, reg_syntax_t syntax,
+ Idx nest, reg_errcode_t *err);
+static bin_tree_t *parse_dup_op (bin_tree_t *dup_elem, re_string_t *regexp,
+ re_dfa_t *dfa, re_token_t *token,
+ reg_syntax_t syntax, reg_errcode_t *err);
+static bin_tree_t *parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa,
+ re_token_t *token, reg_syntax_t syntax,
+ reg_errcode_t *err);
+static reg_errcode_t parse_bracket_element (bracket_elem_t *elem,
+ re_string_t *regexp,
+ re_token_t *token, int token_len,
+ re_dfa_t *dfa,
+ reg_syntax_t syntax,
+ bool accept_hyphen);
+static reg_errcode_t parse_bracket_symbol (bracket_elem_t *elem,
+ re_string_t *regexp,
+ re_token_t *token);
+#ifdef RE_ENABLE_I18N
+static reg_errcode_t build_equiv_class (bitset_t sbcset,
+ re_charset_t *mbcset,
+ Idx *equiv_class_alloc,
+ const unsigned char *name);
+static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
+ bitset_t sbcset,
+ re_charset_t *mbcset,
+ Idx *char_class_alloc,
+ const unsigned char *class_name,
+ reg_syntax_t syntax);
+#else /* not RE_ENABLE_I18N */
+static reg_errcode_t build_equiv_class (bitset_t sbcset,
+ const unsigned char *name);
+static reg_errcode_t build_charclass (RE_TRANSLATE_TYPE trans,
+ bitset_t sbcset,
+ const unsigned char *class_name,
+ reg_syntax_t syntax);
+#endif /* not RE_ENABLE_I18N */
+static bin_tree_t *build_charclass_op (re_dfa_t *dfa,
+ RE_TRANSLATE_TYPE trans,
+ const unsigned char *class_name,
+ const unsigned char *extra,
+ bool non_match, reg_errcode_t *err);
+static bin_tree_t *create_tree (re_dfa_t *dfa,
+ bin_tree_t *left, bin_tree_t *right,
+ re_token_type_t type);
+static bin_tree_t *create_token_tree (re_dfa_t *dfa,
+ bin_tree_t *left, bin_tree_t *right,
+ const re_token_t *token);
+static bin_tree_t *duplicate_tree (const bin_tree_t *src, re_dfa_t *dfa);
+static void free_token (re_token_t *node);
+static reg_errcode_t free_tree (void *extra, bin_tree_t *node);
+static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node);
+
+/* This table gives an error message for each of the error codes listed
+ in regex.h. Obviously the order here has to be same as there.
+ POSIX doesn't require that we do anything for REG_NOERROR,
+ but why not be nice? */
+
+static const char __re_error_msgid[] =
+ {
+#define REG_NOERROR_IDX 0
+ gettext_noop ("Success") /* REG_NOERROR */
+ "\0"
+#define REG_NOMATCH_IDX (REG_NOERROR_IDX + sizeof "Success")
+ gettext_noop ("No match") /* REG_NOMATCH */
+ "\0"
+#define REG_BADPAT_IDX (REG_NOMATCH_IDX + sizeof "No match")
+ gettext_noop ("Invalid regular expression") /* REG_BADPAT */
+ "\0"
+#define REG_ECOLLATE_IDX (REG_BADPAT_IDX + sizeof "Invalid regular expression")
+ gettext_noop ("Invalid collation character") /* REG_ECOLLATE */
+ "\0"
+#define REG_ECTYPE_IDX (REG_ECOLLATE_IDX + sizeof "Invalid collation character")
+ gettext_noop ("Invalid character class name") /* REG_ECTYPE */
+ "\0"
+#define REG_EESCAPE_IDX (REG_ECTYPE_IDX + sizeof "Invalid character class name")
+ gettext_noop ("Trailing backslash") /* REG_EESCAPE */
+ "\0"
+#define REG_ESUBREG_IDX (REG_EESCAPE_IDX + sizeof "Trailing backslash")
+ gettext_noop ("Invalid back reference") /* REG_ESUBREG */
+ "\0"
+#define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference")
+ gettext_noop ("Unmatched [ or [^") /* REG_EBRACK */
+ "\0"
+#define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^")
+ gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */
+ "\0"
+#define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(")
+ gettext_noop ("Unmatched \\{") /* REG_EBRACE */
+ "\0"
+#define REG_BADBR_IDX (REG_EBRACE_IDX + sizeof "Unmatched \\{")
+ gettext_noop ("Invalid content of \\{\\}") /* REG_BADBR */
+ "\0"
+#define REG_ERANGE_IDX (REG_BADBR_IDX + sizeof "Invalid content of \\{\\}")
+ gettext_noop ("Invalid range end") /* REG_ERANGE */
+ "\0"
+#define REG_ESPACE_IDX (REG_ERANGE_IDX + sizeof "Invalid range end")
+ gettext_noop ("Memory exhausted") /* REG_ESPACE */
+ "\0"
+#define REG_BADRPT_IDX (REG_ESPACE_IDX + sizeof "Memory exhausted")
+ gettext_noop ("Invalid preceding regular expression") /* REG_BADRPT */
+ "\0"
+#define REG_EEND_IDX (REG_BADRPT_IDX + sizeof "Invalid preceding regular expression")
+ gettext_noop ("Premature end of regular expression") /* REG_EEND */
+ "\0"
+#define REG_ESIZE_IDX (REG_EEND_IDX + sizeof "Premature end of regular expression")
+ gettext_noop ("Regular expression too big") /* REG_ESIZE */
+ "\0"
+#define REG_ERPAREN_IDX (REG_ESIZE_IDX + sizeof "Regular expression too big")
+ gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */
+ };
+
+static const size_t __re_error_msgid_idx[] =
+ {
+ REG_NOERROR_IDX,
+ REG_NOMATCH_IDX,
+ REG_BADPAT_IDX,
+ REG_ECOLLATE_IDX,
+ REG_ECTYPE_IDX,
+ REG_EESCAPE_IDX,
+ REG_ESUBREG_IDX,
+ REG_EBRACK_IDX,
+ REG_EPAREN_IDX,
+ REG_EBRACE_IDX,
+ REG_BADBR_IDX,
+ REG_ERANGE_IDX,
+ REG_ESPACE_IDX,
+ REG_BADRPT_IDX,
+ REG_EEND_IDX,
+ REG_ESIZE_IDX,
+ REG_ERPAREN_IDX
+ };
+
+/* Entry points for GNU code. */
+
+/* re_compile_pattern is the GNU regular expression compiler: it
+ compiles PATTERN (of length LENGTH) and puts the result in BUFP.
+ Returns 0 if the pattern was valid, otherwise an error string.
+
+ Assumes the 'allocated' (and perhaps 'buffer') and 'translate' fields
+ are set in BUFP on entry. */
+
+#ifdef _LIBC
+const char *
+re_compile_pattern (pattern, length, bufp)
+ const char *pattern;
+ size_t length;
+ struct re_pattern_buffer *bufp;
+#else /* size_t might promote */
+const char *
+re_compile_pattern (const char *pattern, size_t length,
+ struct re_pattern_buffer *bufp)
+#endif
+{
+ reg_errcode_t ret;
+
+ /* And GNU code determines whether or not to get register information
+ by passing null for the REGS argument to re_match, etc., not by
+ setting no_sub, unless RE_NO_SUB is set. */
+ bufp->no_sub = !!(re_syntax_options & RE_NO_SUB);
+
+ /* Match anchors at newline. */
+ bufp->newline_anchor = 1;
+
+ ret = re_compile_internal (bufp, pattern, length, re_syntax_options);
+
+ if (!ret)
+ return NULL;
+ return gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
+}
+#ifdef _LIBC
+weak_alias (__re_compile_pattern, re_compile_pattern)
+#endif
+
+/* Set by 're_set_syntax' to the current regexp syntax to recognize. Can
+ also be assigned to arbitrarily: each pattern buffer stores its own
+ syntax, so it can be changed between regex compilations. */
+/* This has no initializer because initialized variables in Emacs
+ become read-only after dumping. */
+reg_syntax_t re_syntax_options;
+
+
+/* Specify the precise syntax of regexps for compilation. This provides
+ for compatibility for various utilities which historically have
+ different, incompatible syntaxes.
+
+ The argument SYNTAX is a bit mask comprised of the various bits
+ defined in regex.h. We return the old syntax. */
+
+reg_syntax_t
+re_set_syntax (syntax)
+ reg_syntax_t syntax;
+{
+ reg_syntax_t ret = re_syntax_options;
+
+ re_syntax_options = syntax;
+ return ret;
+}
+#ifdef _LIBC
+weak_alias (__re_set_syntax, re_set_syntax)
+#endif
+
+int
+re_compile_fastmap (bufp)
+ struct re_pattern_buffer *bufp;
+{
+ re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
+ char *fastmap = bufp->fastmap;
+
+ memset (fastmap, '\0', sizeof (char) * SBC_MAX);
+ re_compile_fastmap_iter (bufp, dfa->init_state, fastmap);
+ if (dfa->init_state != dfa->init_state_word)
+ re_compile_fastmap_iter (bufp, dfa->init_state_word, fastmap);
+ if (dfa->init_state != dfa->init_state_nl)
+ re_compile_fastmap_iter (bufp, dfa->init_state_nl, fastmap);
+ if (dfa->init_state != dfa->init_state_begbuf)
+ re_compile_fastmap_iter (bufp, dfa->init_state_begbuf, fastmap);
+ bufp->fastmap_accurate = 1;
+ return 0;
+}
+#ifdef _LIBC
+weak_alias (__re_compile_fastmap, re_compile_fastmap)
+#endif
+
+static inline void
+__attribute ((always_inline))
+re_set_fastmap (char *fastmap, bool icase, int ch)
+{
+ fastmap[ch] = 1;
+ if (icase)
+ fastmap[tolower (ch)] = 1;
+}
+
+/* Helper function for re_compile_fastmap.
+ Compile fastmap for the initial_state INIT_STATE. */
+
+static void
+re_compile_fastmap_iter (regex_t *bufp, const re_dfastate_t *init_state,
+ char *fastmap)
+{
+ re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
+ Idx node_cnt;
+ bool icase = (dfa->mb_cur_max == 1 && (bufp->syntax & RE_ICASE));
+ for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt)
+ {
+ Idx node = init_state->nodes.elems[node_cnt];
+ re_token_type_t type = dfa->nodes[node].type;
+
+ if (type == CHARACTER)
+ {
+ re_set_fastmap (fastmap, icase, dfa->nodes[node].opr.c);
+#ifdef RE_ENABLE_I18N
+ if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
+ {
+ unsigned char buf[MB_LEN_MAX];
+ unsigned char *p;
+ wchar_t wc;
+ mbstate_t state;
+
+ p = buf;
+ *p++ = dfa->nodes[node].opr.c;
+ while (++node < dfa->nodes_len
+ && dfa->nodes[node].type == CHARACTER
+ && dfa->nodes[node].mb_partial)
+ *p++ = dfa->nodes[node].opr.c;
+ memset (&state, '\0', sizeof (state));
+ if (__mbrtowc (&wc, (const char *) buf, p - buf,
+ &state) == p - buf
+ && (__wcrtomb ((char *) buf, towlower (wc), &state)
+ != (size_t) -1))
+ re_set_fastmap (fastmap, false, buf[0]);
+ }
+#endif
+ }
+ else if (type == SIMPLE_BRACKET)
+ {
+ int i, ch;
+ for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
+ {
+ int j;
+ bitset_word_t w = dfa->nodes[node].opr.sbcset[i];
+ for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+ if (w & ((bitset_word_t) 1 << j))
+ re_set_fastmap (fastmap, icase, ch);
+ }
+ }
+#ifdef RE_ENABLE_I18N
+ else if (type == COMPLEX_BRACKET)
+ {
+ re_charset_t *cset = dfa->nodes[node].opr.mbcset;
+ Idx i;
+
+# ifdef _LIBC
+ /* See if we have to try all bytes which start multiple collation
+ elements.
+ e.g. In da_DK, we want to catch 'a' since "aa" is a valid
+ collation element, and don't catch 'b' since 'b' is
+ the only collation element which starts from 'b' (and
+ it is caught by SIMPLE_BRACKET). */
+ if (_NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES) != 0
+ && (cset->ncoll_syms || cset->nranges))
+ {
+ const int32_t *table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ for (i = 0; i < SBC_MAX; ++i)
+ if (table[i] < 0)
+ re_set_fastmap (fastmap, icase, i);
+ }
+# endif /* _LIBC */
+
+ /* See if we have to start the match at all multibyte characters,
+ i.e. where we would not find an invalid sequence. This only
+ applies to multibyte character sets; for single byte character
+ sets, the SIMPLE_BRACKET again suffices. */
+ if (dfa->mb_cur_max > 1
+ && (cset->nchar_classes || cset->non_match || cset->nranges
+# ifdef _LIBC
+ || cset->nequiv_classes
+# endif /* _LIBC */
+ ))
+ {
+ unsigned char c = 0;
+ do
+ {
+ mbstate_t mbs;
+ memset (&mbs, 0, sizeof (mbs));
+ if (__mbrtowc (NULL, (char *) &c, 1, &mbs) == (size_t) -2)
+ re_set_fastmap (fastmap, false, (int) c);
+ }
+ while (++c != 0);
+ }
+
+ else
+ {
+ /* ... Else catch all bytes which can start the mbchars. */
+ for (i = 0; i < cset->nmbchars; ++i)
+ {
+ char buf[256];
+ mbstate_t state;
+ memset (&state, '\0', sizeof (state));
+ if (__wcrtomb (buf, cset->mbchars[i], &state) != (size_t) -1)
+ re_set_fastmap (fastmap, icase, *(unsigned char *) buf);
+ if ((bufp->syntax & RE_ICASE) && dfa->mb_cur_max > 1)
+ {
+ if (__wcrtomb (buf, towlower (cset->mbchars[i]), &state)
+ != (size_t) -1)
+ re_set_fastmap (fastmap, false, *(unsigned char *) buf);
+ }
+ }
+ }
+ }
+#endif /* RE_ENABLE_I18N */
+ else if (type == OP_PERIOD
+#ifdef RE_ENABLE_I18N
+ || type == OP_UTF8_PERIOD
+#endif /* RE_ENABLE_I18N */
+ || type == END_OF_RE)
+ {
+ memset (fastmap, '\1', sizeof (char) * SBC_MAX);
+ if (type == END_OF_RE)
+ bufp->can_be_null = 1;
+ return;
+ }
+ }
+}
+
+/* Entry point for POSIX code. */
+/* regcomp takes a regular expression as a string and compiles it.
+
+ PREG is a regex_t *. We do not expect any fields to be initialized,
+ since POSIX says we shouldn't. Thus, we set
+
+ 'buffer' to the compiled pattern;
+ 'used' to the length of the compiled pattern;
+ 'syntax' to RE_SYNTAX_POSIX_EXTENDED if the
+ REG_EXTENDED bit in CFLAGS is set; otherwise, to
+ RE_SYNTAX_POSIX_BASIC;
+ 'newline_anchor' to REG_NEWLINE being set in CFLAGS;
+ 'fastmap' to an allocated space for the fastmap;
+ 'fastmap_accurate' to zero;
+ 're_nsub' to the number of subexpressions in PATTERN.
+
+ PATTERN is the address of the pattern string.
+
+ CFLAGS is a series of bits which affect compilation.
+
+ If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we
+ use POSIX basic syntax.
+
+ If REG_NEWLINE is set, then . and [^...] don't match newline.
+ Also, regexec will try a match beginning after every newline.
+
+ If REG_ICASE is set, then we considers upper- and lowercase
+ versions of letters to be equivalent when matching.
+
+ If REG_NOSUB is set, then when PREG is passed to regexec, that
+ routine will report only success or failure, and nothing about the
+ registers.
+
+ It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for
+ the return codes and their meanings.) */
+
+int
+regcomp (preg, pattern, cflags)
+ regex_t *_Restrict_ preg;
+ const char *_Restrict_ pattern;
+ int cflags;
+{
+ reg_errcode_t ret;
+ reg_syntax_t syntax = ((cflags & REG_EXTENDED) ? RE_SYNTAX_POSIX_EXTENDED
+ : RE_SYNTAX_POSIX_BASIC);
+
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ preg->used = 0;
+
+ /* Try to allocate space for the fastmap. */
+ preg->fastmap = re_malloc (char, SBC_MAX);
+ if (BE (preg->fastmap == NULL, 0))
+ return REG_ESPACE;
+
+ syntax |= (cflags & REG_ICASE) ? RE_ICASE : 0;
+
+ /* If REG_NEWLINE is set, newlines are treated differently. */
+ if (cflags & REG_NEWLINE)
+ { /* REG_NEWLINE implies neither . nor [^...] match newline. */
+ syntax &= ~RE_DOT_NEWLINE;
+ syntax |= RE_HAT_LISTS_NOT_NEWLINE;
+ /* It also changes the matching behavior. */
+ preg->newline_anchor = 1;
+ }
+ else
+ preg->newline_anchor = 0;
+ preg->no_sub = !!(cflags & REG_NOSUB);
+ preg->translate = NULL;
+
+ ret = re_compile_internal (preg, pattern, strlen (pattern), syntax);
+
+ /* POSIX doesn't distinguish between an unmatched open-group and an
+ unmatched close-group: both are REG_EPAREN. */
+ if (ret == REG_ERPAREN)
+ ret = REG_EPAREN;
+
+ /* We have already checked preg->fastmap != NULL. */
+ if (BE (ret == REG_NOERROR, 1))
+ /* Compute the fastmap now, since regexec cannot modify the pattern
+ buffer. This function never fails in this implementation. */
+ (void) re_compile_fastmap (preg);
+ else
+ {
+ /* Some error occurred while compiling the expression. */
+ re_free (preg->fastmap);
+ preg->fastmap = NULL;
+ }
+
+ return (int) ret;
+}
+#ifdef _LIBC
+weak_alias (__regcomp, regcomp)
+#endif
+
+/* Returns a message corresponding to an error code, ERRCODE, returned
+ from either regcomp or regexec. We don't use PREG here. */
+
+#ifdef _LIBC
+size_t
+regerror (errcode, preg, errbuf, errbuf_size)
+ int errcode;
+ const regex_t *_Restrict_ preg;
+ char *_Restrict_ errbuf;
+ size_t errbuf_size;
+#else /* size_t might promote */
+size_t
+regerror (int errcode, const regex_t *_Restrict_ preg,
+ char *_Restrict_ errbuf, size_t errbuf_size)
+#endif
+{
+ const char *msg;
+ size_t msg_size;
+
+ if (BE (errcode < 0
+ || errcode >= (int) (sizeof (__re_error_msgid_idx)
+ / sizeof (__re_error_msgid_idx[0])), 0))
+ /* Only error codes returned by the rest of the code should be passed
+ to this routine. If we are given anything else, or if other regex
+ code generates an invalid error code, then the program has a bug.
+ Dump core so we can fix it. */
+ abort ();
+
+ msg = gettext (__re_error_msgid + __re_error_msgid_idx[errcode]);
+
+ msg_size = strlen (msg) + 1; /* Includes the null. */
+
+ if (BE (errbuf_size != 0, 1))
+ {
+ size_t cpy_size = msg_size;
+ if (BE (msg_size > errbuf_size, 0))
+ {
+ cpy_size = errbuf_size - 1;
+ errbuf[cpy_size] = '\0';
+ }
+ memcpy (errbuf, msg, cpy_size);
+ }
+
+ return msg_size;
+}
+#ifdef _LIBC
+weak_alias (__regerror, regerror)
+#endif
+
+
+#ifdef RE_ENABLE_I18N
+/* This static array is used for the map to single-byte characters when
+ UTF-8 is used. Otherwise we would allocate memory just to initialize
+ it the same all the time. UTF-8 is the preferred encoding so this is
+ a worthwhile optimization. */
+static const bitset_t utf8_sb_map =
+{
+ /* Set the first 128 bits. */
+# if 4 * BITSET_WORD_BITS < ASCII_CHARS
+# error "bitset_word_t is narrower than 32 bits"
+# elif 3 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX, BITSET_WORD_MAX, BITSET_WORD_MAX,
+# elif 2 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX, BITSET_WORD_MAX,
+# elif 1 * BITSET_WORD_BITS < ASCII_CHARS
+ BITSET_WORD_MAX,
+# endif
+ (BITSET_WORD_MAX
+ >> (SBC_MAX % BITSET_WORD_BITS == 0
+ ? 0
+ : BITSET_WORD_BITS - SBC_MAX % BITSET_WORD_BITS))
+};
+#endif
+
+
+static void
+free_dfa_content (re_dfa_t *dfa)
+{
+ Idx i, j;
+
+ if (dfa->nodes)
+ for (i = 0; i < dfa->nodes_len; ++i)
+ free_token (dfa->nodes + i);
+ re_free (dfa->nexts);
+ for (i = 0; i < dfa->nodes_len; ++i)
+ {
+ if (dfa->eclosures != NULL)
+ re_node_set_free (dfa->eclosures + i);
+ if (dfa->inveclosures != NULL)
+ re_node_set_free (dfa->inveclosures + i);
+ if (dfa->edests != NULL)
+ re_node_set_free (dfa->edests + i);
+ }
+ re_free (dfa->edests);
+ re_free (dfa->eclosures);
+ re_free (dfa->inveclosures);
+ re_free (dfa->nodes);
+
+ if (dfa->state_table)
+ for (i = 0; i <= dfa->state_hash_mask; ++i)
+ {
+ struct re_state_table_entry *entry = dfa->state_table + i;
+ for (j = 0; j < entry->num; ++j)
+ {
+ re_dfastate_t *state = entry->array[j];
+ free_state (state);
+ }
+ re_free (entry->array);
+ }
+ re_free (dfa->state_table);
+#ifdef RE_ENABLE_I18N
+ if (dfa->sb_char != utf8_sb_map)
+ re_free (dfa->sb_char);
+#endif
+ re_free (dfa->subexp_map);
+#ifdef DEBUG
+ re_free (dfa->re_str);
+#endif
+
+ re_free (dfa);
+}
+
+
+/* Free dynamically allocated space used by PREG. */
+
+void
+regfree (preg)
+ regex_t *preg;
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ if (BE (dfa != NULL, 1))
+ free_dfa_content (dfa);
+ preg->buffer = NULL;
+ preg->allocated = 0;
+
+ re_free (preg->fastmap);
+ preg->fastmap = NULL;
+
+ re_free (preg->translate);
+ preg->translate = NULL;
+}
+#ifdef _LIBC
+weak_alias (__regfree, regfree)
+#endif
+
+/* Entry points compatible with 4.2 BSD regex library. We don't define
+ them unless specifically requested. */
+
+#if defined _REGEX_RE_COMP || defined _LIBC
+
+/* BSD has one and only one pattern buffer. */
+static struct re_pattern_buffer re_comp_buf;
+
+char *
+# ifdef _LIBC
+/* Make these definitions weak in libc, so POSIX programs can redefine
+ these names if they don't use our functions, and still use
+ regcomp/regexec above without link errors. */
+weak_function
+# endif
+re_comp (s)
+ const char *s;
+{
+ reg_errcode_t ret;
+ char *fastmap;
+
+ if (!s)
+ {
+ if (!re_comp_buf.buffer)
+ return gettext ("No previous regular expression");
+ return 0;
+ }
+
+ if (re_comp_buf.buffer)
+ {
+ fastmap = re_comp_buf.fastmap;
+ re_comp_buf.fastmap = NULL;
+ __regfree (&re_comp_buf);
+ memset (&re_comp_buf, '\0', sizeof (re_comp_buf));
+ re_comp_buf.fastmap = fastmap;
+ }
+
+ if (re_comp_buf.fastmap == NULL)
+ {
+ re_comp_buf.fastmap = (char *) malloc (SBC_MAX);
+ if (re_comp_buf.fastmap == NULL)
+ return (char *) gettext (__re_error_msgid
+ + __re_error_msgid_idx[(int) REG_ESPACE]);
+ }
+
+ /* Since 're_exec' always passes NULL for the 'regs' argument, we
+ don't need to initialize the pattern buffer fields which affect it. */
+
+ /* Match anchors at newlines. */
+ re_comp_buf.newline_anchor = 1;
+
+ ret = re_compile_internal (&re_comp_buf, s, strlen (s), re_syntax_options);
+
+ if (!ret)
+ return NULL;
+
+ /* Yes, we're discarding 'const' here if !HAVE_LIBINTL. */
+ return (char *) gettext (__re_error_msgid + __re_error_msgid_idx[(int) ret]);
+}
+
+#ifdef _LIBC
+libc_freeres_fn (free_mem)
+{
+ __regfree (&re_comp_buf);
+}
+#endif
+
+#endif /* _REGEX_RE_COMP */
+
+/* Internal entry point.
+ Compile the regular expression PATTERN, whose length is LENGTH.
+ SYNTAX indicate regular expression's syntax. */
+
+static reg_errcode_t
+re_compile_internal (regex_t *preg, const char * pattern, size_t length,
+ reg_syntax_t syntax)
+{
+ reg_errcode_t err = REG_NOERROR;
+ re_dfa_t *dfa;
+ re_string_t regexp;
+
+ /* Initialize the pattern buffer. */
+ preg->fastmap_accurate = 0;
+ preg->syntax = syntax;
+ preg->not_bol = preg->not_eol = 0;
+ preg->used = 0;
+ preg->re_nsub = 0;
+ preg->can_be_null = 0;
+ preg->regs_allocated = REGS_UNALLOCATED;
+
+ /* Initialize the dfa. */
+ dfa = (re_dfa_t *) preg->buffer;
+ if (BE (preg->allocated < sizeof (re_dfa_t), 0))
+ {
+ /* If zero allocated, but buffer is non-null, try to realloc
+ enough space. This loses if buffer's address is bogus, but
+ that is the user's responsibility. If ->buffer is NULL this
+ is a simple allocation. */
+ dfa = re_realloc (preg->buffer, re_dfa_t, 1);
+ if (dfa == NULL)
+ return REG_ESPACE;
+ preg->allocated = sizeof (re_dfa_t);
+ preg->buffer = (unsigned char *) dfa;
+ }
+ preg->used = sizeof (re_dfa_t);
+
+ err = init_dfa (dfa, length);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ free_dfa_content (dfa);
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ return err;
+ }
+#ifdef DEBUG
+ /* Note: length+1 will not overflow since it is checked in init_dfa. */
+ dfa->re_str = re_malloc (char, length + 1);
+ strncpy (dfa->re_str, pattern, length + 1);
+#endif
+
+ __libc_lock_init (dfa->lock);
+
+ err = re_string_construct (&regexp, pattern, length, preg->translate,
+ (syntax & RE_ICASE) != 0, dfa);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_compile_internal_free_return:
+ free_workarea_compile (preg);
+ re_string_destruct (&regexp);
+ free_dfa_content (dfa);
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ return err;
+ }
+
+ /* Parse the regular expression, and build a structure tree. */
+ preg->re_nsub = 0;
+ dfa->str_tree = parse (&regexp, preg, syntax, &err);
+ if (BE (dfa->str_tree == NULL, 0))
+ goto re_compile_internal_free_return;
+
+ /* Analyze the tree and create the nfa. */
+ err = analyze (preg);
+ if (BE (err != REG_NOERROR, 0))
+ goto re_compile_internal_free_return;
+
+#ifdef RE_ENABLE_I18N
+ /* If possible, do searching in single byte encoding to speed things up. */
+ if (dfa->is_utf8 && !(syntax & RE_ICASE) && preg->translate == NULL)
+ optimize_utf8 (dfa);
+#endif
+
+ /* Then create the initial state of the dfa. */
+ err = create_initial_state (dfa);
+
+ /* Release work areas. */
+ free_workarea_compile (preg);
+ re_string_destruct (&regexp);
+
+ if (BE (err != REG_NOERROR, 0))
+ {
+ free_dfa_content (dfa);
+ preg->buffer = NULL;
+ preg->allocated = 0;
+ }
+
+ return err;
+}
+
+/* Initialize DFA. We use the length of the regular expression PAT_LEN
+ as the initial length of some arrays. */
+
+static reg_errcode_t
+init_dfa (re_dfa_t *dfa, size_t pat_len)
+{
+ __re_size_t table_size;
+#ifndef _LIBC
+ char *codeset_name;
+#endif
+#ifdef RE_ENABLE_I18N
+ size_t max_i18n_object_size = MAX (sizeof (wchar_t), sizeof (wctype_t));
+#else
+ size_t max_i18n_object_size = 0;
+#endif
+ size_t max_object_size =
+ MAX (sizeof (struct re_state_table_entry),
+ MAX (sizeof (re_token_t),
+ MAX (sizeof (re_node_set),
+ MAX (sizeof (regmatch_t),
+ max_i18n_object_size))));
+
+ memset (dfa, '\0', sizeof (re_dfa_t));
+
+ /* Force allocation of str_tree_storage the first time. */
+ dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
+
+ /* Avoid overflows. The extra "/ 2" is for the table_size doubling
+ calculation below, and for similar doubling calculations
+ elsewhere. And it's <= rather than <, because some of the
+ doubling calculations add 1 afterwards. */
+ if (BE (SIZE_MAX / max_object_size / 2 <= pat_len, 0))
+ return REG_ESPACE;
+
+ dfa->nodes_alloc = pat_len + 1;
+ dfa->nodes = re_malloc (re_token_t, dfa->nodes_alloc);
+
+ /* table_size = 2 ^ ceil(log pat_len) */
+ for (table_size = 1; ; table_size <<= 1)
+ if (table_size > pat_len)
+ break;
+
+ dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
+ dfa->state_hash_mask = table_size - 1;
+
+ dfa->mb_cur_max = MB_CUR_MAX;
+#ifdef _LIBC
+ if (dfa->mb_cur_max == 6
+ && strcmp (_NL_CURRENT (LC_CTYPE, _NL_CTYPE_CODESET_NAME), "UTF-8") == 0)
+ dfa->is_utf8 = 1;
+ dfa->map_notascii = (_NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_MAP_TO_NONASCII)
+ != 0);
+#else
+ codeset_name = nl_langinfo (CODESET);
+ if (strcasecmp (codeset_name, "UTF-8") == 0
+ || strcasecmp (codeset_name, "UTF8") == 0)
+ dfa->is_utf8 = 1;
+
+ /* We check exhaustively in the loop below if this charset is a
+ superset of ASCII. */
+ dfa->map_notascii = 0;
+#endif
+
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ if (dfa->is_utf8)
+ dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map;
+ else
+ {
+ int i, j, ch;
+
+ dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
+ if (BE (dfa->sb_char == NULL, 0))
+ return REG_ESPACE;
+
+ /* Set the bits corresponding to single byte chars. */
+ for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
+ for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+ {
+ wint_t wch = __btowc (ch);
+ if (wch != WEOF)
+ dfa->sb_char[i] |= (bitset_word_t) 1 << j;
+# ifndef _LIBC
+ if (isascii (ch) && wch != ch)
+ dfa->map_notascii = 1;
+# endif
+ }
+ }
+ }
+#endif
+
+ if (BE (dfa->nodes == NULL || dfa->state_table == NULL, 0))
+ return REG_ESPACE;
+ return REG_NOERROR;
+}
+
+/* Initialize WORD_CHAR table, which indicate which character is
+ "word". In this case "word" means that it is the word construction
+ character used by some operators like "\<", "\>", etc. */
+
+static void
+internal_function
+init_word_char (re_dfa_t *dfa)
+{
+ int i, j, ch;
+ dfa->word_ops_used = 1;
+ for (i = 0, ch = 0; i < BITSET_WORDS; ++i)
+ for (j = 0; j < BITSET_WORD_BITS; ++j, ++ch)
+ if (isalnum (ch) || ch == '_')
+ dfa->word_char[i] |= (bitset_word_t) 1 << j;
+}
+
+/* Free the work area which are only used while compiling. */
+
+static void
+free_workarea_compile (regex_t *preg)
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ bin_tree_storage_t *storage, *next;
+ for (storage = dfa->str_tree_storage; storage; storage = next)
+ {
+ next = storage->next;
+ re_free (storage);
+ }
+ dfa->str_tree_storage = NULL;
+ dfa->str_tree_storage_idx = BIN_TREE_STORAGE_SIZE;
+ dfa->str_tree = NULL;
+ re_free (dfa->org_indices);
+ dfa->org_indices = NULL;
+}
+
+/* Create initial states for all contexts. */
+
+static reg_errcode_t
+create_initial_state (re_dfa_t *dfa)
+{
+ Idx first, i;
+ reg_errcode_t err;
+ re_node_set init_nodes;
+
+ /* Initial states have the epsilon closure of the node which is
+ the first node of the regular expression. */
+ first = dfa->str_tree->first->node_idx;
+ dfa->init_node = first;
+ err = re_node_set_init_copy (&init_nodes, dfa->eclosures + first);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* The back-references which are in initial states can epsilon transit,
+ since in this case all of the subexpressions can be null.
+ Then we add epsilon closures of the nodes which are the next nodes of
+ the back-references. */
+ if (dfa->nbackref > 0)
+ for (i = 0; i < init_nodes.nelem; ++i)
+ {
+ Idx node_idx = init_nodes.elems[i];
+ re_token_type_t type = dfa->nodes[node_idx].type;
+
+ Idx clexp_idx;
+ if (type != OP_BACK_REF)
+ continue;
+ for (clexp_idx = 0; clexp_idx < init_nodes.nelem; ++clexp_idx)
+ {
+ re_token_t *clexp_node;
+ clexp_node = dfa->nodes + init_nodes.elems[clexp_idx];
+ if (clexp_node->type == OP_CLOSE_SUBEXP
+ && clexp_node->opr.idx == dfa->nodes[node_idx].opr.idx)
+ break;
+ }
+ if (clexp_idx == init_nodes.nelem)
+ continue;
+
+ if (type == OP_BACK_REF)
+ {
+ Idx dest_idx = dfa->edests[node_idx].elems[0];
+ if (!re_node_set_contains (&init_nodes, dest_idx))
+ {
+ reg_errcode_t merge_err
+ = re_node_set_merge (&init_nodes, dfa->eclosures + dest_idx);
+ if (merge_err != REG_NOERROR)
+ return merge_err;
+ i = 0;
+ }
+ }
+ }
+
+ /* It must be the first time to invoke acquire_state. */
+ dfa->init_state = re_acquire_state_context (&err, dfa, &init_nodes, 0);
+ /* We don't check ERR here, since the initial state must not be NULL. */
+ if (BE (dfa->init_state == NULL, 0))
+ return err;
+ if (dfa->init_state->has_constraint)
+ {
+ dfa->init_state_word = re_acquire_state_context (&err, dfa, &init_nodes,
+ CONTEXT_WORD);
+ dfa->init_state_nl = re_acquire_state_context (&err, dfa, &init_nodes,
+ CONTEXT_NEWLINE);
+ dfa->init_state_begbuf = re_acquire_state_context (&err, dfa,
+ &init_nodes,
+ CONTEXT_NEWLINE
+ | CONTEXT_BEGBUF);
+ if (BE (dfa->init_state_word == NULL || dfa->init_state_nl == NULL
+ || dfa->init_state_begbuf == NULL, 0))
+ return err;
+ }
+ else
+ dfa->init_state_word = dfa->init_state_nl
+ = dfa->init_state_begbuf = dfa->init_state;
+
+ re_node_set_free (&init_nodes);
+ return REG_NOERROR;
+}
+
+#ifdef RE_ENABLE_I18N
+/* If it is possible to do searching in single byte encoding instead of UTF-8
+ to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change
+ DFA nodes where needed. */
+
+static void
+optimize_utf8 (re_dfa_t *dfa)
+{
+ Idx node;
+ int i;
+ bool mb_chars = false;
+ bool has_period = false;
+
+ for (node = 0; node < dfa->nodes_len; ++node)
+ switch (dfa->nodes[node].type)
+ {
+ case CHARACTER:
+ if (dfa->nodes[node].opr.c >= ASCII_CHARS)
+ mb_chars = true;
+ break;
+ case ANCHOR:
+ switch (dfa->nodes[node].opr.ctx_type)
+ {
+ case LINE_FIRST:
+ case LINE_LAST:
+ case BUF_FIRST:
+ case BUF_LAST:
+ break;
+ default:
+ /* Word anchors etc. cannot be handled. It's okay to test
+ opr.ctx_type since constraints (for all DFA nodes) are
+ created by ORing one or more opr.ctx_type values. */
+ return;
+ }
+ break;
+ case OP_PERIOD:
+ has_period = true;
+ break;
+ case OP_BACK_REF:
+ case OP_ALT:
+ case END_OF_RE:
+ case OP_DUP_ASTERISK:
+ case OP_OPEN_SUBEXP:
+ case OP_CLOSE_SUBEXP:
+ break;
+ case COMPLEX_BRACKET:
+ return;
+ case SIMPLE_BRACKET:
+ /* Just double check. */
+ {
+ int rshift = (ASCII_CHARS % BITSET_WORD_BITS == 0
+ ? 0
+ : BITSET_WORD_BITS - ASCII_CHARS % BITSET_WORD_BITS);
+ for (i = ASCII_CHARS / BITSET_WORD_BITS; i < BITSET_WORDS; ++i)
+ {
+ if (dfa->nodes[node].opr.sbcset[i] >> rshift != 0)
+ return;
+ rshift = 0;
+ }
+ }
+ break;
+ default:
+ abort ();
+ }
+
+ if (mb_chars || has_period)
+ for (node = 0; node < dfa->nodes_len; ++node)
+ {
+ if (dfa->nodes[node].type == CHARACTER
+ && dfa->nodes[node].opr.c >= ASCII_CHARS)
+ dfa->nodes[node].mb_partial = 0;
+ else if (dfa->nodes[node].type == OP_PERIOD)
+ dfa->nodes[node].type = OP_UTF8_PERIOD;
+ }
+
+ /* The search can be in single byte locale. */
+ dfa->mb_cur_max = 1;
+ dfa->is_utf8 = 0;
+ dfa->has_mb_node = dfa->nbackref > 0 || has_period;
+}
+#endif
+
+/* Analyze the structure tree, and calculate "first", "next", "edest",
+ "eclosure", and "inveclosure". */
+
+static reg_errcode_t
+analyze (regex_t *preg)
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ reg_errcode_t ret;
+
+ /* Allocate arrays. */
+ dfa->nexts = re_malloc (Idx, dfa->nodes_alloc);
+ dfa->org_indices = re_malloc (Idx, dfa->nodes_alloc);
+ dfa->edests = re_malloc (re_node_set, dfa->nodes_alloc);
+ dfa->eclosures = re_malloc (re_node_set, dfa->nodes_alloc);
+ if (BE (dfa->nexts == NULL || dfa->org_indices == NULL || dfa->edests == NULL
+ || dfa->eclosures == NULL, 0))
+ return REG_ESPACE;
+
+ dfa->subexp_map = re_malloc (Idx, preg->re_nsub);
+ if (dfa->subexp_map != NULL)
+ {
+ Idx i;
+ for (i = 0; i < preg->re_nsub; i++)
+ dfa->subexp_map[i] = i;
+ preorder (dfa->str_tree, optimize_subexps, dfa);
+ for (i = 0; i < preg->re_nsub; i++)
+ if (dfa->subexp_map[i] != i)
+ break;
+ if (i == preg->re_nsub)
+ {
+ free (dfa->subexp_map);
+ dfa->subexp_map = NULL;
+ }
+ }
+
+ ret = postorder (dfa->str_tree, lower_subexps, preg);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ ret = postorder (dfa->str_tree, calc_first, dfa);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ preorder (dfa->str_tree, calc_next, dfa);
+ ret = preorder (dfa->str_tree, link_nfa_nodes, dfa);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ ret = calc_eclosure (dfa);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+
+ /* We only need this during the prune_impossible_nodes pass in regexec.c;
+ skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */
+ if ((!preg->no_sub && preg->re_nsub > 0 && dfa->has_plural_match)
+ || dfa->nbackref)
+ {
+ dfa->inveclosures = re_malloc (re_node_set, dfa->nodes_len);
+ if (BE (dfa->inveclosures == NULL, 0))
+ return REG_ESPACE;
+ ret = calc_inveclosure (dfa);
+ }
+
+ return ret;
+}
+
+/* Our parse trees are very unbalanced, so we cannot use a stack to
+ implement parse tree visits. Instead, we use parent pointers and
+ some hairy code in these two functions. */
+static reg_errcode_t
+postorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra)
+{
+ bin_tree_t *node, *prev;
+
+ for (node = root; ; )
+ {
+ /* Descend down the tree, preferably to the left (or to the right
+ if that's the only child). */
+ while (node->left || node->right)
+ if (node->left)
+ node = node->left;
+ else
+ node = node->right;
+
+ do
+ {
+ reg_errcode_t err = fn (extra, node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ if (node->parent == NULL)
+ return REG_NOERROR;
+ prev = node;
+ node = node->parent;
+ }
+ /* Go up while we have a node that is reached from the right. */
+ while (node->right == prev || node->right == NULL);
+ node = node->right;
+ }
+}
+
+static reg_errcode_t
+preorder (bin_tree_t *root, reg_errcode_t (fn (void *, bin_tree_t *)),
+ void *extra)
+{
+ bin_tree_t *node;
+
+ for (node = root; ; )
+ {
+ reg_errcode_t err = fn (extra, node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* Go to the left node, or up and to the right. */
+ if (node->left)
+ node = node->left;
+ else
+ {
+ bin_tree_t *prev = NULL;
+ while (node->right == prev || node->right == NULL)
+ {
+ prev = node;
+ node = node->parent;
+ if (!node)
+ return REG_NOERROR;
+ }
+ node = node->right;
+ }
+ }
+}
+
+/* Optimization pass: if a SUBEXP is entirely contained, strip it and tell
+ re_search_internal to map the inner one's opr.idx to this one's. Adjust
+ backreferences as well. Requires a preorder visit. */
+static reg_errcode_t
+optimize_subexps (void *extra, bin_tree_t *node)
+{
+ re_dfa_t *dfa = (re_dfa_t *) extra;
+
+ if (node->token.type == OP_BACK_REF && dfa->subexp_map)
+ {
+ int idx = node->token.opr.idx;
+ node->token.opr.idx = dfa->subexp_map[idx];
+ dfa->used_bkref_map |= 1 << node->token.opr.idx;
+ }
+
+ else if (node->token.type == SUBEXP
+ && node->left && node->left->token.type == SUBEXP)
+ {
+ Idx other_idx = node->left->token.opr.idx;
+
+ node->left = node->left->left;
+ if (node->left)
+ node->left->parent = node;
+
+ dfa->subexp_map[other_idx] = dfa->subexp_map[node->token.opr.idx];
+ if (other_idx < BITSET_WORD_BITS)
+ dfa->used_bkref_map &= ~((bitset_word_t) 1 << other_idx);
+ }
+
+ return REG_NOERROR;
+}
+
+/* Lowering pass: Turn each SUBEXP node into the appropriate concatenation
+ of OP_OPEN_SUBEXP, the body of the SUBEXP (if any) and OP_CLOSE_SUBEXP. */
+static reg_errcode_t
+lower_subexps (void *extra, bin_tree_t *node)
+{
+ regex_t *preg = (regex_t *) extra;
+ reg_errcode_t err = REG_NOERROR;
+
+ if (node->left && node->left->token.type == SUBEXP)
+ {
+ node->left = lower_subexp (&err, preg, node->left);
+ if (node->left)
+ node->left->parent = node;
+ }
+ if (node->right && node->right->token.type == SUBEXP)
+ {
+ node->right = lower_subexp (&err, preg, node->right);
+ if (node->right)
+ node->right->parent = node;
+ }
+
+ return err;
+}
+
+static bin_tree_t *
+lower_subexp (reg_errcode_t *err, regex_t *preg, bin_tree_t *node)
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ bin_tree_t *body = node->left;
+ bin_tree_t *op, *cls, *tree1, *tree;
+
+ if (preg->no_sub
+ /* We do not optimize empty subexpressions, because otherwise we may
+ have bad CONCAT nodes with NULL children. This is obviously not
+ very common, so we do not lose much. An example that triggers
+ this case is the sed "script" /\(\)/x. */
+ && node->left != NULL
+ && (node->token.opr.idx >= BITSET_WORD_BITS
+ || !(dfa->used_bkref_map
+ & ((bitset_word_t) 1 << node->token.opr.idx))))
+ return node->left;
+
+ /* Convert the SUBEXP node to the concatenation of an
+ OP_OPEN_SUBEXP, the contents, and an OP_CLOSE_SUBEXP. */
+ op = create_tree (dfa, NULL, NULL, OP_OPEN_SUBEXP);
+ cls = create_tree (dfa, NULL, NULL, OP_CLOSE_SUBEXP);
+ tree1 = body ? create_tree (dfa, body, cls, CONCAT) : cls;
+ tree = create_tree (dfa, op, tree1, CONCAT);
+ if (BE (tree == NULL || tree1 == NULL || op == NULL || cls == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ op->token.opr.idx = cls->token.opr.idx = node->token.opr.idx;
+ op->token.opt_subexp = cls->token.opt_subexp = node->token.opt_subexp;
+ return tree;
+}
+
+/* Pass 1 in building the NFA: compute FIRST and create unlinked automaton
+ nodes. Requires a postorder visit. */
+static reg_errcode_t
+calc_first (void *extra, bin_tree_t *node)
+{
+ re_dfa_t *dfa = (re_dfa_t *) extra;
+ if (node->token.type == CONCAT)
+ {
+ node->first = node->left->first;
+ node->node_idx = node->left->node_idx;
+ }
+ else
+ {
+ node->first = node;
+ node->node_idx = re_dfa_add_node (dfa, node->token);
+ if (BE (node->node_idx == REG_MISSING, 0))
+ return REG_ESPACE;
+ if (node->token.type == ANCHOR)
+ dfa->nodes[node->node_idx].constraint = node->token.opr.ctx_type;
+ }
+ return REG_NOERROR;
+}
+
+/* Pass 2: compute NEXT on the tree. Preorder visit. */
+static reg_errcode_t
+calc_next (void *extra, bin_tree_t *node)
+{
+ switch (node->token.type)
+ {
+ case OP_DUP_ASTERISK:
+ node->left->next = node;
+ break;
+ case CONCAT:
+ node->left->next = node->right->first;
+ node->right->next = node->next;
+ break;
+ default:
+ if (node->left)
+ node->left->next = node->next;
+ if (node->right)
+ node->right->next = node->next;
+ break;
+ }
+ return REG_NOERROR;
+}
+
+/* Pass 3: link all DFA nodes to their NEXT node (any order will do). */
+static reg_errcode_t
+link_nfa_nodes (void *extra, bin_tree_t *node)
+{
+ re_dfa_t *dfa = (re_dfa_t *) extra;
+ Idx idx = node->node_idx;
+ reg_errcode_t err = REG_NOERROR;
+
+ switch (node->token.type)
+ {
+ case CONCAT:
+ break;
+
+ case END_OF_RE:
+ assert (node->next == NULL);
+ break;
+
+ case OP_DUP_ASTERISK:
+ case OP_ALT:
+ {
+ Idx left, right;
+ dfa->has_plural_match = 1;
+ if (node->left != NULL)
+ left = node->left->first->node_idx;
+ else
+ left = node->next->node_idx;
+ if (node->right != NULL)
+ right = node->right->first->node_idx;
+ else
+ right = node->next->node_idx;
+ assert (REG_VALID_INDEX (left));
+ assert (REG_VALID_INDEX (right));
+ err = re_node_set_init_2 (dfa->edests + idx, left, right);
+ }
+ break;
+
+ case ANCHOR:
+ case OP_OPEN_SUBEXP:
+ case OP_CLOSE_SUBEXP:
+ err = re_node_set_init_1 (dfa->edests + idx, node->next->node_idx);
+ break;
+
+ case OP_BACK_REF:
+ dfa->nexts[idx] = node->next->node_idx;
+ if (node->token.type == OP_BACK_REF)
+ err = re_node_set_init_1 (dfa->edests + idx, dfa->nexts[idx]);
+ break;
+
+ default:
+ assert (!IS_EPSILON_NODE (node->token.type));
+ dfa->nexts[idx] = node->next->node_idx;
+ break;
+ }
+
+ return err;
+}
+
+/* Duplicate the epsilon closure of the node ROOT_NODE.
+ Note that duplicated nodes have constraint INIT_CONSTRAINT in addition
+ to their own constraint. */
+
+static reg_errcode_t
+internal_function
+duplicate_node_closure (re_dfa_t *dfa, Idx top_org_node, Idx top_clone_node,
+ Idx root_node, unsigned int init_constraint)
+{
+ Idx org_node, clone_node;
+ bool ok;
+ unsigned int constraint = init_constraint;
+ for (org_node = top_org_node, clone_node = top_clone_node;;)
+ {
+ Idx org_dest, clone_dest;
+ if (dfa->nodes[org_node].type == OP_BACK_REF)
+ {
+ /* If the back reference epsilon-transit, its destination must
+ also have the constraint. Then duplicate the epsilon closure
+ of the destination of the back reference, and store it in
+ edests of the back reference. */
+ org_dest = dfa->nexts[org_node];
+ re_node_set_empty (dfa->edests + clone_node);
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ dfa->nexts[clone_node] = dfa->nexts[org_node];
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ else if (dfa->edests[org_node].nelem == 0)
+ {
+ /* In case of the node can't epsilon-transit, don't duplicate the
+ destination and store the original destination as the
+ destination of the node. */
+ dfa->nexts[clone_node] = dfa->nexts[org_node];
+ break;
+ }
+ else if (dfa->edests[org_node].nelem == 1)
+ {
+ /* In case of the node can epsilon-transit, and it has only one
+ destination. */
+ org_dest = dfa->edests[org_node].elems[0];
+ re_node_set_empty (dfa->edests + clone_node);
+ /* If the node is root_node itself, it means the epsilon closure
+ has a loop. Then tie it to the destination of the root_node. */
+ if (org_node == root_node && clone_node != org_node)
+ {
+ ok = re_node_set_insert (dfa->edests + clone_node, org_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ break;
+ }
+ /* In case the node has another constraint, append it. */
+ constraint |= dfa->nodes[org_node].constraint;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ else /* dfa->edests[org_node].nelem == 2 */
+ {
+ /* In case of the node can epsilon-transit, and it has two
+ destinations. In the bin_tree_t and DFA, that's '|' and '*'. */
+ org_dest = dfa->edests[org_node].elems[0];
+ re_node_set_empty (dfa->edests + clone_node);
+ /* Search for a duplicated node which satisfies the constraint. */
+ clone_dest = search_duplicated_node (dfa, org_dest, constraint);
+ if (clone_dest == REG_MISSING)
+ {
+ /* There is no such duplicated node, create a new one. */
+ reg_errcode_t err;
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ err = duplicate_node_closure (dfa, org_dest, clone_dest,
+ root_node, constraint);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ else
+ {
+ /* There is a duplicated node which satisfies the constraint,
+ use it to avoid infinite loop. */
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+
+ org_dest = dfa->edests[org_node].elems[1];
+ clone_dest = duplicate_node (dfa, org_dest, constraint);
+ if (BE (clone_dest == REG_MISSING, 0))
+ return REG_ESPACE;
+ ok = re_node_set_insert (dfa->edests + clone_node, clone_dest);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ org_node = org_dest;
+ clone_node = clone_dest;
+ }
+ return REG_NOERROR;
+}
+
+/* Search for a node which is duplicated from the node ORG_NODE, and
+ satisfies the constraint CONSTRAINT. */
+
+static Idx
+search_duplicated_node (const re_dfa_t *dfa, Idx org_node,
+ unsigned int constraint)
+{
+ Idx idx;
+ for (idx = dfa->nodes_len - 1; dfa->nodes[idx].duplicated && idx > 0; --idx)
+ {
+ if (org_node == dfa->org_indices[idx]
+ && constraint == dfa->nodes[idx].constraint)
+ return idx; /* Found. */
+ }
+ return REG_MISSING; /* Not found. */
+}
+
+/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT.
+ Return the index of the new node, or REG_MISSING if insufficient storage is
+ available. */
+
+static Idx
+duplicate_node (re_dfa_t *dfa, Idx org_idx, unsigned int constraint)
+{
+ Idx dup_idx = re_dfa_add_node (dfa, dfa->nodes[org_idx]);
+ if (BE (dup_idx != REG_MISSING, 1))
+ {
+ dfa->nodes[dup_idx].constraint = constraint;
+ dfa->nodes[dup_idx].constraint |= dfa->nodes[org_idx].constraint;
+ dfa->nodes[dup_idx].duplicated = 1;
+
+ /* Store the index of the original node. */
+ dfa->org_indices[dup_idx] = org_idx;
+ }
+ return dup_idx;
+}
+
+static reg_errcode_t
+calc_inveclosure (re_dfa_t *dfa)
+{
+ Idx src, idx;
+ bool ok;
+ for (idx = 0; idx < dfa->nodes_len; ++idx)
+ re_node_set_init_empty (dfa->inveclosures + idx);
+
+ for (src = 0; src < dfa->nodes_len; ++src)
+ {
+ Idx *elems = dfa->eclosures[src].elems;
+ for (idx = 0; idx < dfa->eclosures[src].nelem; ++idx)
+ {
+ ok = re_node_set_insert_last (dfa->inveclosures + elems[idx], src);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ }
+
+ return REG_NOERROR;
+}
+
+/* Calculate "eclosure" for all the node in DFA. */
+
+static reg_errcode_t
+calc_eclosure (re_dfa_t *dfa)
+{
+ Idx node_idx;
+ bool incomplete;
+#ifdef DEBUG
+ assert (dfa->nodes_len > 0);
+#endif
+ incomplete = false;
+ /* For each nodes, calculate epsilon closure. */
+ for (node_idx = 0; ; ++node_idx)
+ {
+ reg_errcode_t err;
+ re_node_set eclosure_elem;
+ if (node_idx == dfa->nodes_len)
+ {
+ if (!incomplete)
+ break;
+ incomplete = false;
+ node_idx = 0;
+ }
+
+#ifdef DEBUG
+ assert (dfa->eclosures[node_idx].nelem != REG_MISSING);
+#endif
+
+ /* If we have already calculated, skip it. */
+ if (dfa->eclosures[node_idx].nelem != 0)
+ continue;
+ /* Calculate epsilon closure of 'node_idx'. */
+ err = calc_eclosure_iter (&eclosure_elem, dfa, node_idx, true);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ if (dfa->eclosures[node_idx].nelem == 0)
+ {
+ incomplete = true;
+ re_node_set_free (&eclosure_elem);
+ }
+ }
+ return REG_NOERROR;
+}
+
+/* Calculate epsilon closure of NODE. */
+
+static reg_errcode_t
+calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root)
+{
+ reg_errcode_t err;
+ Idx i;
+ re_node_set eclosure;
+ bool ok;
+ bool incomplete = false;
+ err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* This indicates that we are calculating this node now.
+ We reference this value to avoid infinite loop. */
+ dfa->eclosures[node].nelem = REG_MISSING;
+
+ /* If the current node has constraints, duplicate all nodes
+ since they must inherit the constraints. */
+ if (dfa->nodes[node].constraint
+ && dfa->edests[node].nelem
+ && !dfa->nodes[dfa->edests[node].elems[0]].duplicated)
+ {
+ err = duplicate_node_closure (dfa, node, node, node,
+ dfa->nodes[node].constraint);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ /* Expand each epsilon destination nodes. */
+ if (IS_EPSILON_NODE(dfa->nodes[node].type))
+ for (i = 0; i < dfa->edests[node].nelem; ++i)
+ {
+ re_node_set eclosure_elem;
+ Idx edest = dfa->edests[node].elems[i];
+ /* If calculating the epsilon closure of 'edest' is in progress,
+ return intermediate result. */
+ if (dfa->eclosures[edest].nelem == REG_MISSING)
+ {
+ incomplete = true;
+ continue;
+ }
+ /* If we haven't calculated the epsilon closure of 'edest' yet,
+ calculate now. Otherwise use calculated epsilon closure. */
+ if (dfa->eclosures[edest].nelem == 0)
+ {
+ err = calc_eclosure_iter (&eclosure_elem, dfa, edest, false);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ else
+ eclosure_elem = dfa->eclosures[edest];
+ /* Merge the epsilon closure of 'edest'. */
+ err = re_node_set_merge (&eclosure, &eclosure_elem);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ /* If the epsilon closure of 'edest' is incomplete,
+ the epsilon closure of this node is also incomplete. */
+ if (dfa->eclosures[edest].nelem == 0)
+ {
+ incomplete = true;
+ re_node_set_free (&eclosure_elem);
+ }
+ }
+
+ /* An epsilon closure includes itself. */
+ ok = re_node_set_insert (&eclosure, node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ if (incomplete && !root)
+ dfa->eclosures[node].nelem = 0;
+ else
+ dfa->eclosures[node] = eclosure;
+ *new_set = eclosure;
+ return REG_NOERROR;
+}
+
+/* Functions for token which are used in the parser. */
+
+/* Fetch a token from INPUT.
+ We must not use this function inside bracket expressions. */
+
+static void
+internal_function
+fetch_token (re_token_t *result, re_string_t *input, reg_syntax_t syntax)
+{
+ re_string_skip_bytes (input, peek_token (result, input, syntax));
+}
+
+/* Peek a token from INPUT, and return the length of the token.
+ We must not use this function inside bracket expressions. */
+
+static int
+internal_function
+peek_token (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
+{
+ unsigned char c;
+
+ if (re_string_eoi (input))
+ {
+ token->type = END_OF_RE;
+ return 0;
+ }
+
+ c = re_string_peek_byte (input, 0);
+ token->opr.c = c;
+
+ token->word_char = 0;
+#ifdef RE_ENABLE_I18N
+ token->mb_partial = 0;
+ if (input->mb_cur_max > 1 &&
+ !re_string_first_byte (input, re_string_cur_idx (input)))
+ {
+ token->type = CHARACTER;
+ token->mb_partial = 1;
+ return 1;
+ }
+#endif
+ if (c == '\\')
+ {
+ unsigned char c2;
+ if (re_string_cur_idx (input) + 1 >= re_string_length (input))
+ {
+ token->type = BACK_SLASH;
+ return 1;
+ }
+
+ c2 = re_string_peek_byte_case (input, 1);
+ token->opr.c = c2;
+ token->type = CHARACTER;
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1)
+ {
+ wint_t wc = re_string_wchar_at (input,
+ re_string_cur_idx (input) + 1);
+ token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
+ }
+ else
+#endif
+ token->word_char = IS_WORD_CHAR (c2) != 0;
+
+ switch (c2)
+ {
+ case '|':
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_NO_BK_VBAR))
+ token->type = OP_ALT;
+ break;
+ case '1': case '2': case '3': case '4': case '5':
+ case '6': case '7': case '8': case '9':
+ if (!(syntax & RE_NO_BK_REFS))
+ {
+ token->type = OP_BACK_REF;
+ token->opr.idx = c2 - '1';
+ }
+ break;
+ case '<':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = WORD_FIRST;
+ }
+ break;
+ case '>':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = WORD_LAST;
+ }
+ break;
+ case 'b':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = WORD_DELIM;
+ }
+ break;
+ case 'B':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = NOT_WORD_DELIM;
+ }
+ break;
+ case 'w':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_WORD;
+ break;
+ case 'W':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_NOTWORD;
+ break;
+ case 's':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_SPACE;
+ break;
+ case 'S':
+ if (!(syntax & RE_NO_GNU_OPS))
+ token->type = OP_NOTSPACE;
+ break;
+ case '`':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = BUF_FIRST;
+ }
+ break;
+ case '\'':
+ if (!(syntax & RE_NO_GNU_OPS))
+ {
+ token->type = ANCHOR;
+ token->opr.ctx_type = BUF_LAST;
+ }
+ break;
+ case '(':
+ if (!(syntax & RE_NO_BK_PARENS))
+ token->type = OP_OPEN_SUBEXP;
+ break;
+ case ')':
+ if (!(syntax & RE_NO_BK_PARENS))
+ token->type = OP_CLOSE_SUBEXP;
+ break;
+ case '+':
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_PLUS;
+ break;
+ case '?':
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_QUESTION;
+ break;
+ case '{':
+ if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
+ token->type = OP_OPEN_DUP_NUM;
+ break;
+ case '}':
+ if ((syntax & RE_INTERVALS) && (!(syntax & RE_NO_BK_BRACES)))
+ token->type = OP_CLOSE_DUP_NUM;
+ break;
+ default:
+ break;
+ }
+ return 2;
+ }
+
+ token->type = CHARACTER;
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1)
+ {
+ wint_t wc = re_string_wchar_at (input, re_string_cur_idx (input));
+ token->word_char = IS_WIDE_WORD_CHAR (wc) != 0;
+ }
+ else
+#endif
+ token->word_char = IS_WORD_CHAR (token->opr.c);
+
+ switch (c)
+ {
+ case '\n':
+ if (syntax & RE_NEWLINE_ALT)
+ token->type = OP_ALT;
+ break;
+ case '|':
+ if (!(syntax & RE_LIMITED_OPS) && (syntax & RE_NO_BK_VBAR))
+ token->type = OP_ALT;
+ break;
+ case '*':
+ token->type = OP_DUP_ASTERISK;
+ break;
+ case '+':
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_PLUS;
+ break;
+ case '?':
+ if (!(syntax & RE_LIMITED_OPS) && !(syntax & RE_BK_PLUS_QM))
+ token->type = OP_DUP_QUESTION;
+ break;
+ case '{':
+ if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
+ token->type = OP_OPEN_DUP_NUM;
+ break;
+ case '}':
+ if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
+ token->type = OP_CLOSE_DUP_NUM;
+ break;
+ case '(':
+ if (syntax & RE_NO_BK_PARENS)
+ token->type = OP_OPEN_SUBEXP;
+ break;
+ case ')':
+ if (syntax & RE_NO_BK_PARENS)
+ token->type = OP_CLOSE_SUBEXP;
+ break;
+ case '[':
+ token->type = OP_OPEN_BRACKET;
+ break;
+ case '.':
+ token->type = OP_PERIOD;
+ break;
+ case '^':
+ if (!(syntax & (RE_CONTEXT_INDEP_ANCHORS | RE_CARET_ANCHORS_HERE)) &&
+ re_string_cur_idx (input) != 0)
+ {
+ char prev = re_string_peek_byte (input, -1);
+ if (!(syntax & RE_NEWLINE_ALT) || prev != '\n')
+ break;
+ }
+ token->type = ANCHOR;
+ token->opr.ctx_type = LINE_FIRST;
+ break;
+ case '$':
+ if (!(syntax & RE_CONTEXT_INDEP_ANCHORS) &&
+ re_string_cur_idx (input) + 1 != re_string_length (input))
+ {
+ re_token_t next;
+ re_string_skip_bytes (input, 1);
+ peek_token (&next, input, syntax);
+ re_string_skip_bytes (input, -1);
+ if (next.type != OP_ALT && next.type != OP_CLOSE_SUBEXP)
+ break;
+ }
+ token->type = ANCHOR;
+ token->opr.ctx_type = LINE_LAST;
+ break;
+ default:
+ break;
+ }
+ return 1;
+}
+
+/* Peek a token from INPUT, and return the length of the token.
+ We must not use this function out of bracket expressions. */
+
+static int
+internal_function
+peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax)
+{
+ unsigned char c;
+ if (re_string_eoi (input))
+ {
+ token->type = END_OF_RE;
+ return 0;
+ }
+ c = re_string_peek_byte (input, 0);
+ token->opr.c = c;
+
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1 &&
+ !re_string_first_byte (input, re_string_cur_idx (input)))
+ {
+ token->type = CHARACTER;
+ return 1;
+ }
+#endif /* RE_ENABLE_I18N */
+
+ if (c == '\\' && (syntax & RE_BACKSLASH_ESCAPE_IN_LISTS)
+ && re_string_cur_idx (input) + 1 < re_string_length (input))
+ {
+ /* In this case, '\' escape a character. */
+ unsigned char c2;
+ re_string_skip_bytes (input, 1);
+ c2 = re_string_peek_byte (input, 0);
+ token->opr.c = c2;
+ token->type = CHARACTER;
+ return 1;
+ }
+ if (c == '[') /* '[' is a special char in a bracket exps. */
+ {
+ unsigned char c2;
+ int token_len;
+ if (re_string_cur_idx (input) + 1 < re_string_length (input))
+ c2 = re_string_peek_byte (input, 1);
+ else
+ c2 = 0;
+ token->opr.c = c2;
+ token_len = 2;
+ switch (c2)
+ {
+ case '.':
+ token->type = OP_OPEN_COLL_ELEM;
+ break;
+ case '=':
+ token->type = OP_OPEN_EQUIV_CLASS;
+ break;
+ case ':':
+ if (syntax & RE_CHAR_CLASSES)
+ {
+ token->type = OP_OPEN_CHAR_CLASS;
+ break;
+ }
+ /* else fall through. */
+ default:
+ token->type = CHARACTER;
+ token->opr.c = c;
+ token_len = 1;
+ break;
+ }
+ return token_len;
+ }
+ switch (c)
+ {
+ case '-':
+ token->type = OP_CHARSET_RANGE;
+ break;
+ case ']':
+ token->type = OP_CLOSE_BRACKET;
+ break;
+ case '^':
+ token->type = OP_NON_MATCH_LIST;
+ break;
+ default:
+ token->type = CHARACTER;
+ }
+ return 1;
+}
+
+/* Functions for parser. */
+
+/* Entry point of the parser.
+ Parse the regular expression REGEXP and return the structure tree.
+ If an error is occured, ERR is set by error code, and return NULL.
+ This function build the following tree, from regular expression <reg_exp>:
+ CAT
+ / \
+ / \
+ <reg_exp> EOR
+
+ CAT means concatenation.
+ EOR means end of regular expression. */
+
+static bin_tree_t *
+parse (re_string_t *regexp, regex_t *preg, reg_syntax_t syntax,
+ reg_errcode_t *err)
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ bin_tree_t *tree, *eor, *root;
+ re_token_t current_token;
+ dfa->syntax = syntax;
+ fetch_token (&current_token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+ tree = parse_reg_exp (regexp, preg, &current_token, syntax, 0, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ eor = create_tree (dfa, NULL, NULL, END_OF_RE);
+ if (tree != NULL)
+ root = create_tree (dfa, tree, eor, CONCAT);
+ else
+ root = eor;
+ if (BE (eor == NULL || root == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ return root;
+}
+
+/* This function build the following tree, from regular expression
+ <branch1>|<branch2>:
+ ALT
+ / \
+ / \
+ <branch1> <branch2>
+
+ ALT means alternative, which represents the operator '|'. */
+
+static bin_tree_t *
+parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ bin_tree_t *tree, *branch = NULL;
+ tree = parse_branch (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+
+ while (token->type == OP_ALT)
+ {
+ fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+ if (token->type != OP_ALT && token->type != END_OF_RE
+ && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
+ {
+ branch = parse_branch (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && branch == NULL, 0))
+ return NULL;
+ }
+ else
+ branch = NULL;
+ tree = create_tree (dfa, tree, branch, OP_ALT);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ return tree;
+}
+
+/* This function build the following tree, from regular expression
+ <exp1><exp2>:
+ CAT
+ / \
+ / \
+ <exp1> <exp2>
+
+ CAT means concatenation. */
+
+static bin_tree_t *
+parse_branch (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ bin_tree_t *tree, *expr;
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ tree = parse_expression (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+
+ while (token->type != OP_ALT && token->type != END_OF_RE
+ && (nest == 0 || token->type != OP_CLOSE_SUBEXP))
+ {
+ expr = parse_expression (regexp, preg, token, syntax, nest, err);
+ if (BE (*err != REG_NOERROR && expr == NULL, 0))
+ {
+ return NULL;
+ }
+ if (tree != NULL && expr != NULL)
+ {
+ tree = create_tree (dfa, tree, expr, CONCAT);
+ if (tree == NULL)
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ else if (tree == NULL)
+ tree = expr;
+ /* Otherwise expr == NULL, we don't need to create new tree. */
+ }
+ return tree;
+}
+
+/* This function build the following tree, from regular expression a*:
+ *
+ |
+ a
+*/
+
+static bin_tree_t *
+parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ bin_tree_t *tree;
+ switch (token->type)
+ {
+ case CHARACTER:
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ while (!re_string_eoi (regexp)
+ && !re_string_first_byte (regexp, re_string_cur_idx (regexp)))
+ {
+ bin_tree_t *mbc_remain;
+ fetch_token (token, regexp, syntax);
+ mbc_remain = create_token_tree (dfa, NULL, NULL, token);
+ tree = create_tree (dfa, tree, mbc_remain, CONCAT);
+ if (BE (mbc_remain == NULL || tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ }
+#endif
+ break;
+ case OP_OPEN_SUBEXP:
+ tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_OPEN_BRACKET:
+ tree = parse_bracket_exp (regexp, dfa, token, syntax, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_BACK_REF:
+ if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1))
+ {
+ *err = REG_ESUBREG;
+ return NULL;
+ }
+ dfa->used_bkref_map |= 1 << token->opr.idx;
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ ++dfa->nbackref;
+ dfa->has_mb_node = 1;
+ break;
+ case OP_OPEN_DUP_NUM:
+ if (syntax & RE_CONTEXT_INVALID_DUP)
+ {
+ *err = REG_BADRPT;
+ return NULL;
+ }
+ /* FALLTHROUGH */
+ case OP_DUP_ASTERISK:
+ case OP_DUP_PLUS:
+ case OP_DUP_QUESTION:
+ if (syntax & RE_CONTEXT_INVALID_OPS)
+ {
+ *err = REG_BADRPT;
+ return NULL;
+ }
+ else if (syntax & RE_CONTEXT_INDEP_OPS)
+ {
+ fetch_token (token, regexp, syntax);
+ return parse_expression (regexp, preg, token, syntax, nest, err);
+ }
+ /* else fall through */
+ case OP_CLOSE_SUBEXP:
+ if ((token->type == OP_CLOSE_SUBEXP) &&
+ !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD))
+ {
+ *err = REG_ERPAREN;
+ return NULL;
+ }
+ /* else fall through */
+ case OP_CLOSE_DUP_NUM:
+ /* We treat it as a normal character. */
+
+ /* Then we can these characters as normal characters. */
+ token->type = CHARACTER;
+ /* mb_partial and word_char bits should be initialized already
+ by peek_token. */
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ break;
+ case ANCHOR:
+ if ((token->opr.ctx_type
+ & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST))
+ && dfa->word_ops_used == 0)
+ init_word_char (dfa);
+ if (token->opr.ctx_type == WORD_DELIM
+ || token->opr.ctx_type == NOT_WORD_DELIM)
+ {
+ bin_tree_t *tree_first, *tree_last;
+ if (token->opr.ctx_type == WORD_DELIM)
+ {
+ token->opr.ctx_type = WORD_FIRST;
+ tree_first = create_token_tree (dfa, NULL, NULL, token);
+ token->opr.ctx_type = WORD_LAST;
+ }
+ else
+ {
+ token->opr.ctx_type = INSIDE_WORD;
+ tree_first = create_token_tree (dfa, NULL, NULL, token);
+ token->opr.ctx_type = INSIDE_NOTWORD;
+ }
+ tree_last = create_token_tree (dfa, NULL, NULL, token);
+ tree = create_tree (dfa, tree_first, tree_last, OP_ALT);
+ if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ else
+ {
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ }
+ /* We must return here, since ANCHORs can't be followed
+ by repetition operators.
+ eg. RE"^*" is invalid or "<ANCHOR(^)><CHAR(*)>",
+ it must not be "<ANCHOR(^)><REPEAT(*)>". */
+ fetch_token (token, regexp, syntax);
+ return tree;
+ case OP_PERIOD:
+ tree = create_token_tree (dfa, NULL, NULL, token);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ if (dfa->mb_cur_max > 1)
+ dfa->has_mb_node = 1;
+ break;
+ case OP_WORD:
+ case OP_NOTWORD:
+ tree = build_charclass_op (dfa, regexp->trans,
+ (const unsigned char *) "alnum",
+ (const unsigned char *) "_",
+ token->type == OP_NOTWORD, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_SPACE:
+ case OP_NOTSPACE:
+ tree = build_charclass_op (dfa, regexp->trans,
+ (const unsigned char *) "space",
+ (const unsigned char *) "",
+ token->type == OP_NOTSPACE, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ break;
+ case OP_ALT:
+ case END_OF_RE:
+ return NULL;
+ case BACK_SLASH:
+ *err = REG_EESCAPE;
+ return NULL;
+ default:
+ /* Must not happen? */
+#ifdef DEBUG
+ assert (0);
+#endif
+ return NULL;
+ }
+ fetch_token (token, regexp, syntax);
+
+ while (token->type == OP_DUP_ASTERISK || token->type == OP_DUP_PLUS
+ || token->type == OP_DUP_QUESTION || token->type == OP_OPEN_DUP_NUM)
+ {
+ tree = parse_dup_op (tree, regexp, dfa, token, syntax, err);
+ if (BE (*err != REG_NOERROR && tree == NULL, 0))
+ return NULL;
+ /* In BRE consecutive duplications are not allowed. */
+ if ((syntax & RE_CONTEXT_INVALID_DUP)
+ && (token->type == OP_DUP_ASTERISK
+ || token->type == OP_OPEN_DUP_NUM))
+ {
+ *err = REG_BADRPT;
+ return NULL;
+ }
+ }
+
+ return tree;
+}
+
+/* This function build the following tree, from regular expression
+ (<reg_exp>):
+ SUBEXP
+ |
+ <reg_exp>
+*/
+
+static bin_tree_t *
+parse_sub_exp (re_string_t *regexp, regex_t *preg, re_token_t *token,
+ reg_syntax_t syntax, Idx nest, reg_errcode_t *err)
+{
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+ bin_tree_t *tree;
+ size_t cur_nsub;
+ cur_nsub = preg->re_nsub++;
+
+ fetch_token (token, regexp, syntax | RE_CARET_ANCHORS_HERE);
+
+ /* The subexpression may be a null string. */
+ if (token->type == OP_CLOSE_SUBEXP)
+ tree = NULL;
+ else
+ {
+ tree = parse_reg_exp (regexp, preg, token, syntax, nest, err);
+ if (BE (*err == REG_NOERROR && token->type != OP_CLOSE_SUBEXP, 0))
+ *err = REG_EPAREN;
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ }
+
+ if (cur_nsub <= '9' - '1')
+ dfa->completed_bkref_map |= 1 << cur_nsub;
+
+ tree = create_tree (dfa, tree, NULL, SUBEXP);
+ if (BE (tree == NULL, 0))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+ tree->token.opr.idx = cur_nsub;
+ return tree;
+}
+
+/* This function parse repetition operators like "*", "+", "{1,3}" etc. */
+
+static bin_tree_t *
+parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa,
+ re_token_t *token, reg_syntax_t syntax, reg_errcode_t *err)
+{
+ bin_tree_t *tree = NULL, *old_tree = NULL;
+ Idx i, start, end, start_idx = re_string_cur_idx (regexp);
+ re_token_t start_token = *token;
+
+ if (token->type == OP_OPEN_DUP_NUM)
+ {
+ end = 0;
+ start = fetch_number (regexp, token, syntax);
+ if (start == REG_MISSING)
+ {
+ if (token->type == CHARACTER && token->opr.c == ',')
+ start = 0; /* We treat "{,m}" as "{0,m}". */
+ else
+ {
+ *err = REG_BADBR; /* <re>{} is invalid. */
+ return NULL;
+ }
+ }
+ if (BE (start != REG_ERROR, 1))
+ {
+ /* We treat "{n}" as "{n,n}". */
+ end = ((token->type == OP_CLOSE_DUP_NUM) ? start
+ : ((token->type == CHARACTER && token->opr.c == ',')
+ ? fetch_number (regexp, token, syntax) : REG_ERROR));
+ }
+ if (BE (start == REG_ERROR || end == REG_ERROR, 0))
+ {
+ /* Invalid sequence. */
+ if (BE (!(syntax & RE_INVALID_INTERVAL_ORD), 0))
+ {
+ if (token->type == END_OF_RE)
+ *err = REG_EBRACE;
+ else
+ *err = REG_BADBR;
+
+ return NULL;
+ }
+
+ /* If the syntax bit is set, rollback. */
+ re_string_set_index (regexp, start_idx);
+ *token = start_token;
+ token->type = CHARACTER;
+ /* mb_partial and word_char bits should be already initialized by
+ peek_token. */
+ return elem;
+ }
+
+ if (BE ((end != REG_MISSING && start > end)
+ || token->type != OP_CLOSE_DUP_NUM, 0))
+ {
+ /* First number greater than second. */
+ *err = REG_BADBR;
+ return NULL;
+ }
+ }
+ else
+ {
+ start = (token->type == OP_DUP_PLUS) ? 1 : 0;
+ end = (token->type == OP_DUP_QUESTION) ? 1 : REG_MISSING;
+ }
+
+ fetch_token (token, regexp, syntax);
+
+ if (BE (elem == NULL, 0))
+ return NULL;
+ if (BE (start == 0 && end == 0, 0))
+ {
+ postorder (elem, free_tree, NULL);
+ return NULL;
+ }
+
+ /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */
+ if (BE (start > 0, 0))
+ {
+ tree = elem;
+ for (i = 2; i <= start; ++i)
+ {
+ elem = duplicate_tree (elem, dfa);
+ tree = create_tree (dfa, tree, elem, CONCAT);
+ if (BE (elem == NULL || tree == NULL, 0))
+ goto parse_dup_op_espace;
+ }
+
+ if (start == end)
+ return tree;
+
+ /* Duplicate ELEM before it is marked optional. */
+ elem = duplicate_tree (elem, dfa);
+ old_tree = tree;
+ }
+ else
+ old_tree = NULL;
+
+ if (elem->token.type == SUBEXP)
+ postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx);
+
+ tree = create_tree (dfa, elem, NULL,
+ (end == REG_MISSING ? OP_DUP_ASTERISK : OP_ALT));
+ if (BE (tree == NULL, 0))
+ goto parse_dup_op_espace;
+
+/* From gnulib's "intprops.h":
+ True if the arithmetic type T is signed. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+
+ /* This loop is actually executed only when end != REG_MISSING,
+ to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have
+ already created the start+1-th copy. */
+ if (TYPE_SIGNED (Idx) || end != REG_MISSING)
+ for (i = start + 2; i <= end; ++i)
+ {
+ elem = duplicate_tree (elem, dfa);
+ tree = create_tree (dfa, tree, elem, CONCAT);
+ if (BE (elem == NULL || tree == NULL, 0))
+ goto parse_dup_op_espace;
+
+ tree = create_tree (dfa, tree, NULL, OP_ALT);
+ if (BE (tree == NULL, 0))
+ goto parse_dup_op_espace;
+ }
+
+ if (old_tree)
+ tree = create_tree (dfa, old_tree, tree, CONCAT);
+
+ return tree;
+
+ parse_dup_op_espace:
+ *err = REG_ESPACE;
+ return NULL;
+}
+
+/* Size of the names for collating symbol/equivalence_class/character_class.
+ I'm not sure, but maybe enough. */
+#define BRACKET_NAME_BUF_SIZE 32
+
+#ifndef _LIBC
+ /* Local function for parse_bracket_exp only used in case of NOT _LIBC.
+ Build the range expression which starts from START_ELEM, and ends
+ at END_ELEM. The result are written to MBCSET and SBCSET.
+ RANGE_ALLOC is the allocated size of mbcset->range_starts, and
+ mbcset->range_ends, is a pointer argument sinse we may
+ update it. */
+
+static reg_errcode_t
+internal_function
+# ifdef RE_ENABLE_I18N
+build_range_exp (const reg_syntax_t syntax,
+ bitset_t sbcset,
+ re_charset_t *mbcset,
+ Idx *range_alloc,
+ const bracket_elem_t *start_elem,
+ const bracket_elem_t *end_elem)
+# else /* not RE_ENABLE_I18N */
+build_range_exp (const reg_syntax_t syntax,
+ bitset_t sbcset,
+ const bracket_elem_t *start_elem,
+ const bracket_elem_t *end_elem)
+# endif /* not RE_ENABLE_I18N */
+{
+ unsigned int start_ch, end_ch;
+ /* Equivalence Classes and Character Classes can't be a range start/end. */
+ if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
+ || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS,
+ 0))
+ return REG_ERANGE;
+
+ /* We can handle no multi character collating elements without libc
+ support. */
+ if (BE ((start_elem->type == COLL_SYM
+ && strlen ((char *) start_elem->opr.name) > 1)
+ || (end_elem->type == COLL_SYM
+ && strlen ((char *) end_elem->opr.name) > 1), 0))
+ return REG_ECOLLATE;
+
+# ifdef RE_ENABLE_I18N
+ {
+ wchar_t wc;
+ wint_t start_wc;
+ wint_t end_wc;
+ wchar_t cmp_buf[6] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
+
+ start_ch = ((start_elem->type == SB_CHAR) ? start_elem->opr.ch
+ : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
+ : 0));
+ end_ch = ((end_elem->type == SB_CHAR) ? end_elem->opr.ch
+ : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
+ : 0));
+ start_wc = ((start_elem->type == SB_CHAR || start_elem->type == COLL_SYM)
+ ? __btowc (start_ch) : start_elem->opr.wch);
+ end_wc = ((end_elem->type == SB_CHAR || end_elem->type == COLL_SYM)
+ ? __btowc (end_ch) : end_elem->opr.wch);
+ if (start_wc == WEOF || end_wc == WEOF)
+ return REG_ECOLLATE;
+ cmp_buf[0] = start_wc;
+ cmp_buf[4] = end_wc;
+
+ if (BE ((syntax & RE_NO_EMPTY_RANGES)
+ && wcscoll (cmp_buf, cmp_buf + 4) > 0, 0))
+ return REG_ERANGE;
+
+ /* Got valid collation sequence values, add them as a new entry.
+ However, for !_LIBC we have no collation elements: if the
+ character set is single byte, the single byte character set
+ that we build below suffices. parse_bracket_exp passes
+ no MBCSET if dfa->mb_cur_max == 1. */
+ if (mbcset)
+ {
+ /* Check the space of the arrays. */
+ if (BE (*range_alloc == mbcset->nranges, 0))
+ {
+ /* There is not enough space, need realloc. */
+ wchar_t *new_array_start, *new_array_end;
+ Idx new_nranges;
+
+ /* +1 in case of mbcset->nranges is 0. */
+ new_nranges = 2 * mbcset->nranges + 1;
+ /* Use realloc since mbcset->range_starts and mbcset->range_ends
+ are NULL if *range_alloc == 0. */
+ new_array_start = re_realloc (mbcset->range_starts, wchar_t,
+ new_nranges);
+ new_array_end = re_realloc (mbcset->range_ends, wchar_t,
+ new_nranges);
+
+ if (BE (new_array_start == NULL || new_array_end == NULL, 0))
+ return REG_ESPACE;
+
+ mbcset->range_starts = new_array_start;
+ mbcset->range_ends = new_array_end;
+ *range_alloc = new_nranges;
+ }
+
+ mbcset->range_starts[mbcset->nranges] = start_wc;
+ mbcset->range_ends[mbcset->nranges++] = end_wc;
+ }
+
+ /* Build the table for single byte characters. */
+ for (wc = 0; wc < SBC_MAX; ++wc)
+ {
+ cmp_buf[2] = wc;
+ if (wcscoll (cmp_buf, cmp_buf + 2) <= 0
+ && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0)
+ bitset_set (sbcset, wc);
+ }
+ }
+# else /* not RE_ENABLE_I18N */
+ {
+ unsigned int ch;
+ start_ch = ((start_elem->type == SB_CHAR ) ? start_elem->opr.ch
+ : ((start_elem->type == COLL_SYM) ? start_elem->opr.name[0]
+ : 0));
+ end_ch = ((end_elem->type == SB_CHAR ) ? end_elem->opr.ch
+ : ((end_elem->type == COLL_SYM) ? end_elem->opr.name[0]
+ : 0));
+ if (start_ch > end_ch)
+ return REG_ERANGE;
+ /* Build the table for single byte characters. */
+ for (ch = 0; ch < SBC_MAX; ++ch)
+ if (start_ch <= ch && ch <= end_ch)
+ bitset_set (sbcset, ch);
+ }
+# endif /* not RE_ENABLE_I18N */
+ return REG_NOERROR;
+}
+#endif /* not _LIBC */
+
+#ifndef _LIBC
+/* Helper function for parse_bracket_exp only used in case of NOT _LIBC..
+ Build the collating element which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
+ pointer argument since we may update it. */
+
+static reg_errcode_t
+internal_function
+build_collating_symbol (bitset_t sbcset,
+# ifdef RE_ENABLE_I18N
+ re_charset_t *mbcset, Idx *coll_sym_alloc,
+# endif
+ const unsigned char *name)
+{
+ size_t name_len = strlen ((const char *) name);
+ if (BE (name_len != 1, 0))
+ return REG_ECOLLATE;
+ else
+ {
+ bitset_set (sbcset, name[0]);
+ return REG_NOERROR;
+ }
+}
+#endif /* not _LIBC */
+
+/* This function parse bracket expression like "[abc]", "[a-c]",
+ "[[.a-a.]]" etc. */
+
+static bin_tree_t *
+parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
+ reg_syntax_t syntax, reg_errcode_t *err)
+{
+#ifdef _LIBC
+ const unsigned char *collseqmb;
+ const char *collseqwc;
+ uint32_t nrules;
+ int32_t table_size;
+ const int32_t *symb_table;
+ const unsigned char *extra;
+
+ /* Local function for parse_bracket_exp used in _LIBC environement.
+ Seek the collating symbol entry correspondings to NAME.
+ Return the index of the symbol in the SYMB_TABLE. */
+
+ auto inline int32_t
+ __attribute ((always_inline))
+ seek_collating_symbol_entry (name, name_len)
+ const unsigned char *name;
+ size_t name_len;
+ {
+ int32_t hash = elem_hash ((const char *) name, name_len);
+ int32_t elem = hash % table_size;
+ if (symb_table[2 * elem] != 0)
+ {
+ int32_t second = hash % (table_size - 2) + 1;
+
+ do
+ {
+ /* First compare the hashing value. */
+ if (symb_table[2 * elem] == hash
+ /* Compare the length of the name. */
+ && name_len == extra[symb_table[2 * elem + 1]]
+ /* Compare the name. */
+ && memcmp (name, &extra[symb_table[2 * elem + 1] + 1],
+ name_len) == 0)
+ {
+ /* Yep, this is the entry. */
+ break;
+ }
+
+ /* Next entry. */
+ elem += second;
+ }
+ while (symb_table[2 * elem] != 0);
+ }
+ return elem;
+ }
+
+ /* Local function for parse_bracket_exp used in _LIBC environment.
+ Look up the collation sequence value of BR_ELEM.
+ Return the value if succeeded, UINT_MAX otherwise. */
+
+ auto inline unsigned int
+ __attribute ((always_inline))
+ lookup_collation_sequence_value (br_elem)
+ bracket_elem_t *br_elem;
+ {
+ if (br_elem->type == SB_CHAR)
+ {
+ /*
+ if (MB_CUR_MAX == 1)
+ */
+ if (nrules == 0)
+ return collseqmb[br_elem->opr.ch];
+ else
+ {
+ wint_t wc = __btowc (br_elem->opr.ch);
+ return __collseq_table_lookup (collseqwc, wc);
+ }
+ }
+ else if (br_elem->type == MB_CHAR)
+ {
+ if (nrules != 0)
+ return __collseq_table_lookup (collseqwc, br_elem->opr.wch);
+ }
+ else if (br_elem->type == COLL_SYM)
+ {
+ size_t sym_name_len = strlen ((char *) br_elem->opr.name);
+ if (nrules != 0)
+ {
+ int32_t elem, idx;
+ elem = seek_collating_symbol_entry (br_elem->opr.name,
+ sym_name_len);
+ if (symb_table[2 * elem] != 0)
+ {
+ /* We found the entry. */
+ idx = symb_table[2 * elem + 1];
+ /* Skip the name of collating element name. */
+ idx += 1 + extra[idx];
+ /* Skip the byte sequence of the collating element. */
+ idx += 1 + extra[idx];
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
+ /* Skip the multibyte collation sequence value. */
+ idx += sizeof (unsigned int);
+ /* Skip the wide char sequence of the collating element. */
+ idx += sizeof (unsigned int) *
+ (1 + *(unsigned int *) (extra + idx));
+ /* Return the collation sequence value. */
+ return *(unsigned int *) (extra + idx);
+ }
+ else if (symb_table[2 * elem] == 0 && sym_name_len == 1)
+ {
+ /* No valid character. Match it as a single byte
+ character. */
+ return collseqmb[br_elem->opr.name[0]];
+ }
+ }
+ else if (sym_name_len == 1)
+ return collseqmb[br_elem->opr.name[0]];
+ }
+ return UINT_MAX;
+ }
+
+ /* Local function for parse_bracket_exp used in _LIBC environement.
+ Build the range expression which starts from START_ELEM, and ends
+ at END_ELEM. The result are written to MBCSET and SBCSET.
+ RANGE_ALLOC is the allocated size of mbcset->range_starts, and
+ mbcset->range_ends, is a pointer argument sinse we may
+ update it. */
+
+ auto inline reg_errcode_t
+ __attribute ((always_inline))
+ build_range_exp (sbcset, mbcset, range_alloc, start_elem, end_elem)
+ re_charset_t *mbcset;
+ Idx *range_alloc;
+ bitset_t sbcset;
+ bracket_elem_t *start_elem, *end_elem;
+ {
+ unsigned int ch;
+ uint32_t start_collseq;
+ uint32_t end_collseq;
+
+ /* Equivalence Classes and Character Classes can't be a range
+ start/end. */
+ if (BE (start_elem->type == EQUIV_CLASS || start_elem->type == CHAR_CLASS
+ || end_elem->type == EQUIV_CLASS || end_elem->type == CHAR_CLASS,
+ 0))
+ return REG_ERANGE;
+
+ start_collseq = lookup_collation_sequence_value (start_elem);
+ end_collseq = lookup_collation_sequence_value (end_elem);
+ /* Check start/end collation sequence values. */
+ if (BE (start_collseq == UINT_MAX || end_collseq == UINT_MAX, 0))
+ return REG_ECOLLATE;
+ if (BE ((syntax & RE_NO_EMPTY_RANGES) && start_collseq > end_collseq, 0))
+ return REG_ERANGE;
+
+ /* Got valid collation sequence values, add them as a new entry.
+ However, if we have no collation elements, and the character set
+ is single byte, the single byte character set that we
+ build below suffices. */
+ if (nrules > 0 || dfa->mb_cur_max > 1)
+ {
+ /* Check the space of the arrays. */
+ if (BE (*range_alloc == mbcset->nranges, 0))
+ {
+ /* There is not enough space, need realloc. */
+ uint32_t *new_array_start;
+ uint32_t *new_array_end;
+ Idx new_nranges;
+
+ /* +1 in case of mbcset->nranges is 0. */
+ new_nranges = 2 * mbcset->nranges + 1;
+ new_array_start = re_realloc (mbcset->range_starts, uint32_t,
+ new_nranges);
+ new_array_end = re_realloc (mbcset->range_ends, uint32_t,
+ new_nranges);
+
+ if (BE (new_array_start == NULL || new_array_end == NULL, 0))
+ return REG_ESPACE;
+
+ mbcset->range_starts = new_array_start;
+ mbcset->range_ends = new_array_end;
+ *range_alloc = new_nranges;
+ }
+
+ mbcset->range_starts[mbcset->nranges] = start_collseq;
+ mbcset->range_ends[mbcset->nranges++] = end_collseq;
+ }
+
+ /* Build the table for single byte characters. */
+ for (ch = 0; ch < SBC_MAX; ch++)
+ {
+ uint32_t ch_collseq;
+ /*
+ if (MB_CUR_MAX == 1)
+ */
+ if (nrules == 0)
+ ch_collseq = collseqmb[ch];
+ else
+ ch_collseq = __collseq_table_lookup (collseqwc, __btowc (ch));
+ if (start_collseq <= ch_collseq && ch_collseq <= end_collseq)
+ bitset_set (sbcset, ch);
+ }
+ return REG_NOERROR;
+ }
+
+ /* Local function for parse_bracket_exp used in _LIBC environement.
+ Build the collating element which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a
+ pointer argument sinse we may update it. */
+
+ auto inline reg_errcode_t
+ __attribute ((always_inline))
+ build_collating_symbol (sbcset, mbcset, coll_sym_alloc, name)
+ re_charset_t *mbcset;
+ Idx *coll_sym_alloc;
+ bitset_t sbcset;
+ const unsigned char *name;
+ {
+ int32_t elem, idx;
+ size_t name_len = strlen ((const char *) name);
+ if (nrules != 0)
+ {
+ elem = seek_collating_symbol_entry (name, name_len);
+ if (symb_table[2 * elem] != 0)
+ {
+ /* We found the entry. */
+ idx = symb_table[2 * elem + 1];
+ /* Skip the name of collating element name. */
+ idx += 1 + extra[idx];
+ }
+ else if (symb_table[2 * elem] == 0 && name_len == 1)
+ {
+ /* No valid character, treat it as a normal
+ character. */
+ bitset_set (sbcset, name[0]);
+ return REG_NOERROR;
+ }
+ else
+ return REG_ECOLLATE;
+
+ /* Got valid collation sequence, add it as a new entry. */
+ /* Check the space of the arrays. */
+ if (BE (*coll_sym_alloc == mbcset->ncoll_syms, 0))
+ {
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->ncoll_syms is 0. */
+ Idx new_coll_sym_alloc = 2 * mbcset->ncoll_syms + 1;
+ /* Use realloc since mbcset->coll_syms is NULL
+ if *alloc == 0. */
+ int32_t *new_coll_syms = re_realloc (mbcset->coll_syms, int32_t,
+ new_coll_sym_alloc);
+ if (BE (new_coll_syms == NULL, 0))
+ return REG_ESPACE;
+ mbcset->coll_syms = new_coll_syms;
+ *coll_sym_alloc = new_coll_sym_alloc;
+ }
+ mbcset->coll_syms[mbcset->ncoll_syms++] = idx;
+ return REG_NOERROR;
+ }
+ else
+ {
+ if (BE (name_len != 1, 0))
+ return REG_ECOLLATE;
+ else
+ {
+ bitset_set (sbcset, name[0]);
+ return REG_NOERROR;
+ }
+ }
+ }
+#endif
+
+ re_token_t br_token;
+ re_bitset_ptr_t sbcset;
+#ifdef RE_ENABLE_I18N
+ re_charset_t *mbcset;
+ Idx coll_sym_alloc = 0, range_alloc = 0, mbchar_alloc = 0;
+ Idx equiv_class_alloc = 0, char_class_alloc = 0;
+#endif /* not RE_ENABLE_I18N */
+ bool non_match = false;
+ bin_tree_t *work_tree;
+ int token_len;
+ bool first_round = true;
+#ifdef _LIBC
+ collseqmb = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
+ nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules)
+ {
+ /*
+ if (MB_CUR_MAX > 1)
+ */
+ collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
+ table_size = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZEMB);
+ symb_table = (const int32_t *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_TABLEMB);
+ extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_SYMB_EXTRAMB);
+ }
+#endif
+ sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
+#ifdef RE_ENABLE_I18N
+ mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
+#endif /* RE_ENABLE_I18N */
+#ifdef RE_ENABLE_I18N
+ if (BE (sbcset == NULL || mbcset == NULL, 0))
+#else
+ if (BE (sbcset == NULL, 0))
+#endif /* RE_ENABLE_I18N */
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ token_len = peek_token_bracket (token, regexp, syntax);
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_BADPAT;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token->type == OP_NON_MATCH_LIST)
+ {
+#ifdef RE_ENABLE_I18N
+ mbcset->non_match = 1;
+#endif /* not RE_ENABLE_I18N */
+ non_match = true;
+ if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
+ bitset_set (sbcset, '\n');
+ re_string_skip_bytes (regexp, token_len); /* Skip a token. */
+ token_len = peek_token_bracket (token, regexp, syntax);
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_BADPAT;
+ goto parse_bracket_exp_free_return;
+ }
+ }
+
+ /* We treat the first ']' as a normal character. */
+ if (token->type == OP_CLOSE_BRACKET)
+ token->type = CHARACTER;
+
+ while (1)
+ {
+ bracket_elem_t start_elem, end_elem;
+ unsigned char start_name_buf[BRACKET_NAME_BUF_SIZE];
+ unsigned char end_name_buf[BRACKET_NAME_BUF_SIZE];
+ reg_errcode_t ret;
+ int token_len2 = 0;
+ bool is_range_exp = false;
+ re_token_t token2;
+
+ start_elem.opr.name = start_name_buf;
+ ret = parse_bracket_element (&start_elem, regexp, token, token_len, dfa,
+ syntax, first_round);
+ if (BE (ret != REG_NOERROR, 0))
+ {
+ *err = ret;
+ goto parse_bracket_exp_free_return;
+ }
+ first_round = false;
+
+ /* Get information about the next token. We need it in any case. */
+ token_len = peek_token_bracket (token, regexp, syntax);
+
+ /* Do not check for ranges if we know they are not allowed. */
+ if (start_elem.type != CHAR_CLASS && start_elem.type != EQUIV_CLASS)
+ {
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_EBRACK;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token->type == OP_CHARSET_RANGE)
+ {
+ re_string_skip_bytes (regexp, token_len); /* Skip '-'. */
+ token_len2 = peek_token_bracket (&token2, regexp, syntax);
+ if (BE (token2.type == END_OF_RE, 0))
+ {
+ *err = REG_EBRACK;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token2.type == OP_CLOSE_BRACKET)
+ {
+ /* We treat the last '-' as a normal character. */
+ re_string_skip_bytes (regexp, -token_len);
+ token->type = CHARACTER;
+ }
+ else
+ is_range_exp = true;
+ }
+ }
+
+ if (is_range_exp == true)
+ {
+ end_elem.opr.name = end_name_buf;
+ ret = parse_bracket_element (&end_elem, regexp, &token2, token_len2,
+ dfa, syntax, true);
+ if (BE (ret != REG_NOERROR, 0))
+ {
+ *err = ret;
+ goto parse_bracket_exp_free_return;
+ }
+
+ token_len = peek_token_bracket (token, regexp, syntax);
+
+#ifdef _LIBC
+ *err = build_range_exp (sbcset, mbcset, &range_alloc,
+ &start_elem, &end_elem);
+#else
+# ifdef RE_ENABLE_I18N
+ *err = build_range_exp (syntax, sbcset,
+ dfa->mb_cur_max > 1 ? mbcset : NULL,
+ &range_alloc, &start_elem, &end_elem);
+# else
+ *err = build_range_exp (syntax, sbcset, &start_elem, &end_elem);
+# endif
+#endif /* RE_ENABLE_I18N */
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ }
+ else
+ {
+ switch (start_elem.type)
+ {
+ case SB_CHAR:
+ bitset_set (sbcset, start_elem.opr.ch);
+ break;
+#ifdef RE_ENABLE_I18N
+ case MB_CHAR:
+ /* Check whether the array has enough space. */
+ if (BE (mbchar_alloc == mbcset->nmbchars, 0))
+ {
+ wchar_t *new_mbchars;
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->nmbchars is 0. */
+ mbchar_alloc = 2 * mbcset->nmbchars + 1;
+ /* Use realloc since array is NULL if *alloc == 0. */
+ new_mbchars = re_realloc (mbcset->mbchars, wchar_t,
+ mbchar_alloc);
+ if (BE (new_mbchars == NULL, 0))
+ goto parse_bracket_exp_espace;
+ mbcset->mbchars = new_mbchars;
+ }
+ mbcset->mbchars[mbcset->nmbchars++] = start_elem.opr.wch;
+ break;
+#endif /* RE_ENABLE_I18N */
+ case EQUIV_CLASS:
+ *err = build_equiv_class (sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &equiv_class_alloc,
+#endif /* RE_ENABLE_I18N */
+ start_elem.opr.name);
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ break;
+ case COLL_SYM:
+ *err = build_collating_symbol (sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &coll_sym_alloc,
+#endif /* RE_ENABLE_I18N */
+ start_elem.opr.name);
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ break;
+ case CHAR_CLASS:
+ *err = build_charclass (regexp->trans, sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &char_class_alloc,
+#endif /* RE_ENABLE_I18N */
+ start_elem.opr.name, syntax);
+ if (BE (*err != REG_NOERROR, 0))
+ goto parse_bracket_exp_free_return;
+ break;
+ default:
+ assert (0);
+ break;
+ }
+ }
+ if (BE (token->type == END_OF_RE, 0))
+ {
+ *err = REG_EBRACK;
+ goto parse_bracket_exp_free_return;
+ }
+ if (token->type == OP_CLOSE_BRACKET)
+ break;
+ }
+
+ re_string_skip_bytes (regexp, token_len); /* Skip a token. */
+
+ /* If it is non-matching list. */
+ if (non_match)
+ bitset_not (sbcset);
+
+#ifdef RE_ENABLE_I18N
+ /* Ensure only single byte characters are set. */
+ if (dfa->mb_cur_max > 1)
+ bitset_mask (sbcset, dfa->sb_char);
+
+ if (mbcset->nmbchars || mbcset->ncoll_syms || mbcset->nequiv_classes
+ || mbcset->nranges || (dfa->mb_cur_max > 1 && (mbcset->nchar_classes
+ || mbcset->non_match)))
+ {
+ bin_tree_t *mbc_tree;
+ int sbc_idx;
+ /* Build a tree for complex bracket. */
+ dfa->has_mb_node = 1;
+ br_token.type = COMPLEX_BRACKET;
+ br_token.opr.mbcset = mbcset;
+ mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (mbc_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+ for (sbc_idx = 0; sbc_idx < BITSET_WORDS; ++sbc_idx)
+ if (sbcset[sbc_idx])
+ break;
+ /* If there are no bits set in sbcset, there is no point
+ of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */
+ if (sbc_idx < BITSET_WORDS)
+ {
+ /* Build a tree for simple bracket. */
+ br_token.type = SIMPLE_BRACKET;
+ br_token.opr.sbcset = sbcset;
+ work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (work_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+
+ /* Then join them by ALT node. */
+ work_tree = create_tree (dfa, work_tree, mbc_tree, OP_ALT);
+ if (BE (work_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+ }
+ else
+ {
+ re_free (sbcset);
+ work_tree = mbc_tree;
+ }
+ }
+ else
+#endif /* not RE_ENABLE_I18N */
+ {
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif
+ /* Build a tree for simple bracket. */
+ br_token.type = SIMPLE_BRACKET;
+ br_token.opr.sbcset = sbcset;
+ work_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (work_tree == NULL, 0))
+ goto parse_bracket_exp_espace;
+ }
+ return work_tree;
+
+ parse_bracket_exp_espace:
+ *err = REG_ESPACE;
+ parse_bracket_exp_free_return:
+ re_free (sbcset);
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif /* RE_ENABLE_I18N */
+ return NULL;
+}
+
+/* Parse an element in the bracket expression. */
+
+static reg_errcode_t
+parse_bracket_element (bracket_elem_t *elem, re_string_t *regexp,
+ re_token_t *token, int token_len, re_dfa_t *dfa,
+ reg_syntax_t syntax, bool accept_hyphen)
+{
+#ifdef RE_ENABLE_I18N
+ int cur_char_size;
+ cur_char_size = re_string_char_size_at (regexp, re_string_cur_idx (regexp));
+ if (cur_char_size > 1)
+ {
+ elem->type = MB_CHAR;
+ elem->opr.wch = re_string_wchar_at (regexp, re_string_cur_idx (regexp));
+ re_string_skip_bytes (regexp, cur_char_size);
+ return REG_NOERROR;
+ }
+#endif /* RE_ENABLE_I18N */
+ re_string_skip_bytes (regexp, token_len); /* Skip a token. */
+ if (token->type == OP_OPEN_COLL_ELEM || token->type == OP_OPEN_CHAR_CLASS
+ || token->type == OP_OPEN_EQUIV_CLASS)
+ return parse_bracket_symbol (elem, regexp, token);
+ if (BE (token->type == OP_CHARSET_RANGE, 0) && !accept_hyphen)
+ {
+ /* A '-' must only appear as anything but a range indicator before
+ the closing bracket. Everything else is an error. */
+ re_token_t token2;
+ (void) peek_token_bracket (&token2, regexp, syntax);
+ if (token2.type != OP_CLOSE_BRACKET)
+ /* The actual error value is not standardized since this whole
+ case is undefined. But ERANGE makes good sense. */
+ return REG_ERANGE;
+ }
+ elem->type = SB_CHAR;
+ elem->opr.ch = token->opr.c;
+ return REG_NOERROR;
+}
+
+/* Parse a bracket symbol in the bracket expression. Bracket symbols are
+ such as [:<character_class>:], [.<collating_element>.], and
+ [=<equivalent_class>=]. */
+
+static reg_errcode_t
+parse_bracket_symbol (bracket_elem_t *elem, re_string_t *regexp,
+ re_token_t *token)
+{
+ unsigned char ch, delim = token->opr.c;
+ int i = 0;
+ if (re_string_eoi(regexp))
+ return REG_EBRACK;
+ for (;; ++i)
+ {
+ if (i >= BRACKET_NAME_BUF_SIZE)
+ return REG_EBRACK;
+ if (token->type == OP_OPEN_CHAR_CLASS)
+ ch = re_string_fetch_byte_case (regexp);
+ else
+ ch = re_string_fetch_byte (regexp);
+ if (re_string_eoi(regexp))
+ return REG_EBRACK;
+ if (ch == delim && re_string_peek_byte (regexp, 0) == ']')
+ break;
+ elem->opr.name[i] = ch;
+ }
+ re_string_skip_bytes (regexp, 1);
+ elem->opr.name[i] = '\0';
+ switch (token->type)
+ {
+ case OP_OPEN_COLL_ELEM:
+ elem->type = COLL_SYM;
+ break;
+ case OP_OPEN_EQUIV_CLASS:
+ elem->type = EQUIV_CLASS;
+ break;
+ case OP_OPEN_CHAR_CLASS:
+ elem->type = CHAR_CLASS;
+ break;
+ default:
+ break;
+ }
+ return REG_NOERROR;
+}
+
+ /* Helper function for parse_bracket_exp.
+ Build the equivalence class which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ EQUIV_CLASS_ALLOC is the allocated size of mbcset->equiv_classes,
+ is a pointer argument sinse we may update it. */
+
+static reg_errcode_t
+#ifdef RE_ENABLE_I18N
+build_equiv_class (bitset_t sbcset, re_charset_t *mbcset,
+ Idx *equiv_class_alloc, const unsigned char *name)
+#else /* not RE_ENABLE_I18N */
+build_equiv_class (bitset_t sbcset, const unsigned char *name)
+#endif /* not RE_ENABLE_I18N */
+{
+#ifdef _LIBC
+ uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules != 0)
+ {
+ const int32_t *table, *indirect;
+ const unsigned char *weights, *extra, *cp;
+ unsigned char char_buf[2];
+ int32_t idx1, idx2;
+ unsigned int ch;
+ size_t len;
+ /* This #include defines a local function! */
+# include <locale/weight.h>
+ /* Calculate the index for equivalence class. */
+ cp = name;
+ table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ weights = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_WEIGHTMB);
+ extra = (const unsigned char *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_EXTRAMB);
+ indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_INDIRECTMB);
+ idx1 = findidx (&cp);
+ if (BE (idx1 == 0 || cp < name + strlen ((const char *) name), 0))
+ /* This isn't a valid character. */
+ return REG_ECOLLATE;
+
+ /* Build single byte matcing table for this equivalence class. */
+ char_buf[1] = (unsigned char) '\0';
+ len = weights[idx1 & 0xffffff];
+ for (ch = 0; ch < SBC_MAX; ++ch)
+ {
+ char_buf[0] = ch;
+ cp = char_buf;
+ idx2 = findidx (&cp);
+/*
+ idx2 = table[ch];
+*/
+ if (idx2 == 0)
+ /* This isn't a valid character. */
+ continue;
+ /* Compare only if the length matches and the collation rule
+ index is the same. */
+ if (len == weights[idx2 & 0xffffff] && (idx1 >> 24) == (idx2 >> 24))
+ {
+ int cnt = 0;
+
+ while (cnt <= len &&
+ weights[(idx1 & 0xffffff) + 1 + cnt]
+ == weights[(idx2 & 0xffffff) + 1 + cnt])
+ ++cnt;
+
+ if (cnt > len)
+ bitset_set (sbcset, ch);
+ }
+ }
+ /* Check whether the array has enough space. */
+ if (BE (*equiv_class_alloc == mbcset->nequiv_classes, 0))
+ {
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->nequiv_classes is 0. */
+ Idx new_equiv_class_alloc = 2 * mbcset->nequiv_classes + 1;
+ /* Use realloc since the array is NULL if *alloc == 0. */
+ int32_t *new_equiv_classes = re_realloc (mbcset->equiv_classes,
+ int32_t,
+ new_equiv_class_alloc);
+ if (BE (new_equiv_classes == NULL, 0))
+ return REG_ESPACE;
+ mbcset->equiv_classes = new_equiv_classes;
+ *equiv_class_alloc = new_equiv_class_alloc;
+ }
+ mbcset->equiv_classes[mbcset->nequiv_classes++] = idx1;
+ }
+ else
+#endif /* _LIBC */
+ {
+ if (BE (strlen ((const char *) name) != 1, 0))
+ return REG_ECOLLATE;
+ bitset_set (sbcset, *name);
+ }
+ return REG_NOERROR;
+}
+
+ /* Helper function for parse_bracket_exp.
+ Build the character class which is represented by NAME.
+ The result are written to MBCSET and SBCSET.
+ CHAR_CLASS_ALLOC is the allocated size of mbcset->char_classes,
+ is a pointer argument sinse we may update it. */
+
+static reg_errcode_t
+#ifdef RE_ENABLE_I18N
+build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
+ re_charset_t *mbcset, Idx *char_class_alloc,
+ const unsigned char *class_name, reg_syntax_t syntax)
+#else /* not RE_ENABLE_I18N */
+build_charclass (RE_TRANSLATE_TYPE trans, bitset_t sbcset,
+ const unsigned char *class_name, reg_syntax_t syntax)
+#endif /* not RE_ENABLE_I18N */
+{
+ int i;
+ const char *name = (const char *) class_name;
+
+ /* In case of REG_ICASE "upper" and "lower" match the both of
+ upper and lower cases. */
+ if ((syntax & RE_ICASE)
+ && (strcmp (name, "upper") == 0 || strcmp (name, "lower") == 0))
+ name = "alpha";
+
+#ifdef RE_ENABLE_I18N
+ /* Check the space of the arrays. */
+ if (BE (*char_class_alloc == mbcset->nchar_classes, 0))
+ {
+ /* Not enough, realloc it. */
+ /* +1 in case of mbcset->nchar_classes is 0. */
+ Idx new_char_class_alloc = 2 * mbcset->nchar_classes + 1;
+ /* Use realloc since array is NULL if *alloc == 0. */
+ wctype_t *new_char_classes = re_realloc (mbcset->char_classes, wctype_t,
+ new_char_class_alloc);
+ if (BE (new_char_classes == NULL, 0))
+ return REG_ESPACE;
+ mbcset->char_classes = new_char_classes;
+ *char_class_alloc = new_char_class_alloc;
+ }
+ mbcset->char_classes[mbcset->nchar_classes++] = __wctype (name);
+#endif /* RE_ENABLE_I18N */
+
+#define BUILD_CHARCLASS_LOOP(ctype_func) \
+ do { \
+ if (BE (trans != NULL, 0)) \
+ { \
+ for (i = 0; i < SBC_MAX; ++i) \
+ if (ctype_func (i)) \
+ bitset_set (sbcset, trans[i]); \
+ } \
+ else \
+ { \
+ for (i = 0; i < SBC_MAX; ++i) \
+ if (ctype_func (i)) \
+ bitset_set (sbcset, i); \
+ } \
+ } while (0)
+
+ if (strcmp (name, "alnum") == 0)
+ BUILD_CHARCLASS_LOOP (isalnum);
+ else if (strcmp (name, "cntrl") == 0)
+ BUILD_CHARCLASS_LOOP (iscntrl);
+ else if (strcmp (name, "lower") == 0)
+ BUILD_CHARCLASS_LOOP (islower);
+ else if (strcmp (name, "space") == 0)
+ BUILD_CHARCLASS_LOOP (isspace);
+ else if (strcmp (name, "alpha") == 0)
+ BUILD_CHARCLASS_LOOP (isalpha);
+ else if (strcmp (name, "digit") == 0)
+ BUILD_CHARCLASS_LOOP (isdigit);
+ else if (strcmp (name, "print") == 0)
+ BUILD_CHARCLASS_LOOP (isprint);
+ else if (strcmp (name, "upper") == 0)
+ BUILD_CHARCLASS_LOOP (isupper);
+ else if (strcmp (name, "blank") == 0)
+ BUILD_CHARCLASS_LOOP (isblank);
+ else if (strcmp (name, "graph") == 0)
+ BUILD_CHARCLASS_LOOP (isgraph);
+ else if (strcmp (name, "punct") == 0)
+ BUILD_CHARCLASS_LOOP (ispunct);
+ else if (strcmp (name, "xdigit") == 0)
+ BUILD_CHARCLASS_LOOP (isxdigit);
+ else
+ return REG_ECTYPE;
+
+ return REG_NOERROR;
+}
+
+static bin_tree_t *
+build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
+ const unsigned char *class_name,
+ const unsigned char *extra, bool non_match,
+ reg_errcode_t *err)
+{
+ re_bitset_ptr_t sbcset;
+#ifdef RE_ENABLE_I18N
+ re_charset_t *mbcset;
+ Idx alloc = 0;
+#endif /* not RE_ENABLE_I18N */
+ reg_errcode_t ret;
+ re_token_t br_token;
+ bin_tree_t *tree;
+
+ sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
+#ifdef RE_ENABLE_I18N
+ mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
+#endif /* RE_ENABLE_I18N */
+
+#ifdef RE_ENABLE_I18N
+ if (BE (sbcset == NULL || mbcset == NULL, 0))
+#else /* not RE_ENABLE_I18N */
+ if (BE (sbcset == NULL, 0))
+#endif /* not RE_ENABLE_I18N */
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ if (non_match)
+ {
+#ifdef RE_ENABLE_I18N
+ mbcset->non_match = 1;
+#endif /* not RE_ENABLE_I18N */
+ }
+
+ /* We don't care the syntax in this case. */
+ ret = build_charclass (trans, sbcset,
+#ifdef RE_ENABLE_I18N
+ mbcset, &alloc,
+#endif /* RE_ENABLE_I18N */
+ class_name, 0);
+
+ if (BE (ret != REG_NOERROR, 0))
+ {
+ re_free (sbcset);
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif /* RE_ENABLE_I18N */
+ *err = ret;
+ return NULL;
+ }
+ /* \w match '_' also. */
+ for (; *extra; extra++)
+ bitset_set (sbcset, *extra);
+
+ /* If it is non-matching list. */
+ if (non_match)
+ bitset_not (sbcset);
+
+#ifdef RE_ENABLE_I18N
+ /* Ensure only single byte characters are set. */
+ if (dfa->mb_cur_max > 1)
+ bitset_mask (sbcset, dfa->sb_char);
+#endif
+
+ /* Build a tree for simple bracket. */
+ br_token.type = SIMPLE_BRACKET;
+ br_token.opr.sbcset = sbcset;
+ tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (tree == NULL, 0))
+ goto build_word_op_espace;
+
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ bin_tree_t *mbc_tree;
+ /* Build a tree for complex bracket. */
+ br_token.type = COMPLEX_BRACKET;
+ br_token.opr.mbcset = mbcset;
+ dfa->has_mb_node = 1;
+ mbc_tree = create_token_tree (dfa, NULL, NULL, &br_token);
+ if (BE (mbc_tree == NULL, 0))
+ goto build_word_op_espace;
+ /* Then join them by ALT node. */
+ tree = create_tree (dfa, tree, mbc_tree, OP_ALT);
+ if (BE (mbc_tree != NULL, 1))
+ return tree;
+ }
+ else
+ {
+ free_charset (mbcset);
+ return tree;
+ }
+#else /* not RE_ENABLE_I18N */
+ return tree;
+#endif /* not RE_ENABLE_I18N */
+
+ build_word_op_espace:
+ re_free (sbcset);
+#ifdef RE_ENABLE_I18N
+ free_charset (mbcset);
+#endif /* RE_ENABLE_I18N */
+ *err = REG_ESPACE;
+ return NULL;
+}
+
+/* This is intended for the expressions like "a{1,3}".
+ Fetch a number from 'input', and return the number.
+ Return REG_MISSING if the number field is empty like "{,1}".
+ Return REG_ERROR if an error occurred. */
+
+static Idx
+fetch_number (re_string_t *input, re_token_t *token, reg_syntax_t syntax)
+{
+ Idx num = REG_MISSING;
+ unsigned char c;
+ while (1)
+ {
+ fetch_token (token, input, syntax);
+ c = token->opr.c;
+ if (BE (token->type == END_OF_RE, 0))
+ return REG_ERROR;
+ if (token->type == OP_CLOSE_DUP_NUM || c == ',')
+ break;
+ num = ((token->type != CHARACTER || c < '0' || '9' < c
+ || num == REG_ERROR)
+ ? REG_ERROR
+ : ((num == REG_MISSING) ? c - '0' : num * 10 + c - '0'));
+ num = (num > RE_DUP_MAX) ? REG_ERROR : num;
+ }
+ return num;
+}
+
+#ifdef RE_ENABLE_I18N
+static void
+free_charset (re_charset_t *cset)
+{
+ re_free (cset->mbchars);
+# ifdef _LIBC
+ re_free (cset->coll_syms);
+ re_free (cset->equiv_classes);
+ re_free (cset->range_starts);
+ re_free (cset->range_ends);
+# endif
+ re_free (cset->char_classes);
+ re_free (cset);
+}
+#endif /* RE_ENABLE_I18N */
+
+/* Functions for binary tree operation. */
+
+/* Create a tree node. */
+
+static bin_tree_t *
+create_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
+ re_token_type_t type)
+{
+ re_token_t t;
+ t.type = type;
+ return create_token_tree (dfa, left, right, &t);
+}
+
+static bin_tree_t *
+create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right,
+ const re_token_t *token)
+{
+ bin_tree_t *tree;
+ if (BE (dfa->str_tree_storage_idx == BIN_TREE_STORAGE_SIZE, 0))
+ {
+ bin_tree_storage_t *storage = re_malloc (bin_tree_storage_t, 1);
+
+ if (storage == NULL)
+ return NULL;
+ storage->next = dfa->str_tree_storage;
+ dfa->str_tree_storage = storage;
+ dfa->str_tree_storage_idx = 0;
+ }
+ tree = &dfa->str_tree_storage->data[dfa->str_tree_storage_idx++];
+
+ tree->parent = NULL;
+ tree->left = left;
+ tree->right = right;
+ tree->token = *token;
+ tree->token.duplicated = 0;
+ tree->token.opt_subexp = 0;
+ tree->first = NULL;
+ tree->next = NULL;
+ tree->node_idx = REG_MISSING;
+
+ if (left != NULL)
+ left->parent = tree;
+ if (right != NULL)
+ right->parent = tree;
+ return tree;
+}
+
+/* Mark the tree SRC as an optional subexpression.
+ To be called from preorder or postorder. */
+
+static reg_errcode_t
+mark_opt_subexp (void *extra, bin_tree_t *node)
+{
+ Idx idx = (Idx) (long) extra;
+ if (node->token.type == SUBEXP && node->token.opr.idx == idx)
+ node->token.opt_subexp = 1;
+
+ return REG_NOERROR;
+}
+
+/* Free the allocated memory inside NODE. */
+
+static void
+free_token (re_token_t *node)
+{
+#ifdef RE_ENABLE_I18N
+ if (node->type == COMPLEX_BRACKET && node->duplicated == 0)
+ free_charset (node->opr.mbcset);
+ else
+#endif /* RE_ENABLE_I18N */
+ if (node->type == SIMPLE_BRACKET && node->duplicated == 0)
+ re_free (node->opr.sbcset);
+}
+
+/* Worker function for tree walking. Free the allocated memory inside NODE
+ and its children. */
+
+static reg_errcode_t
+free_tree (void *extra, bin_tree_t *node)
+{
+ free_token (&node->token);
+ return REG_NOERROR;
+}
+
+
+/* Duplicate the node SRC, and return new node. This is a preorder
+ visit similar to the one implemented by the generic visitor, but
+ we need more infrastructure to maintain two parallel trees --- so,
+ it's easier to duplicate. */
+
+static bin_tree_t *
+duplicate_tree (const bin_tree_t *root, re_dfa_t *dfa)
+{
+ const bin_tree_t *node;
+ bin_tree_t *dup_root;
+ bin_tree_t **p_new = &dup_root, *dup_node = root->parent;
+
+ for (node = root; ; )
+ {
+ /* Create a new tree and link it back to the current parent. */
+ *p_new = create_token_tree (dfa, NULL, NULL, &node->token);
+ if (*p_new == NULL)
+ return NULL;
+ (*p_new)->parent = dup_node;
+ (*p_new)->token.duplicated = 1;
+ dup_node = *p_new;
+
+ /* Go to the left node, or up and to the right. */
+ if (node->left)
+ {
+ node = node->left;
+ p_new = &dup_node->left;
+ }
+ else
+ {
+ const bin_tree_t *prev = NULL;
+ while (node->right == prev || node->right == NULL)
+ {
+ prev = node;
+ node = node->parent;
+ dup_node = dup_node->parent;
+ if (!node)
+ return dup_root;
+ }
+ node = node->right;
+ p_new = &dup_node->right;
+ }
+ }
+}
diff --git a/lib/regex.c b/lib/regex.c
new file mode 100644
index 000000000..6e0f752b3
--- /dev/null
+++ b/lib/regex.c
@@ -0,0 +1,72 @@
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2003, 2005-2006, 2009-2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+/* Make sure noone compiles this code with a C++ compiler. */
+#if defined __cplusplus && defined _LIBC
+# error "This is C code, use a C compiler"
+#endif
+
+#ifdef _LIBC
+/* We have to keep the namespace clean. */
+# define regfree(preg) __regfree (preg)
+# define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
+# define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
+# define regerror(errcode, preg, errbuf, errbuf_size) \
+ __regerror(errcode, preg, errbuf, errbuf_size)
+# define re_set_registers(bu, re, nu, st, en) \
+ __re_set_registers (bu, re, nu, st, en)
+# define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
+ __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
+# define re_match(bufp, string, size, pos, regs) \
+ __re_match (bufp, string, size, pos, regs)
+# define re_search(bufp, string, size, startpos, range, regs) \
+ __re_search (bufp, string, size, startpos, range, regs)
+# define re_compile_pattern(pattern, length, bufp) \
+ __re_compile_pattern (pattern, length, bufp)
+# define re_set_syntax(syntax) __re_set_syntax (syntax)
+# define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
+ __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
+# define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
+
+# include "../locale/localeinfo.h"
+#endif
+
+/* On some systems, limits.h sets RE_DUP_MAX to a lower value than
+ GNU regex allows. Include it before <regex.h>, which correctly
+ #undefs RE_DUP_MAX and sets it to the right value. */
+#include <limits.h>
+#include <strings.h>
+
+#include <regex.h>
+#include "regex_internal.h"
+
+#include "regex_internal.c"
+#include "regcomp.c"
+#include "regexec.c"
+
+/* Binary backward compatibility. */
+#if _LIBC
+# include <shlib-compat.h>
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
+link_warning (re_max_failures, "the 're_max_failures' variable is obsolete and will go away.")
+int re_max_failures = 2000;
+# endif
+#endif
diff --git a/lib/regex.h b/lib/regex.h
new file mode 100644
index 000000000..b612adbf5
--- /dev/null
+++ b/lib/regex.h
@@ -0,0 +1,675 @@
+/* Definitions for data structures and routines for the regular
+ expression library.
+ Copyright (C) 1985, 1989-1993, 1995-1998, 2000-2003, 2005-2006, 2009-2012
+ Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _REGEX_H
+#define _REGEX_H 1
+
+#include <sys/types.h>
+
+/* Allow the use in C++ code. */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Define __USE_GNU_REGEX to declare GNU extensions that violate the
+ POSIX name space rules. */
+#undef __USE_GNU_REGEX
+#if (defined _GNU_SOURCE \
+ || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \
+ && !defined _XOPEN_SOURCE))
+# define __USE_GNU_REGEX 1
+#endif
+
+#ifdef _REGEX_LARGE_OFFSETS
+
+/* Use types and values that are wide enough to represent signed and
+ unsigned byte offsets in memory. This currently works only when
+ the regex code is used outside of the GNU C library; it is not yet
+ supported within glibc itself, and glibc users should not define
+ _REGEX_LARGE_OFFSETS. */
+
+/* The type of the offset of a byte within a string.
+ For historical reasons POSIX 1003.1-2004 requires that regoff_t be
+ at least as wide as off_t. However, many common POSIX platforms set
+ regoff_t to the more-sensible ssize_t and the Open Group has
+ signalled its intention to change the requirement to be that
+ regoff_t be at least as wide as ptrdiff_t and ssize_t; see XBD ERN
+ 60 (2005-08-25). We don't know of any hosts where ssize_t or
+ ptrdiff_t is wider than ssize_t, so ssize_t is safe. */
+typedef ssize_t regoff_t;
+
+/* The type of nonnegative object indexes. Traditionally, GNU regex
+ uses 'int' for these. Code that uses __re_idx_t should work
+ regardless of whether the type is signed. */
+typedef size_t __re_idx_t;
+
+/* The type of object sizes. */
+typedef size_t __re_size_t;
+
+/* The type of object sizes, in places where the traditional code
+ uses unsigned long int. */
+typedef size_t __re_long_size_t;
+
+#else
+
+/* Use types that are binary-compatible with the traditional GNU regex
+ implementation, which mishandles strings longer than INT_MAX. */
+
+typedef int regoff_t;
+typedef int __re_idx_t;
+typedef unsigned int __re_size_t;
+typedef unsigned long int __re_long_size_t;
+
+#endif
+
+/* The following two types have to be signed and unsigned integer type
+ wide enough to hold a value of a pointer. For most ANSI compilers
+ ptrdiff_t and size_t should be likely OK. Still size of these two
+ types is 2 for Microsoft C. Ugh... */
+typedef long int s_reg_t;
+typedef unsigned long int active_reg_t;
+
+/* The following bits are used to determine the regexp syntax we
+ recognize. The set/not-set meanings are chosen so that Emacs syntax
+ remains the value 0. The bits are given in alphabetical order, and
+ the definitions shifted by one from the previous bit; thus, when we
+ add or remove a bit, only one other definition need change. */
+typedef unsigned long int reg_syntax_t;
+
+#ifdef __USE_GNU_REGEX
+
+/* If this bit is not set, then \ inside a bracket expression is literal.
+ If set, then such a \ quotes the following character. */
+# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
+
+/* If this bit is not set, then + and ? are operators, and \+ and \? are
+ literals.
+ If set, then \+ and \? are operators and + and ? are literals. */
+# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
+
+/* If this bit is set, then character classes are supported. They are:
+ [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
+ [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
+ If not set, then character classes are not supported. */
+# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
+
+/* If this bit is set, then ^ and $ are always anchors (outside bracket
+ expressions, of course).
+ If this bit is not set, then it depends:
+ ^ is an anchor if it is at the beginning of a regular
+ expression or after an open-group or an alternation operator;
+ $ is an anchor if it is at the end of a regular expression, or
+ before a close-group or an alternation operator.
+
+ This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
+ POSIX draft 11.2 says that * etc. in leading positions is undefined.
+ We already implemented a previous draft which made those constructs
+ invalid, though, so we haven't changed the code back. */
+# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
+
+/* If this bit is set, then special characters are always special
+ regardless of where they are in the pattern.
+ If this bit is not set, then special characters are special only in
+ some contexts; otherwise they are ordinary. Specifically,
+ * + ? and intervals are only special when not after the beginning,
+ open-group, or alternation operator. */
+# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
+
+/* If this bit is set, then *, +, ?, and { cannot be first in an re or
+ immediately after an alternation or begin-group operator. */
+# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
+
+/* If this bit is set, then . matches newline.
+ If not set, then it doesn't. */
+# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
+
+/* If this bit is set, then . doesn't match NUL.
+ If not set, then it does. */
+# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
+
+/* If this bit is set, nonmatching lists [^...] do not match newline.
+ If not set, they do. */
+# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
+
+/* If this bit is set, either \{...\} or {...} defines an
+ interval, depending on RE_NO_BK_BRACES.
+ If not set, \{, \}, {, and } are literals. */
+# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
+
+/* If this bit is set, +, ? and | aren't recognized as operators.
+ If not set, they are. */
+# define RE_LIMITED_OPS (RE_INTERVALS << 1)
+
+/* If this bit is set, newline is an alternation operator.
+ If not set, newline is literal. */
+# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
+
+/* If this bit is set, then '{...}' defines an interval, and \{ and \}
+ are literals.
+ If not set, then '\{...\}' defines an interval. */
+# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
+
+/* If this bit is set, (...) defines a group, and \( and \) are literals.
+ If not set, \(...\) defines a group, and ( and ) are literals. */
+# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
+
+/* If this bit is set, then \<digit> matches <digit>.
+ If not set, then \<digit> is a back-reference. */
+# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
+
+/* If this bit is set, then | is an alternation operator, and \| is literal.
+ If not set, then \| is an alternation operator, and | is literal. */
+# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
+
+/* If this bit is set, then an ending range point collating higher
+ than the starting range point, as in [z-a], is invalid.
+ If not set, then when ending range point collates higher than the
+ starting range point, the range is ignored. */
+# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
+
+/* If this bit is set, then an unmatched ) is ordinary.
+ If not set, then an unmatched ) is invalid. */
+# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
+
+/* If this bit is set, succeed as soon as we match the whole pattern,
+ without further backtracking. */
+# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
+
+/* If this bit is set, do not process the GNU regex operators.
+ If not set, then the GNU regex operators are recognized. */
+# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
+
+/* If this bit is set, turn on internal regex debugging.
+ If not set, and debugging was on, turn it off.
+ This only works if regex.c is compiled -DDEBUG.
+ We define this bit always, so that all that's needed to turn on
+ debugging is to recompile regex.c; the calling code can always have
+ this bit set, and it won't affect anything in the normal case. */
+# define RE_DEBUG (RE_NO_GNU_OPS << 1)
+
+/* If this bit is set, a syntactically invalid interval is treated as
+ a string of ordinary characters. For example, the ERE 'a{1' is
+ treated as 'a\{1'. */
+# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
+
+/* If this bit is set, then ignore case when matching.
+ If not set, then case is significant. */
+# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
+
+/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
+ for ^, because it is difficult to scan the regex backwards to find
+ whether ^ should be special. */
+# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
+
+/* If this bit is set, then \{ cannot be first in a regex or
+ immediately after an alternation, open-group or \} operator. */
+# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
+
+/* If this bit is set, then no_sub will be set to 1 during
+ re_compile_pattern. */
+# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
+
+#endif /* defined __USE_GNU_REGEX */
+
+/* This global variable defines the particular regexp syntax to use (for
+ some interfaces). When a regexp is compiled, the syntax used is
+ stored in the pattern buffer, so changing this does not affect
+ already-compiled regexps. */
+extern reg_syntax_t re_syntax_options;
+
+#ifdef __USE_GNU_REGEX
+/* Define combinations of the above bits for the standard possibilities.
+ (The [[[ comments delimit what gets put into the Texinfo file, so
+ don't delete them!) */
+/* [[[begin syntaxes]]] */
+# define RE_SYNTAX_EMACS 0
+
+# define RE_SYNTAX_AWK \
+ (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
+ | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
+
+# define RE_SYNTAX_GNU_AWK \
+ ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
+ & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
+ | RE_CONTEXT_INVALID_OPS ))
+
+# define RE_SYNTAX_POSIX_AWK \
+ (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
+ | RE_INTERVALS | RE_NO_GNU_OPS)
+
+# define RE_SYNTAX_GREP \
+ (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
+ | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
+ | RE_NEWLINE_ALT)
+
+# define RE_SYNTAX_EGREP \
+ (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
+ | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
+ | RE_NO_BK_VBAR)
+
+# define RE_SYNTAX_POSIX_EGREP \
+ (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
+ | RE_INVALID_INTERVAL_ORD)
+
+/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
+# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
+
+# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
+
+/* Syntax bits common to both basic and extended POSIX regex syntax. */
+# define _RE_SYNTAX_POSIX_COMMON \
+ (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
+ | RE_INTERVALS | RE_NO_EMPTY_RANGES)
+
+# define RE_SYNTAX_POSIX_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
+
+/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
+ RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
+ isn't minimal, since other operators, such as \`, aren't disabled. */
+# define RE_SYNTAX_POSIX_MINIMAL_BASIC \
+ (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
+
+# define RE_SYNTAX_POSIX_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
+ | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
+
+/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
+ removed and RE_NO_BK_REFS is added. */
+# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
+ (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
+ | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
+ | RE_NO_BK_PARENS | RE_NO_BK_REFS \
+ | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
+/* [[[end syntaxes]]] */
+
+#endif /* defined __USE_GNU_REGEX */
+
+#ifdef __USE_GNU_REGEX
+
+/* Maximum number of duplicates an interval can allow. POSIX-conforming
+ systems might define this in <limits.h>, but we want our
+ value, so remove any previous define. */
+# ifdef RE_DUP_MAX
+# undef RE_DUP_MAX
+# endif
+
+/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
+ the counter as a 2-byte signed integer. This is no longer true, so
+ RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
+ ((SIZE_MAX - 2) / 10 - 1) if _REGEX_LARGE_OFFSETS is defined.
+ However, there would be a huge performance problem if someone
+ actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
+ its historical value. */
+# define RE_DUP_MAX (0x7fff)
+
+#endif /* defined __USE_GNU_REGEX */
+
+
+/* POSIX 'cflags' bits (i.e., information for 'regcomp'). */
+
+/* If this bit is set, then use extended regular expression syntax.
+ If not set, then use basic regular expression syntax. */
+#define REG_EXTENDED 1
+
+/* If this bit is set, then ignore case when matching.
+ If not set, then case is significant. */
+#define REG_ICASE (1 << 1)
+
+/* If this bit is set, then anchors do not match at newline
+ characters in the string.
+ If not set, then anchors do match at newlines. */
+#define REG_NEWLINE (1 << 2)
+
+/* If this bit is set, then report only success or fail in regexec.
+ If not set, then returns differ between not matching and errors. */
+#define REG_NOSUB (1 << 3)
+
+
+/* POSIX 'eflags' bits (i.e., information for regexec). */
+
+/* If this bit is set, then the beginning-of-line operator doesn't match
+ the beginning of the string (presumably because it's not the
+ beginning of a line).
+ If not set, then the beginning-of-line operator does match the
+ beginning of the string. */
+#define REG_NOTBOL 1
+
+/* Like REG_NOTBOL, except for the end-of-line. */
+#define REG_NOTEOL (1 << 1)
+
+/* Use PMATCH[0] to delimit the start and end of the search in the
+ buffer. */
+#define REG_STARTEND (1 << 2)
+
+
+/* If any error codes are removed, changed, or added, update the
+ '__re_error_msgid' table in regcomp.c. */
+
+typedef enum
+{
+ _REG_ENOSYS = -1, /* This will never happen for this implementation. */
+ _REG_NOERROR = 0, /* Success. */
+ _REG_NOMATCH, /* Didn't find a match (for regexec). */
+
+ /* POSIX regcomp return error codes. (In the order listed in the
+ standard.) */
+ _REG_BADPAT, /* Invalid pattern. */
+ _REG_ECOLLATE, /* Invalid collating element. */
+ _REG_ECTYPE, /* Invalid character class name. */
+ _REG_EESCAPE, /* Trailing backslash. */
+ _REG_ESUBREG, /* Invalid back reference. */
+ _REG_EBRACK, /* Unmatched left bracket. */
+ _REG_EPAREN, /* Parenthesis imbalance. */
+ _REG_EBRACE, /* Unmatched \{. */
+ _REG_BADBR, /* Invalid contents of \{\}. */
+ _REG_ERANGE, /* Invalid range end. */
+ _REG_ESPACE, /* Ran out of memory. */
+ _REG_BADRPT, /* No preceding re for repetition op. */
+
+ /* Error codes we've added. */
+ _REG_EEND, /* Premature end. */
+ _REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
+ _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
+} reg_errcode_t;
+
+#ifdef _XOPEN_SOURCE
+# define REG_ENOSYS _REG_ENOSYS
+#endif
+#define REG_NOERROR _REG_NOERROR
+#define REG_NOMATCH _REG_NOMATCH
+#define REG_BADPAT _REG_BADPAT
+#define REG_ECOLLATE _REG_ECOLLATE
+#define REG_ECTYPE _REG_ECTYPE
+#define REG_EESCAPE _REG_EESCAPE
+#define REG_ESUBREG _REG_ESUBREG
+#define REG_EBRACK _REG_EBRACK
+#define REG_EPAREN _REG_EPAREN
+#define REG_EBRACE _REG_EBRACE
+#define REG_BADBR _REG_BADBR
+#define REG_ERANGE _REG_ERANGE
+#define REG_ESPACE _REG_ESPACE
+#define REG_BADRPT _REG_BADRPT
+#define REG_EEND _REG_EEND
+#define REG_ESIZE _REG_ESIZE
+#define REG_ERPAREN _REG_ERPAREN
+
+/* struct re_pattern_buffer normally uses member names like 'buffer'
+ that POSIX does not allow. In POSIX mode these members have names
+ with leading 're_' (e.g., 're_buffer'). */
+#ifdef __USE_GNU_REGEX
+# define _REG_RE_NAME(id) id
+# define _REG_RM_NAME(id) id
+#else
+# define _REG_RE_NAME(id) re_##id
+# define _REG_RM_NAME(id) rm_##id
+#endif
+
+/* The user can specify the type of the re_translate member by
+ defining the macro RE_TRANSLATE_TYPE, which defaults to unsigned
+ char *. This pollutes the POSIX name space, so in POSIX mode just
+ use unsigned char *. */
+#ifdef __USE_GNU_REGEX
+# ifndef RE_TRANSLATE_TYPE
+# define RE_TRANSLATE_TYPE unsigned char *
+# endif
+# define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE
+#else
+# define REG_TRANSLATE_TYPE unsigned char *
+#endif
+
+/* This data structure represents a compiled pattern. Before calling
+ the pattern compiler, the fields 'buffer', 'allocated', 'fastmap',
+ 'translate', and 'no_sub' can be set. After the pattern has been
+ compiled, the 're_nsub' field is available. All other fields are
+ private to the regex routines. */
+
+struct re_pattern_buffer
+{
+ /* Space that holds the compiled pattern. It is declared as
+ 'unsigned char *' because its elements are sometimes used as
+ array indexes. */
+ unsigned char *_REG_RE_NAME (buffer);
+
+ /* Number of bytes to which 'buffer' points. */
+ __re_long_size_t _REG_RE_NAME (allocated);
+
+ /* Number of bytes actually used in 'buffer'. */
+ __re_long_size_t _REG_RE_NAME (used);
+
+ /* Syntax setting with which the pattern was compiled. */
+ reg_syntax_t _REG_RE_NAME (syntax);
+
+ /* Pointer to a fastmap, if any, otherwise zero. re_search uses the
+ fastmap, if there is one, to skip over impossible starting points
+ for matches. */
+ char *_REG_RE_NAME (fastmap);
+
+ /* Either a translate table to apply to all characters before
+ comparing them, or zero for no translation. The translation is
+ applied to a pattern when it is compiled and to a string when it
+ is matched. */
+ REG_TRANSLATE_TYPE _REG_RE_NAME (translate);
+
+ /* Number of subexpressions found by the compiler. */
+ size_t re_nsub;
+
+ /* Zero if this pattern cannot match the empty string, one else.
+ Well, in truth it's used only in 're_search_2', to see whether or
+ not we should use the fastmap, so we don't set this absolutely
+ perfectly; see 're_compile_fastmap' (the "duplicate" case). */
+ unsigned int _REG_RE_NAME (can_be_null) : 1;
+
+ /* If REGS_UNALLOCATED, allocate space in the 'regs' structure
+ for 'max (RE_NREGS, re_nsub + 1)' groups.
+ If REGS_REALLOCATE, reallocate space if necessary.
+ If REGS_FIXED, use what's there. */
+#ifdef __USE_GNU_REGEX
+# define REGS_UNALLOCATED 0
+# define REGS_REALLOCATE 1
+# define REGS_FIXED 2
+#endif
+ unsigned int _REG_RE_NAME (regs_allocated) : 2;
+
+ /* Set to zero when 're_compile_pattern' compiles a pattern; set to
+ one by 're_compile_fastmap' if it updates the fastmap. */
+ unsigned int _REG_RE_NAME (fastmap_accurate) : 1;
+
+ /* If set, 're_match_2' does not return information about
+ subexpressions. */
+ unsigned int _REG_RE_NAME (no_sub) : 1;
+
+ /* If set, a beginning-of-line anchor doesn't match at the beginning
+ of the string. */
+ unsigned int _REG_RE_NAME (not_bol) : 1;
+
+ /* Similarly for an end-of-line anchor. */
+ unsigned int _REG_RE_NAME (not_eol) : 1;
+
+ /* If true, an anchor at a newline matches. */
+ unsigned int _REG_RE_NAME (newline_anchor) : 1;
+
+/* [[[end pattern_buffer]]] */
+};
+
+typedef struct re_pattern_buffer regex_t;
+
+/* This is the structure we store register match data in. See
+ regex.texinfo for a full description of what registers match. */
+struct re_registers
+{
+ __re_size_t _REG_RM_NAME (num_regs);
+ regoff_t *_REG_RM_NAME (start);
+ regoff_t *_REG_RM_NAME (end);
+};
+
+
+/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
+ 're_match_2' returns information about at least this many registers
+ the first time a 'regs' structure is passed. */
+#if !defined RE_NREGS && defined __USE_GNU_REGEX
+# define RE_NREGS 30
+#endif
+
+
+/* POSIX specification for registers. Aside from the different names than
+ 're_registers', POSIX uses an array of structures, instead of a
+ structure of arrays. */
+typedef struct
+{
+ regoff_t rm_so; /* Byte offset from string's start to substring's start. */
+ regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
+} regmatch_t;
+
+/* Declarations for routines. */
+
+/* Sets the current default syntax to SYNTAX, and return the old syntax.
+ You can also simply assign to the 're_syntax_options' variable. */
+extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
+
+/* Compile the regular expression PATTERN, with length LENGTH
+ and syntax given by the global 're_syntax_options', into the buffer
+ BUFFER. Return NULL if successful, and an error string if not. */
+extern const char *re_compile_pattern (const char *__pattern, size_t __length,
+ struct re_pattern_buffer *__buffer);
+
+
+/* Compile a fastmap for the compiled pattern in BUFFER; used to
+ accelerate searches. Return 0 if successful and -2 if was an
+ internal error. */
+extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
+
+
+/* Search in the string STRING (with length LENGTH) for the pattern
+ compiled into BUFFER. Start searching at position START, for RANGE
+ characters. Return the starting position of the match, -1 for no
+ match, or -2 for an internal error. Also return register
+ information in REGS (if REGS and BUFFER->no_sub are nonzero). */
+extern regoff_t re_search (struct re_pattern_buffer *__buffer,
+ const char *__string, __re_idx_t __length,
+ __re_idx_t __start, regoff_t __range,
+ struct re_registers *__regs);
+
+
+/* Like 're_search', but search in the concatenation of STRING1 and
+ STRING2. Also, stop searching at index START + STOP. */
+extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
+ const char *__string1, __re_idx_t __length1,
+ const char *__string2, __re_idx_t __length2,
+ __re_idx_t __start, regoff_t __range,
+ struct re_registers *__regs,
+ __re_idx_t __stop);
+
+
+/* Like 're_search', but return how many characters in STRING the regexp
+ in BUFFER matched, starting at position START. */
+extern regoff_t re_match (struct re_pattern_buffer *__buffer,
+ const char *__string, __re_idx_t __length,
+ __re_idx_t __start, struct re_registers *__regs);
+
+
+/* Relates to 're_match' as 're_search_2' relates to 're_search'. */
+extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
+ const char *__string1, __re_idx_t __length1,
+ const char *__string2, __re_idx_t __length2,
+ __re_idx_t __start, struct re_registers *__regs,
+ __re_idx_t __stop);
+
+
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
+ ENDS. Subsequent matches using BUFFER and REGS will use this memory
+ for recording register information. STARTS and ENDS must be
+ allocated with malloc, and must each be at least 'NUM_REGS * sizeof
+ (regoff_t)' bytes long.
+
+ If NUM_REGS == 0, then subsequent matches should allocate their own
+ register data.
+
+ Unless this function is called, the first search or match using
+ BUFFER will allocate its own register data, without freeing the old
+ data. */
+extern void re_set_registers (struct re_pattern_buffer *__buffer,
+ struct re_registers *__regs,
+ __re_size_t __num_regs,
+ regoff_t *__starts, regoff_t *__ends);
+
+#if defined _REGEX_RE_COMP || defined _LIBC
+# ifndef _CRAY
+/* 4.2 bsd compatibility. */
+extern char *re_comp (const char *);
+extern int re_exec (const char *);
+# endif
+#endif
+
+/* GCC 2.95 and later have "__restrict"; C99 compilers have
+ "restrict", and "configure" may have defined "restrict".
+ Other compilers use __restrict, __restrict__, and _Restrict, and
+ 'configure' might #define 'restrict' to those words, so pick a
+ different name. */
+#ifndef _Restrict_
+# if 199901L <= __STDC_VERSION__
+# define _Restrict_ restrict
+# elif 2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)
+# define _Restrict_ __restrict
+# else
+# define _Restrict_
+# endif
+#endif
+/* gcc 3.1 and up support the [restrict] syntax. Don't trust
+ sys/cdefs.h's definition of __restrict_arr, though, as it
+ mishandles gcc -ansi -pedantic. */
+#ifndef _Restrict_arr_
+# if ((199901L <= __STDC_VERSION__ \
+ || ((3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) \
+ && !defined __STRICT_ANSI__)) \
+ && !defined __GNUG__)
+# define _Restrict_arr_ _Restrict_
+# else
+# define _Restrict_arr_
+# endif
+#endif
+
+/* POSIX compatibility. */
+extern int regcomp (regex_t *_Restrict_ __preg,
+ const char *_Restrict_ __pattern,
+ int __cflags);
+
+extern int regexec (const regex_t *_Restrict_ __preg,
+ const char *_Restrict_ __string, size_t __nmatch,
+ regmatch_t __pmatch[_Restrict_arr_],
+ int __eflags);
+
+extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
+ char *_Restrict_ __errbuf, size_t __errbuf_size);
+
+extern void regfree (regex_t *__preg);
+
+
+#ifdef __cplusplus
+}
+#endif /* C++ */
+
+#endif /* regex.h */
diff --git a/lib/regex_internal.c b/lib/regex_internal.c
new file mode 100644
index 000000000..c029c23a9
--- /dev/null
+++ b/lib/regex_internal.c
@@ -0,0 +1,1741 @@
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+static void re_string_construct_common (const char *str, Idx len,
+ re_string_t *pstr,
+ RE_TRANSLATE_TYPE trans, bool icase,
+ const re_dfa_t *dfa) internal_function;
+static re_dfastate_t *create_ci_newstate (const re_dfa_t *dfa,
+ const re_node_set *nodes,
+ re_hashval_t hash) internal_function;
+static re_dfastate_t *create_cd_newstate (const re_dfa_t *dfa,
+ const re_node_set *nodes,
+ unsigned int context,
+ re_hashval_t hash) internal_function;
+
+/* Functions for string operation. */
+
+/* This function allocate the buffers. It is necessary to call
+ re_string_reconstruct before using the object. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_allocate (re_string_t *pstr, const char *str, Idx len, Idx init_len,
+ RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
+{
+ reg_errcode_t ret;
+ Idx init_buf_len;
+
+ /* Ensure at least one character fits into the buffers. */
+ if (init_len < dfa->mb_cur_max)
+ init_len = dfa->mb_cur_max;
+ init_buf_len = (len + 1 < init_len) ? len + 1: init_len;
+ re_string_construct_common (str, len, pstr, trans, icase, dfa);
+
+ ret = re_string_realloc_buffers (pstr, init_buf_len);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+
+ pstr->word_char = dfa->word_char;
+ pstr->word_ops_used = dfa->word_ops_used;
+ pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
+ pstr->valid_len = (pstr->mbs_allocated || dfa->mb_cur_max > 1) ? 0 : len;
+ pstr->valid_raw_len = pstr->valid_len;
+ return REG_NOERROR;
+}
+
+/* This function allocate the buffers, and initialize them. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_construct (re_string_t *pstr, const char *str, Idx len,
+ RE_TRANSLATE_TYPE trans, bool icase, const re_dfa_t *dfa)
+{
+ reg_errcode_t ret;
+ memset (pstr, '\0', sizeof (re_string_t));
+ re_string_construct_common (str, len, pstr, trans, icase, dfa);
+
+ if (len > 0)
+ {
+ ret = re_string_realloc_buffers (pstr, len + 1);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ pstr->mbs = pstr->mbs_allocated ? pstr->mbs : (unsigned char *) str;
+
+ if (icase)
+ {
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ {
+ while (1)
+ {
+ ret = build_wcs_upper_buffer (pstr);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ if (pstr->valid_raw_len >= len)
+ break;
+ if (pstr->bufs_len > pstr->valid_len + dfa->mb_cur_max)
+ break;
+ ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ build_upper_buffer (pstr);
+ }
+ else
+ {
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ build_wcs_buffer (pstr);
+ else
+#endif /* RE_ENABLE_I18N */
+ {
+ if (trans != NULL)
+ re_string_translate_buffer (pstr);
+ else
+ {
+ pstr->valid_len = pstr->bufs_len;
+ pstr->valid_raw_len = pstr->bufs_len;
+ }
+ }
+ }
+
+ return REG_NOERROR;
+}
+
+/* Helper functions for re_string_allocate, and re_string_construct. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_realloc_buffers (re_string_t *pstr, Idx new_buf_len)
+{
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ wint_t *new_wcs;
+
+ /* Avoid overflow. */
+ size_t max_object_size = MAX (sizeof (wint_t), sizeof (Idx));
+ if (BE (SIZE_MAX / max_object_size < new_buf_len, 0))
+ return REG_ESPACE;
+
+ new_wcs = re_realloc (pstr->wcs, wint_t, new_buf_len);
+ if (BE (new_wcs == NULL, 0))
+ return REG_ESPACE;
+ pstr->wcs = new_wcs;
+ if (pstr->offsets != NULL)
+ {
+ Idx *new_offsets = re_realloc (pstr->offsets, Idx, new_buf_len);
+ if (BE (new_offsets == NULL, 0))
+ return REG_ESPACE;
+ pstr->offsets = new_offsets;
+ }
+ }
+#endif /* RE_ENABLE_I18N */
+ if (pstr->mbs_allocated)
+ {
+ unsigned char *new_mbs = re_realloc (pstr->mbs, unsigned char,
+ new_buf_len);
+ if (BE (new_mbs == NULL, 0))
+ return REG_ESPACE;
+ pstr->mbs = new_mbs;
+ }
+ pstr->bufs_len = new_buf_len;
+ return REG_NOERROR;
+}
+
+
+static void
+internal_function
+re_string_construct_common (const char *str, Idx len, re_string_t *pstr,
+ RE_TRANSLATE_TYPE trans, bool icase,
+ const re_dfa_t *dfa)
+{
+ pstr->raw_mbs = (const unsigned char *) str;
+ pstr->len = len;
+ pstr->raw_len = len;
+ pstr->trans = trans;
+ pstr->icase = icase;
+ pstr->mbs_allocated = (trans != NULL || icase);
+ pstr->mb_cur_max = dfa->mb_cur_max;
+ pstr->is_utf8 = dfa->is_utf8;
+ pstr->map_notascii = dfa->map_notascii;
+ pstr->stop = pstr->len;
+ pstr->raw_stop = pstr->stop;
+}
+
+#ifdef RE_ENABLE_I18N
+
+/* Build wide character buffer PSTR->WCS.
+ If the byte sequence of the string are:
+ <mb1>(0), <mb1>(1), <mb2>(0), <mb2>(1), <sb3>
+ Then wide character buffer will be:
+ <wc1> , WEOF , <wc2> , WEOF , <wc3>
+ We use WEOF for padding, they indicate that the position isn't
+ a first byte of a multibyte character.
+
+ Note that this function assumes PSTR->VALID_LEN elements are already
+ built and starts from PSTR->VALID_LEN. */
+
+static void
+internal_function
+build_wcs_buffer (re_string_t *pstr)
+{
+#ifdef _LIBC
+ unsigned char buf[MB_LEN_MAX];
+ assert (MB_LEN_MAX >= pstr->mb_cur_max);
+#else
+ unsigned char buf[64];
+#endif
+ mbstate_t prev_st;
+ Idx byte_idx, end_idx, remain_len;
+ size_t mbclen;
+
+ /* Build the buffers from pstr->valid_len to either pstr->len or
+ pstr->bufs_len. */
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+ for (byte_idx = pstr->valid_len; byte_idx < end_idx;)
+ {
+ wchar_t wc;
+ const char *p;
+
+ remain_len = end_idx - byte_idx;
+ prev_st = pstr->cur_state;
+ /* Apply the translation if we need. */
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i, ch;
+
+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
+ {
+ ch = pstr->raw_mbs [pstr->raw_mbs_idx + byte_idx + i];
+ buf[i] = pstr->mbs[byte_idx + i] = pstr->trans[ch];
+ }
+ p = (const char *) buf;
+ }
+ else
+ p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx;
+ mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
+ if (BE (mbclen == (size_t) -2, 0))
+ {
+ /* The buffer doesn't have enough space, finish to build. */
+ pstr->cur_state = prev_st;
+ break;
+ }
+ else if (BE (mbclen == (size_t) -1 || mbclen == 0, 0))
+ {
+ /* We treat these cases as a singlebyte character. */
+ mbclen = 1;
+ wc = (wchar_t) pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
+ if (BE (pstr->trans != NULL, 0))
+ wc = pstr->trans[wc];
+ pstr->cur_state = prev_st;
+ }
+
+ /* Write wide character and padding. */
+ pstr->wcs[byte_idx++] = wc;
+ /* Write paddings. */
+ for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
+ pstr->wcs[byte_idx++] = WEOF;
+ }
+ pstr->valid_len = byte_idx;
+ pstr->valid_raw_len = byte_idx;
+}
+
+/* Build wide character buffer PSTR->WCS like build_wcs_buffer,
+ but for REG_ICASE. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+build_wcs_upper_buffer (re_string_t *pstr)
+{
+ mbstate_t prev_st;
+ Idx src_idx, byte_idx, end_idx, remain_len;
+ size_t mbclen;
+#ifdef _LIBC
+ char buf[MB_LEN_MAX];
+ assert (MB_LEN_MAX >= pstr->mb_cur_max);
+#else
+ char buf[64];
+#endif
+
+ byte_idx = pstr->valid_len;
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+
+ /* The following optimization assumes that ASCII characters can be
+ mapped to wide characters with a simple cast. */
+ if (! pstr->map_notascii && pstr->trans == NULL && !pstr->offsets_needed)
+ {
+ while (byte_idx < end_idx)
+ {
+ wchar_t wc;
+
+ if (isascii (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx])
+ && mbsinit (&pstr->cur_state))
+ {
+ /* In case of a singlebyte character. */
+ pstr->mbs[byte_idx]
+ = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]);
+ /* The next step uses the assumption that wchar_t is encoded
+ ASCII-safe: all ASCII values can be converted like this. */
+ pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx];
+ ++byte_idx;
+ continue;
+ }
+
+ remain_len = end_idx - byte_idx;
+ prev_st = pstr->cur_state;
+ mbclen = __mbrtowc (&wc,
+ ((const char *) pstr->raw_mbs + pstr->raw_mbs_idx
+ + byte_idx), remain_len, &pstr->cur_state);
+ if (BE (mbclen < (size_t) -2, 1))
+ {
+ wchar_t wcu = wc;
+ if (iswlower (wc))
+ {
+ size_t mbcdlen;
+
+ wcu = towupper (wc);
+ mbcdlen = wcrtomb (buf, wcu, &prev_st);
+ if (BE (mbclen == mbcdlen, 1))
+ memcpy (pstr->mbs + byte_idx, buf, mbclen);
+ else
+ {
+ src_idx = byte_idx;
+ goto offsets_needed;
+ }
+ }
+ else
+ memcpy (pstr->mbs + byte_idx,
+ pstr->raw_mbs + pstr->raw_mbs_idx + byte_idx, mbclen);
+ pstr->wcs[byte_idx++] = wcu;
+ /* Write paddings. */
+ for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
+ pstr->wcs[byte_idx++] = WEOF;
+ }
+ else if (mbclen == (size_t) -1 || mbclen == 0)
+ {
+ /* It is an invalid character or '\0'. Just use the byte. */
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx];
+ pstr->mbs[byte_idx] = ch;
+ /* And also cast it to wide char. */
+ pstr->wcs[byte_idx++] = (wchar_t) ch;
+ if (BE (mbclen == (size_t) -1, 0))
+ pstr->cur_state = prev_st;
+ }
+ else
+ {
+ /* The buffer doesn't have enough space, finish to build. */
+ pstr->cur_state = prev_st;
+ break;
+ }
+ }
+ pstr->valid_len = byte_idx;
+ pstr->valid_raw_len = byte_idx;
+ return REG_NOERROR;
+ }
+ else
+ for (src_idx = pstr->valid_raw_len; byte_idx < end_idx;)
+ {
+ wchar_t wc;
+ const char *p;
+ offsets_needed:
+ remain_len = end_idx - byte_idx;
+ prev_st = pstr->cur_state;
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i, ch;
+
+ for (i = 0; i < pstr->mb_cur_max && i < remain_len; ++i)
+ {
+ ch = pstr->raw_mbs [pstr->raw_mbs_idx + src_idx + i];
+ buf[i] = pstr->trans[ch];
+ }
+ p = (const char *) buf;
+ }
+ else
+ p = (const char *) pstr->raw_mbs + pstr->raw_mbs_idx + src_idx;
+ mbclen = __mbrtowc (&wc, p, remain_len, &pstr->cur_state);
+ if (BE (mbclen < (size_t) -2, 1))
+ {
+ wchar_t wcu = wc;
+ if (iswlower (wc))
+ {
+ size_t mbcdlen;
+
+ wcu = towupper (wc);
+ mbcdlen = wcrtomb ((char *) buf, wcu, &prev_st);
+ if (BE (mbclen == mbcdlen, 1))
+ memcpy (pstr->mbs + byte_idx, buf, mbclen);
+ else if (mbcdlen != (size_t) -1)
+ {
+ size_t i;
+
+ if (byte_idx + mbcdlen > pstr->bufs_len)
+ {
+ pstr->cur_state = prev_st;
+ break;
+ }
+
+ if (pstr->offsets == NULL)
+ {
+ pstr->offsets = re_malloc (Idx, pstr->bufs_len);
+
+ if (pstr->offsets == NULL)
+ return REG_ESPACE;
+ }
+ if (!pstr->offsets_needed)
+ {
+ for (i = 0; i < (size_t) byte_idx; ++i)
+ pstr->offsets[i] = i;
+ pstr->offsets_needed = 1;
+ }
+
+ memcpy (pstr->mbs + byte_idx, buf, mbcdlen);
+ pstr->wcs[byte_idx] = wcu;
+ pstr->offsets[byte_idx] = src_idx;
+ for (i = 1; i < mbcdlen; ++i)
+ {
+ pstr->offsets[byte_idx + i]
+ = src_idx + (i < mbclen ? i : mbclen - 1);
+ pstr->wcs[byte_idx + i] = WEOF;
+ }
+ pstr->len += mbcdlen - mbclen;
+ if (pstr->raw_stop > src_idx)
+ pstr->stop += mbcdlen - mbclen;
+ end_idx = (pstr->bufs_len > pstr->len)
+ ? pstr->len : pstr->bufs_len;
+ byte_idx += mbcdlen;
+ src_idx += mbclen;
+ continue;
+ }
+ else
+ memcpy (pstr->mbs + byte_idx, p, mbclen);
+ }
+ else
+ memcpy (pstr->mbs + byte_idx, p, mbclen);
+
+ if (BE (pstr->offsets_needed != 0, 0))
+ {
+ size_t i;
+ for (i = 0; i < mbclen; ++i)
+ pstr->offsets[byte_idx + i] = src_idx + i;
+ }
+ src_idx += mbclen;
+
+ pstr->wcs[byte_idx++] = wcu;
+ /* Write paddings. */
+ for (remain_len = byte_idx + mbclen - 1; byte_idx < remain_len ;)
+ pstr->wcs[byte_idx++] = WEOF;
+ }
+ else if (mbclen == (size_t) -1 || mbclen == 0)
+ {
+ /* It is an invalid character or '\0'. Just use the byte. */
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + src_idx];
+
+ if (BE (pstr->trans != NULL, 0))
+ ch = pstr->trans [ch];
+ pstr->mbs[byte_idx] = ch;
+
+ if (BE (pstr->offsets_needed != 0, 0))
+ pstr->offsets[byte_idx] = src_idx;
+ ++src_idx;
+
+ /* And also cast it to wide char. */
+ pstr->wcs[byte_idx++] = (wchar_t) ch;
+ if (BE (mbclen == (size_t) -1, 0))
+ pstr->cur_state = prev_st;
+ }
+ else
+ {
+ /* The buffer doesn't have enough space, finish to build. */
+ pstr->cur_state = prev_st;
+ break;
+ }
+ }
+ pstr->valid_len = byte_idx;
+ pstr->valid_raw_len = src_idx;
+ return REG_NOERROR;
+}
+
+/* Skip characters until the index becomes greater than NEW_RAW_IDX.
+ Return the index. */
+
+static Idx
+internal_function
+re_string_skip_chars (re_string_t *pstr, Idx new_raw_idx, wint_t *last_wc)
+{
+ mbstate_t prev_st;
+ Idx rawbuf_idx;
+ size_t mbclen;
+ wint_t wc = WEOF;
+
+ /* Skip the characters which are not necessary to check. */
+ for (rawbuf_idx = pstr->raw_mbs_idx + pstr->valid_raw_len;
+ rawbuf_idx < new_raw_idx;)
+ {
+ wchar_t wc2;
+ Idx remain_len;
+ remain_len = pstr->len - rawbuf_idx;
+ prev_st = pstr->cur_state;
+ mbclen = __mbrtowc (&wc2, (const char *) pstr->raw_mbs + rawbuf_idx,
+ remain_len, &pstr->cur_state);
+ if (BE (mbclen == (size_t) -2 || mbclen == (size_t) -1 || mbclen == 0, 0))
+ {
+ /* We treat these cases as a single byte character. */
+ if (mbclen == 0 || remain_len == 0)
+ wc = L'\0';
+ else
+ wc = *(unsigned char *) (pstr->raw_mbs + rawbuf_idx);
+ mbclen = 1;
+ pstr->cur_state = prev_st;
+ }
+ else
+ wc = wc2;
+ /* Then proceed the next character. */
+ rawbuf_idx += mbclen;
+ }
+ *last_wc = wc;
+ return rawbuf_idx;
+}
+#endif /* RE_ENABLE_I18N */
+
+/* Build the buffer PSTR->MBS, and apply the translation if we need.
+ This function is used in case of REG_ICASE. */
+
+static void
+internal_function
+build_upper_buffer (re_string_t *pstr)
+{
+ Idx char_idx, end_idx;
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+
+ for (char_idx = pstr->valid_len; char_idx < end_idx; ++char_idx)
+ {
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + char_idx];
+ if (BE (pstr->trans != NULL, 0))
+ ch = pstr->trans[ch];
+ if (islower (ch))
+ pstr->mbs[char_idx] = toupper (ch);
+ else
+ pstr->mbs[char_idx] = ch;
+ }
+ pstr->valid_len = char_idx;
+ pstr->valid_raw_len = char_idx;
+}
+
+/* Apply TRANS to the buffer in PSTR. */
+
+static void
+internal_function
+re_string_translate_buffer (re_string_t *pstr)
+{
+ Idx buf_idx, end_idx;
+ end_idx = (pstr->bufs_len > pstr->len) ? pstr->len : pstr->bufs_len;
+
+ for (buf_idx = pstr->valid_len; buf_idx < end_idx; ++buf_idx)
+ {
+ int ch = pstr->raw_mbs[pstr->raw_mbs_idx + buf_idx];
+ pstr->mbs[buf_idx] = pstr->trans[ch];
+ }
+
+ pstr->valid_len = buf_idx;
+ pstr->valid_raw_len = buf_idx;
+}
+
+/* This function re-construct the buffers.
+ Concretely, convert to wide character in case of pstr->mb_cur_max > 1,
+ convert to upper case in case of REG_ICASE, apply translation. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_string_reconstruct (re_string_t *pstr, Idx idx, int eflags)
+{
+ Idx offset;
+
+ if (BE (pstr->raw_mbs_idx <= idx, 0))
+ offset = idx - pstr->raw_mbs_idx;
+ else
+ {
+ /* Reset buffer. */
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
+#endif /* RE_ENABLE_I18N */
+ pstr->len = pstr->raw_len;
+ pstr->stop = pstr->raw_stop;
+ pstr->valid_len = 0;
+ pstr->raw_mbs_idx = 0;
+ pstr->valid_raw_len = 0;
+ pstr->offsets_needed = 0;
+ pstr->tip_context = ((eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
+ : CONTEXT_NEWLINE | CONTEXT_BEGBUF);
+ if (!pstr->mbs_allocated)
+ pstr->mbs = (unsigned char *) pstr->raw_mbs;
+ offset = idx;
+ }
+
+ if (BE (offset != 0, 1))
+ {
+ /* Should the already checked characters be kept? */
+ if (BE (offset < pstr->valid_raw_len, 1))
+ {
+ /* Yes, move them to the front of the buffer. */
+#ifdef RE_ENABLE_I18N
+ if (BE (pstr->offsets_needed, 0))
+ {
+ Idx low = 0, high = pstr->valid_len, mid;
+ do
+ {
+ mid = (high + low) / 2;
+ if (pstr->offsets[mid] > offset)
+ high = mid;
+ else if (pstr->offsets[mid] < offset)
+ low = mid + 1;
+ else
+ break;
+ }
+ while (low < high);
+ if (pstr->offsets[mid] < offset)
+ ++mid;
+ pstr->tip_context = re_string_context_at (pstr, mid - 1,
+ eflags);
+ /* This can be quite complicated, so handle specially
+ only the common and easy case where the character with
+ different length representation of lower and upper
+ case is present at or after offset. */
+ if (pstr->valid_len > offset
+ && mid == offset && pstr->offsets[mid] == offset)
+ {
+ memmove (pstr->wcs, pstr->wcs + offset,
+ (pstr->valid_len - offset) * sizeof (wint_t));
+ memmove (pstr->mbs, pstr->mbs + offset, pstr->valid_len - offset);
+ pstr->valid_len -= offset;
+ pstr->valid_raw_len -= offset;
+ for (low = 0; low < pstr->valid_len; low++)
+ pstr->offsets[low] = pstr->offsets[low + offset] - offset;
+ }
+ else
+ {
+ /* Otherwise, just find out how long the partial multibyte
+ character at offset is and fill it with WEOF/255. */
+ pstr->len = pstr->raw_len - idx + offset;
+ pstr->stop = pstr->raw_stop - idx + offset;
+ pstr->offsets_needed = 0;
+ while (mid > 0 && pstr->offsets[mid - 1] == offset)
+ --mid;
+ while (mid < pstr->valid_len)
+ if (pstr->wcs[mid] != WEOF)
+ break;
+ else
+ ++mid;
+ if (mid == pstr->valid_len)
+ pstr->valid_len = 0;
+ else
+ {
+ pstr->valid_len = pstr->offsets[mid] - offset;
+ if (pstr->valid_len)
+ {
+ for (low = 0; low < pstr->valid_len; ++low)
+ pstr->wcs[low] = WEOF;
+ memset (pstr->mbs, 255, pstr->valid_len);
+ }
+ }
+ pstr->valid_raw_len = pstr->valid_len;
+ }
+ }
+ else
+#endif
+ {
+ pstr->tip_context = re_string_context_at (pstr, offset - 1,
+ eflags);
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ memmove (pstr->wcs, pstr->wcs + offset,
+ (pstr->valid_len - offset) * sizeof (wint_t));
+#endif /* RE_ENABLE_I18N */
+ if (BE (pstr->mbs_allocated, 0))
+ memmove (pstr->mbs, pstr->mbs + offset,
+ pstr->valid_len - offset);
+ pstr->valid_len -= offset;
+ pstr->valid_raw_len -= offset;
+#if DEBUG
+ assert (pstr->valid_len > 0);
+#endif
+ }
+ }
+ else
+ {
+#ifdef RE_ENABLE_I18N
+ /* No, skip all characters until IDX. */
+ Idx prev_valid_len = pstr->valid_len;
+
+ if (BE (pstr->offsets_needed, 0))
+ {
+ pstr->len = pstr->raw_len - idx + offset;
+ pstr->stop = pstr->raw_stop - idx + offset;
+ pstr->offsets_needed = 0;
+ }
+#endif
+ pstr->valid_len = 0;
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ Idx wcs_idx;
+ wint_t wc = WEOF;
+
+ if (pstr->is_utf8)
+ {
+ const unsigned char *raw, *p, *end;
+
+ /* Special case UTF-8. Multi-byte chars start with any
+ byte other than 0x80 - 0xbf. */
+ raw = pstr->raw_mbs + pstr->raw_mbs_idx;
+ end = raw + (offset - pstr->mb_cur_max);
+ if (end < pstr->raw_mbs)
+ end = pstr->raw_mbs;
+ p = raw + offset - 1;
+#ifdef _LIBC
+ /* We know the wchar_t encoding is UCS4, so for the simple
+ case, ASCII characters, skip the conversion step. */
+ if (isascii (*p) && BE (pstr->trans == NULL, 1))
+ {
+ memset (&pstr->cur_state, '\0', sizeof (mbstate_t));
+ /* pstr->valid_len = 0; */
+ wc = (wchar_t) *p;
+ }
+ else
+#endif
+ for (; p >= end; --p)
+ if ((*p & 0xc0) != 0x80)
+ {
+ mbstate_t cur_state;
+ wchar_t wc2;
+ Idx mlen = raw + pstr->len - p;
+ size_t mbclen;
+
+#if 0 /* dead code: buf is set but never used */
+ unsigned char buf[6];
+ if (BE (pstr->trans != NULL, 0))
+ {
+ int i = mlen < 6 ? mlen : 6;
+ while (--i >= 0)
+ buf[i] = pstr->trans[p[i]];
+ }
+#endif
+ /* XXX Don't use mbrtowc, we know which conversion
+ to use (UTF-8 -> UCS4). */
+ memset (&cur_state, 0, sizeof (cur_state));
+ mbclen = __mbrtowc (&wc2, (const char *) p, mlen,
+ &cur_state);
+ if (raw + offset - p <= mbclen
+ && mbclen < (size_t) -2)
+ {
+ memset (&pstr->cur_state, '\0',
+ sizeof (mbstate_t));
+ pstr->valid_len = mbclen - (raw + offset - p);
+ wc = wc2;
+ }
+ break;
+ }
+ }
+
+ if (wc == WEOF)
+ pstr->valid_len = re_string_skip_chars (pstr, idx, &wc) - idx;
+ if (wc == WEOF)
+ pstr->tip_context
+ = re_string_context_at (pstr, prev_valid_len - 1, eflags);
+ else
+ pstr->tip_context = ((BE (pstr->word_ops_used != 0, 0)
+ && IS_WIDE_WORD_CHAR (wc))
+ ? CONTEXT_WORD
+ : ((IS_WIDE_NEWLINE (wc)
+ && pstr->newline_anchor)
+ ? CONTEXT_NEWLINE : 0));
+ if (BE (pstr->valid_len, 0))
+ {
+ for (wcs_idx = 0; wcs_idx < pstr->valid_len; ++wcs_idx)
+ pstr->wcs[wcs_idx] = WEOF;
+ if (pstr->mbs_allocated)
+ memset (pstr->mbs, 255, pstr->valid_len);
+ }
+ pstr->valid_raw_len = pstr->valid_len;
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ {
+ int c = pstr->raw_mbs[pstr->raw_mbs_idx + offset - 1];
+ pstr->valid_raw_len = 0;
+ if (pstr->trans)
+ c = pstr->trans[c];
+ pstr->tip_context = (bitset_contain (pstr->word_char, c)
+ ? CONTEXT_WORD
+ : ((IS_NEWLINE (c) && pstr->newline_anchor)
+ ? CONTEXT_NEWLINE : 0));
+ }
+ }
+ if (!BE (pstr->mbs_allocated, 0))
+ pstr->mbs += offset;
+ }
+ pstr->raw_mbs_idx = idx;
+ pstr->len -= offset;
+ pstr->stop -= offset;
+
+ /* Then build the buffers. */
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ if (pstr->icase)
+ {
+ reg_errcode_t ret = build_wcs_upper_buffer (pstr);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ else
+ build_wcs_buffer (pstr);
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ if (BE (pstr->mbs_allocated, 0))
+ {
+ if (pstr->icase)
+ build_upper_buffer (pstr);
+ else if (pstr->trans != NULL)
+ re_string_translate_buffer (pstr);
+ }
+ else
+ pstr->valid_len = pstr->len;
+
+ pstr->cur_idx = 0;
+ return REG_NOERROR;
+}
+
+static unsigned char
+internal_function __attribute ((pure))
+re_string_peek_byte_case (const re_string_t *pstr, Idx idx)
+{
+ int ch;
+ Idx off;
+
+ /* Handle the common (easiest) cases first. */
+ if (BE (!pstr->mbs_allocated, 1))
+ return re_string_peek_byte (pstr, idx);
+
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1
+ && ! re_string_is_single_byte_char (pstr, pstr->cur_idx + idx))
+ return re_string_peek_byte (pstr, idx);
+#endif
+
+ off = pstr->cur_idx + idx;
+#ifdef RE_ENABLE_I18N
+ if (pstr->offsets_needed)
+ off = pstr->offsets[off];
+#endif
+
+ ch = pstr->raw_mbs[pstr->raw_mbs_idx + off];
+
+#ifdef RE_ENABLE_I18N
+ /* Ensure that e.g. for tr_TR.UTF-8 BACKSLASH DOTLESS SMALL LETTER I
+ this function returns CAPITAL LETTER I instead of first byte of
+ DOTLESS SMALL LETTER I. The latter would confuse the parser,
+ since peek_byte_case doesn't advance cur_idx in any way. */
+ if (pstr->offsets_needed && !isascii (ch))
+ return re_string_peek_byte (pstr, idx);
+#endif
+
+ return ch;
+}
+
+static unsigned char
+internal_function __attribute ((pure))
+re_string_fetch_byte_case (re_string_t *pstr)
+{
+ if (BE (!pstr->mbs_allocated, 1))
+ return re_string_fetch_byte (pstr);
+
+#ifdef RE_ENABLE_I18N
+ if (pstr->offsets_needed)
+ {
+ Idx off;
+ int ch;
+
+ /* For tr_TR.UTF-8 [[:islower:]] there is
+ [[: CAPITAL LETTER I WITH DOT lower:]] in mbs. Skip
+ in that case the whole multi-byte character and return
+ the original letter. On the other side, with
+ [[: DOTLESS SMALL LETTER I return [[:I, as doing
+ anything else would complicate things too much. */
+
+ if (!re_string_first_byte (pstr, pstr->cur_idx))
+ return re_string_fetch_byte (pstr);
+
+ off = pstr->offsets[pstr->cur_idx];
+ ch = pstr->raw_mbs[pstr->raw_mbs_idx + off];
+
+ if (! isascii (ch))
+ return re_string_fetch_byte (pstr);
+
+ re_string_skip_bytes (pstr,
+ re_string_char_size_at (pstr, pstr->cur_idx));
+ return ch;
+ }
+#endif
+
+ return pstr->raw_mbs[pstr->raw_mbs_idx + pstr->cur_idx++];
+}
+
+static void
+internal_function
+re_string_destruct (re_string_t *pstr)
+{
+#ifdef RE_ENABLE_I18N
+ re_free (pstr->wcs);
+ re_free (pstr->offsets);
+#endif /* RE_ENABLE_I18N */
+ if (pstr->mbs_allocated)
+ re_free (pstr->mbs);
+}
+
+/* Return the context at IDX in INPUT. */
+
+static unsigned int
+internal_function
+re_string_context_at (const re_string_t *input, Idx idx, int eflags)
+{
+ int c;
+ if (BE (! REG_VALID_INDEX (idx), 0))
+ /* In this case, we use the value stored in input->tip_context,
+ since we can't know the character in input->mbs[-1] here. */
+ return input->tip_context;
+ if (BE (idx == input->len, 0))
+ return ((eflags & REG_NOTEOL) ? CONTEXT_ENDBUF
+ : CONTEXT_NEWLINE | CONTEXT_ENDBUF);
+#ifdef RE_ENABLE_I18N
+ if (input->mb_cur_max > 1)
+ {
+ wint_t wc;
+ Idx wc_idx = idx;
+ while(input->wcs[wc_idx] == WEOF)
+ {
+#ifdef DEBUG
+ /* It must not happen. */
+ assert (REG_VALID_INDEX (wc_idx));
+#endif
+ --wc_idx;
+ if (! REG_VALID_INDEX (wc_idx))
+ return input->tip_context;
+ }
+ wc = input->wcs[wc_idx];
+ if (BE (input->word_ops_used != 0, 0) && IS_WIDE_WORD_CHAR (wc))
+ return CONTEXT_WORD;
+ return (IS_WIDE_NEWLINE (wc) && input->newline_anchor
+ ? CONTEXT_NEWLINE : 0);
+ }
+ else
+#endif
+ {
+ c = re_string_byte_at (input, idx);
+ if (bitset_contain (input->word_char, c))
+ return CONTEXT_WORD;
+ return IS_NEWLINE (c) && input->newline_anchor ? CONTEXT_NEWLINE : 0;
+ }
+}
+
+/* Functions for set operation. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_alloc (re_node_set *set, Idx size)
+{
+ set->alloc = size;
+ set->nelem = 0;
+ set->elems = re_malloc (Idx, size);
+ if (BE (set->elems == NULL, 0))
+ return REG_ESPACE;
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_1 (re_node_set *set, Idx elem)
+{
+ set->alloc = 1;
+ set->nelem = 1;
+ set->elems = re_malloc (Idx, 1);
+ if (BE (set->elems == NULL, 0))
+ {
+ set->alloc = set->nelem = 0;
+ return REG_ESPACE;
+ }
+ set->elems[0] = elem;
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_2 (re_node_set *set, Idx elem1, Idx elem2)
+{
+ set->alloc = 2;
+ set->elems = re_malloc (Idx, 2);
+ if (BE (set->elems == NULL, 0))
+ return REG_ESPACE;
+ if (elem1 == elem2)
+ {
+ set->nelem = 1;
+ set->elems[0] = elem1;
+ }
+ else
+ {
+ set->nelem = 2;
+ if (elem1 < elem2)
+ {
+ set->elems[0] = elem1;
+ set->elems[1] = elem2;
+ }
+ else
+ {
+ set->elems[0] = elem2;
+ set->elems[1] = elem1;
+ }
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_copy (re_node_set *dest, const re_node_set *src)
+{
+ dest->nelem = src->nelem;
+ if (src->nelem > 0)
+ {
+ dest->alloc = dest->nelem;
+ dest->elems = re_malloc (Idx, dest->alloc);
+ if (BE (dest->elems == NULL, 0))
+ {
+ dest->alloc = dest->nelem = 0;
+ return REG_ESPACE;
+ }
+ memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
+ }
+ else
+ re_node_set_init_empty (dest);
+ return REG_NOERROR;
+}
+
+/* Calculate the intersection of the sets SRC1 and SRC2. And merge it to
+ DEST. Return value indicate the error code or REG_NOERROR if succeeded.
+ Note: We assume dest->elems is NULL, when dest->alloc is 0. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_add_intersect (re_node_set *dest, const re_node_set *src1,
+ const re_node_set *src2)
+{
+ Idx i1, i2, is, id, delta, sbase;
+ if (src1->nelem == 0 || src2->nelem == 0)
+ return REG_NOERROR;
+
+ /* We need dest->nelem + 2 * elems_in_intersection; this is a
+ conservative estimate. */
+ if (src1->nelem + src2->nelem + dest->nelem > dest->alloc)
+ {
+ Idx new_alloc = src1->nelem + src2->nelem + dest->alloc;
+ Idx *new_elems = re_realloc (dest->elems, Idx, new_alloc);
+ if (BE (new_elems == NULL, 0))
+ return REG_ESPACE;
+ dest->elems = new_elems;
+ dest->alloc = new_alloc;
+ }
+
+ /* Find the items in the intersection of SRC1 and SRC2, and copy
+ into the top of DEST those that are not already in DEST itself. */
+ sbase = dest->nelem + src1->nelem + src2->nelem;
+ i1 = src1->nelem - 1;
+ i2 = src2->nelem - 1;
+ id = dest->nelem - 1;
+ for (;;)
+ {
+ if (src1->elems[i1] == src2->elems[i2])
+ {
+ /* Try to find the item in DEST. Maybe we could binary search? */
+ while (REG_VALID_INDEX (id) && dest->elems[id] > src1->elems[i1])
+ --id;
+
+ if (! REG_VALID_INDEX (id) || dest->elems[id] != src1->elems[i1])
+ dest->elems[--sbase] = src1->elems[i1];
+
+ if (! REG_VALID_INDEX (--i1) || ! REG_VALID_INDEX (--i2))
+ break;
+ }
+
+ /* Lower the highest of the two items. */
+ else if (src1->elems[i1] < src2->elems[i2])
+ {
+ if (! REG_VALID_INDEX (--i2))
+ break;
+ }
+ else
+ {
+ if (! REG_VALID_INDEX (--i1))
+ break;
+ }
+ }
+
+ id = dest->nelem - 1;
+ is = dest->nelem + src1->nelem + src2->nelem - 1;
+ delta = is - sbase + 1;
+
+ /* Now copy. When DELTA becomes zero, the remaining
+ DEST elements are already in place; this is more or
+ less the same loop that is in re_node_set_merge. */
+ dest->nelem += delta;
+ if (delta > 0 && REG_VALID_INDEX (id))
+ for (;;)
+ {
+ if (dest->elems[is] > dest->elems[id])
+ {
+ /* Copy from the top. */
+ dest->elems[id + delta--] = dest->elems[is--];
+ if (delta == 0)
+ break;
+ }
+ else
+ {
+ /* Slide from the bottom. */
+ dest->elems[id + delta] = dest->elems[id];
+ if (! REG_VALID_INDEX (--id))
+ break;
+ }
+ }
+
+ /* Copy remaining SRC elements. */
+ memcpy (dest->elems, dest->elems + sbase, delta * sizeof (Idx));
+
+ return REG_NOERROR;
+}
+
+/* Calculate the union set of the sets SRC1 and SRC2. And store it to
+ DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_init_union (re_node_set *dest, const re_node_set *src1,
+ const re_node_set *src2)
+{
+ Idx i1, i2, id;
+ if (src1 != NULL && src1->nelem > 0 && src2 != NULL && src2->nelem > 0)
+ {
+ dest->alloc = src1->nelem + src2->nelem;
+ dest->elems = re_malloc (Idx, dest->alloc);
+ if (BE (dest->elems == NULL, 0))
+ return REG_ESPACE;
+ }
+ else
+ {
+ if (src1 != NULL && src1->nelem > 0)
+ return re_node_set_init_copy (dest, src1);
+ else if (src2 != NULL && src2->nelem > 0)
+ return re_node_set_init_copy (dest, src2);
+ else
+ re_node_set_init_empty (dest);
+ return REG_NOERROR;
+ }
+ for (i1 = i2 = id = 0 ; i1 < src1->nelem && i2 < src2->nelem ;)
+ {
+ if (src1->elems[i1] > src2->elems[i2])
+ {
+ dest->elems[id++] = src2->elems[i2++];
+ continue;
+ }
+ if (src1->elems[i1] == src2->elems[i2])
+ ++i2;
+ dest->elems[id++] = src1->elems[i1++];
+ }
+ if (i1 < src1->nelem)
+ {
+ memcpy (dest->elems + id, src1->elems + i1,
+ (src1->nelem - i1) * sizeof (Idx));
+ id += src1->nelem - i1;
+ }
+ else if (i2 < src2->nelem)
+ {
+ memcpy (dest->elems + id, src2->elems + i2,
+ (src2->nelem - i2) * sizeof (Idx));
+ id += src2->nelem - i2;
+ }
+ dest->nelem = id;
+ return REG_NOERROR;
+}
+
+/* Calculate the union set of the sets DEST and SRC. And store it to
+ DEST. Return value indicate the error code or REG_NOERROR if succeeded. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_node_set_merge (re_node_set *dest, const re_node_set *src)
+{
+ Idx is, id, sbase, delta;
+ if (src == NULL || src->nelem == 0)
+ return REG_NOERROR;
+ if (dest->alloc < 2 * src->nelem + dest->nelem)
+ {
+ Idx new_alloc = 2 * (src->nelem + dest->alloc);
+ Idx *new_buffer = re_realloc (dest->elems, Idx, new_alloc);
+ if (BE (new_buffer == NULL, 0))
+ return REG_ESPACE;
+ dest->elems = new_buffer;
+ dest->alloc = new_alloc;
+ }
+
+ if (BE (dest->nelem == 0, 0))
+ {
+ dest->nelem = src->nelem;
+ memcpy (dest->elems, src->elems, src->nelem * sizeof (Idx));
+ return REG_NOERROR;
+ }
+
+ /* Copy into the top of DEST the items of SRC that are not
+ found in DEST. Maybe we could binary search in DEST? */
+ for (sbase = dest->nelem + 2 * src->nelem,
+ is = src->nelem - 1, id = dest->nelem - 1;
+ REG_VALID_INDEX (is) && REG_VALID_INDEX (id); )
+ {
+ if (dest->elems[id] == src->elems[is])
+ is--, id--;
+ else if (dest->elems[id] < src->elems[is])
+ dest->elems[--sbase] = src->elems[is--];
+ else /* if (dest->elems[id] > src->elems[is]) */
+ --id;
+ }
+
+ if (REG_VALID_INDEX (is))
+ {
+ /* If DEST is exhausted, the remaining items of SRC must be unique. */
+ sbase -= is + 1;
+ memcpy (dest->elems + sbase, src->elems, (is + 1) * sizeof (Idx));
+ }
+
+ id = dest->nelem - 1;
+ is = dest->nelem + 2 * src->nelem - 1;
+ delta = is - sbase + 1;
+ if (delta == 0)
+ return REG_NOERROR;
+
+ /* Now copy. When DELTA becomes zero, the remaining
+ DEST elements are already in place. */
+ dest->nelem += delta;
+ for (;;)
+ {
+ if (dest->elems[is] > dest->elems[id])
+ {
+ /* Copy from the top. */
+ dest->elems[id + delta--] = dest->elems[is--];
+ if (delta == 0)
+ break;
+ }
+ else
+ {
+ /* Slide from the bottom. */
+ dest->elems[id + delta] = dest->elems[id];
+ if (! REG_VALID_INDEX (--id))
+ {
+ /* Copy remaining SRC elements. */
+ memcpy (dest->elems, dest->elems + sbase,
+ delta * sizeof (Idx));
+ break;
+ }
+ }
+ }
+
+ return REG_NOERROR;
+}
+
+/* Insert the new element ELEM to the re_node_set* SET.
+ SET should not already have ELEM.
+ Return true if successful. */
+
+static bool
+internal_function __attribute_warn_unused_result__
+re_node_set_insert (re_node_set *set, Idx elem)
+{
+ Idx idx;
+ /* In case the set is empty. */
+ if (set->alloc == 0)
+ return BE (re_node_set_init_1 (set, elem) == REG_NOERROR, 1);
+
+ if (BE (set->nelem, 0) == 0)
+ {
+ /* We already guaranteed above that set->alloc != 0. */
+ set->elems[0] = elem;
+ ++set->nelem;
+ return true;
+ }
+
+ /* Realloc if we need. */
+ if (set->alloc == set->nelem)
+ {
+ Idx *new_elems;
+ set->alloc = set->alloc * 2;
+ new_elems = re_realloc (set->elems, Idx, set->alloc);
+ if (BE (new_elems == NULL, 0))
+ return false;
+ set->elems = new_elems;
+ }
+
+ /* Move the elements which follows the new element. Test the
+ first element separately to skip a check in the inner loop. */
+ if (elem < set->elems[0])
+ {
+ idx = 0;
+ for (idx = set->nelem; idx > 0; idx--)
+ set->elems[idx] = set->elems[idx - 1];
+ }
+ else
+ {
+ for (idx = set->nelem; set->elems[idx - 1] > elem; idx--)
+ set->elems[idx] = set->elems[idx - 1];
+ }
+
+ /* Insert the new element. */
+ set->elems[idx] = elem;
+ ++set->nelem;
+ return true;
+}
+
+/* Insert the new element ELEM to the re_node_set* SET.
+ SET should not already have any element greater than or equal to ELEM.
+ Return true if successful. */
+
+static bool
+internal_function __attribute_warn_unused_result__
+re_node_set_insert_last (re_node_set *set, Idx elem)
+{
+ /* Realloc if we need. */
+ if (set->alloc == set->nelem)
+ {
+ Idx *new_elems;
+ set->alloc = (set->alloc + 1) * 2;
+ new_elems = re_realloc (set->elems, Idx, set->alloc);
+ if (BE (new_elems == NULL, 0))
+ return false;
+ set->elems = new_elems;
+ }
+
+ /* Insert the new element. */
+ set->elems[set->nelem++] = elem;
+ return true;
+}
+
+/* Compare two node sets SET1 and SET2.
+ Return true if SET1 and SET2 are equivalent. */
+
+static bool
+internal_function __attribute ((pure))
+re_node_set_compare (const re_node_set *set1, const re_node_set *set2)
+{
+ Idx i;
+ if (set1 == NULL || set2 == NULL || set1->nelem != set2->nelem)
+ return false;
+ for (i = set1->nelem ; REG_VALID_INDEX (--i) ; )
+ if (set1->elems[i] != set2->elems[i])
+ return false;
+ return true;
+}
+
+/* Return (idx + 1) if SET contains the element ELEM, return 0 otherwise. */
+
+static Idx
+internal_function __attribute ((pure))
+re_node_set_contains (const re_node_set *set, Idx elem)
+{
+ __re_size_t idx, right, mid;
+ if (! REG_VALID_NONZERO_INDEX (set->nelem))
+ return 0;
+
+ /* Binary search the element. */
+ idx = 0;
+ right = set->nelem - 1;
+ while (idx < right)
+ {
+ mid = (idx + right) / 2;
+ if (set->elems[mid] < elem)
+ idx = mid + 1;
+ else
+ right = mid;
+ }
+ return set->elems[idx] == elem ? idx + 1 : 0;
+}
+
+static void
+internal_function
+re_node_set_remove_at (re_node_set *set, Idx idx)
+{
+ if (idx < 0 || idx >= set->nelem)
+ return;
+ --set->nelem;
+ for (; idx < set->nelem; idx++)
+ set->elems[idx] = set->elems[idx + 1];
+}
+
+
+/* Add the token TOKEN to dfa->nodes, and return the index of the token.
+ Or return REG_MISSING if an error occurred. */
+
+static Idx
+internal_function
+re_dfa_add_node (re_dfa_t *dfa, re_token_t token)
+{
+ if (BE (dfa->nodes_len >= dfa->nodes_alloc, 0))
+ {
+ size_t new_nodes_alloc = dfa->nodes_alloc * 2;
+ Idx *new_nexts, *new_indices;
+ re_node_set *new_edests, *new_eclosures;
+ re_token_t *new_nodes;
+ size_t max_object_size =
+ MAX (sizeof (re_token_t),
+ MAX (sizeof (re_node_set),
+ sizeof (Idx)));
+
+ /* Avoid overflows. */
+ if (BE (SIZE_MAX / 2 / max_object_size < dfa->nodes_alloc, 0))
+ return REG_MISSING;
+
+ new_nodes = re_realloc (dfa->nodes, re_token_t, new_nodes_alloc);
+ if (BE (new_nodes == NULL, 0))
+ return REG_MISSING;
+ dfa->nodes = new_nodes;
+ new_nexts = re_realloc (dfa->nexts, Idx, new_nodes_alloc);
+ new_indices = re_realloc (dfa->org_indices, Idx, new_nodes_alloc);
+ new_edests = re_realloc (dfa->edests, re_node_set, new_nodes_alloc);
+ new_eclosures = re_realloc (dfa->eclosures, re_node_set, new_nodes_alloc);
+ if (BE (new_nexts == NULL || new_indices == NULL
+ || new_edests == NULL || new_eclosures == NULL, 0))
+ return REG_MISSING;
+ dfa->nexts = new_nexts;
+ dfa->org_indices = new_indices;
+ dfa->edests = new_edests;
+ dfa->eclosures = new_eclosures;
+ dfa->nodes_alloc = new_nodes_alloc;
+ }
+ dfa->nodes[dfa->nodes_len] = token;
+ dfa->nodes[dfa->nodes_len].constraint = 0;
+#ifdef RE_ENABLE_I18N
+ {
+ int type = token.type;
+ dfa->nodes[dfa->nodes_len].accept_mb =
+ (type == OP_PERIOD && dfa->mb_cur_max > 1) || type == COMPLEX_BRACKET;
+ }
+#endif
+ dfa->nexts[dfa->nodes_len] = REG_MISSING;
+ re_node_set_init_empty (dfa->edests + dfa->nodes_len);
+ re_node_set_init_empty (dfa->eclosures + dfa->nodes_len);
+ return dfa->nodes_len++;
+}
+
+static inline re_hashval_t
+internal_function
+calc_state_hash (const re_node_set *nodes, unsigned int context)
+{
+ re_hashval_t hash = nodes->nelem + context;
+ Idx i;
+ for (i = 0 ; i < nodes->nelem ; i++)
+ hash += nodes->elems[i];
+ return hash;
+}
+
+/* Search for the state whose node_set is equivalent to NODES.
+ Return the pointer to the state, if we found it in the DFA.
+ Otherwise create the new one and return it. In case of an error
+ return NULL and set the error code in ERR.
+ Note: - We assume NULL as the invalid state, then it is possible that
+ return value is NULL and ERR is REG_NOERROR.
+ - We never return non-NULL value in case of any errors, it is for
+ optimization. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+re_acquire_state (reg_errcode_t *err, const re_dfa_t *dfa,
+ const re_node_set *nodes)
+{
+ re_hashval_t hash;
+ re_dfastate_t *new_state;
+ struct re_state_table_entry *spot;
+ Idx i;
+#ifdef lint
+ /* Suppress bogus uninitialized-variable warnings. */
+ *err = REG_NOERROR;
+#endif
+ if (BE (nodes->nelem == 0, 0))
+ {
+ *err = REG_NOERROR;
+ return NULL;
+ }
+ hash = calc_state_hash (nodes, 0);
+ spot = dfa->state_table + (hash & dfa->state_hash_mask);
+
+ for (i = 0 ; i < spot->num ; i++)
+ {
+ re_dfastate_t *state = spot->array[i];
+ if (hash != state->hash)
+ continue;
+ if (re_node_set_compare (&state->nodes, nodes))
+ return state;
+ }
+
+ /* There are no appropriate state in the dfa, create the new one. */
+ new_state = create_ci_newstate (dfa, nodes, hash);
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
+}
+
+/* Search for the state whose node_set is equivalent to NODES and
+ whose context is equivalent to CONTEXT.
+ Return the pointer to the state, if we found it in the DFA.
+ Otherwise create the new one and return it. In case of an error
+ return NULL and set the error code in ERR.
+ Note: - We assume NULL as the invalid state, then it is possible that
+ return value is NULL and ERR is REG_NOERROR.
+ - We never return non-NULL value in case of any errors, it is for
+ optimization. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+re_acquire_state_context (reg_errcode_t *err, const re_dfa_t *dfa,
+ const re_node_set *nodes, unsigned int context)
+{
+ re_hashval_t hash;
+ re_dfastate_t *new_state;
+ struct re_state_table_entry *spot;
+ Idx i;
+#ifdef lint
+ /* Suppress bogus uninitialized-variable warnings. */
+ *err = REG_NOERROR;
+#endif
+ if (nodes->nelem == 0)
+ {
+ *err = REG_NOERROR;
+ return NULL;
+ }
+ hash = calc_state_hash (nodes, context);
+ spot = dfa->state_table + (hash & dfa->state_hash_mask);
+
+ for (i = 0 ; i < spot->num ; i++)
+ {
+ re_dfastate_t *state = spot->array[i];
+ if (state->hash == hash
+ && state->context == context
+ && re_node_set_compare (state->entrance_nodes, nodes))
+ return state;
+ }
+ /* There are no appropriate state in 'dfa', create the new one. */
+ new_state = create_cd_newstate (dfa, nodes, context, hash);
+ if (BE (new_state == NULL, 0))
+ *err = REG_ESPACE;
+
+ return new_state;
+}
+
+/* Finish initialization of the new state NEWSTATE, and using its hash value
+ HASH put in the appropriate bucket of DFA's state table. Return value
+ indicates the error code if failed. */
+
+static reg_errcode_t
+__attribute_warn_unused_result__
+register_state (const re_dfa_t *dfa, re_dfastate_t *newstate,
+ re_hashval_t hash)
+{
+ struct re_state_table_entry *spot;
+ reg_errcode_t err;
+ Idx i;
+
+ newstate->hash = hash;
+ err = re_node_set_alloc (&newstate->non_eps_nodes, newstate->nodes.nelem);
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ESPACE;
+ for (i = 0; i < newstate->nodes.nelem; i++)
+ {
+ Idx elem = newstate->nodes.elems[i];
+ if (!IS_EPSILON_NODE (dfa->nodes[elem].type))
+ if (BE (! re_node_set_insert_last (&newstate->non_eps_nodes, elem), 0))
+ return REG_ESPACE;
+ }
+
+ spot = dfa->state_table + (hash & dfa->state_hash_mask);
+ if (BE (spot->alloc <= spot->num, 0))
+ {
+ Idx new_alloc = 2 * spot->num + 2;
+ re_dfastate_t **new_array = re_realloc (spot->array, re_dfastate_t *,
+ new_alloc);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ spot->array = new_array;
+ spot->alloc = new_alloc;
+ }
+ spot->array[spot->num++] = newstate;
+ return REG_NOERROR;
+}
+
+static void
+free_state (re_dfastate_t *state)
+{
+ re_node_set_free (&state->non_eps_nodes);
+ re_node_set_free (&state->inveclosure);
+ if (state->entrance_nodes != &state->nodes)
+ {
+ re_node_set_free (state->entrance_nodes);
+ re_free (state->entrance_nodes);
+ }
+ re_node_set_free (&state->nodes);
+ re_free (state->word_trtable);
+ re_free (state->trtable);
+ re_free (state);
+}
+
+/* Create the new state which is independ of contexts.
+ Return the new state if succeeded, otherwise return NULL. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
+ re_hashval_t hash)
+{
+ Idx i;
+ reg_errcode_t err;
+ re_dfastate_t *newstate;
+
+ newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
+ if (BE (newstate == NULL, 0))
+ return NULL;
+ err = re_node_set_init_copy (&newstate->nodes, nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_free (newstate);
+ return NULL;
+ }
+
+ newstate->entrance_nodes = &newstate->nodes;
+ for (i = 0 ; i < nodes->nelem ; i++)
+ {
+ re_token_t *node = dfa->nodes + nodes->elems[i];
+ re_token_type_t type = node->type;
+ if (type == CHARACTER && !node->constraint)
+ continue;
+#ifdef RE_ENABLE_I18N
+ newstate->accept_mb |= node->accept_mb;
+#endif /* RE_ENABLE_I18N */
+
+ /* If the state has the halt node, the state is a halt state. */
+ if (type == END_OF_RE)
+ newstate->halt = 1;
+ else if (type == OP_BACK_REF)
+ newstate->has_backref = 1;
+ else if (type == ANCHOR || node->constraint)
+ newstate->has_constraint = 1;
+ }
+ err = register_state (dfa, newstate, hash);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ free_state (newstate);
+ newstate = NULL;
+ }
+ return newstate;
+}
+
+/* Create the new state which is depend on the context CONTEXT.
+ Return the new state if succeeded, otherwise return NULL. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
+ unsigned int context, re_hashval_t hash)
+{
+ Idx i, nctx_nodes = 0;
+ reg_errcode_t err;
+ re_dfastate_t *newstate;
+
+ newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
+ if (BE (newstate == NULL, 0))
+ return NULL;
+ err = re_node_set_init_copy (&newstate->nodes, nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_free (newstate);
+ return NULL;
+ }
+
+ newstate->context = context;
+ newstate->entrance_nodes = &newstate->nodes;
+
+ for (i = 0 ; i < nodes->nelem ; i++)
+ {
+ re_token_t *node = dfa->nodes + nodes->elems[i];
+ re_token_type_t type = node->type;
+ unsigned int constraint = node->constraint;
+
+ if (type == CHARACTER && !constraint)
+ continue;
+#ifdef RE_ENABLE_I18N
+ newstate->accept_mb |= node->accept_mb;
+#endif /* RE_ENABLE_I18N */
+
+ /* If the state has the halt node, the state is a halt state. */
+ if (type == END_OF_RE)
+ newstate->halt = 1;
+ else if (type == OP_BACK_REF)
+ newstate->has_backref = 1;
+
+ if (constraint)
+ {
+ if (newstate->entrance_nodes == &newstate->nodes)
+ {
+ newstate->entrance_nodes = re_malloc (re_node_set, 1);
+ if (BE (newstate->entrance_nodes == NULL, 0))
+ {
+ free_state (newstate);
+ return NULL;
+ }
+ if (re_node_set_init_copy (newstate->entrance_nodes, nodes)
+ != REG_NOERROR)
+ return NULL;
+ nctx_nodes = 0;
+ newstate->has_constraint = 1;
+ }
+
+ if (NOT_SATISFY_PREV_CONSTRAINT (constraint,context))
+ {
+ re_node_set_remove_at (&newstate->nodes, i - nctx_nodes);
+ ++nctx_nodes;
+ }
+ }
+ }
+ err = register_state (dfa, newstate, hash);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ free_state (newstate);
+ newstate = NULL;
+ }
+ return newstate;
+}
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
new file mode 100644
index 000000000..726119203
--- /dev/null
+++ b/lib/regex_internal.h
@@ -0,0 +1,866 @@
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _REGEX_INTERNAL_H
+#define _REGEX_INTERNAL_H 1
+
+#include <assert.h>
+#include <ctype.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <langinfo.h>
+#ifndef _LIBC
+# include "localcharset.h"
+#endif
+#include <locale.h>
+
+#include <wchar.h>
+#include <wctype.h>
+#include <stdint.h>
+#if defined _LIBC
+# include <bits/libc-lock.h>
+#else
+# define __libc_lock_init(NAME) do { } while (0)
+# define __libc_lock_lock(NAME) do { } while (0)
+# define __libc_lock_unlock(NAME) do { } while (0)
+#endif
+
+/* In case that the system doesn't have isblank(). */
+#if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
+# define isblank(ch) ((ch) == ' ' || (ch) == '\t')
+#endif
+
+#ifdef _LIBC
+# ifndef _RE_DEFINE_LOCALE_FUNCTIONS
+# define _RE_DEFINE_LOCALE_FUNCTIONS 1
+# include <locale/localeinfo.h>
+# include <locale/elem-hash.h>
+# include <locale/coll-lookup.h>
+# endif
+#endif
+
+/* This is for other GNU distributions with internationalized messages. */
+#if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC
+# include <libintl.h>
+# ifdef _LIBC
+# undef gettext
+# define gettext(msgid) \
+ INTUSE(__dcgettext) (_libc_intl_domainname, msgid, LC_MESSAGES)
+# endif
+#else
+# define gettext(msgid) (msgid)
+#endif
+
+#ifndef gettext_noop
+/* This define is so xgettext can find the internationalizable
+ strings. */
+# define gettext_noop(String) String
+#endif
+
+/* For loser systems without the definition. */
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+
+#if (defined MB_CUR_MAX && HAVE_WCTYPE_H && HAVE_ISWCTYPE && HAVE_WCSCOLL) || _LIBC
+# define RE_ENABLE_I18N
+#endif
+
+#if __GNUC__ >= 3
+# define BE(expr, val) __builtin_expect (expr, val)
+#else
+# define BE(expr, val) (expr)
+# ifdef _LIBC
+# define inline
+# endif
+#endif
+
+/* Number of ASCII characters. */
+#define ASCII_CHARS 0x80
+
+/* Number of single byte characters. */
+#define SBC_MAX (UCHAR_MAX + 1)
+
+#define COLL_ELEM_LEN_MAX 8
+
+/* The character which represents newline. */
+#define NEWLINE_CHAR '\n'
+#define WIDE_NEWLINE_CHAR L'\n'
+
+/* Rename to standard API for using out of glibc. */
+#ifndef _LIBC
+# define __wctype wctype
+# define __iswctype iswctype
+# define __btowc btowc
+# define __wcrtomb wcrtomb
+# define __mbrtowc mbrtowc
+# define __regfree regfree
+# define attribute_hidden
+#endif /* not _LIBC */
+
+#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+# define __attribute(arg) __attribute__ (arg)
+#else
+# define __attribute(arg)
+#endif
+
+typedef __re_idx_t Idx;
+
+/* Special return value for failure to match. */
+#define REG_MISSING ((Idx) -1)
+
+/* Special return value for internal error. */
+#define REG_ERROR ((Idx) -2)
+
+/* Test whether N is a valid index, and is not one of the above. */
+#ifdef _REGEX_LARGE_OFFSETS
+# define REG_VALID_INDEX(n) ((Idx) (n) < REG_ERROR)
+#else
+# define REG_VALID_INDEX(n) (0 <= (n))
+#endif
+
+/* Test whether N is a valid nonzero index. */
+#ifdef _REGEX_LARGE_OFFSETS
+# define REG_VALID_NONZERO_INDEX(n) ((Idx) ((n) - 1) < (Idx) (REG_ERROR - 1))
+#else
+# define REG_VALID_NONZERO_INDEX(n) (0 < (n))
+#endif
+
+/* A hash value, suitable for computing hash tables. */
+typedef __re_size_t re_hashval_t;
+
+/* An integer used to represent a set of bits. It must be unsigned,
+ and must be at least as wide as unsigned int. */
+typedef unsigned long int bitset_word_t;
+/* All bits set in a bitset_word_t. */
+#define BITSET_WORD_MAX ULONG_MAX
+
+/* Number of bits in a bitset_word_t. For portability to hosts with
+ padding bits, do not use '(sizeof (bitset_word_t) * CHAR_BIT)';
+ instead, deduce it directly from BITSET_WORD_MAX. Avoid
+ greater-than-32-bit integers and unconditional shifts by more than
+ 31 bits, as they're not portable. */
+#if BITSET_WORD_MAX == 0xffffffffUL
+# define BITSET_WORD_BITS 32
+#elif BITSET_WORD_MAX >> 31 >> 4 == 1
+# define BITSET_WORD_BITS 36
+#elif BITSET_WORD_MAX >> 31 >> 16 == 1
+# define BITSET_WORD_BITS 48
+#elif BITSET_WORD_MAX >> 31 >> 28 == 1
+# define BITSET_WORD_BITS 60
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 1 == 1
+# define BITSET_WORD_BITS 64
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 9 == 1
+# define BITSET_WORD_BITS 72
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 3 == 1
+# define BITSET_WORD_BITS 128
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 == 1
+# define BITSET_WORD_BITS 256
+#elif BITSET_WORD_MAX >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 31 >> 7 > 1
+# define BITSET_WORD_BITS 257 /* any value > SBC_MAX will do here */
+# if BITSET_WORD_BITS <= SBC_MAX
+# error "Invalid SBC_MAX"
+# endif
+#else
+# error "Add case for new bitset_word_t size"
+#endif
+
+/* Number of bitset_word_t values in a bitset_t. */
+#define BITSET_WORDS ((SBC_MAX + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
+
+typedef bitset_word_t bitset_t[BITSET_WORDS];
+typedef bitset_word_t *re_bitset_ptr_t;
+typedef const bitset_word_t *re_const_bitset_ptr_t;
+
+#define PREV_WORD_CONSTRAINT 0x0001
+#define PREV_NOTWORD_CONSTRAINT 0x0002
+#define NEXT_WORD_CONSTRAINT 0x0004
+#define NEXT_NOTWORD_CONSTRAINT 0x0008
+#define PREV_NEWLINE_CONSTRAINT 0x0010
+#define NEXT_NEWLINE_CONSTRAINT 0x0020
+#define PREV_BEGBUF_CONSTRAINT 0x0040
+#define NEXT_ENDBUF_CONSTRAINT 0x0080
+#define WORD_DELIM_CONSTRAINT 0x0100
+#define NOT_WORD_DELIM_CONSTRAINT 0x0200
+
+typedef enum
+{
+ INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
+ WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT,
+ WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
+ INSIDE_NOTWORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT,
+ LINE_FIRST = PREV_NEWLINE_CONSTRAINT,
+ LINE_LAST = NEXT_NEWLINE_CONSTRAINT,
+ BUF_FIRST = PREV_BEGBUF_CONSTRAINT,
+ BUF_LAST = NEXT_ENDBUF_CONSTRAINT,
+ WORD_DELIM = WORD_DELIM_CONSTRAINT,
+ NOT_WORD_DELIM = NOT_WORD_DELIM_CONSTRAINT
+} re_context_type;
+
+typedef struct
+{
+ Idx alloc;
+ Idx nelem;
+ Idx *elems;
+} re_node_set;
+
+typedef enum
+{
+ NON_TYPE = 0,
+
+ /* Node type, These are used by token, node, tree. */
+ CHARACTER = 1,
+ END_OF_RE = 2,
+ SIMPLE_BRACKET = 3,
+ OP_BACK_REF = 4,
+ OP_PERIOD = 5,
+#ifdef RE_ENABLE_I18N
+ COMPLEX_BRACKET = 6,
+ OP_UTF8_PERIOD = 7,
+#endif /* RE_ENABLE_I18N */
+
+ /* We define EPSILON_BIT as a macro so that OP_OPEN_SUBEXP is used
+ when the debugger shows values of this enum type. */
+#define EPSILON_BIT 8
+ OP_OPEN_SUBEXP = EPSILON_BIT | 0,
+ OP_CLOSE_SUBEXP = EPSILON_BIT | 1,
+ OP_ALT = EPSILON_BIT | 2,
+ OP_DUP_ASTERISK = EPSILON_BIT | 3,
+ ANCHOR = EPSILON_BIT | 4,
+
+ /* Tree type, these are used only by tree. */
+ CONCAT = 16,
+ SUBEXP = 17,
+
+ /* Token type, these are used only by token. */
+ OP_DUP_PLUS = 18,
+ OP_DUP_QUESTION,
+ OP_OPEN_BRACKET,
+ OP_CLOSE_BRACKET,
+ OP_CHARSET_RANGE,
+ OP_OPEN_DUP_NUM,
+ OP_CLOSE_DUP_NUM,
+ OP_NON_MATCH_LIST,
+ OP_OPEN_COLL_ELEM,
+ OP_CLOSE_COLL_ELEM,
+ OP_OPEN_EQUIV_CLASS,
+ OP_CLOSE_EQUIV_CLASS,
+ OP_OPEN_CHAR_CLASS,
+ OP_CLOSE_CHAR_CLASS,
+ OP_WORD,
+ OP_NOTWORD,
+ OP_SPACE,
+ OP_NOTSPACE,
+ BACK_SLASH
+
+} re_token_type_t;
+
+#ifdef RE_ENABLE_I18N
+typedef struct
+{
+ /* Multibyte characters. */
+ wchar_t *mbchars;
+
+ /* Collating symbols. */
+# ifdef _LIBC
+ int32_t *coll_syms;
+# endif
+
+ /* Equivalence classes. */
+# ifdef _LIBC
+ int32_t *equiv_classes;
+# endif
+
+ /* Range expressions. */
+# ifdef _LIBC
+ uint32_t *range_starts;
+ uint32_t *range_ends;
+# else /* not _LIBC */
+ wchar_t *range_starts;
+ wchar_t *range_ends;
+# endif /* not _LIBC */
+
+ /* Character classes. */
+ wctype_t *char_classes;
+
+ /* If this character set is the non-matching list. */
+ unsigned int non_match : 1;
+
+ /* # of multibyte characters. */
+ Idx nmbchars;
+
+ /* # of collating symbols. */
+ Idx ncoll_syms;
+
+ /* # of equivalence classes. */
+ Idx nequiv_classes;
+
+ /* # of range expressions. */
+ Idx nranges;
+
+ /* # of character classes. */
+ Idx nchar_classes;
+} re_charset_t;
+#endif /* RE_ENABLE_I18N */
+
+typedef struct
+{
+ union
+ {
+ unsigned char c; /* for CHARACTER */
+ re_bitset_ptr_t sbcset; /* for SIMPLE_BRACKET */
+#ifdef RE_ENABLE_I18N
+ re_charset_t *mbcset; /* for COMPLEX_BRACKET */
+#endif /* RE_ENABLE_I18N */
+ Idx idx; /* for BACK_REF */
+ re_context_type ctx_type; /* for ANCHOR */
+ } opr;
+#if __GNUC__ >= 2 && !defined __STRICT_ANSI__
+ re_token_type_t type : 8;
+#else
+ re_token_type_t type;
+#endif
+ unsigned int constraint : 10; /* context constraint */
+ unsigned int duplicated : 1;
+ unsigned int opt_subexp : 1;
+#ifdef RE_ENABLE_I18N
+ unsigned int accept_mb : 1;
+ /* These 2 bits can be moved into the union if needed (e.g. if running out
+ of bits; move opr.c to opr.c.c and move the flags to opr.c.flags). */
+ unsigned int mb_partial : 1;
+#endif
+ unsigned int word_char : 1;
+} re_token_t;
+
+#define IS_EPSILON_NODE(type) ((type) & EPSILON_BIT)
+
+struct re_string_t
+{
+ /* Indicate the raw buffer which is the original string passed as an
+ argument of regexec(), re_search(), etc.. */
+ const unsigned char *raw_mbs;
+ /* Store the multibyte string. In case of "case insensitive mode" like
+ REG_ICASE, upper cases of the string are stored, otherwise MBS points
+ the same address that RAW_MBS points. */
+ unsigned char *mbs;
+#ifdef RE_ENABLE_I18N
+ /* Store the wide character string which is corresponding to MBS. */
+ wint_t *wcs;
+ Idx *offsets;
+ mbstate_t cur_state;
+#endif
+ /* Index in RAW_MBS. Each character mbs[i] corresponds to
+ raw_mbs[raw_mbs_idx + i]. */
+ Idx raw_mbs_idx;
+ /* The length of the valid characters in the buffers. */
+ Idx valid_len;
+ /* The corresponding number of bytes in raw_mbs array. */
+ Idx valid_raw_len;
+ /* The length of the buffers MBS and WCS. */
+ Idx bufs_len;
+ /* The index in MBS, which is updated by re_string_fetch_byte. */
+ Idx cur_idx;
+ /* length of RAW_MBS array. */
+ Idx raw_len;
+ /* This is RAW_LEN - RAW_MBS_IDX + VALID_LEN - VALID_RAW_LEN. */
+ Idx len;
+ /* End of the buffer may be shorter than its length in the cases such
+ as re_match_2, re_search_2. Then, we use STOP for end of the buffer
+ instead of LEN. */
+ Idx raw_stop;
+ /* This is RAW_STOP - RAW_MBS_IDX adjusted through OFFSETS. */
+ Idx stop;
+
+ /* The context of mbs[0]. We store the context independently, since
+ the context of mbs[0] may be different from raw_mbs[0], which is
+ the beginning of the input string. */
+ unsigned int tip_context;
+ /* The translation passed as a part of an argument of re_compile_pattern. */
+ RE_TRANSLATE_TYPE trans;
+ /* Copy of re_dfa_t's word_char. */
+ re_const_bitset_ptr_t word_char;
+ /* true if REG_ICASE. */
+ unsigned char icase;
+ unsigned char is_utf8;
+ unsigned char map_notascii;
+ unsigned char mbs_allocated;
+ unsigned char offsets_needed;
+ unsigned char newline_anchor;
+ unsigned char word_ops_used;
+ int mb_cur_max;
+};
+typedef struct re_string_t re_string_t;
+
+
+struct re_dfa_t;
+typedef struct re_dfa_t re_dfa_t;
+
+#ifndef _LIBC
+# define internal_function
+#endif
+
+static reg_errcode_t re_string_realloc_buffers (re_string_t *pstr,
+ Idx new_buf_len)
+ internal_function;
+#ifdef RE_ENABLE_I18N
+static void build_wcs_buffer (re_string_t *pstr) internal_function;
+static reg_errcode_t build_wcs_upper_buffer (re_string_t *pstr)
+ internal_function;
+#endif /* RE_ENABLE_I18N */
+static void build_upper_buffer (re_string_t *pstr) internal_function;
+static void re_string_translate_buffer (re_string_t *pstr) internal_function;
+static unsigned int re_string_context_at (const re_string_t *input, Idx idx,
+ int eflags)
+ internal_function __attribute ((pure));
+#define re_string_peek_byte(pstr, offset) \
+ ((pstr)->mbs[(pstr)->cur_idx + offset])
+#define re_string_fetch_byte(pstr) \
+ ((pstr)->mbs[(pstr)->cur_idx++])
+#define re_string_first_byte(pstr, idx) \
+ ((idx) == (pstr)->valid_len || (pstr)->wcs[idx] != WEOF)
+#define re_string_is_single_byte_char(pstr, idx) \
+ ((pstr)->wcs[idx] != WEOF && ((pstr)->valid_len == (idx) + 1 \
+ || (pstr)->wcs[(idx) + 1] != WEOF))
+#define re_string_eoi(pstr) ((pstr)->stop <= (pstr)->cur_idx)
+#define re_string_cur_idx(pstr) ((pstr)->cur_idx)
+#define re_string_get_buffer(pstr) ((pstr)->mbs)
+#define re_string_length(pstr) ((pstr)->len)
+#define re_string_byte_at(pstr,idx) ((pstr)->mbs[idx])
+#define re_string_skip_bytes(pstr,idx) ((pstr)->cur_idx += (idx))
+#define re_string_set_index(pstr,idx) ((pstr)->cur_idx = (idx))
+
+#include <alloca.h>
+
+#ifndef _LIBC
+# if HAVE_ALLOCA
+/* The OS usually guarantees only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ allocate anything larger than 4096 bytes. Also care for the possibility
+ of a few compiler-allocated temporary stack slots. */
+# define __libc_use_alloca(n) ((n) < 4032)
+# else
+/* alloca is implemented with malloc, so just use malloc. */
+# define __libc_use_alloca(n) 0
+# undef alloca
+# define alloca(n) malloc (n)
+# endif
+#endif
+
+#ifndef MAX
+# define MAX(a,b) ((a) < (b) ? (b) : (a))
+#endif
+
+#define re_malloc(t,n) ((t *) malloc ((n) * sizeof (t)))
+#define re_realloc(p,t,n) ((t *) realloc (p, (n) * sizeof (t)))
+#define re_free(p) free (p)
+
+struct bin_tree_t
+{
+ struct bin_tree_t *parent;
+ struct bin_tree_t *left;
+ struct bin_tree_t *right;
+ struct bin_tree_t *first;
+ struct bin_tree_t *next;
+
+ re_token_t token;
+
+ /* 'node_idx' is the index in dfa->nodes, if 'type' == 0.
+ Otherwise 'type' indicate the type of this node. */
+ Idx node_idx;
+};
+typedef struct bin_tree_t bin_tree_t;
+
+#define BIN_TREE_STORAGE_SIZE \
+ ((1024 - sizeof (void *)) / sizeof (bin_tree_t))
+
+struct bin_tree_storage_t
+{
+ struct bin_tree_storage_t *next;
+ bin_tree_t data[BIN_TREE_STORAGE_SIZE];
+};
+typedef struct bin_tree_storage_t bin_tree_storage_t;
+
+#define CONTEXT_WORD 1
+#define CONTEXT_NEWLINE (CONTEXT_WORD << 1)
+#define CONTEXT_BEGBUF (CONTEXT_NEWLINE << 1)
+#define CONTEXT_ENDBUF (CONTEXT_BEGBUF << 1)
+
+#define IS_WORD_CONTEXT(c) ((c) & CONTEXT_WORD)
+#define IS_NEWLINE_CONTEXT(c) ((c) & CONTEXT_NEWLINE)
+#define IS_BEGBUF_CONTEXT(c) ((c) & CONTEXT_BEGBUF)
+#define IS_ENDBUF_CONTEXT(c) ((c) & CONTEXT_ENDBUF)
+#define IS_ORDINARY_CONTEXT(c) ((c) == 0)
+
+#define IS_WORD_CHAR(ch) (isalnum (ch) || (ch) == '_')
+#define IS_NEWLINE(ch) ((ch) == NEWLINE_CHAR)
+#define IS_WIDE_WORD_CHAR(ch) (iswalnum (ch) || (ch) == L'_')
+#define IS_WIDE_NEWLINE(ch) ((ch) == WIDE_NEWLINE_CHAR)
+
+#define NOT_SATISFY_PREV_CONSTRAINT(constraint,context) \
+ ((((constraint) & PREV_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
+ || ((constraint & PREV_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
+ || ((constraint & PREV_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context))\
+ || ((constraint & PREV_BEGBUF_CONSTRAINT) && !IS_BEGBUF_CONTEXT (context)))
+
+#define NOT_SATISFY_NEXT_CONSTRAINT(constraint,context) \
+ ((((constraint) & NEXT_WORD_CONSTRAINT) && !IS_WORD_CONTEXT (context)) \
+ || (((constraint) & NEXT_NOTWORD_CONSTRAINT) && IS_WORD_CONTEXT (context)) \
+ || (((constraint) & NEXT_NEWLINE_CONSTRAINT) && !IS_NEWLINE_CONTEXT (context)) \
+ || (((constraint) & NEXT_ENDBUF_CONSTRAINT) && !IS_ENDBUF_CONTEXT (context)))
+
+struct re_dfastate_t
+{
+ re_hashval_t hash;
+ re_node_set nodes;
+ re_node_set non_eps_nodes;
+ re_node_set inveclosure;
+ re_node_set *entrance_nodes;
+ struct re_dfastate_t **trtable, **word_trtable;
+ unsigned int context : 4;
+ unsigned int halt : 1;
+ /* If this state can accept "multi byte".
+ Note that we refer to multibyte characters, and multi character
+ collating elements as "multi byte". */
+ unsigned int accept_mb : 1;
+ /* If this state has backreference node(s). */
+ unsigned int has_backref : 1;
+ unsigned int has_constraint : 1;
+};
+typedef struct re_dfastate_t re_dfastate_t;
+
+struct re_state_table_entry
+{
+ Idx num;
+ Idx alloc;
+ re_dfastate_t **array;
+};
+
+/* Array type used in re_sub_match_last_t and re_sub_match_top_t. */
+
+typedef struct
+{
+ Idx next_idx;
+ Idx alloc;
+ re_dfastate_t **array;
+} state_array_t;
+
+/* Store information about the node NODE whose type is OP_CLOSE_SUBEXP. */
+
+typedef struct
+{
+ Idx node;
+ Idx str_idx; /* The position NODE match at. */
+ state_array_t path;
+} re_sub_match_last_t;
+
+/* Store information about the node NODE whose type is OP_OPEN_SUBEXP.
+ And information about the node, whose type is OP_CLOSE_SUBEXP,
+ corresponding to NODE is stored in LASTS. */
+
+typedef struct
+{
+ Idx str_idx;
+ Idx node;
+ state_array_t *path;
+ Idx alasts; /* Allocation size of LASTS. */
+ Idx nlasts; /* The number of LASTS. */
+ re_sub_match_last_t **lasts;
+} re_sub_match_top_t;
+
+struct re_backref_cache_entry
+{
+ Idx node;
+ Idx str_idx;
+ Idx subexp_from;
+ Idx subexp_to;
+ char more;
+ char unused;
+ unsigned short int eps_reachable_subexps_map;
+};
+
+typedef struct
+{
+ /* The string object corresponding to the input string. */
+ re_string_t input;
+#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
+ const re_dfa_t *const dfa;
+#else
+ const re_dfa_t *dfa;
+#endif
+ /* EFLAGS of the argument of regexec. */
+ int eflags;
+ /* Where the matching ends. */
+ Idx match_last;
+ Idx last_node;
+ /* The state log used by the matcher. */
+ re_dfastate_t **state_log;
+ Idx state_log_top;
+ /* Back reference cache. */
+ Idx nbkref_ents;
+ Idx abkref_ents;
+ struct re_backref_cache_entry *bkref_ents;
+ int max_mb_elem_len;
+ Idx nsub_tops;
+ Idx asub_tops;
+ re_sub_match_top_t **sub_tops;
+} re_match_context_t;
+
+typedef struct
+{
+ re_dfastate_t **sifted_states;
+ re_dfastate_t **limited_states;
+ Idx last_node;
+ Idx last_str_idx;
+ re_node_set limits;
+} re_sift_context_t;
+
+struct re_fail_stack_ent_t
+{
+ Idx idx;
+ Idx node;
+ regmatch_t *regs;
+ re_node_set eps_via_nodes;
+};
+
+struct re_fail_stack_t
+{
+ Idx num;
+ Idx alloc;
+ struct re_fail_stack_ent_t *stack;
+};
+
+struct re_dfa_t
+{
+ re_token_t *nodes;
+ size_t nodes_alloc;
+ size_t nodes_len;
+ Idx *nexts;
+ Idx *org_indices;
+ re_node_set *edests;
+ re_node_set *eclosures;
+ re_node_set *inveclosures;
+ struct re_state_table_entry *state_table;
+ re_dfastate_t *init_state;
+ re_dfastate_t *init_state_word;
+ re_dfastate_t *init_state_nl;
+ re_dfastate_t *init_state_begbuf;
+ bin_tree_t *str_tree;
+ bin_tree_storage_t *str_tree_storage;
+ re_bitset_ptr_t sb_char;
+ int str_tree_storage_idx;
+
+ /* number of subexpressions 're_nsub' is in regex_t. */
+ re_hashval_t state_hash_mask;
+ Idx init_node;
+ Idx nbackref; /* The number of backreference in this dfa. */
+
+ /* Bitmap expressing which backreference is used. */
+ bitset_word_t used_bkref_map;
+ bitset_word_t completed_bkref_map;
+
+ unsigned int has_plural_match : 1;
+ /* If this dfa has "multibyte node", which is a backreference or
+ a node which can accept multibyte character or multi character
+ collating element. */
+ unsigned int has_mb_node : 1;
+ unsigned int is_utf8 : 1;
+ unsigned int map_notascii : 1;
+ unsigned int word_ops_used : 1;
+ int mb_cur_max;
+ bitset_t word_char;
+ reg_syntax_t syntax;
+ Idx *subexp_map;
+#ifdef DEBUG
+ char* re_str;
+#endif
+#ifdef _LIBC
+ __libc_lock_define (, lock)
+#endif
+};
+
+#define re_node_set_init_empty(set) memset (set, '\0', sizeof (re_node_set))
+#define re_node_set_remove(set,id) \
+ (re_node_set_remove_at (set, re_node_set_contains (set, id) - 1))
+#define re_node_set_empty(p) ((p)->nelem = 0)
+#define re_node_set_free(set) re_free ((set)->elems)
+
+
+typedef enum
+{
+ SB_CHAR,
+ MB_CHAR,
+ EQUIV_CLASS,
+ COLL_SYM,
+ CHAR_CLASS
+} bracket_elem_type;
+
+typedef struct
+{
+ bracket_elem_type type;
+ union
+ {
+ unsigned char ch;
+ unsigned char *name;
+ wchar_t wch;
+ } opr;
+} bracket_elem_t;
+
+
+/* Inline functions for bitset_t operation. */
+
+static inline void
+bitset_set (bitset_t set, Idx i)
+{
+ set[i / BITSET_WORD_BITS] |= (bitset_word_t) 1 << i % BITSET_WORD_BITS;
+}
+
+static inline void
+bitset_clear (bitset_t set, Idx i)
+{
+ set[i / BITSET_WORD_BITS] &= ~ ((bitset_word_t) 1 << i % BITSET_WORD_BITS);
+}
+
+static inline bool
+bitset_contain (const bitset_t set, Idx i)
+{
+ return (set[i / BITSET_WORD_BITS] >> i % BITSET_WORD_BITS) & 1;
+}
+
+static inline void
+bitset_empty (bitset_t set)
+{
+ memset (set, '\0', sizeof (bitset_t));
+}
+
+static inline void
+bitset_set_all (bitset_t set)
+{
+ memset (set, -1, sizeof (bitset_word_t) * (SBC_MAX / BITSET_WORD_BITS));
+ if (SBC_MAX % BITSET_WORD_BITS != 0)
+ set[BITSET_WORDS - 1] =
+ ((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1;
+}
+
+static inline void
+bitset_copy (bitset_t dest, const bitset_t src)
+{
+ memcpy (dest, src, sizeof (bitset_t));
+}
+
+static inline void
+bitset_not (bitset_t set)
+{
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < SBC_MAX / BITSET_WORD_BITS; ++bitset_i)
+ set[bitset_i] = ~set[bitset_i];
+ if (SBC_MAX % BITSET_WORD_BITS != 0)
+ set[BITSET_WORDS - 1] =
+ ((((bitset_word_t) 1 << SBC_MAX % BITSET_WORD_BITS) - 1)
+ & ~set[BITSET_WORDS - 1]);
+}
+
+static inline void
+bitset_merge (bitset_t dest, const bitset_t src)
+{
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
+ dest[bitset_i] |= src[bitset_i];
+}
+
+static inline void
+bitset_mask (bitset_t dest, const bitset_t src)
+{
+ int bitset_i;
+ for (bitset_i = 0; bitset_i < BITSET_WORDS; ++bitset_i)
+ dest[bitset_i] &= src[bitset_i];
+}
+
+#ifdef RE_ENABLE_I18N
+/* Inline functions for re_string. */
+static inline int
+internal_function __attribute ((pure))
+re_string_char_size_at (const re_string_t *pstr, Idx idx)
+{
+ int byte_idx;
+ if (pstr->mb_cur_max == 1)
+ return 1;
+ for (byte_idx = 1; idx + byte_idx < pstr->valid_len; ++byte_idx)
+ if (pstr->wcs[idx + byte_idx] != WEOF)
+ break;
+ return byte_idx;
+}
+
+static inline wint_t
+internal_function __attribute ((pure))
+re_string_wchar_at (const re_string_t *pstr, Idx idx)
+{
+ if (pstr->mb_cur_max == 1)
+ return (wint_t) pstr->mbs[idx];
+ return (wint_t) pstr->wcs[idx];
+}
+
+static int
+internal_function __attribute ((pure))
+re_string_elem_size_at (const re_string_t *pstr, Idx idx)
+{
+# ifdef _LIBC
+ const unsigned char *p, *extra;
+ const int32_t *table, *indirect;
+ int32_t tmp;
+# include <locale/weight.h>
+ uint_fast32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+
+ if (nrules != 0)
+ {
+ table = (const int32_t *) _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
+ indirect = (const int32_t *) _NL_CURRENT (LC_COLLATE,
+ _NL_COLLATE_INDIRECTMB);
+ p = pstr->mbs + idx;
+ tmp = findidx (&p);
+ return p - pstr->mbs - idx;
+ }
+ else
+# endif /* _LIBC */
+ return 1;
+}
+#endif /* RE_ENABLE_I18N */
+
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+# define __GNUC_PREREQ(maj, min) \
+ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+# else
+# define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
+#if __GNUC_PREREQ (3,4)
+# undef __attribute_warn_unused_result__
+# define __attribute_warn_unused_result__ \
+ __attribute__ ((__warn_unused_result__))
+#else
+# define __attribute_warn_unused_result__ /* empty */
+#endif
+
+#endif /* _REGEX_INTERNAL_H */
diff --git a/lib/regexec.c b/lib/regexec.c
new file mode 100644
index 000000000..7130f2a92
--- /dev/null
+++ b/lib/regexec.c
@@ -0,0 +1,4417 @@
+/* Extended regular expression matching and search library.
+ Copyright (C) 2002-2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+static reg_errcode_t match_ctx_init (re_match_context_t *cache, int eflags,
+ Idx n) internal_function;
+static void match_ctx_clean (re_match_context_t *mctx) internal_function;
+static void match_ctx_free (re_match_context_t *cache) internal_function;
+static reg_errcode_t match_ctx_add_entry (re_match_context_t *cache, Idx node,
+ Idx str_idx, Idx from, Idx to)
+ internal_function;
+static Idx search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
+ internal_function;
+static reg_errcode_t match_ctx_add_subtop (re_match_context_t *mctx, Idx node,
+ Idx str_idx) internal_function;
+static re_sub_match_last_t * match_ctx_add_sublast (re_sub_match_top_t *subtop,
+ Idx node, Idx str_idx)
+ internal_function;
+static void sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
+ re_dfastate_t **limited_sts, Idx last_node,
+ Idx last_str_idx)
+ internal_function;
+static reg_errcode_t re_search_internal (const regex_t *preg,
+ const char *string, Idx length,
+ Idx start, Idx last_start, Idx stop,
+ size_t nmatch, regmatch_t pmatch[],
+ int eflags) internal_function;
+static regoff_t re_search_2_stub (struct re_pattern_buffer *bufp,
+ const char *string1, Idx length1,
+ const char *string2, Idx length2,
+ Idx start, regoff_t range,
+ struct re_registers *regs,
+ Idx stop, bool ret_len) internal_function;
+static regoff_t re_search_stub (struct re_pattern_buffer *bufp,
+ const char *string, Idx length, Idx start,
+ regoff_t range, Idx stop,
+ struct re_registers *regs,
+ bool ret_len) internal_function;
+static unsigned int re_copy_regs (struct re_registers *regs, regmatch_t *pmatch,
+ Idx nregs, int regs_allocated)
+ internal_function;
+static reg_errcode_t prune_impossible_nodes (re_match_context_t *mctx)
+ internal_function;
+static Idx check_matching (re_match_context_t *mctx, bool fl_longest_match,
+ Idx *p_match_first) internal_function;
+static Idx check_halt_state_context (const re_match_context_t *mctx,
+ const re_dfastate_t *state, Idx idx)
+ internal_function;
+static void update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
+ regmatch_t *prev_idx_match, Idx cur_node,
+ Idx cur_idx, Idx nmatch) internal_function;
+static reg_errcode_t push_fail_stack (struct re_fail_stack_t *fs,
+ Idx str_idx, Idx dest_node, Idx nregs,
+ regmatch_t *regs,
+ re_node_set *eps_via_nodes)
+ internal_function;
+static reg_errcode_t set_regs (const regex_t *preg,
+ const re_match_context_t *mctx,
+ size_t nmatch, regmatch_t *pmatch,
+ bool fl_backtrack) internal_function;
+static reg_errcode_t free_fail_stack_return (struct re_fail_stack_t *fs)
+ internal_function;
+
+#ifdef RE_ENABLE_I18N
+static int sift_states_iter_mb (const re_match_context_t *mctx,
+ re_sift_context_t *sctx,
+ Idx node_idx, Idx str_idx, Idx max_str_idx)
+ internal_function;
+#endif /* RE_ENABLE_I18N */
+static reg_errcode_t sift_states_backward (const re_match_context_t *mctx,
+ re_sift_context_t *sctx)
+ internal_function;
+static reg_errcode_t build_sifted_states (const re_match_context_t *mctx,
+ re_sift_context_t *sctx, Idx str_idx,
+ re_node_set *cur_dest)
+ internal_function;
+static reg_errcode_t update_cur_sifted_state (const re_match_context_t *mctx,
+ re_sift_context_t *sctx,
+ Idx str_idx,
+ re_node_set *dest_nodes)
+ internal_function;
+static reg_errcode_t add_epsilon_src_nodes (const re_dfa_t *dfa,
+ re_node_set *dest_nodes,
+ const re_node_set *candidates)
+ internal_function;
+static bool check_dst_limits (const re_match_context_t *mctx,
+ const re_node_set *limits,
+ Idx dst_node, Idx dst_idx, Idx src_node,
+ Idx src_idx) internal_function;
+static int check_dst_limits_calc_pos_1 (const re_match_context_t *mctx,
+ int boundaries, Idx subexp_idx,
+ Idx from_node, Idx bkref_idx)
+ internal_function;
+static int check_dst_limits_calc_pos (const re_match_context_t *mctx,
+ Idx limit, Idx subexp_idx,
+ Idx node, Idx str_idx,
+ Idx bkref_idx) internal_function;
+static reg_errcode_t check_subexp_limits (const re_dfa_t *dfa,
+ re_node_set *dest_nodes,
+ const re_node_set *candidates,
+ re_node_set *limits,
+ struct re_backref_cache_entry *bkref_ents,
+ Idx str_idx) internal_function;
+static reg_errcode_t sift_states_bkref (const re_match_context_t *mctx,
+ re_sift_context_t *sctx,
+ Idx str_idx, const re_node_set *candidates)
+ internal_function;
+static reg_errcode_t merge_state_array (const re_dfa_t *dfa,
+ re_dfastate_t **dst,
+ re_dfastate_t **src, Idx num)
+ internal_function;
+static re_dfastate_t *find_recover_state (reg_errcode_t *err,
+ re_match_context_t *mctx) internal_function;
+static re_dfastate_t *transit_state (reg_errcode_t *err,
+ re_match_context_t *mctx,
+ re_dfastate_t *state) internal_function;
+static re_dfastate_t *merge_state_with_log (reg_errcode_t *err,
+ re_match_context_t *mctx,
+ re_dfastate_t *next_state)
+ internal_function;
+static reg_errcode_t check_subexp_matching_top (re_match_context_t *mctx,
+ re_node_set *cur_nodes,
+ Idx str_idx) internal_function;
+#if 0
+static re_dfastate_t *transit_state_sb (reg_errcode_t *err,
+ re_match_context_t *mctx,
+ re_dfastate_t *pstate)
+ internal_function;
+#endif
+#ifdef RE_ENABLE_I18N
+static reg_errcode_t transit_state_mb (re_match_context_t *mctx,
+ re_dfastate_t *pstate)
+ internal_function;
+#endif /* RE_ENABLE_I18N */
+static reg_errcode_t transit_state_bkref (re_match_context_t *mctx,
+ const re_node_set *nodes)
+ internal_function;
+static reg_errcode_t get_subexp (re_match_context_t *mctx,
+ Idx bkref_node, Idx bkref_str_idx)
+ internal_function;
+static reg_errcode_t get_subexp_sub (re_match_context_t *mctx,
+ const re_sub_match_top_t *sub_top,
+ re_sub_match_last_t *sub_last,
+ Idx bkref_node, Idx bkref_str)
+ internal_function;
+static Idx find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
+ Idx subexp_idx, int type) internal_function;
+static reg_errcode_t check_arrival (re_match_context_t *mctx,
+ state_array_t *path, Idx top_node,
+ Idx top_str, Idx last_node, Idx last_str,
+ int type) internal_function;
+static reg_errcode_t check_arrival_add_next_nodes (re_match_context_t *mctx,
+ Idx str_idx,
+ re_node_set *cur_nodes,
+ re_node_set *next_nodes)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl (const re_dfa_t *dfa,
+ re_node_set *cur_nodes,
+ Idx ex_subexp, int type)
+ internal_function;
+static reg_errcode_t check_arrival_expand_ecl_sub (const re_dfa_t *dfa,
+ re_node_set *dst_nodes,
+ Idx target, Idx ex_subexp,
+ int type) internal_function;
+static reg_errcode_t expand_bkref_cache (re_match_context_t *mctx,
+ re_node_set *cur_nodes, Idx cur_str,
+ Idx subexp_num, int type)
+ internal_function;
+static bool build_trtable (const re_dfa_t *dfa,
+ re_dfastate_t *state) internal_function;
+#ifdef RE_ENABLE_I18N
+static int check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
+ const re_string_t *input, Idx idx)
+ internal_function;
+# ifdef _LIBC
+static unsigned int find_collation_sequence_value (const unsigned char *mbs,
+ size_t name_len)
+ internal_function;
+# endif /* _LIBC */
+#endif /* RE_ENABLE_I18N */
+static Idx group_nodes_into_DFAstates (const re_dfa_t *dfa,
+ const re_dfastate_t *state,
+ re_node_set *states_node,
+ bitset_t *states_ch) internal_function;
+static bool check_node_accept (const re_match_context_t *mctx,
+ const re_token_t *node, Idx idx)
+ internal_function;
+static reg_errcode_t extend_buffers (re_match_context_t *mctx)
+ internal_function;
+
+/* Entry point for POSIX code. */
+
+/* regexec searches for a given pattern, specified by PREG, in the
+ string STRING.
+
+ If NMATCH is zero or REG_NOSUB was set in the cflags argument to
+ 'regcomp', we ignore PMATCH. Otherwise, we assume PMATCH has at
+ least NMATCH elements, and we set them to the offsets of the
+ corresponding matched substrings.
+
+ EFLAGS specifies "execution flags" which affect matching: if
+ REG_NOTBOL is set, then ^ does not match at the beginning of the
+ string; if REG_NOTEOL is set, then $ does not match at the end.
+
+ We return 0 if we find a match and REG_NOMATCH if not. */
+
+int
+regexec (preg, string, nmatch, pmatch, eflags)
+ const regex_t *_Restrict_ preg;
+ const char *_Restrict_ string;
+ size_t nmatch;
+ regmatch_t pmatch[_Restrict_arr_];
+ int eflags;
+{
+ reg_errcode_t err;
+ Idx start, length;
+#ifdef _LIBC
+ re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
+#endif
+
+ if (eflags & ~(REG_NOTBOL | REG_NOTEOL | REG_STARTEND))
+ return REG_BADPAT;
+
+ if (eflags & REG_STARTEND)
+ {
+ start = pmatch[0].rm_so;
+ length = pmatch[0].rm_eo;
+ }
+ else
+ {
+ start = 0;
+ length = strlen (string);
+ }
+
+ __libc_lock_lock (dfa->lock);
+ if (preg->no_sub)
+ err = re_search_internal (preg, string, length, start, length,
+ length, 0, NULL, eflags);
+ else
+ err = re_search_internal (preg, string, length, start, length,
+ length, nmatch, pmatch, eflags);
+ __libc_lock_unlock (dfa->lock);
+ return err != REG_NOERROR;
+}
+
+#ifdef _LIBC
+# include <shlib-compat.h>
+versioned_symbol (libc, __regexec, regexec, GLIBC_2_3_4);
+
+# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
+__typeof__ (__regexec) __compat_regexec;
+
+int
+attribute_compat_text_section
+__compat_regexec (const regex_t *_Restrict_ preg,
+ const char *_Restrict_ string, size_t nmatch,
+ regmatch_t pmatch[], int eflags)
+{
+ return regexec (preg, string, nmatch, pmatch,
+ eflags & (REG_NOTBOL | REG_NOTEOL));
+}
+compat_symbol (libc, __compat_regexec, regexec, GLIBC_2_0);
+# endif
+#endif
+
+/* Entry points for GNU code. */
+
+/* re_match, re_search, re_match_2, re_search_2
+
+ The former two functions operate on STRING with length LENGTH,
+ while the later two operate on concatenation of STRING1 and STRING2
+ with lengths LENGTH1 and LENGTH2, respectively.
+
+ re_match() matches the compiled pattern in BUFP against the string,
+ starting at index START.
+
+ re_search() first tries matching at index START, then it tries to match
+ starting from index START + 1, and so on. The last start position tried
+ is START + RANGE. (Thus RANGE = 0 forces re_search to operate the same
+ way as re_match().)
+
+ The parameter STOP of re_{match,search}_2 specifies that no match exceeding
+ the first STOP characters of the concatenation of the strings should be
+ concerned.
+
+ If REGS is not NULL, and BUFP->no_sub is not set, the offsets of the match
+ and all groups is stored in REGS. (For the "_2" variants, the offsets are
+ computed relative to the concatenation, not relative to the individual
+ strings.)
+
+ On success, re_match* functions return the length of the match, re_search*
+ return the position of the start of the match. Return value -1 means no
+ match was found and -2 indicates an internal error. */
+
+regoff_t
+re_match (bufp, string, length, start, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ Idx length, start;
+ struct re_registers *regs;
+{
+ return re_search_stub (bufp, string, length, start, 0, length, regs, true);
+}
+#ifdef _LIBC
+weak_alias (__re_match, re_match)
+#endif
+
+regoff_t
+re_search (bufp, string, length, start, range, regs)
+ struct re_pattern_buffer *bufp;
+ const char *string;
+ Idx length, start;
+ regoff_t range;
+ struct re_registers *regs;
+{
+ return re_search_stub (bufp, string, length, start, range, length, regs,
+ false);
+}
+#ifdef _LIBC
+weak_alias (__re_search, re_search)
+#endif
+
+regoff_t
+re_match_2 (bufp, string1, length1, string2, length2, start, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ Idx length1, length2, start, stop;
+ struct re_registers *regs;
+{
+ return re_search_2_stub (bufp, string1, length1, string2, length2,
+ start, 0, regs, stop, true);
+}
+#ifdef _LIBC
+weak_alias (__re_match_2, re_match_2)
+#endif
+
+regoff_t
+re_search_2 (bufp, string1, length1, string2, length2, start, range, regs, stop)
+ struct re_pattern_buffer *bufp;
+ const char *string1, *string2;
+ Idx length1, length2, start, stop;
+ regoff_t range;
+ struct re_registers *regs;
+{
+ return re_search_2_stub (bufp, string1, length1, string2, length2,
+ start, range, regs, stop, false);
+}
+#ifdef _LIBC
+weak_alias (__re_search_2, re_search_2)
+#endif
+
+static regoff_t
+internal_function
+re_search_2_stub (struct re_pattern_buffer *bufp,
+ const char *string1, Idx length1,
+ const char *string2, Idx length2,
+ Idx start, regoff_t range, struct re_registers *regs,
+ Idx stop, bool ret_len)
+{
+ const char *str;
+ regoff_t rval;
+ Idx len = length1 + length2;
+ char *s = NULL;
+
+ if (BE (length1 < 0 || length2 < 0 || stop < 0 || len < length1, 0))
+ return -2;
+
+ /* Concatenate the strings. */
+ if (length2 > 0)
+ if (length1 > 0)
+ {
+ s = re_malloc (char, len);
+
+ if (BE (s == NULL, 0))
+ return -2;
+#ifdef _LIBC
+ memcpy (__mempcpy (s, string1, length1), string2, length2);
+#else
+ memcpy (s, string1, length1);
+ memcpy (s + length1, string2, length2);
+#endif
+ str = s;
+ }
+ else
+ str = string2;
+ else
+ str = string1;
+
+ rval = re_search_stub (bufp, str, len, start, range, stop, regs,
+ ret_len);
+ re_free (s);
+ return rval;
+}
+
+/* The parameters have the same meaning as those of re_search.
+ Additional parameters:
+ If RET_LEN is true the length of the match is returned (re_match style);
+ otherwise the position of the match is returned. */
+
+static regoff_t
+internal_function
+re_search_stub (struct re_pattern_buffer *bufp,
+ const char *string, Idx length,
+ Idx start, regoff_t range, Idx stop, struct re_registers *regs,
+ bool ret_len)
+{
+ reg_errcode_t result;
+ regmatch_t *pmatch;
+ Idx nregs;
+ regoff_t rval;
+ int eflags = 0;
+#ifdef _LIBC
+ re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
+#endif
+ Idx last_start = start + range;
+
+ /* Check for out-of-range. */
+ if (BE (start < 0 || start > length, 0))
+ return -1;
+ if (BE (length < last_start || (0 <= range && last_start < start), 0))
+ last_start = length;
+ else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0))
+ last_start = 0;
+
+ __libc_lock_lock (dfa->lock);
+
+ eflags |= (bufp->not_bol) ? REG_NOTBOL : 0;
+ eflags |= (bufp->not_eol) ? REG_NOTEOL : 0;
+
+ /* Compile fastmap if we haven't yet. */
+ if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate)
+ re_compile_fastmap (bufp);
+
+ if (BE (bufp->no_sub, 0))
+ regs = NULL;
+
+ /* We need at least 1 register. */
+ if (regs == NULL)
+ nregs = 1;
+ else if (BE (bufp->regs_allocated == REGS_FIXED
+ && regs->num_regs <= bufp->re_nsub, 0))
+ {
+ nregs = regs->num_regs;
+ if (BE (nregs < 1, 0))
+ {
+ /* Nothing can be copied to regs. */
+ regs = NULL;
+ nregs = 1;
+ }
+ }
+ else
+ nregs = bufp->re_nsub + 1;
+ pmatch = re_malloc (regmatch_t, nregs);
+ if (BE (pmatch == NULL, 0))
+ {
+ rval = -2;
+ goto out;
+ }
+
+ result = re_search_internal (bufp, string, length, start, last_start, stop,
+ nregs, pmatch, eflags);
+
+ rval = 0;
+
+ /* I hope we needn't fill ther regs with -1's when no match was found. */
+ if (result != REG_NOERROR)
+ rval = -1;
+ else if (regs != NULL)
+ {
+ /* If caller wants register contents data back, copy them. */
+ bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs,
+ bufp->regs_allocated);
+ if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0))
+ rval = -2;
+ }
+
+ if (BE (rval == 0, 1))
+ {
+ if (ret_len)
+ {
+ assert (pmatch[0].rm_so == start);
+ rval = pmatch[0].rm_eo - start;
+ }
+ else
+ rval = pmatch[0].rm_so;
+ }
+ re_free (pmatch);
+ out:
+ __libc_lock_unlock (dfa->lock);
+ return rval;
+}
+
+static unsigned int
+internal_function
+re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs,
+ int regs_allocated)
+{
+ int rval = REGS_REALLOCATE;
+ Idx i;
+ Idx need_regs = nregs + 1;
+ /* We need one extra element beyond 'num_regs' for the '-1' marker GNU code
+ uses. */
+
+ /* Have the register data arrays been allocated? */
+ if (regs_allocated == REGS_UNALLOCATED)
+ { /* No. So allocate them with malloc. */
+ regs->start = re_malloc (regoff_t, need_regs);
+ if (BE (regs->start == NULL, 0))
+ return REGS_UNALLOCATED;
+ regs->end = re_malloc (regoff_t, need_regs);
+ if (BE (regs->end == NULL, 0))
+ {
+ re_free (regs->start);
+ return REGS_UNALLOCATED;
+ }
+ regs->num_regs = need_regs;
+ }
+ else if (regs_allocated == REGS_REALLOCATE)
+ { /* Yes. If we need more elements than were already
+ allocated, reallocate them. If we need fewer, just
+ leave it alone. */
+ if (BE (need_regs > regs->num_regs, 0))
+ {
+ regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs);
+ regoff_t *new_end;
+ if (BE (new_start == NULL, 0))
+ return REGS_UNALLOCATED;
+ new_end = re_realloc (regs->end, regoff_t, need_regs);
+ if (BE (new_end == NULL, 0))
+ {
+ re_free (new_start);
+ return REGS_UNALLOCATED;
+ }
+ regs->start = new_start;
+ regs->end = new_end;
+ regs->num_regs = need_regs;
+ }
+ }
+ else
+ {
+ assert (regs_allocated == REGS_FIXED);
+ /* This function may not be called with REGS_FIXED and nregs too big. */
+ assert (regs->num_regs >= nregs);
+ rval = REGS_FIXED;
+ }
+
+ /* Copy the regs. */
+ for (i = 0; i < nregs; ++i)
+ {
+ regs->start[i] = pmatch[i].rm_so;
+ regs->end[i] = pmatch[i].rm_eo;
+ }
+ for ( ; i < regs->num_regs; ++i)
+ regs->start[i] = regs->end[i] = -1;
+
+ return rval;
+}
+
+/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
+ ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
+ this memory for recording register information. STARTS and ENDS
+ must be allocated using the malloc library routine, and must each
+ be at least NUM_REGS * sizeof (regoff_t) bytes long.
+
+ If NUM_REGS == 0, then subsequent matches should allocate their own
+ register data.
+
+ Unless this function is called, the first search or match using
+ PATTERN_BUFFER will allocate its own register data, without
+ freeing the old data. */
+
+void
+re_set_registers (bufp, regs, num_regs, starts, ends)
+ struct re_pattern_buffer *bufp;
+ struct re_registers *regs;
+ __re_size_t num_regs;
+ regoff_t *starts, *ends;
+{
+ if (num_regs)
+ {
+ bufp->regs_allocated = REGS_REALLOCATE;
+ regs->num_regs = num_regs;
+ regs->start = starts;
+ regs->end = ends;
+ }
+ else
+ {
+ bufp->regs_allocated = REGS_UNALLOCATED;
+ regs->num_regs = 0;
+ regs->start = regs->end = NULL;
+ }
+}
+#ifdef _LIBC
+weak_alias (__re_set_registers, re_set_registers)
+#endif
+
+/* Entry points compatible with 4.2 BSD regex library. We don't define
+ them unless specifically requested. */
+
+#if defined _REGEX_RE_COMP || defined _LIBC
+int
+# ifdef _LIBC
+weak_function
+# endif
+re_exec (s)
+ const char *s;
+{
+ return 0 == regexec (&re_comp_buf, s, 0, NULL, 0);
+}
+#endif /* _REGEX_RE_COMP */
+
+/* Internal entry point. */
+
+/* Searches for a compiled pattern PREG in the string STRING, whose
+ length is LENGTH. NMATCH, PMATCH, and EFLAGS have the same
+ meaning as with regexec. LAST_START is START + RANGE, where
+ START and RANGE have the same meaning as with re_search.
+ Return REG_NOERROR if we find a match, and REG_NOMATCH if not,
+ otherwise return the error code.
+ Note: We assume front end functions already check ranges.
+ (0 <= LAST_START && LAST_START <= LENGTH) */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+re_search_internal (const regex_t *preg,
+ const char *string, Idx length,
+ Idx start, Idx last_start, Idx stop,
+ size_t nmatch, regmatch_t pmatch[],
+ int eflags)
+{
+ reg_errcode_t err;
+ const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
+ Idx left_lim, right_lim;
+ int incr;
+ bool fl_longest_match;
+ int match_kind;
+ Idx match_first;
+ Idx match_last = REG_MISSING;
+ Idx extra_nmatch;
+ bool sb;
+ int ch;
+#if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
+ re_match_context_t mctx = { .dfa = dfa };
+#else
+ re_match_context_t mctx;
+#endif
+ char *fastmap = ((preg->fastmap != NULL && preg->fastmap_accurate
+ && start != last_start && !preg->can_be_null)
+ ? preg->fastmap : NULL);
+ RE_TRANSLATE_TYPE t = preg->translate;
+
+#if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
+ memset (&mctx, '\0', sizeof (re_match_context_t));
+ mctx.dfa = dfa;
+#endif
+
+ extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0;
+ nmatch -= extra_nmatch;
+
+ /* Check if the DFA haven't been compiled. */
+ if (BE (preg->used == 0 || dfa->init_state == NULL
+ || dfa->init_state_word == NULL || dfa->init_state_nl == NULL
+ || dfa->init_state_begbuf == NULL, 0))
+ return REG_NOMATCH;
+
+#ifdef DEBUG
+ /* We assume front-end functions already check them. */
+ assert (0 <= last_start && last_start <= length);
+#endif
+
+ /* If initial states with non-begbuf contexts have no elements,
+ the regex must be anchored. If preg->newline_anchor is set,
+ we'll never use init_state_nl, so do not check it. */
+ if (dfa->init_state->nodes.nelem == 0
+ && dfa->init_state_word->nodes.nelem == 0
+ && (dfa->init_state_nl->nodes.nelem == 0
+ || !preg->newline_anchor))
+ {
+ if (start != 0 && last_start != 0)
+ return REG_NOMATCH;
+ start = last_start = 0;
+ }
+
+ /* We must check the longest matching, if nmatch > 0. */
+ fl_longest_match = (nmatch != 0 || dfa->nbackref);
+
+ err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1,
+ preg->translate, (preg->syntax & RE_ICASE) != 0,
+ dfa);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ mctx.input.stop = stop;
+ mctx.input.raw_stop = stop;
+ mctx.input.newline_anchor = preg->newline_anchor;
+
+ err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ /* We will log all the DFA states through which the dfa pass,
+ if nmatch > 1, or this dfa has "multibyte node", which is a
+ back-reference or a node which can accept multibyte character or
+ multi character collating element. */
+ if (nmatch > 1 || dfa->has_mb_node)
+ {
+ /* Avoid overflow. */
+ if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= mctx.input.bufs_len, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+
+ mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1);
+ if (BE (mctx.state_log == NULL, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+ }
+ else
+ mctx.state_log = NULL;
+
+ match_first = start;
+ mctx.input.tip_context = (eflags & REG_NOTBOL) ? CONTEXT_BEGBUF
+ : CONTEXT_NEWLINE | CONTEXT_BEGBUF;
+
+ /* Check incrementally whether of not the input string match. */
+ incr = (last_start < start) ? -1 : 1;
+ left_lim = (last_start < start) ? last_start : start;
+ right_lim = (last_start < start) ? start : last_start;
+ sb = dfa->mb_cur_max == 1;
+ match_kind =
+ (fastmap
+ ? ((sb || !(preg->syntax & RE_ICASE || t) ? 4 : 0)
+ | (start <= last_start ? 2 : 0)
+ | (t != NULL ? 1 : 0))
+ : 8);
+
+ for (;; match_first += incr)
+ {
+ err = REG_NOMATCH;
+ if (match_first < left_lim || right_lim < match_first)
+ goto free_return;
+
+ /* Advance as rapidly as possible through the string, until we
+ find a plausible place to start matching. This may be done
+ with varying efficiency, so there are various possibilities:
+ only the most common of them are specialized, in order to
+ save on code size. We use a switch statement for speed. */
+ switch (match_kind)
+ {
+ case 8:
+ /* No fastmap. */
+ break;
+
+ case 7:
+ /* Fastmap with single-byte translation, match forward. */
+ while (BE (match_first < right_lim, 1)
+ && !fastmap[t[(unsigned char) string[match_first]]])
+ ++match_first;
+ goto forward_match_found_start_or_reached_end;
+
+ case 6:
+ /* Fastmap without translation, match forward. */
+ while (BE (match_first < right_lim, 1)
+ && !fastmap[(unsigned char) string[match_first]])
+ ++match_first;
+
+ forward_match_found_start_or_reached_end:
+ if (BE (match_first == right_lim, 0))
+ {
+ ch = match_first >= length
+ ? 0 : (unsigned char) string[match_first];
+ if (!fastmap[t ? t[ch] : ch])
+ goto free_return;
+ }
+ break;
+
+ case 4:
+ case 5:
+ /* Fastmap without multi-byte translation, match backwards. */
+ while (match_first >= left_lim)
+ {
+ ch = match_first >= length
+ ? 0 : (unsigned char) string[match_first];
+ if (fastmap[t ? t[ch] : ch])
+ break;
+ --match_first;
+ }
+ if (match_first < left_lim)
+ goto free_return;
+ break;
+
+ default:
+ /* In this case, we can't determine easily the current byte,
+ since it might be a component byte of a multibyte
+ character. Then we use the constructed buffer instead. */
+ for (;;)
+ {
+ /* If MATCH_FIRST is out of the valid range, reconstruct the
+ buffers. */
+ __re_size_t offset = match_first - mctx.input.raw_mbs_idx;
+ if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0))
+ {
+ err = re_string_reconstruct (&mctx.input, match_first,
+ eflags);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ offset = match_first - mctx.input.raw_mbs_idx;
+ }
+ /* If MATCH_FIRST is out of the buffer, leave it as '\0'.
+ Note that MATCH_FIRST must not be smaller than 0. */
+ ch = (match_first >= length
+ ? 0 : re_string_byte_at (&mctx.input, offset));
+ if (fastmap[ch])
+ break;
+ match_first += incr;
+ if (match_first < left_lim || match_first > right_lim)
+ {
+ err = REG_NOMATCH;
+ goto free_return;
+ }
+ }
+ break;
+ }
+
+ /* Reconstruct the buffers so that the matcher can assume that
+ the matching starts from the beginning of the buffer. */
+ err = re_string_reconstruct (&mctx.input, match_first, eflags);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+#ifdef RE_ENABLE_I18N
+ /* Don't consider this char as a possible match start if it part,
+ yet isn't the head, of a multibyte character. */
+ if (!sb && !re_string_first_byte (&mctx.input, 0))
+ continue;
+#endif
+
+ /* It seems to be appropriate one, then use the matcher. */
+ /* We assume that the matching starts from 0. */
+ mctx.state_log_top = mctx.nbkref_ents = mctx.max_mb_elem_len = 0;
+ match_last = check_matching (&mctx, fl_longest_match,
+ start <= last_start ? &match_first : NULL);
+ if (match_last != REG_MISSING)
+ {
+ if (BE (match_last == REG_ERROR, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+ else
+ {
+ mctx.match_last = match_last;
+ if ((!preg->no_sub && nmatch > 1) || dfa->nbackref)
+ {
+ re_dfastate_t *pstate = mctx.state_log[match_last];
+ mctx.last_node = check_halt_state_context (&mctx, pstate,
+ match_last);
+ }
+ if ((!preg->no_sub && nmatch > 1 && dfa->has_plural_match)
+ || dfa->nbackref)
+ {
+ err = prune_impossible_nodes (&mctx);
+ if (err == REG_NOERROR)
+ break;
+ if (BE (err != REG_NOMATCH, 0))
+ goto free_return;
+ match_last = REG_MISSING;
+ }
+ else
+ break; /* We found a match. */
+ }
+ }
+
+ match_ctx_clean (&mctx);
+ }
+
+#ifdef DEBUG
+ assert (match_last != REG_MISSING);
+ assert (err == REG_NOERROR);
+#endif
+
+ /* Set pmatch[] if we need. */
+ if (nmatch > 0)
+ {
+ Idx reg_idx;
+
+ /* Initialize registers. */
+ for (reg_idx = 1; reg_idx < nmatch; ++reg_idx)
+ pmatch[reg_idx].rm_so = pmatch[reg_idx].rm_eo = -1;
+
+ /* Set the points where matching start/end. */
+ pmatch[0].rm_so = 0;
+ pmatch[0].rm_eo = mctx.match_last;
+ /* FIXME: This function should fail if mctx.match_last exceeds
+ the maximum possible regoff_t value. We need a new error
+ code REG_OVERFLOW. */
+
+ if (!preg->no_sub && nmatch > 1)
+ {
+ err = set_regs (preg, &mctx, nmatch, pmatch,
+ dfa->has_plural_match && dfa->nbackref > 0);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+
+ /* At last, add the offset to the each registers, since we slided
+ the buffers so that we could assume that the matching starts
+ from 0. */
+ for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
+ if (pmatch[reg_idx].rm_so != -1)
+ {
+#ifdef RE_ENABLE_I18N
+ if (BE (mctx.input.offsets_needed != 0, 0))
+ {
+ pmatch[reg_idx].rm_so =
+ (pmatch[reg_idx].rm_so == mctx.input.valid_len
+ ? mctx.input.valid_raw_len
+ : mctx.input.offsets[pmatch[reg_idx].rm_so]);
+ pmatch[reg_idx].rm_eo =
+ (pmatch[reg_idx].rm_eo == mctx.input.valid_len
+ ? mctx.input.valid_raw_len
+ : mctx.input.offsets[pmatch[reg_idx].rm_eo]);
+ }
+#else
+ assert (mctx.input.offsets_needed == 0);
+#endif
+ pmatch[reg_idx].rm_so += match_first;
+ pmatch[reg_idx].rm_eo += match_first;
+ }
+ for (reg_idx = 0; reg_idx < extra_nmatch; ++reg_idx)
+ {
+ pmatch[nmatch + reg_idx].rm_so = -1;
+ pmatch[nmatch + reg_idx].rm_eo = -1;
+ }
+
+ if (dfa->subexp_map)
+ for (reg_idx = 0; reg_idx + 1 < nmatch; reg_idx++)
+ if (dfa->subexp_map[reg_idx] != reg_idx)
+ {
+ pmatch[reg_idx + 1].rm_so
+ = pmatch[dfa->subexp_map[reg_idx] + 1].rm_so;
+ pmatch[reg_idx + 1].rm_eo
+ = pmatch[dfa->subexp_map[reg_idx] + 1].rm_eo;
+ }
+ }
+
+ free_return:
+ re_free (mctx.state_log);
+ if (dfa->nbackref)
+ match_ctx_free (&mctx);
+ re_string_destruct (&mctx.input);
+ return err;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+prune_impossible_nodes (re_match_context_t *mctx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx halt_node, match_last;
+ reg_errcode_t ret;
+ re_dfastate_t **sifted_states;
+ re_dfastate_t **lim_states = NULL;
+ re_sift_context_t sctx;
+#ifdef DEBUG
+ assert (mctx->state_log != NULL);
+#endif
+ match_last = mctx->match_last;
+ halt_node = mctx->last_node;
+
+ /* Avoid overflow. */
+ if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0))
+ return REG_ESPACE;
+
+ sifted_states = re_malloc (re_dfastate_t *, match_last + 1);
+ if (BE (sifted_states == NULL, 0))
+ {
+ ret = REG_ESPACE;
+ goto free_return;
+ }
+ if (dfa->nbackref)
+ {
+ lim_states = re_malloc (re_dfastate_t *, match_last + 1);
+ if (BE (lim_states == NULL, 0))
+ {
+ ret = REG_ESPACE;
+ goto free_return;
+ }
+ while (1)
+ {
+ memset (lim_states, '\0',
+ sizeof (re_dfastate_t *) * (match_last + 1));
+ sift_ctx_init (&sctx, sifted_states, lim_states, halt_node,
+ match_last);
+ ret = sift_states_backward (mctx, &sctx);
+ re_node_set_free (&sctx.limits);
+ if (BE (ret != REG_NOERROR, 0))
+ goto free_return;
+ if (sifted_states[0] != NULL || lim_states[0] != NULL)
+ break;
+ do
+ {
+ --match_last;
+ if (! REG_VALID_INDEX (match_last))
+ {
+ ret = REG_NOMATCH;
+ goto free_return;
+ }
+ } while (mctx->state_log[match_last] == NULL
+ || !mctx->state_log[match_last]->halt);
+ halt_node = check_halt_state_context (mctx,
+ mctx->state_log[match_last],
+ match_last);
+ }
+ ret = merge_state_array (dfa, sifted_states, lim_states,
+ match_last + 1);
+ re_free (lim_states);
+ lim_states = NULL;
+ if (BE (ret != REG_NOERROR, 0))
+ goto free_return;
+ }
+ else
+ {
+ sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last);
+ ret = sift_states_backward (mctx, &sctx);
+ re_node_set_free (&sctx.limits);
+ if (BE (ret != REG_NOERROR, 0))
+ goto free_return;
+ if (sifted_states[0] == NULL)
+ {
+ ret = REG_NOMATCH;
+ goto free_return;
+ }
+ }
+ re_free (mctx->state_log);
+ mctx->state_log = sifted_states;
+ sifted_states = NULL;
+ mctx->last_node = halt_node;
+ mctx->match_last = match_last;
+ ret = REG_NOERROR;
+ free_return:
+ re_free (sifted_states);
+ re_free (lim_states);
+ return ret;
+}
+
+/* Acquire an initial state and return it.
+ We must select appropriate initial state depending on the context,
+ since initial states may have constraints like "\<", "^", etc.. */
+
+static inline re_dfastate_t *
+__attribute ((always_inline)) internal_function
+acquire_init_state_context (reg_errcode_t *err, const re_match_context_t *mctx,
+ Idx idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ if (dfa->init_state->has_constraint)
+ {
+ unsigned int context;
+ context = re_string_context_at (&mctx->input, idx - 1, mctx->eflags);
+ if (IS_WORD_CONTEXT (context))
+ return dfa->init_state_word;
+ else if (IS_ORDINARY_CONTEXT (context))
+ return dfa->init_state;
+ else if (IS_BEGBUF_CONTEXT (context) && IS_NEWLINE_CONTEXT (context))
+ return dfa->init_state_begbuf;
+ else if (IS_NEWLINE_CONTEXT (context))
+ return dfa->init_state_nl;
+ else if (IS_BEGBUF_CONTEXT (context))
+ {
+ /* It is relatively rare case, then calculate on demand. */
+ return re_acquire_state_context (err, dfa,
+ dfa->init_state->entrance_nodes,
+ context);
+ }
+ else
+ /* Must not happen? */
+ return dfa->init_state;
+ }
+ else
+ return dfa->init_state;
+}
+
+/* Check whether the regular expression match input string INPUT or not,
+ and return the index where the matching end. Return REG_MISSING if
+ there is no match, and return REG_ERROR in case of an error.
+ FL_LONGEST_MATCH means we want the POSIX longest matching.
+ If P_MATCH_FIRST is not NULL, and the match fails, it is set to the
+ next place where we may want to try matching.
+ Note that the matcher assume that the maching starts from the current
+ index of the buffer. */
+
+static Idx
+internal_function __attribute_warn_unused_result__
+check_matching (re_match_context_t *mctx, bool fl_longest_match,
+ Idx *p_match_first)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx match = 0;
+ Idx match_last = REG_MISSING;
+ Idx cur_str_idx = re_string_cur_idx (&mctx->input);
+ re_dfastate_t *cur_state;
+ bool at_init_state = p_match_first != NULL;
+ Idx next_start_idx = cur_str_idx;
+
+ err = REG_NOERROR;
+ cur_state = acquire_init_state_context (&err, mctx, cur_str_idx);
+ /* An initial state must not be NULL (invalid). */
+ if (BE (cur_state == NULL, 0))
+ {
+ assert (err == REG_ESPACE);
+ return REG_ERROR;
+ }
+
+ if (mctx->state_log != NULL)
+ {
+ mctx->state_log[cur_str_idx] = cur_state;
+
+ /* Check OP_OPEN_SUBEXP in the initial state in case that we use them
+ later. E.g. Processing back references. */
+ if (BE (dfa->nbackref, 0))
+ {
+ at_init_state = false;
+ err = check_subexp_matching_top (mctx, &cur_state->nodes, 0);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ if (cur_state->has_backref)
+ {
+ err = transit_state_bkref (mctx, &cur_state->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ }
+
+ /* If the RE accepts NULL string. */
+ if (BE (cur_state->halt, 0))
+ {
+ if (!cur_state->has_constraint
+ || check_halt_state_context (mctx, cur_state, cur_str_idx))
+ {
+ if (!fl_longest_match)
+ return cur_str_idx;
+ else
+ {
+ match_last = cur_str_idx;
+ match = 1;
+ }
+ }
+ }
+
+ while (!re_string_eoi (&mctx->input))
+ {
+ re_dfastate_t *old_state = cur_state;
+ Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1;
+
+ if (BE (next_char_idx >= mctx->input.bufs_len, 0)
+ || (BE (next_char_idx >= mctx->input.valid_len, 0)
+ && mctx->input.valid_len < mctx->input.len))
+ {
+ err = extend_buffers (mctx);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ assert (err == REG_ESPACE);
+ return REG_ERROR;
+ }
+ }
+
+ cur_state = transit_state (&err, mctx, cur_state);
+ if (mctx->state_log != NULL)
+ cur_state = merge_state_with_log (&err, mctx, cur_state);
+
+ if (cur_state == NULL)
+ {
+ /* Reached the invalid state or an error. Try to recover a valid
+ state using the state log, if available and if we have not
+ already found a valid (even if not the longest) match. */
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ERROR;
+
+ if (mctx->state_log == NULL
+ || (match && !fl_longest_match)
+ || (cur_state = find_recover_state (&err, mctx)) == NULL)
+ break;
+ }
+
+ if (BE (at_init_state, 0))
+ {
+ if (old_state == cur_state)
+ next_start_idx = next_char_idx;
+ else
+ at_init_state = false;
+ }
+
+ if (cur_state->halt)
+ {
+ /* Reached a halt state.
+ Check the halt state can satisfy the current context. */
+ if (!cur_state->has_constraint
+ || check_halt_state_context (mctx, cur_state,
+ re_string_cur_idx (&mctx->input)))
+ {
+ /* We found an appropriate halt state. */
+ match_last = re_string_cur_idx (&mctx->input);
+ match = 1;
+
+ /* We found a match, do not modify match_first below. */
+ p_match_first = NULL;
+ if (!fl_longest_match)
+ break;
+ }
+ }
+ }
+
+ if (p_match_first)
+ *p_match_first += next_start_idx;
+
+ return match_last;
+}
+
+/* Check NODE match the current context. */
+
+static bool
+internal_function
+check_halt_node_context (const re_dfa_t *dfa, Idx node, unsigned int context)
+{
+ re_token_type_t type = dfa->nodes[node].type;
+ unsigned int constraint = dfa->nodes[node].constraint;
+ if (type != END_OF_RE)
+ return false;
+ if (!constraint)
+ return true;
+ if (NOT_SATISFY_NEXT_CONSTRAINT (constraint, context))
+ return false;
+ return true;
+}
+
+/* Check the halt state STATE match the current context.
+ Return 0 if not match, if the node, STATE has, is a halt node and
+ match the context, return the node. */
+
+static Idx
+internal_function
+check_halt_state_context (const re_match_context_t *mctx,
+ const re_dfastate_t *state, Idx idx)
+{
+ Idx i;
+ unsigned int context;
+#ifdef DEBUG
+ assert (state->halt);
+#endif
+ context = re_string_context_at (&mctx->input, idx, mctx->eflags);
+ for (i = 0; i < state->nodes.nelem; ++i)
+ if (check_halt_node_context (mctx->dfa, state->nodes.elems[i], context))
+ return state->nodes.elems[i];
+ return 0;
+}
+
+/* Compute the next node to which "NFA" transit from NODE("NFA" is a NFA
+ corresponding to the DFA).
+ Return the destination node, and update EPS_VIA_NODES;
+ return REG_MISSING in case of errors. */
+
+static Idx
+internal_function
+proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs,
+ Idx *pidx, Idx node, re_node_set *eps_via_nodes,
+ struct re_fail_stack_t *fs)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx i;
+ bool ok;
+ if (IS_EPSILON_NODE (dfa->nodes[node].type))
+ {
+ re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
+ re_node_set *edests = &dfa->edests[node];
+ Idx dest_node;
+ ok = re_node_set_insert (eps_via_nodes, node);
+ if (BE (! ok, 0))
+ return REG_ERROR;
+ /* Pick up a valid destination, or return REG_MISSING if none
+ is found. */
+ for (dest_node = REG_MISSING, i = 0; i < edests->nelem; ++i)
+ {
+ Idx candidate = edests->elems[i];
+ if (!re_node_set_contains (cur_nodes, candidate))
+ continue;
+ if (dest_node == REG_MISSING)
+ dest_node = candidate;
+
+ else
+ {
+ /* In order to avoid infinite loop like "(a*)*", return the second
+ epsilon-transition if the first was already considered. */
+ if (re_node_set_contains (eps_via_nodes, dest_node))
+ return candidate;
+
+ /* Otherwise, push the second epsilon-transition on the fail stack. */
+ else if (fs != NULL
+ && push_fail_stack (fs, *pidx, candidate, nregs, regs,
+ eps_via_nodes))
+ return REG_ERROR;
+
+ /* We know we are going to exit. */
+ break;
+ }
+ }
+ return dest_node;
+ }
+ else
+ {
+ Idx naccepted = 0;
+ re_token_type_t type = dfa->nodes[node].type;
+
+#ifdef RE_ENABLE_I18N
+ if (dfa->nodes[node].accept_mb)
+ naccepted = check_node_accept_bytes (dfa, node, &mctx->input, *pidx);
+ else
+#endif /* RE_ENABLE_I18N */
+ if (type == OP_BACK_REF)
+ {
+ Idx subexp_idx = dfa->nodes[node].opr.idx + 1;
+ naccepted = regs[subexp_idx].rm_eo - regs[subexp_idx].rm_so;
+ if (fs != NULL)
+ {
+ if (regs[subexp_idx].rm_so == -1 || regs[subexp_idx].rm_eo == -1)
+ return REG_MISSING;
+ else if (naccepted)
+ {
+ char *buf = (char *) re_string_get_buffer (&mctx->input);
+ if (memcmp (buf + regs[subexp_idx].rm_so, buf + *pidx,
+ naccepted) != 0)
+ return REG_MISSING;
+ }
+ }
+
+ if (naccepted == 0)
+ {
+ Idx dest_node;
+ ok = re_node_set_insert (eps_via_nodes, node);
+ if (BE (! ok, 0))
+ return REG_ERROR;
+ dest_node = dfa->edests[node].elems[0];
+ if (re_node_set_contains (&mctx->state_log[*pidx]->nodes,
+ dest_node))
+ return dest_node;
+ }
+ }
+
+ if (naccepted != 0
+ || check_node_accept (mctx, dfa->nodes + node, *pidx))
+ {
+ Idx dest_node = dfa->nexts[node];
+ *pidx = (naccepted == 0) ? *pidx + 1 : *pidx + naccepted;
+ if (fs && (*pidx > mctx->match_last || mctx->state_log[*pidx] == NULL
+ || !re_node_set_contains (&mctx->state_log[*pidx]->nodes,
+ dest_node)))
+ return REG_MISSING;
+ re_node_set_empty (eps_via_nodes);
+ return dest_node;
+ }
+ }
+ return REG_MISSING;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+push_fail_stack (struct re_fail_stack_t *fs, Idx str_idx, Idx dest_node,
+ Idx nregs, regmatch_t *regs, re_node_set *eps_via_nodes)
+{
+ reg_errcode_t err;
+ Idx num = fs->num++;
+ if (fs->num == fs->alloc)
+ {
+ struct re_fail_stack_ent_t *new_array;
+ new_array = realloc (fs->stack, (sizeof (struct re_fail_stack_ent_t)
+ * fs->alloc * 2));
+ if (new_array == NULL)
+ return REG_ESPACE;
+ fs->alloc *= 2;
+ fs->stack = new_array;
+ }
+ fs->stack[num].idx = str_idx;
+ fs->stack[num].node = dest_node;
+ fs->stack[num].regs = re_malloc (regmatch_t, nregs);
+ if (fs->stack[num].regs == NULL)
+ return REG_ESPACE;
+ memcpy (fs->stack[num].regs, regs, sizeof (regmatch_t) * nregs);
+ err = re_node_set_init_copy (&fs->stack[num].eps_via_nodes, eps_via_nodes);
+ return err;
+}
+
+static Idx
+internal_function
+pop_fail_stack (struct re_fail_stack_t *fs, Idx *pidx, Idx nregs,
+ regmatch_t *regs, re_node_set *eps_via_nodes)
+{
+ Idx num = --fs->num;
+ assert (REG_VALID_INDEX (num));
+ *pidx = fs->stack[num].idx;
+ memcpy (regs, fs->stack[num].regs, sizeof (regmatch_t) * nregs);
+ re_node_set_free (eps_via_nodes);
+ re_free (fs->stack[num].regs);
+ *eps_via_nodes = fs->stack[num].eps_via_nodes;
+ return fs->stack[num].node;
+}
+
+/* Set the positions where the subexpressions are starts/ends to registers
+ PMATCH.
+ Note: We assume that pmatch[0] is already set, and
+ pmatch[i].rm_so == pmatch[i].rm_eo == -1 for 0 < i < nmatch. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch,
+ regmatch_t *pmatch, bool fl_backtrack)
+{
+ const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer;
+ Idx idx, cur_node;
+ re_node_set eps_via_nodes;
+ struct re_fail_stack_t *fs;
+ struct re_fail_stack_t fs_body = { 0, 2, NULL };
+ regmatch_t *prev_idx_match;
+ bool prev_idx_match_malloced = false;
+
+#ifdef DEBUG
+ assert (nmatch > 1);
+ assert (mctx->state_log != NULL);
+#endif
+ if (fl_backtrack)
+ {
+ fs = &fs_body;
+ fs->stack = re_malloc (struct re_fail_stack_ent_t, fs->alloc);
+ if (fs->stack == NULL)
+ return REG_ESPACE;
+ }
+ else
+ fs = NULL;
+
+ cur_node = dfa->init_node;
+ re_node_set_init_empty (&eps_via_nodes);
+
+ if (__libc_use_alloca (nmatch * sizeof (regmatch_t)))
+ prev_idx_match = (regmatch_t *) alloca (nmatch * sizeof (regmatch_t));
+ else
+ {
+ prev_idx_match = re_malloc (regmatch_t, nmatch);
+ if (prev_idx_match == NULL)
+ {
+ free_fail_stack_return (fs);
+ return REG_ESPACE;
+ }
+ prev_idx_match_malloced = true;
+ }
+ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
+
+ for (idx = pmatch[0].rm_so; idx <= pmatch[0].rm_eo ;)
+ {
+ update_regs (dfa, pmatch, prev_idx_match, cur_node, idx, nmatch);
+
+ if (idx == pmatch[0].rm_eo && cur_node == mctx->last_node)
+ {
+ Idx reg_idx;
+ if (fs)
+ {
+ for (reg_idx = 0; reg_idx < nmatch; ++reg_idx)
+ if (pmatch[reg_idx].rm_so > -1 && pmatch[reg_idx].rm_eo == -1)
+ break;
+ if (reg_idx == nmatch)
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return free_fail_stack_return (fs);
+ }
+ cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
+ &eps_via_nodes);
+ }
+ else
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return REG_NOERROR;
+ }
+ }
+
+ /* Proceed to next node. */
+ cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node,
+ &eps_via_nodes, fs);
+
+ if (BE (! REG_VALID_INDEX (cur_node), 0))
+ {
+ if (BE (cur_node == REG_ERROR, 0))
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ free_fail_stack_return (fs);
+ return REG_ESPACE;
+ }
+ if (fs)
+ cur_node = pop_fail_stack (fs, &idx, nmatch, pmatch,
+ &eps_via_nodes);
+ else
+ {
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return REG_NOMATCH;
+ }
+ }
+ }
+ re_node_set_free (&eps_via_nodes);
+ if (prev_idx_match_malloced)
+ re_free (prev_idx_match);
+ return free_fail_stack_return (fs);
+}
+
+static reg_errcode_t
+internal_function
+free_fail_stack_return (struct re_fail_stack_t *fs)
+{
+ if (fs)
+ {
+ Idx fs_idx;
+ for (fs_idx = 0; fs_idx < fs->num; ++fs_idx)
+ {
+ re_node_set_free (&fs->stack[fs_idx].eps_via_nodes);
+ re_free (fs->stack[fs_idx].regs);
+ }
+ re_free (fs->stack);
+ }
+ return REG_NOERROR;
+}
+
+static void
+internal_function
+update_regs (const re_dfa_t *dfa, regmatch_t *pmatch,
+ regmatch_t *prev_idx_match, Idx cur_node, Idx cur_idx, Idx nmatch)
+{
+ int type = dfa->nodes[cur_node].type;
+ if (type == OP_OPEN_SUBEXP)
+ {
+ Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
+
+ /* We are at the first node of this sub expression. */
+ if (reg_num < nmatch)
+ {
+ pmatch[reg_num].rm_so = cur_idx;
+ pmatch[reg_num].rm_eo = -1;
+ }
+ }
+ else if (type == OP_CLOSE_SUBEXP)
+ {
+ Idx reg_num = dfa->nodes[cur_node].opr.idx + 1;
+ if (reg_num < nmatch)
+ {
+ /* We are at the last node of this sub expression. */
+ if (pmatch[reg_num].rm_so < cur_idx)
+ {
+ pmatch[reg_num].rm_eo = cur_idx;
+ /* This is a non-empty match or we are not inside an optional
+ subexpression. Accept this right away. */
+ memcpy (prev_idx_match, pmatch, sizeof (regmatch_t) * nmatch);
+ }
+ else
+ {
+ if (dfa->nodes[cur_node].opt_subexp
+ && prev_idx_match[reg_num].rm_so != -1)
+ /* We transited through an empty match for an optional
+ subexpression, like (a?)*, and this is not the subexp's
+ first match. Copy back the old content of the registers
+ so that matches of an inner subexpression are undone as
+ well, like in ((a?))*. */
+ memcpy (pmatch, prev_idx_match, sizeof (regmatch_t) * nmatch);
+ else
+ /* We completed a subexpression, but it may be part of
+ an optional one, so do not update PREV_IDX_MATCH. */
+ pmatch[reg_num].rm_eo = cur_idx;
+ }
+ }
+ }
+}
+
+/* This function checks the STATE_LOG from the SCTX->last_str_idx to 0
+ and sift the nodes in each states according to the following rules.
+ Updated state_log will be wrote to STATE_LOG.
+
+ Rules: We throw away the Node 'a' in the STATE_LOG[STR_IDX] if...
+ 1. When STR_IDX == MATCH_LAST(the last index in the state_log):
+ If 'a' isn't the LAST_NODE and 'a' can't epsilon transit to
+ the LAST_NODE, we throw away the node 'a'.
+ 2. When 0 <= STR_IDX < MATCH_LAST and 'a' accepts
+ string 's' and transit to 'b':
+ i. If 'b' isn't in the STATE_LOG[STR_IDX+strlen('s')], we throw
+ away the node 'a'.
+ ii. If 'b' is in the STATE_LOG[STR_IDX+strlen('s')] but 'b' is
+ thrown away, we throw away the node 'a'.
+ 3. When 0 <= STR_IDX < MATCH_LAST and 'a' epsilon transit to 'b':
+ i. If 'b' isn't in the STATE_LOG[STR_IDX], we throw away the
+ node 'a'.
+ ii. If 'b' is in the STATE_LOG[STR_IDX] but 'b' is thrown away,
+ we throw away the node 'a'. */
+
+#define STATE_NODE_CONTAINS(state,node) \
+ ((state) != NULL && re_node_set_contains (&(state)->nodes, node))
+
+static reg_errcode_t
+internal_function
+sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx)
+{
+ reg_errcode_t err;
+ int null_cnt = 0;
+ Idx str_idx = sctx->last_str_idx;
+ re_node_set cur_dest;
+
+#ifdef DEBUG
+ assert (mctx->state_log != NULL && mctx->state_log[str_idx] != NULL);
+#endif
+
+ /* Build sifted state_log[str_idx]. It has the nodes which can epsilon
+ transit to the last_node and the last_node itself. */
+ err = re_node_set_init_1 (&cur_dest, sctx->last_node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ /* Then check each states in the state_log. */
+ while (str_idx > 0)
+ {
+ /* Update counters. */
+ null_cnt = (sctx->sifted_states[str_idx] == NULL) ? null_cnt + 1 : 0;
+ if (null_cnt > mctx->max_mb_elem_len)
+ {
+ memset (sctx->sifted_states, '\0',
+ sizeof (re_dfastate_t *) * str_idx);
+ re_node_set_free (&cur_dest);
+ return REG_NOERROR;
+ }
+ re_node_set_empty (&cur_dest);
+ --str_idx;
+
+ if (mctx->state_log[str_idx])
+ {
+ err = build_sifted_states (mctx, sctx, str_idx, &cur_dest);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+
+ /* Add all the nodes which satisfy the following conditions:
+ - It can epsilon transit to a node in CUR_DEST.
+ - It is in CUR_SRC.
+ And update state_log. */
+ err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ err = REG_NOERROR;
+ free_return:
+ re_node_set_free (&cur_dest);
+ return err;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx,
+ Idx str_idx, re_node_set *cur_dest)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *cur_src = &mctx->state_log[str_idx]->non_eps_nodes;
+ Idx i;
+
+ /* Then build the next sifted state.
+ We build the next sifted state on 'cur_dest', and update
+ 'sifted_states[str_idx]' with 'cur_dest'.
+ Note:
+ 'cur_dest' is the sifted state from 'state_log[str_idx + 1]'.
+ 'cur_src' points the node_set of the old 'state_log[str_idx]'
+ (with the epsilon nodes pre-filtered out). */
+ for (i = 0; i < cur_src->nelem; i++)
+ {
+ Idx prev_node = cur_src->elems[i];
+ int naccepted = 0;
+ bool ok;
+
+#ifdef DEBUG
+ re_token_type_t type = dfa->nodes[prev_node].type;
+ assert (!IS_EPSILON_NODE (type));
+#endif
+#ifdef RE_ENABLE_I18N
+ /* If the node may accept "multi byte". */
+ if (dfa->nodes[prev_node].accept_mb)
+ naccepted = sift_states_iter_mb (mctx, sctx, prev_node,
+ str_idx, sctx->last_str_idx);
+#endif /* RE_ENABLE_I18N */
+
+ /* We don't check backreferences here.
+ See update_cur_sifted_state(). */
+ if (!naccepted
+ && check_node_accept (mctx, dfa->nodes + prev_node, str_idx)
+ && STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + 1],
+ dfa->nexts[prev_node]))
+ naccepted = 1;
+
+ if (naccepted == 0)
+ continue;
+
+ if (sctx->limits.nelem)
+ {
+ Idx to_idx = str_idx + naccepted;
+ if (check_dst_limits (mctx, &sctx->limits,
+ dfa->nexts[prev_node], to_idx,
+ prev_node, str_idx))
+ continue;
+ }
+ ok = re_node_set_insert (cur_dest, prev_node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+
+ return REG_NOERROR;
+}
+
+/* Helper functions. */
+
+static reg_errcode_t
+internal_function
+clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx)
+{
+ Idx top = mctx->state_log_top;
+
+ if (next_state_log_idx >= mctx->input.bufs_len
+ || (next_state_log_idx >= mctx->input.valid_len
+ && mctx->input.valid_len < mctx->input.len))
+ {
+ reg_errcode_t err;
+ err = extend_buffers (mctx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ if (top < next_state_log_idx)
+ {
+ memset (mctx->state_log + top + 1, '\0',
+ sizeof (re_dfastate_t *) * (next_state_log_idx - top));
+ mctx->state_log_top = next_state_log_idx;
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function
+merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst,
+ re_dfastate_t **src, Idx num)
+{
+ Idx st_idx;
+ reg_errcode_t err;
+ for (st_idx = 0; st_idx < num; ++st_idx)
+ {
+ if (dst[st_idx] == NULL)
+ dst[st_idx] = src[st_idx];
+ else if (src[st_idx] != NULL)
+ {
+ re_node_set merged_set;
+ err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes,
+ &src[st_idx]->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ dst[st_idx] = re_acquire_state (&err, dfa, &merged_set);
+ re_node_set_free (&merged_set);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function
+update_cur_sifted_state (const re_match_context_t *mctx,
+ re_sift_context_t *sctx, Idx str_idx,
+ re_node_set *dest_nodes)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err = REG_NOERROR;
+ const re_node_set *candidates;
+ candidates = ((mctx->state_log[str_idx] == NULL) ? NULL
+ : &mctx->state_log[str_idx]->nodes);
+
+ if (dest_nodes->nelem == 0)
+ sctx->sifted_states[str_idx] = NULL;
+ else
+ {
+ if (candidates)
+ {
+ /* At first, add the nodes which can epsilon transit to a node in
+ DEST_NODE. */
+ err = add_epsilon_src_nodes (dfa, dest_nodes, candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ /* Then, check the limitations in the current sift_context. */
+ if (sctx->limits.nelem)
+ {
+ err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits,
+ mctx->bkref_ents, str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+
+ sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ if (candidates && mctx->state_log[str_idx]->has_backref)
+ {
+ err = sift_states_bkref (mctx, sctx, str_idx, candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes,
+ const re_node_set *candidates)
+{
+ reg_errcode_t err = REG_NOERROR;
+ Idx i;
+
+ re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ if (!state->inveclosure.alloc)
+ {
+ err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem);
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ESPACE;
+ for (i = 0; i < dest_nodes->nelem; i++)
+ {
+ err = re_node_set_merge (&state->inveclosure,
+ dfa->inveclosures + dest_nodes->elems[i]);
+ if (BE (err != REG_NOERROR, 0))
+ return REG_ESPACE;
+ }
+ }
+ return re_node_set_add_intersect (dest_nodes, candidates,
+ &state->inveclosure);
+}
+
+static reg_errcode_t
+internal_function
+sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes,
+ const re_node_set *candidates)
+{
+ Idx ecl_idx;
+ reg_errcode_t err;
+ re_node_set *inv_eclosure = dfa->inveclosures + node;
+ re_node_set except_nodes;
+ re_node_set_init_empty (&except_nodes);
+ for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
+ {
+ Idx cur_node = inv_eclosure->elems[ecl_idx];
+ if (cur_node == node)
+ continue;
+ if (IS_EPSILON_NODE (dfa->nodes[cur_node].type))
+ {
+ Idx edst1 = dfa->edests[cur_node].elems[0];
+ Idx edst2 = ((dfa->edests[cur_node].nelem > 1)
+ ? dfa->edests[cur_node].elems[1] : REG_MISSING);
+ if ((!re_node_set_contains (inv_eclosure, edst1)
+ && re_node_set_contains (dest_nodes, edst1))
+ || (REG_VALID_NONZERO_INDEX (edst2)
+ && !re_node_set_contains (inv_eclosure, edst2)
+ && re_node_set_contains (dest_nodes, edst2)))
+ {
+ err = re_node_set_add_intersect (&except_nodes, candidates,
+ dfa->inveclosures + cur_node);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&except_nodes);
+ return err;
+ }
+ }
+ }
+ }
+ for (ecl_idx = 0; ecl_idx < inv_eclosure->nelem; ++ecl_idx)
+ {
+ Idx cur_node = inv_eclosure->elems[ecl_idx];
+ if (!re_node_set_contains (&except_nodes, cur_node))
+ {
+ Idx idx = re_node_set_contains (dest_nodes, cur_node) - 1;
+ re_node_set_remove_at (dest_nodes, idx);
+ }
+ }
+ re_node_set_free (&except_nodes);
+ return REG_NOERROR;
+}
+
+static bool
+internal_function
+check_dst_limits (const re_match_context_t *mctx, const re_node_set *limits,
+ Idx dst_node, Idx dst_idx, Idx src_node, Idx src_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx lim_idx, src_pos, dst_pos;
+
+ Idx dst_bkref_idx = search_cur_bkref_entry (mctx, dst_idx);
+ Idx src_bkref_idx = search_cur_bkref_entry (mctx, src_idx);
+ for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
+ {
+ Idx subexp_idx;
+ struct re_backref_cache_entry *ent;
+ ent = mctx->bkref_ents + limits->elems[lim_idx];
+ subexp_idx = dfa->nodes[ent->node].opr.idx;
+
+ dst_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx],
+ subexp_idx, dst_node, dst_idx,
+ dst_bkref_idx);
+ src_pos = check_dst_limits_calc_pos (mctx, limits->elems[lim_idx],
+ subexp_idx, src_node, src_idx,
+ src_bkref_idx);
+
+ /* In case of:
+ <src> <dst> ( <subexp> )
+ ( <subexp> ) <src> <dst>
+ ( <subexp1> <src> <subexp2> <dst> <subexp3> ) */
+ if (src_pos == dst_pos)
+ continue; /* This is unrelated limitation. */
+ else
+ return true;
+ }
+ return false;
+}
+
+static int
+internal_function
+check_dst_limits_calc_pos_1 (const re_match_context_t *mctx, int boundaries,
+ Idx subexp_idx, Idx from_node, Idx bkref_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ const re_node_set *eclosures = dfa->eclosures + from_node;
+ Idx node_idx;
+
+ /* Else, we are on the boundary: examine the nodes on the epsilon
+ closure. */
+ for (node_idx = 0; node_idx < eclosures->nelem; ++node_idx)
+ {
+ Idx node = eclosures->elems[node_idx];
+ switch (dfa->nodes[node].type)
+ {
+ case OP_BACK_REF:
+ if (bkref_idx != REG_MISSING)
+ {
+ struct re_backref_cache_entry *ent = mctx->bkref_ents + bkref_idx;
+ do
+ {
+ Idx dst;
+ int cpos;
+
+ if (ent->node != node)
+ continue;
+
+ if (subexp_idx < BITSET_WORD_BITS
+ && !(ent->eps_reachable_subexps_map
+ & ((bitset_word_t) 1 << subexp_idx)))
+ continue;
+
+ /* Recurse trying to reach the OP_OPEN_SUBEXP and
+ OP_CLOSE_SUBEXP cases below. But, if the
+ destination node is the same node as the source
+ node, don't recurse because it would cause an
+ infinite loop: a regex that exhibits this behavior
+ is ()\1*\1* */
+ dst = dfa->edests[node].elems[0];
+ if (dst == from_node)
+ {
+ if (boundaries & 1)
+ return -1;
+ else /* if (boundaries & 2) */
+ return 0;
+ }
+
+ cpos =
+ check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx,
+ dst, bkref_idx);
+ if (cpos == -1 /* && (boundaries & 1) */)
+ return -1;
+ if (cpos == 0 && (boundaries & 2))
+ return 0;
+
+ if (subexp_idx < BITSET_WORD_BITS)
+ ent->eps_reachable_subexps_map
+ &= ~((bitset_word_t) 1 << subexp_idx);
+ }
+ while (ent++->more);
+ }
+ break;
+
+ case OP_OPEN_SUBEXP:
+ if ((boundaries & 1) && subexp_idx == dfa->nodes[node].opr.idx)
+ return -1;
+ break;
+
+ case OP_CLOSE_SUBEXP:
+ if ((boundaries & 2) && subexp_idx == dfa->nodes[node].opr.idx)
+ return 0;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return (boundaries & 2) ? 1 : 0;
+}
+
+static int
+internal_function
+check_dst_limits_calc_pos (const re_match_context_t *mctx, Idx limit,
+ Idx subexp_idx, Idx from_node, Idx str_idx,
+ Idx bkref_idx)
+{
+ struct re_backref_cache_entry *lim = mctx->bkref_ents + limit;
+ int boundaries;
+
+ /* If we are outside the range of the subexpression, return -1 or 1. */
+ if (str_idx < lim->subexp_from)
+ return -1;
+
+ if (lim->subexp_to < str_idx)
+ return 1;
+
+ /* If we are within the subexpression, return 0. */
+ boundaries = (str_idx == lim->subexp_from);
+ boundaries |= (str_idx == lim->subexp_to) << 1;
+ if (boundaries == 0)
+ return 0;
+
+ /* Else, examine epsilon closure. */
+ return check_dst_limits_calc_pos_1 (mctx, boundaries, subexp_idx,
+ from_node, bkref_idx);
+}
+
+/* Check the limitations of sub expressions LIMITS, and remove the nodes
+ which are against limitations from DEST_NODES. */
+
+static reg_errcode_t
+internal_function
+check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes,
+ const re_node_set *candidates, re_node_set *limits,
+ struct re_backref_cache_entry *bkref_ents, Idx str_idx)
+{
+ reg_errcode_t err;
+ Idx node_idx, lim_idx;
+
+ for (lim_idx = 0; lim_idx < limits->nelem; ++lim_idx)
+ {
+ Idx subexp_idx;
+ struct re_backref_cache_entry *ent;
+ ent = bkref_ents + limits->elems[lim_idx];
+
+ if (str_idx <= ent->subexp_from || ent->str_idx < str_idx)
+ continue; /* This is unrelated limitation. */
+
+ subexp_idx = dfa->nodes[ent->node].opr.idx;
+ if (ent->subexp_to == str_idx)
+ {
+ Idx ops_node = REG_MISSING;
+ Idx cls_node = REG_MISSING;
+ for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
+ {
+ Idx node = dest_nodes->elems[node_idx];
+ re_token_type_t type = dfa->nodes[node].type;
+ if (type == OP_OPEN_SUBEXP
+ && subexp_idx == dfa->nodes[node].opr.idx)
+ ops_node = node;
+ else if (type == OP_CLOSE_SUBEXP
+ && subexp_idx == dfa->nodes[node].opr.idx)
+ cls_node = node;
+ }
+
+ /* Check the limitation of the open subexpression. */
+ /* Note that (ent->subexp_to = str_idx != ent->subexp_from). */
+ if (REG_VALID_INDEX (ops_node))
+ {
+ err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes,
+ candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ /* Check the limitation of the close subexpression. */
+ if (REG_VALID_INDEX (cls_node))
+ for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
+ {
+ Idx node = dest_nodes->elems[node_idx];
+ if (!re_node_set_contains (dfa->inveclosures + node,
+ cls_node)
+ && !re_node_set_contains (dfa->eclosures + node,
+ cls_node))
+ {
+ /* It is against this limitation.
+ Remove it form the current sifted state. */
+ err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
+ candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ --node_idx;
+ }
+ }
+ }
+ else /* (ent->subexp_to != str_idx) */
+ {
+ for (node_idx = 0; node_idx < dest_nodes->nelem; ++node_idx)
+ {
+ Idx node = dest_nodes->elems[node_idx];
+ re_token_type_t type = dfa->nodes[node].type;
+ if (type == OP_CLOSE_SUBEXP || type == OP_OPEN_SUBEXP)
+ {
+ if (subexp_idx != dfa->nodes[node].opr.idx)
+ continue;
+ /* It is against this limitation.
+ Remove it form the current sifted state. */
+ err = sub_epsilon_src_nodes (dfa, node, dest_nodes,
+ candidates);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ }
+ }
+ return REG_NOERROR;
+}
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
+ Idx str_idx, const re_node_set *candidates)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx node_idx, node;
+ re_sift_context_t local_sctx;
+ Idx first_idx = search_cur_bkref_entry (mctx, str_idx);
+
+ if (first_idx == REG_MISSING)
+ return REG_NOERROR;
+
+ local_sctx.sifted_states = NULL; /* Mark that it hasn't been initialized. */
+
+ for (node_idx = 0; node_idx < candidates->nelem; ++node_idx)
+ {
+ Idx enabled_idx;
+ re_token_type_t type;
+ struct re_backref_cache_entry *entry;
+ node = candidates->elems[node_idx];
+ type = dfa->nodes[node].type;
+ /* Avoid infinite loop for the REs like "()\1+". */
+ if (node == sctx->last_node && str_idx == sctx->last_str_idx)
+ continue;
+ if (type != OP_BACK_REF)
+ continue;
+
+ entry = mctx->bkref_ents + first_idx;
+ enabled_idx = first_idx;
+ do
+ {
+ Idx subexp_len;
+ Idx to_idx;
+ Idx dst_node;
+ bool ok;
+ re_dfastate_t *cur_state;
+
+ if (entry->node != node)
+ continue;
+ subexp_len = entry->subexp_to - entry->subexp_from;
+ to_idx = str_idx + subexp_len;
+ dst_node = (subexp_len ? dfa->nexts[node]
+ : dfa->edests[node].elems[0]);
+
+ if (to_idx > sctx->last_str_idx
+ || sctx->sifted_states[to_idx] == NULL
+ || !STATE_NODE_CONTAINS (sctx->sifted_states[to_idx], dst_node)
+ || check_dst_limits (mctx, &sctx->limits, node,
+ str_idx, dst_node, to_idx))
+ continue;
+
+ if (local_sctx.sifted_states == NULL)
+ {
+ local_sctx = *sctx;
+ err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ local_sctx.last_node = node;
+ local_sctx.last_str_idx = str_idx;
+ ok = re_node_set_insert (&local_sctx.limits, enabled_idx);
+ if (BE (! ok, 0))
+ {
+ err = REG_ESPACE;
+ goto free_return;
+ }
+ cur_state = local_sctx.sifted_states[str_idx];
+ err = sift_states_backward (mctx, &local_sctx);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ if (sctx->limited_states != NULL)
+ {
+ err = merge_state_array (dfa, sctx->limited_states,
+ local_sctx.sifted_states,
+ str_idx + 1);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ local_sctx.sifted_states[str_idx] = cur_state;
+ re_node_set_remove (&local_sctx.limits, enabled_idx);
+
+ /* mctx->bkref_ents may have changed, reload the pointer. */
+ entry = mctx->bkref_ents + enabled_idx;
+ }
+ while (enabled_idx++, entry++->more);
+ }
+ err = REG_NOERROR;
+ free_return:
+ if (local_sctx.sifted_states != NULL)
+ {
+ re_node_set_free (&local_sctx.limits);
+ }
+
+ return err;
+}
+
+
+#ifdef RE_ENABLE_I18N
+static int
+internal_function
+sift_states_iter_mb (const re_match_context_t *mctx, re_sift_context_t *sctx,
+ Idx node_idx, Idx str_idx, Idx max_str_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ int naccepted;
+ /* Check the node can accept "multi byte". */
+ naccepted = check_node_accept_bytes (dfa, node_idx, &mctx->input, str_idx);
+ if (naccepted > 0 && str_idx + naccepted <= max_str_idx &&
+ !STATE_NODE_CONTAINS (sctx->sifted_states[str_idx + naccepted],
+ dfa->nexts[node_idx]))
+ /* The node can't accept the "multi byte", or the
+ destination was already thrown away, then the node
+ could't accept the current input "multi byte". */
+ naccepted = 0;
+ /* Otherwise, it is sure that the node could accept
+ 'naccepted' bytes input. */
+ return naccepted;
+}
+#endif /* RE_ENABLE_I18N */
+
+
+/* Functions for state transition. */
+
+/* Return the next state to which the current state STATE will transit by
+ accepting the current input byte, and update STATE_LOG if necessary.
+ If STATE can accept a multibyte char/collating element/back reference
+ update the destination of STATE_LOG. */
+
+static re_dfastate_t *
+internal_function __attribute_warn_unused_result__
+transit_state (reg_errcode_t *err, re_match_context_t *mctx,
+ re_dfastate_t *state)
+{
+ re_dfastate_t **trtable;
+ unsigned char ch;
+
+#ifdef RE_ENABLE_I18N
+ /* If the current state can accept multibyte. */
+ if (BE (state->accept_mb, 0))
+ {
+ *err = transit_state_mb (mctx, state);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ }
+#endif /* RE_ENABLE_I18N */
+
+ /* Then decide the next state with the single byte. */
+#if 0
+ if (0)
+ /* don't use transition table */
+ return transit_state_sb (err, mctx, state);
+#endif
+
+ /* Use transition table */
+ ch = re_string_fetch_byte (&mctx->input);
+ for (;;)
+ {
+ trtable = state->trtable;
+ if (BE (trtable != NULL, 1))
+ return trtable[ch];
+
+ trtable = state->word_trtable;
+ if (BE (trtable != NULL, 1))
+ {
+ unsigned int context;
+ context
+ = re_string_context_at (&mctx->input,
+ re_string_cur_idx (&mctx->input) - 1,
+ mctx->eflags);
+ if (IS_WORD_CONTEXT (context))
+ return trtable[ch + SBC_MAX];
+ else
+ return trtable[ch];
+ }
+
+ if (!build_trtable (mctx->dfa, state))
+ {
+ *err = REG_ESPACE;
+ return NULL;
+ }
+
+ /* Retry, we now have a transition table. */
+ }
+}
+
+/* Update the state_log if we need */
+static re_dfastate_t *
+internal_function
+merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx,
+ re_dfastate_t *next_state)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx cur_idx = re_string_cur_idx (&mctx->input);
+
+ if (cur_idx > mctx->state_log_top)
+ {
+ mctx->state_log[cur_idx] = next_state;
+ mctx->state_log_top = cur_idx;
+ }
+ else if (mctx->state_log[cur_idx] == 0)
+ {
+ mctx->state_log[cur_idx] = next_state;
+ }
+ else
+ {
+ re_dfastate_t *pstate;
+ unsigned int context;
+ re_node_set next_nodes, *log_nodes, *table_nodes = NULL;
+ /* If (state_log[cur_idx] != 0), it implies that cur_idx is
+ the destination of a multibyte char/collating element/
+ back reference. Then the next state is the union set of
+ these destinations and the results of the transition table. */
+ pstate = mctx->state_log[cur_idx];
+ log_nodes = pstate->entrance_nodes;
+ if (next_state != NULL)
+ {
+ table_nodes = next_state->entrance_nodes;
+ *err = re_node_set_init_union (&next_nodes, table_nodes,
+ log_nodes);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ }
+ else
+ next_nodes = *log_nodes;
+ /* Note: We already add the nodes of the initial state,
+ then we don't need to add them here. */
+
+ context = re_string_context_at (&mctx->input,
+ re_string_cur_idx (&mctx->input) - 1,
+ mctx->eflags);
+ next_state = mctx->state_log[cur_idx]
+ = re_acquire_state_context (err, dfa, &next_nodes, context);
+ /* We don't need to check errors here, since the return value of
+ this function is next_state and ERR is already set. */
+
+ if (table_nodes != NULL)
+ re_node_set_free (&next_nodes);
+ }
+
+ if (BE (dfa->nbackref, 0) && next_state != NULL)
+ {
+ /* Check OP_OPEN_SUBEXP in the current state in case that we use them
+ later. We must check them here, since the back references in the
+ next state might use them. */
+ *err = check_subexp_matching_top (mctx, &next_state->nodes,
+ cur_idx);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+
+ /* If the next state has back references. */
+ if (next_state->has_backref)
+ {
+ *err = transit_state_bkref (mctx, &next_state->nodes);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ next_state = mctx->state_log[cur_idx];
+ }
+ }
+
+ return next_state;
+}
+
+/* Skip bytes in the input that correspond to part of a
+ multi-byte match, then look in the log for a state
+ from which to restart matching. */
+static re_dfastate_t *
+internal_function
+find_recover_state (reg_errcode_t *err, re_match_context_t *mctx)
+{
+ re_dfastate_t *cur_state;
+ do
+ {
+ Idx max = mctx->state_log_top;
+ Idx cur_str_idx = re_string_cur_idx (&mctx->input);
+
+ do
+ {
+ if (++cur_str_idx > max)
+ return NULL;
+ re_string_skip_bytes (&mctx->input, 1);
+ }
+ while (mctx->state_log[cur_str_idx] == NULL);
+
+ cur_state = merge_state_with_log (err, mctx, NULL);
+ }
+ while (*err == REG_NOERROR && cur_state == NULL);
+ return cur_state;
+}
+
+/* Helper functions for transit_state. */
+
+/* From the node set CUR_NODES, pick up the nodes whose types are
+ OP_OPEN_SUBEXP and which have corresponding back references in the regular
+ expression. And register them to use them later for evaluating the
+ correspoding back references. */
+
+static reg_errcode_t
+internal_function
+check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes,
+ Idx str_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx node_idx;
+ reg_errcode_t err;
+
+ /* TODO: This isn't efficient.
+ Because there might be more than one nodes whose types are
+ OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all
+ nodes.
+ E.g. RE: (a){2} */
+ for (node_idx = 0; node_idx < cur_nodes->nelem; ++node_idx)
+ {
+ Idx node = cur_nodes->elems[node_idx];
+ if (dfa->nodes[node].type == OP_OPEN_SUBEXP
+ && dfa->nodes[node].opr.idx < BITSET_WORD_BITS
+ && (dfa->used_bkref_map
+ & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx)))
+ {
+ err = match_ctx_add_subtop (mctx, node, str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ return REG_NOERROR;
+}
+
+#if 0
+/* Return the next state to which the current state STATE will transit by
+ accepting the current input byte. */
+
+static re_dfastate_t *
+transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx,
+ re_dfastate_t *state)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ re_node_set next_nodes;
+ re_dfastate_t *next_state;
+ Idx node_cnt, cur_str_idx = re_string_cur_idx (&mctx->input);
+ unsigned int context;
+
+ *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1);
+ if (BE (*err != REG_NOERROR, 0))
+ return NULL;
+ for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt)
+ {
+ Idx cur_node = state->nodes.elems[node_cnt];
+ if (check_node_accept (mctx, dfa->nodes + cur_node, cur_str_idx))
+ {
+ *err = re_node_set_merge (&next_nodes,
+ dfa->eclosures + dfa->nexts[cur_node]);
+ if (BE (*err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return NULL;
+ }
+ }
+ }
+ context = re_string_context_at (&mctx->input, cur_str_idx, mctx->eflags);
+ next_state = re_acquire_state_context (err, dfa, &next_nodes, context);
+ /* We don't need to check errors here, since the return value of
+ this function is next_state and ERR is already set. */
+
+ re_node_set_free (&next_nodes);
+ re_string_skip_bytes (&mctx->input, 1);
+ return next_state;
+}
+#endif
+
+#ifdef RE_ENABLE_I18N
+static reg_errcode_t
+internal_function
+transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx i;
+
+ for (i = 0; i < pstate->nodes.nelem; ++i)
+ {
+ re_node_set dest_nodes, *new_nodes;
+ Idx cur_node_idx = pstate->nodes.elems[i];
+ int naccepted;
+ Idx dest_idx;
+ unsigned int context;
+ re_dfastate_t *dest_state;
+
+ if (!dfa->nodes[cur_node_idx].accept_mb)
+ continue;
+
+ if (dfa->nodes[cur_node_idx].constraint)
+ {
+ context = re_string_context_at (&mctx->input,
+ re_string_cur_idx (&mctx->input),
+ mctx->eflags);
+ if (NOT_SATISFY_NEXT_CONSTRAINT (dfa->nodes[cur_node_idx].constraint,
+ context))
+ continue;
+ }
+
+ /* How many bytes the node can accept? */
+ naccepted = check_node_accept_bytes (dfa, cur_node_idx, &mctx->input,
+ re_string_cur_idx (&mctx->input));
+ if (naccepted == 0)
+ continue;
+
+ /* The node can accepts 'naccepted' bytes. */
+ dest_idx = re_string_cur_idx (&mctx->input) + naccepted;
+ mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
+ : mctx->max_mb_elem_len);
+ err = clean_state_log_if_needed (mctx, dest_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+#ifdef DEBUG
+ assert (dfa->nexts[cur_node_idx] != REG_MISSING);
+#endif
+ new_nodes = dfa->eclosures + dfa->nexts[cur_node_idx];
+
+ dest_state = mctx->state_log[dest_idx];
+ if (dest_state == NULL)
+ dest_nodes = *new_nodes;
+ else
+ {
+ err = re_node_set_init_union (&dest_nodes,
+ dest_state->entrance_nodes, new_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ context = re_string_context_at (&mctx->input, dest_idx - 1,
+ mctx->eflags);
+ mctx->state_log[dest_idx]
+ = re_acquire_state_context (&err, dfa, &dest_nodes, context);
+ if (dest_state != NULL)
+ re_node_set_free (&dest_nodes);
+ if (BE (mctx->state_log[dest_idx] == NULL && err != REG_NOERROR, 0))
+ return err;
+ }
+ return REG_NOERROR;
+}
+#endif /* RE_ENABLE_I18N */
+
+static reg_errcode_t
+internal_function
+transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx i;
+ Idx cur_str_idx = re_string_cur_idx (&mctx->input);
+
+ for (i = 0; i < nodes->nelem; ++i)
+ {
+ Idx dest_str_idx, prev_nelem, bkc_idx;
+ Idx node_idx = nodes->elems[i];
+ unsigned int context;
+ const re_token_t *node = dfa->nodes + node_idx;
+ re_node_set *new_dest_nodes;
+
+ /* Check whether 'node' is a backreference or not. */
+ if (node->type != OP_BACK_REF)
+ continue;
+
+ if (node->constraint)
+ {
+ context = re_string_context_at (&mctx->input, cur_str_idx,
+ mctx->eflags);
+ if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
+ continue;
+ }
+
+ /* 'node' is a backreference.
+ Check the substring which the substring matched. */
+ bkc_idx = mctx->nbkref_ents;
+ err = get_subexp (mctx, node_idx, cur_str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+
+ /* And add the epsilon closures (which is 'new_dest_nodes') of
+ the backreference to appropriate state_log. */
+#ifdef DEBUG
+ assert (dfa->nexts[node_idx] != REG_MISSING);
+#endif
+ for (; bkc_idx < mctx->nbkref_ents; ++bkc_idx)
+ {
+ Idx subexp_len;
+ re_dfastate_t *dest_state;
+ struct re_backref_cache_entry *bkref_ent;
+ bkref_ent = mctx->bkref_ents + bkc_idx;
+ if (bkref_ent->node != node_idx || bkref_ent->str_idx != cur_str_idx)
+ continue;
+ subexp_len = bkref_ent->subexp_to - bkref_ent->subexp_from;
+ new_dest_nodes = (subexp_len == 0
+ ? dfa->eclosures + dfa->edests[node_idx].elems[0]
+ : dfa->eclosures + dfa->nexts[node_idx]);
+ dest_str_idx = (cur_str_idx + bkref_ent->subexp_to
+ - bkref_ent->subexp_from);
+ context = re_string_context_at (&mctx->input, dest_str_idx - 1,
+ mctx->eflags);
+ dest_state = mctx->state_log[dest_str_idx];
+ prev_nelem = ((mctx->state_log[cur_str_idx] == NULL) ? 0
+ : mctx->state_log[cur_str_idx]->nodes.nelem);
+ /* Add 'new_dest_node' to state_log. */
+ if (dest_state == NULL)
+ {
+ mctx->state_log[dest_str_idx]
+ = re_acquire_state_context (&err, dfa, new_dest_nodes,
+ context);
+ if (BE (mctx->state_log[dest_str_idx] == NULL
+ && err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ else
+ {
+ re_node_set dest_nodes;
+ err = re_node_set_init_union (&dest_nodes,
+ dest_state->entrance_nodes,
+ new_dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&dest_nodes);
+ goto free_return;
+ }
+ mctx->state_log[dest_str_idx]
+ = re_acquire_state_context (&err, dfa, &dest_nodes, context);
+ re_node_set_free (&dest_nodes);
+ if (BE (mctx->state_log[dest_str_idx] == NULL
+ && err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ /* We need to check recursively if the backreference can epsilon
+ transit. */
+ if (subexp_len == 0
+ && mctx->state_log[cur_str_idx]->nodes.nelem > prev_nelem)
+ {
+ err = check_subexp_matching_top (mctx, new_dest_nodes,
+ cur_str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ err = transit_state_bkref (mctx, new_dest_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ goto free_return;
+ }
+ }
+ }
+ err = REG_NOERROR;
+ free_return:
+ return err;
+}
+
+/* Enumerate all the candidates which the backreference BKREF_NODE can match
+ at BKREF_STR_IDX, and register them by match_ctx_add_entry().
+ Note that we might collect inappropriate candidates here.
+ However, the cost of checking them strictly here is too high, then we
+ delay these checking for prune_impossible_nodes(). */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ Idx subexp_num, sub_top_idx;
+ const char *buf = (const char *) re_string_get_buffer (&mctx->input);
+ /* Return if we have already checked BKREF_NODE at BKREF_STR_IDX. */
+ Idx cache_idx = search_cur_bkref_entry (mctx, bkref_str_idx);
+ if (cache_idx != REG_MISSING)
+ {
+ const struct re_backref_cache_entry *entry
+ = mctx->bkref_ents + cache_idx;
+ do
+ if (entry->node == bkref_node)
+ return REG_NOERROR; /* We already checked it. */
+ while (entry++->more);
+ }
+
+ subexp_num = dfa->nodes[bkref_node].opr.idx;
+
+ /* For each sub expression */
+ for (sub_top_idx = 0; sub_top_idx < mctx->nsub_tops; ++sub_top_idx)
+ {
+ reg_errcode_t err;
+ re_sub_match_top_t *sub_top = mctx->sub_tops[sub_top_idx];
+ re_sub_match_last_t *sub_last;
+ Idx sub_last_idx, sl_str, bkref_str_off;
+
+ if (dfa->nodes[sub_top->node].opr.idx != subexp_num)
+ continue; /* It isn't related. */
+
+ sl_str = sub_top->str_idx;
+ bkref_str_off = bkref_str_idx;
+ /* At first, check the last node of sub expressions we already
+ evaluated. */
+ for (sub_last_idx = 0; sub_last_idx < sub_top->nlasts; ++sub_last_idx)
+ {
+ regoff_t sl_str_diff;
+ sub_last = sub_top->lasts[sub_last_idx];
+ sl_str_diff = sub_last->str_idx - sl_str;
+ /* The matched string by the sub expression match with the substring
+ at the back reference? */
+ if (sl_str_diff > 0)
+ {
+ if (BE (bkref_str_off + sl_str_diff > mctx->input.valid_len, 0))
+ {
+ /* Not enough chars for a successful match. */
+ if (bkref_str_off + sl_str_diff > mctx->input.len)
+ break;
+
+ err = clean_state_log_if_needed (mctx,
+ bkref_str_off
+ + sl_str_diff);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ buf = (const char *) re_string_get_buffer (&mctx->input);
+ }
+ if (memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0)
+ /* We don't need to search this sub expression any more. */
+ break;
+ }
+ bkref_str_off += sl_str_diff;
+ sl_str += sl_str_diff;
+ err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
+ bkref_str_idx);
+
+ /* Reload buf, since the preceding call might have reallocated
+ the buffer. */
+ buf = (const char *) re_string_get_buffer (&mctx->input);
+
+ if (err == REG_NOMATCH)
+ continue;
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+
+ if (sub_last_idx < sub_top->nlasts)
+ continue;
+ if (sub_last_idx > 0)
+ ++sl_str;
+ /* Then, search for the other last nodes of the sub expression. */
+ for (; sl_str <= bkref_str_idx; ++sl_str)
+ {
+ Idx cls_node;
+ regoff_t sl_str_off;
+ const re_node_set *nodes;
+ sl_str_off = sl_str - sub_top->str_idx;
+ /* The matched string by the sub expression match with the substring
+ at the back reference? */
+ if (sl_str_off > 0)
+ {
+ if (BE (bkref_str_off >= mctx->input.valid_len, 0))
+ {
+ /* If we are at the end of the input, we cannot match. */
+ if (bkref_str_off >= mctx->input.len)
+ break;
+
+ err = extend_buffers (mctx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+
+ buf = (const char *) re_string_get_buffer (&mctx->input);
+ }
+ if (buf [bkref_str_off++] != buf[sl_str - 1])
+ break; /* We don't need to search this sub expression
+ any more. */
+ }
+ if (mctx->state_log[sl_str] == NULL)
+ continue;
+ /* Does this state have a ')' of the sub expression? */
+ nodes = &mctx->state_log[sl_str]->nodes;
+ cls_node = find_subexp_node (dfa, nodes, subexp_num,
+ OP_CLOSE_SUBEXP);
+ if (cls_node == REG_MISSING)
+ continue; /* No. */
+ if (sub_top->path == NULL)
+ {
+ sub_top->path = calloc (sizeof (state_array_t),
+ sl_str - sub_top->str_idx + 1);
+ if (sub_top->path == NULL)
+ return REG_ESPACE;
+ }
+ /* Can the OP_OPEN_SUBEXP node arrive the OP_CLOSE_SUBEXP node
+ in the current context? */
+ err = check_arrival (mctx, sub_top->path, sub_top->node,
+ sub_top->str_idx, cls_node, sl_str,
+ OP_CLOSE_SUBEXP);
+ if (err == REG_NOMATCH)
+ continue;
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str);
+ if (BE (sub_last == NULL, 0))
+ return REG_ESPACE;
+ err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node,
+ bkref_str_idx);
+ if (err == REG_NOMATCH)
+ continue;
+ }
+ }
+ return REG_NOERROR;
+}
+
+/* Helper functions for get_subexp(). */
+
+/* Check SUB_LAST can arrive to the back reference BKREF_NODE at BKREF_STR.
+ If it can arrive, register the sub expression expressed with SUB_TOP
+ and SUB_LAST. */
+
+static reg_errcode_t
+internal_function
+get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top,
+ re_sub_match_last_t *sub_last, Idx bkref_node, Idx bkref_str)
+{
+ reg_errcode_t err;
+ Idx to_idx;
+ /* Can the subexpression arrive the back reference? */
+ err = check_arrival (mctx, &sub_last->path, sub_last->node,
+ sub_last->str_idx, bkref_node, bkref_str,
+ OP_OPEN_SUBEXP);
+ if (err != REG_NOERROR)
+ return err;
+ err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx,
+ sub_last->str_idx);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx;
+ return clean_state_log_if_needed (mctx, to_idx);
+}
+
+/* Find the first node which is '(' or ')' and whose index is SUBEXP_IDX.
+ Search '(' if FL_OPEN, or search ')' otherwise.
+ TODO: This function isn't efficient...
+ Because there might be more than one nodes whose types are
+ OP_OPEN_SUBEXP and whose index is SUBEXP_IDX, we must check all
+ nodes.
+ E.g. RE: (a){2} */
+
+static Idx
+internal_function
+find_subexp_node (const re_dfa_t *dfa, const re_node_set *nodes,
+ Idx subexp_idx, int type)
+{
+ Idx cls_idx;
+ for (cls_idx = 0; cls_idx < nodes->nelem; ++cls_idx)
+ {
+ Idx cls_node = nodes->elems[cls_idx];
+ const re_token_t *node = dfa->nodes + cls_node;
+ if (node->type == type
+ && node->opr.idx == subexp_idx)
+ return cls_node;
+ }
+ return REG_MISSING;
+}
+
+/* Check whether the node TOP_NODE at TOP_STR can arrive to the node
+ LAST_NODE at LAST_STR. We record the path onto PATH since it will be
+ heavily reused.
+ Return REG_NOERROR if it can arrive, or REG_NOMATCH otherwise. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node,
+ Idx top_str, Idx last_node, Idx last_str, int type)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err = REG_NOERROR;
+ Idx subexp_num, backup_cur_idx, str_idx, null_cnt;
+ re_dfastate_t *cur_state = NULL;
+ re_node_set *cur_nodes, next_nodes;
+ re_dfastate_t **backup_state_log;
+ unsigned int context;
+
+ subexp_num = dfa->nodes[top_node].opr.idx;
+ /* Extend the buffer if we need. */
+ if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0))
+ {
+ re_dfastate_t **new_array;
+ Idx old_alloc = path->alloc;
+ Idx new_alloc = old_alloc + last_str + mctx->max_mb_elem_len + 1;
+ if (BE (new_alloc < old_alloc, 0)
+ || BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0))
+ return REG_ESPACE;
+ new_array = re_realloc (path->array, re_dfastate_t *, new_alloc);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ path->array = new_array;
+ path->alloc = new_alloc;
+ memset (new_array + old_alloc, '\0',
+ sizeof (re_dfastate_t *) * (path->alloc - old_alloc));
+ }
+
+ str_idx = path->next_idx ? path->next_idx : top_str;
+
+ /* Temporary modify MCTX. */
+ backup_state_log = mctx->state_log;
+ backup_cur_idx = mctx->input.cur_idx;
+ mctx->state_log = path->array;
+ mctx->input.cur_idx = str_idx;
+
+ /* Setup initial node set. */
+ context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
+ if (str_idx == top_str)
+ {
+ err = re_node_set_init_1 (&next_nodes, top_node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ else
+ {
+ cur_state = mctx->state_log[str_idx];
+ if (cur_state && cur_state->has_backref)
+ {
+ err = re_node_set_init_copy (&next_nodes, &cur_state->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ else
+ re_node_set_init_empty (&next_nodes);
+ }
+ if (str_idx == top_str || (cur_state && cur_state->has_backref))
+ {
+ if (next_nodes.nelem)
+ {
+ err = expand_bkref_cache (mctx, &next_nodes, str_idx,
+ subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
+ if (BE (cur_state == NULL && err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ mctx->state_log[str_idx] = cur_state;
+ }
+
+ for (null_cnt = 0; str_idx < last_str && null_cnt <= mctx->max_mb_elem_len;)
+ {
+ re_node_set_empty (&next_nodes);
+ if (mctx->state_log[str_idx + 1])
+ {
+ err = re_node_set_merge (&next_nodes,
+ &mctx->state_log[str_idx + 1]->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ if (cur_state)
+ {
+ err = check_arrival_add_next_nodes (mctx, str_idx,
+ &cur_state->non_eps_nodes,
+ &next_nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ ++str_idx;
+ if (next_nodes.nelem)
+ {
+ err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ err = expand_bkref_cache (mctx, &next_nodes, str_idx,
+ subexp_num, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ }
+ context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags);
+ cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context);
+ if (BE (cur_state == NULL && err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&next_nodes);
+ return err;
+ }
+ mctx->state_log[str_idx] = cur_state;
+ null_cnt = cur_state == NULL ? null_cnt + 1 : 0;
+ }
+ re_node_set_free (&next_nodes);
+ cur_nodes = (mctx->state_log[last_str] == NULL ? NULL
+ : &mctx->state_log[last_str]->nodes);
+ path->next_idx = str_idx;
+
+ /* Fix MCTX. */
+ mctx->state_log = backup_state_log;
+ mctx->input.cur_idx = backup_cur_idx;
+
+ /* Then check the current node set has the node LAST_NODE. */
+ if (cur_nodes != NULL && re_node_set_contains (cur_nodes, last_node))
+ return REG_NOERROR;
+
+ return REG_NOMATCH;
+}
+
+/* Helper functions for check_arrival. */
+
+/* Calculate the destination nodes of CUR_NODES at STR_IDX, and append them
+ to NEXT_NODES.
+ TODO: This function is similar to the functions transit_state*(),
+ however this function has many additional works.
+ Can't we unify them? */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx,
+ re_node_set *cur_nodes, re_node_set *next_nodes)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ bool ok;
+ Idx cur_idx;
+#ifdef RE_ENABLE_I18N
+ reg_errcode_t err = REG_NOERROR;
+#endif
+ re_node_set union_set;
+ re_node_set_init_empty (&union_set);
+ for (cur_idx = 0; cur_idx < cur_nodes->nelem; ++cur_idx)
+ {
+ int naccepted = 0;
+ Idx cur_node = cur_nodes->elems[cur_idx];
+#ifdef DEBUG
+ re_token_type_t type = dfa->nodes[cur_node].type;
+ assert (!IS_EPSILON_NODE (type));
+#endif
+#ifdef RE_ENABLE_I18N
+ /* If the node may accept "multi byte". */
+ if (dfa->nodes[cur_node].accept_mb)
+ {
+ naccepted = check_node_accept_bytes (dfa, cur_node, &mctx->input,
+ str_idx);
+ if (naccepted > 1)
+ {
+ re_dfastate_t *dest_state;
+ Idx next_node = dfa->nexts[cur_node];
+ Idx next_idx = str_idx + naccepted;
+ dest_state = mctx->state_log[next_idx];
+ re_node_set_empty (&union_set);
+ if (dest_state)
+ {
+ err = re_node_set_merge (&union_set, &dest_state->nodes);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&union_set);
+ return err;
+ }
+ }
+ ok = re_node_set_insert (&union_set, next_node);
+ if (BE (! ok, 0))
+ {
+ re_node_set_free (&union_set);
+ return REG_ESPACE;
+ }
+ mctx->state_log[next_idx] = re_acquire_state (&err, dfa,
+ &union_set);
+ if (BE (mctx->state_log[next_idx] == NULL
+ && err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&union_set);
+ return err;
+ }
+ }
+ }
+#endif /* RE_ENABLE_I18N */
+ if (naccepted
+ || check_node_accept (mctx, dfa->nodes + cur_node, str_idx))
+ {
+ ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]);
+ if (BE (! ok, 0))
+ {
+ re_node_set_free (&union_set);
+ return REG_ESPACE;
+ }
+ }
+ }
+ re_node_set_free (&union_set);
+ return REG_NOERROR;
+}
+
+/* For all the nodes in CUR_NODES, add the epsilon closures of them to
+ CUR_NODES, however exclude the nodes which are:
+ - inside the sub expression whose number is EX_SUBEXP, if FL_OPEN.
+ - out of the sub expression whose number is EX_SUBEXP, if !FL_OPEN.
+*/
+
+static reg_errcode_t
+internal_function
+check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes,
+ Idx ex_subexp, int type)
+{
+ reg_errcode_t err;
+ Idx idx, outside_node;
+ re_node_set new_nodes;
+#ifdef DEBUG
+ assert (cur_nodes->nelem);
+#endif
+ err = re_node_set_alloc (&new_nodes, cur_nodes->nelem);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ /* Create a new node set NEW_NODES with the nodes which are epsilon
+ closures of the node in CUR_NODES. */
+
+ for (idx = 0; idx < cur_nodes->nelem; ++idx)
+ {
+ Idx cur_node = cur_nodes->elems[idx];
+ const re_node_set *eclosure = dfa->eclosures + cur_node;
+ outside_node = find_subexp_node (dfa, eclosure, ex_subexp, type);
+ if (outside_node == REG_MISSING)
+ {
+ /* There are no problematic nodes, just merge them. */
+ err = re_node_set_merge (&new_nodes, eclosure);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&new_nodes);
+ return err;
+ }
+ }
+ else
+ {
+ /* There are problematic nodes, re-calculate incrementally. */
+ err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node,
+ ex_subexp, type);
+ if (BE (err != REG_NOERROR, 0))
+ {
+ re_node_set_free (&new_nodes);
+ return err;
+ }
+ }
+ }
+ re_node_set_free (cur_nodes);
+ *cur_nodes = new_nodes;
+ return REG_NOERROR;
+}
+
+/* Helper function for check_arrival_expand_ecl.
+ Check incrementally the epsilon closure of TARGET, and if it isn't
+ problematic append it to DST_NODES. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes,
+ Idx target, Idx ex_subexp, int type)
+{
+ Idx cur_node;
+ for (cur_node = target; !re_node_set_contains (dst_nodes, cur_node);)
+ {
+ bool ok;
+
+ if (dfa->nodes[cur_node].type == type
+ && dfa->nodes[cur_node].opr.idx == ex_subexp)
+ {
+ if (type == OP_CLOSE_SUBEXP)
+ {
+ ok = re_node_set_insert (dst_nodes, cur_node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ }
+ break;
+ }
+ ok = re_node_set_insert (dst_nodes, cur_node);
+ if (BE (! ok, 0))
+ return REG_ESPACE;
+ if (dfa->edests[cur_node].nelem == 0)
+ break;
+ if (dfa->edests[cur_node].nelem == 2)
+ {
+ reg_errcode_t err;
+ err = check_arrival_expand_ecl_sub (dfa, dst_nodes,
+ dfa->edests[cur_node].elems[1],
+ ex_subexp, type);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ cur_node = dfa->edests[cur_node].elems[0];
+ }
+ return REG_NOERROR;
+}
+
+
+/* For all the back references in the current state, calculate the
+ destination of the back references by the appropriate entry
+ in MCTX->BKREF_ENTS. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes,
+ Idx cur_str, Idx subexp_num, int type)
+{
+ const re_dfa_t *const dfa = mctx->dfa;
+ reg_errcode_t err;
+ Idx cache_idx_start = search_cur_bkref_entry (mctx, cur_str);
+ struct re_backref_cache_entry *ent;
+
+ if (cache_idx_start == REG_MISSING)
+ return REG_NOERROR;
+
+ restart:
+ ent = mctx->bkref_ents + cache_idx_start;
+ do
+ {
+ Idx to_idx, next_node;
+
+ /* Is this entry ENT is appropriate? */
+ if (!re_node_set_contains (cur_nodes, ent->node))
+ continue; /* No. */
+
+ to_idx = cur_str + ent->subexp_to - ent->subexp_from;
+ /* Calculate the destination of the back reference, and append it
+ to MCTX->STATE_LOG. */
+ if (to_idx == cur_str)
+ {
+ /* The backreference did epsilon transit, we must re-check all the
+ node in the current state. */
+ re_node_set new_dests;
+ reg_errcode_t err2, err3;
+ next_node = dfa->edests[ent->node].elems[0];
+ if (re_node_set_contains (cur_nodes, next_node))
+ continue;
+ err = re_node_set_init_1 (&new_dests, next_node);
+ err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type);
+ err3 = re_node_set_merge (cur_nodes, &new_dests);
+ re_node_set_free (&new_dests);
+ if (BE (err != REG_NOERROR || err2 != REG_NOERROR
+ || err3 != REG_NOERROR, 0))
+ {
+ err = (err != REG_NOERROR ? err
+ : (err2 != REG_NOERROR ? err2 : err3));
+ return err;
+ }
+ /* TODO: It is still inefficient... */
+ goto restart;
+ }
+ else
+ {
+ re_node_set union_set;
+ next_node = dfa->nexts[ent->node];
+ if (mctx->state_log[to_idx])
+ {
+ bool ok;
+ if (re_node_set_contains (&mctx->state_log[to_idx]->nodes,
+ next_node))
+ continue;
+ err = re_node_set_init_copy (&union_set,
+ &mctx->state_log[to_idx]->nodes);
+ ok = re_node_set_insert (&union_set, next_node);
+ if (BE (err != REG_NOERROR || ! ok, 0))
+ {
+ re_node_set_free (&union_set);
+ err = err != REG_NOERROR ? err : REG_ESPACE;
+ return err;
+ }
+ }
+ else
+ {
+ err = re_node_set_init_1 (&union_set, next_node);
+ if (BE (err != REG_NOERROR, 0))
+ return err;
+ }
+ mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set);
+ re_node_set_free (&union_set);
+ if (BE (mctx->state_log[to_idx] == NULL
+ && err != REG_NOERROR, 0))
+ return err;
+ }
+ }
+ while (ent++->more);
+ return REG_NOERROR;
+}
+
+/* Build transition table for the state.
+ Return true if successful. */
+
+static bool
+internal_function
+build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
+{
+ reg_errcode_t err;
+ Idx i, j;
+ int ch;
+ bool need_word_trtable = false;
+ bitset_word_t elem, mask;
+ bool dests_node_malloced = false;
+ bool dest_states_malloced = false;
+ Idx ndests; /* Number of the destination states from 'state'. */
+ re_dfastate_t **trtable;
+ re_dfastate_t **dest_states = NULL, **dest_states_word, **dest_states_nl;
+ re_node_set follows, *dests_node;
+ bitset_t *dests_ch;
+ bitset_t acceptable;
+
+ struct dests_alloc
+ {
+ re_node_set dests_node[SBC_MAX];
+ bitset_t dests_ch[SBC_MAX];
+ } *dests_alloc;
+
+ /* We build DFA states which corresponds to the destination nodes
+ from 'state'. 'dests_node[i]' represents the nodes which i-th
+ destination state contains, and 'dests_ch[i]' represents the
+ characters which i-th destination state accepts. */
+ if (__libc_use_alloca (sizeof (struct dests_alloc)))
+ dests_alloc = (struct dests_alloc *) alloca (sizeof (struct dests_alloc));
+ else
+ {
+ dests_alloc = re_malloc (struct dests_alloc, 1);
+ if (BE (dests_alloc == NULL, 0))
+ return false;
+ dests_node_malloced = true;
+ }
+ dests_node = dests_alloc->dests_node;
+ dests_ch = dests_alloc->dests_ch;
+
+ /* Initialize transiton table. */
+ state->word_trtable = state->trtable = NULL;
+
+ /* At first, group all nodes belonging to 'state' into several
+ destinations. */
+ ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch);
+ if (BE (! REG_VALID_NONZERO_INDEX (ndests), 0))
+ {
+ if (dests_node_malloced)
+ free (dests_alloc);
+ if (ndests == 0)
+ {
+ state->trtable = (re_dfastate_t **)
+ calloc (sizeof (re_dfastate_t *), SBC_MAX);
+ if (BE (state->trtable == NULL, 0))
+ return false;
+ return true;
+ }
+ return false;
+ }
+
+ err = re_node_set_alloc (&follows, ndests + 1);
+ if (BE (err != REG_NOERROR, 0))
+ goto out_free;
+
+ /* Avoid arithmetic overflow in size calculation. */
+ if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX)
+ / (3 * sizeof (re_dfastate_t *)))
+ < ndests),
+ 0))
+ goto out_free;
+
+ if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX
+ + ndests * 3 * sizeof (re_dfastate_t *)))
+ dest_states = (re_dfastate_t **)
+ alloca (ndests * 3 * sizeof (re_dfastate_t *));
+ else
+ {
+ dest_states = (re_dfastate_t **)
+ malloc (ndests * 3 * sizeof (re_dfastate_t *));
+ if (BE (dest_states == NULL, 0))
+ {
+out_free:
+ if (dest_states_malloced)
+ free (dest_states);
+ re_node_set_free (&follows);
+ for (i = 0; i < ndests; ++i)
+ re_node_set_free (dests_node + i);
+ if (dests_node_malloced)
+ free (dests_alloc);
+ return false;
+ }
+ dest_states_malloced = true;
+ }
+ dest_states_word = dest_states + ndests;
+ dest_states_nl = dest_states_word + ndests;
+ bitset_empty (acceptable);
+
+ /* Then build the states for all destinations. */
+ for (i = 0; i < ndests; ++i)
+ {
+ Idx next_node;
+ re_node_set_empty (&follows);
+ /* Merge the follows of this destination states. */
+ for (j = 0; j < dests_node[i].nelem; ++j)
+ {
+ next_node = dfa->nexts[dests_node[i].elems[j]];
+ if (next_node != REG_MISSING)
+ {
+ err = re_node_set_merge (&follows, dfa->eclosures + next_node);
+ if (BE (err != REG_NOERROR, 0))
+ goto out_free;
+ }
+ }
+ dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0);
+ if (BE (dest_states[i] == NULL && err != REG_NOERROR, 0))
+ goto out_free;
+ /* If the new state has context constraint,
+ build appropriate states for these contexts. */
+ if (dest_states[i]->has_constraint)
+ {
+ dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows,
+ CONTEXT_WORD);
+ if (BE (dest_states_word[i] == NULL && err != REG_NOERROR, 0))
+ goto out_free;
+
+ if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1)
+ need_word_trtable = true;
+
+ dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows,
+ CONTEXT_NEWLINE);
+ if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0))
+ goto out_free;
+ }
+ else
+ {
+ dest_states_word[i] = dest_states[i];
+ dest_states_nl[i] = dest_states[i];
+ }
+ bitset_merge (acceptable, dests_ch[i]);
+ }
+
+ if (!BE (need_word_trtable, 0))
+ {
+ /* We don't care about whether the following character is a word
+ character, or we are in a single-byte character set so we can
+ discern by looking at the character code: allocate a
+ 256-entry transition table. */
+ trtable = state->trtable =
+ (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
+ if (BE (trtable == NULL, 0))
+ goto out_free;
+
+ /* For all characters ch...: */
+ for (i = 0; i < BITSET_WORDS; ++i)
+ for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
+ elem;
+ mask <<= 1, elem >>= 1, ++ch)
+ if (BE (elem & 1, 0))
+ {
+ /* There must be exactly one destination which accepts
+ character ch. See group_nodes_into_DFAstates. */
+ for (j = 0; (dests_ch[j][i] & mask) == 0; ++j)
+ ;
+
+ /* j-th destination accepts the word character ch. */
+ if (dfa->word_char[i] & mask)
+ trtable[ch] = dest_states_word[j];
+ else
+ trtable[ch] = dest_states[j];
+ }
+ }
+ else
+ {
+ /* We care about whether the following character is a word
+ character, and we are in a multi-byte character set: discern
+ by looking at the character code: build two 256-entry
+ transition tables, one starting at trtable[0] and one
+ starting at trtable[SBC_MAX]. */
+ trtable = state->word_trtable =
+ (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
+ if (BE (trtable == NULL, 0))
+ goto out_free;
+
+ /* For all characters ch...: */
+ for (i = 0; i < BITSET_WORDS; ++i)
+ for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1;
+ elem;
+ mask <<= 1, elem >>= 1, ++ch)
+ if (BE (elem & 1, 0))
+ {
+ /* There must be exactly one destination which accepts
+ character ch. See group_nodes_into_DFAstates. */
+ for (j = 0; (dests_ch[j][i] & mask) == 0; ++j)
+ ;
+
+ /* j-th destination accepts the word character ch. */
+ trtable[ch] = dest_states[j];
+ trtable[ch + SBC_MAX] = dest_states_word[j];
+ }
+ }
+
+ /* new line */
+ if (bitset_contain (acceptable, NEWLINE_CHAR))
+ {
+ /* The current state accepts newline character. */
+ for (j = 0; j < ndests; ++j)
+ if (bitset_contain (dests_ch[j], NEWLINE_CHAR))
+ {
+ /* k-th destination accepts newline character. */
+ trtable[NEWLINE_CHAR] = dest_states_nl[j];
+ if (need_word_trtable)
+ trtable[NEWLINE_CHAR + SBC_MAX] = dest_states_nl[j];
+ /* There must be only one destination which accepts
+ newline. See group_nodes_into_DFAstates. */
+ break;
+ }
+ }
+
+ if (dest_states_malloced)
+ free (dest_states);
+
+ re_node_set_free (&follows);
+ for (i = 0; i < ndests; ++i)
+ re_node_set_free (dests_node + i);
+
+ if (dests_node_malloced)
+ free (dests_alloc);
+
+ return true;
+}
+
+/* Group all nodes belonging to STATE into several destinations.
+ Then for all destinations, set the nodes belonging to the destination
+ to DESTS_NODE[i] and set the characters accepted by the destination
+ to DEST_CH[i]. This function return the number of destinations. */
+
+static Idx
+internal_function
+group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state,
+ re_node_set *dests_node, bitset_t *dests_ch)
+{
+ reg_errcode_t err;
+ bool ok;
+ Idx i, j, k;
+ Idx ndests; /* Number of the destinations from 'state'. */
+ bitset_t accepts; /* Characters a node can accept. */
+ const re_node_set *cur_nodes = &state->nodes;
+ bitset_empty (accepts);
+ ndests = 0;
+
+ /* For all the nodes belonging to 'state', */
+ for (i = 0; i < cur_nodes->nelem; ++i)
+ {
+ re_token_t *node = &dfa->nodes[cur_nodes->elems[i]];
+ re_token_type_t type = node->type;
+ unsigned int constraint = node->constraint;
+
+ /* Enumerate all single byte character this node can accept. */
+ if (type == CHARACTER)
+ bitset_set (accepts, node->opr.c);
+ else if (type == SIMPLE_BRACKET)
+ {
+ bitset_merge (accepts, node->opr.sbcset);
+ }
+ else if (type == OP_PERIOD)
+ {
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ bitset_merge (accepts, dfa->sb_char);
+ else
+#endif
+ bitset_set_all (accepts);
+ if (!(dfa->syntax & RE_DOT_NEWLINE))
+ bitset_clear (accepts, '\n');
+ if (dfa->syntax & RE_DOT_NOT_NULL)
+ bitset_clear (accepts, '\0');
+ }
+#ifdef RE_ENABLE_I18N
+ else if (type == OP_UTF8_PERIOD)
+ {
+ if (ASCII_CHARS % BITSET_WORD_BITS == 0)
+ memset (accepts, -1, ASCII_CHARS / CHAR_BIT);
+ else
+ bitset_merge (accepts, utf8_sb_map);
+ if (!(dfa->syntax & RE_DOT_NEWLINE))
+ bitset_clear (accepts, '\n');
+ if (dfa->syntax & RE_DOT_NOT_NULL)
+ bitset_clear (accepts, '\0');
+ }
+#endif
+ else
+ continue;
+
+ /* Check the 'accepts' and sift the characters which are not
+ match it the context. */
+ if (constraint)
+ {
+ if (constraint & NEXT_NEWLINE_CONSTRAINT)
+ {
+ bool accepts_newline = bitset_contain (accepts, NEWLINE_CHAR);
+ bitset_empty (accepts);
+ if (accepts_newline)
+ bitset_set (accepts, NEWLINE_CHAR);
+ else
+ continue;
+ }
+ if (constraint & NEXT_ENDBUF_CONSTRAINT)
+ {
+ bitset_empty (accepts);
+ continue;
+ }
+
+ if (constraint & NEXT_WORD_CONSTRAINT)
+ {
+ bitset_word_t any_set = 0;
+ if (type == CHARACTER && !node->word_char)
+ {
+ bitset_empty (accepts);
+ continue;
+ }
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= (dfa->word_char[j] | ~dfa->sb_char[j]));
+ else
+#endif
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= dfa->word_char[j]);
+ if (!any_set)
+ continue;
+ }
+ if (constraint & NEXT_NOTWORD_CONSTRAINT)
+ {
+ bitset_word_t any_set = 0;
+ if (type == CHARACTER && node->word_char)
+ {
+ bitset_empty (accepts);
+ continue;
+ }
+#ifdef RE_ENABLE_I18N
+ if (dfa->mb_cur_max > 1)
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= ~(dfa->word_char[j] & dfa->sb_char[j]));
+ else
+#endif
+ for (j = 0; j < BITSET_WORDS; ++j)
+ any_set |= (accepts[j] &= ~dfa->word_char[j]);
+ if (!any_set)
+ continue;
+ }
+ }
+
+ /* Then divide 'accepts' into DFA states, or create a new
+ state. Above, we make sure that accepts is not empty. */
+ for (j = 0; j < ndests; ++j)
+ {
+ bitset_t intersec; /* Intersection sets, see below. */
+ bitset_t remains;
+ /* Flags, see below. */
+ bitset_word_t has_intersec, not_subset, not_consumed;
+
+ /* Optimization, skip if this state doesn't accept the character. */
+ if (type == CHARACTER && !bitset_contain (dests_ch[j], node->opr.c))
+ continue;
+
+ /* Enumerate the intersection set of this state and 'accepts'. */
+ has_intersec = 0;
+ for (k = 0; k < BITSET_WORDS; ++k)
+ has_intersec |= intersec[k] = accepts[k] & dests_ch[j][k];
+ /* And skip if the intersection set is empty. */
+ if (!has_intersec)
+ continue;
+
+ /* Then check if this state is a subset of 'accepts'. */
+ not_subset = not_consumed = 0;
+ for (k = 0; k < BITSET_WORDS; ++k)
+ {
+ not_subset |= remains[k] = ~accepts[k] & dests_ch[j][k];
+ not_consumed |= accepts[k] = accepts[k] & ~dests_ch[j][k];
+ }
+
+ /* If this state isn't a subset of 'accepts', create a
+ new group state, which has the 'remains'. */
+ if (not_subset)
+ {
+ bitset_copy (dests_ch[ndests], remains);
+ bitset_copy (dests_ch[j], intersec);
+ err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]);
+ if (BE (err != REG_NOERROR, 0))
+ goto error_return;
+ ++ndests;
+ }
+
+ /* Put the position in the current group. */
+ ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]);
+ if (BE (! ok, 0))
+ goto error_return;
+
+ /* If all characters are consumed, go to next node. */
+ if (!not_consumed)
+ break;
+ }
+ /* Some characters remain, create a new group. */
+ if (j == ndests)
+ {
+ bitset_copy (dests_ch[ndests], accepts);
+ err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]);
+ if (BE (err != REG_NOERROR, 0))
+ goto error_return;
+ ++ndests;
+ bitset_empty (accepts);
+ }
+ }
+ return ndests;
+ error_return:
+ for (j = 0; j < ndests; ++j)
+ re_node_set_free (dests_node + j);
+ return REG_MISSING;
+}
+
+#ifdef RE_ENABLE_I18N
+/* Check how many bytes the node 'dfa->nodes[node_idx]' accepts.
+ Return the number of the bytes the node accepts.
+ STR_IDX is the current index of the input string.
+
+ This function handles the nodes which can accept one character, or
+ one collating element like '.', '[a-z]', opposite to the other nodes
+ can only accept one byte. */
+
+static int
+internal_function
+check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
+ const re_string_t *input, Idx str_idx)
+{
+ const re_token_t *node = dfa->nodes + node_idx;
+ int char_len, elem_len;
+ Idx i;
+
+ if (BE (node->type == OP_UTF8_PERIOD, 0))
+ {
+ unsigned char c = re_string_byte_at (input, str_idx), d;
+ if (BE (c < 0xc2, 1))
+ return 0;
+
+ if (str_idx + 2 > input->len)
+ return 0;
+
+ d = re_string_byte_at (input, str_idx + 1);
+ if (c < 0xe0)
+ return (d < 0x80 || d > 0xbf) ? 0 : 2;
+ else if (c < 0xf0)
+ {
+ char_len = 3;
+ if (c == 0xe0 && d < 0xa0)
+ return 0;
+ }
+ else if (c < 0xf8)
+ {
+ char_len = 4;
+ if (c == 0xf0 && d < 0x90)
+ return 0;
+ }
+ else if (c < 0xfc)
+ {
+ char_len = 5;
+ if (c == 0xf8 && d < 0x88)
+ return 0;
+ }
+ else if (c < 0xfe)
+ {
+ char_len = 6;
+ if (c == 0xfc && d < 0x84)
+ return 0;
+ }
+ else
+ return 0;
+
+ if (str_idx + char_len > input->len)
+ return 0;
+
+ for (i = 1; i < char_len; ++i)
+ {
+ d = re_string_byte_at (input, str_idx + i);
+ if (d < 0x80 || d > 0xbf)
+ return 0;
+ }
+ return char_len;
+ }
+
+ char_len = re_string_char_size_at (input, str_idx);
+ if (node->type == OP_PERIOD)
+ {
+ if (char_len <= 1)
+ return 0;
+ /* FIXME: I don't think this if is needed, as both '\n'
+ and '\0' are char_len == 1. */
+ /* '.' accepts any one character except the following two cases. */
+ if ((!(dfa->syntax & RE_DOT_NEWLINE) &&
+ re_string_byte_at (input, str_idx) == '\n') ||
+ ((dfa->syntax & RE_DOT_NOT_NULL) &&
+ re_string_byte_at (input, str_idx) == '\0'))
+ return 0;
+ return char_len;
+ }
+
+ elem_len = re_string_elem_size_at (input, str_idx);
+ if ((elem_len <= 1 && char_len <= 1) || char_len == 0)
+ return 0;
+
+ if (node->type == COMPLEX_BRACKET)
+ {
+ const re_charset_t *cset = node->opr.mbcset;
+# ifdef _LIBC
+ const unsigned char *pin
+ = ((const unsigned char *) re_string_get_buffer (input) + str_idx);
+ Idx j;
+ uint32_t nrules;
+# endif /* _LIBC */
+ int match_len = 0;
+ wchar_t wc = ((cset->nranges || cset->nchar_classes || cset->nmbchars)
+ ? re_string_wchar_at (input, str_idx) : 0);
+
+ /* match with multibyte character? */
+ for (i = 0; i < cset->nmbchars; ++i)
+ if (wc == cset->mbchars[i])
+ {
+ match_len = char_len;
+ goto check_node_accept_bytes_match;
+ }
+ /* match with character_class? */
+ for (i = 0; i < cset->nchar_classes; ++i)
+ {
+ wctype_t wt = cset->char_classes[i];
+ if (__iswctype (wc, wt))
+ {
+ match_len = char_len;
+ goto check_node_accept_bytes_match;
+ }
+ }
+
+# ifdef _LIBC
+ nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules != 0)
+ {
+ unsigned int in_collseq = 0;
+ const int32_t *table, *indirect;
+ const unsigned char *weights, *extra;
+ const char *collseqwc;
+ int32_t idx;
+ /* This #include defines a local function! */
+# include <locale/weight.h>
+
+ /* match with collating_symbol? */
+ if (cset->ncoll_syms)
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
+ for (i = 0; i < cset->ncoll_syms; ++i)
+ {
+ const unsigned char *coll_sym = extra + cset->coll_syms[i];
+ /* Compare the length of input collating element and
+ the length of current collating element. */
+ if (*coll_sym != elem_len)
+ continue;
+ /* Compare each bytes. */
+ for (j = 0; j < *coll_sym; j++)
+ if (pin[j] != coll_sym[1 + j])
+ break;
+ if (j == *coll_sym)
+ {
+ /* Match if every bytes is equal. */
+ match_len = j;
+ goto check_node_accept_bytes_match;
+ }
+ }
+
+ if (cset->nranges)
+ {
+ if (elem_len <= char_len)
+ {
+ collseqwc = _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQWC);
+ in_collseq = __collseq_table_lookup (collseqwc, wc);
+ }
+ else
+ in_collseq = find_collation_sequence_value (pin, elem_len);
+ }
+ /* match with range expression? */
+ for (i = 0; i < cset->nranges; ++i)
+ if (cset->range_starts[i] <= in_collseq
+ && in_collseq <= cset->range_ends[i])
+ {
+ match_len = elem_len;
+ goto check_node_accept_bytes_match;
+ }
+
+ /* match with equivalence_class? */
+ if (cset->nequiv_classes)
+ {
+ const unsigned char *cp = pin;
+ table = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEMB);
+ weights = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTMB);
+ extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAMB);
+ indirect = (const int32_t *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
+ int32_t idx = findidx (&cp);
+ if (idx > 0)
+ for (i = 0; i < cset->nequiv_classes; ++i)
+ {
+ int32_t equiv_class_idx = cset->equiv_classes[i];
+ size_t weight_len = weights[idx & 0xffffff];
+ if (weight_len == weights[equiv_class_idx & 0xffffff]
+ && (idx >> 24) == (equiv_class_idx >> 24))
+ {
+ Idx cnt = 0;
+
+ idx &= 0xffffff;
+ equiv_class_idx &= 0xffffff;
+
+ while (cnt <= weight_len
+ && (weights[equiv_class_idx + 1 + cnt]
+ == weights[idx + 1 + cnt]))
+ ++cnt;
+ if (cnt > weight_len)
+ {
+ match_len = elem_len;
+ goto check_node_accept_bytes_match;
+ }
+ }
+ }
+ }
+ }
+ else
+# endif /* _LIBC */
+ {
+ /* match with range expression? */
+#if __GNUC__ >= 2 && ! (__STDC_VERSION__ < 199901L && defined __STRICT_ANSI__)
+ wchar_t cmp_buf[] = {L'\0', L'\0', wc, L'\0', L'\0', L'\0'};
+#else
+ wchar_t cmp_buf[] = {L'\0', L'\0', L'\0', L'\0', L'\0', L'\0'};
+ cmp_buf[2] = wc;
+#endif
+ for (i = 0; i < cset->nranges; ++i)
+ {
+ cmp_buf[0] = cset->range_starts[i];
+ cmp_buf[4] = cset->range_ends[i];
+ if (wcscoll (cmp_buf, cmp_buf + 2) <= 0
+ && wcscoll (cmp_buf + 2, cmp_buf + 4) <= 0)
+ {
+ match_len = char_len;
+ goto check_node_accept_bytes_match;
+ }
+ }
+ }
+ check_node_accept_bytes_match:
+ if (!cset->non_match)
+ return match_len;
+ else
+ {
+ if (match_len > 0)
+ return 0;
+ else
+ return (elem_len > char_len) ? elem_len : char_len;
+ }
+ }
+ return 0;
+}
+
+# ifdef _LIBC
+static unsigned int
+internal_function
+find_collation_sequence_value (const unsigned char *mbs, size_t mbs_len)
+{
+ uint32_t nrules = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
+ if (nrules == 0)
+ {
+ if (mbs_len == 1)
+ {
+ /* No valid character. Match it as a single byte character. */
+ const unsigned char *collseq = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_COLLSEQMB);
+ return collseq[mbs[0]];
+ }
+ return UINT_MAX;
+ }
+ else
+ {
+ int32_t idx;
+ const unsigned char *extra = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
+ int32_t extrasize = (const unsigned char *)
+ _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB + 1) - extra;
+
+ for (idx = 0; idx < extrasize;)
+ {
+ int mbs_cnt;
+ bool found = false;
+ int32_t elem_mbs_len;
+ /* Skip the name of collating element name. */
+ idx = idx + extra[idx] + 1;
+ elem_mbs_len = extra[idx++];
+ if (mbs_len == elem_mbs_len)
+ {
+ for (mbs_cnt = 0; mbs_cnt < elem_mbs_len; ++mbs_cnt)
+ if (extra[idx + mbs_cnt] != mbs[mbs_cnt])
+ break;
+ if (mbs_cnt == elem_mbs_len)
+ /* Found the entry. */
+ found = true;
+ }
+ /* Skip the byte sequence of the collating element. */
+ idx += elem_mbs_len;
+ /* Adjust for the alignment. */
+ idx = (idx + 3) & ~3;
+ /* Skip the collation sequence value. */
+ idx += sizeof (uint32_t);
+ /* Skip the wide char sequence of the collating element. */
+ idx = idx + sizeof (uint32_t) * (extra[idx] + 1);
+ /* If we found the entry, return the sequence value. */
+ if (found)
+ return *(uint32_t *) (extra + idx);
+ /* Skip the collation sequence value. */
+ idx += sizeof (uint32_t);
+ }
+ return UINT_MAX;
+ }
+}
+# endif /* _LIBC */
+#endif /* RE_ENABLE_I18N */
+
+/* Check whether the node accepts the byte which is IDX-th
+ byte of the INPUT. */
+
+static bool
+internal_function
+check_node_accept (const re_match_context_t *mctx, const re_token_t *node,
+ Idx idx)
+{
+ unsigned char ch;
+ ch = re_string_byte_at (&mctx->input, idx);
+ switch (node->type)
+ {
+ case CHARACTER:
+ if (node->opr.c != ch)
+ return false;
+ break;
+
+ case SIMPLE_BRACKET:
+ if (!bitset_contain (node->opr.sbcset, ch))
+ return false;
+ break;
+
+#ifdef RE_ENABLE_I18N
+ case OP_UTF8_PERIOD:
+ if (ch >= ASCII_CHARS)
+ return false;
+ /* FALLTHROUGH */
+#endif
+ case OP_PERIOD:
+ if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE))
+ || (ch == '\0' && (mctx->dfa->syntax & RE_DOT_NOT_NULL)))
+ return false;
+ break;
+
+ default:
+ return false;
+ }
+
+ if (node->constraint)
+ {
+ /* The node has constraints. Check whether the current context
+ satisfies the constraints. */
+ unsigned int context = re_string_context_at (&mctx->input, idx,
+ mctx->eflags);
+ if (NOT_SATISFY_NEXT_CONSTRAINT (node->constraint, context))
+ return false;
+ }
+
+ return true;
+}
+
+/* Extend the buffers, if the buffers have run out. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+extend_buffers (re_match_context_t *mctx)
+{
+ reg_errcode_t ret;
+ re_string_t *pstr = &mctx->input;
+
+ /* Avoid overflow. */
+ if (BE (SIZE_MAX / 2 / sizeof (re_dfastate_t *) <= pstr->bufs_len, 0))
+ return REG_ESPACE;
+
+ /* Double the lengthes of the buffers. */
+ ret = re_string_realloc_buffers (pstr, pstr->bufs_len * 2);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+
+ if (mctx->state_log != NULL)
+ {
+ /* And double the length of state_log. */
+ /* XXX We have no indication of the size of this buffer. If this
+ allocation fail we have no indication that the state_log array
+ does not have the right size. */
+ re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *,
+ pstr->bufs_len + 1);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ mctx->state_log = new_array;
+ }
+
+ /* Then reconstruct the buffers. */
+ if (pstr->icase)
+ {
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ {
+ ret = build_wcs_upper_buffer (pstr);
+ if (BE (ret != REG_NOERROR, 0))
+ return ret;
+ }
+ else
+#endif /* RE_ENABLE_I18N */
+ build_upper_buffer (pstr);
+ }
+ else
+ {
+#ifdef RE_ENABLE_I18N
+ if (pstr->mb_cur_max > 1)
+ build_wcs_buffer (pstr);
+ else
+#endif /* RE_ENABLE_I18N */
+ {
+ if (pstr->trans != NULL)
+ re_string_translate_buffer (pstr);
+ }
+ }
+ return REG_NOERROR;
+}
+
+
+/* Functions for matching context. */
+
+/* Initialize MCTX. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+match_ctx_init (re_match_context_t *mctx, int eflags, Idx n)
+{
+ mctx->eflags = eflags;
+ mctx->match_last = REG_MISSING;
+ if (n > 0)
+ {
+ /* Avoid overflow. */
+ size_t max_object_size =
+ MAX (sizeof (struct re_backref_cache_entry),
+ sizeof (re_sub_match_top_t *));
+ if (BE (SIZE_MAX / max_object_size < n, 0))
+ return REG_ESPACE;
+
+ mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n);
+ mctx->sub_tops = re_malloc (re_sub_match_top_t *, n);
+ if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0))
+ return REG_ESPACE;
+ }
+ /* Already zero-ed by the caller.
+ else
+ mctx->bkref_ents = NULL;
+ mctx->nbkref_ents = 0;
+ mctx->nsub_tops = 0; */
+ mctx->abkref_ents = n;
+ mctx->max_mb_elem_len = 1;
+ mctx->asub_tops = n;
+ return REG_NOERROR;
+}
+
+/* Clean the entries which depend on the current input in MCTX.
+ This function must be invoked when the matcher changes the start index
+ of the input, or changes the input string. */
+
+static void
+internal_function
+match_ctx_clean (re_match_context_t *mctx)
+{
+ Idx st_idx;
+ for (st_idx = 0; st_idx < mctx->nsub_tops; ++st_idx)
+ {
+ Idx sl_idx;
+ re_sub_match_top_t *top = mctx->sub_tops[st_idx];
+ for (sl_idx = 0; sl_idx < top->nlasts; ++sl_idx)
+ {
+ re_sub_match_last_t *last = top->lasts[sl_idx];
+ re_free (last->path.array);
+ re_free (last);
+ }
+ re_free (top->lasts);
+ if (top->path)
+ {
+ re_free (top->path->array);
+ re_free (top->path);
+ }
+ free (top);
+ }
+
+ mctx->nsub_tops = 0;
+ mctx->nbkref_ents = 0;
+}
+
+/* Free all the memory associated with MCTX. */
+
+static void
+internal_function
+match_ctx_free (re_match_context_t *mctx)
+{
+ /* First, free all the memory associated with MCTX->SUB_TOPS. */
+ match_ctx_clean (mctx);
+ re_free (mctx->sub_tops);
+ re_free (mctx->bkref_ents);
+}
+
+/* Add a new backreference entry to MCTX.
+ Note that we assume that caller never call this function with duplicate
+ entry, and call with STR_IDX which isn't smaller than any existing entry.
+*/
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from,
+ Idx to)
+{
+ if (mctx->nbkref_ents >= mctx->abkref_ents)
+ {
+ struct re_backref_cache_entry* new_entry;
+ new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry,
+ mctx->abkref_ents * 2);
+ if (BE (new_entry == NULL, 0))
+ {
+ re_free (mctx->bkref_ents);
+ return REG_ESPACE;
+ }
+ mctx->bkref_ents = new_entry;
+ memset (mctx->bkref_ents + mctx->nbkref_ents, '\0',
+ sizeof (struct re_backref_cache_entry) * mctx->abkref_ents);
+ mctx->abkref_ents *= 2;
+ }
+ if (mctx->nbkref_ents > 0
+ && mctx->bkref_ents[mctx->nbkref_ents - 1].str_idx == str_idx)
+ mctx->bkref_ents[mctx->nbkref_ents - 1].more = 1;
+
+ mctx->bkref_ents[mctx->nbkref_ents].node = node;
+ mctx->bkref_ents[mctx->nbkref_ents].str_idx = str_idx;
+ mctx->bkref_ents[mctx->nbkref_ents].subexp_from = from;
+ mctx->bkref_ents[mctx->nbkref_ents].subexp_to = to;
+
+ /* This is a cache that saves negative results of check_dst_limits_calc_pos.
+ If bit N is clear, means that this entry won't epsilon-transition to
+ an OP_OPEN_SUBEXP or OP_CLOSE_SUBEXP for the N+1-th subexpression. If
+ it is set, check_dst_limits_calc_pos_1 will recurse and try to find one
+ such node.
+
+ A backreference does not epsilon-transition unless it is empty, so set
+ to all zeros if FROM != TO. */
+ mctx->bkref_ents[mctx->nbkref_ents].eps_reachable_subexps_map
+ = (from == to ? -1 : 0);
+
+ mctx->bkref_ents[mctx->nbkref_ents++].more = 0;
+ if (mctx->max_mb_elem_len < to - from)
+ mctx->max_mb_elem_len = to - from;
+ return REG_NOERROR;
+}
+
+/* Return the first entry with the same str_idx, or REG_MISSING if none is
+ found. Note that MCTX->BKREF_ENTS is already sorted by MCTX->STR_IDX. */
+
+static Idx
+internal_function
+search_cur_bkref_entry (const re_match_context_t *mctx, Idx str_idx)
+{
+ Idx left, right, mid, last;
+ last = right = mctx->nbkref_ents;
+ for (left = 0; left < right;)
+ {
+ mid = (left + right) / 2;
+ if (mctx->bkref_ents[mid].str_idx < str_idx)
+ left = mid + 1;
+ else
+ right = mid;
+ }
+ if (left < last && mctx->bkref_ents[left].str_idx == str_idx)
+ return left;
+ else
+ return REG_MISSING;
+}
+
+/* Register the node NODE, whose type is OP_OPEN_SUBEXP, and which matches
+ at STR_IDX. */
+
+static reg_errcode_t
+internal_function __attribute_warn_unused_result__
+match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx)
+{
+#ifdef DEBUG
+ assert (mctx->sub_tops != NULL);
+ assert (mctx->asub_tops > 0);
+#endif
+ if (BE (mctx->nsub_tops == mctx->asub_tops, 0))
+ {
+ Idx new_asub_tops = mctx->asub_tops * 2;
+ re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops,
+ re_sub_match_top_t *,
+ new_asub_tops);
+ if (BE (new_array == NULL, 0))
+ return REG_ESPACE;
+ mctx->sub_tops = new_array;
+ mctx->asub_tops = new_asub_tops;
+ }
+ mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t));
+ if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0))
+ return REG_ESPACE;
+ mctx->sub_tops[mctx->nsub_tops]->node = node;
+ mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx;
+ return REG_NOERROR;
+}
+
+/* Register the node NODE, whose type is OP_CLOSE_SUBEXP, and which matches
+ at STR_IDX, whose corresponding OP_OPEN_SUBEXP is SUB_TOP. */
+
+static re_sub_match_last_t *
+internal_function
+match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx)
+{
+ re_sub_match_last_t *new_entry;
+ if (BE (subtop->nlasts == subtop->alasts, 0))
+ {
+ Idx new_alasts = 2 * subtop->alasts + 1;
+ re_sub_match_last_t **new_array = re_realloc (subtop->lasts,
+ re_sub_match_last_t *,
+ new_alasts);
+ if (BE (new_array == NULL, 0))
+ return NULL;
+ subtop->lasts = new_array;
+ subtop->alasts = new_alasts;
+ }
+ new_entry = calloc (1, sizeof (re_sub_match_last_t));
+ if (BE (new_entry != NULL, 1))
+ {
+ subtop->lasts[subtop->nlasts] = new_entry;
+ new_entry->node = node;
+ new_entry->str_idx = str_idx;
+ ++subtop->nlasts;
+ }
+ return new_entry;
+}
+
+static void
+internal_function
+sift_ctx_init (re_sift_context_t *sctx, re_dfastate_t **sifted_sts,
+ re_dfastate_t **limited_sts, Idx last_node, Idx last_str_idx)
+{
+ sctx->sifted_states = sifted_sts;
+ sctx->limited_states = limited_sts;
+ sctx->last_node = last_node;
+ sctx->last_str_idx = last_str_idx;
+ re_node_set_init_empty (&sctx->limits);
+}
diff --git a/lib/strcasecmp.c b/lib/strcasecmp.c
new file mode 100644
index 000000000..1ed517531
--- /dev/null
+++ b/lib/strcasecmp.c
@@ -0,0 +1,63 @@
+/* Case-insensitive string comparison function.
+ Copyright (C) 1998-1999, 2005-2007, 2009-2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include <string.h>
+
+#include <ctype.h>
+#include <limits.h>
+
+#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
+
+/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
+ greater than zero if S1 is lexicographically less than, equal to or greater
+ than S2.
+ Note: This function does not work with multibyte strings! */
+
+int
+strcasecmp (const char *s1, const char *s2)
+{
+ const unsigned char *p1 = (const unsigned char *) s1;
+ const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+
+ if (p1 == p2)
+ return 0;
+
+ do
+ {
+ c1 = TOLOWER (*p1);
+ c2 = TOLOWER (*p2);
+
+ if (c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ }
+ while (c1 == c2);
+
+ if (UCHAR_MAX <= INT_MAX)
+ return c1 - c2;
+ else
+ /* On machines where 'char' and 'int' are types of the same size, the
+ difference of two 'unsigned char' values - including the sign bit -
+ doesn't fit in an 'int'. */
+ return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
+}
diff --git a/lib/streq.h b/lib/streq.h
new file mode 100644
index 000000000..b64941116
--- /dev/null
+++ b/lib/streq.h
@@ -0,0 +1,176 @@
+/* Optimized string comparison.
+ Copyright (C) 2001-2002, 2007, 2009-2012 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>. */
+
+#ifndef _GL_STREQ_H
+#define _GL_STREQ_H
+
+#include <string.h>
+
+/* STREQ allows to optimize string comparison with a small literal string.
+ STREQ (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
+ is semantically equivalent to
+ strcmp (s, "EUC-KR") == 0
+ just faster. */
+
+/* Help GCC to generate good code for string comparisons with
+ immediate strings. */
+#if defined (__GNUC__) && defined (__OPTIMIZE__)
+
+static inline int
+streq9 (const char *s1, const char *s2)
+{
+ return strcmp (s1 + 9, s2 + 9) == 0;
+}
+
+static inline int
+streq8 (const char *s1, const char *s2, char s28)
+{
+ if (s1[8] == s28)
+ {
+ if (s28 == 0)
+ return 1;
+ else
+ return streq9 (s1, s2);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq7 (const char *s1, const char *s2, char s27, char s28)
+{
+ if (s1[7] == s27)
+ {
+ if (s27 == 0)
+ return 1;
+ else
+ return streq8 (s1, s2, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq6 (const char *s1, const char *s2, char s26, char s27, char s28)
+{
+ if (s1[6] == s26)
+ {
+ if (s26 == 0)
+ return 1;
+ else
+ return streq7 (s1, s2, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
+{
+ if (s1[5] == s25)
+ {
+ if (s25 == 0)
+ return 1;
+ else
+ return streq6 (s1, s2, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[4] == s24)
+ {
+ if (s24 == 0)
+ return 1;
+ else
+ return streq5 (s1, s2, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[3] == s23)
+ {
+ if (s23 == 0)
+ return 1;
+ else
+ return streq4 (s1, s2, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[2] == s22)
+ {
+ if (s22 == 0)
+ return 1;
+ else
+ return streq3 (s1, s2, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[1] == s21)
+ {
+ if (s21 == 0)
+ return 1;
+ else
+ return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+static inline int
+streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
+{
+ if (s1[0] == s20)
+ {
+ if (s20 == 0)
+ return 1;
+ else
+ return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
+ }
+ else
+ return 0;
+}
+
+#define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+ streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
+
+#else
+
+#define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
+ (strcmp (s1, s2) == 0)
+
+#endif
+
+#endif /* _GL_STREQ_H */
diff --git a/lib/strings.in.h b/lib/strings.in.h
new file mode 100644
index 000000000..fc60919b7
--- /dev/null
+++ b/lib/strings.in.h
@@ -0,0 +1,123 @@
+/* A substitute <strings.h>.
+
+ Copyright (C) 2007-2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#ifndef _@GUARD_PREFIX@_STRINGS_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* Minix 3.1.8 has a bug: <sys/types.h> must be included before <strings.h>.
+ But avoid namespace pollution on glibc systems. */
+#if defined __minix && !defined __GLIBC__
+# include <sys/types.h>
+#endif
+
+/* The include_next requires a split double-inclusion guard. */
+#if @HAVE_STRINGS_H@
+# @INCLUDE_NEXT@ @NEXT_STRINGS_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_STRINGS_H
+#define _@GUARD_PREFIX@_STRINGS_H
+
+#if ! @HAVE_DECL_STRNCASECMP@
+/* Get size_t. */
+# include <stddef.h>
+#endif
+
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+
+/* The definition of _GL_ARG_NONNULL is copied here. */
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+ /* Find the index of the least-significant set bit. */
+#if @GNULIB_FFS@
+# if !@HAVE_FFS@
+_GL_FUNCDECL_SYS (ffs, int, (int i));
+# endif
+_GL_CXXALIAS_SYS (ffs, int, (int i));
+_GL_CXXALIASWARN (ffs);
+#elif defined GNULIB_POSIXCHECK
+# undef ffs
+# if HAVE_RAW_DECL_FFS
+_GL_WARN_ON_USE (ffs, "ffs is not portable - use the ffs module");
+# endif
+#endif
+
+/* Compare strings S1 and S2, ignoring case, returning less than, equal to or
+ greater than zero if S1 is lexicographically less than, equal to or greater
+ than S2.
+ Note: This function does not work in multibyte locales. */
+#if ! @HAVE_STRCASECMP@
+extern int strcasecmp (char const *s1, char const *s2)
+ _GL_ARG_NONNULL ((1, 2));
+#endif
+#if defined GNULIB_POSIXCHECK
+/* strcasecmp() does not work with multibyte strings:
+ POSIX says that it operates on "strings", and "string" in POSIX is defined
+ as a sequence of bytes, not of characters. */
+# undef strcasecmp
+# if HAVE_RAW_DECL_STRCASECMP
+_GL_WARN_ON_USE (strcasecmp, "strcasecmp cannot work correctly on character "
+ "strings in multibyte locales - "
+ "use mbscasecmp if you care about "
+ "internationalization, or use c_strcasecmp , "
+ "gnulib module c-strcase) if you want a locale "
+ "independent function");
+# endif
+#endif
+
+/* Compare no more than N bytes of strings S1 and S2, ignoring case,
+ returning less than, equal to or greater than zero if S1 is
+ lexicographically less than, equal to or greater than S2.
+ Note: This function cannot work correctly in multibyte locales. */
+#if ! @HAVE_DECL_STRNCASECMP@
+extern int strncasecmp (char const *s1, char const *s2, size_t n)
+ _GL_ARG_NONNULL ((1, 2));
+#endif
+#if defined GNULIB_POSIXCHECK
+/* strncasecmp() does not work with multibyte strings:
+ POSIX says that it operates on "strings", and "string" in POSIX is defined
+ as a sequence of bytes, not of characters. */
+# undef strncasecmp
+# if HAVE_RAW_DECL_STRNCASECMP
+_GL_WARN_ON_USE (strncasecmp, "strncasecmp cannot work correctly on character "
+ "strings in multibyte locales - "
+ "use mbsncasecmp or mbspcasecmp if you care about "
+ "internationalization, or use c_strncasecmp , "
+ "gnulib module c-strcase) if you want a locale "
+ "independent function");
+# endif
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _@GUARD_PREFIX@_STRING_H */
+#endif /* _@GUARD_PREFIX@_STRING_H */
diff --git a/lib/strncasecmp.c b/lib/strncasecmp.c
new file mode 100644
index 000000000..d330ff678
--- /dev/null
+++ b/lib/strncasecmp.c
@@ -0,0 +1,63 @@
+/* strncasecmp.c -- case insensitive string comparator
+ Copyright (C) 1998-1999, 2005-2007, 2009-2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include <string.h>
+
+#include <ctype.h>
+#include <limits.h>
+
+#define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
+
+/* Compare no more than N bytes of strings S1 and S2, ignoring case,
+ returning less than, equal to or greater than zero if S1 is
+ lexicographically less than, equal to or greater than S2.
+ Note: This function cannot work correctly in multibyte locales. */
+
+int
+strncasecmp (const char *s1, const char *s2, size_t n)
+{
+ register const unsigned char *p1 = (const unsigned char *) s1;
+ register const unsigned char *p2 = (const unsigned char *) s2;
+ unsigned char c1, c2;
+
+ if (p1 == p2 || n == 0)
+ return 0;
+
+ do
+ {
+ c1 = TOLOWER (*p1);
+ c2 = TOLOWER (*p2);
+
+ if (--n == 0 || c1 == '\0')
+ break;
+
+ ++p1;
+ ++p2;
+ }
+ while (c1 == c2);
+
+ if (UCHAR_MAX <= INT_MAX)
+ return c1 - c2;
+ else
+ /* On machines where 'char' and 'int' are types of the same size, the
+ difference of two 'unsigned char' values - including the sign bit -
+ doesn't fit in an 'int'. */
+ return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
+}
diff --git a/lib/wcrtomb.c b/lib/wcrtomb.c
new file mode 100644
index 000000000..a4d6bcdbd
--- /dev/null
+++ b/lib/wcrtomb.c
@@ -0,0 +1,53 @@
+/* Convert wide character to multibyte character.
+ Copyright (C) 2008-2012 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <wchar.h>
+
+#include <errno.h>
+#include <stdlib.h>
+
+
+size_t
+wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
+{
+ /* This implementation of wcrtomb on top of wctomb() supports only
+ stateless encodings. ps must be in the initial state. */
+ if (ps != NULL && !mbsinit (ps))
+ {
+ errno = EINVAL;
+ return (size_t)(-1);
+ }
+
+ if (s == NULL)
+ /* We know the NUL wide character corresponds to the NUL character. */
+ return 1;
+ else
+ {
+ int ret = wctomb (s, wc);
+
+ if (ret >= 0)
+ return ret;
+ else
+ {
+ errno = EILSEQ;
+ return (size_t)(-1);
+ }
+ }
+}
diff --git a/lib/wctype.in.h b/lib/wctype.in.h
new file mode 100644
index 000000000..f25ad30e2
--- /dev/null
+++ b/lib/wctype.in.h
@@ -0,0 +1,499 @@
+/* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
+
+ Copyright (C) 2006-2012 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+/* Written by Bruno Haible and Paul Eggert. */
+
+/*
+ * ISO C 99 <wctype.h> for platforms that lack it.
+ * <http://www.opengroup.org/susv3xbd/wctype.h.html>
+ *
+ * iswctype, towctrans, towlower, towupper, wctrans, wctype,
+ * wctrans_t, and wctype_t are not yet implemented.
+ */
+
+#ifndef _@GUARD_PREFIX@_WCTYPE_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+#if @HAVE_WINT_T@
+/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
+ Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+# include <stddef.h>
+# include <stdio.h>
+# include <time.h>
+# include <wchar.h>
+#endif
+
+/* Include the original <wctype.h> if it exists.
+ BeOS 5 has the functions but no <wctype.h>. */
+/* The include_next requires a split double-inclusion guard. */
+#if @HAVE_WCTYPE_H@
+# @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_WCTYPE_H
+#define _@GUARD_PREFIX@_WCTYPE_H
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
+
+/* The definition of _GL_WARN_ON_USE is copied here. */
+
+/* Solaris 2.6 <wctype.h> includes <widec.h> which includes <euc.h> which
+ #defines a number of identifiers in the application namespace. Revert
+ these #defines. */
+#ifdef __sun
+# undef multibyte
+# undef eucw1
+# undef eucw2
+# undef eucw3
+# undef scrw1
+# undef scrw2
+# undef scrw3
+#endif
+
+/* Define wint_t and WEOF. (Also done in wchar.in.h.) */
+#if !@HAVE_WINT_T@ && !defined wint_t
+# define wint_t int
+# ifndef WEOF
+# define WEOF -1
+# endif
+#else
+/* MSVC defines wint_t as 'unsigned short' in <crtdefs.h>.
+ This is too small: ISO C 99 section 7.24.1.(2) says that wint_t must be
+ "unchanged by default argument promotions". Override it. */
+# if defined _MSC_VER
+# if !GNULIB_defined_wint_t
+# include <crtdefs.h>
+typedef unsigned int rpl_wint_t;
+# undef wint_t
+# define wint_t rpl_wint_t
+# define GNULIB_defined_wint_t 1
+# endif
+# endif
+# ifndef WEOF
+# define WEOF ((wint_t) -1)
+# endif
+#endif
+
+
+#if !GNULIB_defined_wctype_functions
+
+/* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
+ Linux libc5 has <wctype.h> and the functions but they are broken.
+ Assume all 11 functions (all isw* except iswblank) are implemented the
+ same way, or not at all. */
+# if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
+
+/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
+ undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
+ refer to system functions like _iswctype that are not in the
+ standard C library. Rather than try to get ancient buggy
+ implementations like this to work, just disable them. */
+# undef iswalnum
+# undef iswalpha
+# undef iswblank
+# undef iswcntrl
+# undef iswdigit
+# undef iswgraph
+# undef iswlower
+# undef iswprint
+# undef iswpunct
+# undef iswspace
+# undef iswupper
+# undef iswxdigit
+# undef towlower
+# undef towupper
+
+/* Linux libc5 has <wctype.h> and the functions but they are broken. */
+# if @REPLACE_ISWCNTRL@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define iswalnum rpl_iswalnum
+# define iswalpha rpl_iswalpha
+# define iswblank rpl_iswblank
+# define iswcntrl rpl_iswcntrl
+# define iswdigit rpl_iswdigit
+# define iswgraph rpl_iswgraph
+# define iswlower rpl_iswlower
+# define iswprint rpl_iswprint
+# define iswpunct rpl_iswpunct
+# define iswspace rpl_iswspace
+# define iswupper rpl_iswupper
+# define iswxdigit rpl_iswxdigit
+# endif
+# endif
+# if @REPLACE_TOWLOWER@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define towlower rpl_towlower
+# define towupper rpl_towupper
+# endif
+# endif
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswalnum
+# else
+iswalnum
+# endif
+ (wint_t wc)
+{
+ return ((wc >= '0' && wc <= '9')
+ || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswalpha
+# else
+iswalpha
+# endif
+ (wint_t wc)
+{
+ return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswblank
+# else
+iswblank
+# endif
+ (wint_t wc)
+{
+ return wc == ' ' || wc == '\t';
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswcntrl
+# else
+iswcntrl
+# endif
+ (wint_t wc)
+{
+ return (wc & ~0x1f) == 0 || wc == 0x7f;
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswdigit
+# else
+iswdigit
+# endif
+ (wint_t wc)
+{
+ return wc >= '0' && wc <= '9';
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswgraph
+# else
+iswgraph
+# endif
+ (wint_t wc)
+{
+ return wc >= '!' && wc <= '~';
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswlower
+# else
+iswlower
+# endif
+ (wint_t wc)
+{
+ return wc >= 'a' && wc <= 'z';
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswprint
+# else
+iswprint
+# endif
+ (wint_t wc)
+{
+ return wc >= ' ' && wc <= '~';
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswpunct
+# else
+iswpunct
+# endif
+ (wint_t wc)
+{
+ return (wc >= '!' && wc <= '~'
+ && !((wc >= '0' && wc <= '9')
+ || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswspace
+# else
+iswspace
+# endif
+ (wint_t wc)
+{
+ return (wc == ' ' || wc == '\t'
+ || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswupper
+# else
+iswupper
+# endif
+ (wint_t wc)
+{
+ return wc >= 'A' && wc <= 'Z';
+}
+
+static inline int
+# if @REPLACE_ISWCNTRL@
+rpl_iswxdigit
+# else
+iswxdigit
+# endif
+ (wint_t wc)
+{
+ return ((wc >= '0' && wc <= '9')
+ || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
+}
+
+static inline wint_t
+# if @REPLACE_TOWLOWER@
+rpl_towlower
+# else
+towlower
+# endif
+ (wint_t wc)
+{
+ return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
+}
+
+static inline wint_t
+# if @REPLACE_TOWLOWER@
+rpl_towupper
+# else
+towupper
+# endif
+ (wint_t wc)
+{
+ return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
+}
+
+# elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
+/* Only the iswblank function is missing. */
+
+# if @REPLACE_ISWBLANK@
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define iswblank rpl_iswblank
+# endif
+_GL_FUNCDECL_RPL (iswblank, int, (wint_t wc));
+# else
+_GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
+# endif
+
+# endif
+
+# if defined __MINGW32__
+
+/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
+ The functions towlower and towupper are implemented in the MSVCRT library
+ to take a wchar_t argument and return a wchar_t result. mingw declares
+ these functions to take a wint_t argument and return a wint_t result.
+ This means that:
+ 1. When the user passes an argument outside the range 0x0000..0xFFFF, the
+ function will look only at the lower 16 bits. This is allowed according
+ to POSIX.
+ 2. The return value is returned in the lower 16 bits of the result register.
+ The upper 16 bits are random: whatever happened to be in that part of the
+ result register. We need to fix this by adding a zero-extend from
+ wchar_t to wint_t after the call. */
+
+static inline wint_t
+rpl_towlower (wint_t wc)
+{
+ return (wint_t) (wchar_t) towlower (wc);
+}
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define towlower rpl_towlower
+# endif
+
+static inline wint_t
+rpl_towupper (wint_t wc)
+{
+ return (wint_t) (wchar_t) towupper (wc);
+}
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# define towupper rpl_towupper
+# endif
+
+# endif /* __MINGW32__ */
+
+# define GNULIB_defined_wctype_functions 1
+#endif
+
+#if @REPLACE_ISWCNTRL@
+_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
+_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
+#else
+_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
+_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
+#endif
+_GL_CXXALIASWARN (iswalnum);
+_GL_CXXALIASWARN (iswalpha);
+_GL_CXXALIASWARN (iswcntrl);
+_GL_CXXALIASWARN (iswdigit);
+_GL_CXXALIASWARN (iswgraph);
+_GL_CXXALIASWARN (iswlower);
+_GL_CXXALIASWARN (iswprint);
+_GL_CXXALIASWARN (iswpunct);
+_GL_CXXALIASWARN (iswspace);
+_GL_CXXALIASWARN (iswupper);
+_GL_CXXALIASWARN (iswxdigit);
+
+#if @GNULIB_ISWBLANK@
+# if @REPLACE_ISWCNTRL@ || @REPLACE_ISWBLANK@
+_GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
+# else
+_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
+# endif
+_GL_CXXALIASWARN (iswblank);
+#endif
+
+#if !@HAVE_WCTYPE_T@
+# if !GNULIB_defined_wctype_t
+typedef void * wctype_t;
+# define GNULIB_defined_wctype_t 1
+# endif
+#endif
+
+/* Get a descriptor for a wide character property. */
+#if @GNULIB_WCTYPE@
+# if !@HAVE_WCTYPE_T@
+_GL_FUNCDECL_SYS (wctype, wctype_t, (const char *name));
+# endif
+_GL_CXXALIAS_SYS (wctype, wctype_t, (const char *name));
+_GL_CXXALIASWARN (wctype);
+#elif defined GNULIB_POSIXCHECK
+# undef wctype
+# if HAVE_RAW_DECL_WCTYPE
+_GL_WARN_ON_USE (wctype, "wctype is unportable - "
+ "use gnulib module wctype for portability");
+# endif
+#endif
+
+/* Test whether a wide character has a given property.
+ The argument WC must be either a wchar_t value or WEOF.
+ The argument DESC must have been returned by the wctype() function. */
+#if @GNULIB_ISWCTYPE@
+# if !@HAVE_WCTYPE_T@
+_GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc));
+# endif
+_GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc));
+_GL_CXXALIASWARN (iswctype);
+#elif defined GNULIB_POSIXCHECK
+# undef iswctype
+# if HAVE_RAW_DECL_ISWCTYPE
+_GL_WARN_ON_USE (iswctype, "iswctype is unportable - "
+ "use gnulib module iswctype for portability");
+# endif
+#endif
+
+#if @REPLACE_TOWLOWER@ || defined __MINGW32__
+_GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
+_GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
+#else
+_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
+_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
+#endif
+_GL_CXXALIASWARN (towlower);
+_GL_CXXALIASWARN (towupper);
+
+#if !@HAVE_WCTRANS_T@
+# if !GNULIB_defined_wctrans_t
+typedef void * wctrans_t;
+# define GNULIB_defined_wctrans_t 1
+# endif
+#endif
+
+/* Get a descriptor for a wide character case conversion. */
+#if @GNULIB_WCTRANS@
+# if !@HAVE_WCTRANS_T@
+_GL_FUNCDECL_SYS (wctrans, wctrans_t, (const char *name));
+# endif
+_GL_CXXALIAS_SYS (wctrans, wctrans_t, (const char *name));
+_GL_CXXALIASWARN (wctrans);
+#elif defined GNULIB_POSIXCHECK
+# undef wctrans
+# if HAVE_RAW_DECL_WCTRANS
+_GL_WARN_ON_USE (wctrans, "wctrans is unportable - "
+ "use gnulib module wctrans for portability");
+# endif
+#endif
+
+/* Perform a given case conversion on a wide character.
+ The argument WC must be either a wchar_t value or WEOF.
+ The argument DESC must have been returned by the wctrans() function. */
+#if @GNULIB_TOWCTRANS@
+# if !@HAVE_WCTRANS_T@
+_GL_FUNCDECL_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
+# endif
+_GL_CXXALIAS_SYS (towctrans, wint_t, (wint_t wc, wctrans_t desc));
+_GL_CXXALIASWARN (towctrans);
+#elif defined GNULIB_POSIXCHECK
+# undef towctrans
+# if HAVE_RAW_DECL_TOWCTRANS
+_GL_WARN_ON_USE (towctrans, "towctrans is unportable - "
+ "use gnulib module towctrans for portability");
+# endif
+#endif
+
+
+#endif /* _@GUARD_PREFIX@_WCTYPE_H */
+#endif /* _@GUARD_PREFIX@_WCTYPE_H */
diff --git a/libguile/alist.c b/libguile/alist.c
index 799e9f10e..82c70a03c 100644
--- a/libguile/alist.c
+++ b/libguile/alist.c
@@ -255,9 +255,9 @@ SCM_DEFINE (scm_assq_set_x, "assq-set!", 3, 0, 0,
(SCM alist, SCM key, SCM val),
"@deffnx {Scheme Procedure} assv-set! alist key value\n"
"@deffnx {Scheme Procedure} assoc-set! alist key value\n"
- "Reassociate @var{key} in @var{alist} with @var{value}: find any existing\n"
+ "Reassociate @var{key} in @var{alist} with @var{val}: find any existing\n"
"@var{alist} entry for @var{key} and associate it with the new\n"
- "@var{value}. If @var{alist} does not contain an entry for @var{key},\n"
+ "@var{val}. If @var{alist} does not contain an entry for @var{key},\n"
"add a new one. Return the (possibly new) alist.\n\n"
"These functions do not attempt to verify the structure of @var{alist},\n"
"and so may cause unusual results if passed an object that is not an\n"
diff --git a/libguile/array-map.c b/libguile/array-map.c
index acd167da6..c0f0f00bc 100644
--- a/libguile/array-map.c
+++ b/libguile/array-map.c
@@ -320,8 +320,8 @@ scm_ramapc (void *cproc_ptr, SCM data, SCM ra0, SCM lra, const char *what)
SCM_DEFINE (scm_array_fill_x, "array-fill!", 2, 0, 0,
(SCM ra, SCM fill),
- "Store @var{fill} in every element of @var{array}. The value returned\n"
- "is unspecified.")
+ "Store @var{fill} in every element of array @var{ra}. The value\n"
+ "returned is unspecified.")
#define FUNC_NAME s_scm_array_fill_x
{
scm_ramapc (scm_array_fill_int, fill, ra, SCM_EOL, FUNC_NAME);
@@ -374,9 +374,9 @@ SCM_REGISTER_PROC(s_array_copy_in_order_x, "array-copy-in-order!", 2, 0, 0, scm_
SCM_DEFINE (scm_array_copy_x, "array-copy!", 2, 0, 0,
(SCM src, SCM dst),
"@deffnx {Scheme Procedure} array-copy-in-order! src dst\n"
- "Copy every element from vector or array @var{source} to the\n"
- "corresponding element of @var{destination}. @var{destination} must have\n"
- "the same rank as @var{source}, and be at least as large in each\n"
+ "Copy every element from vector or array @var{src} to the\n"
+ "corresponding element of @var{dst}. @var{dst} must have the\n"
+ "same rank as @var{src}, and be at least as large in each\n"
"dimension. The order is unspecified.")
#define FUNC_NAME s_scm_array_copy_x
{
@@ -670,12 +670,13 @@ SCM_SYMBOL (sym_b, "b");
SCM_DEFINE (scm_array_map_x, "array-map!", 2, 0, 1,
(SCM ra0, SCM proc, SCM lra),
"@deffnx {Scheme Procedure} array-map-in-order! ra0 proc . lra\n"
- "@var{array1}, @dots{} must have the same number of dimensions as\n"
- "@var{array0} and have a range for each index which includes the range\n"
- "for the corresponding index in @var{array0}. @var{proc} is applied to\n"
- "each tuple of elements of @var{array1} @dots{} and the result is stored\n"
- "as the corresponding element in @var{array0}. The value returned is\n"
- "unspecified. The order of application is unspecified.")
+ "@var{array1}, @dots{} must have the same number of dimensions\n"
+ "as @var{ra0} and have a range for each index which includes the\n"
+ "range for the corresponding index in @var{ra0}. @var{proc} is\n"
+ "applied to each tuple of elements of @var{array1}, @dots{} and\n"
+ "the result is stored as the corresponding element in @var{ra0}.\n"
+ "The value returned is unspecified. The order of application is\n"
+ "unspecified.")
#define FUNC_NAME s_scm_array_map_x
{
SCM_VALIDATE_PROC (2, proc);
@@ -722,7 +723,7 @@ rafe (SCM ra0, SCM proc, SCM ras)
SCM_DEFINE (scm_array_for_each, "array-for-each", 2, 0, 1,
(SCM proc, SCM ra0, SCM lra),
- "Apply @var{proc} to each tuple of elements of @var{array0} @dots{}\n"
+ "Apply @var{proc} to each tuple of elements of @var{ra0} @dots{}\n"
"in row-major order. The value returned is unspecified.")
#define FUNC_NAME s_scm_array_for_each
{
@@ -735,7 +736,7 @@ SCM_DEFINE (scm_array_for_each, "array-for-each", 2, 0, 1,
SCM_DEFINE (scm_array_index_map_x, "array-index-map!", 2, 0, 0,
(SCM ra, SCM proc),
- "Apply @var{proc} to the indices of each element of @var{array} in\n"
+ "Apply @var{proc} to the indices of each element of @var{ra} in\n"
"turn, storing the result in the corresponding element. The value\n"
"returned and the order of application are unspecified.\n\n"
"One can implement @var{array-indexes} as\n"
diff --git a/libguile/arrays.c b/libguile/arrays.c
index 935d6f363..f0f901239 100644
--- a/libguile/arrays.c
+++ b/libguile/arrays.c
@@ -326,11 +326,12 @@ scm_i_ra_set_contp (SCM ra)
SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
(SCM oldra, SCM mapfunc, SCM dims),
- "@code{make-shared-array} can be used to create shared subarrays of other\n"
- "arrays. The @var{mapper} is a function that translates coordinates in\n"
- "the new array into coordinates in the old array. A @var{mapper} must be\n"
- "linear, and its range must stay within the bounds of the old array, but\n"
- "it can be otherwise arbitrary. A simple example:\n"
+ "@code{make-shared-array} can be used to create shared subarrays\n"
+ "of other arrays. The @var{mapfunc} is a function that\n"
+ "translates coordinates in the new array into coordinates in the\n"
+ "old array. A @var{mapfunc} must be linear, and its range must\n"
+ "stay within the bounds of the old array, but it can be\n"
+ "otherwise arbitrary. A simple example:\n"
"@lisp\n"
"(define fred (make-array #f 8 8))\n"
"(define freds-diagonal\n"
@@ -444,18 +445,18 @@ SCM_DEFINE (scm_make_shared_array, "make-shared-array", 2, 0, 1,
/* args are RA . DIMS */
SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
(SCM ra, SCM args),
- "Return an array sharing contents with @var{array}, but with\n"
+ "Return an array sharing contents with @var{ra}, but with\n"
"dimensions arranged in a different order. There must be one\n"
- "@var{dim} argument for each dimension of @var{array}.\n"
+ "@var{dim} argument for each dimension of @var{ra}.\n"
"@var{dim0}, @var{dim1}, @dots{} should be integers between 0\n"
"and the rank of the array to be returned. Each integer in that\n"
"range must appear at least once in the argument list.\n"
"\n"
"The values of @var{dim0}, @var{dim1}, @dots{} correspond to\n"
"dimensions in the array to be returned, their positions in the\n"
- "argument list to dimensions of @var{array}. Several @var{dim}s\n"
+ "argument list to dimensions of @var{ra}. Several @var{dim}s\n"
"may have the same value, in which case the returned array will\n"
- "have smaller rank than @var{array}.\n"
+ "have smaller rank than @var{ra}.\n"
"\n"
"@lisp\n"
"(transpose-array '#2((a b) (c d)) 1 0) @result{} #2((a c) (b d))\n"
@@ -546,15 +547,15 @@ SCM_DEFINE (scm_transpose_array, "transpose-array", 1, 0, 1,
wouldn't have contiguous elements. */
SCM_DEFINE (scm_array_contents, "array-contents", 1, 1, 0,
(SCM ra, SCM strict),
- "If @var{array} may be @dfn{unrolled} into a one dimensional shared array\n"
- "without changing their order (last subscript changing fastest), then\n"
- "@code{array-contents} returns that shared array, otherwise it returns\n"
- "@code{#f}. All arrays made by @var{make-array} and\n"
- "@var{make-uniform-array} may be unrolled, some arrays made by\n"
- "@var{make-shared-array} may not be.\n\n"
- "If the optional argument @var{strict} is provided, a shared array will\n"
- "be returned only if its elements are stored internally contiguous in\n"
- "memory.")
+ "If @var{ra} may be @dfn{unrolled} into a one dimensional shared\n"
+ "array without changing their order (last subscript changing\n"
+ "fastest), then @code{array-contents} returns that shared array,\n"
+ "otherwise it returns @code{#f}. All arrays made by\n"
+ "@code{make-array} and @code{make-uniform-array} may be unrolled,\n"
+ "some arrays made by @code{make-shared-array} may not be. If\n"
+ "the optional argument @var{strict} is provided, a shared array\n"
+ "will be returned only if its elements are stored internally\n"
+ "contiguous in memory.")
#define FUNC_NAME s_scm_array_contents
{
SCM sra;
diff --git a/libguile/bitvectors.c b/libguile/bitvectors.c
index bc273a3b1..ffea6d182 100644
--- a/libguile/bitvectors.c
+++ b/libguile/bitvectors.c
@@ -497,7 +497,7 @@ SCM_DEFINE (scm_bit_position, "bit-position", 3, 0, 0,
"Return the index of the first occurrence of @var{item} in bit\n"
"vector @var{v}, starting from @var{k}. If there is no\n"
"@var{item} entry between @var{k} and the end of\n"
- "@var{bitvector}, then return @code{#f}. For example,\n"
+ "@var{v}, then return @code{#f}. For example,\n"
"\n"
"@example\n"
"(bit-position #t #*000101 0) @result{} 3\n"
diff --git a/libguile/continuations.c b/libguile/continuations.c
index 86627703c..058e21e88 100644
--- a/libguile/continuations.c
+++ b/libguile/continuations.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995,1996,1998,2000,2001,2004, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,2000,2001,2004, 2006, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -71,36 +71,35 @@ static scm_t_bits tc16_continuation;
#define META_HEADER(meta) meta, 0, 0, 0, 0, 0, 0, 0
#endif
-#define ALIGN_PTR(type,p,align) (type*)(ROUND_UP (((scm_t_bits)p), align))
+#define OBJCODE_TAG SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_STATIC, 0)
-#ifdef SCM_ALIGNED
+#if defined (SCM_ALIGNED) && 0
#define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym) \
static const type sym[]
#define SCM_STATIC_ALIGNED_ARRAY(alignment, type, sym) \
static SCM_ALIGNED (alignment) const type sym[]
-#else
-#define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym) \
-static type *sym
-#define SCM_STATIC_ALIGNED_ARRAY(alignment, type, sym) \
-SCM_SNARF_INIT(sym = scm_malloc_pointerless (sizeof(sym##__unaligned)); \
- memcpy (sym, sym##__unaligned, sizeof(sym##__unaligned));) \
-static type *sym = NULL; \
-static const type sym##__unaligned[]
-#endif
-
-#define STATIC_OBJCODE_TAG \
- SCM_PACK (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_STATIC, 0))
-
#define SCM_STATIC_OBJCODE(sym) \
SCM_DECLARE_STATIC_ALIGNED_ARRAY (scm_t_uint8, sym##__bytecode); \
SCM_STATIC_ALIGNED_ARRAY (8, scm_t_cell, sym##__cells) = { \
- { STATIC_OBJCODE_TAG, SCM_PACK (sym##__bytecode) }, \
+ { SCM_PACK (OBJCODE_TAG), SCM_PACK (sym##__bytecode) }, \
{ SCM_BOOL_F, SCM_PACK (0) } \
}; \
static const SCM sym = SCM_PACK (sym##__cells); \
SCM_STATIC_ALIGNED_ARRAY (8, scm_t_uint8, sym##__bytecode)
+#else
+#define SCM_STATIC_OBJCODE(sym) \
+static SCM sym; \
+static scm_t_uint8 *sym##_bytecode; \
+SCM_SNARF_INIT(sym##_bytecode = scm_gc_malloc_pointerless (sizeof(sym##_bytecode__unaligned), "partial continuation stub"); \
+ memcpy (sym##_bytecode, sym##_bytecode__unaligned, sizeof(sym##_bytecode__unaligned));) \
+SCM_SNARF_INIT(sym = scm_double_cell (OBJCODE_TAG, \
+ (scm_t_bits)sym##_bytecode, \
+ SCM_UNPACK (SCM_BOOL_F), \
+ 0);) \
+static const scm_t_uint8 sym##_bytecode__unaligned[]
+#endif
+
-
SCM_STATIC_OBJCODE (cont_objcode) = {
/* This code is the same as in gsubr.c, except we use continuation_call
instead of subr_call. */
diff --git a/libguile/control.c b/libguile/control.c
index 6302c0750..ff6bfd89a 100644
--- a/libguile/control.c
+++ b/libguile/control.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -81,36 +81,35 @@ scm_i_prompt_pop_abort_args_x (SCM vm)
#define META_HEADER(meta) meta, 0, 0, 0, 0, 0, 0, 0
#endif
-#define ALIGN_PTR(type,p,align) (type*)(ROUND_UP (((scm_t_bits)p), align))
+#define OBJCODE_TAG SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_STATIC, 0)
-#ifdef SCM_ALIGNED
+#if defined (SCM_ALIGNED)
#define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym) \
static const type sym[]
#define SCM_STATIC_ALIGNED_ARRAY(alignment, type, sym) \
static SCM_ALIGNED (alignment) const type sym[]
-#else
-#define SCM_DECLARE_STATIC_ALIGNED_ARRAY(type, sym) \
-static type *sym
-#define SCM_STATIC_ALIGNED_ARRAY(alignment, type, sym) \
-SCM_SNARF_INIT(sym = scm_malloc_pointerless (sizeof(sym##__unaligned); \
- memcpy (sym, sym##__unaligned, sizeof(sym##__unaligned));) \
-static type *sym = NULL; \
-static const type sym##__unaligned[]
-#endif
-
-#define STATIC_OBJCODE_TAG \
- SCM_PACK (SCM_MAKE_OBJCODE_TAG (SCM_OBJCODE_TYPE_STATIC, 0))
-
#define SCM_STATIC_OBJCODE(sym) \
SCM_DECLARE_STATIC_ALIGNED_ARRAY (scm_t_uint8, sym##__bytecode); \
SCM_STATIC_ALIGNED_ARRAY (8, scm_t_cell, sym##__cells) = { \
- { STATIC_OBJCODE_TAG, SCM_PACK (sym##__bytecode) }, \
+ { SCM_PACK (OBJCODE_TAG), SCM_PACK (sym##__bytecode) }, \
{ SCM_BOOL_F, SCM_PACK (0) } \
}; \
static const SCM sym = SCM_PACK (sym##__cells); \
SCM_STATIC_ALIGNED_ARRAY (8, scm_t_uint8, sym##__bytecode)
+#else
+#define SCM_STATIC_OBJCODE(sym) \
+static SCM sym; \
+static scm_t_uint8 *sym##_bytecode; \
+SCM_SNARF_INIT(sym##_bytecode = scm_gc_malloc_pointerless (sizeof(sym##_bytecode__unaligned), "partial continuation stub"); \
+ memcpy (sym##_bytecode, sym##_bytecode__unaligned, sizeof(sym##_bytecode__unaligned));) \
+SCM_SNARF_INIT(sym = scm_double_cell (OBJCODE_TAG, \
+ (scm_t_bits)sym##_bytecode, \
+ SCM_UNPACK (SCM_BOOL_F), \
+ 0);) \
+static const scm_t_uint8 sym##_bytecode__unaligned[]
+#endif
+
-
SCM_STATIC_OBJCODE (cont_objcode) = {
/* Like in continuations.c, but with partial-cont-call. */
OBJCODE_HEADER (8, 19),
diff --git a/libguile/error.c b/libguile/error.c
index b4ed7d055..790ed0571 100644
--- a/libguile/error.c
+++ b/libguile/error.c
@@ -1,5 +1,6 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2004, 2006, 2010 Free Software Foundation, Inc.
- *
+/* Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2004, 2006, 2010,
+ * 2012 Free Software Foundation, Inc.
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of
@@ -99,7 +100,7 @@ SCM_DEFINE (scm_error_scm, "scm-error", 5, 0, 0,
}
#undef FUNC_NAME
-#ifdef __MINGW32__
+#if defined __MINGW32__ && defined HAVE_NETWORKING
# include "win32-socket.h"
# define SCM_I_STRERROR(err) \
((err >= WSABASEERR) ? scm_i_socket_strerror (err) : strerror (err))
diff --git a/libguile/filesys.c b/libguile/filesys.c
index 63e5a206b..a45a56488 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -465,7 +465,7 @@ static int fstat_Win32 (int fdes, struct stat *buf)
SCM_DEFINE (scm_stat, "stat", 1, 1, 0,
(SCM object, SCM exception_on_error),
"Return an object containing various information about the file\n"
- "determined by @var{obj}. @var{obj} can be a string containing\n"
+ "determined by @var{object}. @var{object} can be a string containing\n"
"a file name or a port or integer file descriptor which is open\n"
"on a file (in which case @code{fstat} is used as the underlying\n"
"system call).\n"
@@ -586,7 +586,7 @@ SCM_DEFINE (scm_lstat, "lstat", 1, 0, 0,
(SCM str),
"Similar to @code{stat}, but does not follow symbolic links, i.e.,\n"
"it will return information about a symbolic link itself, not the\n"
- "file it points to. @var{path} must be a string.")
+ "file it points to. @var{str} must be a string.")
#define FUNC_NAME s_scm_lstat
{
int rv;
@@ -640,7 +640,7 @@ SCM_DEFINE (scm_link, "link", 2, 0, 0,
SCM_DEFINE (scm_chdir, "chdir", 1, 0, 0,
(SCM str),
- "Change the current working directory to @var{path}.\n"
+ "Change the current working directory to @var{str}.\n"
"The return value is unspecified.")
#define FUNC_NAME s_scm_chdir
{
@@ -942,10 +942,10 @@ SCM_DEFINE (scm_select, "select", 3, 2, 0,
#ifdef HAVE_FCNTL
SCM_DEFINE (scm_fcntl, "fcntl", 2, 1, 0,
(SCM object, SCM cmd, SCM value),
- "Apply @var{command} to the specified file descriptor or the underlying\n"
+ "Apply @var{cmd} to the specified file descriptor or the underlying\n"
"file descriptor of the specified port. @var{value} is an optional\n"
"integer argument.\n\n"
- "Values for @var{command} are:\n\n"
+ "Values for @var{cmd} are:\n\n"
"@table @code\n"
"@item F_DUPFD\n"
"Duplicate a file descriptor\n"
@@ -993,9 +993,9 @@ SCM_DEFINE (scm_fcntl, "fcntl", 2, 1, 0,
SCM_DEFINE (scm_fsync, "fsync", 1, 0, 0,
(SCM object),
- "Copies any unwritten data for the specified output file descriptor to disk.\n"
- "If @var{port/fd} is a port, its buffer is flushed before the underlying\n"
- "file descriptor is fsync'd.\n"
+ "Copies any unwritten data for the specified output file\n"
+ "descriptor to disk. If @var{object} is a port, its buffer is\n"
+ "flushed before the underlying file descriptor is fsync'd.\n"
"The return value is unspecified.")
#define FUNC_NAME s_scm_fsync
{
@@ -1020,8 +1020,9 @@ SCM_DEFINE (scm_fsync, "fsync", 1, 0, 0,
#ifdef HAVE_SYMLINK
SCM_DEFINE (scm_symlink, "symlink", 2, 0, 0,
(SCM oldpath, SCM newpath),
- "Create a symbolic link named @var{path-to} with the value (i.e., pointing to)\n"
- "@var{path-from}. The return value is unspecified.")
+ "Create a symbolic link named @var{oldpath} with the value\n"
+ "(i.e., pointing to) @var{newpath}. The return value is\n"
+ "unspecified.")
#define FUNC_NAME s_scm_symlink
{
int val;
@@ -1079,7 +1080,7 @@ SCM_DEFINE (scm_readlink, "readlink", 1, 0, 0,
SCM_DEFINE (scm_copy_file, "copy-file", 2, 0, 0,
(SCM oldfile, SCM newfile),
- "Copy the file specified by @var{path-from} to @var{path-to}.\n"
+ "Copy the file specified by @var{oldfile} to @var{newfile}.\n"
"The return value is unspecified.")
#define FUNC_NAME s_scm_copy_file
{
@@ -1257,7 +1258,7 @@ SCM_DEFINE (scm_rename, "rename-file", 2, 0, 0,
SCM_DEFINE (scm_delete_file, "delete-file", 1, 0, 0,
(SCM str),
- "Deletes (or \"unlinks\") the file specified by @var{path}.")
+ "Deletes (or \"unlinks\") the file specified by @var{str}.")
#define FUNC_NAME s_scm_delete_file
{
int ans;
@@ -1325,12 +1326,12 @@ SCM_DEFINE (scm_access, "access?", 2, 0, 0,
SCM_DEFINE (scm_chmod, "chmod", 2, 0, 0,
(SCM object, SCM mode),
- "Changes the permissions of the file referred to by @var{obj}.\n"
- "@var{obj} can be a string containing a file name or a port or integer file\n"
- "descriptor which is open on a file (in which case @code{fchmod} is used\n"
- "as the underlying system call).\n"
- "@var{mode} specifies\n"
- "the new permissions as a decimal number, e.g., @code{(chmod \"foo\" #o755)}.\n"
+ "Changes the permissions of the file referred to by\n"
+ "@var{object}. @var{object} can be a string containing a file\n"
+ "name or a port or integer file descriptor which is open on a\n"
+ "file (in which case @code{fchmod} is used as the underlying\n"
+ "system call). @var{mode} specifies the new permissions as a\n"
+ "decimal number, e.g., @code{(chmod \"foo\" #o755)}.\n"
"The return value is unspecified.")
#define FUNC_NAME s_scm_chmod
{
@@ -1488,7 +1489,7 @@ SCM_DEFINE (scm_basename, "basename", 1, 1, 0,
"Return the base name of the file name @var{filename}. The\n"
"base name is the file name without any directory components.\n"
"If @var{suffix} is provided, and is equal to the end of\n"
- "@var{basename}, it is removed also.")
+ "@var{filename}, it is removed also.")
#define FUNC_NAME s_scm_basename
{
int i, j, len, end;
@@ -1625,7 +1626,7 @@ scm_t_bits scm_tc16_dir;
SCM_DEFINE (scm_directory_stream_p, "directory-stream?", 1, 0, 0,
(SCM obj),
- "Return a boolean indicating whether @var{object} is a directory\n"
+ "Return a boolean indicating whether @var{obj} is a directory\n"
"stream as returned by @code{opendir}.")
#define FUNC_NAME s_scm_directory_stream_p
{
@@ -1636,7 +1637,7 @@ SCM_DEFINE (scm_directory_stream_p, "directory-stream?", 1, 0, 0,
SCM_DEFINE (scm_opendir, "opendir", 1, 0, 0,
(SCM dirname),
- "Open the directory specified by @var{path} and return a directory\n"
+ "Open the directory specified by @var{dirname} and return a directory\n"
"stream.")
#define FUNC_NAME s_scm_opendir
{
@@ -1658,7 +1659,7 @@ SCM_DEFINE (scm_opendir, "opendir", 1, 0, 0,
SCM_DEFINE (scm_readdir, "readdir", 1, 0, 0,
(SCM port),
"Return (as a string) the next directory entry from the directory stream\n"
- "@var{stream}. If there is no remaining entry to be read then the\n"
+ "@var{port}. If there is no remaining entry to be read then the\n"
"end of file object is returned.")
#define FUNC_NAME s_scm_readdir
{
@@ -1732,7 +1733,7 @@ SCM_DEFINE (scm_readdir, "readdir", 1, 0, 0,
SCM_DEFINE (scm_rewinddir, "rewinddir", 1, 0, 0,
(SCM port),
- "Reset the directory port @var{stream} so that the next call to\n"
+ "Reset the directory port @var{port} so that the next call to\n"
"@code{readdir} will return the first directory entry.")
#define FUNC_NAME s_scm_rewinddir
{
@@ -1749,7 +1750,7 @@ SCM_DEFINE (scm_rewinddir, "rewinddir", 1, 0, 0,
SCM_DEFINE (scm_closedir, "closedir", 1, 0, 0,
(SCM port),
- "Close the directory stream @var{stream}.\n"
+ "Close the directory stream @var{port}.\n"
"The return value is unspecified.")
#define FUNC_NAME s_scm_closedir
{
diff --git a/libguile/foreign.c b/libguile/foreign.c
index 41c3e7e82..33df96386 100644
--- a/libguile/foreign.c
+++ b/libguile/foreign.c
@@ -136,6 +136,15 @@ SCM_DEFINE (scm_make_pointer, "make-pointer", 1, 1, 0,
}
#undef FUNC_NAME
+void *
+scm_to_pointer (SCM pointer)
+#define FUNC_NAME "scm_to_pointer"
+{
+ SCM_VALIDATE_POINTER (1, pointer);
+ return SCM_POINTER_VALUE (pointer);
+}
+#undef FUNC_NAME
+
SCM
scm_from_pointer (void *ptr, scm_t_pointer_finalizer finalizer)
{
@@ -1138,11 +1147,11 @@ invoke_closure (ffi_cif *cif, void *ret, void **args, void *data)
SCM_DEFINE (scm_procedure_to_pointer, "procedure->pointer", 3, 0, 0,
(SCM return_type, SCM proc, SCM arg_types),
- "Return a pointer to a C function of type @var{return-type}\n"
- "taking arguments of types @var{arg-types} (a list) and\n"
+ "Return a pointer to a C function of type @var{return_type}\n"
+ "taking arguments of types @var{arg_types} (a list) and\n"
"behaving as a proxy to procedure @var{proc}. Thus\n"
"@var{proc}'s arity, supported argument types, and return\n"
- "type should match @var{return-type} and @var{arg-types}.\n")
+ "type should match @var{return_type} and @var{arg_types}.\n")
#define FUNC_NAME s_scm_procedure_to_pointer
{
SCM cif_pointer, pointer;
diff --git a/libguile/foreign.h b/libguile/foreign.h
index eac4ca048..172fa24e3 100644
--- a/libguile/foreign.h
+++ b/libguile/foreign.h
@@ -1,7 +1,7 @@
#ifndef SCM_FOREIGN_H
#define SCM_FOREIGN_H
-/* Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -23,8 +23,7 @@
/* A "foreign pointer" is a wrapped C pointer. It is represented by a
cell whose second word is a pointer. The first word has the
- `scm_tc7_pointer' type code and a bit saying whether it has an
- associated finalizer or not.
+ `scm_tc7_pointer' type code.
The basic idea is that we can help the programmer to avoid cutting herself,
but we won't take away her knives. */
@@ -55,6 +54,7 @@ typedef void (*scm_t_pointer_finalizer) (void *);
#define SCM_POINTER_VALUE(x) \
((void *) SCM_CELL_WORD_1 (x))
+SCM_API void *scm_to_pointer (SCM pointer);
SCM_API SCM scm_from_pointer (void *, scm_t_pointer_finalizer);
SCM_API SCM scm_alignof (SCM type);
diff --git a/libguile/gc-malloc.c b/libguile/gc-malloc.c
index 5c230dd1f..179558fe1 100644
--- a/libguile/gc-malloc.c
+++ b/libguile/gc-malloc.c
@@ -1,5 +1,5 @@
/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
- * 2004, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ * 2004, 2006, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -77,6 +77,49 @@ extern unsigned long * __libc_ia64_register_backing_store_base;
+
+static void*
+do_realloc (void *from, size_t new_size)
+{
+ scm_gc_register_allocation (new_size);
+ return realloc (from, new_size);
+}
+
+static void*
+do_calloc (size_t n, size_t size)
+{
+ scm_gc_register_allocation (size);
+ return calloc (n, size);
+}
+
+static void*
+do_gc_malloc (size_t size, const char *what)
+{
+ /* Ensure nonzero size to be compatible with always-nonzero return of
+ glibc malloc. */
+ return GC_MALLOC (size ? size : sizeof (void *));
+}
+
+static void*
+do_gc_malloc_atomic (size_t size, const char *what)
+{
+ return GC_MALLOC_ATOMIC (size ? size : sizeof (void *));
+}
+
+static void*
+do_gc_realloc (void *from, size_t size, const char *what)
+{
+ return GC_REALLOC (from, size ? size : sizeof (void *));
+}
+
+static void
+do_gc_free (void *ptr)
+{
+ GC_FREE (ptr);
+}
+
+
+
/* Function for non-cell memory management.
*/
@@ -85,10 +128,9 @@ scm_realloc (void *mem, size_t size)
{
void *ptr;
- scm_gc_register_allocation (size);
+ ptr = do_realloc (mem, size);
- SCM_SYSCALL (ptr = realloc (mem, size));
- if (ptr)
+ if (ptr || size == 0)
return ptr;
/* Time is hard: trigger a full, ``stop-the-world'' GC, and try again. */
@@ -98,7 +140,7 @@ scm_realloc (void *mem, size_t size)
GC_gcollect ();
#endif
- SCM_SYSCALL (ptr = realloc (mem, size));
+ ptr = do_realloc (mem, size);
if (ptr)
return ptr;
@@ -124,8 +166,8 @@ scm_calloc (size_t sz)
By default, try to use calloc, as it is likely more efficient than
calling memset by hand.
*/
- SCM_SYSCALL (ptr = calloc (sz, 1));
- if (ptr)
+ ptr = do_calloc (sz, 1);
+ if (ptr || sz == 0)
return ptr;
ptr = scm_realloc (NULL, sz);
@@ -180,57 +222,38 @@ scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what)
void *
scm_gc_malloc_pointerless (size_t size, const char *what)
{
- return GC_MALLOC_ATOMIC (size);
+ return do_gc_malloc_atomic (size, what);
}
void *
scm_gc_malloc (size_t size, const char *what)
{
- void *ptr;
-
- if (size == 0)
- /* `GC_MALLOC ()' doesn't handle zero. */
- size = sizeof (void *);
-
- ptr = GC_MALLOC (size);
-
- return ptr;
+ return do_gc_malloc (size, what);
}
void *
scm_gc_calloc (size_t size, const char *what)
{
/* `GC_MALLOC ()' always returns a zeroed buffer. */
- return scm_gc_malloc (size, what);
+ return do_gc_malloc (size, what);
}
-
void *
scm_gc_realloc (void *mem, size_t old_size, size_t new_size, const char *what)
{
- void *ptr;
-
- ptr = GC_REALLOC (mem, new_size);
-
-#ifdef GUILE_DEBUG_MALLOC
- if (mem)
- scm_malloc_reregister (mem, ptr, what);
-#endif
-
- return ptr;
+ return do_gc_realloc (mem, new_size, what);
}
void
scm_gc_free (void *mem, size_t size, const char *what)
{
- scm_gc_unregister_collectable_memory (mem, size, what);
- GC_FREE (mem);
+ do_gc_free (mem);
}
char *
scm_gc_strndup (const char *str, size_t n, const char *what)
{
- char *dst = GC_MALLOC_ATOMIC (n + 1);
+ char *dst = do_gc_malloc_atomic (n + 1, what);
memcpy (dst, str, n);
dst[n] = 0;
return dst;
diff --git a/libguile/generalized-arrays.c b/libguile/generalized-arrays.c
index a04b5faa1..3a0ce25c7 100644
--- a/libguile/generalized-arrays.c
+++ b/libguile/generalized-arrays.c
@@ -198,7 +198,7 @@ SCM_DEFINE (scm_array_in_bounds_p, "array-in-bounds?", 1, 0, 1,
SCM_DEFINE (scm_array_ref, "array-ref", 1, 0, 1,
(SCM v, SCM args),
"Return the element at the @code{(index1, index2)} element in\n"
- "@var{array}.")
+ "array @var{v}.")
#define FUNC_NAME s_scm_array_ref
{
scm_t_array_handle handle;
@@ -214,8 +214,9 @@ SCM_DEFINE (scm_array_ref, "array-ref", 1, 0, 1,
SCM_DEFINE (scm_array_set_x, "array-set!", 2, 0, 1,
(SCM v, SCM obj, SCM args),
- "Set the element at the @code{(index1, index2)} element in @var{array} to\n"
- "@var{new-value}. The value returned by array-set! is unspecified.")
+ "Set the element at the @code{(index1, index2)} element in array\n"
+ "@var{v} to @var{obj}. The value returned by @code{array-set!}\n"
+ "is unspecified.")
#define FUNC_NAME s_scm_array_set_x
{
scm_t_array_handle handle;
diff --git a/libguile/hashtab.c b/libguile/hashtab.c
index e6406429e..d01df763b 100644
--- a/libguile/hashtab.c
+++ b/libguile/hashtab.c
@@ -404,7 +404,7 @@ SCM_DEFINE (scm_hashq_ref, "hashq-ref", 2, 1, 0,
(SCM table, SCM key, SCM dflt),
"Look up @var{key} in the hash table @var{table}, and return the\n"
"value (if any) associated with it. If @var{key} is not found,\n"
- "return @var{default} (or @code{#f} if no @var{default} argument\n"
+ "return @var{dflt} (or @code{#f} if no @var{dflt} argument\n"
"is supplied). Uses @code{eq?} for equality testing.")
#define FUNC_NAME s_scm_hashq_ref
{
@@ -426,7 +426,7 @@ SCM_DEFINE (scm_hashq_ref, "hashq-ref", 2, 1, 0,
SCM_DEFINE (scm_hashq_set_x, "hashq-set!", 3, 0, 0,
(SCM table, SCM key, SCM val),
"Find the entry in @var{table} associated with @var{key}, and\n"
- "store @var{value} there. Uses @code{eq?} for equality testing.")
+ "store @var{val} there. Uses @code{eq?} for equality testing.")
#define FUNC_NAME s_scm_hashq_set_x
{
if (SCM_WEAK_TABLE_P (table))
@@ -501,7 +501,7 @@ SCM_DEFINE (scm_hashv_ref, "hashv-ref", 2, 1, 0,
(SCM table, SCM key, SCM dflt),
"Look up @var{key} in the hash table @var{table}, and return the\n"
"value (if any) associated with it. If @var{key} is not found,\n"
- "return @var{default} (or @code{#f} if no @var{default} argument\n"
+ "return @var{dflt} (or @code{#f} if no @var{dflt} argument\n"
"is supplied). Uses @code{eqv?} for equality testing.")
#define FUNC_NAME s_scm_hashv_ref
{
@@ -606,7 +606,7 @@ SCM_DEFINE (scm_hash_ref, "hash-ref", 2, 1, 0,
(SCM table, SCM key, SCM dflt),
"Look up @var{key} in the hash table @var{table}, and return the\n"
"value (if any) associated with it. If @var{key} is not found,\n"
- "return @var{default} (or @code{#f} if no @var{default} argument\n"
+ "return @var{dflt} (or @code{#f} if no @var{dflt} argument\n"
"is supplied). Uses @code{equal?} for equality testing.")
#define FUNC_NAME s_scm_hash_ref
{
@@ -629,7 +629,7 @@ SCM_DEFINE (scm_hash_ref, "hash-ref", 2, 1, 0,
SCM_DEFINE (scm_hash_set_x, "hash-set!", 3, 0, 0,
(SCM table, SCM key, SCM val),
"Find the entry in @var{table} associated with @var{key}, and\n"
- "store @var{value} there. Uses @code{equal?} for equality\n"
+ "store @var{val} there. Uses @code{equal?} for equality\n"
"testing.")
#define FUNC_NAME s_scm_hash_set_x
{
diff --git a/libguile/i18n.c b/libguile/i18n.c
index 5a53bfae5..057711fdb 100644
--- a/libguile/i18n.c
+++ b/libguile/i18n.c
@@ -59,16 +59,8 @@
#include "libguile/posix.h" /* for `scm_i_locale_mutex' */
-#ifdef HAVE_LANGINFO_H
-# include <langinfo.h>
-#endif
-#ifdef HAVE_NL_TYPES_H
-# include <nl_types.h>
-#endif
-#ifndef HAVE_NL_ITEM
-/* Cygwin has <langinfo.h> but lacks <nl_types.h> and `nl_item'. */
-typedef int nl_item;
-#endif
+/* Use Gnulib's header, which also provides `nl_item' & co. */
+#include <langinfo.h>
#ifndef HAVE_SETLOCALE
static inline char *
@@ -223,7 +215,7 @@ SCM_GLOBAL_VARIABLE (scm_global_locale, "%global-locale");
#define SCM_VALIDATE_OPTIONAL_LOCALE_COPY(_pos, _arg, _c_locale) \
do \
{ \
- if (!scm_is_eq ((_arg), SCM_UNDEFINED)) \
+ if (!SCM_UNBNDP (_arg)) \
SCM_VALIDATE_LOCALE_COPY (_pos, _arg, _c_locale); \
else \
(_c_locale) = NULL; \
@@ -1481,14 +1473,11 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
"Reference Manual}).")
#define FUNC_NAME s_scm_nl_langinfo
{
-#ifdef HAVE_NL_LANGINFO
SCM result;
nl_item c_item;
char *c_result;
scm_t_locale c_locale;
-#ifdef HAVE_LANGINFO_CODESET
char *codeset;
-#endif
SCM_VALIDATE_INT_COPY (2, item, c_item);
SCM_VALIDATE_OPTIONAL_LOCALE_COPY (2, locale, c_locale);
@@ -1505,9 +1494,7 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
{
#ifdef USE_GNU_LOCALE_API
c_result = nl_langinfo_l (c_item, c_locale);
-#ifdef HAVE_LANGINFO_CODESET
codeset = nl_langinfo_l (CODESET, c_locale);
-#endif /* HAVE_LANGINFO_CODESET */
#else /* !USE_GNU_LOCALE_API */
/* We can't use `RUN_IN_LOCALE_SECTION ()' here because the locale
mutex is already taken. */
@@ -1532,9 +1519,7 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
else
{
c_result = nl_langinfo (c_item);
-#ifdef HAVE_LANGINFO_CODESET
codeset = nl_langinfo (CODESET);
-#endif /* HAVE_LANGINFO_CODESET */
restore_locale_settings (&lsec_prev_locale);
free_locale_settings (&lsec_prev_locale);
@@ -1544,9 +1529,7 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
else
{
c_result = nl_langinfo (c_item);
-#ifdef HAVE_LANGINFO_CODESET
codeset = nl_langinfo (CODESET);
-#endif /* HAVE_LANGINFO_CODESET */
}
c_result = strdup (c_result);
@@ -1659,26 +1642,14 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
#endif
default:
-#ifdef HAVE_LANGINFO_CODESET
result = scm_from_stringn (c_result, strlen (c_result),
codeset,
SCM_FAILED_CONVERSION_QUESTION_MARK);
-#else /* !HAVE_LANGINFO_CODESET */
- /* This may be incorrectly encoded if the locale differs
- from the c_locale. */
- result = scm_from_locale_string (c_result);
-#endif /* !HAVE_LANGINFO_CODESET */
free (c_result);
}
}
return result;
-#else
- scm_syserror_msg (FUNC_NAME, "`nl-langinfo' not supported on your system",
- SCM_EOL, ENOSYS);
-
- return SCM_BOOL_F;
-#endif
}
#undef FUNC_NAME
@@ -1686,8 +1657,6 @@ SCM_DEFINE (scm_nl_langinfo, "nl-langinfo", 1, 1, 0,
static inline void
define_langinfo_items (void)
{
-#ifdef HAVE_LANGINFO_H
-
#define DEFINE_NLITEM_CONSTANT(_item) \
scm_c_define (# _item, scm_from_int (_item))
@@ -1852,8 +1821,6 @@ define_langinfo_items (void)
#endif
#undef DEFINE_NLITEM_CONSTANT
-
-#endif /* HAVE_NL_TYPES_H */
}
@@ -1862,10 +1829,8 @@ scm_init_i18n ()
{
SCM global_locale_smob;
-#ifdef HAVE_NL_LANGINFO
scm_add_feature ("nl-langinfo");
define_langinfo_items ();
-#endif
#include "libguile/i18n.x"
diff --git a/libguile/init.c b/libguile/init.c
index 35ab85603..3509ba315 100644
--- a/libguile/init.c
+++ b/libguile/init.c
@@ -1,5 +1,6 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2002, 2003, 2004, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
- *
+/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
+ * 2004, 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of
@@ -91,7 +92,7 @@
#include "libguile/poll.h"
#include "libguile/ports.h"
#include "libguile/posix.h"
-#ifdef HAVE_REGCOMP
+#ifdef ENABLE_REGEX
#include "libguile/regex-posix.h"
#endif
#include "libguile/print.h"
@@ -452,7 +453,7 @@ scm_i_init_guile (void *base)
#ifdef HAVE_POSIX
scm_init_posix ();
#endif
-#ifdef HAVE_REGCOMP
+#ifdef ENABLE_REGEX
scm_init_regex_posix (); /* Requires smob_prehistory */
#endif
scm_init_procs ();
diff --git a/libguile/ioext.c b/libguile/ioext.c
index b1addf4c1..94b0f4f0f 100644
--- a/libguile/ioext.c
+++ b/libguile/ioext.c
@@ -49,7 +49,7 @@
SCM_DEFINE (scm_ftell, "ftell", 1, 0, 0,
(SCM fd_port),
"Return an integer representing the current position of\n"
- "@var{fd/port}, measured from the beginning. Equivalent to:\n"
+ "@var{fd_port}, measured from the beginning. Equivalent to:\n"
"\n"
"@lisp\n"
"(seek port 0 SEEK_CUR)\n"
@@ -63,8 +63,8 @@ SCM_DEFINE (scm_ftell, "ftell", 1, 0, 0,
SCM_DEFINE (scm_redirect_port, "redirect-port", 2, 0, 0,
(SCM old, SCM new),
"This procedure takes two ports and duplicates the underlying file\n"
- "descriptor from @var{old-port} into @var{new-port}. The\n"
- "current file descriptor in @var{new-port} will be closed.\n"
+ "descriptor from @var{old} into @var{new}. The\n"
+ "current file descriptor in @var{new} will be closed.\n"
"After the redirection the two ports will share a file position\n"
"and file status flags.\n\n"
"The return value is unspecified.\n\n"
@@ -236,7 +236,7 @@ SCM_DEFINE (scm_fdopen, "fdopen", 2, 0, 0,
SCM_DEFINE (scm_primitive_move_to_fdes, "primitive-move->fdes", 2, 0, 0,
(SCM port, SCM fd),
"Moves the underlying file descriptor for @var{port} to the integer\n"
- "value @var{fdes} without changing the revealed count of @var{port}.\n"
+ "value @var{fd} without changing the revealed count of @var{port}.\n"
"Any other ports already using this descriptor will be automatically\n"
"shifted to new descriptors and their revealed counts reset to zero.\n"
"The return value is @code{#f} if the file descriptor already had the\n"
@@ -284,7 +284,7 @@ get_matching_port (void *closure, SCM port, SCM result)
/* Return a list of ports using a given file descriptor. */
SCM_DEFINE (scm_fdes_to_ports, "fdes->ports", 1, 0, 0,
(SCM fd),
- "Return a list of existing ports which have @var{fdes} as an\n"
+ "Return a list of existing ports which have @var{fd} as an\n"
"underlying file descriptor, without changing their revealed\n"
"counts.")
#define FUNC_NAME s_scm_fdes_to_ports
diff --git a/libguile/load.c b/libguile/load.c
index 135a621cb..86d7e53fb 100644
--- a/libguile/load.c
+++ b/libguile/load.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2004, 2006, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2004, 2006, 2008,
+ * 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -419,8 +420,9 @@ scm_c_string_has_an_ext (char *str, size_t len, SCM extensions)
/* Search PATH for a directory containing a file named FILENAME.
The file must be readable, and not a directory.
- If we find one, return its full filename; otherwise, return #f.
+ If we find one, return its full pathname; otherwise, return #f.
If FILENAME is absolute, return it unchanged.
+ We also fill *stat_buf corresponding to the returned pathname.
If given, EXTENSIONS is a list of strings; for each directory
in PATH, we search for FILENAME concatenated with each EXTENSION. */
static SCM
@@ -445,7 +447,7 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts,
filename_len = strlen (filename_chars);
scm_dynwind_free (filename_chars);
- /* If FILENAME is absolute, return it unchanged. */
+ /* If FILENAME is absolute and is still valid, return it unchanged. */
#ifdef __MINGW32__
if (((filename_len >= 1) &&
(filename_chars[0] == '/' || filename_chars[0] == '\\')) ||
@@ -457,14 +459,13 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts,
if (filename_len >= 1 && filename_chars[0] == '/')
#endif
{
- SCM res = filename;
- if (scm_is_true (require_exts) &&
- !scm_c_string_has_an_ext (filename_chars, filename_len,
+ if ((scm_is_false (require_exts) ||
+ scm_c_string_has_an_ext (filename_chars, filename_len,
extensions))
- res = SCM_BOOL_F;
-
- scm_dynwind_end ();
- return res;
+ && stat (filename_chars, stat_buf) == 0
+ && !(stat_buf->st_mode & S_IFDIR))
+ result = filename;
+ goto end;
}
/* If FILENAME has an extension, don't try to add EXTENSIONS to it. */
@@ -483,8 +484,7 @@ search_path (SCM path, SCM filename, SCM extensions, SCM require_exts,
{
/* This filename has an extension, but not one of the right
ones... */
- scm_dynwind_end ();
- return SCM_BOOL_F;
+ goto end;
}
/* This filename already has an extension, so cancel the
list of extensions. */
@@ -571,9 +571,9 @@ SCM_DEFINE (scm_search_path, "search-path", 2, 0, 1,
"@var{filename}. The file must be readable, and not a directory.\n"
"If we find one, return its full filename; otherwise, return\n"
"@code{#f}. If @var{filename} is absolute, return it unchanged.\n"
- "If given, @var{extensions} is a list of strings; for each\n"
+ "If given, @var{rest} is a list of extension strings; for each\n"
"directory in @var{path}, we search for @var{filename}\n"
- "concatenated with each @var{extension}.")
+ "concatenated with each extension.")
#define FUNC_NAME s_scm_search_path
{
SCM extensions, require_exts;
diff --git a/libguile/net_db.c b/libguile/net_db.c
index 61dd2f386..4d63aabcc 100644
--- a/libguile/net_db.c
+++ b/libguile/net_db.c
@@ -1,6 +1,7 @@
/* "net_db.c" network database support
- * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2006, 2009, 2010, 2011 Free Software Foundation, Inc.
- *
+ * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2006, 2009,
+ * 2010, 2011, 2012 Free Software Foundation, Inc.
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of
@@ -590,10 +591,14 @@ SCM_DEFINE (scm_getaddrinfo, "getaddrinfo", 1, 5, 0,
"@item EAI_NONAME\n"
"Either @var{name} does not resolve for the supplied parameters, "
"or neither @var{name} nor @var{service} were supplied.\n\n"
+
+ /* See `sysdeps/posix/getaddrinfo.c' in the GNU libc, and
+ <http://www.opensource.apple.com/source/Libinfo/Libinfo-324.1/lookup.subproj/netdb.h>,
+ for details on EAI_NODATA. */
"@item EAI_NODATA\n"
- "This non-POSIX error code can be returned on GNU systems when a\n"
- "request was actually made but returned no data, meaning\n"
- "that no address is associated with @var{name}. Error handling\n"
+ "This non-POSIX error code can be returned on some systems (GNU "
+ "and Darwin, at least), for example when @var{name} is known "
+ "but requests that were made turned out no data. Error handling\n"
"code should be prepared to handle it when it is defined.\n\n"
"@item EAI_SERVICE\n"
"@var{service} was not recognized for the specified socket type.\n\n"
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 46a195a98..cb457d114 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -8704,8 +8704,8 @@ scm_c_make_rectangular (double re, double im)
SCM_DEFINE (scm_make_rectangular, "make-rectangular", 2, 0, 0,
(SCM real_part, SCM imaginary_part),
- "Return a complex number constructed of the given @var{real-part} "
- "and @var{imaginary-part} parts.")
+ "Return a complex number constructed of the given @var{real_part} "
+ "and @var{imaginary_part} parts.")
#define FUNC_NAME s_scm_make_rectangular
{
SCM_ASSERT_TYPE (scm_is_real (real_part), real_part,
diff --git a/libguile/ports.c b/libguile/ports.c
index 2f9945349..7acf06299 100644
--- a/libguile/ports.c
+++ b/libguile/ports.c
@@ -1,5 +1,5 @@
/* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004,
- * 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ * 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -1991,10 +1991,11 @@ SCM_DEFINE (scm_peek_char, "peek-char", 0, 1, 0,
SCM_DEFINE (scm_unread_char, "unread-char", 1, 1, 0,
(SCM cobj, SCM port),
- "Place @var{char} in @var{port} so that it will be read by the\n"
- "next read operation. If called multiple times, the unread characters\n"
- "will be read again in last-in first-out order. If @var{port} is\n"
- "not supplied, the current input port is used.")
+ "Place character @var{cobj} in @var{port} so that it will be\n"
+ "read by the next read operation. If called multiple times, the\n"
+ "unread characters will be read again in last-in first-out\n"
+ "order. If @var{port} is not supplied, the current input port\n"
+ "is used.")
#define FUNC_NAME s_scm_unread_char
{
int c;
@@ -2406,7 +2407,7 @@ SCM_DEFINE (scm_char_ready_p, "char-ready?", 0, 1, 0,
SCM_DEFINE (scm_seek, "seek", 3, 0, 0,
(SCM fd_port, SCM offset, SCM whence),
- "Sets the current position of @var{fd/port} to the integer\n"
+ "Sets the current position of @var{fd_port} to the integer\n"
"@var{offset}, which is interpreted according to the value of\n"
"@var{whence}.\n"
"\n"
@@ -2421,7 +2422,7 @@ SCM_DEFINE (scm_seek, "seek", 3, 0, 0,
"@defvar SEEK_END\n"
"Seek from the end of the file.\n"
"@end defvar\n"
- "If @var{fd/port} is a file descriptor, the underlying system\n"
+ "If @var{fd_port} is a file descriptor, the underlying system\n"
"call is @code{lseek}. @var{port} may be a string port.\n"
"\n"
"The value returned is the new position in the file. This means\n"
@@ -2495,8 +2496,9 @@ truncate (const char *file, off_t length)
SCM_DEFINE (scm_truncate_file, "truncate-file", 1, 1, 0,
(SCM object, SCM length),
- "Truncate @var{file} to @var{length} bytes. @var{file} can be a\n"
- "filename string, a port object, or an integer file descriptor.\n"
+ "Truncate file @var{object} to @var{length} bytes. @var{object}\n"
+ "can be a filename string, a port object, or an integer file\n"
+ "descriptor.\n"
"The return value is unspecified.\n"
"\n"
"For a port or file descriptor @var{length} can be omitted, in\n"
@@ -2731,9 +2733,9 @@ SCM_DEFINE (scm_port_for_each, "port-for-each", 1, 0, 0,
"Apply @var{proc} to each port in the Guile port table\n"
"in turn. The return value is unspecified. More specifically,\n"
"@var{proc} is applied exactly once to every port that exists\n"
- "in the system at the time @var{port-for-each} is invoked.\n"
- "Changes to the port table while @var{port-for-each} is running\n"
- "have no effect as far as @var{port-for-each} is concerned.")
+ "in the system at the time @code{port-for-each} is invoked.\n"
+ "Changes to the port table while @code{port-for-each} is running\n"
+ "have no effect as far as @code{port-for-each} is concerned.")
#define FUNC_NAME s_scm_port_for_each
{
SCM_VALIDATE_PROC (1, proc);
diff --git a/libguile/posix.c b/libguile/posix.c
index ea406aee1..154d26ad9 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -285,7 +285,7 @@ SCM_DEFINE (scm_getgroups, "getgroups", 0, 0, 0,
SCM_DEFINE (scm_setgroups, "setgroups", 1, 0, 0,
(SCM group_vec),
"Set the current set of supplementary group IDs to the integers\n"
- "in the given vector @var{vec}. The return value is\n"
+ "in the given vector @var{group_vec}. The return value is\n"
"unspecified.\n"
"\n"
"Generally only the superuser can set the process group IDs.")
@@ -335,9 +335,10 @@ SCM_DEFINE (scm_setgroups, "setgroups", 1, 0, 0,
#ifdef HAVE_GETPWENT
SCM_DEFINE (scm_getpwuid, "getpw", 0, 1, 0,
(SCM user),
- "Look up an entry in the user database. @var{obj} can be an integer,\n"
- "a string, or omitted, giving the behaviour of getpwuid, getpwnam\n"
- "or getpwent respectively.")
+ "Look up an entry in the user database. @var{user} can be an\n"
+ "integer, a string, or omitted, giving the behaviour of\n"
+ "@code{getpwuid}, @code{getpwnam} or @code{getpwent}\n"
+ "respectively.")
#define FUNC_NAME s_scm_getpwuid
{
struct passwd *entry;
@@ -404,9 +405,10 @@ SCM_DEFINE (scm_setpwent, "setpw", 0, 1, 0,
/* Combines getgrgid and getgrnam. */
SCM_DEFINE (scm_getgrgid, "getgr", 0, 1, 0,
(SCM name),
- "Look up an entry in the group database. @var{obj} can be an integer,\n"
- "a string, or omitted, giving the behaviour of getgrgid, getgrnam\n"
- "or getgrent respectively.")
+ "Look up an entry in the group database. @var{name} can be an\n"
+ "integer, a string, or omitted, giving the behaviour of\n"
+ "@code{getgrgid}, @code{getgrnam} or @code{getgrent}\n"
+ "respectively.")
#define FUNC_NAME s_scm_getgrgid
{
struct group *entry;
@@ -698,7 +700,7 @@ SCM_DEFINE (scm_waitpid, "waitpid", 1, 1, 0,
"group.\n"
"@item @var{pid} less than -1\n"
"Request status information for any child process whose process group ID\n"
- "is -@var{PID}.\n"
+ "is -@var{pid}.\n"
"@end table\n\n"
"The @var{options} argument, if supplied, should be the bitwise OR of the\n"
"values of zero or more of the following variables:\n\n"
@@ -1122,10 +1124,10 @@ SCM_DEFINE (scm_tcsetpgrp, "tcsetpgrp", 2, 0, 0,
SCM_DEFINE (scm_execl, "execl", 1, 0, 1,
(SCM filename, SCM args),
- "Executes the file named by @var{path} as a new process image.\n"
+ "Executes the file named by @var{filename} as a new process image.\n"
"The remaining arguments are supplied to the process; from a C program\n"
"they are accessible as the @code{argv} argument to @code{main}.\n"
- "Conventionally the first @var{arg} is the same as @var{path}.\n"
+ "Conventionally the first @var{arg} is the same as @var{filename}.\n"
"All arguments must be strings.\n\n"
"If @var{arg} is missing, @var{path} is executed with a null\n"
"argument list, which may have system-dependent side-effects.\n\n"
@@ -1359,7 +1361,7 @@ SCM_DEFINE (scm_utime, "utime", 1, 5, 0,
(SCM pathname, SCM actime, SCM modtime, SCM actimens, SCM modtimens,
SCM flags),
"@code{utime} sets the access and modification times for the\n"
- "file named by @var{path}. If @var{actime} or @var{modtime} is\n"
+ "file named by @var{pathname}. If @var{actime} or @var{modtime} is\n"
"not supplied, then the current time is used. @var{actime} and\n"
"@var{modtime} must be integer time values as returned by the\n"
"@code{current-time} procedure.\n\n"
@@ -1461,14 +1463,14 @@ SCM_DEFINE (scm_getpid, "getpid", 0, 0, 0,
SCM_DEFINE (scm_putenv, "putenv", 1, 0, 0,
(SCM str),
- "Modifies the environment of the current process, which is\n"
- "also the default environment inherited by child processes.\n\n"
- "If @var{string} is of the form @code{NAME=VALUE} then it will be written\n"
- "directly into the environment, replacing any existing environment string\n"
- "with\n"
- "name matching @code{NAME}. If @var{string} does not contain an equal\n"
- "sign, then any existing string with name matching @var{string} will\n"
- "be removed.\n\n"
+ "Modifies the environment of the current process, which is also\n"
+ "the default environment inherited by child processes. If\n"
+ "@var{str} is of the form @code{NAME=VALUE} then it will be\n"
+ "written directly into the environment, replacing any existing\n"
+ "environment string with name matching @code{NAME}. If\n"
+ "@var{str} does not contain an equal sign, then any existing\n"
+ "string with name matching @var{str} will be removed.\n"
+ "\n"
"The return value is unspecified.")
#define FUNC_NAME s_scm_putenv
{
diff --git a/libguile/print.c b/libguile/print.c
index b800362c1..10b16f345 100644
--- a/libguile/print.c
+++ b/libguile/print.c
@@ -1343,7 +1343,7 @@ SCM_DEFINE (scm_simple_format, "simple-format", 2, 0, 1,
"@var{message} can contain @code{~A} (was @code{%s}) and\n"
"@code{~S} (was @code{%S}) escapes. When printed,\n"
"the escapes are replaced with corresponding members of\n"
- "@var{ARGS}:\n"
+ "@var{args}:\n"
"@code{~A} formats using @code{display} and @code{~S} formats\n"
"using @code{write}.\n"
"If @var{destination} is @code{#t}, then use the current output\n"
diff --git a/libguile/procprop.c b/libguile/procprop.c
index 93ee7f033..56bd3896b 100644
--- a/libguile/procprop.c
+++ b/libguile/procprop.c
@@ -125,7 +125,7 @@ SCM_DEFINE (scm_procedure_minimum_arity, "procedure-minimum-arity", 1, 0, 0,
SCM_DEFINE (scm_procedure_properties, "procedure-properties", 1, 0, 0,
(SCM proc),
- "Return @var{obj}'s property list.")
+ "Return @var{proc}'s property list.")
#define FUNC_NAME s_scm_procedure_properties
{
SCM ret;
diff --git a/libguile/promises.c b/libguile/promises.c
index 57a208104..dcd0ac383 100644
--- a/libguile/promises.c
+++ b/libguile/promises.c
@@ -98,8 +98,8 @@ promise_print (SCM exp, SCM port, scm_print_state *pstate)
SCM_DEFINE (scm_force, "force", 1, 0, 0,
(SCM promise),
- "If the promise @var{x} has not been computed yet, compute and\n"
- "return @var{x}, otherwise just return the previously computed\n"
+ "If @var{promise} has not been computed yet, compute and\n"
+ "return @var{promise}, otherwise just return the previously computed\n"
"value.")
#define FUNC_NAME s_scm_force
{
diff --git a/libguile/regex-posix.c b/libguile/regex-posix.c
index 34230994e..bec0f89fb 100644
--- a/libguile/regex-posix.c
+++ b/libguile/regex-posix.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004, 2006, 2007, 2010, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004, 2006, 2007, 2010, 2011, 2012 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
@@ -35,23 +35,7 @@
#include "libguile/_scm.h"
-/* Supposedly, this file is never compiled unless we know we have
- POSIX regular expressions. But we still put this in an #ifdef so
- the file is CPP'able (for dependency scanning) even on systems that
- don't have a <regex.h> header. */
-#ifdef HAVE_REGCOMP
-#ifdef HAVE_REGEX_H
#include <regex.h>
-#else
-#ifdef HAVE_RXPOSIX_H
-#include <rxposix.h> /* GNU Rx library */
-#else
-#ifdef HAVE_RX_RXPOSIX_H
-#include <rx/rxposix.h> /* GNU Rx library on Linux */
-#endif
-#endif
-#endif
-#endif
#ifdef HAVE_WCHAR_H
#include <wchar.h>
diff --git a/libguile/simpos.c b/libguile/simpos.c
index 84b8b9d67..5c8fe9623 100644
--- a/libguile/simpos.c
+++ b/libguile/simpos.c
@@ -169,7 +169,7 @@ SCM_DEFINE (scm_system_star, "system*", 0, 0, 1,
SCM_DEFINE (scm_getenv, "getenv", 1, 0, 0,
(SCM nam),
- "Looks up the string @var{name} in the current environment. The return\n"
+ "Looks up the string @var{nam} in the current environment. The return\n"
"value is @code{#f} unless a string of the form @code{NAME=VALUE} is\n"
"found, in which case the string @code{VALUE} is returned.")
#define FUNC_NAME s_scm_getenv
diff --git a/libguile/socket.c b/libguile/socket.c
index d085d330e..149ec005f 100644
--- a/libguile/socket.c
+++ b/libguile/socket.c
@@ -515,10 +515,10 @@ SCM_DEFINE (scm_getsockopt, "getsockopt", 3, 0, 0,
"@end defvar\n"
"\n"
"@defvar SO_LINGER\n"
- "The @var{value} returned is a pair of integers\n"
- "@code{(@var{ENABLE} . @var{TIMEOUT})}. On old systems without\n"
+ "The value returned is a pair of integers\n"
+ "@code{(@var{enable} . @var{timeout})}. On old systems without\n"
"timeout support (ie.@: without @code{struct linger}), only\n"
- "@var{ENABLE} has an effect but the value in Guile is always a\n"
+ "@var{enable} has an effect but the value in Guile is always a\n"
"pair.\n"
"@end defvar")
#define FUNC_NAME s_scm_getsockopt
@@ -1560,7 +1560,7 @@ SCM_DEFINE (scm_sendto, "sendto", 3, 1, 1,
(SCM sock, SCM message, SCM fam_or_sockaddr, SCM address, SCM args_and_flags),
"Transmit bytevector @var{message} on socket port\n"
"@var{sock}. The\n"
- "destination address is specified using the @var{fam},\n"
+ "destination address is specified using the @var{fam_or_sockaddr},\n"
"@var{address} and\n"
"@var{args_and_flags} arguments, or just a socket address object "
"returned by @code{make-socket-address}, in a similar way to the\n"
diff --git a/libguile/srfi-1.c b/libguile/srfi-1.c
index ed6d3d9d1..54c7e2aa3 100644
--- a/libguile/srfi-1.c
+++ b/libguile/srfi-1.c
@@ -714,8 +714,8 @@ SCM_DEFINE (scm_srfi1_lset_difference_x, "lset-difference!", 2, 0, 1,
SCM_DEFINE (scm_srfi1_assoc, "assoc", 2, 1, 0,
(SCM key, SCM alist, SCM pred),
- "Behaves like @code{assq} but uses third argument @var{pred?}\n"
- "for key comparison. If @var{pred?} is not supplied,\n"
+ "Behaves like @code{assq} but uses third argument @var{pred}\n"
+ "for key comparison. If @var{pred} is not supplied,\n"
"@code{equal?} is used. (Extended from R5RS.)\n")
#define FUNC_NAME s_scm_srfi1_assoc
{
@@ -844,9 +844,9 @@ SCM_DEFINE (scm_srfi1_partition_x, "partition!", 2, 0, 0,
SCM_DEFINE (scm_srfi1_remove, "remove", 2, 0, 0,
(SCM pred, SCM list),
- "Return a list containing all elements from @var{lst} which do\n"
+ "Return a list containing all elements from @var{list} which do\n"
"not satisfy the predicate @var{pred}. The elements in the\n"
- "result list have the same order as in @var{lst}. The order in\n"
+ "result list have the same order as in @var{list}. The order in\n"
"which @var{pred} is applied to the list elements is not\n"
"specified.")
#define FUNC_NAME s_scm_srfi1_remove
diff --git a/libguile/srfi-13.c b/libguile/srfi-13.c
index 92d4a9d70..75feae3b2 100644
--- a/libguile/srfi-13.c
+++ b/libguile/srfi-13.c
@@ -375,7 +375,7 @@ SCM_SYMBOL (scm_sym_prefix, "prefix");
SCM_DEFINE (scm_string_join, "string-join", 1, 2, 0,
(SCM ls, SCM delimiter, SCM grammar),
"Append the string in the string list @var{ls}, using the string\n"
- "@var{delim} as a delimiter between the elements of @var{ls}.\n"
+ "@var{delimiter} as a delimiter between the elements of @var{ls}.\n"
"@var{grammar} is a symbol which specifies how the delimiter is\n"
"placed between the strings, and defaults to the symbol\n"
"@code{infix}.\n"
@@ -1356,7 +1356,7 @@ SCM_DEFINE (scm_string_ci_ge, "string-ci>=", 2, 4, 0,
SCM_DEFINE (scm_substring_hash, "string-hash", 1, 3, 0,
(SCM s, SCM bound, SCM start, SCM end),
- "Compute a hash value for @var{S}. the optional argument "
+ "Compute a hash value for @var{s}. the optional argument "
"@var{bound} is a non-negative exact "
"integer specifying the range of the hash function. "
"A positive value restricts the return value to the "
@@ -1373,7 +1373,7 @@ SCM_DEFINE (scm_substring_hash, "string-hash", 1, 3, 0,
SCM_DEFINE (scm_substring_hash_ci, "string-hash-ci", 1, 3, 0,
(SCM s, SCM bound, SCM start, SCM end),
- "Compute a hash value for @var{S}. the optional argument "
+ "Compute a hash value for @var{s}. the optional argument "
"@var{bound} is a non-negative exact "
"integer specifying the range of the hash function. "
"A positive value restricts the return value to the "
diff --git a/libguile/srfi-14.c b/libguile/srfi-14.c
index 09323704d..bf95ce982 100644
--- a/libguile/srfi-14.c
+++ b/libguile/srfi-14.c
@@ -698,8 +698,8 @@ SCM_DEFINE (scm_char_set_eq, "char-set=", 0, 0, 1,
SCM_DEFINE (scm_char_set_leq, "char-set<=", 0, 0, 1,
(SCM char_sets),
- "Return @code{#t} if every character set @var{cs}i is a subset\n"
- "of character set @var{cs}i+1.")
+ "Return @code{#t} if every character set @var{char_set}i is a subset\n"
+ "of character set @var{char_set}i+1.")
#define FUNC_NAME s_scm_char_set_leq
{
int argnum = 1;
@@ -732,7 +732,7 @@ SCM_DEFINE (scm_char_set_hash, "char-set-hash", 1, 1, 0,
(SCM cs, SCM bound),
"Compute a hash value for the character set @var{cs}. If\n"
"@var{bound} is given and non-zero, it restricts the\n"
- "returned value to the range 0 @dots{} @var{bound - 1}.")
+ "returned value to the range 0 @dots{} @var{bound} - 1.")
#define FUNC_NAME s_scm_char_set_hash
{
const unsigned long default_bnd = 871;
diff --git a/libguile/srfi-14.i.c b/libguile/srfi-14.i.c
index 8047cdc1e..f59a8071c 100644
--- a/libguile/srfi-14.i.c
+++ b/libguile/srfi-14.i.c
@@ -1053,6 +1053,8 @@ scm_t_char_range cs_lower_case_ranges[] = {
,
{0xa791, 0xa791}
,
+ {0xa793, 0xa793}
+ ,
{0xa7a1, 0xa7a1}
,
{0xa7a3, 0xa7a3}
@@ -1063,6 +1065,8 @@ scm_t_char_range cs_lower_case_ranges[] = {
,
{0xa7a9, 0xa7a9}
,
+ {0xa7f9, 0xa7f9}
+ ,
{0xfb00, 0xfb06}
,
{0xfb13, 0xfb17}
@@ -1077,7 +1081,7 @@ scm_t_char_range cs_lower_case_ranges[] = {
};
scm_t_char_set cs_lower_case = {
- 534,
+ 536,
cs_lower_case_ranges
};
@@ -1616,6 +1620,10 @@ scm_t_char_range cs_upper_case_ranges[] = {
,
{0x10a0, 0x10c5}
,
+ {0x10c7, 0x10c7}
+ ,
+ {0x10cd, 0x10cd}
+ ,
{0x1d7b, 0x1d7b}
,
{0x1d7e, 0x1d7e}
@@ -2070,6 +2078,8 @@ scm_t_char_range cs_upper_case_ranges[] = {
,
{0xa790, 0xa790}
,
+ {0xa792, 0xa792}
+ ,
{0xa7a0, 0xa7a0}
,
{0xa7a2, 0xa7a2}
@@ -2080,6 +2090,8 @@ scm_t_char_range cs_upper_case_ranges[] = {
,
{0xa7a8, 0xa7a8}
,
+ {0xa7aa, 0xa7aa}
+ ,
{0xff21, 0xff3a}
,
{0x10400, 0x10427}
@@ -2098,7 +2110,7 @@ scm_t_char_range cs_upper_case_ranges[] = {
};
scm_t_char_set cs_upper_case = {
- 507,
+ 511,
cs_upper_case_ranges
};
@@ -2224,6 +2236,10 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x0840, 0x0858}
,
+ {0x08a0, 0x08a0}
+ ,
+ {0x08a2, 0x08ac}
+ ,
{0x0904, 0x0939}
,
{0x093d, 0x093d}
@@ -2434,7 +2450,7 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x0ec6, 0x0ec6}
,
- {0x0edc, 0x0edd}
+ {0x0edc, 0x0edf}
,
{0x0f00, 0x0f00}
,
@@ -2464,11 +2480,13 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x10a0, 0x10c5}
,
- {0x10d0, 0x10fa}
+ {0x10c7, 0x10c7}
+ ,
+ {0x10cd, 0x10cd}
,
- {0x10fc, 0x10fc}
+ {0x10d0, 0x10fa}
,
- {0x1100, 0x1248}
+ {0x10fc, 0x1248}
,
{0x124a, 0x124d}
,
@@ -2562,7 +2580,7 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x1bae, 0x1baf}
,
- {0x1bc0, 0x1be5}
+ {0x1bba, 0x1be5}
,
{0x1c00, 0x1c23}
,
@@ -2574,6 +2592,8 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x1cee, 0x1cf1}
,
+ {0x1cf5, 0x1cf6}
+ ,
{0x1d00, 0x1dbf}
,
{0x1e00, 0x1f15}
@@ -2656,9 +2676,15 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x2ceb, 0x2cee}
,
+ {0x2cf2, 0x2cf3}
+ ,
{0x2d00, 0x2d25}
,
- {0x2d30, 0x2d65}
+ {0x2d27, 0x2d27}
+ ,
+ {0x2d2d, 0x2d2d}
+ ,
+ {0x2d30, 0x2d67}
,
{0x2d6f, 0x2d6f}
,
@@ -2706,7 +2732,7 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x3400, 0x4db5}
,
- {0x4e00, 0x9fcb}
+ {0x4e00, 0x9fcc}
,
{0xa000, 0xa48c}
,
@@ -2730,11 +2756,11 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0xa78b, 0xa78e}
,
- {0xa790, 0xa791}
+ {0xa790, 0xa793}
,
- {0xa7a0, 0xa7a9}
+ {0xa7a0, 0xa7aa}
,
- {0xa7fa, 0xa801}
+ {0xa7f8, 0xa801}
,
{0xa803, 0xa805}
,
@@ -2784,6 +2810,10 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0xaadb, 0xaadd}
,
+ {0xaae0, 0xaaea}
+ ,
+ {0xaaf2, 0xaaf4}
+ ,
{0xab01, 0xab06}
,
{0xab09, 0xab0e}
@@ -2802,9 +2832,7 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0xd7cb, 0xd7fb}
,
- {0xf900, 0xfa2d}
- ,
- {0xfa30, 0xfa6d}
+ {0xf900, 0xfa6d}
,
{0xfa70, 0xfad9}
,
@@ -2902,6 +2930,10 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x10920, 0x10939}
,
+ {0x10980, 0x109b7}
+ ,
+ {0x109be, 0x109bf}
+ ,
{0x10a00, 0x10a00}
,
{0x10a10, 0x10a13}
@@ -2924,12 +2956,28 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x11083, 0x110af}
,
+ {0x110d0, 0x110e8}
+ ,
+ {0x11103, 0x11126}
+ ,
+ {0x11183, 0x111b2}
+ ,
+ {0x111c1, 0x111c4}
+ ,
+ {0x11680, 0x116aa}
+ ,
{0x12000, 0x1236e}
,
{0x13000, 0x1342e}
,
{0x16800, 0x16a38}
,
+ {0x16f00, 0x16f44}
+ ,
+ {0x16f50, 0x16f50}
+ ,
+ {0x16f93, 0x16f9f}
+ ,
{0x1b000, 0x1b001}
,
{0x1d400, 0x1d454}
@@ -2992,6 +3040,72 @@ scm_t_char_range cs_letter_ranges[] = {
,
{0x1d7c4, 0x1d7cb}
,
+ {0x1ee00, 0x1ee03}
+ ,
+ {0x1ee05, 0x1ee1f}
+ ,
+ {0x1ee21, 0x1ee22}
+ ,
+ {0x1ee24, 0x1ee24}
+ ,
+ {0x1ee27, 0x1ee27}
+ ,
+ {0x1ee29, 0x1ee32}
+ ,
+ {0x1ee34, 0x1ee37}
+ ,
+ {0x1ee39, 0x1ee39}
+ ,
+ {0x1ee3b, 0x1ee3b}
+ ,
+ {0x1ee42, 0x1ee42}
+ ,
+ {0x1ee47, 0x1ee47}
+ ,
+ {0x1ee49, 0x1ee49}
+ ,
+ {0x1ee4b, 0x1ee4b}
+ ,
+ {0x1ee4d, 0x1ee4f}
+ ,
+ {0x1ee51, 0x1ee52}
+ ,
+ {0x1ee54, 0x1ee54}
+ ,
+ {0x1ee57, 0x1ee57}
+ ,
+ {0x1ee59, 0x1ee59}
+ ,
+ {0x1ee5b, 0x1ee5b}
+ ,
+ {0x1ee5d, 0x1ee5d}
+ ,
+ {0x1ee5f, 0x1ee5f}
+ ,
+ {0x1ee61, 0x1ee62}
+ ,
+ {0x1ee64, 0x1ee64}
+ ,
+ {0x1ee67, 0x1ee6a}
+ ,
+ {0x1ee6c, 0x1ee72}
+ ,
+ {0x1ee74, 0x1ee77}
+ ,
+ {0x1ee79, 0x1ee7c}
+ ,
+ {0x1ee7e, 0x1ee7e}
+ ,
+ {0x1ee80, 0x1ee89}
+ ,
+ {0x1ee8b, 0x1ee9b}
+ ,
+ {0x1eea1, 0x1eea3}
+ ,
+ {0x1eea5, 0x1eea9}
+ ,
+ {0x1eeab, 0x1eebb}
+ ,
{0x20000, 0x2a6d6}
,
{0x2a700, 0x2b734}
@@ -3002,7 +3116,7 @@ scm_t_char_range cs_letter_ranges[] = {
};
scm_t_char_set cs_letter = {
- 435,
+ 486,
cs_letter_ranges
};
@@ -3081,11 +3195,19 @@ scm_t_char_range cs_digit_ranges[] = {
,
{0x11066, 0x1106f}
,
+ {0x110f0, 0x110f9}
+ ,
+ {0x11136, 0x1113f}
+ ,
+ {0x111d0, 0x111d9}
+ ,
+ {0x116c0, 0x116c9}
+ ,
{0x1d7ce, 0x1d7ff}
};
scm_t_char_set cs_digit = {
- 38,
+ 42,
cs_digit_ranges
};
@@ -3199,6 +3321,10 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x0840, 0x0858}
,
+ {0x08a0, 0x08a0}
+ ,
+ {0x08a2, 0x08ac}
+ ,
{0x0904, 0x0939}
,
{0x093d, 0x093d}
@@ -3429,7 +3555,7 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x0ed0, 0x0ed9}
,
- {0x0edc, 0x0edd}
+ {0x0edc, 0x0edf}
,
{0x0f00, 0x0f00}
,
@@ -3463,11 +3589,13 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x10a0, 0x10c5}
,
- {0x10d0, 0x10fa}
+ {0x10c7, 0x10c7}
,
- {0x10fc, 0x10fc}
+ {0x10cd, 0x10cd}
,
- {0x1100, 0x1248}
+ {0x10d0, 0x10fa}
+ ,
+ {0x10fc, 0x1248}
,
{0x124a, 0x124d}
,
@@ -3571,9 +3699,7 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x1b83, 0x1ba0}
,
- {0x1bae, 0x1bb9}
- ,
- {0x1bc0, 0x1be5}
+ {0x1bae, 0x1be5}
,
{0x1c00, 0x1c23}
,
@@ -3585,6 +3711,8 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x1cee, 0x1cf1}
,
+ {0x1cf5, 0x1cf6}
+ ,
{0x1d00, 0x1dbf}
,
{0x1e00, 0x1f15}
@@ -3667,9 +3795,15 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x2ceb, 0x2cee}
,
+ {0x2cf2, 0x2cf3}
+ ,
{0x2d00, 0x2d25}
,
- {0x2d30, 0x2d65}
+ {0x2d27, 0x2d27}
+ ,
+ {0x2d2d, 0x2d2d}
+ ,
+ {0x2d30, 0x2d67}
,
{0x2d6f, 0x2d6f}
,
@@ -3717,7 +3851,7 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x3400, 0x4db5}
,
- {0x4e00, 0x9fcb}
+ {0x4e00, 0x9fcc}
,
{0xa000, 0xa48c}
,
@@ -3739,11 +3873,11 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0xa78b, 0xa78e}
,
- {0xa790, 0xa791}
+ {0xa790, 0xa793}
,
- {0xa7a0, 0xa7a9}
+ {0xa7a0, 0xa7aa}
,
- {0xa7fa, 0xa801}
+ {0xa7f8, 0xa801}
,
{0xa803, 0xa805}
,
@@ -3797,6 +3931,10 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0xaadb, 0xaadd}
,
+ {0xaae0, 0xaaea}
+ ,
+ {0xaaf2, 0xaaf4}
+ ,
{0xab01, 0xab06}
,
{0xab09, 0xab0e}
@@ -3817,9 +3955,7 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0xd7cb, 0xd7fb}
,
- {0xf900, 0xfa2d}
- ,
- {0xfa30, 0xfa6d}
+ {0xf900, 0xfa6d}
,
{0xfa70, 0xfad9}
,
@@ -3921,6 +4057,10 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x10920, 0x10939}
,
+ {0x10980, 0x109b7}
+ ,
+ {0x109be, 0x109bf}
+ ,
{0x10a00, 0x10a00}
,
{0x10a10, 0x10a13}
@@ -3945,12 +4085,36 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x11083, 0x110af}
,
+ {0x110d0, 0x110e8}
+ ,
+ {0x110f0, 0x110f9}
+ ,
+ {0x11103, 0x11126}
+ ,
+ {0x11136, 0x1113f}
+ ,
+ {0x11183, 0x111b2}
+ ,
+ {0x111c1, 0x111c4}
+ ,
+ {0x111d0, 0x111d9}
+ ,
+ {0x11680, 0x116aa}
+ ,
+ {0x116c0, 0x116c9}
+ ,
{0x12000, 0x1236e}
,
{0x13000, 0x1342e}
,
{0x16800, 0x16a38}
,
+ {0x16f00, 0x16f44}
+ ,
+ {0x16f50, 0x16f50}
+ ,
+ {0x16f93, 0x16f9f}
+ ,
{0x1b000, 0x1b001}
,
{0x1d400, 0x1d454}
@@ -4015,6 +4179,72 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
,
{0x1d7ce, 0x1d7ff}
,
+ {0x1ee00, 0x1ee03}
+ ,
+ {0x1ee05, 0x1ee1f}
+ ,
+ {0x1ee21, 0x1ee22}
+ ,
+ {0x1ee24, 0x1ee24}
+ ,
+ {0x1ee27, 0x1ee27}
+ ,
+ {0x1ee29, 0x1ee32}
+ ,
+ {0x1ee34, 0x1ee37}
+ ,
+ {0x1ee39, 0x1ee39}
+ ,
+ {0x1ee3b, 0x1ee3b}
+ ,
+ {0x1ee42, 0x1ee42}
+ ,
+ {0x1ee47, 0x1ee47}
+ ,
+ {0x1ee49, 0x1ee49}
+ ,
+ {0x1ee4b, 0x1ee4b}
+ ,
+ {0x1ee4d, 0x1ee4f}
+ ,
+ {0x1ee51, 0x1ee52}
+ ,
+ {0x1ee54, 0x1ee54}
+ ,
+ {0x1ee57, 0x1ee57}
+ ,
+ {0x1ee59, 0x1ee59}
+ ,
+ {0x1ee5b, 0x1ee5b}
+ ,
+ {0x1ee5d, 0x1ee5d}
+ ,
+ {0x1ee5f, 0x1ee5f}
+ ,
+ {0x1ee61, 0x1ee62}
+ ,
+ {0x1ee64, 0x1ee64}
+ ,
+ {0x1ee67, 0x1ee6a}
+ ,
+ {0x1ee6c, 0x1ee72}
+ ,
+ {0x1ee74, 0x1ee77}
+ ,
+ {0x1ee79, 0x1ee7c}
+ ,
+ {0x1ee7e, 0x1ee7e}
+ ,
+ {0x1ee80, 0x1ee89}
+ ,
+ {0x1ee8b, 0x1ee9b}
+ ,
+ {0x1eea1, 0x1eea3}
+ ,
+ {0x1eea5, 0x1eea9}
+ ,
+ {0x1eeab, 0x1eebb}
+ ,
{0x20000, 0x2a6d6}
,
{0x2a700, 0x2b734}
@@ -4025,7 +4255,7 @@ scm_t_char_range cs_letter_plus_digit_ranges[] = {
};
scm_t_char_set cs_letter_plus_digit = {
- 460,
+ 514,
cs_letter_plus_digit_ranges
};
@@ -4054,6 +4284,8 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x0589, 0x058a}
,
+ {0x058f, 0x058f}
+ ,
{0x0591, 0x05c7}
,
{0x05d0, 0x05ea}
@@ -4080,6 +4312,12 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x085e, 0x085e}
,
+ {0x08a0, 0x08a0}
+ ,
+ {0x08a2, 0x08ac}
+ ,
+ {0x08e4, 0x08fe}
+ ,
{0x0900, 0x0977}
,
{0x0979, 0x097f}
@@ -4168,9 +4406,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x0ae0, 0x0ae3}
,
- {0x0ae6, 0x0aef}
- ,
- {0x0af1, 0x0af1}
+ {0x0ae6, 0x0af1}
,
{0x0b01, 0x0b03}
,
@@ -4370,7 +4606,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x0ed0, 0x0ed9}
,
- {0x0edc, 0x0edd}
+ {0x0edc, 0x0edf}
,
{0x0f00, 0x0f47}
,
@@ -4386,9 +4622,11 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1000, 0x10c5}
,
- {0x10d0, 0x10fc}
+ {0x10c7, 0x10c7}
,
- {0x1100, 0x1248}
+ {0x10cd, 0x10cd}
+ ,
+ {0x10d0, 0x1248}
,
{0x124a, 0x124d}
,
@@ -4446,9 +4684,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1772, 0x1773}
,
- {0x1780, 0x17b3}
- ,
- {0x17b6, 0x17dd}
+ {0x1780, 0x17dd}
,
{0x17e0, 0x17e9}
,
@@ -4498,11 +4734,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1b50, 0x1b7c}
,
- {0x1b80, 0x1baa}
- ,
- {0x1bae, 0x1bb9}
- ,
- {0x1bc0, 0x1bf3}
+ {0x1b80, 0x1bf3}
,
{0x1bfc, 0x1c37}
,
@@ -4510,7 +4742,9 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1c4d, 0x1c7f}
,
- {0x1cd0, 0x1cf2}
+ {0x1cc0, 0x1cc7}
+ ,
+ {0x1cd0, 0x1cf6}
,
{0x1d00, 0x1de6}
,
@@ -4570,11 +4804,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x2460, 0x26ff}
,
- {0x2701, 0x27ca}
- ,
- {0x27cc, 0x27cc}
- ,
- {0x27ce, 0x2b4c}
+ {0x2701, 0x2b4c}
,
{0x2b50, 0x2b59}
,
@@ -4582,11 +4812,15 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x2c30, 0x2c5e}
,
- {0x2c60, 0x2cf1}
+ {0x2c60, 0x2cf3}
,
{0x2cf9, 0x2d25}
,
- {0x2d30, 0x2d65}
+ {0x2d27, 0x2d27}
+ ,
+ {0x2d2d, 0x2d2d}
+ ,
+ {0x2d30, 0x2d67}
,
{0x2d6f, 0x2d70}
,
@@ -4608,7 +4842,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x2dd8, 0x2dde}
,
- {0x2de0, 0x2e31}
+ {0x2de0, 0x2e3b}
,
{0x2e80, 0x2e99}
,
@@ -4638,7 +4872,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x3300, 0x4db5}
,
- {0x4dc0, 0x9fcb}
+ {0x4dc0, 0x9fcc}
,
{0xa000, 0xa48c}
,
@@ -4646,19 +4880,17 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0xa4d0, 0xa62b}
,
- {0xa640, 0xa673}
- ,
- {0xa67c, 0xa697}
+ {0xa640, 0xa697}
,
- {0xa6a0, 0xa6f7}
+ {0xa69f, 0xa6f7}
,
{0xa700, 0xa78e}
,
- {0xa790, 0xa791}
+ {0xa790, 0xa793}
,
- {0xa7a0, 0xa7a9}
+ {0xa7a0, 0xa7aa}
,
- {0xa7fa, 0xa82b}
+ {0xa7f8, 0xa82b}
,
{0xa830, 0xa839}
,
@@ -4690,7 +4922,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0xaa80, 0xaac2}
,
- {0xaadb, 0xaadf}
+ {0xaadb, 0xaaf6}
,
{0xab01, 0xab06}
,
@@ -4712,9 +4944,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0xd7cb, 0xd7fb}
,
- {0xf900, 0xfa2d}
- ,
- {0xfa30, 0xfa6d}
+ {0xf900, 0xfa6d}
,
{0xfa70, 0xfad9}
,
@@ -4836,6 +5066,10 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1093f, 0x1093f}
,
+ {0x10980, 0x109b7}
+ ,
+ {0x109be, 0x109bf}
+ ,
{0x10a00, 0x10a03}
,
{0x10a05, 0x10a06}
@@ -4874,6 +5108,22 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x110be, 0x110c1}
,
+ {0x110d0, 0x110e8}
+ ,
+ {0x110f0, 0x110f9}
+ ,
+ {0x11100, 0x11134}
+ ,
+ {0x11136, 0x11143}
+ ,
+ {0x11180, 0x111c8}
+ ,
+ {0x111d0, 0x111d9}
+ ,
+ {0x11680, 0x116b7}
+ ,
+ {0x116c0, 0x116c9}
+ ,
{0x12000, 0x1236e}
,
{0x12400, 0x12462}
@@ -4884,6 +5134,12 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x16800, 0x16a38}
,
+ {0x16f00, 0x16f44}
+ ,
+ {0x16f50, 0x16f7e}
+ ,
+ {0x16f8f, 0x16f9f}
+ ,
{0x1b000, 0x1b001}
,
{0x1d000, 0x1d0f5}
@@ -4942,6 +5198,74 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1d7ce, 0x1d7ff}
,
+ {0x1ee00, 0x1ee03}
+ ,
+ {0x1ee05, 0x1ee1f}
+ ,
+ {0x1ee21, 0x1ee22}
+ ,
+ {0x1ee24, 0x1ee24}
+ ,
+ {0x1ee27, 0x1ee27}
+ ,
+ {0x1ee29, 0x1ee32}
+ ,
+ {0x1ee34, 0x1ee37}
+ ,
+ {0x1ee39, 0x1ee39}
+ ,
+ {0x1ee3b, 0x1ee3b}
+ ,
+ {0x1ee42, 0x1ee42}
+ ,
+ {0x1ee47, 0x1ee47}
+ ,
+ {0x1ee49, 0x1ee49}
+ ,
+ {0x1ee4b, 0x1ee4b}
+ ,
+ {0x1ee4d, 0x1ee4f}
+ ,
+ {0x1ee51, 0x1ee52}
+ ,
+ {0x1ee54, 0x1ee54}
+ ,
+ {0x1ee57, 0x1ee57}
+ ,
+ {0x1ee59, 0x1ee59}
+ ,
+ {0x1ee5b, 0x1ee5b}
+ ,
+ {0x1ee5d, 0x1ee5d}
+ ,
+ {0x1ee5f, 0x1ee5f}
+ ,
+ {0x1ee61, 0x1ee62}
+ ,
+ {0x1ee64, 0x1ee64}
+ ,
+ {0x1ee67, 0x1ee6a}
+ ,
+ {0x1ee6c, 0x1ee72}
+ ,
+ {0x1ee74, 0x1ee77}
+ ,
+ {0x1ee79, 0x1ee7c}
+ ,
+ {0x1ee7e, 0x1ee7e}
+ ,
+ {0x1ee80, 0x1ee89}
+ ,
+ {0x1ee8b, 0x1ee9b}
+ ,
+ {0x1eea1, 0x1eea3}
+ ,
+ {0x1eea5, 0x1eea9}
+ ,
+ {0x1eeab, 0x1eebb}
+ ,
+ {0x1eef0, 0x1eef1}
+ ,
{0x1f000, 0x1f02b}
,
{0x1f030, 0x1f093}
@@ -4958,7 +5282,7 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1f110, 0x1f12e}
,
- {0x1f130, 0x1f169}
+ {0x1f130, 0x1f16b}
,
{0x1f170, 0x1f19a}
,
@@ -4994,31 +5318,11 @@ scm_t_char_range cs_graphic_ranges[] = {
,
{0x1f500, 0x1f53d}
,
- {0x1f550, 0x1f567}
- ,
- {0x1f5fb, 0x1f5ff}
- ,
- {0x1f601, 0x1f610}
+ {0x1f540, 0x1f543}
,
- {0x1f612, 0x1f614}
- ,
- {0x1f616, 0x1f616}
- ,
- {0x1f618, 0x1f618}
- ,
- {0x1f61a, 0x1f61a}
- ,
- {0x1f61c, 0x1f61e}
- ,
- {0x1f620, 0x1f625}
- ,
- {0x1f628, 0x1f62b}
- ,
- {0x1f62d, 0x1f62d}
- ,
- {0x1f630, 0x1f633}
+ {0x1f550, 0x1f567}
,
- {0x1f635, 0x1f640}
+ {0x1f5fb, 0x1f640}
,
{0x1f645, 0x1f64f}
,
@@ -5038,7 +5342,7 @@ scm_t_char_range cs_graphic_ranges[] = {
};
scm_t_char_set cs_graphic = {
- 503,
+ 540,
cs_graphic_ranges
};
@@ -5096,6 +5400,8 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x0589, 0x058a}
,
+ {0x058f, 0x058f}
+ ,
{0x0591, 0x05c7}
,
{0x05d0, 0x05ea}
@@ -5122,6 +5428,12 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x085e, 0x085e}
,
+ {0x08a0, 0x08a0}
+ ,
+ {0x08a2, 0x08ac}
+ ,
+ {0x08e4, 0x08fe}
+ ,
{0x0900, 0x0977}
,
{0x0979, 0x097f}
@@ -5210,9 +5522,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x0ae0, 0x0ae3}
,
- {0x0ae6, 0x0aef}
- ,
- {0x0af1, 0x0af1}
+ {0x0ae6, 0x0af1}
,
{0x0b01, 0x0b03}
,
@@ -5412,7 +5722,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x0ed0, 0x0ed9}
,
- {0x0edc, 0x0edd}
+ {0x0edc, 0x0edf}
,
{0x0f00, 0x0f47}
,
@@ -5428,9 +5738,11 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1000, 0x10c5}
,
- {0x10d0, 0x10fc}
+ {0x10c7, 0x10c7}
,
- {0x1100, 0x1248}
+ {0x10cd, 0x10cd}
+ ,
+ {0x10d0, 0x1248}
,
{0x124a, 0x124d}
,
@@ -5486,9 +5798,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1772, 0x1773}
,
- {0x1780, 0x17b3}
- ,
- {0x17b6, 0x17dd}
+ {0x1780, 0x17dd}
,
{0x17e0, 0x17e9}
,
@@ -5538,11 +5848,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1b50, 0x1b7c}
,
- {0x1b80, 0x1baa}
- ,
- {0x1bae, 0x1bb9}
- ,
- {0x1bc0, 0x1bf3}
+ {0x1b80, 0x1bf3}
,
{0x1bfc, 0x1c37}
,
@@ -5550,7 +5856,9 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1c4d, 0x1c7f}
,
- {0x1cd0, 0x1cf2}
+ {0x1cc0, 0x1cc7}
+ ,
+ {0x1cd0, 0x1cf6}
,
{0x1d00, 0x1de6}
,
@@ -5612,11 +5920,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x2460, 0x26ff}
,
- {0x2701, 0x27ca}
- ,
- {0x27cc, 0x27cc}
- ,
- {0x27ce, 0x2b4c}
+ {0x2701, 0x2b4c}
,
{0x2b50, 0x2b59}
,
@@ -5624,11 +5928,15 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x2c30, 0x2c5e}
,
- {0x2c60, 0x2cf1}
+ {0x2c60, 0x2cf3}
,
{0x2cf9, 0x2d25}
,
- {0x2d30, 0x2d65}
+ {0x2d27, 0x2d27}
+ ,
+ {0x2d2d, 0x2d2d}
+ ,
+ {0x2d30, 0x2d67}
,
{0x2d6f, 0x2d70}
,
@@ -5650,7 +5958,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x2dd8, 0x2dde}
,
- {0x2de0, 0x2e31}
+ {0x2de0, 0x2e3b}
,
{0x2e80, 0x2e99}
,
@@ -5680,7 +5988,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x3300, 0x4db5}
,
- {0x4dc0, 0x9fcb}
+ {0x4dc0, 0x9fcc}
,
{0xa000, 0xa48c}
,
@@ -5688,19 +5996,17 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0xa4d0, 0xa62b}
,
- {0xa640, 0xa673}
- ,
- {0xa67c, 0xa697}
+ {0xa640, 0xa697}
,
- {0xa6a0, 0xa6f7}
+ {0xa69f, 0xa6f7}
,
{0xa700, 0xa78e}
,
- {0xa790, 0xa791}
+ {0xa790, 0xa793}
,
- {0xa7a0, 0xa7a9}
+ {0xa7a0, 0xa7aa}
,
- {0xa7fa, 0xa82b}
+ {0xa7f8, 0xa82b}
,
{0xa830, 0xa839}
,
@@ -5732,7 +6038,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0xaa80, 0xaac2}
,
- {0xaadb, 0xaadf}
+ {0xaadb, 0xaaf6}
,
{0xab01, 0xab06}
,
@@ -5754,9 +6060,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0xd7cb, 0xd7fb}
,
- {0xf900, 0xfa2d}
- ,
- {0xfa30, 0xfa6d}
+ {0xf900, 0xfa6d}
,
{0xfa70, 0xfad9}
,
@@ -5878,6 +6182,10 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1093f, 0x1093f}
,
+ {0x10980, 0x109b7}
+ ,
+ {0x109be, 0x109bf}
+ ,
{0x10a00, 0x10a03}
,
{0x10a05, 0x10a06}
@@ -5916,6 +6224,22 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x110be, 0x110c1}
,
+ {0x110d0, 0x110e8}
+ ,
+ {0x110f0, 0x110f9}
+ ,
+ {0x11100, 0x11134}
+ ,
+ {0x11136, 0x11143}
+ ,
+ {0x11180, 0x111c8}
+ ,
+ {0x111d0, 0x111d9}
+ ,
+ {0x11680, 0x116b7}
+ ,
+ {0x116c0, 0x116c9}
+ ,
{0x12000, 0x1236e}
,
{0x12400, 0x12462}
@@ -5926,6 +6250,12 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x16800, 0x16a38}
,
+ {0x16f00, 0x16f44}
+ ,
+ {0x16f50, 0x16f7e}
+ ,
+ {0x16f8f, 0x16f9f}
+ ,
{0x1b000, 0x1b001}
,
{0x1d000, 0x1d0f5}
@@ -5984,6 +6314,74 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1d7ce, 0x1d7ff}
,
+ {0x1ee00, 0x1ee03}
+ ,
+ {0x1ee05, 0x1ee1f}
+ ,
+ {0x1ee21, 0x1ee22}
+ ,
+ {0x1ee24, 0x1ee24}
+ ,
+ {0x1ee27, 0x1ee27}
+ ,
+ {0x1ee29, 0x1ee32}
+ ,
+ {0x1ee34, 0x1ee37}
+ ,
+ {0x1ee39, 0x1ee39}
+ ,
+ {0x1ee3b, 0x1ee3b}
+ ,
+ {0x1ee42, 0x1ee42}
+ ,
+ {0x1ee47, 0x1ee47}
+ ,
+ {0x1ee49, 0x1ee49}
+ ,
+ {0x1ee4b, 0x1ee4b}
+ ,
+ {0x1ee4d, 0x1ee4f}
+ ,
+ {0x1ee51, 0x1ee52}
+ ,
+ {0x1ee54, 0x1ee54}
+ ,
+ {0x1ee57, 0x1ee57}
+ ,
+ {0x1ee59, 0x1ee59}
+ ,
+ {0x1ee5b, 0x1ee5b}
+ ,
+ {0x1ee5d, 0x1ee5d}
+ ,
+ {0x1ee5f, 0x1ee5f}
+ ,
+ {0x1ee61, 0x1ee62}
+ ,
+ {0x1ee64, 0x1ee64}
+ ,
+ {0x1ee67, 0x1ee6a}
+ ,
+ {0x1ee6c, 0x1ee72}
+ ,
+ {0x1ee74, 0x1ee77}
+ ,
+ {0x1ee79, 0x1ee7c}
+ ,
+ {0x1ee7e, 0x1ee7e}
+ ,
+ {0x1ee80, 0x1ee89}
+ ,
+ {0x1ee8b, 0x1ee9b}
+ ,
+ {0x1eea1, 0x1eea3}
+ ,
+ {0x1eea5, 0x1eea9}
+ ,
+ {0x1eeab, 0x1eebb}
+ ,
+ {0x1eef0, 0x1eef1}
+ ,
{0x1f000, 0x1f02b}
,
{0x1f030, 0x1f093}
@@ -6000,7 +6398,7 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1f110, 0x1f12e}
,
- {0x1f130, 0x1f169}
+ {0x1f130, 0x1f16b}
,
{0x1f170, 0x1f19a}
,
@@ -6036,31 +6434,11 @@ scm_t_char_range cs_printing_ranges[] = {
,
{0x1f500, 0x1f53d}
,
- {0x1f550, 0x1f567}
- ,
- {0x1f5fb, 0x1f5ff}
- ,
- {0x1f601, 0x1f610}
- ,
- {0x1f612, 0x1f614}
- ,
- {0x1f616, 0x1f616}
- ,
- {0x1f618, 0x1f618}
- ,
- {0x1f61a, 0x1f61a}
- ,
- {0x1f61c, 0x1f61e}
- ,
- {0x1f620, 0x1f625}
+ {0x1f540, 0x1f543}
,
- {0x1f628, 0x1f62b}
- ,
- {0x1f62d, 0x1f62d}
- ,
- {0x1f630, 0x1f633}
+ {0x1f550, 0x1f567}
,
- {0x1f635, 0x1f640}
+ {0x1f5fb, 0x1f640}
,
{0x1f645, 0x1f64f}
,
@@ -6080,7 +6458,7 @@ scm_t_char_range cs_printing_ranges[] = {
};
scm_t_char_set cs_printing = {
- 504,
+ 541,
cs_printing_ranges
};
@@ -6116,9 +6494,11 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0x00a1, 0x00a1}
,
+ {0x00a7, 0x00a7}
+ ,
{0x00ab, 0x00ab}
,
- {0x00b7, 0x00b7}
+ {0x00b6, 0x00b7}
,
{0x00bb, 0x00bb}
,
@@ -6166,6 +6546,8 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0x0970, 0x0970}
,
+ {0x0af0, 0x0af0}
+ ,
{0x0df4, 0x0df4}
,
{0x0e4f, 0x0e4f}
@@ -6174,6 +6556,8 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0x0f04, 0x0f12}
,
+ {0x0f14, 0x0f14}
+ ,
{0x0f3a, 0x0f3d}
,
{0x0f85, 0x0f85}
@@ -6186,7 +6570,7 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0x10fb, 0x10fb}
,
- {0x1361, 0x1368}
+ {0x1360, 0x1368}
,
{0x1400, 0x1400}
,
@@ -6220,6 +6604,8 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0x1c7e, 0x1c7f}
,
+ {0x1cc0, 0x1cc7}
+ ,
{0x1cd3, 0x1cd3}
,
{0x2010, 0x2027}
@@ -6256,7 +6642,7 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0x2e00, 0x2e2e}
,
- {0x2e30, 0x2e31}
+ {0x2e30, 0x2e3b}
,
{0x3001, 0x3003}
,
@@ -6300,6 +6686,8 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0xaade, 0xaadf}
,
+ {0xaaf0, 0xaaf1}
+ ,
{0xabeb, 0xabeb}
,
{0xfd3e, 0xfd3f}
@@ -6336,7 +6724,7 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0xff5f, 0xff65}
,
- {0x10100, 0x10101}
+ {0x10100, 0x10102}
,
{0x1039f, 0x1039f}
,
@@ -6360,11 +6748,15 @@ scm_t_char_range cs_punctuation_ranges[] = {
,
{0x110be, 0x110c1}
,
+ {0x11140, 0x11143}
+ ,
+ {0x111c5, 0x111c8}
+ ,
{0x12470, 0x12473}
};
scm_t_char_set cs_punctuation = {
- 133,
+ 140,
cs_punctuation_ranges
};
@@ -6383,7 +6775,9 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x007e, 0x007e}
,
- {0x00a2, 0x00a9}
+ {0x00a2, 0x00a6}
+ ,
+ {0x00a8, 0x00a9}
,
{0x00ac, 0x00ac}
,
@@ -6391,8 +6785,6 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x00b4, 0x00b4}
,
- {0x00b6, 0x00b6}
- ,
{0x00b8, 0x00b8}
,
{0x00d7, 0x00d7}
@@ -6417,6 +6809,8 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x0482, 0x0482}
,
+ {0x058f, 0x058f}
+ ,
{0x0606, 0x0608}
,
{0x060b, 0x060b}
@@ -6449,7 +6843,9 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x0f01, 0x0f03}
,
- {0x0f13, 0x0f17}
+ {0x0f13, 0x0f13}
+ ,
+ {0x0f15, 0x0f17}
,
{0x0f1a, 0x0f1f}
,
@@ -6469,8 +6865,6 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x109e, 0x109f}
,
- {0x1360, 0x1360}
- ,
{0x1390, 0x1399}
,
{0x17db, 0x17db}
@@ -6549,11 +6943,7 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x2794, 0x27c4}
,
- {0x27c7, 0x27ca}
- ,
- {0x27cc, 0x27cc}
- ,
- {0x27ce, 0x27e5}
+ {0x27c7, 0x27e5}
,
{0x27f0, 0x2982}
,
@@ -6595,7 +6985,9 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x3200, 0x321e}
,
- {0x322a, 0x3250}
+ {0x322a, 0x3247}
+ ,
+ {0x3250, 0x3250}
,
{0x3260, 0x327f}
,
@@ -6653,8 +7045,6 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0xfffc, 0xfffd}
,
- {0x10102, 0x10102}
- ,
{0x10137, 0x1013f}
,
{0x10179, 0x10189}
@@ -6703,6 +7093,8 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x1d7c3, 0x1d7c3}
,
+ {0x1eef0, 0x1eef1}
+ ,
{0x1f000, 0x1f02b}
,
{0x1f030, 0x1f093}
@@ -6717,7 +7109,7 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x1f110, 0x1f12e}
,
- {0x1f130, 0x1f169}
+ {0x1f130, 0x1f16b}
,
{0x1f170, 0x1f19a}
,
@@ -6753,31 +7145,11 @@ scm_t_char_range cs_symbol_ranges[] = {
,
{0x1f500, 0x1f53d}
,
- {0x1f550, 0x1f567}
- ,
- {0x1f5fb, 0x1f5ff}
- ,
- {0x1f601, 0x1f610}
- ,
- {0x1f612, 0x1f614}
+ {0x1f540, 0x1f543}
,
- {0x1f616, 0x1f616}
- ,
- {0x1f618, 0x1f618}
- ,
- {0x1f61a, 0x1f61a}
- ,
- {0x1f61c, 0x1f61e}
- ,
- {0x1f620, 0x1f625}
- ,
- {0x1f628, 0x1f62b}
- ,
- {0x1f62d, 0x1f62d}
- ,
- {0x1f630, 0x1f633}
+ {0x1f550, 0x1f567}
,
- {0x1f635, 0x1f640}
+ {0x1f5fb, 0x1f640}
,
{0x1f645, 0x1f64f}
,
@@ -6787,7 +7159,7 @@ scm_t_char_range cs_symbol_ranges[] = {
};
scm_t_char_set cs_symbol = {
- 208,
+ 198,
cs_symbol_ranges
};
@@ -6854,13 +7226,15 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x0589, 0x058a}
,
+ {0x058f, 0x058f}
+ ,
{0x0591, 0x05c7}
,
{0x05d0, 0x05ea}
,
{0x05f0, 0x05f4}
,
- {0x0600, 0x0603}
+ {0x0600, 0x0604}
,
{0x0606, 0x061b}
,
@@ -6880,6 +7254,12 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x085e, 0x085e}
,
+ {0x08a0, 0x08a0}
+ ,
+ {0x08a2, 0x08ac}
+ ,
+ {0x08e4, 0x08fe}
+ ,
{0x0900, 0x0977}
,
{0x0979, 0x097f}
@@ -6968,9 +7348,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x0ae0, 0x0ae3}
,
- {0x0ae6, 0x0aef}
- ,
- {0x0af1, 0x0af1}
+ {0x0ae6, 0x0af1}
,
{0x0b01, 0x0b03}
,
@@ -7170,7 +7548,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x0ed0, 0x0ed9}
,
- {0x0edc, 0x0edd}
+ {0x0edc, 0x0edf}
,
{0x0f00, 0x0f47}
,
@@ -7186,9 +7564,11 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x1000, 0x10c5}
,
- {0x10d0, 0x10fc}
+ {0x10c7, 0x10c7}
,
- {0x1100, 0x1248}
+ {0x10cd, 0x10cd}
+ ,
+ {0x10d0, 0x1248}
,
{0x124a, 0x124d}
,
@@ -7294,11 +7674,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x1b50, 0x1b7c}
,
- {0x1b80, 0x1baa}
- ,
- {0x1bae, 0x1bb9}
- ,
- {0x1bc0, 0x1bf3}
+ {0x1b80, 0x1bf3}
,
{0x1bfc, 0x1c37}
,
@@ -7306,7 +7682,9 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x1c4d, 0x1c7f}
,
- {0x1cd0, 0x1cf2}
+ {0x1cc0, 0x1cc7}
+ ,
+ {0x1cd0, 0x1cf6}
,
{0x1d00, 0x1de6}
,
@@ -7364,11 +7742,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x2460, 0x26ff}
,
- {0x2701, 0x27ca}
- ,
- {0x27cc, 0x27cc}
- ,
- {0x27ce, 0x2b4c}
+ {0x2701, 0x2b4c}
,
{0x2b50, 0x2b59}
,
@@ -7376,11 +7750,15 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x2c30, 0x2c5e}
,
- {0x2c60, 0x2cf1}
+ {0x2c60, 0x2cf3}
,
{0x2cf9, 0x2d25}
,
- {0x2d30, 0x2d65}
+ {0x2d27, 0x2d27}
+ ,
+ {0x2d2d, 0x2d2d}
+ ,
+ {0x2d30, 0x2d67}
,
{0x2d6f, 0x2d70}
,
@@ -7402,7 +7780,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x2dd8, 0x2dde}
,
- {0x2de0, 0x2e31}
+ {0x2de0, 0x2e3b}
,
{0x2e80, 0x2e99}
,
@@ -7432,7 +7810,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x3300, 0x4db5}
,
- {0x4dc0, 0x9fcb}
+ {0x4dc0, 0x9fcc}
,
{0xa000, 0xa48c}
,
@@ -7440,19 +7818,17 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0xa4d0, 0xa62b}
,
- {0xa640, 0xa673}
- ,
- {0xa67c, 0xa697}
+ {0xa640, 0xa697}
,
- {0xa6a0, 0xa6f7}
+ {0xa69f, 0xa6f7}
,
{0xa700, 0xa78e}
,
- {0xa790, 0xa791}
+ {0xa790, 0xa793}
,
- {0xa7a0, 0xa7a9}
+ {0xa7a0, 0xa7aa}
,
- {0xa7fa, 0xa82b}
+ {0xa7f8, 0xa82b}
,
{0xa830, 0xa839}
,
@@ -7484,7 +7860,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0xaa80, 0xaac2}
,
- {0xaadb, 0xaadf}
+ {0xaadb, 0xaaf6}
,
{0xab01, 0xab06}
,
@@ -7506,9 +7882,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0xd7cb, 0xd7fb}
,
- {0xe000, 0xfa2d}
- ,
- {0xfa30, 0xfa6d}
+ {0xe000, 0xfa6d}
,
{0xfa70, 0xfad9}
,
@@ -7632,6 +8006,10 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x1093f, 0x1093f}
,
+ {0x10980, 0x109b7}
+ ,
+ {0x109be, 0x109bf}
+ ,
{0x10a00, 0x10a03}
,
{0x10a05, 0x10a06}
@@ -7668,6 +8046,22 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x11080, 0x110c1}
,
+ {0x110d0, 0x110e8}
+ ,
+ {0x110f0, 0x110f9}
+ ,
+ {0x11100, 0x11134}
+ ,
+ {0x11136, 0x11143}
+ ,
+ {0x11180, 0x111c8}
+ ,
+ {0x111d0, 0x111d9}
+ ,
+ {0x11680, 0x116b7}
+ ,
+ {0x116c0, 0x116c9}
+ ,
{0x12000, 0x1236e}
,
{0x12400, 0x12462}
@@ -7678,6 +8072,12 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x16800, 0x16a38}
,
+ {0x16f00, 0x16f44}
+ ,
+ {0x16f50, 0x16f7e}
+ ,
+ {0x16f8f, 0x16f9f}
+ ,
{0x1b000, 0x1b001}
,
{0x1d000, 0x1d0f5}
@@ -7734,6 +8134,74 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x1d7ce, 0x1d7ff}
,
+ {0x1ee00, 0x1ee03}
+ ,
+ {0x1ee05, 0x1ee1f}
+ ,
+ {0x1ee21, 0x1ee22}
+ ,
+ {0x1ee24, 0x1ee24}
+ ,
+ {0x1ee27, 0x1ee27}
+ ,
+ {0x1ee29, 0x1ee32}
+ ,
+ {0x1ee34, 0x1ee37}
+ ,
+ {0x1ee39, 0x1ee39}
+ ,
+ {0x1ee3b, 0x1ee3b}
+ ,
+ {0x1ee42, 0x1ee42}
+ ,
+ {0x1ee47, 0x1ee47}
+ ,
+ {0x1ee49, 0x1ee49}
+ ,
+ {0x1ee4b, 0x1ee4b}
+ ,
+ {0x1ee4d, 0x1ee4f}
+ ,
+ {0x1ee51, 0x1ee52}
+ ,
+ {0x1ee54, 0x1ee54}
+ ,
+ {0x1ee57, 0x1ee57}
+ ,
+ {0x1ee59, 0x1ee59}
+ ,
+ {0x1ee5b, 0x1ee5b}
+ ,
+ {0x1ee5d, 0x1ee5d}
+ ,
+ {0x1ee5f, 0x1ee5f}
+ ,
+ {0x1ee61, 0x1ee62}
+ ,
+ {0x1ee64, 0x1ee64}
+ ,
+ {0x1ee67, 0x1ee6a}
+ ,
+ {0x1ee6c, 0x1ee72}
+ ,
+ {0x1ee74, 0x1ee77}
+ ,
+ {0x1ee79, 0x1ee7c}
+ ,
+ {0x1ee7e, 0x1ee7e}
+ ,
+ {0x1ee80, 0x1ee89}
+ ,
+ {0x1ee8b, 0x1ee9b}
+ ,
+ {0x1eea1, 0x1eea3}
+ ,
+ {0x1eea5, 0x1eea9}
+ ,
+ {0x1eeab, 0x1eebb}
+ ,
+ {0x1eef0, 0x1eef1}
+ ,
{0x1f000, 0x1f02b}
,
{0x1f030, 0x1f093}
@@ -7750,7 +8218,7 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x1f110, 0x1f12e}
,
- {0x1f130, 0x1f169}
+ {0x1f130, 0x1f16b}
,
{0x1f170, 0x1f19a}
,
@@ -7786,31 +8254,11 @@ scm_t_char_range cs_designated_ranges[] = {
,
{0x1f500, 0x1f53d}
,
- {0x1f550, 0x1f567}
- ,
- {0x1f5fb, 0x1f5ff}
- ,
- {0x1f601, 0x1f610}
- ,
- {0x1f612, 0x1f614}
- ,
- {0x1f616, 0x1f616}
- ,
- {0x1f618, 0x1f618}
+ {0x1f540, 0x1f543}
,
- {0x1f61a, 0x1f61a}
- ,
- {0x1f61c, 0x1f61e}
- ,
- {0x1f620, 0x1f625}
- ,
- {0x1f628, 0x1f62b}
- ,
- {0x1f62d, 0x1f62d}
- ,
- {0x1f630, 0x1f633}
+ {0x1f550, 0x1f567}
,
- {0x1f635, 0x1f640}
+ {0x1f5fb, 0x1f640}
,
{0x1f645, 0x1f64f}
,
@@ -7838,6 +8286,6 @@ scm_t_char_range cs_designated_ranges[] = {
};
scm_t_char_set cs_designated = {
- 501,
+ 539,
cs_designated_ranges
};
diff --git a/libguile/stacks.c b/libguile/stacks.c
index d0e82f7bd..9599554a2 100644
--- a/libguile/stacks.c
+++ b/libguile/stacks.c
@@ -225,7 +225,7 @@ SCM_DEFINE (scm_make_stack, "make-stack", 1, 0, 1,
"@code{(@var{inner_cut_1} @var{outer_cut_1} @var{inner_cut_2}\n"
"@var{outer_cut_2} @dots{})}.\n"
"\n"
- "Each @var{inner_cut_N} can be @code{#t}, an integer, a prompt\n"
+ "Each @var{inner_cut_i} can be @code{#t}, an integer, a prompt\n"
"tag, or a procedure. @code{#t} means to cut away all frames up\n"
"to but excluding the first user module frame. An integer means\n"
"to cut away exactly that number of frames. A prompt tag means\n"
@@ -234,14 +234,14 @@ SCM_DEFINE (scm_make_stack, "make-stack", 1, 0, 1,
"excluding the application frame whose procedure matches the\n"
"specified one.\n"
"\n"
- "Each @var{outer_cut_N} can be an integer, a prompt tag, or a\n"
+ "Each @var{outer_cut_i} can be an integer, a prompt tag, or a\n"
"procedure. An integer means to cut away that number of frames.\n"
"A prompt tag means to cut away all frames that are outside a\n"
"prompt with the given tag. A procedure means to cut away\n"
"frames down to but excluding the application frame whose\n"
"procedure matches the specified one.\n"
"\n"
- "If the @var{outer_cut_N} of the last pair is missing, it is\n"
+ "If the @var{outer_cut_i} of the last pair is missing, it is\n"
"taken as 0.")
#define FUNC_NAME s_scm_make_stack
{
diff --git a/libguile/stime.c b/libguile/stime.c
index dda82e720..7fdbba9a7 100644
--- a/libguile/stime.c
+++ b/libguile/stime.c
@@ -551,13 +551,14 @@ bdtime2c (SCM sbd_time, struct tm *lt, int pos, const char *subr)
SCM_DEFINE (scm_mktime, "mktime", 1, 1, 0,
(SCM sbd_time, SCM zone),
- "@var{bd-time} is an object representing broken down time and @code{zone}\n"
- "is an optional time zone specifier (otherwise the TZ environment variable\n"
- "or the system default is used).\n\n"
- "Returns a pair: the car is a corresponding\n"
- "integer time value like that returned\n"
- "by @code{current-time}; the cdr is a broken down time object, similar to\n"
- "as @var{bd-time} but with normalized values.")
+ "@var{sbd_time} is an object representing broken down time and\n"
+ "@code{zone} is an optional time zone specifier (otherwise the\n"
+ "TZ environment variable or the system default is used).\n"
+ "\n"
+ "Returns a pair: the car is a corresponding integer time value\n"
+ "like that returned by @code{current-time}; the cdr is a broken\n"
+ "down time object, similar to as @var{sbd_time} but with\n"
+ "normalized values.")
#define FUNC_NAME s_scm_mktime
{
timet itime;
@@ -763,7 +764,7 @@ SCM_DEFINE (scm_strptime, "strptime", 2, 0, 0,
(SCM format, SCM string),
"Performs the reverse action to @code{strftime}, parsing\n"
"@var{string} according to the specification supplied in\n"
- "@var{template}. The interpretation of month and day names is\n"
+ "@var{format}. The interpretation of month and day names is\n"
"dependent on the current locale. The value returned is a pair.\n"
"The car has an object with time components\n"
"in the form returned by @code{localtime} or @code{gmtime},\n"
diff --git a/libguile/strings.c b/libguile/strings.c
index cdd43e1b2..b216ec27a 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -1157,7 +1157,7 @@ SCM_DEFINE (scm_make_string, "make-string", 1, 1, 0,
"Return a newly allocated string of\n"
"length @var{k}. If @var{chr} is given, then all elements of\n"
"the string are initialized to @var{chr}, otherwise the contents\n"
- "of the @var{string} are all set to @var{#\nul}.")
+ "of the string are all set to @code{#\nul}.")
#define FUNC_NAME s_scm_make_string
{
return scm_c_make_string (scm_to_size_t (k), chr);
diff --git a/libguile/struct.c b/libguile/struct.c
index 73b2e4ddf..35e6c681f 100644
--- a/libguile/struct.c
+++ b/libguile/struct.c
@@ -528,9 +528,9 @@ scm_c_make_struct (SCM vtable, size_t n_tail, size_t n_init, scm_t_bits init, ..
SCM_DEFINE (scm_make_struct, "make-struct", 2, 0, 1,
(SCM vtable, SCM tail_array_size, SCM init),
"Create a new structure.\n\n"
- "@var{type} must be a vtable structure (@pxref{Vtables}).\n\n"
- "@var{tail-elts} must be a non-negative integer. If the layout\n"
- "specification indicated by @var{type} includes a tail-array,\n"
+ "@var{vtable} must be a vtable structure (@pxref{Vtables}).\n\n"
+ "@var{tail_array_size} must be a non-negative integer. If the layout\n"
+ "specification indicated by @var{vtable} includes a tail-array,\n"
"this is the number of elements allocated to that array.\n\n"
"The @var{init1}, @dots{} are optional arguments describing how\n"
"successive fields of the structure should be initialized. Only fields\n"
@@ -578,7 +578,7 @@ SCM_DEFINE (scm_make_vtable_vtable, "make-vtable-vtable", 2, 0, 1,
"@var{user-fields} is a string describing user defined fields of the\n"
"vtable beginning at index @code{vtable-offset-user}\n"
"(see @code{make-struct-layout}).\n\n"
- "@var{tail-size} specifies the size of the tail-array (if any) of\n"
+ "@var{tail_array_size} specifies the size of the tail-array (if any) of\n"
"this vtable.\n\n"
"@var{init1}, @dots{} are the optional initializers for the fields of\n"
"the vtable.\n\n"
@@ -771,10 +771,15 @@ scm_i_struct_equalp (SCM s1, SCM s2)
SCM_DEFINE (scm_struct_ref, "struct-ref", 2, 0, 0,
(SCM handle, SCM pos),
- "Access the @var{n}th field of @var{struct}.\n\n"
- "If the field is of type 'p', then it can be set to an arbitrary value.\n\n"
- "If the field is of type 'u', then it can only be set to a non-negative\n"
- "integer value small enough to fit in one machine word.")
+ "Access the @var{pos}th field of struct associated with\n"
+ "@var{handle}.\n"
+ "\n"
+ "If the field is of type 'p', then it can be set to an arbitrary\n"
+ "value.\n"
+ "\n"
+ "If the field is of type 'u', then it can only be set to a\n"
+ "non-negative integer value small enough to fit in one machine\n"
+ "word.")
#define FUNC_NAME s_scm_struct_ref
{
SCM vtable, answer = SCM_UNDEFINED;
@@ -943,7 +948,8 @@ SCM_DEFINE (scm_struct_set_x, "struct-set!", 3, 0, 0,
SCM_DEFINE (scm_struct_vtable, "struct-vtable", 1, 0, 0,
(SCM handle),
- "Return the vtable structure that describes the type of @var{struct}.")
+ "Return the vtable structure that describes the type of struct\n"
+ "associated with @var{handle}.")
#define FUNC_NAME s_scm_struct_vtable
{
SCM_VALIDATE_STRUCT (1, handle);
diff --git a/libguile/symbols.c b/libguile/symbols.c
index 9cb300ab0..fd7e21470 100644
--- a/libguile/symbols.c
+++ b/libguile/symbols.c
@@ -422,7 +422,7 @@ SCM_DEFINE (scm_symbol_hash, "symbol-hash", 1, 0, 0,
SCM_DEFINE (scm_symbol_fref, "symbol-fref", 1, 0, 0,
(SCM s),
- "Return the contents of @var{symbol}'s @dfn{function slot}.")
+ "Return the contents of the symbol @var{s}'s @dfn{function slot}.")
#define FUNC_NAME s_scm_symbol_fref
{
SCM_VALIDATE_SYMBOL (1, s);
@@ -433,7 +433,8 @@ SCM_DEFINE (scm_symbol_fref, "symbol-fref", 1, 0, 0,
SCM_DEFINE (scm_symbol_pref, "symbol-pref", 1, 0, 0,
(SCM s),
- "Return the @dfn{property list} currently associated with @var{symbol}.")
+ "Return the @dfn{property list} currently associated with the\n"
+ "symbol @var{s}.")
#define FUNC_NAME s_scm_symbol_pref
{
SCM_VALIDATE_SYMBOL (1, s);
@@ -444,7 +445,7 @@ SCM_DEFINE (scm_symbol_pref, "symbol-pref", 1, 0, 0,
SCM_DEFINE (scm_symbol_fset_x, "symbol-fset!", 2, 0, 0,
(SCM s, SCM val),
- "Change the binding of @var{symbol}'s function slot.")
+ "Change the binding of the symbol @var{s}'s function slot.")
#define FUNC_NAME s_scm_symbol_fset_x
{
SCM_VALIDATE_SYMBOL (1, s);
@@ -456,7 +457,7 @@ SCM_DEFINE (scm_symbol_fset_x, "symbol-fset!", 2, 0, 0,
SCM_DEFINE (scm_symbol_pset_x, "symbol-pset!", 2, 0, 0,
(SCM s, SCM val),
- "Change the binding of @var{symbol}'s property slot.")
+ "Change the binding of the symbol @var{s}'s property slot.")
#define FUNC_NAME s_scm_symbol_pset_x
{
SCM_VALIDATE_SYMBOL (1, s);
diff --git a/libguile/threads.c b/libguile/threads.c
index 463414f4a..d5c51eaf3 100644
--- a/libguile/threads.c
+++ b/libguile/threads.c
@@ -1471,11 +1471,12 @@ SCM scm_lock_mutex (SCM mx)
SCM_DEFINE (scm_lock_mutex_timed, "lock-mutex", 1, 2, 0,
(SCM m, SCM timeout, SCM owner),
-"Lock @var{mutex}. If the mutex is already locked, the calling thread "
-"blocks until the mutex becomes available. The function returns when "
-"the calling thread owns the lock on @var{mutex}. Locking a mutex that "
-"a thread already owns will succeed right away and will not block the "
-"thread. That is, Guile's mutexes are @emph{recursive}. ")
+ "Lock mutex @var{m}. If the mutex is already locked, the calling\n"
+ "thread blocks until the mutex becomes available. The function\n"
+ "returns when the calling thread owns the lock on @var{m}.\n"
+ "Locking a mutex that a thread already owns will succeed right\n"
+ "away and will not block the thread. That is, Guile's mutexes\n"
+ "are @emph{recursive}.")
#define FUNC_NAME s_scm_lock_mutex_timed
{
SCM exception;
@@ -1784,9 +1785,9 @@ SCM_DEFINE (scm_make_condition_variable, "make-condition-variable", 0, 0, 0,
SCM_DEFINE (scm_timed_wait_condition_variable, "wait-condition-variable", 2, 1, 0,
(SCM cv, SCM mx, SCM t),
-"Wait until @var{cond-var} has been signalled. While waiting, "
-"@var{mutex} is atomically unlocked (as with @code{unlock-mutex}) and "
-"is locked again when this function returns. When @var{time} is given, "
+"Wait until condition variable @var{cv} has been signalled. While waiting, "
+"mutex @var{mx} is atomically unlocked (as with @code{unlock-mutex}) and "
+"is locked again when this function returns. When @var{t} is given, "
"it specifies a point in time where the waiting should be aborted. It "
"can be either a integer as returned by @code{current-time} or a pair "
"as returned by @code{gettimeofday}. When the waiting is aborted the "
diff --git a/m4/btowc.m4 b/m4/btowc.m4
new file mode 100644
index 000000000..e565321ce
--- /dev/null
+++ b/m4/btowc.m4
@@ -0,0 +1,116 @@
+# btowc.m4 serial 10
+dnl Copyright (C) 2008-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_BTOWC],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+ dnl Check whether <wchar.h> is usable at all, first. Otherwise the test
+ dnl program below may lead to an endless loop. See
+ dnl <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42440>.
+ AC_REQUIRE([gl_WCHAR_H_INLINE_OK])
+
+ AC_CHECK_FUNCS_ONCE([btowc])
+ if test $ac_cv_func_btowc = no; then
+ HAVE_BTOWC=0
+ else
+
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_FR])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+
+ dnl Cygwin 1.7.2 btowc('\0') is WEOF, not 0.
+ AC_CACHE_CHECK([whether btowc(0) is correct],
+ [gl_cv_func_btowc_nul],
+ [
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ if (btowc ('\0') != 0)
+ return 1;
+ return 0;
+}]])],
+ [gl_cv_func_btowc_nul=yes],
+ [gl_cv_func_btowc_nul=no],
+ [
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on Cygwin.
+ cygwin*) gl_cv_func_btowc_nul="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_btowc_nul="guessing yes" ;;
+ esac
+changequote([,])dnl
+ ])
+ ])
+
+ dnl IRIX 6.5 btowc(EOF) is 0xFF, not WEOF.
+ AC_CACHE_CHECK([whether btowc(EOF) is correct],
+ [gl_cv_func_btowc_eof],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on IRIX.
+ irix*) gl_cv_func_btowc_eof="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_btowc_eof="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_FR != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
+ {
+ if (btowc (EOF) != WEOF)
+ return 1;
+ }
+ return 0;
+}]])],
+ [gl_cv_func_btowc_eof=yes],
+ [gl_cv_func_btowc_eof=no],
+ [:])
+ fi
+ ])
+
+ case "$gl_cv_func_btowc_nul" in
+ *yes) ;;
+ *) REPLACE_BTOWC=1 ;;
+ esac
+ case "$gl_cv_func_btowc_eof" in
+ *yes) ;;
+ *) REPLACE_BTOWC=1 ;;
+ esac
+ fi
+])
+
+# Prerequisites of lib/btowc.c.
+AC_DEFUN([gl_PREREQ_BTOWC], [
+ :
+])
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index 8065a0553..fc7c54f24 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -27,7 +27,7 @@
# Specification in the form of a command-line invocation:
-# gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nproc open pipe2 putenv recv recvfrom rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
+# gnulib-tool --import --dir=. --local-dir=gnulib-local --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --lgpl=3 --no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept alignof alloca-opt announce-gen autobuild bind byteswap canonicalize-lgpl ceil close connect dirfd duplocale environ extensions flock floor fpieee frexp full-read full-write func gendocs getaddrinfo getpeername getsockname getsockopt git-version-gen gitlog-to-changelog gnu-web-doc-update gnupload havelib iconv_open-utf inet_ntop inet_pton isinf isnan ldexp lib-symbol-versions lib-symbol-visibility libunistring listen localcharset locale log1p maintainer-makefile malloc-gnu malloca nl_langinfo nproc open pipe2 putenv recv recvfrom regex rename send sendto setenv setsockopt shutdown socket stat-time stdlib strftime striconveh string sys_stat trunc verify vsnprintf warnings wchar
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([gnulib-local])
@@ -81,12 +81,14 @@ gl_MODULES([
maintainer-makefile
malloc-gnu
malloca
+ nl_langinfo
nproc
open
pipe2
putenv
recv
recvfrom
+ regex
rename
send
sendto
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 9ec19f03d..498c5fa04 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -48,6 +48,7 @@ AC_DEFUN([gl_EARLY],
AB_INIT
# Code from module binary-io:
# Code from module bind:
+ # Code from module btowc:
# Code from module byteswap:
# Code from module c-ctype:
# Code from module c-strcase:
@@ -108,6 +109,7 @@ AC_DEFUN([gl_EARLY],
# Code from module isnand-nolibm:
# Code from module isnanf:
# Code from module isnanl:
+ # Code from module langinfo:
# Code from module largefile:
AC_REQUIRE([AC_SYS_LARGEFILE])
# Code from module ldexp:
@@ -124,12 +126,16 @@ AC_DEFUN([gl_EARLY],
# Code from module malloc-posix:
# Code from module malloca:
# Code from module math:
+ # Code from module mbrtowc:
+ # Code from module mbsinit:
+ # Code from module mbtowc:
# Code from module memchr:
# Code from module msvc-inval:
# Code from module msvc-nothrow:
# Code from module multiarch:
# Code from module netdb:
# Code from module netinet_in:
+ # Code from module nl_langinfo:
# Code from module nocrash:
# Code from module nproc:
# Code from module open:
@@ -141,6 +147,7 @@ AC_DEFUN([gl_EARLY],
# Code from module readlink:
# Code from module recv:
# Code from module recvfrom:
+ # Code from module regex:
# Code from module rename:
# Code from module rmdir:
# Code from module safe-read:
@@ -173,9 +180,12 @@ AC_DEFUN([gl_EARLY],
# Code from module stdint:
# Code from module stdio:
# Code from module stdlib:
+ # Code from module strcase:
+ # Code from module streq:
# Code from module strftime:
# Code from module striconveh:
# Code from module string:
+ # Code from module strings:
# Code from module sys_file:
# Code from module sys_socket:
# Code from module sys_stat:
@@ -200,6 +210,8 @@ AC_DEFUN([gl_EARLY],
# Code from module vsnprintf:
# Code from module warnings:
# Code from module wchar:
+ # Code from module wcrtomb:
+ # Code from module wctype-h:
# Code from module write:
# Code from module xsize:
])
@@ -231,6 +243,12 @@ if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([bind])
fi
gl_SYS_SOCKET_MODULE_INDICATOR([bind])
+gl_FUNC_BTOWC
+if test $HAVE_BTOWC = 0 || test $REPLACE_BTOWC = 1; then
+ AC_LIBOBJ([btowc])
+ gl_PREREQ_BTOWC
+fi
+gl_WCHAR_MODULE_INDICATOR([btowc])
gl_BYTESWAP
gl_CANONICALIZE_LGPL
if test $HAVE_CANONICALIZE_FILE_NAME = 0 || test $REPLACE_CANONICALIZE_FILE_NAME = 1; then
@@ -406,6 +424,7 @@ if test $HAVE_ISNANL = 0 || test $REPLACE_ISNAN = 1; then
gl_PREREQ_ISNANL
fi
gl_MATH_MODULE_INDICATOR([isnanl])
+gl_LANGINFO_H
gl_FUNC_LDEXP
gl_LD_VERSION_SCRIPT
gl_VISIBILITY
@@ -440,6 +459,24 @@ fi
gl_STDLIB_MODULE_INDICATOR([malloc-posix])
gl_MALLOCA
gl_MATH_H
+gl_FUNC_MBRTOWC
+if test $HAVE_MBRTOWC = 0 || test $REPLACE_MBRTOWC = 1; then
+ AC_LIBOBJ([mbrtowc])
+ gl_PREREQ_MBRTOWC
+fi
+gl_WCHAR_MODULE_INDICATOR([mbrtowc])
+gl_FUNC_MBSINIT
+if test $HAVE_MBSINIT = 0 || test $REPLACE_MBSINIT = 1; then
+ AC_LIBOBJ([mbsinit])
+ gl_PREREQ_MBSINIT
+fi
+gl_WCHAR_MODULE_INDICATOR([mbsinit])
+gl_FUNC_MBTOWC
+if test $REPLACE_MBTOWC = 1; then
+ AC_LIBOBJ([mbtowc])
+ gl_PREREQ_MBTOWC
+fi
+gl_STDLIB_MODULE_INDICATOR([mbtowc])
gl_FUNC_MEMCHR
if test $HAVE_MEMCHR = 0 || test $REPLACE_MEMCHR = 1; then
AC_LIBOBJ([memchr])
@@ -458,6 +495,11 @@ gl_MULTIARCH
gl_HEADER_NETDB
gl_HEADER_NETINET_IN
AC_PROG_MKDIR_P
+gl_FUNC_NL_LANGINFO
+if test $HAVE_NL_LANGINFO = 0 || test $REPLACE_NL_LANGINFO = 1; then
+ AC_LIBOBJ([nl_langinfo])
+fi
+gl_LANGINFO_MODULE_INDICATOR([nl_langinfo])
gl_NPROC
gl_FUNC_OPEN
if test $REPLACE_OPEN = 1; then
@@ -501,6 +543,11 @@ if test "$ac_cv_header_winsock2_h" = yes; then
AC_LIBOBJ([recvfrom])
fi
gl_SYS_SOCKET_MODULE_INDICATOR([recvfrom])
+gl_REGEX
+if test $ac_use_included_regex = yes; then
+ AC_LIBOBJ([regex])
+ gl_PREREQ_REGEX
+fi
gl_FUNC_RENAME
if test $REPLACE_RENAME = 1; then
AC_LIBOBJ([rename])
@@ -576,12 +623,22 @@ gl_STDDEF_H
gl_STDINT_H
gl_STDIO_H
gl_STDLIB_H
+gl_STRCASE
+if test $HAVE_STRCASECMP = 0; then
+ AC_LIBOBJ([strcasecmp])
+ gl_PREREQ_STRCASECMP
+fi
+if test $HAVE_STRNCASECMP = 0; then
+ AC_LIBOBJ([strncasecmp])
+ gl_PREREQ_STRNCASECMP
+fi
gl_FUNC_GNU_STRFTIME
if test $gl_cond_libtool = false; then
gl_ltlibdeps="$gl_ltlibdeps $LTLIBICONV"
gl_libdeps="$gl_libdeps $LIBICONV"
fi
gl_HEADER_STRING_H
+gl_HEADER_STRINGS_H
gl_HEADER_SYS_FILE_H
AC_PROG_MKDIR_P
gl_HEADER_SYS_SOCKET
@@ -623,6 +680,13 @@ gl_FUNC_VSNPRINTF
gl_STDIO_MODULE_INDICATOR([vsnprintf])
AC_SUBST([WARN_CFLAGS])
gl_WCHAR_H
+gl_FUNC_WCRTOMB
+if test $HAVE_WCRTOMB = 0 || test $REPLACE_WCRTOMB = 1; then
+ AC_LIBOBJ([wcrtomb])
+ gl_PREREQ_WCRTOMB
+fi
+gl_WCHAR_MODULE_INDICATOR([wcrtomb])
+gl_WCTYPE_H
gl_FUNC_WRITE
if test $REPLACE_WRITE = 1; then
AC_LIBOBJ([write])
@@ -789,6 +853,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/basename-lgpl.c
lib/binary-io.h
lib/bind.c
+ lib/btowc.c
lib/byteswap.in.h
lib/c-ctype.c
lib/c-ctype.h
@@ -847,6 +912,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/isnanf.c
lib/isnanl.c
lib/itold.c
+ lib/langinfo.in.h
lib/libunistring.valgrind
lib/listen.c
lib/localcharset.c
@@ -858,6 +924,10 @@ AC_DEFUN([gl_FILE_LIST], [
lib/malloca.h
lib/malloca.valgrind
lib/math.in.h
+ lib/mbrtowc.c
+ lib/mbsinit.c
+ lib/mbtowc-impl.h
+ lib/mbtowc.c
lib/memchr.c
lib/memchr.valgrind
lib/msvc-inval.c
@@ -866,6 +936,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/msvc-nothrow.h
lib/netdb.in.h
lib/netinet_in.in.h
+ lib/nl_langinfo.c
lib/nproc.c
lib/nproc.h
lib/open.c
@@ -883,6 +954,12 @@ AC_DEFUN([gl_FILE_LIST], [
lib/recvfrom.c
lib/ref-add.sin
lib/ref-del.sin
+ lib/regcomp.c
+ lib/regex.c
+ lib/regex.h
+ lib/regex_internal.c
+ lib/regex_internal.h
+ lib/regexec.c
lib/rename.c
lib/rmdir.c
lib/safe-read.c
@@ -909,12 +986,16 @@ AC_DEFUN([gl_FILE_LIST], [
lib/stdint.in.h
lib/stdio.in.h
lib/stdlib.in.h
+ lib/strcasecmp.c
+ lib/streq.h
lib/strftime.c
lib/strftime.h
lib/striconveh.c
lib/striconveh.h
lib/string.in.h
+ lib/strings.in.h
lib/stripslash.c
+ lib/strncasecmp.c
lib/sys_file.in.h
lib/sys_socket.in.h
lib/sys_stat.in.h
@@ -941,6 +1022,8 @@ AC_DEFUN([gl_FILE_LIST], [
lib/vsnprintf.c
lib/w32sock.h
lib/wchar.in.h
+ lib/wcrtomb.c
+ lib/wctype.in.h
lib/write.c
lib/xsize.h
m4/00gnulib.m4
@@ -948,6 +1031,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/alloca.m4
m4/arpa_inet_h.m4
m4/autobuild.m4
+ m4/btowc.m4
m4/byteswap.m4
m4/canonicalize.m4
m4/ceil.m4
@@ -995,6 +1079,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/isnand.m4
m4/isnanf.m4
m4/isnanl.m4
+ m4/langinfo_h.m4
m4/largefile.m4
m4/ld-version-script.m4
m4/ldexp.m4
@@ -1004,6 +1089,9 @@ AC_DEFUN([gl_FILE_LIST], [
m4/libunistring-base.m4
m4/libunistring.m4
m4/localcharset.m4
+ m4/locale-fr.m4
+ m4/locale-ja.m4
+ m4/locale-zh.m4
m4/locale_h.m4
m4/longlong.m4
m4/lstat.m4
@@ -1011,6 +1099,10 @@ AC_DEFUN([gl_FILE_LIST], [
m4/malloca.m4
m4/math_h.m4
m4/mathfunc.m4
+ m4/mbrtowc.m4
+ m4/mbsinit.m4
+ m4/mbstate_t.m4
+ m4/mbtowc.m4
m4/memchr.m4
m4/mmap-anon.m4
m4/mode_t.m4
@@ -1019,6 +1111,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/multiarch.m4
m4/netdb_h.m4
m4/netinet_in_h.m4
+ m4/nl_langinfo.m4
m4/nocrash.m4
m4/nproc.m4
m4/open.m4
@@ -1029,6 +1122,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/raise.m4
m4/read.m4
m4/readlink.m4
+ m4/regex.m4
m4/rename.m4
m4/rmdir.m4
m4/safe-read.m4
@@ -1052,8 +1146,10 @@ AC_DEFUN([gl_FILE_LIST], [
m4/stdint_h.m4
m4/stdio_h.m4
m4/stdlib_h.m4
+ m4/strcase.m4
m4/strftime.m4
m4/string_h.m4
+ m4/strings_h.m4
m4/sys_file_h.m4
m4/sys_socket_h.m4
m4/sys_stat_h.m4
@@ -1072,6 +1168,8 @@ AC_DEFUN([gl_FILE_LIST], [
m4/warnings.m4
m4/wchar_h.m4
m4/wchar_t.m4
+ m4/wcrtomb.m4
+ m4/wctype_h.m4
m4/wint_t.m4
m4/write.m4
m4/xsize.m4
diff --git a/m4/langinfo_h.m4 b/m4/langinfo_h.m4
new file mode 100644
index 000000000..b93fe7066
--- /dev/null
+++ b/m4/langinfo_h.m4
@@ -0,0 +1,105 @@
+# langinfo_h.m4 serial 7
+dnl Copyright (C) 2009-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_LANGINFO_H],
+[
+ AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
+
+ dnl Persuade glibc-2.0.6 <langinfo.h> to define CODESET.
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+ dnl <langinfo.h> is always overridden, because of GNULIB_POSIXCHECK.
+ gl_CHECK_NEXT_HEADERS([langinfo.h])
+
+ dnl Determine whether <langinfo.h> exists. It is missing on mingw and BeOS.
+ HAVE_LANGINFO_CODESET=0
+ HAVE_LANGINFO_T_FMT_AMPM=0
+ HAVE_LANGINFO_ERA=0
+ HAVE_LANGINFO_YESEXPR=0
+ AC_CHECK_HEADERS_ONCE([langinfo.h])
+ if test $ac_cv_header_langinfo_h = yes; then
+ HAVE_LANGINFO_H=1
+ dnl Determine what <langinfo.h> defines. CODESET and ERA etc. are missing
+ dnl on OpenBSD 3.8. T_FMT_AMPM and YESEXPR, NOEXPR are missing on IRIX 5.3.
+ AC_CACHE_CHECK([whether langinfo.h defines CODESET],
+ [gl_cv_header_langinfo_codeset],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[#include <langinfo.h>
+int a = CODESET;
+]])],
+ [gl_cv_header_langinfo_codeset=yes],
+ [gl_cv_header_langinfo_codeset=no])
+ ])
+ if test $gl_cv_header_langinfo_codeset = yes; then
+ HAVE_LANGINFO_CODESET=1
+ fi
+ AC_CACHE_CHECK([whether langinfo.h defines T_FMT_AMPM],
+ [gl_cv_header_langinfo_t_fmt_ampm],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[#include <langinfo.h>
+int a = T_FMT_AMPM;
+]])],
+ [gl_cv_header_langinfo_t_fmt_ampm=yes],
+ [gl_cv_header_langinfo_t_fmt_ampm=no])
+ ])
+ if test $gl_cv_header_langinfo_t_fmt_ampm = yes; then
+ HAVE_LANGINFO_T_FMT_AMPM=1
+ fi
+ AC_CACHE_CHECK([whether langinfo.h defines ERA],
+ [gl_cv_header_langinfo_era],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[#include <langinfo.h>
+int a = ERA;
+]])],
+ [gl_cv_header_langinfo_era=yes],
+ [gl_cv_header_langinfo_era=no])
+ ])
+ if test $gl_cv_header_langinfo_era = yes; then
+ HAVE_LANGINFO_ERA=1
+ fi
+ AC_CACHE_CHECK([whether langinfo.h defines YESEXPR],
+ [gl_cv_header_langinfo_yesexpr],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM([[#include <langinfo.h>
+int a = YESEXPR;
+]])],
+ [gl_cv_header_langinfo_yesexpr=yes],
+ [gl_cv_header_langinfo_yesexpr=no])
+ ])
+ if test $gl_cv_header_langinfo_yesexpr = yes; then
+ HAVE_LANGINFO_YESEXPR=1
+ fi
+ else
+ HAVE_LANGINFO_H=0
+ fi
+ AC_SUBST([HAVE_LANGINFO_H])
+ AC_SUBST([HAVE_LANGINFO_CODESET])
+ AC_SUBST([HAVE_LANGINFO_T_FMT_AMPM])
+ AC_SUBST([HAVE_LANGINFO_ERA])
+ AC_SUBST([HAVE_LANGINFO_YESEXPR])
+
+ dnl Check for declarations of anything we want to poison if the
+ dnl corresponding gnulib module is not in use.
+ gl_WARN_ON_USE_PREPARE([[#include <langinfo.h>
+ ]], [nl_langinfo])
+])
+
+AC_DEFUN([gl_LANGINFO_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
+ gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+ dnl Define it also as a C macro, for the benefit of the unit tests.
+ gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_LANGINFO_H_DEFAULTS],
+[
+ GNULIB_NL_LANGINFO=0; AC_SUBST([GNULIB_NL_LANGINFO])
+ dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE_NL_LANGINFO=1; AC_SUBST([HAVE_NL_LANGINFO])
+ REPLACE_NL_LANGINFO=0; AC_SUBST([REPLACE_NL_LANGINFO])
+])
diff --git a/m4/locale-fr.m4 b/m4/locale-fr.m4
new file mode 100644
index 000000000..4cb14b5f5
--- /dev/null
+++ b/m4/locale-fr.m4
@@ -0,0 +1,246 @@
+# locale-fr.m4 serial 14
+dnl Copyright (C) 2003, 2005-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl Determine the name of a french locale with traditional encoding.
+AC_DEFUN([gt_LOCALE_FR],
+[
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_REQUIRE([AM_LANGINFO_CODESET])
+ AC_CACHE_CHECK([for a traditional french locale], [gt_cv_locale_fr], [
+ AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main () {
+ /* Check whether the given locale name is recognized by the system. */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+ /* On native Windows, setlocale(category, "") looks at the system settings,
+ not at the environment variables. Also, when an encoding suffix such
+ as ".65001" or ".54936" is speficied, it succeeds but sets the LC_CTYPE
+ category of the locale to "C". */
+ if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
+ || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
+ return 1;
+#else
+ if (setlocale (LC_ALL, "") == NULL) return 1;
+#endif
+ /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+ On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+ is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+ On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+ succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+ some unit tests fail.
+ On MirBSD 10, when an unsupported locale is specified, setlocale()
+ succeeds but then nl_langinfo(CODESET) is "UTF-8". */
+#if HAVE_LANGINFO_CODESET
+ {
+ const char *cs = nl_langinfo (CODESET);
+ if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
+ || strcmp (cs, "UTF-8") == 0)
+ return 1;
+ }
+#endif
+#ifdef __CYGWIN__
+ /* On Cygwin, avoid locale names without encoding suffix, because the
+ locale_charset() function relies on the encoding suffix. Note that
+ LC_ALL is set on the command line. */
+ if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+ /* Check whether in the abbreviation of the second month, the second
+ character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is only
+ one byte long. This excludes the UTF-8 encoding. */
+ t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+ if (strftime (buf, sizeof (buf), "%b", &t) < 3 || buf[2] != 'v') return 1;
+ /* Check whether the decimal separator is a comma.
+ On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
+ are nl_langinfo(RADIXCHAR) are both ".". */
+ if (localeconv () ->decimal_point[0] != ',') return 1;
+ return 0;
+}
+changequote([,])dnl
+ ])])
+ if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+ case "$host_os" in
+ # Handle native Windows specially, because there setlocale() interprets
+ # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256",
+ # "fr" or "fra" as "French" or "French_France.1252",
+ # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252",
+ # "ja" as "Japanese" or "Japanese_Japan.932",
+ # and similar.
+ mingw*)
+ # Test for the native Windows locale name.
+ if (LC_ALL=French_France.1252 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr=French_France.1252
+ else
+ # None found.
+ gt_cv_locale_fr=none
+ fi
+ ;;
+ *)
+ # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+ # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+ # configure script would override the LC_ALL setting. Likewise for
+ # LC_CTYPE, which is also set at the beginning of the configure script.
+ # Test for the usual locale name.
+ if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr=fr_FR
+ else
+ # Test for the locale name with explicit encoding suffix.
+ if (LC_ALL=fr_FR.ISO-8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr=fr_FR.ISO-8859-1
+ else
+ # Test for the AIX, OSF/1, FreeBSD, NetBSD, OpenBSD locale name.
+ if (LC_ALL=fr_FR.ISO8859-1 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr=fr_FR.ISO8859-1
+ else
+ # Test for the HP-UX locale name.
+ if (LC_ALL=fr_FR.iso88591 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr=fr_FR.iso88591
+ else
+ # Test for the Solaris 7 locale name.
+ if (LC_ALL=fr LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr=fr
+ else
+ # None found.
+ gt_cv_locale_fr=none
+ fi
+ fi
+ fi
+ fi
+ fi
+ ;;
+ esac
+ fi
+ rm -fr conftest*
+ ])
+ LOCALE_FR=$gt_cv_locale_fr
+ AC_SUBST([LOCALE_FR])
+])
+
+dnl Determine the name of a french locale with UTF-8 encoding.
+AC_DEFUN([gt_LOCALE_FR_UTF8],
+[
+ AC_REQUIRE([AM_LANGINFO_CODESET])
+ AC_CACHE_CHECK([for a french Unicode locale], [gt_cv_locale_fr_utf8], [
+ AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main () {
+ /* On BeOS and Haiku, locales are not implemented in libc. Rather, libintl
+ imitates locale dependent behaviour by looking at the environment
+ variables, and all locales use the UTF-8 encoding. */
+#if !(defined __BEOS__ || defined __HAIKU__)
+ /* Check whether the given locale name is recognized by the system. */
+# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+ /* On native Windows, setlocale(category, "") looks at the system settings,
+ not at the environment variables. Also, when an encoding suffix such
+ as ".65001" or ".54936" is speficied, it succeeds but sets the LC_CTYPE
+ category of the locale to "C". */
+ if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
+ || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
+ return 1;
+# else
+ if (setlocale (LC_ALL, "") == NULL) return 1;
+# endif
+ /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+ On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+ is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+ On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+ succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+ some unit tests fail. */
+# if HAVE_LANGINFO_CODESET
+ {
+ const char *cs = nl_langinfo (CODESET);
+ if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0)
+ return 1;
+ }
+# endif
+# ifdef __CYGWIN__
+ /* On Cygwin, avoid locale names without encoding suffix, because the
+ locale_charset() function relies on the encoding suffix. Note that
+ LC_ALL is set on the command line. */
+ if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+# endif
+ /* Check whether in the abbreviation of the second month, the second
+ character (should be U+00E9: LATIN SMALL LETTER E WITH ACUTE) is
+ two bytes long, with UTF-8 encoding. */
+ t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+ if (strftime (buf, sizeof (buf), "%b", &t) < 4
+ || buf[1] != (char) 0xc3 || buf[2] != (char) 0xa9 || buf[3] != 'v')
+ return 1;
+#endif
+ /* Check whether the decimal separator is a comma.
+ On NetBSD 3.0 in the fr_FR.ISO8859-1 locale, localeconv()->decimal_point
+ are nl_langinfo(RADIXCHAR) are both ".". */
+ if (localeconv () ->decimal_point[0] != ',') return 1;
+ return 0;
+}
+changequote([,])dnl
+ ])])
+ if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+ case "$host_os" in
+ # Handle native Windows specially, because there setlocale() interprets
+ # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256",
+ # "fr" or "fra" as "French" or "French_France.1252",
+ # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252",
+ # "ja" as "Japanese" or "Japanese_Japan.932",
+ # and similar.
+ mingw*)
+ # Test for the hypothetical native Windows locale name.
+ if (LC_ALL=French_France.65001 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr_utf8=French_France.65001
+ else
+ # None found.
+ gt_cv_locale_fr_utf8=none
+ fi
+ ;;
+ *)
+ # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+ # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+ # configure script would override the LC_ALL setting. Likewise for
+ # LC_CTYPE, which is also set at the beginning of the configure script.
+ # Test for the usual locale name.
+ if (LC_ALL=fr_FR LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr_utf8=fr_FR
+ else
+ # Test for the locale name with explicit encoding suffix.
+ if (LC_ALL=fr_FR.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr_utf8=fr_FR.UTF-8
+ else
+ # Test for the Solaris 7 locale name.
+ if (LC_ALL=fr.UTF-8 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_fr_utf8=fr.UTF-8
+ else
+ # None found.
+ gt_cv_locale_fr_utf8=none
+ fi
+ fi
+ fi
+ ;;
+ esac
+ fi
+ rm -fr conftest*
+ ])
+ LOCALE_FR_UTF8=$gt_cv_locale_fr_utf8
+ AC_SUBST([LOCALE_FR_UTF8])
+])
diff --git a/m4/locale-ja.m4 b/m4/locale-ja.m4
new file mode 100644
index 000000000..b427f0992
--- /dev/null
+++ b/m4/locale-ja.m4
@@ -0,0 +1,136 @@
+# locale-ja.m4 serial 10
+dnl Copyright (C) 2003, 2005-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl Determine the name of a japanese locale with EUC-JP encoding.
+AC_DEFUN([gt_LOCALE_JA],
+[
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_REQUIRE([AM_LANGINFO_CODESET])
+ AC_CACHE_CHECK([for a traditional japanese locale], [gt_cv_locale_ja], [
+ AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main ()
+{
+ const char *p;
+ /* Check whether the given locale name is recognized by the system. */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+ /* On native Windows, setlocale(category, "") looks at the system settings,
+ not at the environment variables. Also, when an encoding suffix such
+ as ".65001" or ".54936" is speficied, it succeeds but sets the LC_CTYPE
+ category of the locale to "C". */
+ if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
+ || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
+ return 1;
+#else
+ if (setlocale (LC_ALL, "") == NULL) return 1;
+#endif
+ /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+ On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+ is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+ On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+ succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+ some unit tests fail.
+ On MirBSD 10, when an unsupported locale is specified, setlocale()
+ succeeds but then nl_langinfo(CODESET) is "UTF-8". */
+#if HAVE_LANGINFO_CODESET
+ {
+ const char *cs = nl_langinfo (CODESET);
+ if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
+ || strcmp (cs, "UTF-8") == 0)
+ return 1;
+ }
+#endif
+#ifdef __CYGWIN__
+ /* On Cygwin, avoid locale names without encoding suffix, because the
+ locale_charset() function relies on the encoding suffix. Note that
+ LC_ALL is set on the command line. */
+ if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+ /* Check whether MB_CUR_MAX is > 1. This excludes the dysfunctional locales
+ on Cygwin 1.5.x. */
+ if (MB_CUR_MAX == 1)
+ return 1;
+ /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
+ This excludes the UTF-8 encoding (except on MirBSD). */
+ t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+ if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+ for (p = buf; *p != '\0'; p++)
+ if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+ return 1;
+ return 0;
+}
+changequote([,])dnl
+ ])])
+ if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+ case "$host_os" in
+ # Handle native Windows specially, because there setlocale() interprets
+ # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256",
+ # "fr" or "fra" as "French" or "French_France.1252",
+ # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252",
+ # "ja" as "Japanese" or "Japanese_Japan.932",
+ # and similar.
+ mingw*)
+ # Note that on native Windows, the Japanese locale is
+ # Japanese_Japan.932, and CP932 is very different from EUC-JP, so we
+ # cannot use it here.
+ gt_cv_locale_ja=none
+ ;;
+ *)
+ # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+ # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+ # configure script would override the LC_ALL setting. Likewise for
+ # LC_CTYPE, which is also set at the beginning of the configure script.
+ # Test for the AIX locale name.
+ if (LC_ALL=ja_JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_ja=ja_JP
+ else
+ # Test for the locale name with explicit encoding suffix.
+ if (LC_ALL=ja_JP.EUC-JP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_ja=ja_JP.EUC-JP
+ else
+ # Test for the HP-UX, OSF/1, NetBSD locale name.
+ if (LC_ALL=ja_JP.eucJP LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_ja=ja_JP.eucJP
+ else
+ # Test for the IRIX, FreeBSD locale name.
+ if (LC_ALL=ja_JP.EUC LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_ja=ja_JP.EUC
+ else
+ # Test for the Solaris 7 locale name.
+ if (LC_ALL=ja LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_ja=ja
+ else
+ # Special test for NetBSD 1.6.
+ if test -f /usr/share/locale/ja_JP.eucJP/LC_CTYPE; then
+ gt_cv_locale_ja=ja_JP.eucJP
+ else
+ # None found.
+ gt_cv_locale_ja=none
+ fi
+ fi
+ fi
+ fi
+ fi
+ fi
+ ;;
+ esac
+ fi
+ rm -fr conftest*
+ ])
+ LOCALE_JA=$gt_cv_locale_ja
+ AC_SUBST([LOCALE_JA])
+])
diff --git a/m4/locale-zh.m4 b/m4/locale-zh.m4
new file mode 100644
index 000000000..de1a43b30
--- /dev/null
+++ b/m4/locale-zh.m4
@@ -0,0 +1,130 @@
+# locale-zh.m4 serial 10
+dnl Copyright (C) 2003, 2005-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl From Bruno Haible.
+
+dnl Determine the name of a chinese locale with GB18030 encoding.
+AC_DEFUN([gt_LOCALE_ZH_CN],
+[
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_REQUIRE([AM_LANGINFO_CODESET])
+ AC_CACHE_CHECK([for a transitional chinese locale], [gt_cv_locale_zh_CN], [
+ AC_LANG_CONFTEST([AC_LANG_SOURCE([
+changequote(,)dnl
+#include <locale.h>
+#include <stdlib.h>
+#include <time.h>
+#if HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+struct tm t;
+char buf[16];
+int main ()
+{
+ const char *p;
+ /* Check whether the given locale name is recognized by the system. */
+#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
+ /* On native Windows, setlocale(category, "") looks at the system settings,
+ not at the environment variables. Also, when an encoding suffix such
+ as ".65001" or ".54936" is speficied, it succeeds but sets the LC_CTYPE
+ category of the locale to "C". */
+ if (setlocale (LC_ALL, getenv ("LC_ALL")) == NULL
+ || strcmp (setlocale (LC_CTYPE, NULL), "C") == 0)
+ return 1;
+#else
+ if (setlocale (LC_ALL, "") == NULL) return 1;
+#endif
+ /* Check whether nl_langinfo(CODESET) is nonempty and not "ASCII" or "646".
+ On MacOS X 10.3.5 (Darwin 7.5) in the fr_FR locale, nl_langinfo(CODESET)
+ is empty, and the behaviour of Tcl 8.4 in this locale is not useful.
+ On OpenBSD 4.0, when an unsupported locale is specified, setlocale()
+ succeeds but then nl_langinfo(CODESET) is "646". In this situation,
+ some unit tests fail.
+ On MirBSD 10, when an unsupported locale is specified, setlocale()
+ succeeds but then nl_langinfo(CODESET) is "UTF-8". */
+#if HAVE_LANGINFO_CODESET
+ {
+ const char *cs = nl_langinfo (CODESET);
+ if (cs[0] == '\0' || strcmp (cs, "ASCII") == 0 || strcmp (cs, "646") == 0
+ || strcmp (cs, "UTF-8") == 0)
+ return 1;
+ }
+#endif
+#ifdef __CYGWIN__
+ /* On Cygwin, avoid locale names without encoding suffix, because the
+ locale_charset() function relies on the encoding suffix. Note that
+ LC_ALL is set on the command line. */
+ if (strchr (getenv ("LC_ALL"), '.') == NULL) return 1;
+#endif
+ /* Check whether in a month name, no byte in the range 0x80..0x9F occurs.
+ This excludes the UTF-8 encoding (except on MirBSD). */
+ t.tm_year = 1975 - 1900; t.tm_mon = 2 - 1; t.tm_mday = 4;
+ if (strftime (buf, sizeof (buf), "%B", &t) < 2) return 1;
+ for (p = buf; *p != '\0'; p++)
+ if ((unsigned char) *p >= 0x80 && (unsigned char) *p < 0xa0)
+ return 1;
+ /* Check whether a typical GB18030 multibyte sequence is recognized as a
+ single wide character. This excludes the GB2312 and GBK encodings. */
+ if (mblen ("\203\062\332\066", 5) != 4)
+ return 1;
+ return 0;
+}
+changequote([,])dnl
+ ])])
+ if AC_TRY_EVAL([ac_link]) && test -s conftest$ac_exeext; then
+ case "$host_os" in
+ # Handle native Windows specially, because there setlocale() interprets
+ # "ar" as "Arabic" or "Arabic_Saudi Arabia.1256",
+ # "fr" or "fra" as "French" or "French_France.1252",
+ # "ge"(!) or "deu"(!) as "German" or "German_Germany.1252",
+ # "ja" as "Japanese" or "Japanese_Japan.932",
+ # and similar.
+ mingw*)
+ # Test for the hypothetical native Windows locale name.
+ if (LC_ALL=Chinese_China.54936 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_zh_CN=Chinese_China.54936
+ else
+ # None found.
+ gt_cv_locale_zh_CN=none
+ fi
+ ;;
+ solaris2.8)
+ # On Solaris 8, the locales zh_CN.GB18030, zh_CN.GBK, zh.GBK are
+ # broken. One witness is the test case in gl_MBRTOWC_SANITYCHECK.
+ # Another witness is that "LC_ALL=zh_CN.GB18030 bash -c true" dumps core.
+ gt_cv_locale_zh_CN=none
+ ;;
+ *)
+ # Setting LC_ALL is not enough. Need to set LC_TIME to empty, because
+ # otherwise on MacOS X 10.3.5 the LC_TIME=C from the beginning of the
+ # configure script would override the LC_ALL setting. Likewise for
+ # LC_CTYPE, which is also set at the beginning of the configure script.
+ # Test for the locale name without encoding suffix.
+ if (LC_ALL=zh_CN LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_zh_CN=zh_CN
+ else
+ # Test for the locale name with explicit encoding suffix.
+ if (LC_ALL=zh_CN.GB18030 LC_TIME= LC_CTYPE= ./conftest; exit) 2>/dev/null; then
+ gt_cv_locale_zh_CN=zh_CN.GB18030
+ else
+ # None found.
+ gt_cv_locale_zh_CN=none
+ fi
+ fi
+ ;;
+ esac
+ else
+ # If there was a link error, due to mblen(), the system is so old that
+ # it certainly doesn't have a chinese locale.
+ gt_cv_locale_zh_CN=none
+ fi
+ rm -fr conftest*
+ ])
+ LOCALE_ZH_CN=$gt_cv_locale_zh_CN
+ AC_SUBST([LOCALE_ZH_CN])
+])
diff --git a/m4/mbrtowc.m4 b/m4/mbrtowc.m4
new file mode 100644
index 000000000..8f829c8ea
--- /dev/null
+++ b/m4/mbrtowc.m4
@@ -0,0 +1,572 @@
+# mbrtowc.m4 serial 25
+dnl Copyright (C) 2001-2002, 2004-2005, 2008-2012 Free Software Foundation,
+dnl Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBRTOWC],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+ AC_REQUIRE([AC_TYPE_MBSTATE_T])
+ gl_MBSTATE_T_BROKEN
+
+ AC_CHECK_FUNCS_ONCE([mbrtowc])
+ if test $ac_cv_func_mbrtowc = no; then
+ HAVE_MBRTOWC=0
+ AC_CHECK_DECLS([mbrtowc],,, [[
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+]])
+ if test $ac_cv_have_decl_mbrtowc = yes; then
+ dnl On Minix 3.1.8, the system's <wchar.h> declares mbrtowc() although
+ dnl it does not have the function. Avoid a collision with gnulib's
+ dnl replacement.
+ REPLACE_MBRTOWC=1
+ fi
+ else
+ if test $REPLACE_MBSTATE_T = 1; then
+ REPLACE_MBRTOWC=1
+ else
+ gl_MBRTOWC_NULL_ARG1
+ gl_MBRTOWC_NULL_ARG2
+ gl_MBRTOWC_RETVAL
+ gl_MBRTOWC_NUL_RETVAL
+ case "$gl_cv_func_mbrtowc_null_arg1" in
+ *yes) ;;
+ *) AC_DEFINE([MBRTOWC_NULL_ARG1_BUG], [1],
+ [Define if the mbrtowc function has the NULL pwc argument bug.])
+ REPLACE_MBRTOWC=1
+ ;;
+ esac
+ case "$gl_cv_func_mbrtowc_null_arg2" in
+ *yes) ;;
+ *) AC_DEFINE([MBRTOWC_NULL_ARG2_BUG], [1],
+ [Define if the mbrtowc function has the NULL string argument bug.])
+ REPLACE_MBRTOWC=1
+ ;;
+ esac
+ case "$gl_cv_func_mbrtowc_retval" in
+ *yes) ;;
+ *) AC_DEFINE([MBRTOWC_RETVAL_BUG], [1],
+ [Define if the mbrtowc function returns a wrong return value.])
+ REPLACE_MBRTOWC=1
+ ;;
+ esac
+ case "$gl_cv_func_mbrtowc_nul_retval" in
+ *yes) ;;
+ *) AC_DEFINE([MBRTOWC_NUL_RETVAL_BUG], [1],
+ [Define if the mbrtowc function does not return 0 for a NUL character.])
+ REPLACE_MBRTOWC=1
+ ;;
+ esac
+ fi
+ fi
+])
+
+dnl Test whether mbsinit() and mbrtowc() need to be overridden in a way that
+dnl redefines the semantics of the given mbstate_t type.
+dnl Result is REPLACE_MBSTATE_T.
+dnl When this is set to 1, we replace both mbsinit() and mbrtowc(), in order to
+dnl avoid inconsistencies.
+
+AC_DEFUN([gl_MBSTATE_T_BROKEN],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+ AC_REQUIRE([AC_TYPE_MBSTATE_T])
+ AC_CHECK_FUNCS_ONCE([mbsinit])
+ AC_CHECK_FUNCS_ONCE([mbrtowc])
+ if test $ac_cv_func_mbsinit = yes && test $ac_cv_func_mbrtowc = yes; then
+ gl_MBRTOWC_INCOMPLETE_STATE
+ gl_MBRTOWC_SANITYCHECK
+ REPLACE_MBSTATE_T=0
+ case "$gl_cv_func_mbrtowc_incomplete_state" in
+ *yes) ;;
+ *) REPLACE_MBSTATE_T=1 ;;
+ esac
+ case "$gl_cv_func_mbrtowc_sanitycheck" in
+ *yes) ;;
+ *) REPLACE_MBSTATE_T=1 ;;
+ esac
+ else
+ REPLACE_MBSTATE_T=1
+ fi
+])
+
+dnl Test whether mbrtowc puts the state into non-initial state when parsing an
+dnl incomplete multibyte character.
+dnl Result is gl_cv_func_mbrtowc_incomplete_state.
+
+AC_DEFUN([gl_MBRTOWC_INCOMPLETE_STATE],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_JA])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether mbrtowc handles incomplete characters],
+ [gl_cv_func_mbrtowc_incomplete_state],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on AIX and OSF/1.
+ aix* | osf*) gl_cv_func_mbrtowc_incomplete_state="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_mbrtowc_incomplete_state="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_JA != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+ {
+ const char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+ if (mbsinit (&state))
+ return 1;
+ }
+ return 0;
+}]])],
+ [gl_cv_func_mbrtowc_incomplete_state=yes],
+ [gl_cv_func_mbrtowc_incomplete_state=no],
+ [:])
+ fi
+ ])
+])
+
+dnl Test whether mbrtowc works not worse than mbtowc.
+dnl Result is gl_cv_func_mbrtowc_sanitycheck.
+
+AC_DEFUN([gl_MBRTOWC_SANITYCHECK],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_ZH_CN])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether mbrtowc works as well as mbtowc],
+ [gl_cv_func_mbrtowc_sanitycheck],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on Solaris 8.
+ solaris2.8) gl_cv_func_mbrtowc_sanitycheck="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_mbrtowc_sanitycheck="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_ZH_CN != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ /* This fails on Solaris 8:
+ mbrtowc returns 2, and sets wc to 0x00F0.
+ mbtowc returns 4 (correct) and sets wc to 0x5EDC. */
+ if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+ {
+ char input[] = "B\250\271\201\060\211\070er"; /* "Büßer" */
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, input + 3, 6, &state) != 4
+ && mbtowc (&wc, input + 3, 6) == 4)
+ return 1;
+ }
+ return 0;
+}]])],
+ [gl_cv_func_mbrtowc_sanitycheck=yes],
+ [gl_cv_func_mbrtowc_sanitycheck=no],
+ [:])
+ fi
+ ])
+])
+
+dnl Test whether mbrtowc supports a NULL pwc argument correctly.
+dnl Result is gl_cv_func_mbrtowc_null_arg1.
+
+AC_DEFUN([gl_MBRTOWC_NULL_ARG1],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_FR_UTF8])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether mbrtowc handles a NULL pwc argument],
+ [gl_cv_func_mbrtowc_null_arg1],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on Solaris.
+ solaris*) gl_cv_func_mbrtowc_null_arg1="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_mbrtowc_null_arg1="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_FR_UTF8 != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <stdlib.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ int result = 0;
+
+ if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+ {
+ char input[] = "\303\237er";
+ mbstate_t state;
+ wchar_t wc;
+ size_t ret;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ wc = (wchar_t) 0xBADFACE;
+ ret = mbrtowc (&wc, input, 5, &state);
+ if (ret != 2)
+ result |= 1;
+ if (!mbsinit (&state))
+ result |= 2;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ ret = mbrtowc (NULL, input, 5, &state);
+ if (ret != 2) /* Solaris 7 fails here: ret is -1. */
+ result |= 4;
+ if (!mbsinit (&state))
+ result |= 8;
+ }
+ return result;
+}]])],
+ [gl_cv_func_mbrtowc_null_arg1=yes],
+ [gl_cv_func_mbrtowc_null_arg1=no],
+ [:])
+ fi
+ ])
+])
+
+dnl Test whether mbrtowc supports a NULL string argument correctly.
+dnl Result is gl_cv_func_mbrtowc_null_arg2.
+
+AC_DEFUN([gl_MBRTOWC_NULL_ARG2],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_FR_UTF8])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether mbrtowc handles a NULL string argument],
+ [gl_cv_func_mbrtowc_null_arg2],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on OSF/1.
+ osf*) gl_cv_func_mbrtowc_null_arg2="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_mbrtowc_null_arg2="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_FR_UTF8 != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+ {
+ mbstate_t state;
+ wchar_t wc;
+ int ret;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ wc = (wchar_t) 0xBADFACE;
+ mbrtowc (&wc, NULL, 5, &state);
+ /* Check that wc was not modified. */
+ if (wc != (wchar_t) 0xBADFACE)
+ return 1;
+ }
+ return 0;
+}]])],
+ [gl_cv_func_mbrtowc_null_arg2=yes],
+ [gl_cv_func_mbrtowc_null_arg2=no],
+ [:])
+ fi
+ ])
+])
+
+dnl Test whether mbrtowc, when parsing the end of a multibyte character,
+dnl correctly returns the number of bytes that were needed to complete the
+dnl character (not the total number of bytes of the multibyte character).
+dnl Result is gl_cv_func_mbrtowc_retval.
+
+AC_DEFUN([gl_MBRTOWC_RETVAL],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_FR_UTF8])
+ AC_REQUIRE([gt_LOCALE_JA])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_CACHE_CHECK([whether mbrtowc has a correct return value],
+ [gl_cv_func_mbrtowc_retval],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on HP-UX, Solaris, native Windows.
+ hpux* | solaris* | mingw*) gl_cv_func_mbrtowc_retval="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_mbrtowc_retval="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none \
+ || { case "$host_os" in mingw*) true;; *) false;; esac; }; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ int result = 0;
+ int found_some_locale = 0;
+ /* This fails on Solaris. */
+ if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+ {
+ char input[] = "B\303\274\303\237er"; /* "Büßer" */
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+ {
+ input[1] = '\0';
+ if (mbrtowc (&wc, input + 2, 5, &state) != 1)
+ result |= 1;
+ }
+ found_some_locale = 1;
+ }
+ /* This fails on HP-UX 11.11. */
+ if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+ {
+ char input[] = "B\217\253\344\217\251\316er"; /* "Büßer" */
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, input + 1, 1, &state) == (size_t)(-2))
+ {
+ input[1] = '\0';
+ if (mbrtowc (&wc, input + 2, 5, &state) != 2)
+ result |= 2;
+ }
+ found_some_locale = 1;
+ }
+ /* This fails on native Windows. */
+ if (setlocale (LC_ALL, "Japanese_Japan.932") != NULL)
+ {
+ char input[] = "<\223\372\226\173\214\352>"; /* "<日本語>" */
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
+ {
+ input[3] = '\0';
+ if (mbrtowc (&wc, input + 4, 4, &state) != 1)
+ result |= 4;
+ }
+ found_some_locale = 1;
+ }
+ if (setlocale (LC_ALL, "Chinese_Taiwan.950") != NULL)
+ {
+ char input[] = "<\244\351\245\273\273\171>"; /* "<日本語>" */
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
+ {
+ input[3] = '\0';
+ if (mbrtowc (&wc, input + 4, 4, &state) != 1)
+ result |= 8;
+ }
+ found_some_locale = 1;
+ }
+ if (setlocale (LC_ALL, "Chinese_China.936") != NULL)
+ {
+ char input[] = "<\310\325\261\276\325\132>"; /* "<日本語>" */
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, input + 3, 1, &state) == (size_t)(-2))
+ {
+ input[3] = '\0';
+ if (mbrtowc (&wc, input + 4, 4, &state) != 1)
+ result |= 16;
+ }
+ found_some_locale = 1;
+ }
+ return (found_some_locale ? result : 77);
+}]])],
+ [gl_cv_func_mbrtowc_retval=yes],
+ [if test $? != 77; then
+ gl_cv_func_mbrtowc_retval=no
+ fi
+ ],
+ [:])
+ fi
+ ])
+])
+
+dnl Test whether mbrtowc, when parsing a NUL character, correctly returns 0.
+dnl Result is gl_cv_func_mbrtowc_nul_retval.
+
+AC_DEFUN([gl_MBRTOWC_NUL_RETVAL],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_ZH_CN])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether mbrtowc returns 0 when parsing a NUL character],
+ [gl_cv_func_mbrtowc_nul_retval],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on Solaris 8 and 9.
+ solaris2.[89]) gl_cv_func_mbrtowc_nul_retval="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_mbrtowc_nul_retval="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_ZH_CN != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ /* This fails on Solaris 8 and 9. */
+ if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+ {
+ mbstate_t state;
+ wchar_t wc;
+
+ memset (&state, '\0', sizeof (mbstate_t));
+ if (mbrtowc (&wc, "", 1, &state) != 0)
+ return 1;
+ }
+ return 0;
+}]])],
+ [gl_cv_func_mbrtowc_nul_retval=yes],
+ [gl_cv_func_mbrtowc_nul_retval=no],
+ [:])
+ fi
+ ])
+])
+
+# Prerequisites of lib/mbrtowc.c.
+AC_DEFUN([gl_PREREQ_MBRTOWC], [
+ :
+])
+
+
+dnl From Paul Eggert
+
+dnl This is an override of an autoconf macro.
+
+AC_DEFUN([AC_FUNC_MBRTOWC],
+[
+ dnl Same as AC_FUNC_MBRTOWC in autoconf-2.60.
+ AC_CACHE_CHECK([whether mbrtowc and mbstate_t are properly declared],
+ gl_cv_func_mbrtowc,
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
+ included before <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
+ must be included before <wchar.h>. */
+ #include <stddef.h>
+ #include <stdio.h>
+ #include <time.h>
+ #include <wchar.h>]],
+ [[wchar_t wc;
+ char const s[] = "";
+ size_t n = 1;
+ mbstate_t state;
+ return ! (sizeof state && (mbrtowc) (&wc, s, n, &state));]])],
+ gl_cv_func_mbrtowc=yes,
+ gl_cv_func_mbrtowc=no)])
+ if test $gl_cv_func_mbrtowc = yes; then
+ AC_DEFINE([HAVE_MBRTOWC], [1],
+ [Define to 1 if mbrtowc and mbstate_t are properly declared.])
+ fi
+])
diff --git a/m4/mbsinit.m4 b/m4/mbsinit.m4
new file mode 100644
index 000000000..da56c3d11
--- /dev/null
+++ b/m4/mbsinit.m4
@@ -0,0 +1,51 @@
+# mbsinit.m4 serial 8
+dnl Copyright (C) 2008, 2010-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBSINIT],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+
+ AC_REQUIRE([AC_TYPE_MBSTATE_T])
+ gl_MBSTATE_T_BROKEN
+
+ AC_CHECK_FUNCS_ONCE([mbsinit])
+ if test $ac_cv_func_mbsinit = no; then
+ HAVE_MBSINIT=0
+ AC_CHECK_DECLS([mbsinit],,, [[
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+]])
+ if test $ac_cv_have_decl_mbsinit = yes; then
+ dnl On Minix 3.1.8, the system's <wchar.h> declares mbsinit() although
+ dnl it does not have the function. Avoid a collision with gnulib's
+ dnl replacement.
+ REPLACE_MBSINIT=1
+ fi
+ else
+ if test $REPLACE_MBSTATE_T = 1; then
+ REPLACE_MBSINIT=1
+ else
+ dnl On mingw, mbsinit() always returns 1, which is inappropriate for
+ dnl states produced by mbrtowc() for an incomplete multibyte character
+ dnl in multibyte locales.
+ case "$host_os" in
+ mingw*) REPLACE_MBSINIT=1 ;;
+ esac
+ fi
+ fi
+])
+
+# Prerequisites of lib/mbsinit.c.
+AC_DEFUN([gl_PREREQ_MBSINIT], [
+ :
+])
diff --git a/m4/mbstate_t.m4 b/m4/mbstate_t.m4
new file mode 100644
index 000000000..61a8190ce
--- /dev/null
+++ b/m4/mbstate_t.m4
@@ -0,0 +1,41 @@
+# mbstate_t.m4 serial 13
+dnl Copyright (C) 2000-2002, 2008-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# From Paul Eggert.
+
+# BeOS 5 has <wchar.h> but does not define mbstate_t,
+# so you can't declare an object of that type.
+# Check for this incompatibility with Standard C.
+
+# AC_TYPE_MBSTATE_T
+# -----------------
+AC_DEFUN([AC_TYPE_MBSTATE_T],
+[
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) dnl for HP-UX 11.11
+
+ AC_CACHE_CHECK([for mbstate_t], [ac_cv_type_mbstate_t],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [AC_INCLUDES_DEFAULT[
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>]],
+ [[mbstate_t x; return sizeof x;]])],
+ [ac_cv_type_mbstate_t=yes],
+ [ac_cv_type_mbstate_t=no])])
+ if test $ac_cv_type_mbstate_t = yes; then
+ AC_DEFINE([HAVE_MBSTATE_T], [1],
+ [Define to 1 if <wchar.h> declares mbstate_t.])
+ else
+ AC_DEFINE([mbstate_t], [int],
+ [Define to a type if <wchar.h> does not define.])
+ fi
+])
diff --git a/m4/mbtowc.m4 b/m4/mbtowc.m4
new file mode 100644
index 000000000..fec0d2582
--- /dev/null
+++ b/m4/mbtowc.m4
@@ -0,0 +1,19 @@
+# mbtowc.m4 serial 2
+dnl Copyright (C) 2011-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBTOWC],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+ if false; then
+ REPLACE_MBTOWC=1
+ fi
+])
+
+# Prerequisites of lib/mbtowc.c.
+AC_DEFUN([gl_PREREQ_MBTOWC], [
+ :
+])
diff --git a/m4/nl_langinfo.m4 b/m4/nl_langinfo.m4
new file mode 100644
index 000000000..80fe60d57
--- /dev/null
+++ b/m4/nl_langinfo.m4
@@ -0,0 +1,50 @@
+# nl_langinfo.m4 serial 5
+dnl Copyright (C) 2009-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_NL_LANGINFO],
+[
+ AC_REQUIRE([gl_LANGINFO_H_DEFAULTS])
+ AC_REQUIRE([gl_LANGINFO_H])
+ AC_CHECK_FUNCS_ONCE([nl_langinfo])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ if test $ac_cv_func_nl_langinfo = yes; then
+ # On Irix 6.5, YESEXPR is defined, but nl_langinfo(YESEXPR) is broken.
+ AC_CACHE_CHECK([whether YESEXPR works],
+ [gl_cv_func_nl_langinfo_yesexpr_works],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM([[#include <langinfo.h>
+]], [[return !*nl_langinfo(YESEXPR);
+]])],
+ [gl_cv_func_nl_langinfo_yesexpr_works=yes],
+ [gl_cv_func_nl_langinfo_yesexpr_works=no],
+ [
+ case "$host_os" in
+ # Guess no on irix systems.
+ irix*) gl_cv_func_nl_langinfo_yesexpr_works="guessing no";;
+ # Guess yes elsewhere.
+ *) gl_cv_func_nl_langinfo_yesexpr_works="guessing yes";;
+ esac
+ ])
+ ])
+ case $gl_cv_func_nl_langinfo_yesexpr_works in
+ *yes) FUNC_NL_LANGINFO_YESEXPR_WORKS=1 ;;
+ *) FUNC_NL_LANGINFO_YESEXPR_WORKS=0 ;;
+ esac
+ AC_DEFINE_UNQUOTED([FUNC_NL_LANGINFO_YESEXPR_WORKS],
+ [$FUNC_NL_LANGINFO_YESEXPR_WORKS],
+ [Define to 1 if nl_langinfo (YESEXPR) returns a non-empty string.])
+ if test $HAVE_LANGINFO_CODESET = 1 && test $HAVE_LANGINFO_ERA = 1 \
+ && test $FUNC_NL_LANGINFO_YESEXPR_WORKS = 1; then
+ :
+ else
+ REPLACE_NL_LANGINFO=1
+ AC_DEFINE([REPLACE_NL_LANGINFO], [1],
+ [Define if nl_langinfo exists but is overridden by gnulib.])
+ fi
+ else
+ HAVE_NL_LANGINFO=0
+ fi
+])
diff --git a/m4/regex.m4 b/m4/regex.m4
new file mode 100644
index 000000000..08f1352e2
--- /dev/null
+++ b/m4/regex.m4
@@ -0,0 +1,223 @@
+# serial 60
+
+# Copyright (C) 1996-2001, 2003-2012 Free Software Foundation, Inc.
+#
+# This file 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.
+
+dnl Initially derived from code in GNU grep.
+dnl Mostly written by Jim Meyering.
+
+AC_PREREQ([2.50])
+
+AC_DEFUN([gl_REGEX],
+[
+ AC_ARG_WITH([included-regex],
+ [AS_HELP_STRING([--without-included-regex],
+ [don't compile regex; this is the default on systems
+ with recent-enough versions of the GNU C Library
+ (use with caution on other systems).])])
+
+ case $with_included_regex in #(
+ yes|no) ac_use_included_regex=$with_included_regex
+ ;;
+ '')
+ # If the system regex support is good enough that it passes the
+ # following run test, then default to *not* using the included regex.c.
+ # If cross compiling, assume the test would fail and use the included
+ # regex.c.
+ AC_CACHE_CHECK([for working re_compile_pattern],
+ [gl_cv_func_re_compile_pattern_working],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [AC_INCLUDES_DEFAULT[
+ #include <locale.h>
+ #include <limits.h>
+ #include <regex.h>
+ ]],
+ [[int result = 0;
+ static struct re_pattern_buffer regex;
+ unsigned char folded_chars[UCHAR_MAX + 1];
+ int i;
+ const char *s;
+ struct re_registers regs;
+
+ /* http://sourceware.org/ml/libc-hacker/2006-09/msg00008.html
+ This test needs valgrind to catch the bug on Debian
+ GNU/Linux 3.1 x86, but it might catch the bug better
+ on other platforms and it shouldn't hurt to try the
+ test here. */
+ if (setlocale (LC_ALL, "en_US.UTF-8"))
+ {
+ static char const pat[] = "insert into";
+ static char const data[] =
+ "\xFF\0\x12\xA2\xAA\xC4\xB1,K\x12\xC4\xB1*\xACK";
+ re_set_syntax (RE_SYNTAX_GREP | RE_HAT_LISTS_NOT_NEWLINE
+ | RE_ICASE);
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern (pat, sizeof pat - 1, &regex);
+ if (s)
+ result |= 1;
+ else if (re_search (&regex, data, sizeof data - 1,
+ 0, sizeof data - 1, &regs)
+ != -1)
+ result |= 1;
+ if (! setlocale (LC_ALL, "C"))
+ return 1;
+ }
+
+ /* This test is from glibc bug 3957, reported by Andrew Mackey. */
+ re_set_syntax (RE_SYNTAX_EGREP | RE_HAT_LISTS_NOT_NEWLINE);
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern ("a[^x]b", 6, &regex);
+ if (s)
+ result |= 2;
+ /* This should fail, but succeeds for glibc-2.5. */
+ else if (re_search (&regex, "a\nb", 3, 0, 3, &regs) != -1)
+ result |= 2;
+
+ /* This regular expression is from Spencer ere test number 75
+ in grep-2.3. */
+ re_set_syntax (RE_SYNTAX_POSIX_EGREP);
+ memset (&regex, 0, sizeof regex);
+ for (i = 0; i <= UCHAR_MAX; i++)
+ folded_chars[i] = i;
+ regex.translate = folded_chars;
+ s = re_compile_pattern ("a[[:@:>@:]]b\n", 11, &regex);
+ /* This should fail with _Invalid character class name_ error. */
+ if (!s)
+ result |= 4;
+
+ /* Ensure that [b-a] is diagnosed as invalid, when
+ using RE_NO_EMPTY_RANGES. */
+ re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES);
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern ("a[b-a]", 6, &regex);
+ if (s == 0)
+ result |= 8;
+
+ /* This should succeed, but does not for glibc-2.1.3. */
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern ("{1", 2, &regex);
+ if (s)
+ result |= 8;
+
+ /* The following example is derived from a problem report
+ against gawk from Jorge Stolfi <stolfi@ic.unicamp.br>. */
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern ("[an\371]*n", 7, &regex);
+ if (s)
+ result |= 8;
+ /* This should match, but does not for glibc-2.2.1. */
+ else if (re_match (&regex, "an", 2, 0, &regs) != 2)
+ result |= 8;
+
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern ("x", 1, &regex);
+ if (s)
+ result |= 8;
+ /* glibc-2.2.93 does not work with a negative RANGE argument. */
+ else if (re_search (&regex, "wxy", 3, 2, -2, &regs) != 1)
+ result |= 8;
+
+ /* The version of regex.c in older versions of gnulib
+ ignored RE_ICASE. Detect that problem too. */
+ re_set_syntax (RE_SYNTAX_EMACS | RE_ICASE);
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern ("x", 1, &regex);
+ if (s)
+ result |= 16;
+ else if (re_search (&regex, "WXY", 3, 0, 3, &regs) < 0)
+ result |= 16;
+
+ /* Catch a bug reported by Vin Shelton in
+ http://lists.gnu.org/archive/html/bug-coreutils/2007-06/msg00089.html
+ */
+ re_set_syntax (RE_SYNTAX_POSIX_BASIC
+ & ~RE_CONTEXT_INVALID_DUP
+ & ~RE_NO_EMPTY_RANGES);
+ memset (&regex, 0, sizeof regex);
+ s = re_compile_pattern ("[[:alnum:]_-]\\\\+$", 16, &regex);
+ if (s)
+ result |= 32;
+
+ /* REG_STARTEND was added to glibc on 2004-01-15.
+ Reject older versions. */
+ if (! REG_STARTEND)
+ result |= 64;
+
+#if 0
+ /* It would be nice to reject hosts whose regoff_t values are too
+ narrow (including glibc on hosts with 64-bit ptrdiff_t and
+ 32-bit int), but we should wait until glibc implements this
+ feature. Otherwise, support for equivalence classes and
+ multibyte collation symbols would always be broken except
+ when compiling --without-included-regex. */
+ if (sizeof (regoff_t) < sizeof (ptrdiff_t)
+ || sizeof (regoff_t) < sizeof (ssize_t))
+ result |= 64;
+#endif
+
+ return result;
+ ]])],
+ [gl_cv_func_re_compile_pattern_working=yes],
+ [gl_cv_func_re_compile_pattern_working=no],
+ dnl When crosscompiling, assume it is not working.
+ [gl_cv_func_re_compile_pattern_working=no])])
+ case $gl_cv_func_re_compile_pattern_working in #(
+ yes) ac_use_included_regex=no;; #(
+ no) ac_use_included_regex=yes;;
+ esac
+ ;;
+ *) AC_MSG_ERROR([Invalid value for --with-included-regex: $with_included_regex])
+ ;;
+ esac
+
+ if test $ac_use_included_regex = yes; then
+ AC_DEFINE([_REGEX_LARGE_OFFSETS], [1],
+ [Define if you want regoff_t to be at least as wide POSIX requires.])
+ AC_DEFINE([re_syntax_options], [rpl_re_syntax_options],
+ [Define to rpl_re_syntax_options if the replacement should be used.])
+ AC_DEFINE([re_set_syntax], [rpl_re_set_syntax],
+ [Define to rpl_re_set_syntax if the replacement should be used.])
+ AC_DEFINE([re_compile_pattern], [rpl_re_compile_pattern],
+ [Define to rpl_re_compile_pattern if the replacement should be used.])
+ AC_DEFINE([re_compile_fastmap], [rpl_re_compile_fastmap],
+ [Define to rpl_re_compile_fastmap if the replacement should be used.])
+ AC_DEFINE([re_search], [rpl_re_search],
+ [Define to rpl_re_search if the replacement should be used.])
+ AC_DEFINE([re_search_2], [rpl_re_search_2],
+ [Define to rpl_re_search_2 if the replacement should be used.])
+ AC_DEFINE([re_match], [rpl_re_match],
+ [Define to rpl_re_match if the replacement should be used.])
+ AC_DEFINE([re_match_2], [rpl_re_match_2],
+ [Define to rpl_re_match_2 if the replacement should be used.])
+ AC_DEFINE([re_set_registers], [rpl_re_set_registers],
+ [Define to rpl_re_set_registers if the replacement should be used.])
+ AC_DEFINE([re_comp], [rpl_re_comp],
+ [Define to rpl_re_comp if the replacement should be used.])
+ AC_DEFINE([re_exec], [rpl_re_exec],
+ [Define to rpl_re_exec if the replacement should be used.])
+ AC_DEFINE([regcomp], [rpl_regcomp],
+ [Define to rpl_regcomp if the replacement should be used.])
+ AC_DEFINE([regexec], [rpl_regexec],
+ [Define to rpl_regexec if the replacement should be used.])
+ AC_DEFINE([regerror], [rpl_regerror],
+ [Define to rpl_regerror if the replacement should be used.])
+ AC_DEFINE([regfree], [rpl_regfree],
+ [Define to rpl_regfree if the replacement should be used.])
+ fi
+])
+
+# Prerequisites of lib/regex.c and lib/regex_internal.c.
+AC_DEFUN([gl_PREREQ_REGEX],
+[
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+ AC_REQUIRE([AC_C_INLINE])
+ AC_REQUIRE([AC_C_RESTRICT])
+ AC_REQUIRE([AC_TYPE_MBSTATE_T])
+ AC_CHECK_HEADERS([libintl.h])
+ AC_CHECK_FUNCS_ONCE([isblank iswctype wcscoll])
+ AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])
+])
diff --git a/m4/strcase.m4 b/m4/strcase.m4
new file mode 100644
index 000000000..717fa9c32
--- /dev/null
+++ b/m4/strcase.m4
@@ -0,0 +1,45 @@
+# strcase.m4 serial 11
+dnl Copyright (C) 2002, 2005-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_STRCASE],
+[
+ gl_FUNC_STRCASECMP
+ gl_FUNC_STRNCASECMP
+])
+
+AC_DEFUN([gl_FUNC_STRCASECMP],
+[
+ AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
+ AC_CHECK_FUNCS([strcasecmp])
+ if test $ac_cv_func_strcasecmp = no; then
+ HAVE_STRCASECMP=0
+ fi
+])
+
+AC_DEFUN([gl_FUNC_STRNCASECMP],
+[
+ AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
+ AC_CHECK_FUNCS([strncasecmp])
+ if test $ac_cv_func_strncasecmp = yes; then
+ HAVE_STRNCASECMP=1
+ else
+ HAVE_STRNCASECMP=0
+ fi
+ AC_CHECK_DECLS([strncasecmp])
+ if test $ac_cv_have_decl_strncasecmp = no; then
+ HAVE_DECL_STRNCASECMP=0
+ fi
+])
+
+# Prerequisites of lib/strcasecmp.c.
+AC_DEFUN([gl_PREREQ_STRCASECMP], [
+ :
+])
+
+# Prerequisites of lib/strncasecmp.c.
+AC_DEFUN([gl_PREREQ_STRNCASECMP], [
+ :
+])
diff --git a/m4/strings_h.m4 b/m4/strings_h.m4
new file mode 100644
index 000000000..a057e1c8b
--- /dev/null
+++ b/m4/strings_h.m4
@@ -0,0 +1,52 @@
+# Configure a replacement for <strings.h>.
+# serial 6
+
+# Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
+# This file 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.
+
+AC_DEFUN([gl_HEADER_STRINGS_H],
+[
+ dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+ dnl once only, before all statements that occur in other macros.
+ AC_REQUIRE([gl_HEADER_STRINGS_H_BODY])
+])
+
+AC_DEFUN([gl_HEADER_STRINGS_H_BODY],
+[
+ AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
+
+ gl_CHECK_NEXT_HEADERS([strings.h])
+ if test $ac_cv_header_strings_h = yes; then
+ HAVE_STRINGS_H=1
+ else
+ HAVE_STRINGS_H=0
+ fi
+ AC_SUBST([HAVE_STRINGS_H])
+
+ dnl Check for declarations of anything we want to poison if the
+ dnl corresponding gnulib module is not in use.
+ gl_WARN_ON_USE_PREPARE([[
+ /* Minix 3.1.8 has a bug: <sys/types.h> must be included before
+ <strings.h>. */
+ #include <sys/types.h>
+ #include <strings.h>
+ ]], [ffs strcasecmp strncasecmp])
+])
+
+AC_DEFUN([gl_STRINGS_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_HEADER_STRINGS_H_DEFAULTS])
+ gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+])
+
+AC_DEFUN([gl_HEADER_STRINGS_H_DEFAULTS],
+[
+ GNULIB_FFS=0; AC_SUBST([GNULIB_FFS])
+ dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE_FFS=1; AC_SUBST([HAVE_FFS])
+ HAVE_STRCASECMP=1; AC_SUBST([HAVE_STRCASECMP])
+ HAVE_DECL_STRNCASECMP=1; AC_SUBST([HAVE_DECL_STRNCASECMP])
+])
diff --git a/m4/wcrtomb.m4 b/m4/wcrtomb.m4
new file mode 100644
index 000000000..00d7302e8
--- /dev/null
+++ b/m4/wcrtomb.m4
@@ -0,0 +1,112 @@
+# wcrtomb.m4 serial 11
+dnl Copyright (C) 2008-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_WCRTOMB],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+
+ AC_REQUIRE([AC_TYPE_MBSTATE_T])
+ gl_MBSTATE_T_BROKEN
+
+ AC_CHECK_FUNCS_ONCE([wcrtomb])
+ if test $ac_cv_func_wcrtomb = no; then
+ HAVE_WCRTOMB=0
+ AC_CHECK_DECLS([wcrtomb],,, [[
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+]])
+ if test $ac_cv_have_decl_wcrtomb = yes; then
+ dnl On Minix 3.1.8, the system's <wchar.h> declares wcrtomb() although
+ dnl it does not have the function. Avoid a collision with gnulib's
+ dnl replacement.
+ REPLACE_WCRTOMB=1
+ fi
+ else
+ if test $REPLACE_MBSTATE_T = 1; then
+ REPLACE_WCRTOMB=1
+ else
+ dnl On AIX 4.3, OSF/1 5.1 and Solaris 10, wcrtomb (NULL, 0, NULL) sometimes
+ dnl returns 0 instead of 1.
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([gt_LOCALE_FR])
+ AC_REQUIRE([gt_LOCALE_FR_UTF8])
+ AC_REQUIRE([gt_LOCALE_JA])
+ AC_REQUIRE([gt_LOCALE_ZH_CN])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether wcrtomb return value is correct],
+ [gl_cv_func_wcrtomb_retval],
+ [
+ dnl Initial guess, used when cross-compiling or when no suitable locale
+ dnl is present.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on AIX 4, OSF/1 and Solaris.
+ aix4* | osf* | solaris*) gl_cv_func_wcrtomb_retval="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_wcrtomb_retval="guessing yes" ;;
+ esac
+changequote([,])dnl
+ if test $LOCALE_FR != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_JA != none || test $LOCALE_ZH_CN != none; then
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <locale.h>
+#include <string.h>
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#include <wchar.h>
+int main ()
+{
+ int result = 0;
+ if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
+ {
+ if (wcrtomb (NULL, 0, NULL) != 1)
+ result |= 1;
+ }
+ if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
+ {
+ if (wcrtomb (NULL, 0, NULL) != 1)
+ result |= 2;
+ }
+ if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
+ {
+ if (wcrtomb (NULL, 0, NULL) != 1)
+ result |= 4;
+ }
+ if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
+ {
+ if (wcrtomb (NULL, 0, NULL) != 1)
+ result |= 8;
+ }
+ return result;
+}]])],
+ [gl_cv_func_wcrtomb_retval=yes],
+ [gl_cv_func_wcrtomb_retval=no],
+ [:])
+ fi
+ ])
+ case "$gl_cv_func_wcrtomb_retval" in
+ *yes) ;;
+ *) REPLACE_WCRTOMB=1 ;;
+ esac
+ fi
+ fi
+])
+
+# Prerequisites of lib/wcrtomb.c.
+AC_DEFUN([gl_PREREQ_WCRTOMB], [
+ :
+])
diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4
new file mode 100644
index 000000000..a10938307
--- /dev/null
+++ b/m4/wctype_h.m4
@@ -0,0 +1,211 @@
+# wctype_h.m4 serial 16
+
+dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
+
+dnl Copyright (C) 2006-2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl_WCTYPE_H],
+[
+ AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_CHECK_FUNCS_ONCE([iswcntrl])
+ if test $ac_cv_func_iswcntrl = yes; then
+ HAVE_ISWCNTRL=1
+ else
+ HAVE_ISWCNTRL=0
+ fi
+ AC_SUBST([HAVE_ISWCNTRL])
+
+ AC_REQUIRE([AC_C_INLINE])
+
+ AC_REQUIRE([gt_TYPE_WINT_T])
+ if test $gt_cv_c_wint_t = yes; then
+ HAVE_WINT_T=1
+ else
+ HAVE_WINT_T=0
+ fi
+ AC_SUBST([HAVE_WINT_T])
+
+ gl_CHECK_NEXT_HEADERS([wctype.h])
+ if test $ac_cv_header_wctype_h = yes; then
+ if test $ac_cv_func_iswcntrl = yes; then
+ dnl Linux libc5 has an iswprint function that returns 0 for all arguments.
+ dnl The other functions are likely broken in the same way.
+ AC_CACHE_CHECK([whether iswcntrl works], [gl_cv_func_iswcntrl_works],
+ [
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+ /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
+ included before <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
+ must be included before <wchar.h>. */
+ #include <stddef.h>
+ #include <stdio.h>
+ #include <time.h>
+ #include <wchar.h>
+ #include <wctype.h>
+ int main () { return iswprint ('x') == 0; }
+ ]])],
+ [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
+ #if __GNU_LIBRARY__ == 1
+ Linux libc5 i18n is broken.
+ #endif]], [])],
+ [gl_cv_func_iswcntrl_works=yes], [gl_cv_func_iswcntrl_works=no])
+ ])
+ ])
+ fi
+ HAVE_WCTYPE_H=1
+ else
+ HAVE_WCTYPE_H=0
+ fi
+ AC_SUBST([HAVE_WCTYPE_H])
+
+ if test "$gl_cv_func_iswcntrl_works" = no; then
+ REPLACE_ISWCNTRL=1
+ else
+ REPLACE_ISWCNTRL=0
+ fi
+ AC_SUBST([REPLACE_ISWCNTRL])
+
+ if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
+ dnl Redefine all of iswcntrl, ..., iswxdigit in <wctype.h>.
+ :
+ fi
+
+ if test $REPLACE_ISWCNTRL = 1; then
+ REPLACE_TOWLOWER=1
+ else
+ AC_CHECK_FUNCS([towlower])
+ if test $ac_cv_func_towlower = yes; then
+ REPLACE_TOWLOWER=0
+ else
+ AC_CHECK_DECLS([towlower],,,
+ [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
+ included before <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
+ must be included before <wchar.h>. */
+ #include <stddef.h>
+ #include <stdio.h>
+ #include <time.h>
+ #include <wchar.h>
+ #if HAVE_WCTYPE_H
+ # include <wctype.h>
+ #endif
+ ]])
+ if test $ac_cv_have_decl_towlower = yes; then
+ dnl On Minix 3.1.8, the system's <wctype.h> declares towlower() and
+ dnl towupper() although it does not have the functions. Avoid a
+ dnl collision with gnulib's replacement.
+ REPLACE_TOWLOWER=1
+ else
+ REPLACE_TOWLOWER=0
+ fi
+ fi
+ fi
+ AC_SUBST([REPLACE_TOWLOWER])
+
+ if test $HAVE_ISWCNTRL = 0 || test $REPLACE_TOWLOWER = 1; then
+ dnl Redefine towlower, towupper in <wctype.h>.
+ :
+ fi
+
+ dnl We assume that the wctype() and iswctype() functions exist if and only
+ dnl if the type wctype_t is defined in <wchar.h> or in <wctype.h> if that
+ dnl exists.
+ dnl HP-UX 11.00 declares all these in <wchar.h> and lacks <wctype.h>.
+ AC_CACHE_CHECK([for wctype_t], [gl_cv_type_wctype_t],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
+ included before <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
+ must be included before <wchar.h>. */
+ #include <stddef.h>
+ #include <stdio.h>
+ #include <time.h>
+ #include <wchar.h>
+ #if HAVE_WCTYPE_H
+ # include <wctype.h>
+ #endif
+ wctype_t a;
+ ]],
+ [[]])],
+ [gl_cv_type_wctype_t=yes],
+ [gl_cv_type_wctype_t=no])
+ ])
+ if test $gl_cv_type_wctype_t = no; then
+ HAVE_WCTYPE_T=0
+ fi
+
+ dnl We assume that the wctrans() and towctrans() functions exist if and only
+ dnl if the type wctrans_t is defined in <wctype.h>.
+ AC_CACHE_CHECK([for wctrans_t], [gl_cv_type_wctrans_t],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be
+ included before <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h>
+ must be included before <wchar.h>. */
+ #include <stddef.h>
+ #include <stdio.h>
+ #include <time.h>
+ #include <wchar.h>
+ #include <wctype.h>
+ wctrans_t a;
+ ]],
+ [[]])],
+ [gl_cv_type_wctrans_t=yes],
+ [gl_cv_type_wctrans_t=no])
+ ])
+ if test $gl_cv_type_wctrans_t = no; then
+ HAVE_WCTRANS_T=0
+ fi
+
+ dnl Check for declarations of anything we want to poison if the
+ dnl corresponding gnulib module is not in use.
+ gl_WARN_ON_USE_PREPARE([[
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+ <wchar.h>.
+ BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+ included before <wchar.h>. */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <stddef.h>
+# include <stdio.h>
+# include <time.h>
+# include <wchar.h>
+#endif
+#include <wctype.h>
+ ]],
+ [wctype iswctype wctrans towctrans
+ ])
+])
+
+AC_DEFUN([gl_WCTYPE_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
+ gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+ dnl Define it also as a C macro, for the benefit of the unit tests.
+ gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_WCTYPE_H_DEFAULTS],
+[
+ GNULIB_ISWBLANK=0; AC_SUBST([GNULIB_ISWBLANK])
+ GNULIB_WCTYPE=0; AC_SUBST([GNULIB_WCTYPE])
+ GNULIB_ISWCTYPE=0; AC_SUBST([GNULIB_ISWCTYPE])
+ GNULIB_WCTRANS=0; AC_SUBST([GNULIB_WCTRANS])
+ GNULIB_TOWCTRANS=0; AC_SUBST([GNULIB_TOWCTRANS])
+ dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE_ISWBLANK=1; AC_SUBST([HAVE_ISWBLANK])
+ HAVE_WCTYPE_T=1; AC_SUBST([HAVE_WCTYPE_T])
+ HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T])
+ REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK])
+])
diff --git a/meta/guile-2.2-uninstalled.pc.in b/meta/guile-2.2-uninstalled.pc.in
index 6d8c36b18..e43fd3ae4 100644
--- a/meta/guile-2.2-uninstalled.pc.in
+++ b/meta/guile-2.2-uninstalled.pc.in
@@ -5,5 +5,8 @@ Name: GNU Guile (uninstalled)
Description: GNU's Ubiquitous Intelligent Language for Extension (uninstalled)
Version: @GUILE_VERSION@
Libs: -L${builddir}/libguile -lguile-@GUILE_EFFECTIVE_VERSION@ @BDW_GC_LIBS@
-Libs.private: @LIB_CLOCK_GETTIME@ @LIBGMP@ @LIBLTDL@ @LIBFFI_LIBS@ @GUILE_LIBS@
+Libs.private: @LIB_CLOCK_GETTIME@ @LIBGMP@ @LIBLTDL@ @LIBFFI_LIBS@ \
+ @LIBUNISTRING@ @GUILE_LIBS@ @LIBICONV@ @LIBINTL@ @LIBSOCKET@ \
+ @SERVENT_LIB@ @HOSTENT_LIB@ @GETADDRINFO_LIB@ @INET_NTOP_LIB@ \
+ @INET_PTON_LIB@
Cflags: -I${srcdir} -I${builddir} @GUILE_CFLAGS@ @BDW_GC_CFLAGS@
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 1780b843c..e929c4d58 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -161,7 +161,7 @@ non-locally, that exit determines the continuation."
(set! with-throw-handler
(lambda (k thunk pre-unwind-handler)
"Add @var{handler} to the dynamic context as a throw handler
-for key @var{key}, then invoke @var{thunk}."
+for key @var{k}, then invoke @var{thunk}."
(if (not (or (symbol? k) (eqv? k #t)))
(scm-error 'wrong-type-arg "with-throw-handler"
"Wrong type argument in position ~a: ~a"
diff --git a/module/ice-9/format.scm b/module/ice-9/format.scm
index c62348d9f..d038ace5a 100644
--- a/module/ice-9/format.scm
+++ b/module/ice-9/format.scm
@@ -1,5 +1,5 @@
;;;; "format.scm" Common LISP text output formatter for SLIB
-;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+;;; Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@
(define-module (ice-9 format)
#:autoload (ice-9 pretty-print) (pretty-print truncated-print)
+ #:autoload (ice-9 i18n) (%global-locale number->locale-string)
#:replace (format))
(define format:version "3.0")
@@ -272,6 +273,24 @@
((#\D) ; Decimal
(format:out-num-padded modifier (next-arg) params 10)
(anychar-dispatch))
+ ((#\H) ; Localized number
+ (let* ((num (next-arg))
+ (locale (case modifier
+ ((colon) (next-arg))
+ (else %global-locale)))
+ (argc (length params))
+ (width (format:par params argc 0 #f "width"))
+ (decimals (format:par params argc 1 #t "decimals"))
+ (padchar (integer->char
+ (format:par params argc 2 format:space-ch
+ "padchar")))
+ (str (number->locale-string num decimals
+ locale)))
+ (format:out-str (if (and width
+ (< (string-length str) width))
+ (string-pad str width padchar)
+ str)))
+ (anychar-dispatch))
((#\X) ; Hexadecimal
(format:out-num-padded modifier (next-arg) params 16)
(anychar-dispatch))
diff --git a/module/ice-9/i18n.scm b/module/ice-9/i18n.scm
index ce04aa304..ca949b4f3 100644
--- a/module/ice-9/i18n.scm
+++ b/module/ice-9/i18n.scm
@@ -1,6 +1,6 @@
;;;; i18n.scm --- internationalization support -*- coding: utf-8 -*-
-;;;; Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+;;;; Copyright (C) 2006, 2007, 2009, 2010, 2012 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -101,13 +101,10 @@
;;;
;; Helper macro: Define a procedure named NAME that maps its argument to
-;; NL-ITEMS (when `nl-langinfo' is provided) or DEFAULTS (when `nl-langinfo'
-;; is not provided).
-(define-macro (define-vector-langinfo-mapping name nl-items defaults)
+;; NL-ITEMS. Gnulib guarantees that these items are available.
+(define-macro (define-vector-langinfo-mapping name nl-items)
(let* ((item-count (length nl-items))
- (defines (if (provided? 'nl-langinfo)
- `(define %nl-items (vector #f ,@nl-items))
- `(define %defaults (vector #f ,@defaults))))
+ (defines `(define %nl-items (vector #f ,@nl-items)))
(make-body (lambda (result)
`(if (and (integer? item) (exact? item))
(if (and (>= item 1) (<= item ,item-count))
@@ -116,28 +113,21 @@
(throw 'wrong-type-arg "wrong argument type" item)))))
`(define (,name item . locale)
,defines
- ,(make-body (if (provided? 'nl-langinfo)
- '(apply nl-langinfo (vector-ref %nl-items item) locale)
- '(vector-ref %defaults item))))))
+ ,(make-body '(apply nl-langinfo (vector-ref %nl-items item) locale)))))
(define-vector-langinfo-mapping locale-day-short
- (ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7)
- ("Sun" "Mon" "Tue" "Wed" "Thu" "Fri" "Sat"))
+ (ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7))
(define-vector-langinfo-mapping locale-day
- (DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7)
- ("Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"))
+ (DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7))
(define-vector-langinfo-mapping locale-month-short
(ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6
- ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12)
- ("Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
+ ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12))
(define-vector-langinfo-mapping locale-month
- (MON_1 MON_2 MON_3 MON_4 MON_5 MON_6 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12)
- ("January" "February" "March" "April" "May" "June" "July" "August"
- "September" "October" "November" "December"))
+ (MON_1 MON_2 MON_3 MON_4 MON_5 MON_6 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12))
@@ -145,9 +135,13 @@
;;; Date and time.
;;;
-;; Helper macro: Define a procedure NAME that gets langinfo item ITEM.
+;; Define a procedure NAME that gets langinfo item ITEM. Gnulib's
+;; `nl_langinfo' does not guarantee that all these items are supported
+;; (for instance, `GROUPING' is lacking on Darwin and Gnulib provides no
+;; replacement), so use DEFAULT as the default value when ITEM is not
+;; available.
(define-macro (define-simple-langinfo-mapping name item default)
- (let ((body (if (and (provided? 'nl-langinfo) (defined? item))
+ (let ((body (if (defined? item)
`(apply nl-langinfo ,item locale)
default)))
`(define (,name . locale)
@@ -182,13 +176,18 @@
;;; Monetary information.
;;;
+;; Define a procedure NAME that gets item LOCAL-ITEM or INTL-ITEM,
+;; depending on whether the caller asked for the international version
+;; or not. Since Gnulib's `nl_langinfo' module doesn't guarantee that
+;; all these items are available, use DEFAULT/LOCAL and DEFAULT/INTL as
+;; default values when the system does not support them.
(define-macro (define-monetary-langinfo-mapping name local-item intl-item
default/local default/intl)
(let ((body
- (let ((intl (if (and (provided? 'nl-langinfo) (defined? intl-item))
+ (let ((intl (if (defined? intl-item)
`(apply nl-langinfo ,intl-item locale)
default/intl))
- (local (if (and (provided? 'nl-langinfo) (defined? local-item))
+ (local (if (defined? local-item)
`(apply nl-langinfo ,local-item locale)
default/local)))
`(if intl? ,intl ,local))))
diff --git a/module/ice-9/popen.scm b/module/ice-9/popen.scm
index b3def4a1e..b9debd444 100644
--- a/module/ice-9/popen.scm
+++ b/module/ice-9/popen.scm
@@ -136,7 +136,7 @@
"Executes the program @var{command} with optional arguments
@var{args} (all strings) in a subprocess.
A port to the process (based on pipes) is created and returned.
-@var{modes} specifies whether an input, an output or an input-output
+@var{mode} specifies whether an input, an output or an input-output
port to the process is created: it should be the value of
@code{OPEN_READ}, @code{OPEN_WRITE} or @code{OPEN_BOTH}."
(let* ((port/pid (apply open-process mode command args))
@@ -148,7 +148,7 @@ port to the process is created: it should be the value of
(define (open-pipe command mode)
"Executes the shell command @var{command} (a string) in a subprocess.
A port to the process (based on pipes) is created and returned.
-@var{modes} specifies whether an input, an output or an input-output
+@var{mode} specifies whether an input, an output or an input-output
port to the process is created: it should be the value of
@code{OPEN_READ}, @code{OPEN_WRITE} or @code{OPEN_BOTH}."
(open-pipe* mode "/bin/sh" "-c" command))
diff --git a/module/ice-9/pretty-print.scm b/module/ice-9/pretty-print.scm
index 5ea66c7e5..8a0c0b855 100644
--- a/module/ice-9/pretty-print.scm
+++ b/module/ice-9/pretty-print.scm
@@ -298,7 +298,7 @@ port directly after OBJ, like (pretty-print OBJ PORT)."
(width 79)
(display? #f)
(breadth-first? #f))
- "Print @var{obj}, truncating the output, if necessary, to make it fit
+ "Print @var{x}, truncating the output, if necessary, to make it fit
into @var{width} characters. By default, @var{x} will be printed using
@code{write}, though that behavior can be overriden via the
@var{display?} keyword argument.
diff --git a/module/ice-9/r4rs.scm b/module/ice-9/r4rs.scm
index 86b6e9454..072c8c6b4 100644
--- a/module/ice-9/r4rs.scm
+++ b/module/ice-9/r4rs.scm
@@ -39,14 +39,14 @@
(@call-with-values producer consumer))
(define (dynamic-wind in thunk out)
"All three arguments must be 0-argument procedures.
-@var{in_guard} is called, then @var{thunk}, then
-@var{out_guard}.
+Guard @var{in} is called, then @var{thunk}, then
+guard @var{out}.
If, any time during the execution of @var{thunk}, the
continuation of the @code{dynamic_wind} expression is escaped
-non-locally, @var{out_guard} is called. If the continuation of
-the dynamic-wind is re-entered, @var{in_guard} is called. Thus
-@var{in_guard} and @var{out_guard} may be called any number of
+non-locally, @var{out} is called. If the continuation of
+the dynamic-wind is re-entered, @var{in} is called. Thus
+@var{in} and @var{out} may be called any number of
times.
@lisp
(define x 'normal-binding)
diff --git a/module/language/tree-il/analyze.scm b/module/language/tree-il/analyze.scm
index 04687a8c9..28312514a 100644
--- a/module/language/tree-il/analyze.scm
+++ b/module/language/tree-il/analyze.scm
@@ -1,6 +1,6 @@
;;; TREE-IL -> GLIL compiler
-;; Copyright (C) 2001, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 2001, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -1334,6 +1334,12 @@ accurate information is missing from a given `tree-il' element."
;; We don't have enough info to determine the exact number
;; of args, but we could determine a lower bound (TODO).
(values 'any 'any))
+ ((#\h #\H)
+ (let ((argc (if (memq #\: params) 2 1)))
+ (loop (cdr chars) 'literal '()
+ conditions end-group
+ (+ argc min-count)
+ (+ argc max-count))))
(else (loop (cdr chars) 'literal '()
conditions end-group
(+ 1 min-count) (+ 1 max-count)))))
diff --git a/module/rnrs/io/ports.scm b/module/rnrs/io/ports.scm
index 246e46b39..fddb4914b 100644
--- a/module/rnrs/io/ports.scm
+++ b/module/rnrs/io/ports.scm
@@ -237,7 +237,7 @@ if the port has no transcoder."
(not (port-encoding port)))
(define (textual-port? port)
- "Always returns @var{#t}, as all ports can be used for textual I/O in
+ "Always returns @code{#t}, as all ports can be used for textual I/O in
Guile."
#t)
diff --git a/module/texinfo/string-utils.scm b/module/texinfo/string-utils.scm
index eff914369..767514952 100644
--- a/module/texinfo/string-utils.scm
+++ b/module/texinfo/string-utils.scm
@@ -160,7 +160,7 @@ characters. Any needed padding is done by character @var{chr}, which
defaults to @samp{#\\space}. If @var{rchr} is provided, then the
padding to the right will use it instead. See the examples below.
left and @var{rchr} on the right. The default @var{width} is 80. The
-default @var{lchr} and @var{rchr} is @samp{#\\space}. The string is
+default @var{chr} and @var{rchr} is @samp{#\\space}. The string is
never truncated.
@lisp
(center-string \"Richard Todd\" 24)
@@ -392,7 +392,7 @@ in @code{make-text-wrapper}."
(define (fill-string str . kwargs)
"Wraps the text given in string @var{str} according to the parameters
-provided in @var{keywds}, or the default setting if they are not
+provided in @var{kwargs}, or the default setting if they are not
given. Returns a single string with the wrapped text. Valid keyword
arguments are discussed in @code{make-text-wrapper}."
(string-join (apply string->wrapped-lines str kwargs)
diff --git a/module/web/http.scm b/module/web/http.scm
index b060af91e..c15bc3ed7 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -205,7 +205,7 @@ header with name @var{sym}."
(define (write-header sym val port)
"Writes the given header name and value to @var{port}. If @var{sym}
is a known header, uses the specific writer registered for that header.
-Otherwise the value is written using @var{display}."
+Otherwise the value is written using @code{display}."
(display (header->string sym) port)
(display ": " port)
((header-writer sym) val port)
diff --git a/module/web/request.scm b/module/web/request.scm
index c9204a4bf..8259887c0 100644
--- a/module/web/request.scm
+++ b/module/web/request.scm
@@ -217,7 +217,7 @@ on @var{port}, perhaps using some transfer encoding."
(bytevector-length bv) nbytes))))))
(define (write-request-body r bv)
- "Write @var{body}, a bytevector, to the port corresponding to the HTTP
+ "Write @var{bv}, a bytevector, to the port corresponding to the HTTP
request @var{r}."
(put-bytevector (request-port r) bv))
diff --git a/module/web/response.scm b/module/web/response.scm
index 62837721c..f49a602f0 100644
--- a/module/web/response.scm
+++ b/module/web/response.scm
@@ -226,7 +226,7 @@ on @var{port}, perhaps using some transfer encoding."
(bytevector-length bv) nbytes))))))
(define (write-response-body r bv)
- "Write @var{body}, a bytevector, to the port corresponding to the HTTP
+ "Write @var{bv}, a bytevector, to the port corresponding to the HTTP
response @var{r}."
(put-bytevector (response-port r) bv))
diff --git a/test-suite/lib.scm b/test-suite/lib.scm
index 9a03dc915..681a0d158 100644
--- a/test-suite/lib.scm
+++ b/test-suite/lib.scm
@@ -1,6 +1,6 @@
;;;; test-suite/lib.scm --- generic support for testing
;;;; Copyright (C) 1999, 2000, 2001, 2004, 2006, 2007, 2009, 2010,
-;;;; 2011 Free Software Foundation, Inc.
+;;;; 2011, 2012 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -56,6 +56,9 @@
;; Using the debugging evaluator.
with-debugging-evaluator with-debugging-evaluator*
+ ;; Clearing stale references on the C stack for GC-sensitive tests.
+ clear-stale-stack-references
+
;; Using a given locale
with-locale with-locale* with-latin1-locale with-latin1-locale*
@@ -484,6 +487,17 @@
(define-macro (with-debugging-evaluator . body)
`(with-debugging-evaluator* (lambda () ,@body)))
+;; Recurse through a C function that should clear any values that might
+;; have spilled on the stack temporarily. (The salient feature of
+;; with-continuation-barrier is that currently it is implemented as a C
+;; function that recursively calls the VM.)
+;;
+(define* (clear-stale-stack-references #:optional (n 10))
+ (if (positive? n)
+ (with-continuation-barrier
+ (lambda ()
+ (clear-stale-stack-references (1- n))))))
+
;;; Call THUNK with a given locale
(define (with-locale* nloc thunk)
(let ((loc #f))
diff --git a/test-suite/standalone/test-loose-ends.c b/test-suite/standalone/test-loose-ends.c
index ee0fcf3f3..b4ea5b94a 100644
--- a/test-suite/standalone/test-loose-ends.c
+++ b/test-suite/standalone/test-loose-ends.c
@@ -75,11 +75,28 @@ test_scm_call ()
}
static void
+test_scm_to_pointer ()
+{
+ int (*add3) (int a, int b, int c);
+ SCM int_type = scm_c_public_ref ("system foreign", "int");
+
+ add3 = scm_to_pointer
+ (scm_procedure_to_pointer (int_type,
+ scm_c_public_ref ("guile", "+"),
+ scm_list_3 (int_type,
+ int_type,
+ int_type)));
+
+ assert ((*add3) (1000000, 1000, -1) == 1000999);
+}
+
+static void
tests (void *data, int argc, char **argv)
{
test_scm_from_locale_keywordn ();
test_scm_local_eval ();
test_scm_call ();
+ test_scm_to_pointer ();
}
int
diff --git a/test-suite/tests/format.test b/test-suite/tests/format.test
index 24ad8354c..a411b49e7 100644
--- a/test-suite/tests/format.test
+++ b/test-suite/tests/format.test
@@ -1,7 +1,7 @@
;;;; format.test --- test suite for Guile's CL-ish format -*- scheme -*-
;;;; Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de> --- June 2001
;;;;
-;;;; Copyright (C) 2001, 2003, 2004, 2006, 2010, 2011 Free Software Foundation, Inc.
+;;;; Copyright (C) 2001, 2003, 2004, 2006, 2010, 2011, 2012 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,7 @@
(define-module (test-format)
#:use-module (test-suite lib)
+ #:use-module (ice-9 i18n)
#:use-module (ice-9 format))
@@ -97,6 +98,31 @@
(string=? "2.5" (format #f "~f" "02.5"))))
;;;
+;;; ~h
+;;;
+
+(setlocale LC_ALL "C")
+(with-test-prefix "~h localized number"
+
+ (pass-if "1234.5"
+ (string=? (format #f "~h" 1234.5) "1234.5"))
+
+ (pass-if "padding"
+ (string=? (format #f "~6h" 123.2) " 123.2"))
+
+ (pass-if "padchar"
+ (string=? (format #f "~8,,'*h" 123.2) "***123.2"))
+
+ (pass-if "decimals"
+ (string=? (format #f "~,2h" 123.4567)
+ "123.45"))
+
+ (pass-if "locale"
+ (string=? (format #f "~,3:h, ~a" 1234.5678
+ %global-locale "approximately")
+ "1234.567, approximately")))
+
+;;;
;;; ~{
;;;
diff --git a/test-suite/tests/gc.test b/test-suite/tests/gc.test
index 97eeb195e..e13c8f7cd 100644
--- a/test-suite/tests/gc.test
+++ b/test-suite/tests/gc.test
@@ -22,6 +22,16 @@
#:use-module ((system base compile) #:select (compile)))
+;; Some of these tests verify that things are collectable. As we use a
+;; third-party conservative collector, we really can't guarantee that --
+;; we can try, but on some platforms, on some versions (possibly), the
+;; test might fail. But we don't want that to stop the build. So,
+;; instead of failing, throw 'unresolved.
+;;
+(define (maybe-gc-flakiness result)
+ (or result
+ (throw 'unresolved)))
+
;;;
;;; miscellaneous
;;;
@@ -49,13 +59,6 @@
;;;
;;;
-(define (stack-cleanup depth)
- ;; Clean up stack space for DEPTH words. This is defined here so that
- ;; `peval' doesn't inline it.
- (let cleanup ((i depth))
- (and (> i 0)
- (begin (cleanup (1- i)) i))))
-
(with-test-prefix "gc"
(pass-if "after-gc-hook gets called"
@@ -73,18 +76,19 @@
(for-each (lambda (x) (guard (make-module))) (iota total))
;; Avoid false references to the modules on the stack.
- (stack-cleanup 20)
+ (clear-stale-stack-references)
(gc)
(gc) ;; twice: have to kill the weak vectors.
(gc) ;; thrice: because the test doesn't succeed with only
;; one gc round. not sure why.
- (= (let lp ((i 0))
- (if (guard)
- (lp (1+ i))
- i))
- total)))
+ (maybe-gc-flakiness
+ (= (let lp ((i 0))
+ (if (guard)
+ (lp (1+ i))
+ i))
+ total))))
(pass-if "Lexical vars are collectable"
(let ((l (compile
@@ -92,21 +96,9 @@
(define guardian (make-guardian))
(let ((f (list 'foo)))
(guardian f))
- ;; See below.
- ;; ((lambda () #t))
+ ((@ (test-suite lib) clear-stale-stack-references))
(gc)(gc)(gc)
(guardian))
;; Prevent the optimizer from propagating f.
#:opts '(#:partial-eval? #f))))
- (if (not l)
- ;; We think that something on the C stack in the VM is holding
- ;; on to a reference to the list. This happens on
- ;; register-poor architectures, where more locals are spilled
- ;; to the stack. If more code runs before the (gc) is run,
- ;; like a ((lambda () #t)), then the test passes. So given
- ;; that at some point, the reference will be dropped, we will
- ;; count these cases as "unresolved" instead of "fail".
- ;;
- ;; See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=10336.
- (throw 'unresolved)
- (equal? l '(foo))))))
+ (equal? l '(foo)))))
diff --git a/test-suite/tests/i18n.test b/test-suite/tests/i18n.test
index da2308058..ef08dd4b4 100644
--- a/test-suite/tests/i18n.test
+++ b/test-suite/tests/i18n.test
@@ -18,9 +18,10 @@
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(define-module (test-suite i18n)
- :use-module (ice-9 i18n)
- :use-module (srfi srfi-1)
- :use-module (test-suite lib))
+ #:use-module (ice-9 i18n)
+ #:use-module (ice-9 format)
+ #:use-module (srfi srfi-1)
+ #:use-module (test-suite lib))
;; Start from a pristine locale state.
(setlocale LC_ALL "C")
@@ -94,6 +95,9 @@
(define %greek-utf8-locale-name
"el_GR.UTF-8")
+(define %american-english-locale-name
+ "en_US")
+
(define %french-locale
(false-if-exception
(make-locale (list LC_CTYPE LC_COLLATE LC_NUMERIC LC_TIME)
@@ -119,6 +123,11 @@
(make-locale LC_ALL
%turkish-utf8-locale-name)))
+(define %american-english-locale
+ (false-if-exception
+ (make-locale LC_ALL
+ %american-english-locale-name)))
+
(define (under-locale-or-unresolved locale thunk)
;; On non-GNU systems, an exception may be raised only when the locale is
;; actually used rather than at `make-locale'-time. Thus, we must guard
@@ -138,11 +147,12 @@
(under-locale-or-unresolved %french-utf8-locale thunk))
(define (under-turkish-utf8-locale-or-unresolved thunk)
- ;; FreeBSD 8.2 and Solaris 2.10 have a broken tr_TR locale where `i'
- ;; is mapped to uppercase `I' instead of `Ä°', so disable tests on that
- ;; platform.
+ ;; FreeBSD 8.2, Solaris 2.10, and Darwin 8.11.0 have a broken tr_TR
+ ;; locale where `i' is mapped to uppercase `I' instead of `Ä°', so
+ ;; disable tests on that platform.
(if (or (string-contains %host-type "freebsd8")
- (string-contains %host-type "solaris2.10"))
+ (string-contains %host-type "solaris2.10")
+ (string-contains %host-type "darwin8"))
(throw 'unresolved)
(under-locale-or-unresolved %turkish-utf8-locale thunk)))
@@ -152,6 +162,10 @@
(define (under-greek-utf8-locale-or-unresolved thunk)
(under-locale-or-unresolved %greek-utf8-locale thunk))
+(define (under-american-english-locale-or-unresolved thunk)
+ (under-locale-or-unresolved %american-english-locale thunk))
+
+
(with-test-prefix "text collation (French)"
(pass-if "string-locale<?"
@@ -478,3 +492,48 @@
(let ((fr (make-locale LC_ALL %french-locale-name)))
(string=? "1 234,5"
(number->locale-string 1234.567 1 fr))))))))
+
+(with-test-prefix "format ~h"
+
+ ;; Some systems like Darwin lack the `GROUPING' nl_item, and thus
+ ;; `locale-digit-grouping' defaults to '(); skip the tests in that
+ ;; case.
+
+ (with-test-prefix "French"
+
+ (pass-if "12345.5678"
+ (under-french-locale-or-unresolved
+ (lambda ()
+ (if (null? (locale-digit-grouping %french-locale))
+ (throw 'unresolved)
+ (string=? "12 345,6789"
+ (format #f "~:h" 12345.6789 %french-locale)))))))
+
+ (with-test-prefix "English"
+
+ (pass-if "12345.5678"
+ (under-american-english-locale-or-unresolved
+ (lambda ()
+ (if (null? (locale-digit-grouping %american-english-locale))
+ (throw 'unresolved)
+ (string=? "12,345.6789"
+ (format #f "~:h" 12345.6789
+ %american-english-locale))))))))
+
+(with-test-prefix "monetary-amount->locale-string"
+
+ (with-test-prefix "French"
+
+ (pass-if "integer"
+ (under-french-locale-or-unresolved
+ (lambda ()
+ (let ((fr (make-locale LC_ALL %french-locale-name)))
+ (string=? "123 456 +EUR"
+ (monetary-amount->locale-string 123456 #f fr))))))
+
+ (pass-if "fraction"
+ (under-french-locale-or-unresolved
+ (lambda ()
+ (let ((fr (make-locale LC_ALL %french-locale-name)))
+ (string=? "1 234,56 EUR "
+ (monetary-amount->locale-string 1234.567 #t fr))))))))
diff --git a/test-suite/tests/net-db.test b/test-suite/tests/net-db.test
index 89ebb1b1c..edd87cef8 100644
--- a/test-suite/tests/net-db.test
+++ b/test-suite/tests/net-db.test
@@ -1,7 +1,7 @@
;;;; net-db.test --- Test suite for `net-db' -*- mode: scheme; coding: utf-8; -*-
;;;; Ludovic Courtès <ludo@gnu.org>
;;;;
-;;;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+;;;; Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -100,7 +100,11 @@
#f))
(lambda (key errcode)
;; According to POSIX, both error codes are valid (glibc 2.11
- ;; chooses `EAI_SERVICE'; Darwin chooses `EAI_NONAME'.)
+ ;; chooses `EAI_SERVICE'; Darwin 8.11.0 chooses the non-POSIX
+ ;; `EAI_NODATA', and more recent Darwin versions choose
+ ;; `EAI_NONAME'.)
(and (or (= errcode EAI_SERVICE)
- (= errcode EAI_NONAME))
+ (= errcode EAI_NONAME)
+ (and (defined? 'EAI_NODATA)
+ (= errcode EAI_NODATA)))
(string? (gai-strerror errcode))))))))
diff --git a/test-suite/tests/srfi-14.test b/test-suite/tests/srfi-14.test
index 959612c7a..5f937604f 100644
--- a/test-suite/tests/srfi-14.test
+++ b/test-suite/tests/srfi-14.test
@@ -797,13 +797,13 @@
(pass-if "char-set:punctuation"
(char-set<= (string->char-set
(string-append "!\"#%&'()*,-./:;?@[\\]_{}"
- "¡«·»¿"))
+ "¡§«¶·»¿"))
char-set:punctuation))
(pass-if "char-set:symbol"
(char-set<= (string->char-set
(string-append "$+<=>^`|~"
- "¢£¤¥¦§¨©¬®¯°±´¶¸×÷"))
+ "¢£¤¥¦¨©¬®¯°±´¸×÷"))
char-set:symbol))
;; Note that SRFI-14 itself is inconsistent here. Characters that
diff --git a/test-suite/tests/srfi-42.test b/test-suite/tests/srfi-42.test
index 5417de04c..1de337e30 100644
--- a/test-suite/tests/srfi-42.test
+++ b/test-suite/tests/srfi-42.test
@@ -3,7 +3,7 @@
;;; Examples for Eager Comprehensions in [outer..inner|expr]-Convention
;;; ===================================================================
;;;
-;;; Copyright (C) 2010 Free Software Foundation, Inc.
+;;; Copyright (C) 2010, 2012 Free Software Foundation, Inc.
;;; Copyright (c) 2007 Sebastian Egner
;;;
;;; This code is based on the file examples.scm in the reference
@@ -616,3 +616,5 @@
(close-output-port f))
(read-lines "tmp1") )
=> (list-ec (:char-range c #\0 #\9) (string c #\newline)) )
+
+(false-if-exception (delete-file "tmp1"))
diff --git a/test-suite/tests/threads.test b/test-suite/tests/threads.test
index 85a7c38ef..be722fc75 100644
--- a/test-suite/tests/threads.test
+++ b/test-suite/tests/threads.test
@@ -1,6 +1,6 @@
;;;; threads.test --- Tests for Guile threading. -*- scheme -*-
;;;;
-;;;; Copyright 2003, 2006, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+;;;; Copyright 2003, 2006, 2007, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@@ -36,13 +36,6 @@
(equal? '(a b c) '(a b c))
a))
-(define (stack-cleanup depth)
- ;; Clean up stack space for DEPTH words. This is defined here so that
- ;; `peval' doesn't inline it.
- (let cleanup ((i depth))
- (and (> i 0)
- (begin (cleanup (1- i)) i))))
-
(if (provided? 'threads)
(begin
@@ -410,7 +403,7 @@
(g (let ((m (make-mutex))) (lock-mutex m) m))
;; Avoid false references to M on the stack.
- (stack-cleanup 20)
+ (clear-stale-stack-references)
(gc) (gc)
(let ((m (g)))
diff --git a/test-suite/tests/tree-il.test b/test-suite/tests/tree-il.test
index 0ab58c98a..1e0b8c179 100644
--- a/test-suite/tests/tree-il.test
+++ b/test-suite/tests/tree-il.test
@@ -2250,6 +2250,32 @@
(number? (string-contains (car w)
"expected 1, got 2")))))
+ (pass-if "~h"
+ (null? (call-with-warnings
+ (lambda ()
+ (compile '((@ (ice-9 format) format) #t
+ "foo ~h ~a~%" 123.4 'bar)
+ #:opts %opts-w-format
+ #:to 'assembly)))))
+
+ (pass-if "~:h with locale object"
+ (null? (call-with-warnings
+ (lambda ()
+ (compile '((@ (ice-9 format) format) #t
+ "foo ~:h~%" 123.4 %global-locale)
+ #:opts %opts-w-format
+ #:to 'assembly)))))
+
+ (pass-if "~:h without locale object"
+ (let ((w (call-with-warnings
+ (lambda ()
+ (compile '((@ (ice-9 format) format) #t "foo ~,2:h" 123.4)
+ #:opts %opts-w-format
+ #:to 'assembly)))))
+ (and (= (length w) 1)
+ (number? (string-contains (car w)
+ "expected 2, got 1")))))
+
(with-test-prefix "conditionals"
(pass-if "literals"
(null? (call-with-warnings
diff --git a/test-suite/vm/run-vm-tests.scm b/test-suite/vm/run-vm-tests.scm
index f23dff682..9304e8179 100644
--- a/test-suite/vm/run-vm-tests.scm
+++ b/test-suite/vm/run-vm-tests.scm
@@ -67,7 +67,7 @@ it succeeded."
(define (run-vm-tests files)
"For each file listed in @var{files}, load it and run it through both the
interpreter and the VM (after having it compiled). Both results must be
-equal in the sense of @var{equal?}."
+equal in the sense of @code{equal?}."
(let* ((res (map (lambda (file)
(format #t "running `~a'... " file)
(if (catch #t