Add libregex, connect it to the build

libregex is a regex(3) implementation intended to feature GNU extensions and
any other non-POSIX compliant extensions that are deemed worthy.

These extensions are separated out into a separate library for the sake of
not cluttering up libc further with them as well as not deteriorating the
speed (or lack thereof) of the libc implementation.

libregex is implemented as a build of the libc implementation with LIBREGEX
defined to distinguish this from a libc build. The reasons for
implementation like this are two-fold:

1.) Maintenance- This reduces the overhead induced by adding yet another
regex implementation to base.

2.) Ease of use- Flipping on GNU extensions will be as simple as linking
against libregex, and POSIX-compliant compilations can be guaranteed with a
REG_POSIX cflag that should be ignored by libc/regex and disables extensions
in libregex. It is also easier to keep REG_POSIX sane and POSIX pure when
implemented in this fashion.

Tests are added for future functionality, but left disconnected for the time
being while other testing is done.

Reviewed by:	cem (previous version)
Differential Revision:	https://reviews.freebsd.org/D12934
This commit is contained in:
Kyle Evans 2018-01-22 02:44:41 +00:00
parent 44c514b142
commit b37f6c9805
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=328240
11 changed files with 193 additions and 58 deletions

View file

@ -354,6 +354,10 @@
..
libproc
..
libregex
data
..
..
librt
..
libsbuf

View file

@ -71,6 +71,7 @@ SUBDIR= ${SUBDIR_BOOTSTRAP} \
libpjdlog \
${_libproc} \
libprocstat \
libregex \
librpcsvc \
librss \
librt \

View file

@ -10,8 +10,11 @@ SRCS+= regcomp.c regerror.c regexec.c regfree.c
SYM_MAPS+=${LIBC_SRCTOP}/regex/Symbol.map
# manpages only included in libc version
.if ${LIB} == "c"
MAN+= regex.3
MAN+= re_format.7
MLINKS+=regex.3 regcomp.3 regex.3 regexec.3 regex.3 regerror.3
MLINKS+=regexec.3 regfree.3
.endif

View file

@ -1,63 +1,7 @@
# $FreeBSD$
.include <bsd.own.mk>
PACKAGE= tests
BINDIR= ${TESTSDIR}
# SKIP_LEFTASSOC -> these testcases fail on FreeBSD.
IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC
CFLAGS.h_regex+=-I${TESTSRC} -I${.CURDIR:H:H}/regex
PROGS+= h_regex
SRCS.h_regex= main.c split.c debug.c
NETBSD_ATF_TESTS_SH= regex_test
${PACKAGE}FILES+= README
FILESGROUPS+= ${PACKAGE}DATA_FILES
${PACKAGE}DATA_FILESPACKAGE=${PACKAGE}
${PACKAGE}DATA_FILESDIR= ${TESTSDIR}/data
${PACKAGE}DATA_FILES+= data/anchor.in
${PACKAGE}DATA_FILES+= data/backref.in
${PACKAGE}DATA_FILES+= data/basic.in
${PACKAGE}DATA_FILES+= data/bracket.in
${PACKAGE}DATA_FILES+= data/c_comments.in
${PACKAGE}DATA_FILES+= data/complex.in
${PACKAGE}DATA_FILES+= data/error.in
${PACKAGE}DATA_FILES+= data/meta.in
${PACKAGE}DATA_FILES+= data/nospec.in
${PACKAGE}DATA_FILES+= data/paren.in
${PACKAGE}DATA_FILES+= data/regress.in
${PACKAGE}DATA_FILES+= data/repet_bounded.in
${PACKAGE}DATA_FILES+= data/repet_multi.in
${PACKAGE}DATA_FILES+= data/repet_ordinary.in
${PACKAGE}DATA_FILES+= data/startend.in
${PACKAGE}DATA_FILES+= data/subexp.in
${PACKAGE}DATA_FILES+= data/subtle.in
${PACKAGE}DATA_FILES+= data/word_bound.in
${PACKAGE}DATA_FILES+= data/zero.in
#${PACKAGE}DATA_FILES+= data/att/README
${PACKAGE}DATA_FILES+= data/att/basic.dat
${PACKAGE}DATA_FILES+= data/att/categorization.dat
${PACKAGE}DATA_FILES+= data/att/forcedassoc.dat
${PACKAGE}DATA_FILES+= data/att/leftassoc.dat
${PACKAGE}DATA_FILES+= data/att/nullsubexpr.dat
${PACKAGE}DATA_FILES+= data/att/repetition.dat
${PACKAGE}DATA_FILES+= data/att/rightassoc.dat
NETBSD_ATF_TESTS_C= exhaust_test
NETBSD_ATF_TESTS_C+= regex_att_test
.for t in ${NETBSD_ATF_TESTS_C}
CFLAGS.$t+= -I${TESTSRC} ${IMPLEMENTATION}
.endfor
.include "../Makefile.netbsd-tests"
LIBADD.regex_att_test+= util
.include "Makefile.inc"
.include "${.CURDIR:H}/Makefile.netbsd-tests"
.include <bsd.test.mk>

View file

@ -0,0 +1,57 @@
# $FreeBSD$
.include <bsd.own.mk>
BINDIR?= ${TESTSDIR}
# SKIP_LEFTASSOC -> these testcases fail on FreeBSD.
IMPLEMENTATION?= -DREGEX_SPENCER -DSKIP_LEFTASSOC
CFLAGS.h_regex+=-I${TESTSRC} -I${SRCTOP}/lib/libc/regex
PROGS+= h_regex
SRCS.h_regex= main.c split.c debug.c
NETBSD_ATF_TESTS_SH= regex_test
${PACKAGE}FILES+= README
FILESGROUPS+= ${PACKAGE}DATA_FILES
${PACKAGE}DATA_FILESPACKAGE=${PACKAGE}
${PACKAGE}DATA_FILESDIR= ${TESTSDIR}/data
${PACKAGE}DATA_FILES+= data/anchor.in
${PACKAGE}DATA_FILES+= data/backref.in
${PACKAGE}DATA_FILES+= data/basic.in
${PACKAGE}DATA_FILES+= data/bracket.in
${PACKAGE}DATA_FILES+= data/c_comments.in
${PACKAGE}DATA_FILES+= data/complex.in
${PACKAGE}DATA_FILES+= data/error.in
${PACKAGE}DATA_FILES+= data/meta.in
${PACKAGE}DATA_FILES+= data/nospec.in
${PACKAGE}DATA_FILES+= data/paren.in
${PACKAGE}DATA_FILES+= data/regress.in
${PACKAGE}DATA_FILES+= data/repet_bounded.in
${PACKAGE}DATA_FILES+= data/repet_multi.in
${PACKAGE}DATA_FILES+= data/repet_ordinary.in
${PACKAGE}DATA_FILES+= data/startend.in
${PACKAGE}DATA_FILES+= data/subexp.in
${PACKAGE}DATA_FILES+= data/subtle.in
${PACKAGE}DATA_FILES+= data/word_bound.in
${PACKAGE}DATA_FILES+= data/zero.in
#${PACKAGE}DATA_FILES+= data/att/README
${PACKAGE}DATA_FILES+= data/att/basic.dat
${PACKAGE}DATA_FILES+= data/att/categorization.dat
${PACKAGE}DATA_FILES+= data/att/forcedassoc.dat
${PACKAGE}DATA_FILES+= data/att/leftassoc.dat
${PACKAGE}DATA_FILES+= data/att/nullsubexpr.dat
${PACKAGE}DATA_FILES+= data/att/repetition.dat
${PACKAGE}DATA_FILES+= data/att/rightassoc.dat
NETBSD_ATF_TESTS_C= exhaust_test
NETBSD_ATF_TESTS_C+= regex_att_test
.for t in ${NETBSD_ATF_TESTS_C}
CFLAGS.$t+= -I${TESTSRC} ${IMPLEMENTATION}
.endfor
LIBADD.regex_att_test+= util

19
lib/libregex/Makefile Normal file
View file

@ -0,0 +1,19 @@
# $FreeBSD$
.include <src.opts.mk>
PACKAGE=lib${LIB}
LIB= regex
SHLIB_MAJOR= 1
SHLIB_MINOR= 0
CFLAGS+= -DLIBREGEX
LIBC_SRCTOP= ${.CURDIR:H}/libc
SYMBOL_MAPS= ${SYM_MAPS}
#HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
.include "../Makefile.inc"
.include "${LIBC_SRCTOP}/regex/Makefile.inc"
.include <bsd.lib.mk>

View file

@ -0,0 +1,20 @@
# $FreeBSD$
PACKAGE= tests
TESTSRC= ${SRCTOP}/contrib/netbsd-tests/lib/libc/regex
.PATH: ${SRCTOP}/tests
.include "${SRCTOP}/lib/libc/tests/regex/Makefile.inc"
ATF_TESTS_SH+= libregex_test
${PACKAGE}DATA_FILES+= gnuext.in
LIBADD.h_regex+=regex
.for t in ${NETBSD_ATF_TESTS_C}
LIBADD.$t+= regex
.endfor
.include <netbsd-tests.test.mk>
.include <bsd.test.mk>

View file

@ -0,0 +1,30 @@
# BRE Quantifiers
ab\?c b abc abc
ab\+c b abc abc
# BRE Branching
abc\|de b abc abc
a\|b\|c b abc a
\(ab\|bc\) b abcd ab
# ERE Backrefs
(ab)\1 - ab
(ab)\1 - abab abab
\1(ab) C ESUBREG
(a)(b)(c)(d)(e)(f)(g)(h)(i)\9 - abcdefghii abcdefghii
# \w, \W, \s, \S (alnum, ^alnum, space, ^space)
\w+ - -%@a0X- a0X
\w\+ b -%@a0X- a0X
\s+ - aSNTb SNT
\s\+ b aSNTb SNT
# Word boundaries (\b, \B, \<, \>, \`, \')
# (is/not boundary, start/end word, start/end subject string)
\babc\b & <abc> abc
\<abc\> & <abc> abc
\Babc\B & abc
\B[abc]\B & <abc> b
\B[abc]+ - <abc> bc
\B[abc]\+ b <abc> bc
\`abc\' & abc abc
\`.+\' - abNc abNc
\`.\+\' b abNc abNc
(\`a) - Na
(a\') - aN

View file

@ -0,0 +1,55 @@
#
# Copyright (c) 2017 Kyle Evans <kevans@FreeBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
#
# $FreeBSD$
check()
{
local dataname="${1}"; shift
prog="$(atf_get_srcdir)/h_regex"
data="$(atf_get_srcdir)/data/${dataname}.in"
atf_check -x "${prog} <${data}"
atf_check -x "${prog} -el <${data}"
atf_check -x "${prog} -er <${data}"
}
create_tc()
{
local name="${1}"; shift
local descr="${1}"; shift
atf_test_case "${name}"
eval "${name}_head() { atf_set 'descr' '${descr}'; }"
eval "${name}_body() { check '${name}'; }"
atf_add_test_case "${name}"
}
atf_init_test_cases()
{
create_tc gnuext "Check GNU extension functionality"
}

View file

@ -132,6 +132,7 @@ LIBPROCSTAT?= ${LIBDESTDIR}${LIBDIR_BASE}/libprocstat.a
LIBPTHREAD?= ${LIBDESTDIR}${LIBDIR_BASE}/libpthread.a
LIBRADIUS?= ${LIBDESTDIR}${LIBDIR_BASE}/libradius.a
LIBRDMACM?= ${LIBDESTDIR}${LIBDIR_BASE}/librdmacm.a
LIBREGEX?= ${LIBDESTDIR}${LIBDIR_BASE}/libregex.a
LIBROKEN?= ${LIBDESTDIR}${LIBDIR_BASE}/libroken.a
LIBRPCSEC_GSS?= ${LIBDESTDIR}${LIBDIR_BASE}/librpcsec_gss.a
LIBRPCSVC?= ${LIBDESTDIR}${LIBDIR_BASE}/librpcsvc.a

View file

@ -148,6 +148,7 @@ _LIBRARIES= \
pthread \
radius \
readline \
regex \
roken \
rpcsec_gss \
rpcsvc \