Merge branch 'master' of github.com:urbit/urbit

Conflicts:
	urb/zod/arvo/zuse.hoon
This commit is contained in:
C. Guy Yarvin 2014-04-09 16:52:25 -07:00
commit 60ce1c4cc6
38 changed files with 7883 additions and 6 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
/urb/urbit.pill binary

View File

@ -34,7 +34,7 @@ LIB=$(PWD)/lib
RM=rm -f
CC=gcc
CLD=gcc -O2 -g -L/usr/local/lib -L/opt/local/lib
CLD=g++ -O2 -g -L/usr/local/lib -L/opt/local/lib
YACC=bison -v -b$(GENERATED)/y
LEX=lex
@ -50,7 +50,7 @@ ifeq ($(OS),bsd)
OSLIBS=-lpthread -lncurses -lkvm
endif
LIBS=-lssl -lcrypto -lgmp -lncurses -lsigsegv $(OSLIBS)
LIBS=-lssl -lcrypto -lgmp -lncurses -lsigsegv $(OSLIBS) -lre2
INCLUDE=include
GENERATED=generated
@ -61,6 +61,7 @@ CFLAGS=-O2 -g \
-I/opt/local/include \
-I$(INCLUDE) \
-Ioutside/libuv/include \
-Ioutside/cre2/include \
-I $(GENERATED) \
$(DEFINES) \
$(MDEFINES)
@ -451,6 +452,8 @@ J164_5_OFILES=\
gen164/5/mat.o \
gen164/5/mink.o \
gen164/5/parse.o \
gen164/5/repg.o \
gen164/5/rexp.o \
gen164/5/rub.o \
gen164/5/shax.o \
gen164/5/lore.o \
@ -549,17 +552,21 @@ VERE_OFILES=\
$(OUT_OFILES)
LIBUV=outside/libuv/libuv.a
LIBCRE=outside/cre2/lib/libcre2.a
all: $(BIN)/vere
$(LIBUV):
$(MAKE) -C outside/libuv libuv.a
$(LIBCRE):
cd outside/cre2/src && sh build.sh
$(V_OFILES) f/loom.o f/trac.o: include/v/vere.h
$(BIN)/vere: $(VERE_OFILES) $(LIBUV) $(CAPN)
$(BIN)/vere: $(LIBCRE) $(VERE_OFILES) $(LIBUV) $(CAPN)
mkdir -p $(BIN)
$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(CAPN) $(LIBS)
$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(CAPN) $(LIBS)
tags:
ctags -R -f .tags --exclude=root
@ -570,4 +577,5 @@ etags:
clean:
$(RM) $(VERE_OFILES) $(BIN)/vere $(BIN)/eyre
$(MAKE) -C outside/libuv clean
cd outside/cre2/src && sh clean.sh

155
gen164/5/repg.c Normal file
View File

@ -0,0 +1,155 @@
/* j/5/repg.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"
#include "cre2.h"
#include <string.h>
u2_noun // produce
j2_mbc(Pt5, repg)(u2_wire wir_r,
u2_noun lub,
u2_noun rad,
u2_noun rep) // retain
{
c3_y* lub_y = u2_cr_tape(lub);
c3_y* rad_y = u2_cr_tape(rad);
c3_y* rep_y = u2_cr_tape(rep);
char* rec = (char*)lub_y;
char* end;
while(*rec != 0) {
if(*rec == '\\') {
rec++;
switch (*rec) {
case 'P':
case 'p':
free(lub_y);
free(rad_y);
return u2_nul;
case 'Q':
end = strstr(rec, "\\E");
if(end == NULL) rec += strlen(rec) - 1;
else rec = end;
}
rec++;
}
else if(*rec == '(') {
rec++;
if(*rec == '?') {
rec++;
if(*rec != ':') {
free(lub_y);
free(rad_y);
return u2_nul;
}
rec++;
}
}
else
rec++;
}
fprintf(stderr, "\r\nrepg: \r\n%s : %s\r\n", lub_y, rad_y);
cre2_regexp_t * rex;
cre2_options_t * opt;
opt = cre2_opt_new();
if (opt) {
cre2_opt_set_log_errors(opt, 0);
cre2_opt_set_encoding(opt, CRE2_Latin1);
cre2_opt_set_perl_classes(opt, 1);
cre2_opt_set_one_line(opt, 1);
cre2_opt_set_longest_match(opt, 1);
rex = cre2_new((const char *)lub_y, strlen((char *)lub_y), opt);
if (rex) {
if (!cre2_error_code(rex)) {
int text_len = strlen((char *)rad_y);
cre2_string_t matches[1];
int ic = 0;
u2_noun ret = u2_nul;
while (ic <= text_len) {
int match = cre2_match(rex, (const char*)rad_y, text_len, ic, text_len, CRE2_ANCHOR_START, matches, 1);
if (!match) {
if(rad_y[ic])
ret = u2_cn_cell((u2_atom)rad_y[ic], ret);
ic++;
}
else {
int mlen = matches[0].length;
if (mlen == 0) {
ret = u2_ckb_weld(u2_ckb_flop(u2_ci_tape((char *) rad_y+ic)), u2_ckb_flop(u2_ci_tape((char *)rep_y)));
ic = text_len + 1;
}
else {
ret = u2_ckb_weld(u2_ckb_flop(u2_ci_tape((char *)rep_y)), ret);
ic += mlen;
}
}
}
cre2_opt_delete(opt);
cre2_delete(rex);
free(lub_y);
free(rad_y);
free(rep_y);
return u2_cn_cell(u2_nul, u2_ckb_flop(ret));
}
else {
// Compiling the regular expression failed
cre2_opt_delete(opt);
cre2_delete(rex);
free(lub_y);
free(rad_y);
return u2_nul;
}
cre2_opt_delete(opt);
cre2_delete(rex);
}
else {
// rex Allocation Error
cre2_opt_delete(opt);
free(lub_y);
free(rad_y);
u2_bl_bail(wir_r, c3__exit);
}
cre2_opt_delete(opt);
}
// opt Allocation Error
free(lub_y);
free(rad_y);
u2_bl_bail(wir_r, c3__exit);
return u2_nul;
}
u2_weak // produce
j2_mb(Pt5, repg)(u2_wire wir_r,
u2_noun cor) // retain
{
u2_noun lub;
u2_noun rad;
u2_noun rep;
if ( (u2_none == (lub = u2_frag(u2_cv_sam_2, cor))) ||
(u2_none == (rad = u2_frag(u2_cv_sam_6, cor))) ||
(u2_none == (rep = u2_frag(u2_cv_sam_7, cor))) )
{
return u2_bl_bail(wir_r, c3__fail);
} else {
return j2_mbc(Pt5, repg)(wir_r, lub, rad, rep);
}
}
/* structures
*/
u2_ho_jet
j2_mbj(Pt5, repg)[] = {
{ ".2", c3__lite, j2_mb(Pt5, repg), u2_jet_live | u2_jet_test, u2_none, u2_none },
{ }
};

154
gen164/5/rexp.c Normal file
View File

@ -0,0 +1,154 @@
/* j/5/rexp.c
**
** This file is in the public domain.
*/
#include "all.h"
#include "../pit.h"
#include "cre2.h"
#include <string.h>
u2_noun // produce
j2_mbc(Pt5, rexp)(u2_wire wir_r,
u2_noun lub,
u2_noun rad) // retain
{
c3_y* lub_y = u2_cr_tape(lub);
c3_y* rad_y = u2_cr_tape(rad);
u2k(lub);
int lub_l = u2_ckb_lent(lub);
if (lub_l != strlen((char *)lub_y)) {
free(lub_y);
free(rad_y);
return u2_nul;
}
char* rec = (char*)lub_y;
char* end;
while(*rec != 0) {
if(*rec > 127) {
free(lub_y);
free(rad_y);
return u2_nul;
}
else if(*rec == '\\') {
rec++;
switch (*rec) {
case 'P':
case 'p':
free(lub_y);
free(rad_y);
return u2_nul;
case 'Q':
end = strstr(rec, "\\E");
if(end == NULL) rec += strlen(rec) - 1;
else rec = end;
}
}
else if(*rec == '(') {
rec++;
if(*rec == '?') {
rec++;
if(*rec != ':') {
free(lub_y);
free(rad_y);
return u2_nul;
}
rec++;
}
}
else
rec++;
}
fprintf(stderr, "\r\n%s : %s\r\n", lub_y, rad_y);
cre2_regexp_t * rex;
cre2_options_t * opt;
opt = cre2_opt_new();
if (opt) {
cre2_opt_set_log_errors(opt, 0);
cre2_opt_set_encoding(opt, CRE2_UTF8);
cre2_opt_set_perl_classes(opt, 1);
cre2_opt_set_one_line(opt, 1);
cre2_opt_set_longest_match(opt, 1);
rex = cre2_new((const char *)lub_y, strlen((char *)lub_y), opt);
if (rex) {
if (!cre2_error_code(rex)) {
int text_len = strlen((char *)rad_y);
int captures = cre2_num_capturing_groups(rex);
cre2_string_t matches[captures+1];
int match = cre2_match(rex, (const char*)rad_y, text_len, 0, text_len, CRE2_UNANCHORED, matches, captures+1);
if (!match) {
// No matches
cre2_opt_delete(opt);
cre2_delete(rex);
free(lub_y);
free(rad_y);
return u2_cn_cell(u2_nul, u2_nul);
}
u2_noun map = u2_nul;
int i;
for (i = 0; i < captures+1; i++) {
char * buf = malloc(matches[i].length + 1);
memcpy(buf, matches[i].data, matches[i].length);
buf[matches[i].length] = 0;
fprintf(stderr, "%d: %s\r\n", i, buf);
map = u2_ckd_by_put(map, i, u2_ci_tape(buf));
free(buf);
}
cre2_opt_delete(opt);
cre2_delete(rex);
free(lub_y);
free(rad_y);
return u2_cn_cell(u2_nul, u2_cn_cell(u2_nul, map));
}
else {
// Compiling the regular expression failed
cre2_opt_delete(opt);
cre2_delete(rex);
free(lub_y);
free(rad_y);
return u2_nul;
}
cre2_delete(rex);
}
cre2_opt_delete(opt);
}
free(lub_y);
free(rad_y);
u2_bl_bail(wir_r, c3__exit);
return u2_nul;
}
u2_weak // produce
j2_mb(Pt5, rexp)(u2_wire wir_r,
u2_noun cor) // retain
{
u2_noun lub;
u2_noun rad;
if ( (u2_none == (lub = u2_frag(u2_cv_sam_2, cor))) ||
(u2_none == (rad = u2_frag(u2_cv_sam_3, cor))) )
{
return u2_bl_bail(wir_r, c3__fail);
} else {
return j2_mbc(Pt5, rexp)(wir_r, lub, rad);
}
}
/* structures
*/
u2_ho_jet
j2_mbj(Pt5, rexp)[] = {
{ ".2", c3__lite, j2_mb(Pt5, rexp), u2_jet_live | u2_jet_test, u2_none, u2_none },
{ }
};

View File

@ -87,6 +87,8 @@
extern u2_ho_jet j2_mbj(Pt5, pfix)[];
extern u2_ho_jet j2_mbj(Pt5, plug)[];
extern u2_ho_jet j2_mbj(Pt5, pose)[];
extern u2_ho_jet j2_mbj(Pt5, repg)[];
extern u2_ho_jet j2_mbj(Pt5, rexp)[];
extern u2_ho_jet j2_mbj(Pt5, rub)[];
extern u2_ho_jet j2_mbj(Pt5, sfix)[];
extern u2_ho_jet j2_mbj(Pt5, shax)[];
@ -229,6 +231,8 @@
{ j2_sb(Pt5, pfix), j2_mbj(Pt5, pfix), 0, 0, u2_none },
{ j2_sb(Pt5, plug), j2_mbj(Pt5, plug), 0, 0, u2_none },
{ j2_sb(Pt5, pose), j2_mbj(Pt5, pose), 0, 0, u2_none },
{ j2_sb(Pt5, repg), j2_mbj(Pt5, repg), 0, 0, u2_none },
{ j2_sb(Pt5, rexp), j2_mbj(Pt5, rexp), 0, 0, u2_none },
{ j2_sb(Pt5, rub), j2_mbj(Pt5, rub), 0, 0, u2_none },
{ j2_sb(Pt5, sfix), j2_mbj(Pt5, sfix), 0, 0, u2_none },
{ j2_sb(Pt5, shax), j2_mbj(Pt5, shax), 0, 0, u2_none },

View File

@ -0,0 +1,35 @@
Copyright (c) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2011 Keegan McAllister
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
3. Neither the name of the author nor the names of his
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,27 @@
// Copyright (c) 2009 The RE2 Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,175 @@
C wrapper for re2
=================
Topics
------
1. Introduction
2. License
3. Install
4. Usage
A. Credits
B. Bugs
C. Resources
1. Introduction
---------------
The CRE2 distribution is a C language wrapper for the RE2
library, which is implemented in C++. RE2 is a fast, safe,
thread-friendly alternative to backtracking regular
expression engines like those used in PCRE, Perl, and
Python.
This distribution makes use of the GNU Autotools.
2. License
----------
Copyright (c) 2012, 2013 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2011 Keegan McAllister
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
3. Neither the name of the author nor the names of his
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3. Install
----------
To install RE2 follow the instructions in the README file in
RE2's. To install CRE2 from a proper release tarball, do
this:
$ cd cre2-0.1.0
$ mkdir "=build"
$ cd "=build"
to inspect the available configuration options:
$ ../configure --help
then do it:
$ ../configure [options]
$ make
$ make check
$ make install
From a repository checkout or snapshot (the ones from the
Github site): we may need to manually run "libtoolize" the
first time, then we must first run the script "autogen.sh"
from the top source directory, to generate the needed files:
$ sh autogen.sh
for this we need to have installed the GNU Autotools:
Automake, Autoconf, Libtool. After this:
$ ../configure --enable-maintainer-mode [options]
$ make
$ make check
$ make install
The Makefile supports the DESTDIR environment variable to
install files in a temporary location, example: to see what
will happen:
$ make -n install DESTDIR=/tmp/marco/cre2
to really do it:
$ make install DESTDIR=/tmp/marco/cre2
4. Usage
--------
Read the documentation.
A. Credits
----------
RE2 is a Google project. CRE2 is based on code by Keegan
McAllister. This distribution was assembled by Marco Maggi.
B. Bugs
-------
Bug reports are appreciated. Register issues at the CRE2
issue tracker:
<http://github.com/marcomaggi/cre2/issues>
C. Resources
------------
The GNU Project software can be found here:
<http://www.gnu.org/>
RE2 is available at:
<http://code.google.com/p/re2/>
development of this package happens at:
<http://github.com/marcomaggi/cre2/>
and as backup at:
<http://sourceforge.net/projects/cre2/>
proper release tarballs for this package are in the download
area at:
<http://sourceforge.net/projects/cre2/files/>
the documentation is available online:
<http://marcomaggi.github.com/docs/cre2.html>
### end of file
# Local Variables:
# mode: text
# coding: utf-8-unix
# fill-column: 60
# paragraph-start: "*"
# End:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,18 @@
This is the file .../info/dir, which contains the
topmost node of the Info hierarchy, called (dir)Top.
The first time you invoke Info you start off looking at this node.

File: dir, Node: Top This is the top of the INFO tree
This (the Directory node) gives a menu of major topics.
Typing "q" exits, "?" lists all Info commands, "d" returns here,
"h" gives a primer for first-timers,
"mEmacs<Return>" visits the Emacs manual, etc.
In Emacs, you can click mouse button 2 on a menu item or cross reference
to select it.
* Menu:
Development
* cre2: (cre2). C wrapper for RE2.

44
outside/cre2/src/.gitignore vendored Normal file
View File

@ -0,0 +1,44 @@
*~
=*
,,*
*.a
*.bz2
*.fasl
*.gz
*.html
*.info
*.o
*.out
*.so
*.so.*
*.tgz
*.tmp
.DS_Store
.arch
.deps/
.emacs.*
.gdb_history
.vimview
Makefile
Makefile.in
aclocal.m4
ar-lib
autom4te*
compile
config.guess
config.h.in
config.sub
config.cache
configure
depcomp
test-driver
doc/mdate-sh
doc/stamp-vti
doc/texinfo.tex
doc/version.texi
install-sh
missing
mkinstalldirs
ltmain.sh
m4/
autotools/

35
outside/cre2/src/COPYING Normal file
View File

@ -0,0 +1,35 @@
Copyright (c) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2011 Keegan McAllister
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
3. Neither the name of the author nor the names of his
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

365
outside/cre2/src/INSTALL Normal file
View File

@ -0,0 +1,365 @@
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without warranty of any kind.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package. Some packages provide this
`INSTALL' file but do not implement all of the features documented
below. The lack of an optional feature in a given package is not
necessarily a bug. More recommendations for GNU packages can be found
in *note Makefile Conventions: (standards)Makefile Conventions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package, generally using the just-built uninstalled binaries.
4. Type `make install' to install the programs and any data files and
documentation. When installing into a prefix owned by root, it is
recommended that the package be configured and built as a regular
user, and only the `make install' phase executed with root
privileges.
5. Optionally, type `make installcheck' to repeat any self-tests, but
this time using the binaries in their final installed location.
This target does not install anything. Running this target as a
regular user, particularly if the prior `make install' required
root privileges, verifies that the installation completed
correctly.
6. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
7. Often, you can also type `make uninstall' to remove the installed
files again. In practice, not all packages have tested that
uninstallation works correctly, even though it is required by the
GNU Coding Standards.
8. Some packages, particularly those that use Automake, provide `make
distcheck', which can by used by developers to test that all other
targets like `make install' and `make uninstall' work correctly.
This target is generally not run by end users.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'. This
is known as a "VPATH" build.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
On MacOS X 10.5 and later systems, you can create libraries and
executables that work on multiple system types--known as "fat" or
"universal" binaries--by specifying multiple `-arch' options to the
compiler but only a single `-arch' option to the preprocessor. Like
this:
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
CPP="gcc -E" CXXCPP="g++ -E"
This is not guaranteed to produce working output in all cases, you
may have to build one architecture at a time and combine the results
using the `lipo' tool if you have problems.
Installation Names
==================
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX', where PREFIX must be an
absolute file name.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them. In general, the
default for these options is expressed in terms of `${prefix}', so that
specifying just `--prefix' will affect all of the other directory
specifications that were not explicitly provided.
The most portable way to affect installation locations is to pass the
correct locations to `configure'; however, many packages provide one or
both of the following shortcuts of passing variable assignments to the
`make install' command line to change installation locations without
having to reconfigure or recompile.
The first method involves providing an override variable for each
affected directory. For example, `make install
prefix=/alternate/directory' will choose an alternate location for all
directory configuration variables that were expressed in terms of
`${prefix}'. Any directories that were specified during `configure',
but not in terms of `${prefix}', must each be overridden at install
time for the entire installation to be relocated. The approach of
makefile variable overrides for each directory variable is required by
the GNU Coding Standards, and ideally causes no recompilation.
However, some platforms have known limitations with the semantics of
shared libraries that end up requiring recompilation when using this
method, particularly noticeable in packages that use GNU Libtool.
The second method involves providing the `DESTDIR' variable. For
example, `make install DESTDIR=/alternate/directory' will prepend
`/alternate/directory' before all installation names. The approach of
`DESTDIR' overrides is not required by the GNU Coding Standards, and
does not work on platforms that have drive letters. On the other hand,
it does better at avoiding recompilation issues, and works well even
when some directory options were not specified in terms of `${prefix}'
at `configure' time.
Optional Features
=================
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Some packages offer the ability to configure how verbose the
execution of `make' will be. For these packages, running `./configure
--enable-silent-rules' sets the default to minimal output, which can be
overridden with `make V=1'; while running `./configure
--disable-silent-rules' sets the default to verbose, which can be
overridden with `make V=0'.
Particular systems
==================
On HP-UX, the default C compiler is not ANSI C compatible. If GNU
CC is not installed, it is recommended to use the following options in
order to use an ANSI C compiler:
./configure CC="cc -Ae -D_XOPEN_SOURCE=500"
and if that doesn't work, install pre-built binaries of GCC for HP-UX.
On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
parse its `<wchar.h>' header file. The option `-nodtk' can be used as
a workaround. If GNU CC is not installed, it is therefore recommended
to try
./configure CC="cc"
and if that doesn't work, try
./configure CC="cc -nodtk"
On Solaris, don't put `/usr/ucb' early in your `PATH'. This
directory contains several dysfunctional programs; working variants of
these programs are available in `/usr/bin'. So, if you need `/usr/ucb'
in your `PATH', put it _after_ `/usr/bin'.
On Haiku, software installed for all users goes in `/boot/common',
not `/usr/local'. It is recommended to use the following options:
./configure --prefix=/boot/common
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS
KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the
"host" platform (i.e., that on which the generated programs will
eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of all of the options to `configure', and exit.
`--help=short'
`--help=recursive'
Print a summary of the options unique to this package's
`configure', and exit. The `short' variant lists options used
only in the top level, while the `recursive' variant lists options
also present in any nested packages.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`--prefix=DIR'
Use DIR as the installation prefix. *note Installation Names::
for more details, including other options available for fine-tuning
the installation locations.
`--no-create'
`-n'
Run the configure checks, but stop before creating any output
files.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.

View File

@ -0,0 +1,27 @@
// Copyright (c) 2009 The RE2 Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,48 @@
## Process this file with automake to produce Makefile.in
ACLOCAL_AMFLAGS = -I autotools
EXTRA_DIST = INSTALL configure.sh prepare.sh
dist_doc_DATA = README COPYING LICENSE.re2
## --------------------------------------------------------------------
cre2_CURRENT = @cre2_VERSION_INTERFACE_CURRENT@
cre2_REVISION = @cre2_VERSION_INTERFACE_REVISION@
cre2_AGE = @cre2_VERSION_INTERFACE_AGE@
include_HEADERS = src/cre2.h
lib_LTLIBRARIES = libcre2.la
libcre2_la_LDFLAGS = -version-info $(cre2_CURRENT):$(cre2_REVISION):$(cre2_AGE)
libcre2_la_SOURCES = src/cre2.cpp
## --------------------------------------------------------------------
AM_MAKEINFOFLAGS = --no-split
info_TEXINFOS = doc/cre2.texi
doc_cre2_TEXINFOS = doc/fdl-1.3.texi
## --------------------------------------------------------------------
check_PROGRAMS = \
tests/test-version \
tests/test-options \
tests/test-rex-alloc \
tests/test-matching \
tests/test-easy-matching \
tests/test-full-match \
tests/test-partial-match \
tests/test-consume-match \
tests/test-find-and-consume-match \
tests/test-replace \
tests/test-misc
AM_CPPFLAGS = -I$(top_srcdir)/src
LDADD = libcre2.la
TESTS = $(check_PROGRAMS)
installcheck-local: $(check_PROGRAMS)
for f in $(check_PROGRAMS); do $$f; done
### end of file

175
outside/cre2/src/README Normal file
View File

@ -0,0 +1,175 @@
C wrapper for re2
=================
Topics
------
1. Introduction
2. License
3. Install
4. Usage
A. Credits
B. Bugs
C. Resources
1. Introduction
---------------
The CRE2 distribution is a C language wrapper for the RE2
library, which is implemented in C++. RE2 is a fast, safe,
thread-friendly alternative to backtracking regular
expression engines like those used in PCRE, Perl, and
Python.
This distribution makes use of the GNU Autotools.
2. License
----------
Copyright (c) 2012, 2013 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2011 Keegan McAllister
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
3. Neither the name of the author nor the names of his
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3. Install
----------
To install RE2 follow the instructions in the README file in
RE2's. To install CRE2 from a proper release tarball, do
this:
$ cd cre2-0.1.0
$ mkdir "=build"
$ cd "=build"
to inspect the available configuration options:
$ ../configure --help
then do it:
$ ../configure [options]
$ make
$ make check
$ make install
From a repository checkout or snapshot (the ones from the
Github site): we may need to manually run "libtoolize" the
first time, then we must first run the script "autogen.sh"
from the top source directory, to generate the needed files:
$ sh autogen.sh
for this we need to have installed the GNU Autotools:
Automake, Autoconf, Libtool. After this:
$ ../configure --enable-maintainer-mode [options]
$ make
$ make check
$ make install
The Makefile supports the DESTDIR environment variable to
install files in a temporary location, example: to see what
will happen:
$ make -n install DESTDIR=/tmp/marco/cre2
to really do it:
$ make install DESTDIR=/tmp/marco/cre2
4. Usage
--------
Read the documentation.
A. Credits
----------
RE2 is a Google project. CRE2 is based on code by Keegan
McAllister. This distribution was assembled by Marco Maggi.
B. Bugs
-------
Bug reports are appreciated. Register issues at the CRE2
issue tracker:
<http://github.com/marcomaggi/cre2/issues>
C. Resources
------------
The GNU Project software can be found here:
<http://www.gnu.org/>
RE2 is available at:
<http://code.google.com/p/re2/>
development of this package happens at:
<http://github.com/marcomaggi/cre2/>
and as backup at:
<http://sourceforge.net/projects/cre2/>
proper release tarballs for this package are in the download
area at:
<http://sourceforge.net/projects/cre2/files/>
the documentation is available online:
<http://marcomaggi.github.com/docs/cre2.html>
### end of file
# Local Variables:
# mode: text
# coding: utf-8-unix
# fill-column: 60
# paragraph-start: "*"
# End:

View File

@ -0,0 +1,11 @@
# autogen.sh --
#
# Run this in the top source directory to rebuild the infrastructure.
set -xe
test -d autotools || mkdir autotools
test -f autotools/libtool.m4 || libtoolize
autoreconf --warnings=all --install --verbose "$@"
### end of file

17
outside/cre2/src/build.sh Normal file
View File

@ -0,0 +1,17 @@
if [ ! -d "=build" ]; then
mkdir "=build"
(libtoolize || glibtoolize)
sh autogen.sh
cd "=build"
../configure --enable-maintainer-mode LDFLAGS=-pthread
make
cd ..
fi
if [ ! -d "../lib" ]; then
mkdir ../lib
fi
if [ ! -d "../include" ]; then
mkdir ../include
fi
cp \=build/.libs/* ../lib
cp src/cre2.h ../include

View File

@ -0,0 +1,9 @@
if [ -d "=build" ]; then
rm -r "=build"
fi
if [ -d "../lib" ]; then
rm -r ../lib
fi
if [ -d "../include" ]; then
rm -r ../include
fi

View File

@ -0,0 +1,58 @@
dnl @configure_input@
dnl
AC_PREREQ([2.68])
AC_INIT([CRE2],[0.1b5],[marco.maggi-ipsu@poste.it],
[cre2],[http://github.com/marcomaggi/cre2/])
AC_CONFIG_SRCDIR([src/])
AC_CONFIG_MACRO_DIR([autotools])
AC_CONFIG_AUX_DIR([autotools])
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([1.14 foreign subdir-objects dist-xz no-dist-gzip -Wall])
AM_MAINTAINER_MODE
AM_PROG_AR
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_MKDIR_P
LT_PREREQ([2.4])
LT_INIT
AC_PROG_CC
AC_PROG_CC_C_O
AC_LANG([C++])
AC_PROG_CXX
AC_PROG_CXX_C_O
AC_CHECK_LIB([re2],[main],,[AC_MSG_FAILURE([test for RE2 library failed])])
AC_CHECK_HEADERS([re2/re2.h],,[AC_MSG_ERROR([test for RE2 header failed])])
cre2_VERSION_INTERFACE_CURRENT=0
cre2_VERSION_INTERFACE_REVISION=0
cre2_VERSION_INTERFACE_AGE=0
AC_DEFINE_UNQUOTED([cre2_VERSION_INTERFACE_CURRENT],
[$cre2_VERSION_INTERFACE_CURRENT],
[current interface number])
AC_DEFINE_UNQUOTED([cre2_VERSION_INTERFACE_REVISION],
[$cre2_VERSION_INTERFACE_REVISION],
[current interface implementation number])
AC_DEFINE_UNQUOTED([cre2_VERSION_INTERFACE_AGE],
[$cre2_VERSION_INTERFACE_AGE],
[current interface age number])
AC_DEFINE_UNQUOTED([cre2_VERSION_INTERFACE_STRING],
["$cre2_VERSION_INTERFACE_CURRENT.$cre2_VERSION_INTERFACE_REVISION"],
[library interface version])
AC_SUBST([cre2_VERSION_INTERFACE_CURRENT])
AC_SUBST([cre2_VERSION_INTERFACE_REVISION])
AC_SUBST([cre2_VERSION_INTERFACE_AGE])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
dnl end of file

View File

@ -0,0 +1,24 @@
# configure.sh --
#
# Run this to configure.
set -xe
prefix=/usr/local
if test -d /lib64
then libdir=${prefix}/lib64
else libdir=${prefix}/lib
fi
../configure \
--config-cache \
--cache-file=../config.cache \
--enable-maintainer-mode \
--disable-static --enable-shared \
--prefix="${prefix}" \
--libdir="${libdir}" \
CFLAGS='-O3' \
LDFLAGS="-L${libdir}" \
"$@"
### end of file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,509 @@
@node Documentation License
@appendix GNU Free Documentation License
@cindex FDL, GNU Free Documentation License
@center Version 1.3, 3 November 2008
@c This file is intended to be included within another document,
@c hence no sectioning command or @node.
@display
Copyright @copyright{} 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
@uref{http://fsf.org/}
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display
@enumerate 0
@item
PREAMBLE
The purpose of this License is to make a manual, textbook, or other
functional and useful document @dfn{free} in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of ``copyleft'', which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
@item
APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The ``Document'', below,
refers to any such manual or work. Any member of the public is a
licensee, and is addressed as ``you''. You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.
A ``Modified Version'' of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A ``Secondary Section'' is a named appendix or a front-matter section
of the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall
subject (or to related matters) and contains nothing that could fall
directly within that overall subject. (Thus, if the Document is in
part a textbook of mathematics, a Secondary Section may not explain
any mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.
The ``Invariant Sections'' are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant. The Document may contain zero
Invariant Sections. If the Document does not identify any Invariant
Sections then there are none.
The ``Cover Texts'' are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License. A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.
A ``Transparent'' copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters. A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text. A copy that is not ``Transparent'' is called ``Opaque''.
Examples of suitable formats for Transparent copies include plain
@sc{ascii} without markup, Texinfo input format, La@TeX{} input
format, @acronym{SGML} or @acronym{XML} using a publicly available
@acronym{DTD}, and standard-conforming simple @acronym{HTML},
PostScript or @acronym{PDF} designed for human modification. Examples
of transparent image formats include @acronym{PNG}, @acronym{XCF} and
@acronym{JPG}. Opaque formats include proprietary formats that can be
read and edited only by proprietary word processors, @acronym{SGML} or
@acronym{XML} for which the @acronym{DTD} and/or processing tools are
not generally available, and the machine-generated @acronym{HTML},
PostScript or @acronym{PDF} produced by some word processors for
output purposes only.
The ``Title Page'' means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page. For works in
formats which do not have any title page as such, ``Title Page'' means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.
The ``publisher'' means any person or entity that distributes copies
of the Document to the public.
A section ``Entitled XYZ'' means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language. (Here XYZ stands for a
specific section name mentioned below, such as ``Acknowledgements'',
``Dedications'', ``Endorsements'', or ``History''.) To ``Preserve the Title''
of such a section when you modify the Document means that it remains a
section ``Entitled XYZ'' according to this definition.
The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document. These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.
@item
VERBATIM COPYING
You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough
number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and
you may publicly display copies.
@item
COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify
you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and
visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.
If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.
@item
MODIFICATIONS
You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it. In addition, you must do these things in the Modified Version:
@enumerate A
@item
Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document). You may use the same title as a previous version
if the original publisher of that version gives permission.
@item
List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.
@item
State on the Title page the name of the publisher of the
Modified Version, as the publisher.
@item
Preserve all the copyright notices of the Document.
@item
Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.
@item
Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.
@item
Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.
@item
Include an unaltered copy of this License.
@item
Preserve the section Entitled ``History'', Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page. If
there is no section Entitled ``History'' in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.
@item
Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on. These may be placed in the ``History'' section.
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.
@item
For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve
the Title of the section, and preserve in the section all the
substance and tone of each of the contributor acknowledgements and/or
dedications given therein.
@item
Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles. Section numbers
or the equivalent are not considered part of the section titles.
@item
Delete any section Entitled ``Endorsements''. Such a section
may not be included in the Modified Version.
@item
Do not retitle any existing section to be Entitled ``Endorsements'' or
to conflict in title with any Invariant Section.
@item
Preserve any Warranty Disclaimers.
@end enumerate
If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant. To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.
You may add a section Entitled ``Endorsements'', provided it contains
nothing but endorsements of your Modified Version by various
parties---for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.
You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version. Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
@item
COMBINING DOCUMENTS
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled ``History''
in the various original documents, forming one section Entitled
``History''; likewise combine any sections Entitled ``Acknowledgements'',
and any sections Entitled ``Dedications''. You must delete all
sections Entitled ``Endorsements.''
@item
COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.
@item
AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an ``aggregate'' if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.
@item
TRANSLATION
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled ``Acknowledgements'',
``Dedications'', or ``History'', the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.
@item
TERMINATION
You may not copy, modify, sublicense, or distribute the Document
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense, or distribute it is void, and
will automatically terminate your rights under this License.
However, if you cease all violation of this License, then your license
from a particular copyright holder is reinstated (a) provisionally,
unless and until the copyright holder explicitly and finally
terminates your license, and (b) permanently, if the copyright holder
fails to notify you of the violation by some reasonable means prior to
60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, receipt of a copy of some or all of the same material does
not give you any rights to use it.
@item
FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
@uref{http://www.gnu.org/copyleft/}.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License ``or any later version'' applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation. If the Document
specifies that a proxy can decide which future versions of this
License can be used, that proxy's public statement of acceptance of a
version permanently authorizes you to choose that version for the
Document.
@item
RELICENSING
``Massive Multiauthor Collaboration Site'' (or ``MMC Site'') means any
World Wide Web server that publishes copyrightable works and also
provides prominent facilities for anybody to edit those works. A
public wiki that anybody can edit is an example of such a server. A
``Massive Multiauthor Collaboration'' (or ``MMC'') contained in the
site means any set of copyrightable works thus published on the MMC
site.
``CC-BY-SA'' means the Creative Commons Attribution-Share Alike 3.0
license published by Creative Commons Corporation, a not-for-profit
corporation with a principal place of business in San Francisco,
California, as well as future copyleft versions of that license
published by that same organization.
``Incorporate'' means to publish or republish a Document, in whole or
in part, as part of another Document.
An MMC is ``eligible for relicensing'' if it is licensed under this
License, and if all works that were first published under this License
somewhere other than this MMC, and subsequently incorporated in whole
or in part into the MMC, (1) had no cover texts or invariant sections,
and (2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site
under CC-BY-SA on the same site at any time before August 1, 2009,
provided the MMC is eligible for relicensing.
@end enumerate
@page
@heading ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:
@smallexample
@group
Copyright (C) @var{year} @var{your name}.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
Free Documentation License''.
@end group
@end smallexample
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the ``with@dots{}Texts.'' line with this:
@smallexample
@group
with the Invariant Sections being @var{list their titles}, with
the Front-Cover Texts being @var{list}, and with the Back-Cover Texts
being @var{list}.
@end group
@end smallexample
If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.
If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.
@c Local Variables:
@c ispell-local-pdict: "ispell-dict"
@c End:

View File

@ -0,0 +1,10 @@
# prepare.sh --
#
# Run this to rebuild the infrastructure and configure.
set -xe
(cd .. && sh autogen.sh)
sh ../configure.sh
### end of file

View File

@ -0,0 +1,631 @@
/*
Source file for CRE2, a C language wrapper for RE2: a regular
expressions library by Google.
Copyright (c) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2011 Keegan McAllister
All rights reserved.
For the license notice see the COPYING file.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <re2/re2.h>
#include "cre2.h"
#include <cstdlib>
#include <cstdio>
/** --------------------------------------------------------------------
** Version functions.
** ----------------------------------------------------------------- */
const char *
cre2_version_string (void)
{
return cre2_VERSION_INTERFACE_STRING;
}
int
cre2_version_interface_current (void)
{
return cre2_VERSION_INTERFACE_CURRENT;
}
int
cre2_version_interface_revision (void)
{
return cre2_VERSION_INTERFACE_REVISION;
}
int
cre2_version_interface_age (void)
{
return cre2_VERSION_INTERFACE_AGE;
}
/** --------------------------------------------------------------------
** Options objects.
** ----------------------------------------------------------------- */
/* Cast the pointer argument "opt" to a pointer of type
"RE2::Options*". */
#define TO_OPT(opt) (reinterpret_cast<RE2::Options *>(opt))
cre2_options_t *
cre2_opt_new(void)
/* Allocate and return a new options object. */
{
// FIXME: is this use of "nothrow" good to avoid raising exceptions
// when memory allocation fails and to return NULL instead?
return reinterpret_cast<void*>(new (std::nothrow) RE2::Options());
}
void
cre2_opt_delete (cre2_options_t *opt)
/* Finalise an options object. */
{
delete TO_OPT(opt);
}
/* Set or unset option flags in an options object. */
#define OPT_BOOL(name) \
void cre2_opt_set_##name (cre2_options_t *opt, int flag) \
{ \
TO_OPT(opt)->set_##name(bool(flag)); \
} \
int cre2_opt_##name (cre2_options_t *opt) \
{ \
return TO_OPT(opt)->name(); \
}
OPT_BOOL(posix_syntax)
OPT_BOOL(longest_match)
OPT_BOOL(log_errors)
OPT_BOOL(literal)
OPT_BOOL(never_nl)
OPT_BOOL(case_sensitive)
OPT_BOOL(perl_classes)
OPT_BOOL(word_boundary)
OPT_BOOL(one_line)
#undef OPT_BOOL
void
cre2_opt_set_encoding (cre2_options_t *opt, cre2_encoding_t enc)
/* Select the encoding in an options object. */
{
switch (enc) {
case CRE2_UTF8:
TO_OPT(opt)->set_encoding(RE2::Options::EncodingUTF8);
break;
case CRE2_Latin1:
TO_OPT(opt)->set_encoding(RE2::Options::EncodingLatin1);
break;
default:
fprintf(stderr, "CRE2: internal error: unknown encoding %d\n", enc);
exit(EXIT_FAILURE);
}
}
cre2_encoding_t
cre2_opt_encoding (cre2_options_t *opt)
{
RE2::Options::Encoding E = TO_OPT(opt)->encoding();
switch (E) {
case RE2::Options::EncodingUTF8:
return CRE2_UTF8;
case RE2::Options::EncodingLatin1:
return CRE2_Latin1;
default:
return CRE2_UNKNOWN;
}
}
void
cre2_opt_set_max_mem (cre2_options_t *opt, int m)
/* Configure the maximum amount of memory in an options object. */
{
TO_OPT(opt)->set_max_mem(m);
}
int
cre2_opt_max_mem (cre2_options_t *opt)
{
return TO_OPT(opt)->max_mem();
}
/** --------------------------------------------------------------------
** Precompiled regular expressions objects.
** ----------------------------------------------------------------- */
#define TO_RE2(re) (reinterpret_cast<RE2 *>(re))
#define TO_CONST_RE2(re) (reinterpret_cast<const RE2 *>(re))
cre2_regexp_t *
cre2_new (const char *pattern, int pattern_len, const cre2_options_t *opt)
{
re2::StringPiece pattern_re2(pattern, pattern_len);
if (opt) {
// FIXME: is this use of "nothrow" enough to avoid raising
// exceptions when memory allocation fails and to return NULL
// instead?
return reinterpret_cast<void*>
(new (std::nothrow) RE2(pattern_re2, *reinterpret_cast<const RE2::Options *>(opt)));
} else {
return reinterpret_cast<void*> (new (std::nothrow) RE2(pattern_re2));
}
}
void
cre2_delete (cre2_regexp_t *re)
{
delete TO_RE2(re);
}
const char *
cre2_pattern (const cre2_regexp_t *re)
{
return TO_CONST_RE2(re)->pattern().c_str();
}
int
cre2_error_code (const cre2_regexp_t *re)
{
return int(TO_CONST_RE2(re)->error_code());
}
const char *
cre2_error_string (const cre2_regexp_t *re)
{
return TO_CONST_RE2(re)->error().c_str();
}
void
cre2_error_arg (const cre2_regexp_t *re, cre2_string_t *arg)
{
const std::string &argstr = TO_CONST_RE2(re)->error_arg();
arg->data = argstr.data();
arg->length = argstr.length();
}
int
cre2_num_capturing_groups (const cre2_regexp_t *re)
{
return TO_CONST_RE2(re)->NumberOfCapturingGroups();
}
int
cre2_program_size (const cre2_regexp_t *re)
{
return TO_CONST_RE2(re)->ProgramSize();
}
/** --------------------------------------------------------------------
** Matching with precompiled regular expressions objects.
** ----------------------------------------------------------------- */
int
cre2_match (const cre2_regexp_t *re , const char *text,
int textlen, int startpos, int endpos, cre2_anchor_t anchor,
cre2_string_t *match, int nmatch)
{
re2::StringPiece text_re2(text, textlen);
re2::StringPiece *match_re2;
RE2::Anchor anchor_re2 = RE2::UNANCHORED;
bool retval; // 0 for no match
// 1 for successful matching
match_re2 = (re2::StringPiece *)malloc(sizeof(re2::StringPiece) * nmatch);
switch (anchor) {
case CRE2_ANCHOR_START:
anchor_re2 = RE2::ANCHOR_START;
break;
case CRE2_ANCHOR_BOTH:
anchor_re2 = RE2::ANCHOR_BOTH;
break;
case CRE2_UNANCHORED:
break;
}
retval = TO_CONST_RE2(re)->Match(text_re2, startpos, endpos, anchor_re2, match_re2, nmatch);
if (retval) {
for (int i=0; i<nmatch; i++) {
match[i].data = match_re2[i].data();
match[i].length = match_re2[i].length();
}
}
free(match_re2);
return (retval)? 1 : 0;
}
int
cre2_easy_match (const char * pattern, int pattern_len,
const char *text, int text_len,
cre2_string_t *match, int nmatch)
{
cre2_regexp_t * rex;
cre2_options_t * opt;
int retval; // 0 for no match, 1 for successful
// matching, 2 for wrong regexp
opt = cre2_opt_new();
if (!opt) return 2;
cre2_opt_set_log_errors(opt, 0);
rex = cre2_new(pattern, pattern_len, opt);
if (!rex) {
cre2_opt_delete(opt);
return 2;
}
{
if (!cre2_error_code(rex)) {
retval = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, match, nmatch);
} else {
retval = 2;
}
}
cre2_delete(rex);
cre2_opt_delete(opt);
return retval;
}
void
cre2_strings_to_ranges (const char * text, cre2_range_t * ranges, cre2_string_t * strings, int nmatch)
{
for (int i=0; i<nmatch; ++i) {
ranges[i].start = strings[i].data - text;
ranges[i].past = ranges[i].start + strings[i].length;
}
}
/** --------------------------------------------------------------------
** Other matching functions: stringz pattern.
** ----------------------------------------------------------------- */
#define DEFINE_MATCH_ZSTRING_FUN(NAME,FUN) \
int \
NAME (const char * pattern, const cre2_string_t * text, \
cre2_string_t * match, int nmatch) \
{ \
re2::StringPiece input(text->data, text->length); \
re2::StringPiece *strv; \
RE2::Arg *argv; \
RE2::Arg * *args; \
bool retval; \
strv = (re2::StringPiece *) (malloc(sizeof(re2::StringPiece) *nmatch)); \
argv = (RE2::Arg *) (malloc(sizeof(RE2::Arg) *nmatch)); \
args = (RE2::Arg **) (malloc(sizeof(RE2::Arg *) *nmatch)); \
for (int i=0; i<nmatch; ++i) { \
argv[i] = &strv[i]; \
args[i] = &argv[i]; \
} \
retval = RE2::FUN(input, pattern, args, nmatch); \
if (retval) { \
for (int i=0; i<nmatch; ++i) { \
match[i].data = strv[i].data(); \
match[i].length = strv[i].length(); \
} \
} \
free(strv); \
free(argv); \
free(args); \
return int(retval); \
}
DEFINE_MATCH_ZSTRING_FUN(cre2_full_match,FullMatchN)
DEFINE_MATCH_ZSTRING_FUN(cre2_partial_match,PartialMatchN)
/* This is different from the above in that the "input" argument is
mutated to reference the text after the mathing portion. */
#define DEFINE_MATCH_ZSTRING_FUN2(NAME,FUN) \
int \
NAME (const char * pattern, cre2_string_t * text, \
cre2_string_t * match, int nmatch) \
{ \
re2::StringPiece input(text->data, text->length); \
re2::StringPiece *strv; \
RE2::Arg *argv; \
RE2::Arg * *args; \
bool retval; \
strv = (re2::StringPiece *) (malloc(sizeof(re2::StringPiece) *nmatch)); \
argv = (RE2::Arg *) (malloc(sizeof(RE2::Arg) *nmatch)); \
args = (RE2::Arg **) (malloc(sizeof(RE2::Arg *) *nmatch)); \
for (int i=0; i<nmatch; ++i) { \
argv[i] = &strv[i]; \
args[i] = &argv[i]; \
} \
retval = RE2::FUN(&input, pattern, args, nmatch); \
if (retval) { \
text->data = input.data(); \
text->length = input.length(); \
for (int i=0; i<nmatch; ++i) { \
match[i].data = strv[i].data(); \
match[i].length = strv[i].length(); \
} \
} \
free(strv); \
free(argv); \
free(args); \
return int(retval); \
}
DEFINE_MATCH_ZSTRING_FUN2(cre2_consume,ConsumeN)
DEFINE_MATCH_ZSTRING_FUN2(cre2_find_and_consume,FindAndConsumeN)
/** --------------------------------------------------------------------
** Other matching functions: rex pattern.
** ----------------------------------------------------------------- */
#define DEFINE_MATCH_REX_FUN(NAME,FUN) \
int \
NAME (cre2_regexp_t * rex, const cre2_string_t * text, \
cre2_string_t * match, int nmatch) \
{ \
re2::StringPiece input(text->data, text->length); \
re2::StringPiece *strv; \
RE2::Arg *argv; \
RE2::Arg * *args; \
bool retval; \
strv = (re2::StringPiece *) (malloc(sizeof(re2::StringPiece) *nmatch)); \
argv = (RE2::Arg *) (malloc(sizeof(RE2::Arg) *nmatch)); \
args = (RE2::Arg **) (malloc(sizeof(RE2::Arg *) *nmatch)); \
for (int i=0; i<nmatch; ++i) { \
argv[i] = &strv[i]; \
args[i] = &argv[i]; \
} \
retval = RE2::FUN(input, *TO_RE2(rex), args, nmatch); \
if (retval) { \
for (int i=0; i<nmatch; ++i) { \
match[i].data = strv[i].data(); \
match[i].length = strv[i].length(); \
} \
} \
free(strv); \
free(argv); \
free(args); \
return int(retval); \
}
DEFINE_MATCH_REX_FUN(cre2_full_match_re,FullMatchN)
DEFINE_MATCH_REX_FUN(cre2_partial_match_re,PartialMatchN)
/* This is different from the above in that the "input" argument is
mutated to reference the text after the mathing portion. */
#define DEFINE_MATCH_REX_FUN2(NAME,FUN) \
int \
NAME (cre2_regexp_t * rex, cre2_string_t * text, \
cre2_string_t * match, int nmatch) \
{ \
re2::StringPiece input(text->data, text->length); \
re2::StringPiece *strv; \
RE2::Arg *argv; \
RE2::Arg * *args; \
bool retval; \
strv = (re2::StringPiece *) (malloc(sizeof(re2::StringPiece) *nmatch)); \
argv = (RE2::Arg *) (malloc(sizeof(RE2::Arg) *nmatch)); \
args = (RE2::Arg **) (malloc(sizeof(RE2::Arg *) *nmatch)); \
for (int i=0; i<nmatch; ++i) { \
argv[i] = &strv[i]; \
args[i] = &argv[i]; \
} \
retval = RE2::FUN(&input, *TO_RE2(rex), args, nmatch); \
if (retval) { \
text->data = input.data(); \
text->length = input.length(); \
for (int i=0; i<nmatch; ++i) { \
match[i].data = strv[i].data(); \
match[i].length = strv[i].length(); \
} \
} \
free(strv); \
free(argv); \
free(args); \
return int(retval); \
}
DEFINE_MATCH_REX_FUN2(cre2_consume_re,ConsumeN)
DEFINE_MATCH_REX_FUN2(cre2_find_and_consume_re,FindAndConsumeN)
/** --------------------------------------------------------------------
** Problematic functions.
** ----------------------------------------------------------------- */
/* The following functions rely on C++ memory allocation. It is not
clear how they can be written to allow a correct API towards C. */
int
cre2_replace (const char * pattern, cre2_string_t * text_and_target, cre2_string_t * rewrite)
{
try {
std::string S(text_and_target->data, text_and_target->length);
re2::StringPiece R(rewrite->data, rewrite->length);
char * buffer; /* this exists to make GCC shut up about const */
bool retval;
retval = RE2::Replace(&S, pattern, R);
text_and_target->length = S.length();
buffer = (char *)malloc(1+text_and_target->length);
if (buffer) {
S.copy(buffer, text_and_target->length);
buffer[text_and_target->length] = '\0';
text_and_target->data = buffer;
} else
return -1;
return int(retval);
} catch(const std::exception &e) {
// e.what();
return -1;
} catch(...) {
return -1;
}
}
int
cre2_replace_re (cre2_regexp_t * rex, cre2_string_t * text_and_target, cre2_string_t * rewrite)
{
std::string S(text_and_target->data, text_and_target->length);
re2::StringPiece R(rewrite->data, rewrite->length);
char * buffer; /* this exists to make GCC shut up about const */
bool retval;
retval = RE2::Replace(&S, *TO_RE2(rex), R);
text_and_target->length = S.length();
buffer = (char *)malloc(1+text_and_target->length);
if (buffer) {
S.copy(buffer, text_and_target->length);
buffer[text_and_target->length] = '\0';
text_and_target->data = buffer;
} else
return -1;
return int(retval);
}
/* ------------------------------------------------------------------ */
int
cre2_global_replace (const char * pattern, cre2_string_t * text_and_target, cre2_string_t * rewrite)
{
std::string S(text_and_target->data, text_and_target->length);
re2::StringPiece R(rewrite->data, rewrite->length);
char * buffer; /* this exists to make GCC shut up about const */
int retval;
retval = RE2::GlobalReplace(&S, pattern, R);
text_and_target->length = S.length();
buffer = (char *)malloc(1+text_and_target->length);
if (buffer) {
S.copy(buffer, text_and_target->length);
buffer[text_and_target->length] = '\0';
text_and_target->data = buffer;
} else
return -1;
return int(retval);
}
int
cre2_global_replace_re (cre2_regexp_t * rex, cre2_string_t * text_and_target, cre2_string_t * rewrite)
{
std::string S(text_and_target->data, text_and_target->length);
re2::StringPiece R(rewrite->data, rewrite->length);
char * buffer; /* this exists to make GCC shut up about const */
int retval;
retval = RE2::GlobalReplace(&S, *TO_RE2(rex), R);
text_and_target->length = S.length();
buffer = (char *)malloc(1+text_and_target->length);
if (buffer) {
S.copy(buffer, text_and_target->length);
buffer[text_and_target->length] = '\0';
text_and_target->data = buffer;
} else
return -1;
return retval;
}
/* ------------------------------------------------------------------ */
int
cre2_extract (const char * pattern, cre2_string_t * text,
cre2_string_t * rewrite, cre2_string_t * target)
{
re2::StringPiece T(text->data, text->length);
re2::StringPiece R(rewrite->data, rewrite->length);
std::string O;
char * buffer; /* this exists to make GCC shut up about const */
bool retval;
retval = RE2::Extract(T, pattern, R, &O);
target->length = O.length();
buffer = (char *)malloc(1+target->length);
if (buffer) {
O.copy(buffer, target->length);
buffer[target->length] = '\0';
target->data = buffer;
} else
return -1;
return int(retval);
}
int
cre2_extract_re (cre2_regexp_t * rex, cre2_string_t * text,
cre2_string_t * rewrite, cre2_string_t * target)
{
re2::StringPiece T(text->data, text->length);
re2::StringPiece R(rewrite->data, rewrite->length);
std::string O;
char * buffer; /* this exists to make GCC shut up about const */
bool retval;
retval = RE2::Extract(T, *TO_RE2(rex), R, &O);
target->length = O.length();
buffer = (char *)malloc(1+target->length);
if (buffer) {
O.copy(buffer, target->length);
buffer[target->length] = '\0';
target->data = buffer;
} else
return -1;
return int(retval);
}
/* ------------------------------------------------------------------ */
int
cre2_quote_meta (cre2_string_t * quoted, cre2_string_t * original)
{
re2::StringPiece O(original->data, original->length);
std::string Q;
char * buffer; /* this exists to make GCC shut up about const */
Q = RE2::QuoteMeta(O);
quoted->length = Q.length();
buffer = (char *)malloc(1+quoted->length);
if (buffer) {
Q.copy(buffer, quoted->length);
buffer[quoted->length] = '\0';
quoted->data = buffer;
return 0;
} else
return -1;
}
int
cre2_possible_match_range (cre2_regexp_t * rex,
cre2_string_t * min_, cre2_string_t * max_, int maxlen)
{
std::string MIN, MAX;
cre2_string_t min, max;
char * buffer; /* this exists to make GCC shut up about const */
bool retval;
retval = TO_RE2(rex)->PossibleMatchRange(&MIN, &MAX, maxlen);
if (retval) {
/* copy MIN */
min.length = MIN.length();
buffer = (char *)malloc(1+min.length);
if (buffer) {
MIN.copy(buffer, min.length);
buffer[min.length] = '\0';
min.data = buffer;
} else
return -1;
/* copy MAX */
max.length = MAX.length();
buffer = (char *)malloc(1+max.length);
if (buffer) {
MAX.copy(buffer, max.length);
buffer[max.length] = '\0';
max.data = buffer;
} else {
free((void *)min.data);
min.data = NULL;
return -1;
}
*min_ = min;
*max_ = max;
return 1;
} else
return 0;
}
int
cre2_check_rewrite_string (cre2_regexp_t * rex, cre2_string_t * rewrite, cre2_string_t * errmsg)
{
re2::StringPiece R(rewrite->data, rewrite->length);
std::string E;
char * buffer; /* this exists to make GCC shut up about const */
bool retval;
retval = TO_RE2(rex)->CheckRewriteString(R, &E);
if (retval) {
errmsg->data = NULL;
errmsg->length = 0;
return 1;
} else {
errmsg->length = E.length();
buffer = (char *)malloc(1+errmsg->length);
if (buffer) {
E.copy(buffer, errmsg->length);
buffer[errmsg->length] = '\0';
errmsg->data = buffer;
} else
return -1;
return 0;
}
}
/* end of file */

299
outside/cre2/src/src/cre2.h Normal file
View File

@ -0,0 +1,299 @@
/*
Header file for CRE2, a C language wrapper for RE2: a regular
expressions library by Google.
Copyright (c) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2011 Keegan McAllister
All rights reserved.
For the license notice see the COPYING file.
*/
/** --------------------------------------------------------------------
** Headers.
** ----------------------------------------------------------------- */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef cre2_decl
# define cre2_decl extern
#endif
/** --------------------------------------------------------------------
** Version functions.
** ----------------------------------------------------------------- */
cre2_decl const char * cre2_version_string (void);
cre2_decl int cre2_version_interface_current (void);
cre2_decl int cre2_version_interface_revision (void);
cre2_decl int cre2_version_interface_age (void);
/** --------------------------------------------------------------------
** Regular expressions configuration options.
** ----------------------------------------------------------------- */
typedef void cre2_options_t;
typedef enum cre2_encoding_t {
CRE2_UNKNOWN = 0, /* should never happen */
CRE2_UTF8 = 1,
CRE2_Latin1 = 2
} cre2_encoding_t;
cre2_decl cre2_options_t *cre2_opt_new (void);
cre2_decl void cre2_opt_delete (cre2_options_t *opt);
cre2_decl void cre2_opt_set_posix_syntax (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_longest_match (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_log_errors (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_literal (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_never_nl (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_case_sensitive (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_perl_classes (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_word_boundary (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_one_line (cre2_options_t *opt, int flag);
cre2_decl void cre2_opt_set_max_mem (cre2_options_t *opt, int m);
cre2_decl void cre2_opt_set_encoding (cre2_options_t *opt, cre2_encoding_t enc);
cre2_decl int cre2_opt_posix_syntax (cre2_options_t *opt);
cre2_decl int cre2_opt_longest_match (cre2_options_t *opt);
cre2_decl int cre2_opt_log_errors (cre2_options_t *opt);
cre2_decl int cre2_opt_literal (cre2_options_t *opt);
cre2_decl int cre2_opt_never_nl (cre2_options_t *opt);
cre2_decl int cre2_opt_case_sensitive (cre2_options_t *opt);
cre2_decl int cre2_opt_perl_classes (cre2_options_t *opt);
cre2_decl int cre2_opt_word_boundary (cre2_options_t *opt);
cre2_decl int cre2_opt_one_line (cre2_options_t *opt);
cre2_decl int cre2_opt_max_mem (cre2_options_t *opt);
cre2_decl cre2_encoding_t cre2_opt_encoding (cre2_options_t *opt);
/** --------------------------------------------------------------------
** Precompiled regular expressions.
** ----------------------------------------------------------------- */
typedef struct cre2_string_t {
const char * data;
int length;
} cre2_string_t;
typedef void cre2_regexp_t;
/* This definition must be kept in sync with the definition of "enum
ErrorCode" in the file "re2.h" of the original RE2 distribution. */
typedef enum cre2_error_code_t {
CRE2_NO_ERROR = 0,
CRE2_ERROR_INTERNAL, /* unexpected error */
/* parse errors */
CRE2_ERROR_BAD_ESCAPE, /* bad escape sequence */
CRE2_ERROR_BAD_CHAR_CLASS, /* bad character class */
CRE2_ERROR_BAD_CHAR_RANGE, /* bad character class range */
CRE2_ERROR_MISSING_BRACKET, /* missing closing ] */
CRE2_ERROR_MISSING_PAREN, /* missing closing ) */
CRE2_ERROR_TRAILING_BACKSLASH,/* trailing \ at end of regexp */
CRE2_ERROR_REPEAT_ARGUMENT, /* repeat argument missing, e.g. "*" */
CRE2_ERROR_REPEAT_SIZE, /* bad repetition argument */
CRE2_ERROR_REPEA_TOP, /* bad repetition operator */
CRE2_ERROR_BAD_PERL_OP, /* bad perl operator */
CRE2_ERROR_BAD_UTF8, /* invalid UTF-8 in regexp */
CRE2_ERROR_BAD_NAMED_CAPTURE, /* bad named capture group */
CRE2_ERROR_PATTERN_TOO_LARGE, /* pattern too large (compile failed) */
} cre2_error_code_t;
/* construction and destruction */
cre2_decl cre2_regexp_t * cre2_new (const char *pattern, int pattern_len,
const cre2_options_t *opt);
cre2_decl void cre2_delete (cre2_regexp_t *re);
/* regular expression inspection */
cre2_decl const char * cre2_pattern (const cre2_regexp_t *re);
cre2_decl int cre2_error_code (const cre2_regexp_t *re);
cre2_decl int cre2_num_capturing_groups (const cre2_regexp_t *re);
cre2_decl int cre2_program_size (const cre2_regexp_t *re);
/* invalidated by further re use */
cre2_decl const char *cre2_error_string(const cre2_regexp_t *re);
cre2_decl void cre2_error_arg(const cre2_regexp_t *re, cre2_string_t * arg);
/** --------------------------------------------------------------------
** Main matching functions.
** ----------------------------------------------------------------- */
typedef enum cre2_anchor_t {
CRE2_UNANCHORED = 1,
CRE2_ANCHOR_START = 2,
CRE2_ANCHOR_BOTH = 3
} cre2_anchor_t;
typedef struct cre2_range_t {
long start; /* inclusive start index for bytevector */
long past; /* exclusive end index for bytevector */
} cre2_range_t;
cre2_decl int cre2_match (const cre2_regexp_t * re,
const char * text, int textlen,
int startpos, int endpos, cre2_anchor_t anchor,
cre2_string_t * match, int nmatch);
cre2_decl int cre2_easy_match (const char * pattern, int pattern_len,
const char * text, int text_len,
cre2_string_t * match, int nmatch);
cre2_decl void cre2_strings_to_ranges (const char * text, cre2_range_t * ranges,
cre2_string_t * strings, int nmatch);
/** --------------------------------------------------------------------
** Other matching functions.
** ----------------------------------------------------------------- */
typedef int cre2_match_stringz_fun_t (const char * pattern, const cre2_string_t * text,
cre2_string_t * match, int nmatch);
typedef int cre2_match_stringz2_fun_t (const char * pattern, cre2_string_t * text,
cre2_string_t * match, int nmatch);
typedef int cre2_match_rex_fun_t (cre2_regexp_t * rex, const cre2_string_t * text,
cre2_string_t * match, int nmatch);
typedef int cre2_match_rex2_fun_t (cre2_regexp_t * rex, cre2_string_t * text,
cre2_string_t * match, int nmatch);
cre2_decl cre2_match_stringz_fun_t cre2_full_match;
cre2_decl cre2_match_stringz_fun_t cre2_partial_match;
cre2_decl cre2_match_stringz2_fun_t cre2_consume;
cre2_decl cre2_match_stringz2_fun_t cre2_find_and_consume;
cre2_decl cre2_match_rex_fun_t cre2_full_match_re;
cre2_decl cre2_match_rex_fun_t cre2_partial_match_re;
cre2_decl cre2_match_rex2_fun_t cre2_consume_re;
cre2_decl cre2_match_rex2_fun_t cre2_find_and_consume_re;
/** --------------------------------------------------------------------
** Problematic functions.
** ----------------------------------------------------------------- */
/* Match the text in the buffer "text_and_target" against the rex in
"pattern" or "rex". Mutate "text_and_target" so that it references a
malloc'ed buffer holding the original text in which the first, and
only the first, match is substituted with the text in "rewrite".
Numeric backslash sequences (\1 to \9) in "rewrite" are substituted
with the portions of text matching the corresponding parenthetical
subexpressions.
Return 0 if no match, 1 if successful match, -1 if error allocating
memory. */
cre2_decl int cre2_replace (const char * pattern,
cre2_string_t * text_and_target,
cre2_string_t * rewrite);
cre2_decl int cre2_replace_re (cre2_regexp_t * rex,
cre2_string_t * text_and_target,
cre2_string_t * rewrite);
/* Match the text in the buffer "text_and_target" against the rex in
"pattern" or "rex". Mutate "text_and_target" so that it references a
malloc'ed buffer holding the original text in which the all the
matching substrings are substituted with the text in "rewrite".
Numeric backslash sequences (\1 to \9) in "rewrite" are substituted
with the portions of text matching the corresponding parenthetical
subexpressions.
Return 0 if no match, positive integer representing the number of
substitutions performed if successful match, -1 if error allocating
memory. */
cre2_decl int cre2_global_replace (const char * pattern,
cre2_string_t * text_and_target,
cre2_string_t * rewrite);
cre2_decl int cre2_global_replace_re (cre2_regexp_t * rex,
cre2_string_t * text_and_target,
cre2_string_t * rewrite);
/* Match the text in the buffer "text" against the rex in "pattern" or
"rex". Mutate "target" so that it references a malloc'ed buffer
holding a copy of the text in "rewrite"; numeric backslash sequences
(\1 to \9) in "rewrite" are substituted with the portions of text
matching the corresponding parenthetical subexpressions.
Non-matching text in "text" is ignored.
Return 0 if no match, 1 if successful match, -1 if error allocating
memory. */
cre2_decl int cre2_extract (const char * pattern,
cre2_string_t * text,
cre2_string_t * rewrite,
cre2_string_t * target);
cre2_decl int cre2_extract_re (cre2_regexp_t * rex,
cre2_string_t * text,
cre2_string_t * rewrite,
cre2_string_t * target);
/* ------------------------------------------------------------------ */
/* Allocate a zero-terminated malloc'ed buffer and fill it with the text
from "original" having all the regexp meta characters quoted with
single backslashes. Return 0 if successful, return -1 if an error
allocating memory occurs. */
cre2_decl int cre2_quote_meta (cre2_string_t * quoted, cre2_string_t * original);
/* Compute a "minimum" string and a "maximum" string matching the given
regular expression. The min and max can in some cases be arbitrarily
precise, so the caller gets to specify "maxlen" begin the maximum
desired length of string returned.
Assuming the call returns successfully, any string S that is an
anchored match for this regexp satisfies:
min <= S && S <= max.
Note that this function will only consider the first copy of an
infinitely repeated element (i.e., any regexp element followed by a
'*' or '+' operator). Regexps with "{N}" constructions are not
affected, as those do not compile down to infinite repetitions.
"min_" and "max_" are mutated to reference zero-terminated malloc'ed
buffers holding the min and max strings.
Return 0 if failure, return 1 if successful, return -1 if an error
allocating memory occurs. */
cre2_decl int cre2_possible_match_range (cre2_regexp_t * rex,
cre2_string_t * min_, cre2_string_t * max_,
int maxlen);
/* Check that the given rewrite string is suitable for use with this
regular expression. It checks that:
* The regular expression has enough parenthesized subexpressions to
satisfy all of the \N tokens in rewrite
* The rewrite string doesn't have any syntax errors. E.g., '\'
followed by anything other than a digit or '\'.
A true return value guarantees that the replace and extract functions
won't fail because of a bad rewrite string.
In case of error: "errmsg" is mutated to reference a zero-terminated
malloc'ed string describing the problem.
Return 1 if the string is correct, return 0 if the string is
incorrect, return -1 if an error occurred allocating memory. */
cre2_decl int cre2_check_rewrite_string (cre2_regexp_t * rex,
cre2_string_t * rewrite, cre2_string_t * errmsg);
/** --------------------------------------------------------------------
** Done.
** ----------------------------------------------------------------- */
#ifdef __cplusplus
} // extern "C"
#endif
/* end of file */

View File

@ -0,0 +1,335 @@
/*
Part of: CRE2
Contents: test for consume match function
Date: Tue Jan 3, 2012
Abstract
Test file for consume match function.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
{ /* success, no parentheses, full consumed buffer */
const char * pattern = "ci.*ut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_consume(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp("", input.data, input.length))
goto error;
}
{ /* success, no parentheses, partially consumed buffer */
const char * pattern = "ci.*ut";
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_consume(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_consume(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
result = cre2_consume(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_consume(pattern, &input, NULL, 0);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_consume(pattern, &input, match, nmatch);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_consume(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
result = cre2_consume(pattern, &input, match, nmatch);
if (0 != result)
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_consume(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* wrong regexp specification */
const char * pattern = "cia(o salut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_consume(pattern, &input, match, nmatch);
if (0 != result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
/* ------------------------------------------------------------------ */
{ /* success, no parentheses, full buffer consumed */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, no parentheses, partial buffer consumed */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (0 != result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,103 @@
/*
Part of: CRE2
Contents: test for easy matching
Date: Mon Jan 2, 2012
Abstract
Test file for regular expressions matching.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
const char * pattern;
const char * text;
/* ------------------------------------------------------------------ */
/* single match */
pattern = "ciao";
text = "ciao";
{
cre2_string_t match;
int nmatch = 1;
cre2_easy_match(pattern, strlen(pattern),
text, strlen(text),
&match, nmatch);
PRINTF("match: ");
FWRITE(match.data, match.length, 1, stdout);
PRINTF("\n");
if (0 != strncmp("ciao", match.data, match.length))
goto error;
}
/* ------------------------------------------------------------------ */
/* wrong pattern */
pattern = "ci(ao";
text = "ciao";
{
cre2_string_t match;
int nmatch = 1;
int retval;
retval = cre2_easy_match(pattern, strlen(pattern),
text, strlen(text),
&match, nmatch);
if (2 != retval)
goto error;
}
/* ------------------------------------------------------------------ */
/* two groups */
pattern = "(ciao) (hello)";
text = "ciao hello";
{
int nmatch = 3;
cre2_string_t match[nmatch];
cre2_easy_match(pattern, strlen(pattern),
text, strlen(text),
match, nmatch);
PRINTF("full match: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("first group: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
PRINTF("second group: ");
FWRITE(match[2].data, match[2].length, 1, stdout);
PRINTF("\n");
if (0 != strncmp("ciao hello", match[0].data, match[0].length))
goto error;
if (0 != strncmp("ciao", match[1].data, match[1].length))
goto error;
if (0 != strncmp("hello", match[2].data, match[2].length))
goto error;
}
/* ------------------------------------------------------------------ */
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,335 @@
/*
Part of: CRE2
Contents: test for find and consume match function
Date: Tue Jan 3, 2012
Abstract
Test file for find and consume match function.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
{ /* success, no parentheses, full consumed buffer */
const char * pattern = "ci.*ut";
const char * text = "prefix ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_find_and_consume(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp("", input.data, input.length))
goto error;
}
{ /* success, no parentheses, partially consumed buffer */
const char * pattern = "ci.*ut";
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_find_and_consume(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_find_and_consume(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
result = cre2_find_and_consume(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
const char * text = "prefix ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_find_and_consume(pattern, &input, NULL, 0);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
const char * text = "prefix ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_find_and_consume(pattern, &input, match, nmatch);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_find_and_consume(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
result = cre2_find_and_consume(pattern, &input, match, nmatch);
if (0 != result)
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_find_and_consume(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* wrong regexp specification */
const char * pattern = "cia(o salut";
const char * text = "prefix ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_find_and_consume(pattern, &input, match, nmatch);
if (0 != result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
/* ------------------------------------------------------------------ */
{ /* success, no parentheses, full buffer consumed */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "prefix ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, no parentheses, partial buffer consumed */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "prefix ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "prefix ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "prefix ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (0 != result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "prefix ciao salut hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_find_and_consume_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(" hello", input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,308 @@
/*
Part of: CRE2
Contents: test for full match function
Date: Tue Jan 3, 2012
Abstract
Test file for full match function.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
{ /* success, no parentheses */
const char * pattern = "ci.*ut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_full_match(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_full_match(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
result = cre2_full_match(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_full_match(pattern, &input, NULL, 0);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_full_match(pattern, &input, match, nmatch);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_full_match(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
result = cre2_full_match(pattern, &input, match, nmatch);
if (0 != result)
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_full_match(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* wrong regexp specification */
const char * pattern = "cia(o salut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_full_match(pattern, &input, match, nmatch);
if (0 != result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
/* ------------------------------------------------------------------ */
{ /* success, no parentheses */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (0 != result)
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_full_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,122 @@
/*
Part of: CRE2
Contents: test for matching
Date: Mon Jan 2, 2012
Abstract
Test file for regular expressions matching.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
cre2_regexp_t * rex;
cre2_options_t * opt;
const char * pattern;
/* ------------------------------------------------------------------ */
/* single match */
pattern = "ciao";
opt = cre2_opt_new();
cre2_opt_set_posix_syntax(opt, 1);
rex = cre2_new(pattern, strlen(pattern), opt);
{
if (cre2_error_code(rex))
goto error;
cre2_string_t match;
int nmatch = 1;
int e;
const char * text = "ciao";
int text_len = strlen(text);
e = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, &match, nmatch);
if (1 != e)
goto error;
PRINTF("match: retval=%d, ", e);
FWRITE(match.data, match.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
cre2_opt_delete(opt);
/* ------------------------------------------------------------------ */
/* two groups */
pattern = "(ciao) (hello)";
opt = cre2_opt_new();
rex = cre2_new(pattern, strlen(pattern), opt);
{
if (cre2_error_code(rex))
goto error;
int nmatch = 3;
cre2_string_t strings[nmatch];
cre2_range_t ranges[nmatch];
int e;
const char * text = "ciao hello";
int text_len = strlen(text);
e = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, strings, nmatch);
if (1 != e)
goto error;
cre2_strings_to_ranges(text, ranges, strings, nmatch);
PRINTF("full match: ");
FWRITE(text+ranges[0].start, ranges[0].past-ranges[0].start, 1, stdout);
PRINTF("\n");
PRINTF("first group: ");
FWRITE(text+ranges[1].start, ranges[1].past-ranges[1].start, 1, stdout);
PRINTF("\n");
PRINTF("second group: ");
FWRITE(text+ranges[2].start, ranges[2].past-ranges[2].start, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
cre2_opt_delete(opt);
/* ------------------------------------------------------------------ */
/* test literal option */
pattern = "(ciao) (hello)";
opt = cre2_opt_new();
cre2_opt_set_literal(opt, 1);
rex = cre2_new(pattern, strlen(pattern), opt);
{
if (cre2_error_code(rex))
goto error;
int nmatch = 0;
int e;
const char * text = "(ciao) (hello)";
int text_len = strlen(text);
e = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, NULL, nmatch);
if (0 == e)
goto error;
}
cre2_delete(rex);
cre2_opt_delete(opt);
/* ------------------------------------------------------------------ */
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,119 @@
/*
Part of: CRE2
Contents: test for miscellaneous functions
Date: Wed Jan 4, 2012
Abstract
Test file for miscellaneous functions.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
{ /* quote meta characters */
const char * pattern = "1.5-2.0?";
cre2_string_t original = {
.data = pattern,
.length = strlen(pattern)
};
cre2_string_t quoted;
int result;
result = cre2_quote_meta(&quoted, &original);
if (0 != result)
goto error;
if (0 != strncmp("1\\.5\\-2\\.0\\?", quoted.data, quoted.length))
goto error;
free((void *)quoted.data);
}
/* ------------------------------------------------------------------ */
{ /* minimum and maximum matching strings */
const char * pattern = "(?i)ABCdef";
cre2_regexp_t * rex;
cre2_string_t min, max;
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_possible_match_range(rex, &min, &max, 1024);
if (1 != result)
goto error;
if (0 != strncmp("ABCDEF", min.data, min.length))
goto error;
if (0 != strncmp("abcdef", max.data, max.length))
goto error;
}
cre2_delete(rex);
free((void *)min.data);
free((void *)max.data);
}
/* ------------------------------------------------------------------ */
{ /* successfully check rewrite string */
const char * pattern = "a(b)c";
const char * subst = "def";
cre2_string_t rewrite = {
.data = subst,
.length = strlen(subst)
};
cre2_regexp_t * rex;
cre2_string_t errmsg;
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_check_rewrite_string(rex, &rewrite, &errmsg);
if (1 != result)
goto error;
}
cre2_delete(rex);
}
{ /* failed check rewrite string */
const char * pattern = "a(b)c";
const char * subst = "\\1 \\2";
cre2_string_t rewrite = {
.data = subst,
.length = strlen(subst)
};
cre2_regexp_t * rex;
cre2_string_t errmsg;
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_check_rewrite_string(rex, &rewrite, &errmsg);
if (0 != result)
goto error;
PRINTF("error message: ");
FWRITE(errmsg.data, errmsg.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)errmsg.data);
}
/* ------------------------------------------------------------------ */
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,43 @@
/*
Part of: CRE2
Contents: test for options
Date: Mon Jan 2, 2012
Abstract
Test file for options objects.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <cre2.h>
int
main (int argc, const char *const argv[])
{
cre2_options_t * opt;
opt = cre2_opt_new();
{
cre2_opt_set_posix_syntax(opt, 1);
cre2_opt_set_longest_match(opt, 1);
cre2_opt_set_log_errors(opt, 1);
cre2_opt_set_literal(opt, 1);
cre2_opt_set_never_nl(opt, 1);
cre2_opt_set_case_sensitive(opt, 1);
cre2_opt_set_perl_classes(opt, 1);
cre2_opt_set_word_boundary(opt, 1);
cre2_opt_set_one_line(opt, 1);
cre2_opt_set_encoding(opt, CRE2_UTF8);
cre2_opt_set_encoding(opt, CRE2_Latin1);
cre2_opt_set_max_mem(opt, 4096);
}
cre2_opt_delete(opt);
exit(EXIT_SUCCESS);
}
/* end of file */

View File

@ -0,0 +1,308 @@
/*
Part of: CRE2
Contents: test for partial match function
Date: Tue Jan 3, 2012
Abstract
Test file for partial match function.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
{ /* success, no parentheses */
const char * pattern = "ci.*ut";
const char * text = "pre ciao salut post";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_partial_match(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_partial_match(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
result = cre2_partial_match(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_partial_match(pattern, &input, NULL, 0);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_partial_match(pattern, &input, match, nmatch);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
result = cre2_partial_match(pattern, &input, NULL, 0);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
result = cre2_partial_match(pattern, &input, match, nmatch);
if (0 != result)
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_partial_match(pattern, &input, match, nmatch);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* wrong regexp specification */
const char * pattern = "cia(o salut";
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
result = cre2_partial_match(pattern, &input, match, nmatch);
if (0 != result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
/* ------------------------------------------------------------------ */
{ /* success, no parentheses */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, one match entry */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
{ /* success, two parenthetical subexpressions, two match entries */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp("salut", match[1].data, match[1].length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
PRINTF("match 1: ");
FWRITE(match[1].data, match[1].length, 1, stdout);
PRINTF("\n");
}
{ /* failure, no parentheses */
const char * pattern = "ci.*ut";
cre2_regexp_t * rex;
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (result)
goto error;
}
{ /* failure, one parenthetical subexpression */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao hello";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* success, one parenthetical subexpression, no match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, NULL, 0);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
}
{ /* failure, one parenthetical subexpression, two match entries */
const char * pattern = "(ciao) salut";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 2;
cre2_string_t match[nmatch];
int result;
memset(match, '\0', nmatch * sizeof(cre2_string_t));
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (0 != result)
goto error;
}
{ /* success, two parenthetical subexpressions, one match entry */
const char * pattern = "(ciao) (salut)";
cre2_regexp_t * rex;
const char * text = "ciao salut";
cre2_string_t input = { .data = text, .length = strlen(text) };
int nmatch = 1;
cre2_string_t match[nmatch];
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
result = cre2_partial_match_re(rex, &input, match, nmatch);
cre2_delete(rex);
if (! result)
goto error;
if (0 != strncmp("ciao", match[0].data, match[0].length))
goto error;
if (0 != strncmp(text, input.data, input.length))
goto error;
PRINTF("match 0: ");
FWRITE(match[0].data, match[0].length, 1, stdout);
PRINTF("\n");
}
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,257 @@
/*
Part of: CRE2
Contents: test for replace
Date: Wed Jan 4, 2012
Abstract
Test file for replacing.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
{ /* replace all the buffer using the full match */
cre2_regexp_t * rex;
const char * pattern = "ciao hello salut";
const char * text = "ciao hello salut";
const char * replace = "pre \\0 post";
cre2_string_t target = {
.data = text,
.length = strlen(text)
};
cre2_string_t rewrite = {
.data = replace,
.length = strlen(replace)
};
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_replace_re(rex, &target, &rewrite);
if (1 != result)
goto error;
if (0 != strncmp("pre ciao hello salut post", target.data, target.length))
goto error;
if ('\0' != target.data[target.length])
goto error;
PRINTF("rewritten to: ");
FWRITE(target.data, target.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)target.data);
}
{ /* replace substring with fixed string */
cre2_regexp_t * rex;
const char * pattern = "hello";
const char * text = "ciao hello salut";
const char * replace = "ohayo";
cre2_string_t target = {
.data = text,
.length = strlen(text)
};
cre2_string_t rewrite = {
.data = replace,
.length = strlen(replace)
};
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_replace_re(rex, &target, &rewrite);
if (1 != result)
goto error;
if (0 != strncmp("ciao ohayo salut", target.data, target.length))
goto error;
if ('\0' != target.data[target.length])
goto error;
PRINTF("rewritten to: ");
FWRITE(target.data, target.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)target.data);
}
/* ------------------------------------------------------------------ */
{ /* global replace all the buffer using the full match */
cre2_regexp_t * rex;
const char * pattern = "ciao hello salut";
const char * text = "ciao hello salut";
const char * replace = "pre \\0 post";
cre2_string_t target = {
.data = text,
.length = strlen(text)
};
cre2_string_t rewrite = {
.data = replace,
.length = strlen(replace)
};
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_global_replace_re(rex, &target, &rewrite);
if (1 != result)
goto error;
if (0 != strncmp("pre ciao hello salut post", target.data, target.length))
goto error;
if ('\0' != target.data[target.length])
goto error;
PRINTF("rewritten to: ");
FWRITE(target.data, target.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)target.data);
}
{ /* global replace substring with fixed string */
cre2_regexp_t * rex;
const char * pattern = "hello";
const char * text = "ciao hello salut";
const char * replace = "ohayo";
cre2_string_t target = {
.data = text,
.length = strlen(text)
};
cre2_string_t rewrite = {
.data = replace,
.length = strlen(replace)
};
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_global_replace_re(rex, &target, &rewrite);
if (1 != result)
goto error;
if (0 != strncmp("ciao ohayo salut", target.data, target.length))
goto error;
if ('\0' != target.data[target.length])
goto error;
PRINTF("rewritten to: ");
FWRITE(target.data, target.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)target.data);
}
{ /* global replace multiple substrings with parametrised string */
cre2_regexp_t * rex;
const char * pattern = "[a-z]+\\(([0-9]+)\\)";
const char * text = "ciao(1) hello(2) salut(3)";
const char * replace = "ohayo(\\1)";
cre2_string_t target = {
.data = text,
.length = strlen(text)
};
cre2_string_t rewrite = {
.data = replace,
.length = strlen(replace)
};
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_global_replace_re(rex, &target, &rewrite);
if (3 != result) /* 3 substitutions */
goto error;
if (0 != strncmp("ohayo(1) ohayo(2) ohayo(3)", target.data, target.length))
goto error;
if ('\0' != target.data[target.length])
goto error;
PRINTF("result %d, rewritten to: ", result);
FWRITE(target.data, target.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)target.data);
}
/* ------------------------------------------------------------------ */
{ /* extract all the buffer using the full match */
cre2_regexp_t * rex;
const char * pattern = "ciao hello salut";
const char * text = "ciao hello salut";
const char * replace = "pre \\0 post";
cre2_string_t input = {
.data = text,
.length = strlen(text)
};
cre2_string_t rewrite = {
.data = replace,
.length = strlen(replace)
};
cre2_string_t target;
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_extract_re(rex, &input, &rewrite, &target);
if (1 != result)
goto error;
if (0 != strncmp("pre ciao hello salut post", target.data, target.length))
goto error;
if ('\0' != target.data[target.length])
goto error;
PRINTF("rewritten to: ");
FWRITE(target.data, target.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)target.data);
}
{ /* extract substring with fixed string */
cre2_regexp_t * rex;
const char * pattern = "hello([0-9]+)";
const char * text = "ciao hello123 salut";
const char * replace = "ohayo\\1";
cre2_string_t input = {
.data = text,
.length = strlen(text)
};
cre2_string_t rewrite = {
.data = replace,
.length = strlen(replace)
};
cre2_string_t target;
int result;
rex = cre2_new(pattern, strlen(pattern), NULL);
{
result = cre2_extract_re(rex, &input, &rewrite, &target);
if (1 != result)
goto error;
if (0 != strncmp("ohayo123", target.data, target.length))
goto error;
if ('\0' != target.data[target.length])
goto error;
PRINTF("rewritten to: ");
FWRITE(target.data, target.length, 1, stdout);
PRINTF("\n");
}
cre2_delete(rex);
free((void *)target.data);
}
/* ------------------------------------------------------------------ */
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,113 @@
/*
Part of: CRE2
Contents: test for rex allocation
Date: Mon Jan 2, 2012
Abstract
Test file for regular expressions allocation.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cre2.h>
#if 0
# define PRINTF printf
# define FWRITE fwrite
#else
# define PRINTF(MSG, ...) /* empty string */
# define FWRITE(BUF, ...) /* empty string */
#endif
int
main (int argc, const char *const argv[])
{
cre2_regexp_t * rex;
cre2_options_t * opt;
opt = cre2_opt_new();
cre2_opt_set_posix_syntax(opt, 1);
rex = cre2_new("ciao", 4, opt);
{
cre2_string_t S;
PRINTF("pattern: %s\n", cre2_pattern(rex));
PRINTF("error code: %d\n", cre2_error_code(rex));
PRINTF("error string: \"%s\"\n", cre2_error_string(rex));
PRINTF("number of capturing groups: %d\n", cre2_num_capturing_groups(rex));
PRINTF("program size: %d\n", cre2_program_size(rex));
cre2_error_arg(rex, &S);
PRINTF("error arg: len=%d, data=\"%s\"\n", S.length, S.data);
if (cre2_error_code(rex))
goto error;
if (cre2_num_capturing_groups(rex))
goto error;
if (cre2_error_code(rex))
goto error;
if (0 != strlen(cre2_error_string(rex)))
goto error;
if (0 != S.length)
goto error;
}
cre2_delete(rex);
cre2_opt_delete(opt);
/* ------------------------------------------------------------------ */
/* no options object */
rex = cre2_new("ciao", 4, NULL);
{
if (cre2_error_code(rex))
goto error;
}
cre2_delete(rex);
/* ------------------------------------------------------------------ */
opt = cre2_opt_new();
cre2_opt_set_posix_syntax(opt, 1);
rex = cre2_new("ci(ao)", 6, opt);
{
PRINTF("error code: %d\n", cre2_error_code(rex));
PRINTF("number of capturing groups: %d\n", cre2_num_capturing_groups(rex));
PRINTF("program size: %d\n", cre2_program_size(rex));
if (cre2_error_code(rex))
goto error;
if (1 != cre2_num_capturing_groups(rex))
goto error;
}
cre2_delete(rex);
cre2_opt_delete(opt);
/* ------------------------------------------------------------------ */
opt = cre2_opt_new();
cre2_opt_set_log_errors(opt, 0);
rex = cre2_new("ci(ao", 5, opt);
{
int code = cre2_error_code(rex);
const char * msg = cre2_error_string(rex);
cre2_string_t S;
cre2_error_arg(rex, &S);
if (CRE2_ERROR_MISSING_PAREN != code)
goto error;
if (! msg)
goto error;
PRINTF("pattern: %s\n", cre2_pattern(rex));
PRINTF("error: code=%d, msg=\"%s\"\n", code, msg);
PRINTF("error arg: len=%d, data=\"%s\"\n", S.length, S.data);
}
cre2_delete(rex);
cre2_opt_delete(opt);
exit(EXIT_SUCCESS);
error:
exit(EXIT_FAILURE);
}
/* end of file */

View File

@ -0,0 +1,30 @@
/*
Part of: CRE2
Contents: test for version functions
Date: Mon Jan 2, 2012
Abstract
Test file for version functions.
Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>
See the COPYING file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <cre2.h>
int
main (int argc, const char *const argv[])
{
printf("version number string: %s\n", cre2_version_string());
printf("libtool version number: %d:%d:%d\n",
cre2_version_interface_current(),
cre2_version_interface_revision(),
cre2_version_interface_age());
exit(EXIT_SUCCESS);
}
/* end of file */

View File

@ -180,12 +180,14 @@ _unix_fs_event_cb(uv_fs_event_t* was_u,
u2_unod* nod_u = (void*)was_u;
// uL(fprintf(uH, "fs: %s in %s\n", pax_c, nod_u->pax_c));
u2_lo_open();
{
while ( nod_u ) {
nod_u->dry = u2_no;
nod_u = (u2_unod*) nod_u->par_u;
}
}
u2_lo_shut(u2_yes);
}
/* _unix_file_watch(): create file tracker (from filesystem)