Commit 92418c9b authored by Erick's avatar Erick

Recognize UTF-8 strings in regexps

parent 686b9eeb
...@@ -6279,6 +6279,7 @@ then ...@@ -6279,6 +6279,7 @@ then
PCRE_FLAGS="-Dregexec=PCRE_regexec -Dregcomp=PCRE_regcomp \ PCRE_FLAGS="-Dregexec=PCRE_regexec -Dregcomp=PCRE_regcomp \
-Dregerror=PCRE_regerror -Dregfree=PCRE_regfree" -Dregerror=PCRE_regerror -Dregfree=PCRE_regfree"
(cd pcre; CC=${CC} CFLAGS="${CFLAGS} $PCRE_FLAGS" ./configure \ (cd pcre; CC=${CC} CFLAGS="${CFLAGS} $PCRE_FLAGS" ./configure \
--enable-utf8 \
--prefix=$prefix --disable-shared --disable-cpp) || \ --prefix=$prefix --disable-shared --disable-cpp) || \
{ echo "Cannot configure PCRE"; exit; } { echo "Cannot configure PCRE"; exit; }
PCRE=pcre PCRE=pcre
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
### ###
### Author: Erick Gallesio [eg@unice.fr] ### Author: Erick Gallesio [eg@unice.fr]
### Creation date: 28-Dec-1999 21:19 (eg) ### Creation date: 28-Dec-1999 21:19 (eg)
### Last file update: 27-Jul-2011 23:01 (eg) ### Last file update: 21-Aug-2011 12:56 (eg)
AC_PREREQ(2.64) AC_PREREQ(2.64)
AC_INIT([stklos], [1.10]) AC_INIT([stklos], [1.10])
...@@ -62,7 +62,7 @@ fi ...@@ -62,7 +62,7 @@ fi
eval `CC=$CC /bin/sh ./utils/shlib-options` eval `CC=$CC /bin/sh ./utils/shlib-options`
case $OS_NAME_VERSION in case $OS_NAME_VERSION in
SUNOS*) SUNOS*)
CFLAGS="$CFLAGS -DSOLARIS"; CFLAGS="$CFLAGS -DSOLARIS";
LIBS="$LIBS -lsocket -lrt -lnsl -lpthread" LIBS="$LIBS -lsocket -lrt -lnsl -lpthread"
;; ;;
...@@ -76,7 +76,7 @@ case $OS_NAME_VERSION in ...@@ -76,7 +76,7 @@ case $OS_NAME_VERSION in
echo "**** Please modify the script \"utils/shlib-options\" to add" echo "**** Please modify the script \"utils/shlib-options\" to add"
echo "**** support for your system (it's easy) and restart installation process." echo "**** support for your system (it's easy) and restart installation process."
echo "**** Thanks for sending your modifications to <bugs _at_ stklos.net>" echo "**** Thanks for sending your modifications to <bugs _at_ stklos.net>"
exit 1 exit 1
;; ;;
esac esac
...@@ -90,8 +90,8 @@ PREFIX=$prefix ...@@ -90,8 +90,8 @@ PREFIX=$prefix
BUILD_OS=$os-$version BUILD_OS=$os-$version
BUILD_ARCH=`uname -m` BUILD_ARCH=`uname -m`
OS_NAME=$OS OS_NAME=$OS
case $OS in case $OS in
LINUX) LINUX)
v=`echo $version | sed -e 's/\([[0-9]]*\)\.\([[0-9\]]*\).*/\1_\2/'` v=`echo $version | sed -e 's/\([[0-9]]*\)\.\([[0-9\]]*\).*/\1_\2/'`
OS_NAME_VERSION=LINUX_$v OS_NAME_VERSION=LINUX_$v
;; ;;
...@@ -102,7 +102,7 @@ case $OS in ...@@ -102,7 +102,7 @@ case $OS in
*) OS_NAME_VERSION=DARWIN_OLD;; *) OS_NAME_VERSION=DARWIN_OLD;;
esac esac
;; ;;
*) *)
v=`echo $version | sed -e 's/[[^0-9]]/_/g'` v=`echo $version | sed -e 's/[[^0-9]]/_/g'`
OS_NAME_VERSION=$OS\_$v; OS_NAME_VERSION=$OS\_$v;
esac esac
...@@ -144,7 +144,7 @@ case "$THREADS" in ...@@ -144,7 +144,7 @@ case "$THREADS" in
;; ;;
posix | pthreads) posix | pthreads)
### Check for pthreads ### Check for pthreads
AC_CHECK_LIB(pthread, pthread_create, LIBS="-lpthread $LIBS", AC_CHECK_LIB(pthread, pthread_create, LIBS="-lpthread $LIBS",
[AC_MSG_ERROR([Missing PThread library])]) [AC_MSG_ERROR([Missing PThread library])])
THREADS=pthreads THREADS=pthreads
AC_DEFINE(THREADS_PTHREADS, [], [PThread support]) AC_DEFINE(THREADS_PTHREADS, [], [PThread support])
...@@ -172,16 +172,16 @@ AM_CONDITIONAL(PTHREADS, test "$THREADS" = pthreads) ...@@ -172,16 +172,16 @@ AM_CONDITIONAL(PTHREADS, test "$THREADS" = pthreads)
AM_CONDITIONAL(NO_THREAD, test "$THREADS" = none) AM_CONDITIONAL(NO_THREAD, test "$THREADS" = none)
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# GC support # GC support
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
echo "*****" echo "*****"
echo "***** GC support" echo "***** GC support"
echo "*****" echo "*****"
# Try to determine if libgc is installed # Try to determine if libgc is installed
if ${PKGCONFIG} --exists bdw-gc ;then if ${PKGCONFIG} --exists bdw-gc ;then
HAVE_GC="yes" HAVE_GC="yes"
else else
AC_CHECK_LIB(gc, GC_malloc, HAVE_GC="yes", HAVE_GC="no", $LIBS) AC_CHECK_LIB(gc, GC_malloc, HAVE_GC="yes", HAVE_GC="no", $LIBS)
fi fi
...@@ -191,11 +191,11 @@ AC_ARG_WITH(provided-gc, ...@@ -191,11 +191,11 @@ AC_ARG_WITH(provided-gc,
PROV_GC="$withval", PROV_GC="no") PROV_GC="$withval", PROV_GC="no")
if test "$HAVE_GC" = "no" -o "$PROV_GC" = "yes" if test "$HAVE_GC" = "no" -o "$PROV_GC" = "yes"
then then
echo "... Configuring libgc" echo "... Configuring libgc"
case $OS_NAME_VERSION in case $OS_NAME_VERSION in
DARWIN_10) DARWIN_10)
cflags="${CFLAGS} -D_XOPEN_SOURCE";; cflags="${CFLAGS} -D_XOPEN_SOURCE";;
*) *)
cflags="${CFLAGS}";; cflags="${CFLAGS}";;
...@@ -223,7 +223,7 @@ fi ...@@ -223,7 +223,7 @@ fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# GMP support # GMP support
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
echo "*****" echo "*****"
echo "***** GMP support" echo "***** GMP support"
...@@ -240,7 +240,7 @@ if test "$HAVE_GMP" = "no" ;then ...@@ -240,7 +240,7 @@ if test "$HAVE_GMP" = "no" ;then
AC_CHECK_LIB(gmp, __gmpz_init_set, HAVE_GMP="yes", HAVE_GMP="no") AC_CHECK_LIB(gmp, __gmpz_init_set, HAVE_GMP="yes", HAVE_GMP="no")
fi fi
# Test if the user want to force with our GMP lib # Test if the user want to force with our GMP lib
# (2 names available for that --with-provided-bignum or (legacy) --with-gmp-light # (2 names available for that --with-provided-bignum or (legacy) --with-gmp-light
AC_ARG_WITH(provided-bignum, AC_ARG_WITH(provided-bignum,
[ --with-provided-bignum use the provided Bignum (GMPlite) library], [ --with-provided-bignum use the provided Bignum (GMPlite) library],
...@@ -253,7 +253,7 @@ if test "$PROV_GMP" = "no" ;then ...@@ -253,7 +253,7 @@ if test "$PROV_GMP" = "no" ;then
fi fi
if test "$HAVE_GMP" = "no" -o "$PROV_GMP" = "yes" if test "$HAVE_GMP" = "no" -o "$PROV_GMP" = "yes"
then then
echo "... Configuring libgmp" echo "... Configuring libgmp"
(cd gmp; CC=${CC} CFLAGS="${cflags} -I../src -DFOR_STKLOS=1" ./configure \ (cd gmp; CC=${CC} CFLAGS="${cflags} -I../src -DFOR_STKLOS=1" ./configure \
--prefix=$prefix) || { echo "Cannot configure the GMP"; exit; } --prefix=$prefix) || { echo "Cannot configure the GMP"; exit; }
...@@ -272,17 +272,17 @@ fi ...@@ -272,17 +272,17 @@ fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# PCRE support # PCRE support
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
echo "*****" echo "*****"
echo "***** Regexp support" echo "***** Regexp support"
echo "*****" echo "*****"
# Try to determine if libpcre is installed # Try to determine if libpcre is installed
if ${PKGCONFIG} --exists libpcre ;then if ${PKGCONFIG} --exists libpcre ;then
HAVE_PCRE="yes" HAVE_PCRE="yes"
PCREPKG="present" PCREPKG="present"
else else
AC_CHECK_LIB(pcre, pcre_fullinfo, HAVE_PCRE="yes", HAVE_PCRE="no", $LIBS) AC_CHECK_LIB(pcre, pcre_fullinfo, HAVE_PCRE="yes", HAVE_PCRE="no", $LIBS)
fi fi
...@@ -292,11 +292,12 @@ AC_ARG_WITH(provided-regexp, ...@@ -292,11 +292,12 @@ AC_ARG_WITH(provided-regexp,
PROV_PCRE="$withval", PROV_PCRE="no") PROV_PCRE="$withval", PROV_PCRE="no")
if test "$HAVE_PCRE" = "no" -o "$PROV_PCRE" = "yes" if test "$HAVE_PCRE" = "no" -o "$PROV_PCRE" = "yes"
then then
echo "... Configuring libpcre" echo "... Configuring libpcre"
PCRE_FLAGS="-Dregexec=PCRE_regexec -Dregcomp=PCRE_regcomp \ PCRE_FLAGS="-Dregexec=PCRE_regexec -Dregcomp=PCRE_regcomp \
-Dregerror=PCRE_regerror -Dregfree=PCRE_regfree" -Dregerror=PCRE_regerror -Dregfree=PCRE_regfree"
(cd pcre; CC=${CC} CFLAGS="${CFLAGS} $PCRE_FLAGS" ./configure \ (cd pcre; CC=${CC} CFLAGS="${CFLAGS} $PCRE_FLAGS" ./configure \
--enable-utf8 \
--prefix=$prefix --disable-shared --disable-cpp) || \ --prefix=$prefix --disable-shared --disable-cpp) || \
{ echo "Cannot configure PCRE"; exit; } { echo "Cannot configure PCRE"; exit; }
PCRE=pcre PCRE=pcre
...@@ -310,26 +311,26 @@ else ...@@ -310,26 +311,26 @@ else
if $PKGCONFIG --exists libpcre ;then if $PKGCONFIG --exists libpcre ;then
PCREINC="$($PKGCONFIG --cflags libpcre)" PCREINC="$($PKGCONFIG --cflags libpcre)"
PCRELIB="$($PKGCONFIG --libs libpcre) -lpcreposix" PCRELIB="$($PKGCONFIG --libs libpcre) -lpcreposix"
else else
PCREINC="" PCREINC=""
PCRELIB="-lpcre -lpcreposix" PCRELIB="-lpcre -lpcreposix"
fi fi
AC_DEFINE(HAVE_PCRE, 1 , [We use our version of pcre]) AC_DEFINE(HAVE_PCRE, 1 , [We use our version of pcre])
SYST_LIBS="libpcre $SYST_LIBS" SYST_LIBS="libpcre $SYST_LIBS"
fi fi
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# FFI support # FFI support
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
echo "*****" echo "*****"
echo "***** FFI support" echo "***** FFI support"
echo "*****" echo "*****"
# Try to determine if libffi is installed # Try to determine if libffi is installed
if ${PKGCONFIG} --exists libffi ;then if ${PKGCONFIG} --exists libffi ;then
HAVE_FFI="yes" HAVE_FFI="yes"
else else
AC_CHECK_LIB(ffi, ffi_prep_cif, HAVE_FFI="yes", HAVE_FFI="no", $LIBS) AC_CHECK_LIB(ffi, ffi_prep_cif, HAVE_FFI="yes", HAVE_FFI="no", $LIBS)
fi fi
...@@ -339,7 +340,7 @@ AC_ARG_WITH(provided-ffi, ...@@ -339,7 +340,7 @@ AC_ARG_WITH(provided-ffi,
PROV_FFI="$withval", PROV_FFI="no") PROV_FFI="$withval", PROV_FFI="no")
if test "$HAVE_FFI" = "no" -o "$PROV_FFI" = "yes" if test "$HAVE_FFI" = "no" -o "$PROV_FFI" = "yes"
then then
echo "... Configuring libffi" echo "... Configuring libffi"
(cd ffi; CC=${CC} CFLAGS=${CFLAGS} ./configure \ (cd ffi; CC=${CC} CFLAGS=${CFLAGS} ./configure \
--disable-structs --disable-raw-api --disable-shared \ --disable-structs --disable-raw-api --disable-shared \
...@@ -348,7 +349,7 @@ then ...@@ -348,7 +349,7 @@ then
FFIINC="-I../ffi/include" FFIINC="-I../ffi/include"
FFILIB="../ffi/.libs/libffi.a" FFILIB="../ffi/.libs/libffi.a"
COMP_LIBS="libffi $COMP_LIBS" COMP_LIBS="libffi $COMP_LIBS"
else else
echo "... Using system libffi library" echo "... Using system libffi library"
FFI="" FFI=""
if $PKGCONFIG --exists libffi ;then if $PKGCONFIG --exists libffi ;then
...@@ -361,7 +362,7 @@ else ...@@ -361,7 +362,7 @@ else
SYST_LIBS="libffi $SYST_LIBS" SYST_LIBS="libffi $SYST_LIBS"
fi fi
# We always want FFI. Should be modifiable in the future # We always want FFI. Should be modifiable in the future
AC_DEFINE(HAVE_FFI, 1, [System provides FFI]) AC_DEFINE(HAVE_FFI, 1, [System provides FFI])
### ###
### See in what direction the stack grows (code stolen from Sawfish) ### See in what direction the stack grows (code stolen from Sawfish)
...@@ -379,7 +380,7 @@ AC_TRY_RUN([ void inner (char *foo) { char bar; exit (!(foo >= &bar)); } ...@@ -379,7 +380,7 @@ AC_TRY_RUN([ void inner (char *foo) { char bar; exit (!(foo >= &bar)); }
LIB_SUMMARY="(:system ($SYST_LIBS) :compiled ($COMP_LIBS))" LIB_SUMMARY="(:system ($SYST_LIBS) :compiled ($COMP_LIBS))"
### Output files ### Output files
AC_SUBST(STKCFLAGS) AC_SUBST(STKCFLAGS)
AC_SUBST(VERSION) AC_SUBST(VERSION)
AC_SUBST(HAVE_DLOPEN) AC_SUBST(HAVE_DLOPEN)
...@@ -424,11 +425,11 @@ AC_SUBST(THREADS) ...@@ -424,11 +425,11 @@ AC_SUBST(THREADS)
AC_SUBST(LIB_SUMMARY) AC_SUBST(LIB_SUMMARY)
AC_CONFIG_FILES([Makefile src/Makefile src/extraconf.h doc/Makefile AC_CONFIG_FILES([Makefile src/Makefile src/extraconf.h doc/Makefile
lib/Makefile utils/Makefile utils/stklos-config lib/Makefile utils/Makefile utils/stklos-config
utils/stklos-script examples/Makefile utils/stklos-script examples/Makefile
lib/Match.d/Makefile lib/SILex.d/Makefile lib/Lalr.d/Makefile lib/Match.d/Makefile lib/SILex.d/Makefile lib/Lalr.d/Makefile
lib/ScmPkg.d/Makefile tests/Makefile lib/ScmPkg.d/Makefile tests/Makefile
doc/stklos.1 doc/stklos-config.1 doc/stklos-compile.1 doc/stklos.1 doc/stklos-config.1 doc/stklos-compile.1
doc/stklos-genlex.1 doc/stklos-pkg.1 doc/skb/stklos-version.stk doc/stklos-genlex.1 doc/stklos-pkg.1 doc/skb/stklos-version.stk
pkgman/Makefile]) pkgman/Makefile])
AC_OUTPUT AC_OUTPUT
...@@ -445,12 +446,12 @@ echo " OS type: " $OS_FLAVOUR ...@@ -445,12 +446,12 @@ echo " OS type: " $OS_FLAVOUR
echo " Install prefix : " $prefix echo " Install prefix : " $prefix
echo " C compiler: " $CC echo " C compiler: " $CC
echo " Compilation flags: " $CFLAGS echo " Compilation flags: " $CFLAGS
echo " Thread support: " $THREADS echo " Thread support: " $THREADS
echo "System libraries used: " $SYST_LIBS echo "System libraries used: " $SYST_LIBS
echo " Compiled libraries: " $COMP_LIBS echo " Compiled libraries: " $COMP_LIBS
echo " " echo " "
echo "If this is correct, you can just type 'make' now at your shell prompt." echo "If this is correct, you can just type 'make' now at your shell prompt."
echo "Otherwise, re-run 'configure' with correct options." echo "Otherwise, re-run 'configure' with correct options."
echo " " echo " "
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
* *
* Author: Erick Gallesio [eg@essi.fr] * Author: Erick Gallesio [eg@essi.fr]
* Creation date: 1-Jul-2003 11:38 (eg) * Creation date: 1-Jul-2003 11:38 (eg)
* Last file update: 27-May-2011 22:34 (eg) * Last file update: 19-Aug-2011 18:00 (eg)
*/ */
...@@ -250,7 +250,7 @@ DEFINE_PRIMITIVE("%parameter-dynenv-pop!", parameter_dynenv_pop, subr1, (SCM par ...@@ -250,7 +250,7 @@ DEFINE_PRIMITIVE("%parameter-dynenv-pop!", parameter_dynenv_pop, subr1, (SCM par
* *
\*===========================================================================*/ \*===========================================================================*/
struct extended_type_descr xtype_parameter = { "parameter", NULL }; static struct extended_type_descr xtype_parameter = { "parameter", NULL };
int STk_init_parameter(void) int STk_init_parameter(void)
{ {
......
/* /*
* promise.c -- Implementation of promises * promise.c -- Implementation of promises
* *
* Copyright © 2000-2005 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr> * Copyright © 2000-2011 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA. * USA.
* *
* Author: Erick Gallesio [eg@unice.fr] * Author: Erick Gallesio [eg@unice.fr]
* Author: Erick Gallesio [eg@kaolin.unice.fr] * Author: Erick Gallesio [eg@kaolin.unice.fr]
* Creation date: 2-Jun-1993 12:27 (eg) * Creation date: 2-Jun-1993 12:27 (eg)
* Last file update: 24-Apr-2005 21:55 (eg) * Last file update: 19-Aug-2011 18:01 (eg)
*/ */
#include <stklos.h> #include <stklos.h>
...@@ -57,19 +57,19 @@ DEFINE_PRIMITIVE("%make-promise", make_promise, subr1, (SCM expr)) ...@@ -57,19 +57,19 @@ DEFINE_PRIMITIVE("%make-promise", make_promise, subr1, (SCM expr))
* returned. The value of the promise is cached (or "memoized") so * returned. The value of the promise is cached (or "memoized") so
* that if it is forced a second time, the previously computed value * that if it is forced a second time, the previously computed value
* is returned. * is returned.
* *
* @lisp * @lisp
* (force (delay (+ 1 2))) => 3 * (force (delay (+ 1 2))) => 3
* (let ((p (delay (+ 1 2)))) * (let ((p (delay (+ 1 2))))
* (list (force p) (force p))) => (3 3) * (list (force p) (force p))) => (3 3)
* *
* (define a-stream * (define a-stream
* (letrec ((next (lambda (n) * (letrec ((next (lambda (n)
* (cons n (delay (next (+ n 1))))))) * (cons n (delay (next (+ n 1)))))))
* (next 0))) * (next 0)))
* (define head car) * (define head car)
* (define tail (lambda (stream) (force (cdr stream)))) * (define tail (lambda (stream) (force (cdr stream))))
* *
* (head (tail (tail a-stream))) => 2 * (head (tail (tail a-stream))) => 2
* @end lisp * @end lisp
* *
...@@ -91,8 +91,8 @@ DEFINE_PRIMITIVE("%make-promise", make_promise, subr1, (SCM expr)) ...@@ -91,8 +91,8 @@ DEFINE_PRIMITIVE("%make-promise", make_promise, subr1, (SCM expr))
* (begin (set! x 10) * (begin (set! x 10)
* (force p)) => 6 * (force p)) => 6
* @end lisp * @end lisp
* ,(bold "Note:") See R5RS for details on a posssible way to implement * ,(bold "Note:") See R5RS for details on a posssible way to implement
* |force| and |delay|. * |force| and |delay|.
doc> doc>
*/ */
DEFINE_PRIMITIVE("force", force, subr1, (SCM promise)) DEFINE_PRIMITIVE("force", force, subr1, (SCM promise))
...@@ -102,7 +102,7 @@ DEFINE_PRIMITIVE("force", force, subr1, (SCM promise)) ...@@ -102,7 +102,7 @@ DEFINE_PRIMITIVE("force", force, subr1, (SCM promise))
if (!PROMISEP(promise)) return promise; if (!PROMISEP(promise)) return promise;
if (RESULT_READYP(promise)) if (RESULT_READYP(promise))
/* promise was already evaluated. It's expr field contains the result */ /* promise was already evaluated. It's expr field contains the result */
return PROMISE_EXPR(promise); return PROMISE_EXPR(promise);
z = STk_C_apply(PROMISE_EXPR(promise), 0); z = STk_C_apply(PROMISE_EXPR(promise), 0);
...@@ -146,7 +146,7 @@ static void print_promise(SCM promise, SCM port, int mode) ...@@ -146,7 +146,7 @@ static void print_promise(SCM promise, SCM port, int mode)
} }
struct extended_type_descr xtype_promise = { static struct extended_type_descr xtype_promise = {
"promise", "promise",
print_promise print_promise
}; };
......
/* /*
* regexp.c -- STklos Regexps * regexp.c -- STklos Regexps
* *
* Copyright © 2000-2010 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr> * Copyright © 2000-2011 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
* *
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA. * USA.
* *
* Author: Erick Gallesio [eg@unice.fr] * Author: Erick Gallesio [eg@unice.fr]
* Creation date: 24-Nov-2000 10:35 (eg) * Creation date: 24-Nov-2000 10:35 (eg)
* Last file update: 4-Apr-2010 12:22 (eg) * Last file update: 21-Aug-2011 13:33 (eg)
*/ */
#include "stklos.h" #include "stklos.h"
/* /*
* All the complexity comes from MAC OS. I don't remember why I had to do * All the complexity comes from MAC OS. I don't remember why I had to do
* this, but I remember the culprit !!! * this, but I remember the culprit !!!
*/ */
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
# define PCRE_regcomp regcomp # define PCRE_regcomp regcomp
# define PCRE_regerror regerror # define PCRE_regerror regerror
# define PCRE_regfree regfree # define PCRE_regfree regfree
#else #else
# define regexec PCRE_regexec # define regexec PCRE_regexec
# define regcomp PCRE_regcomp # define regcomp PCRE_regcomp
# define regerror PCRE_regerror # define regerror PCRE_regerror
...@@ -46,29 +46,38 @@ ...@@ -46,29 +46,38 @@
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
#ifdef PCRE_PKG_CONFIG #ifdef PCRE_PKG_CONFIG
# include <pcreposix.h> # include <pcreposix.h>
#else #else
/* Here again Mac Os problems. /* Here again Mac Os problems.
* Here, we used to have a #include <pcreposix.h> * Here, we used to have a #include <pcreposix.h>
* However, on a fresh 10.6 install, there is a pcre lib which is * However, on a fresh 10.6 install, there is a pcre lib which is
* installed, but the "pcreposix.h" file isn't. * installed, but the "pcreposix.h" file isn't.
* *
* So what we do here is potentially FALSE. However, it is unlikely * So what we do here is potentially FALSE. However, it is unlikely
* that the code include in STklos is not compatible with the one * that the code include in STklos is not compatible with the one
* used to compile the installed library (this file seems to have * used to compile the installed library (this file seems to have
* been always "semantically" compatible). The only point wehr we * been always "semantically" compatible). The only point where we
* can have difference shoul be the definition of regmatch_t type * can have difference should be the definition of regmatch_t type
*/ */
# include "../pcre/pcreposix.h" # include "../pcre/pcreposix.h"
#endif #endif
#ifdef REG_UTF8
# define PCRE_COMP_FLAG REG_UTF8
#else
# define PCRE_COMP_FLAG 0
#endif
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
struct regexp_obj { struct regexp_obj {
stk_header header; stk_header header;
SCM src;
regex_t buffer; regex_t buffer;
}; };
#define REGEXPP(p) (BOXED_TYPE_EQ((p), tc_regexp)) #define REGEXPP(p) (BOXED_TYPE_EQ((p), tc_regexp))
#define REGEXP_SRC(p) (((struct regexp_obj *) (p))->src)
#define REGEXP_BUFFER(p) (((struct regexp_obj *) (p))->buffer) #define REGEXP_BUFFER(p) (((struct regexp_obj *) (p))->buffer)
#define REGEXP_DEPTH(p) ((((struct regexp_obj *) (p))->buffer).re_nsub) #define REGEXP_DEPTH(p) ((((struct regexp_obj *) (p))->buffer).re_nsub)
...@@ -99,7 +108,14 @@ static void regexp_finalizer(SCM re) ...@@ -99,7 +108,14 @@ static void regexp_finalizer(SCM re)
PCRE_regfree(&REGEXP_BUFFER(re)); PCRE_regfree(&REGEXP_BUFFER(re));
} }
static void print_regexp(SCM obj, SCM port, int mode)
{
STk_fprintf(port,
"#[regexp '%s' @ %lx]",
STRING_CHARS(REGEXP_SRC(obj)),
(unsigned long) obj);
}
/* /*
<doc EXT string->regexp <doc EXT string->regexp
* (string->regexp string) * (string->regexp string)
...@@ -110,8 +126,8 @@ static void regexp_finalizer(SCM re) ...@@ -110,8 +126,8 @@ static void regexp_finalizer(SCM re)
* the matching pattern. If a regular expression string is used * the matching pattern. If a regular expression string is used
* multiple times, it is faster to compile the string once to a regexp * multiple times, it is faster to compile the string once to a regexp
* value and use it for repeated matches instead of using the string * value and use it for repeated matches instead of using the string
* each time. * each time.
doc> doc>
*/ */
DEFINE_PRIMITIVE("string->regexp", str2regexp, subr1, (SCM re)) DEFINE_PRIMITIVE("string->regexp", str2regexp, subr1, (SCM re))
{ {
...@@ -119,10 +135,12 @@ DEFINE_PRIMITIVE("string->regexp", str2regexp, subr1, (SCM re)) ...@@ -119,10 +135,12 @@ DEFINE_PRIMITIVE("string->regexp", str2regexp, subr1, (SCM re))
int ret; int ret;
if (!STRINGP(re)) error_bad_string(re); if (!STRINGP(re)) error_bad_string(re);
NEWCELL_ATOMIC(z, regexp, sizeof(struct regexp_obj) ); NEWCELL(z, regexp);
ret = PCRE_regcomp(&REGEXP_BUFFER(z), STRING_CHARS(re), 0);
ret = PCRE_regcomp(&REGEXP_BUFFER(z),
STRING_CHARS(re),
STk_use_utf8? PCRE_COMP_FLAG: 0);
REGEXP_SRC(z) = re;
if (ret) signal_regexp_error(ret, &REGEXP_BUFFER(z)); if (ret) signal_regexp_error(ret, &REGEXP_BUFFER(z));
STk_register_finalizer(z, regexp_finalizer); STk_register_finalizer(z, regexp_finalizer);
...@@ -131,9 +149,9 @@ DEFINE_PRIMITIVE("string->regexp", str2regexp, subr1, (SCM re)) ...@@ -131,9 +149,9 @@ DEFINE_PRIMITIVE("string->regexp", str2regexp, subr1, (SCM re))
/* /*
<doc EXT regexp? <doc EXT regexp?
* (regexp? obj) * (regexp? obj)
* *
* |Regexp| returns |#t| if |obj| is a regexp value created by the |regexp|, * |Regexp| returns |#t| if |obj| is a regexp value created by the |regexp|,
* otherwise |regexp| returns |#f|. * otherwise |regexp| returns |#f|.
doc> doc>
*/ */
...@@ -148,17 +166,17 @@ DEFINE_PRIMITIVE("regexp?", regexpp, subr1, (SCM obj)) ...@@ -148,17 +166,17 @@ DEFINE_PRIMITIVE("regexp?", regexpp, subr1, (SCM obj))
* (regexp-match pattern str) * (regexp-match pattern str)
* (regexp-match-positions pattern str) * (regexp-match-positions pattern str)
* *
* These functions attempt to match |pattern| (a string or a regexp value) * These functions attempt to match |pattern| (a string or a regexp value)
* to |str|. If the match fails, |#f| is returned. If the match succeeds, * to |str|. If the match fails, |#f| is returned. If the match succeeds,
* a list (containing strings for |regexp-match| and positions for * a list (containing strings for |regexp-match| and positions for
* |regexp-match-positions| is returned. The first string (or positions) in * |regexp-match-positions| is returned. The first string (or positions) in
* this list is the portion of string that matched pattern. If two portions * this list is the portion of string that matched pattern. If two portions
* of string can match pattern, then the earliest and longest match is found, * of string can match pattern, then the earliest and longest match is found,
* by default. * by default.
* *
* Additional strings or positions are returned in the list if pattern contains * Additional strings or positions are returned in the list if pattern contains
* parenthesized sub-expressions; matches for the sub-expressions are provided * parenthesized sub-expressions; matches for the sub-expressions are provided
* in the order of the opening parentheses in pattern. * in the order of the opening parentheses in pattern.
* @lisp * @lisp
* (regexp-match-positions "ca" "abracadabra") * (regexp-match-positions "ca" "abracadabra")
* => ((4 6)) * => ((4 6))
...@@ -172,9 +190,9 @@ DEFINE_PRIMITIVE("regexp?", regexpp, subr1, (SCM obj)) ...@@ -172,9 +190,9 @@ DEFINE_PRIMITIVE("regexp?", regexpp, subr1, (SCM obj))
* => ((0 3) (0 1) (1 2) (2 3)) * => ((0 3) (0 1) (1 2) (2 3))
* (regexp-match-positions "(a*)(b*)(c*)" "c") * (regexp-match-positions "(a*)(b*)(c*)" "c")
* => ((0 1) (0 0) (0 0) (0 1)) * => ((0 1) (0 0) (0 0) (0 1))
* (regexp-match-positions "(?<=\\\\d{3})(?<!999)foo" * (regexp-match-positions "(?<=\\\\d{3})(?<!999)foo"
* "999foo and 123foo") * "999foo and 123foo")
* => ((14 17)) * => ((14 17))
* @end lisp * @end lisp
doc> doc>
*/ */
...@@ -186,6 +204,7 @@ static SCM regexec_helper(SCM re, SCM str, int pos_only) ...@@ -186,6 +204,7 @@ static SCM regexec_helper(SCM re, SCM str, int pos_only)
int i, ret, depth, max; int i, ret, depth, max;
SCM result; SCM result;
STk_debug("regexec helper ~S ~S", re, str);
/* RE can be a string or a already compiled regexp */ /* RE can be a string or a already compiled regexp */
if (STRINGP(re)) re = STk_str2regexp(re); if (STRINGP(re)) re = STk_str2regexp(re);
else if (!REGEXPP(re)) STk_error("bad compiled regexp ~S", re); else if (!REGEXPP(re)) STk_error("bad compiled regexp ~S", re);
...@@ -202,7 +221,7 @@ static SCM regexec_helper(SCM re, SCM str, int pos_only) ...@@ -202,7 +221,7 @@ static SCM regexec_helper(SCM re, SCM str, int pos_only)
result = STk_nil; result = STk_nil;