├── .gitignore ├── COPYING ├── INSTALL ├── LICENSE.re2 ├── Makefile.am ├── NEWS ├── README ├── README.md ├── acinclude.m4 ├── autogen.sh ├── codecov.yml ├── configure.ac ├── configure.sh ├── doc ├── cre2.style.css ├── cre2.texi ├── fdl-1.3.texi ├── macros.texi └── overview-linking.texi ├── meta ├── autoconf │ ├── ax-append-compile-flags.m4 │ ├── ax-append-flag.m4 │ ├── ax-append-link-flags.m4 │ ├── ax-check-compile-flag.m4 │ ├── ax-check-link-flag.m4 │ ├── ax-cxx-compile-stdcxx-11.m4 │ ├── ax-cxx-compile-stdcxx.m4 │ ├── ax-gcc-version.m4 │ ├── ax-is-release.m4 │ ├── ax-pthread.m4 │ ├── ax-require-defined.m4 │ ├── mmux-c-headers-includes.m4 │ ├── mmux-check-page-shift.m4 │ ├── mmux-check-page-size.m4 │ ├── mmux-check-pkg-config-macros.m4 │ ├── mmux-check-re2.m4 │ ├── mmux-check-target-os.m4 │ ├── mmux-core.m4 │ ├── mmux-determine-sizeof.m4 │ ├── mmux-lang-c99.m4 │ ├── mmux-lang-cxx11.m4 │ ├── mmux-libtool-library-versions.m4 │ └── mmux-pkg-config-find-include-file.m4 ├── automake │ └── mmux-makefile-rules ├── build │ ├── .gitignore │ ├── Makefile │ ├── POD1 │ │ └── README │ └── build-re2.bash.m4 └── scripts │ └── cre2.pc.in ├── src ├── cre2.cpp └── cre2.h └── tests ├── cre2-test.h ├── test-capture-names-iter.c ├── test-consume-match.c ├── test-easy-matching.c ├── test-find-and-consume-match.c ├── test-full-match.c ├── test-matching.c ├── test-misc.c ├── test-options.c ├── test-partial-match.c ├── test-replace.c ├── test-rex-alloc.c ├── test-set.c └── test-version.c /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | =* 3 | ,,* 4 | *.a 5 | *.bz2 6 | *.fasl 7 | *.gz 8 | *.html 9 | *.info 10 | *.la 11 | *.lo 12 | *.o 13 | *.out 14 | *.so 15 | *.so.* 16 | *.tgz 17 | *.tmp 18 | .DS_Store 19 | .arch 20 | .dirstamp 21 | .emacs.* 22 | .gdb_history 23 | .vimview 24 | .deps/ 25 | .libs/ 26 | Makefile 27 | Makefile.in 28 | aclocal.m4 29 | ar-lib 30 | autom4te* 31 | compile 32 | config.cache 33 | config.guess 34 | config.h 35 | config.h.in 36 | config.log 37 | config.status 38 | config.sub 39 | configure 40 | depcomp 41 | install-sh 42 | libtool 43 | ltmain.sh 44 | missing 45 | mkinstalldirs 46 | stamp-h1 47 | test-driver 48 | autotools/ 49 | doc/mdate-sh 50 | doc/stamp-vti 51 | doc/texinfo.tex 52 | doc/version.texi 53 | m4/ 54 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | -*- coding: utf-8-unix -*- 2 | 3 | This license is meant to be the "BSD-3-Clause". 4 | 5 | Copyright (c) 2012, 2013, 2015, 2016, 2017, 2024 Marco Maggi 6 | Copyright (c) 2011 Keegan McAllister 7 | All rights reserved. 8 | 9 | Redistribution and use in source and binary forms, with or without modification, 10 | are permitted provided that the following conditions are met: 11 | 12 | 1. Redistributions of source code must retain the above copyright notice, this 13 | list of conditions and the following disclaimer. 14 | 15 | 2. Redistributions in binary form must reproduce the above copyright notice, 16 | this list of conditions and the following disclaimer in the documentation 17 | and/or other materials provided with the distribution. 18 | 19 | 3. Neither the name of the author nor the names of his contributors may be used 20 | to endorse or promote products derived from this software without specific 21 | prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY 27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | ### end of file 35 | # Local Variables: 36 | # mode: text 37 | # fill-column: 80 38 | # paragraph-start: "*" 39 | # ispell-local-dictionary: "en_GB" 40 | # End: 41 | -------------------------------------------------------------------------------- /LICENSE.re2: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The RE2 Authors. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | ACLOCAL_AMFLAGS = -I meta/autotools 4 | AUTOMAKE_OPTIONS = foreign 5 | EXTRA_DIST = INSTALL 6 | dist_doc_DATA = README COPYING LICENSE.re2 7 | AM_CPPFLAGS = -I$(top_srcdir)/src 8 | AM_CFLAGS = $(MMUX_CFLAGS) 9 | AM_CXXFLAGS = $(MMUX_CXXFLAGS) 10 | CLEANFILES = 11 | 12 | AM_DISTCHECK_CONFIGURE_FLAGS = CC="$(CC)" CXX="$(CXX)" 13 | 14 | ## -------------------------------------------------------------------- 15 | 16 | nodist_pkgconfig_DATA = meta/scripts/cre2.pc 17 | 18 | 19 | #### documentation 20 | 21 | EXTRA_DIST += doc/cre2.style.css 22 | CLEANFILES += doc/cre2.css 23 | 24 | AM_MAKEINFOFLAGS = --no-split 25 | AM_MAKEINFOHTMLFLAGS = --split=node -c WORDS_IN_PAGE=0 --css-ref=cre2.css \ 26 | -c PRE_BODY_CLOSE="

This document describes version $(PACKAGE_VERSION) of $(PACKAGE_NAME).

" 27 | 28 | info_TEXINFOS = doc/cre2.texi 29 | doc_cre2_TEXINFOS = \ 30 | doc/macros.texi \ 31 | doc/overview-linking.texi \ 32 | doc/fdl-1.3.texi 33 | 34 | ## -------------------------------------------------------------------- 35 | 36 | doc/cre2.html/$(am__dirstamp): doc/$(am__dirstamp) 37 | @$(MKDIR_P) doc/cre2.html/ 38 | @: > doc/cre2.html/$(am__dirstamp) 39 | 40 | doc/cre2.html/cre2.css: doc/cre2.style.css doc/cre2.html/$(am__dirstamp) 41 | $(INSTALL) -m 0444 "$(top_srcdir)/doc/cre2.style.css" "$(builddir)/doc/cre2.html/cre2.css" 42 | 43 | ## -------------------------------------------------------------------- 44 | 45 | html-local: doc/cre2.html/cre2.css 46 | 47 | install-html-local: 48 | $(MKDIR_P) "$(DESTDIR)$(htmldir)/cre2.html/" 49 | $(INSTALL) -m 0444 $(builddir)/doc/cre2.html/cre2.css "$(DESTDIR)$(htmldir)/cre2.html/" 50 | 51 | 52 | #### libraries 53 | 54 | cre2_CURRENT = @cre2_VERSION_INTERFACE_CURRENT@ 55 | cre2_REVISION = @cre2_VERSION_INTERFACE_REVISION@ 56 | cre2_AGE = @cre2_VERSION_INTERFACE_AGE@ 57 | cre2_LINKER_VERSION = -version-info $(cre2_CURRENT):$(cre2_REVISION):$(cre2_AGE) 58 | 59 | include_HEADERS = src/cre2.h 60 | 61 | lib_LTLIBRARIES = libcre2.la 62 | libcre2_la_CPPFLAGS = $(AM_CPPFLAGS) 63 | libcre2_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) $(RE2_CFLAGS) 64 | libcre2_la_CXXFLAGS = $(AM_CXXFLAGS) $(PTHREAD_CFLAGS) $(RE2_CFLAGS) 65 | libcre2_la_LDFLAGS = $(cre2_LINKER_VERSION) $(AM_LDFLAGS) $(PTHREAD_LIBS) $(RE2_LIBS) 66 | libcre2_la_SOURCES = src/cre2.cpp 67 | 68 | 69 | #### tests 70 | 71 | check_PROGRAMS = \ 72 | tests/test-version \ 73 | tests/test-options \ 74 | tests/test-rex-alloc \ 75 | tests/test-matching \ 76 | tests/test-easy-matching \ 77 | tests/test-full-match \ 78 | tests/test-partial-match \ 79 | tests/test-consume-match \ 80 | tests/test-capture-names-iter \ 81 | tests/test-find-and-consume-match \ 82 | tests/test-replace \ 83 | tests/test-set \ 84 | tests/test-misc 85 | 86 | TESTS = $(check_PROGRAMS) 87 | 88 | # We can set TESTS_ENVIRONMENT from the command line of make; the 89 | # following is package specific. 90 | # 91 | # Remember that if the shared library "libre2" is used: it must be 92 | # reachable by the linker when running the test files. To do this we 93 | # may have to export a correct value of LD_LIBRARY_PATH. 94 | # 95 | #AM_TESTS_ENVIRONMENT = 96 | 97 | ## -------------------------------------------------------------------- 98 | 99 | cre2_common_sources = tests/cre2-test.h 100 | cre2_common_cflags = $(AM_CFLAGS) 101 | cre2_common_ldadd = $(AM_LDFLAGS) libcre2.la 102 | 103 | # We are linking the C++ library "libre2" with a C library "libcre2", 104 | # so we need to link the C++ Standard Library; Libtool does not know 105 | # this, because we are linking by calling "gcc" rather than "g++", so 106 | # we have to add linker options explicitly. 107 | # 108 | # (Aug 24, 2024: Marco Maggi) 109 | # 110 | 111 | # if ENABLE_STATIC 112 | # cre2_common_ldadd += -lstdc++ 113 | # endif 114 | 115 | ## -------------------------------------------------------------------- 116 | 117 | tests_test_version_SOURCES = tests/test-version.c $(cre2_common_sources) 118 | tests_test_version_CFLAGS = $(cre2_common_cflags) 119 | tests_test_version_LDADD = $(cre2_common_ldadd) 120 | 121 | tests_test_options_SOURCES = tests/test-options.c $(cre2_common_sources) 122 | tests_test_options_CFLAGS = $(cre2_common_cflags) 123 | tests_test_options_LDADD = $(cre2_common_ldadd) 124 | 125 | tests_test_rex_alloc_SOURCES = tests/test-rex-alloc.c $(cre2_common_sources) 126 | tests_test_rex_alloc_CFLAGS = $(cre2_common_cflags) 127 | tests_test_rex_alloc_LDADD = $(cre2_common_ldadd) 128 | 129 | tests_test_matching_SOURCES = tests/test-matching.c $(cre2_common_sources) 130 | tests_test_matching_CFLAGS = $(cre2_common_cflags) 131 | tests_test_matching_LDADD = $(cre2_common_ldadd) 132 | 133 | tests_test_easy_matching_SOURCES = tests/test-easy-matching.c $(cre2_common_sources) 134 | tests_test_easy_matching_CFLAGS = $(cre2_common_cflags) 135 | tests_test_easy_matching_LDADD = $(cre2_common_ldadd) 136 | 137 | tests_test_full_match_SOURCES = tests/test-full-match.c $(cre2_common_sources) 138 | tests_test_full_match_CFLAGS = $(cre2_common_cflags) 139 | tests_test_full_match_LDADD = $(cre2_common_ldadd) 140 | 141 | tests_test_partial_match_SOURCES = tests/test-partial-match.c $(cre2_common_sources) 142 | tests_test_partial_match_CFLAGS = $(cre2_common_cflags) 143 | tests_test_partial_match_LDADD = $(cre2_common_ldadd) 144 | 145 | tests_test_consume_match_SOURCES = tests/test-consume-match.c $(cre2_common_sources) 146 | tests_test_consume_match_CFLAGS = $(cre2_common_cflags) 147 | tests_test_consume_match_LDADD = $(cre2_common_ldadd) 148 | 149 | tests_test_capture_names_iter_SOURCES = tests/test-capture-names-iter.c $(cre2_common_sources) 150 | tests_test_capture_names_iter_CFLAGS = $(cre2_common_cflags) 151 | tests_test_capture_names_iter_LDADD = $(cre2_common_ldadd) 152 | 153 | tests_test_find_and_consume_match_SOURCES = tests/test-find-and-consume-match.c $(cre2_common_sources) 154 | 155 | tests_test_find_and_consume_match_CFLAGS= $(cre2_common_cflags) 156 | tests_test_find_and_consume_match_LDADD = $(cre2_common_ldadd) 157 | 158 | tests_test_replace_SOURCES = tests/test-replace.c $(cre2_common_sources) 159 | tests_test_replace_CFLAGS = $(cre2_common_cflags) 160 | tests_test_replace_LDADD = $(cre2_common_ldadd) 161 | 162 | tests_test_set_SOURCES = tests/test-set.c $(cre2_common_sources) 163 | tests_test_set_CFLAGS = $(cre2_common_cflags) 164 | tests_test_set_LDADD = $(cre2_common_ldadd) 165 | 166 | tests_test_misc_SOURCES = tests/test-misc.c $(cre2_common_sources) 167 | tests_test_misc_CFLAGS = $(cre2_common_cflags) 168 | tests_test_misc_LDADD = $(cre2_common_ldadd) 169 | 170 | ## -------------------------------------------------------------------- 171 | 172 | installcheck-local: $(check_PROGRAMS) 173 | for f in $(check_PROGRAMS); do $$f; done 174 | 175 | 176 | #### common rules 177 | 178 | include $(top_srcdir)/meta/automake/mmux-makefile-rules 179 | 180 | ### end of file 181 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | -*- coding: utf-8-unix -*- 2 | 3 | Notes for revision 0.4.0-devel.2 4 | -------------------------------- 5 | 6 | * Some makefile fixes to allow clang++ usage. 7 | 8 | * Added CSS file for HTML documentation. 9 | 10 | 11 | Notes for revision 0.4.0-devel.0 12 | -------------------------------- 13 | 14 | * Package infrastructure development. 15 | 16 | * Added iterator over names of named captured patterns. 17 | 18 | 19 | Notes for revision 0.3.6 20 | ------------------------ 21 | 22 | * Fixed missing inclusion of "". 23 | 24 | 25 | Notes for revision 0.3.5 26 | ------------------------ 27 | 28 | * Fixed missing dependency in pkg-config script. 29 | 30 | 31 | Notes for revision 0.3.4 32 | ------------------------ 33 | 34 | * Some typo fixes and implementation of the new function 35 | "cre2_find_named_capturing_groups()". 36 | 37 | 38 | ### end of file 39 | # Local Variables: 40 | # mode: text 41 | # fill-column: 72 42 | # paragraph-start: "*" 43 | # ispell-local-dictionary: "en_GB" 44 | # End: 45 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | -*- coding: utf-8-unix -*- 2 | 3 | C wrapper for re2 4 | ================= 5 | 6 | 7 | Topics 8 | ------ 9 | 10 | 1. Introduction 11 | 2. License 12 | 3. Install 13 | 4. Usage 14 | A. Credits 15 | B. Bugs, vulnerabilities and contributions 16 | C. Resources 17 | D. Installing re2 and its dependencies 18 | 19 | 20 | 1. Introduction 21 | --------------- 22 | 23 | The CRE2 distribution is a C language wrapper for the RE2 library, which 24 | is implemented in C++. RE2 is a fast, safe, thread-friendly alternative 25 | to backtracking regular expression engines like those used in PCRE, 26 | Perl, and Python. 27 | 28 | This distribution makes use of the GNU Autotools; it relies on 29 | pkg-config to find the installed re2 library. The last time the 30 | maintainer updated this paragraph, he had tested this package with a 31 | release of RE2 2024-07-02. 32 | 33 | 34 | 2. License 35 | ---------- 36 | 37 | Copyright (c) 2012, 2013, 2015, 2016, 2017, 2019, 2024 Marco Maggi 38 | Copyright (c) 2011 Keegan McAllister 39 | All rights reserved. 40 | 41 | This license is meant to be the "BSD-3-Clause". 42 | 43 | Redistribution and use in source and binary forms, with or without 44 | modification, are permitted provided that the following conditions are 45 | met: 46 | 47 | 1. Redistributions of source code must retain the above copyright 48 | notice, this list of conditions and the following disclaimer. 49 | 50 | 2. Redistributions in binary form must reproduce the above copyright 51 | notice, this list of conditions and the following disclaimer in the 52 | documentation and/or other materials provided with the distribution. 53 | 54 | 3. Neither the name of the author nor the names of his contributors may 55 | be used to endorse or promote products derived from this software 56 | without specific prior written permission. 57 | 58 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS 59 | IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 60 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 61 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR 62 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 63 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 64 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 65 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 66 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 67 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 68 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 69 | 70 | 71 | 3. Install 72 | ---------- 73 | 74 | To install RE2 follow the instructions in the README file in RE2's. To 75 | install from a proper release tarball, do this: 76 | 77 | $ cd cre2-0.1.0 78 | $ mkdir build 79 | $ cd build 80 | $ ../configure 81 | $ make 82 | $ make check 83 | $ make install 84 | 85 | to inspect the available configuration options: 86 | 87 | $ ../configure --help 88 | 89 | The Makefile is designed to allow parallel builds, so we can do: 90 | 91 | $ make -j4 all && make -j4 check 92 | 93 | which, on a 4-core CPU, should speed up building and checking 94 | significantly. 95 | 96 | The Makefile supports the DESTDIR environment variable to install 97 | files in a temporary location, example: to see what will happen: 98 | 99 | $ make -n install DESTDIR=/tmp/cre2 100 | 101 | to really do it: 102 | 103 | $ make install DESTDIR=/tmp/cre2 104 | 105 | After the installation it is possible to verify the installed library 106 | against the test suite with: 107 | 108 | $ make installcheck 109 | 110 | From a repository checkout or snapshot (the ones from the Github 111 | site): we must install the GNU Autotools (GNU Automake, GNU Autoconf, 112 | GNU Libtool), then we must first run the script "autogen.sh" from the 113 | top source directory, to generate the needed files: 114 | 115 | $ cd cre2 116 | $ sh autogen.sh 117 | 118 | notice that "autogen.sh" will run the programs "autoreconf" and 119 | "libtoolize"; the latter is selected through the environment variable 120 | "LIBTOOLIZE", whose value can be customised; for example to run 121 | "glibtoolize" rather than "libtoolize" we do: 122 | 123 | $ LIBTOOLIZE=glibtoolize sh autogen.sh 124 | 125 | After this the procedure is the same as the one for building from a 126 | proper release tarball, but we have to enable maintainer mode: 127 | 128 | $ ../configure --enable-maintainer-mode [options] 129 | $ make 130 | $ make check 131 | $ make install 132 | 133 | 134 | 4. Usage 135 | -------- 136 | 137 | Read the documentation. 138 | 139 | 140 | A. Credits 141 | ---------- 142 | 143 | RE2 is a Google project. CRE2 is based on code by Keegan McAllister. 144 | This distribution was assembled by Marco Maggi. 145 | 146 | Matthew Hall (https://github.com/megahall) contributed miscellaneous 147 | fixes. 148 | 149 | Maksym Melnychok (https://github.com/keymone) contributed a fix for 150 | wrong usage of variable-length arrays. 151 | 152 | afiaux (https://github.com/afiaux) contributed the RE2:Set() 153 | interface. 154 | 155 | Guillaume Massé (https://github.com/MasseGuillaume) contributed fixes 156 | and the implementation of "cre2_find_named_capturing_groups()". 157 | 158 | Will Speak (https://github.com/iwillspeak) contributed the 159 | implementation of the named capturing --> groups iterator. 160 | 161 | 162 | B. Bugs, vulnerabilities and contributions 163 | ------------------------------------------ 164 | 165 | Bug and vulnerability reports are appreciated, all the vulnerability 166 | reports are public; register them at the Issue Tracker at the project's 167 | Github site. For contributions and patches please use the Pull Requests 168 | feature at the project's Github site. 169 | 170 | 171 | C. Resources 172 | ------------ 173 | 174 | RE2 is available at: 175 | 176 | 177 | 178 | and there exists a repackaging under the GNU Autotools in the 179 | repository: 180 | 181 | 182 | 183 | in the branch "autotools.marcomaggi-2016-02-15". 184 | 185 | The latest release of this package can be downloaded from: 186 | 187 | 188 | 189 | development takes place at: 190 | 191 | 192 | 193 | and as backup at: 194 | 195 | 196 | 197 | the documentation is available online: 198 | 199 | 200 | 201 | the GNU Project software can be found here: 202 | 203 | 204 | 205 | 206 | D. Installing re2 and its dependencies 207 | -------------------------------------- 208 | 209 | This may be a challenge, depending on how much of a cmake connoisseur we 210 | are. 211 | 212 | In general, we have to remember that: if we install both the shared 213 | and the static libraries: when compiling with common command line 214 | options, the static libraries will take precedence. This package is 215 | meant to be used with shared libraries, but it should work fine with 216 | static libraries, too. 217 | 218 | Let's suppose we want to install all the packages under the directory 219 | "/opt/re2/2024-07-02"; on a Unix system, we will need to put in some 220 | profile configuration file something like: 221 | 222 | RE2_PREFIX=/opt/re2/2024-07-02 223 | RE2_LIBDIR=${RE2_PREFIX}/lib64 224 | export LD_LIBRARY_PATH=${RE2_LIBDIR}:$LD_LIBRARY_PATH 225 | export PKG_CONFIG_PATH=${RE2_LIBDIR}/pkgconfig:$PKG_CONFIG_PATH 226 | 227 | as a first attempt: no other search path should be upgraded, let's leave 228 | to the packages to find include files and everything else. 229 | 230 | When configuring, building and installing the prerequisite package 231 | "abseil" we should follow the instructions in its README file; but here 232 | is a hint to configure the package to build shared libraries: 233 | 234 | $ cmake . \ 235 | --install-prefix "$RE2_PREFIX" \ 236 | -DCMAKE_BUILD_TYPE=RelWithDebInfo \ 237 | -DCMAKE_CXX_FLAGS:STRING="-fPIC" \ 238 | -DCMAKE_CXX_STANDARD=17 \ 239 | -DBUILD_SHARED_LIBS=ON \ 240 | -DCMAKE_BUILD_TYPE=Release \ 241 | -DABSL_PROPAGATE_CXX_STD=ON 242 | 243 | When configuring, building and installing the prerequisite package 244 | "googletest" we should follow the instructions in its README file; but 245 | here is a hint to configure the package to build shared libraries: 246 | 247 | $ cmake . \ 248 | --install-prefix "$RE2_PREFIX" \ 249 | -DBUILD_SHARED_LIBS=ON \ 250 | -DCMAKE_CXX_FLAGS:STRING="-fPIC" 251 | 252 | When configuring, building and installing the package "re2" itself we 253 | should follow the instructions in its README file; but here is a hint to 254 | configure the package to build shared libraries: 255 | 256 | $ cmake . \ 257 | --install-prefix "$RE2_PREFIX" \ 258 | -DBUILD_SHARED_LIBS=ON \ 259 | -DCMAKE_CXX_FLAGS:STRING="-fPIC" \ 260 | -DCMAKE_BUILD_TYPE=Release 261 | 262 | ### end of file 263 | # Local Variables: 264 | # mode: text 265 | # fill-column: 72 266 | # paragraph-start: "*" 267 | # End: 268 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marcomaggi/cre2/fe0f44803244af9f5cb9fd50045ddfdfd36e7784/README.md -------------------------------------------------------------------------------- /acinclude.m4: -------------------------------------------------------------------------------- 1 | # acinclude.m4 -- 2 | # 3 | 4 | m4_include(meta/autoconf/mmux-core.m4) 5 | m4_include(meta/autoconf/mmux-check-pkg-config-macros.m4) 6 | m4_include(meta/autoconf/mmux-check-target-os.m4) 7 | m4_include(meta/autoconf/mmux-libtool-library-versions.m4) 8 | 9 | m4_include(meta/autoconf/ax-is-release.m4) 10 | m4_include(meta/autoconf/ax-require-defined.m4) 11 | m4_include(meta/autoconf/ax-check-compile-flag.m4) 12 | m4_include(meta/autoconf/ax-check-link-flag.m4) 13 | m4_include(meta/autoconf/ax-append-flag.m4) 14 | m4_include(meta/autoconf/ax-append-compile-flags.m4) 15 | m4_include(meta/autoconf/ax-append-link-flags.m4) 16 | m4_include(meta/autoconf/ax-gcc-version.m4) 17 | m4_include(meta/autoconf/ax-cxx-compile-stdcxx.m4) 18 | m4_include(meta/autoconf/ax-cxx-compile-stdcxx-11.m4) 19 | m4_include(meta/autoconf/ax-pthread.m4) 20 | 21 | m4_include(meta/autoconf/mmux-lang-c99.m4) 22 | m4_include(meta/autoconf/mmux-lang-cxx11.m4) 23 | m4_include(meta/autoconf/mmux-check-page-size.m4) 24 | m4_include(meta/autoconf/mmux-check-page-shift.m4) 25 | m4_include(meta/autoconf/mmux-determine-sizeof.m4) 26 | m4_include(meta/autoconf/mmux-c-headers-includes.m4) 27 | m4_include(meta/autoconf/mmux-pkg-config-find-include-file.m4) 28 | 29 | m4_include(meta/autoconf/mmux-check-re2.m4) 30 | 31 | ### end of file 32 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # autogen.sh -- 3 | # 4 | # Run this in the top source directory to rebuild the infrastructure. 5 | 6 | LIBTOOLIZE=${LIBTOOLIZE:=libtoolize} 7 | 8 | set -xe 9 | test -d meta/autotools || mkdir -p meta/autotools 10 | test -f meta/autotools/libtool.m4 || "$LIBTOOLIZE" 11 | autoreconf --warnings=all --install --verbose "$@" 12 | 13 | ### end of file 14 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "tests" # ignore test folder and all its contents 3 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # @configure_input@ 2 | # 3 | 4 | AC_PREREQ([2.68]) 5 | MMUX_PKG_VERSIONS([0],[4],[0],[devel.2]) 6 | AC_INIT([CRE2],[MMUX_PACKAGE_VERSION],[mrc.mgg@gmail.com], 7 | [cre2],[http://github.com/marcomaggi/cre2/]) 8 | MMUX_INIT 9 | MMUX_LIBTOOL_LIBRARY_VERSIONS([cre2],0,0,0) 10 | AC_REVISION([1.0]) 11 | AC_COPYRIGHT([This license is meant to be the "BSD-3-Clause". 12 | 13 | Copyright (c) 2012, 2013, 2015, 2016, 2017, 2019, 2020, 2024 Marco Maggi 14 | Copyright (c) 2011 Keegan McAllister 15 | All rights reserved. 16 | 17 | Redistribution and use in source and binary forms, with or without modification, 18 | are permitted provided that the following conditions are met: 19 | 20 | 1. Redistributions of source code must retain the above copyright notice, this 21 | list of conditions and the following disclaimer. 22 | 23 | 2. Redistributions in binary form must reproduce the above copyright notice, 24 | this list of conditions and the following disclaimer in the documentation 25 | and/or other materials provided with the distribution. 26 | 27 | 3. Neither the name of the author nor the names of his contributors may be used 28 | to endorse or promote products derived from this software without specific 29 | prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 32 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 34 | DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY 35 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 36 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 37 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 38 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 40 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | ]) 42 | AC_CONFIG_SRCDIR([src/]) 43 | AC_CONFIG_MACRO_DIR([meta/autotools]) 44 | AC_CONFIG_AUX_DIR([meta/autotools]) 45 | AC_CANONICAL_BUILD 46 | AC_CANONICAL_HOST 47 | AC_CANONICAL_TARGET 48 | AM_INIT_AUTOMAKE([1.16 foreign subdir-objects]) 49 | AM_MAINTAINER_MODE 50 | 51 | AM_PROG_AR 52 | AC_PROG_INSTALL 53 | AC_PROG_LN_S 54 | AC_PROG_MAKE_SET 55 | AC_PROG_MKDIR_P 56 | 57 | LT_PREREQ([2.4]) 58 | LT_INIT 59 | 60 | 61 | #### basic system inspection 62 | 63 | MMUX_CHECK_TARGET_OS 64 | AX_IS_RELEASE([git-directory]) 65 | 66 | AC_LANG([C]) 67 | MMUX_LANG_C99 68 | AC_PROG_CC_C_O 69 | 70 | AC_LANG([C++]) 71 | AC_PROG_CXX 72 | MMUX_LANG_CXX11 73 | AC_PROG_CXX_C_O 74 | 75 | 76 | #### external libraries 77 | 78 | PKG_PREREQ([0.29]) 79 | PKG_INSTALLDIR 80 | 81 | AX_PTHREAD 82 | 83 | # This defines RE2_LIBS and RE2_CFLAGS. 84 | PKG_CHECK_MODULES([RE2],[re2]) 85 | 86 | AC_CACHE_SAVE 87 | 88 | 89 | #### finish 90 | 91 | AC_CONFIG_HEADERS([config.h]) 92 | AC_CONFIG_FILES([Makefile] 93 | [meta/scripts/cre2.pc]) 94 | MMUX_OUTPUT 95 | AC_OUTPUT 96 | 97 | ### end of file 98 | -------------------------------------------------------------------------------- /configure.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # configure.sh -- 3 | # 4 | 5 | set -ex 6 | 7 | prefix=${prefix:=/opt/re2/2024-07-02/shared} 8 | export PKG_CONFIG_PATH=${prefix}/lib64/pkgconfig:${PKG_CONFIG_PATH} 9 | if test -d /lib64 10 | then libdir=${prefix}/lib64 11 | else libdir=${prefix}/lib 12 | fi 13 | 14 | CC='/usr/bin/gcc' 15 | CXX='/usr/bin/g++' 16 | 17 | ../configure \ 18 | --config-cache \ 19 | --cache-file=./config.cache \ 20 | --enable-maintainer-mode \ 21 | --disable-static --enable-shared \ 22 | --prefix="$prefix" \ 23 | --libdir="$libdir" \ 24 | CC=$CC \ 25 | CXX=$CXX \ 26 | CFLAGS='-O3' \ 27 | CXXFLAGS='-O3' \ 28 | "$@" 29 | 30 | ### end of file 31 | -------------------------------------------------------------------------------- /doc/cre2.style.css: -------------------------------------------------------------------------------- 1 | /* weblog.css */ 2 | 3 | body { 4 | max-width: 25cm; 5 | margin: 0; 6 | padding: 0; 7 | margin-top: 1.5em; 8 | margin-left: 3em; 9 | margin-right: 3em; 10 | background: #E1F0C4; 11 | text-align: justify; 12 | font-family: Times, Helvetica, Arial, sans-serif; 13 | font-size: large; 14 | /* color: #909B78; */ 15 | color: #606B48; 16 | } 17 | 18 | /* code { */ 19 | /* font-size: large; */ 20 | /* } */ 21 | 22 | samp { 23 | font-size: large; 24 | } 25 | 26 | /* h2 code { */ 27 | /* font-size: xx-large; */ 28 | /* } */ 29 | 30 | /* h3 code { */ 31 | /* font-size: xx-large; */ 32 | /* } */ 33 | 34 | .example { 35 | font-size: large; 36 | } 37 | 38 | ACRONYM { 39 | font-variant: small-caps; 40 | } 41 | 42 | /* end of file */ 43 | -------------------------------------------------------------------------------- /doc/macros.texi: -------------------------------------------------------------------------------- 1 | @c ------------------------------------------------------------ 2 | @c Macros. 3 | @c ------------------------------------------------------------ 4 | 5 | @macro version{} 6 | @value{VERSION} 7 | @end macro 8 | 9 | @macro gnu{} 10 | @acronym{GNU} 11 | @end macro 12 | 13 | @macro gpl{} 14 | @acronym{GPL} 15 | @end macro 16 | 17 | @macro lgpl{} 18 | @acronym{LGPL} 19 | @end macro 20 | 21 | @macro fdl{} 22 | @acronym{FDL} 23 | @end macro 24 | 25 | 26 | @c page 27 | @c ------------------------------------------------------------ 28 | @c Special notes. 29 | @c ------------------------------------------------------------ 30 | 31 | @macro forunix{} 32 | @strong{Unix:} 33 | @end macro 34 | 35 | @macro fixme{TEXT} 36 | @strong{FIXME: \TEXT\} 37 | @end macro 38 | 39 | @c page 40 | @c ------------------------------------------------------------ 41 | @c Miscellaneous acronyms. 42 | @c ------------------------------------------------------------ 43 | 44 | @c *** KEEP ALPHABETIC ORDER *** 45 | 46 | @macro acpi{} 47 | @acronym{ACPI} 48 | @end macro 49 | 50 | @macro alsa{} 51 | @acronym{ALSA} 52 | @end macro 53 | 54 | @macro adsl{} 55 | @acronym{ADSL} 56 | @end macro 57 | 58 | @macro ansi{} 59 | @acronym{ANSI} 60 | @end macro 61 | 62 | @macro api{} 63 | @acronym{API} 64 | @end macro 65 | 66 | @macro ascii{} 67 | @acronym{ASCII} 68 | @end macro 69 | 70 | @macro asciiz{} 71 | @acronym{ASCIIZ} 72 | @end macro 73 | 74 | @c Remember that @url is already used by Texinfo. 75 | @macro aurl{} 76 | @acronym{URL} 77 | @end macro 78 | 79 | @c Remember that @xml is already used by Texinfo. 80 | @macro axml{} 81 | @acronym{XML} 82 | @end macro 83 | 84 | @c ------------------------------------------------------------ 85 | 86 | @macro cdrom{} 87 | @acronym{CDROM} 88 | @end macro 89 | 90 | @macro cli{} 91 | @acronym{CLI} 92 | @end macro 93 | 94 | @macro cpu{} 95 | @acronym{CPU} 96 | @end macro 97 | 98 | @macro csv{} 99 | @acronym{CSV} 100 | @end macro 101 | 102 | @c ------------------------------------------------------------ 103 | 104 | @macro dhcp{} 105 | @acronym{DHCP} 106 | @end macro 107 | 108 | @macro dns{} 109 | @acronym{DNS} 110 | @end macro 111 | 112 | @macro dtd{} 113 | @acronym{DTD} 114 | @end macro 115 | 116 | @c ------------------------------------------------------------ 117 | 118 | @macro eof{} 119 | @acronym{EOF} 120 | @end macro 121 | 122 | @c ------------------------------------------------------------ 123 | 124 | @macro ffi{} 125 | @acronym{FFI} 126 | @end macro 127 | 128 | @macro fifo{} 129 | @acronym{FIFO} 130 | @end macro 131 | 132 | @macro ftp{} 133 | @acronym{FTP} 134 | @end macro 135 | 136 | @c ------------------------------------------------------------ 137 | 138 | @macro git{} 139 | @acronym{GIT} 140 | @end macro 141 | 142 | @c ------------------------------------------------------------ 143 | 144 | @macro http{} 145 | @acronym{HTTP} 146 | @end macro 147 | 148 | @c ------------------------------------------------------------ 149 | 150 | @macro ieee{} 151 | @acronym{IEEE} 152 | @end macro 153 | 154 | @macro imap{} 155 | @acronym{IMAP} 156 | @end macro 157 | 158 | @macro ip{} 159 | @acronym{IP} 160 | @end macro 161 | 162 | @macro iso{} 163 | @acronym{ISO} 164 | @end macro 165 | 166 | @macro isp{} 167 | @acronym{ISP} 168 | @end macro 169 | 170 | @c ------------------------------------------------------------ 171 | 172 | @macro mime{} 173 | @acronym{MIME} 174 | @end macro 175 | 176 | @macro mpeg{} 177 | @acronym{MPEG} 178 | @end macro 179 | 180 | @c ------------------------------------------------------------ 181 | 182 | @macro oob{} 183 | @acronym{OOB} 184 | @end macro 185 | 186 | @macro os{} 187 | @acronym{OS} 188 | @end macro 189 | 190 | @c ------------------------------------------------------------ 191 | 192 | @macro posix{} 193 | @acronym{POSIX} 194 | @end macro 195 | 196 | @macro ppp{} 197 | @acronym{PPP} 198 | @end macro 199 | 200 | @c ------------------------------------------------------------ 201 | 202 | @macro rfc{} 203 | @acronym{RFC} 204 | @end macro 205 | 206 | @c ------------------------------------------------------------ 207 | 208 | @macro sftp{} 209 | @acronym{SFTP} 210 | @end macro 211 | 212 | @macro smtp{} 213 | @acronym{SMTP} 214 | @end macro 215 | 216 | @macro snmp{} 217 | @acronym{SNMP} 218 | @end macro 219 | 220 | @macro sql{} 221 | @acronym{SQL} 222 | @end macro 223 | 224 | @macro ssh{} 225 | @acronym{SSH} 226 | @end macro 227 | 228 | @macro ssl{} 229 | @acronym{SSL} 230 | @end macro 231 | 232 | @c ------------------------------------------------------------ 233 | 234 | @macro tai{} 235 | @acronym{TAI} 236 | @end macro 237 | 238 | @macro tcp{} 239 | @acronym{TCP} 240 | @end macro 241 | 242 | @macro tls{} 243 | @acronym{TLS} 244 | @end macro 245 | 246 | @c ------------------------------------------------------------ 247 | 248 | @macro udp{} 249 | @acronym{UDP} 250 | @end macro 251 | 252 | @macro utf{} 253 | @acronym{UTF} 254 | @end macro 255 | 256 | @macro utc{} 257 | @acronym{UTC} 258 | @end macro 259 | 260 | @macro uri{} 261 | @acronym{URI} 262 | @end macro 263 | 264 | @macro urldate{DATE} 265 | (@acronym{URL} last verified \DATE\) 266 | @end macro 267 | 268 | @macro usb{} 269 | @acronym{USB} 270 | @end macro 271 | 272 | @c ------------------------------------------------------------ 273 | 274 | @macro vlc{} 275 | @acronym{VLC} 276 | @end macro 277 | 278 | @c ------------------------------------------------------------ 279 | 280 | 281 | 282 | @c page 283 | @c ------------------------------------------------------------ 284 | @c Software acronyms. 285 | @c ------------------------------------------------------------ 286 | 287 | @macro bash{} 288 | @command{bash} 289 | @end macro 290 | 291 | @macro bub{} 292 | @acronym{bub} 293 | @end macro 294 | 295 | @macro ffmpeg{} 296 | @acronym{FFMPEG} 297 | @end macro 298 | 299 | @macro gpg{} 300 | @acronym{GPG} 301 | @end macro 302 | 303 | @macro gmp{} 304 | @acronym{GMP} 305 | @end macro 306 | 307 | @macro gcc{} 308 | @acronym{GCC} 309 | @end macro 310 | 311 | @macro cretwo{} 312 | @acronym{CRE2} 313 | @end macro 314 | 315 | @macro retwo{} 316 | @acronym{RE2} 317 | @end macro 318 | 319 | @c ------------------------------------------------------------------------ 320 | 321 | @ifhtml 322 | @macro uid{} 323 | @acronym{uid} 324 | @end macro 325 | @end ifhtml 326 | 327 | @ifnothtml 328 | @macro uid{} 329 | @acronym{UID} 330 | @end macro 331 | @end ifnothtml 332 | 333 | @c ------------------------------------------------------------------------ 334 | 335 | @ifhtml 336 | @macro gid{} 337 | @acronym{gid} 338 | @end macro 339 | @end ifhtml 340 | 341 | @ifnothtml 342 | @macro gid{} 343 | @acronym{GID} 344 | @end macro 345 | @end ifnothtml 346 | 347 | @c page 348 | @c ------------------------------------------------------------ 349 | @c Scheme language macros. 350 | @c ------------------------------------------------------------ 351 | 352 | @c *** KEEP ALPHABETIC ORDER *** 353 | 354 | @macro aclass{NAME} 355 | <\NAME\> 356 | @end macro 357 | 358 | @c Separating the @srfi{} macro from the number with a '--' rather than 359 | @c a '-' makes the expansion look ugly in menu entries under the Info 360 | @c reader. IMHO this should not happen, but it does; so we live with 361 | @c this, because the main purpose of this document is to provide an Info 362 | @c version. 363 | @macro ansrfi{NUM} 364 | @srfi{}-\NUM\ 365 | @end macro 366 | 367 | @c ------------------------------------------------------------ 368 | 369 | @macro cclass{NAME} 370 | <\NAME\> 371 | @end macro 372 | 373 | @macro class{NAME} 374 | @code{<\NAME\>} 375 | @end macro 376 | 377 | @macro clos{} 378 | @acronym{CLOS} 379 | @end macro 380 | 381 | @macro condition{NAME} 382 | @code{&\NAME\} 383 | @end macro 384 | 385 | @c ------------------------------------------------------------ 386 | 387 | @macro false{} 388 | @code{#f} 389 | @end macro 390 | 391 | @macro func{NAME} 392 | @code{\NAME\} 393 | @end macro 394 | 395 | @c ------------------------------------------------------------ 396 | 397 | @macro keyword{NAME} 398 | @code{#:\NAME\} 399 | @end macro 400 | 401 | @c ------------------------------------------------------------ 402 | 403 | @macro library{SPEC} 404 | @code{(\SPEC\)} 405 | @end macro 406 | 407 | @c ------------------------------------------------------------ 408 | 409 | @macro nil{} 410 | @acronym{NIL} 411 | @end macro 412 | 413 | @c ------------------------------------------------------------ 414 | 415 | @macro objtype{NAME} 416 | @code{\NAME\} 417 | @end macro 418 | 419 | @c ------------------------------------------------------------ 420 | 421 | @macro repl{} 422 | @acronym{REPL} 423 | @end macro 424 | 425 | @macro rnrs{VERSION} 426 | @acronym{R\VERSION\RS} 427 | @end macro 428 | 429 | @macro rtd{} 430 | @acronym{RTD} 431 | @end macro 432 | 433 | @macro rsix{} 434 | Revised^6 Report on the algorithmic language Scheme 435 | @end macro 436 | 437 | @c ------------------------------------------------------------ 438 | 439 | @macro true{} 440 | @code{#t} 441 | @end macro 442 | 443 | @c ------------------------------------------------------------ 444 | 445 | @macro snull{} 446 | @code{()} 447 | @end macro 448 | 449 | @macro srfi{} 450 | @acronym{SRFI} 451 | @end macro 452 | 453 | @c page 454 | @c ------------------------------------------------------------ 455 | @c C language macros. 456 | @c ------------------------------------------------------------ 457 | 458 | @macro cfunc{NAME} 459 | @code{\NAME\()} 460 | @end macro 461 | 462 | @macro cnull{} 463 | @code{NULL} 464 | @end macro 465 | 466 | @macro ctrue{} 467 | @code{true} 468 | @end macro 469 | 470 | @macro cfalse{} 471 | @code{false} 472 | @end macro 473 | 474 | @macro struct{} 475 | @code{struct} 476 | @end macro 477 | 478 | @macro method{NAME} 479 | @cfunc{\NAME\} 480 | @end macro 481 | 482 | @macro iface{NAME} 483 | @code{\NAME\} 484 | @end macro 485 | 486 | @macro trait{NAME} 487 | @code{\NAME\} 488 | @end macro 489 | 490 | @macro stdin{} 491 | @code{stdin} 492 | @end macro 493 | 494 | @macro stdout{} 495 | @code{stdout} 496 | @end macro 497 | 498 | @macro stderr{} 499 | @code{stderr} 500 | @end macro 501 | 502 | @c page 503 | @c ------------------------------------------------------------ 504 | @c Macros for references to external documents. 505 | @c ------------------------------------------------------------ 506 | 507 | @macro glibcref{NODE, TITLE} 508 | @ref{\NODE\,\TITLE\,\TITLE\,libc} 509 | @end macro 510 | 511 | @c @macro rsixref{NODE, TITLE} 512 | @c @ref{\NODE\,\TITLE\,\TITLE\,r6rs} 513 | @c @end macro 514 | 515 | @macro bibref{TAG} 516 | @code{[\TAG\]} 517 | @end macro 518 | 519 | @macro autoconfref{NODE, TITLE} 520 | @ref{\NODE\,\TITLE\,\TITLE\,autoconf} 521 | @end macro 522 | 523 | @macro ccexceptionsref{NODE, TITLE} 524 | @ref{\NODE\,\TITLE\,\TITLE\,ccexceptions} 525 | @end macro 526 | 527 | @macro ccmemoryref{NODE, TITLE} 528 | @ref{\NODE\,\TITLE\,\TITLE\,ccmemory} 529 | @end macro 530 | 531 | @macro ccstructsref{NODE, TITLE} 532 | @ref{\NODE\,\TITLE\,\TITLE\,ccstructs} 533 | @end macro 534 | 535 | @macro ccstringsref{NODE, TITLE} 536 | @ref{\NODE\,\TITLE\,\TITLE\,ccstrings} 537 | @end macro 538 | 539 | @macro manpage{NODE, TITLE} 540 | @ref{\NODE\,\TITLE\,\TITLE\,*manpages*} 541 | @end macro 542 | 543 | @c page 544 | @c ------------------------------------------------------------ 545 | @c RNRS document macros. 546 | @c ------------------------------------------------------------ 547 | 548 | @macro rsixlibrary{THING} 549 | @code{(rnrs \THING\ (6))} 550 | @end macro 551 | 552 | @c The following macro does not work. It appears that it is not 553 | @c possible to use "@cindex" in the expansion of a macro because the DVI 554 | @c output will not work. Texinfo output would work, though. Tested 555 | @c with "texi2dvi" version 1.135 (GNU Texinfo 4.13). 556 | @c 557 | @c @macro cindexRsixlibrary{THING} 558 | @c @cindex @rsixlibrary{\THING\}, library 559 | @c @cindex Library, @rsixlibrary{\THING\} 560 | @c @end macro 561 | 562 | @macro arbno{THING} 563 | \THING\* 564 | @end macro 565 | 566 | @macro atleastone{THING} 567 | \THING\+ 568 | @end macro 569 | 570 | @c ------------------------------------------------------------ 571 | @c To be used in normal text. 572 | 573 | @macro meta{THING} 574 | <\THING\> 575 | @end macro 576 | 577 | @macro metao{THING} 578 | <\THING\0> 579 | @end macro 580 | 581 | @macro metai{THING} 582 | <\THING\1> 583 | @end macro 584 | 585 | @macro metaii{THING} 586 | <\THING\2> 587 | @end macro 588 | 589 | @macro metaiii{THING} 590 | <\THING\3> 591 | @end macro 592 | 593 | @macro metan{THING} 594 | <\THING\N> 595 | @end macro 596 | 597 | @macro metani{THING} 598 | <\THING\N+1> 599 | @end macro 600 | 601 | @c ------------------------------------------------------------ 602 | @c To be used inside @example environment and @samp directives. 603 | 604 | @macro cmeta{THING} 605 | <\THING\> 606 | @end macro 607 | 608 | @macro cmetao{THING} 609 | <\THING\0> 610 | @end macro 611 | 612 | @macro cmetai{THING} 613 | <\THING\1> 614 | @end macro 615 | 616 | @macro cmetaii{THING} 617 | <\THING\2> 618 | @end macro 619 | 620 | @macro cmetaiii{THING} 621 | <\THING\3> 622 | @end macro 623 | 624 | @macro cmetan{THING} 625 | <\THING\N> 626 | @end macro 627 | 628 | @macro cmetani{THING} 629 | <\THING\N+1> 630 | @end macro 631 | 632 | @c ------------------------------------------------------------ 633 | @c To be used inside argument lists. 634 | 635 | @macro ameta{THING} 636 | <\THING\> 637 | @end macro 638 | 639 | @macro ametao{THING} 640 | <\THING\0> 641 | @end macro 642 | 643 | @macro ametai{THING} 644 | <\THING\1> 645 | @end macro 646 | 647 | @macro ametaii{THING} 648 | <\THING\2> 649 | @end macro 650 | 651 | @macro ametaiii{THING} 652 | <\THING\3> 653 | @end macro 654 | 655 | @macro ametan{THING} 656 | <\THING\N> 657 | @end macro 658 | 659 | @macro ametani{THING} 660 | <\THING\N+1> 661 | @end macro 662 | 663 | @c ------------------------------------------------------------ 664 | 665 | @macro hyper{THING} 666 | <\THING\> 667 | @end macro 668 | 669 | @macro hyperi{THING} 670 | <\THING\1> 671 | @end macro 672 | 673 | @macro hyperii{THING} 674 | <\THING\2> 675 | @end macro 676 | 677 | @macro hyperiii{THING} 678 | <\THING\3> 679 | @end macro 680 | 681 | @macro hypern{THING} 682 | <\THING\n> 683 | @end macro 684 | 685 | @c ------------------------------------------------------------ 686 | 687 | @macro varo{THING} 688 | @var{\THING\0} 689 | @end macro 690 | 691 | @macro vari{THING} 692 | @var{\THING\1} 693 | @end macro 694 | 695 | @macro varii{THING} 696 | @var{\THING\2} 697 | @end macro 698 | 699 | @macro variii{THING} 700 | @var{\THING\3} 701 | @end macro 702 | 703 | @macro variv{THING} 704 | @var{\THING\4} 705 | @end macro 706 | 707 | @macro varn{THING} 708 | @var{\THING\n} 709 | @end macro 710 | 711 | @macro vark{THING} 712 | @var{\THING\k} 713 | @end macro 714 | 715 | @macro varj{THING} 716 | @var{\THING\j} 717 | @end macro 718 | 719 | @c ------------------------------------------------------------ 720 | 721 | @macro void{} 722 | @code{#} 723 | @end macro 724 | 725 | 726 | @macro eol{} 727 | @acronym{EOL} 728 | @end macro 729 | 730 | @c page 731 | @c ------------------------------------------------------------ 732 | @c Vicare specific macros. 733 | @c ------------------------------------------------------------ 734 | 735 | @macro cif{} 736 | @acronym{CIF} 737 | @end macro 738 | 739 | @macro fasl{} 740 | @acronym{FASL} 741 | @end macro 742 | 743 | @macro ikptr{} 744 | @code{ikptr} 745 | @end macro 746 | 747 | @macro pcb{} 748 | @acronym{PCB} 749 | @end macro 750 | 751 | 752 | @c Local Variables: 753 | @c mode: texinfo 754 | @c TeX-master: t 755 | @c End: 756 | -------------------------------------------------------------------------------- /doc/overview-linking.texi: -------------------------------------------------------------------------------- 1 | @node overview linking 2 | @section Linking code with the library 3 | 4 | 5 | This package installs a data file for @command{pkg-config}, so when searching for the installed 6 | library with the @gnu{} Autotools, we can add the following macro use to @file{configure.ac}: 7 | 8 | @example 9 | PKG_CHECK_MODULES([@value{PackageAutoconfPrefix}],[@value{PackagePkgconfigModule} >= 0.1.0]) 10 | @end example 11 | 12 | @noindent 13 | which will set the variables @value{PackageLibsVar} and @value{PackageCflagsVar}. The macros for 14 | @gnu{} Autoconf installed by @code{pkg-config} are documented in the manual page 15 | @code{pkg-config(1)}. To avoid problems with @command{pkg-config}, we need to remember that: 16 | 17 | @itemize 18 | @item 19 | The macro file defining @code{PKG_CHECK_MODULES} is installed by the package @code{pkg-config}; such 20 | file usually is in one of the locations: 21 | 22 | @center @file{/usr/share/aclocal/pkg.m4} 23 | @center @file{/usr/local/share/aclocal/pkg.m4} 24 | 25 | @item 26 | The macro file is located by @command{aclocal}, which in turn is installed by the package @gnu{} 27 | Automake; @command{aclocal} is used by @command{autoreconf}. We must make sure that 28 | @command{aclocal} finds all the installed macro files; for this purpose we can use the environment 29 | variable @env{ACLOCAL_PATH}. To include all the common possible directories, we can add the 30 | following chunk of Bourne shell code to our shell profile file: 31 | 32 | @smallexample 33 | ACLOCAL_PATH= 34 | for dir in \ 35 | /share/aclocal \ 36 | /usr/share/aclocal \ 37 | /usr/local/share/aclocal 38 | do 39 | if test -d "$dir" 40 | then 41 | if test -n "$ACLOCAL_PATH" 42 | then ACLOCAL_PATH=$@{dir@}:$@{ACLOCAL_PATH@} 43 | else ACLOCAL_PATH=$@{dir@} 44 | fi 45 | fi 46 | done 47 | export ACLOCAL_PATH 48 | @end smallexample 49 | 50 | @item 51 | The executable @command{pkg-config} searches for the package data files in a set of directories; we 52 | can configure the search path with the environment variable @env{PKG_CONFIG_PATH}. To include all 53 | the common possible directories, we can add the following chunk of Bourne shell code to our shell 54 | profile file: 55 | 56 | @example 57 | PKG_CONFIG_PATH= 58 | for dir in \ 59 | /lib/pkgconfig \ 60 | /lib64/pkgconfig \ 61 | /share/pkgconfig \ 62 | /usr/lib/pkgconfig \ 63 | /usr/lib64/pkgconfig \ 64 | /usr/share/pkgconfig \ 65 | /usr/local/lib/pkgconfig \ 66 | /usr/local/lib64/pkgconfig \ 67 | /usr/local/share/pkgconfig 68 | do 69 | if test -d "$dir" 70 | then 71 | if test -n "$PKG_CONFIG_PATH" 72 | then PKG_CONFIG_PATH=$@{dir@}:$@{PKG_CONFIG_PATH@} 73 | else PKG_CONFIG_PATH=$@{dir@} 74 | fi 75 | fi 76 | done 77 | export PKG_CONFIG_PATH 78 | @end example 79 | 80 | @end itemize 81 | 82 | Alternatively we can use the raw @gnu{} Autoconf macros: 83 | 84 | @example 85 | AC_CHECK_LIB([@value{PackageLibstem}],[@value{PackageApiPrefixLower}version_string],, 86 | [AC_MSG_FAILURE([test for @value{TITLE} library failed])]) 87 | AC_CHECK_HEADERS([@value{PackageHeader}],, 88 | [AC_MSG_FAILURE([test for @value{TITLE} header failed])]) 89 | @end example 90 | 91 | @c Local Variables: 92 | @c mode: texinfo 93 | @c End: 94 | -------------------------------------------------------------------------------- /meta/autoconf/ax-append-compile-flags.m4: -------------------------------------------------------------------------------- 1 | # ============================================================================ 2 | # https://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html 3 | # ============================================================================ 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # For every FLAG1, FLAG2 it is checked whether the compiler works with the 12 | # flag. If it does, the flag is added FLAGS-VARIABLE 13 | # 14 | # If FLAGS-VARIABLE is not specified, the current language's flags (e.g. 15 | # CFLAGS) is used. During the check the flag is always added to the 16 | # current language's flags. 17 | # 18 | # If EXTRA-FLAGS is defined, it is added to the current language's default 19 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 20 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 21 | # force the compiler to issue an error when a bad flag is given. 22 | # 23 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 24 | # 25 | # NOTE: This macro depends on the AX_APPEND_FLAG and 26 | # AX_CHECK_COMPILE_FLAG. Please keep this macro in sync with 27 | # AX_APPEND_LINK_FLAGS. 28 | # 29 | # LICENSE 30 | # 31 | # Copyright (c) 2011 Maarten Bosmans 32 | # 33 | # Copying and distribution of this file, with or without modification, are 34 | # permitted in any medium without royalty provided the copyright notice 35 | # and this notice are preserved. This file is offered as-is, without any 36 | # warranty. 37 | 38 | #serial 7 39 | 40 | AC_DEFUN([AX_APPEND_COMPILE_FLAGS], 41 | [AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) 42 | AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) 43 | for flag in $1; do 44 | AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3], [$4]) 45 | done 46 | ])dnl AX_APPEND_COMPILE_FLAGS 47 | -------------------------------------------------------------------------------- /meta/autoconf/ax-append-flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_append_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # FLAG is appended to the FLAGS-VARIABLE shell variable, with a space 12 | # added in between. 13 | # 14 | # If FLAGS-VARIABLE is not specified, the current language's flags (e.g. 15 | # CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains 16 | # FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly 17 | # FLAG. 18 | # 19 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. 20 | # 21 | # LICENSE 22 | # 23 | # Copyright (c) 2008 Guido U. Draheim 24 | # Copyright (c) 2011 Maarten Bosmans 25 | # 26 | # Copying and distribution of this file, with or without modification, are 27 | # permitted in any medium without royalty provided the copyright notice 28 | # and this notice are preserved. This file is offered as-is, without any 29 | # warranty. 30 | 31 | #serial 8 32 | 33 | AC_DEFUN([AX_APPEND_FLAG], 34 | [dnl 35 | AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF 36 | AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])]) 37 | AS_VAR_SET_IF(FLAGS,[ 38 | AS_CASE([" AS_VAR_GET(FLAGS) "], 39 | [*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])], 40 | [ 41 | AS_VAR_APPEND(FLAGS,[" $1"]) 42 | AC_RUN_LOG([: FLAGS="$FLAGS"]) 43 | ]) 44 | ], 45 | [ 46 | AS_VAR_SET(FLAGS,[$1]) 47 | AC_RUN_LOG([: FLAGS="$FLAGS"]) 48 | ]) 49 | AS_VAR_POPDEF([FLAGS])dnl 50 | ])dnl AX_APPEND_FLAG 51 | -------------------------------------------------------------------------------- /meta/autoconf/ax-append-link-flags.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_append_link_flags.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_APPEND_LINK_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # For every FLAG1, FLAG2 it is checked whether the linker works with the 12 | # flag. If it does, the flag is added FLAGS-VARIABLE 13 | # 14 | # If FLAGS-VARIABLE is not specified, the linker's flags (LDFLAGS) is 15 | # used. During the check the flag is always added to the linker's flags. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the linker's default flags 18 | # when the check is done. The check is thus made with the flags: "LDFLAGS 19 | # EXTRA-FLAGS FLAG". This can for example be used to force the linker to 20 | # issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: This macro depends on the AX_APPEND_FLAG and AX_CHECK_LINK_FLAG. 25 | # Please keep this macro in sync with AX_APPEND_COMPILE_FLAGS. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2011 Maarten Bosmans 30 | # 31 | # Copying and distribution of this file, with or without modification, are 32 | # permitted in any medium without royalty provided the copyright notice 33 | # and this notice are preserved. This file is offered as-is, without any 34 | # warranty. 35 | 36 | #serial 7 37 | 38 | AC_DEFUN([AX_APPEND_LINK_FLAGS], 39 | [AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 40 | AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) 41 | for flag in $1; do 42 | AX_CHECK_LINK_FLAG([$flag], [AX_APPEND_FLAG([$flag], [m4_default([$2], [LDFLAGS])])], [], [$3], [$4]) 43 | done 44 | ])dnl AX_APPEND_LINK_FLAGS 45 | -------------------------------------------------------------------------------- /meta/autoconf/ax-check-compile-flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # This program is free software: you can redistribute it and/or modify it 33 | # under the terms of the GNU General Public License as published by the 34 | # Free Software Foundation, either version 3 of the License, or (at your 35 | # option) any later version. 36 | # 37 | # This program is distributed in the hope that it will be useful, but 38 | # WITHOUT ANY WARRANTY; without even the implied warranty of 39 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 40 | # Public License for more details. 41 | # 42 | # You should have received a copy of the GNU General Public License along 43 | # with this program. If not, see . 44 | # 45 | # As a special exception, the respective Autoconf Macro's copyright owner 46 | # gives unlimited permission to copy, distribute and modify the configure 47 | # scripts that are the output of Autoconf when processing the Macro. You 48 | # need not follow the terms of the GNU General Public License when using 49 | # or distributing such scripts, even though portions of the text of the 50 | # Macro appear in them. The GNU General Public License (GPL) does govern 51 | # all other use of the material that constitutes the Autoconf Macro. 52 | # 53 | # This special exception to the GPL applies to versions of the Autoconf 54 | # Macro released by the Autoconf Archive. When you make and distribute a 55 | # modified version of the Autoconf Macro, you may extend this special 56 | # exception to the GPL to apply to your modified version as well. 57 | 58 | #serial 4 59 | 60 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 61 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 62 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 63 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 64 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 65 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 66 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 67 | [AS_VAR_SET(CACHEVAR,[yes])], 68 | [AS_VAR_SET(CACHEVAR,[no])]) 69 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 70 | AS_VAR_IF(CACHEVAR,yes, 71 | [m4_default([$2], :)], 72 | [m4_default([$3], :)]) 73 | AS_VAR_POPDEF([CACHEVAR])dnl 74 | ])dnl AX_CHECK_COMPILE_FLAGS 75 | -------------------------------------------------------------------------------- /meta/autoconf/ax-check-link-flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the linker or gives an error. 12 | # (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the linker's default flags 18 | # when the check is done. The check is thus made with the flags: "LDFLAGS 19 | # EXTRA-FLAGS FLAG". This can for example be used to force the linker to 20 | # issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_LINK_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # Copying and distribution of this file, with or without modification, are 33 | # permitted in any medium without royalty provided the copyright notice 34 | # and this notice are preserved. This file is offered as-is, without any 35 | # warranty. 36 | 37 | #serial 6 38 | 39 | AC_DEFUN([AX_CHECK_LINK_FLAG], 40 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 41 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl 42 | AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [ 43 | ax_check_save_flags=$LDFLAGS 44 | LDFLAGS="$LDFLAGS $4 $1" 45 | AC_LINK_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 46 | [AS_VAR_SET(CACHEVAR,[yes])], 47 | [AS_VAR_SET(CACHEVAR,[no])]) 48 | LDFLAGS=$ax_check_save_flags]) 49 | AS_VAR_IF(CACHEVAR,yes, 50 | [m4_default([$2], :)], 51 | [m4_default([$3], :)]) 52 | AS_VAR_POPDEF([CACHEVAR])dnl 53 | ])dnl AX_CHECK_LINK_FLAGS 54 | -------------------------------------------------------------------------------- /meta/autoconf/ax-cxx-compile-stdcxx-11.m4: -------------------------------------------------------------------------------- 1 | # ============================================================================ 2 | # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html 3 | # ============================================================================ 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check for baseline language coverage in the compiler for the C++11 12 | # standard; if necessary, add switches to CXX and CXXCPP to enable 13 | # support. 14 | # 15 | # This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX 16 | # macro with the version set to C++11. The two optional arguments are 17 | # forwarded literally as the second and third argument respectively. 18 | # Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for 19 | # more information. If you want to use this macro, you also need to 20 | # download the ax_cxx_compile_stdcxx.m4 file. 21 | # 22 | # LICENSE 23 | # 24 | # Copyright (c) 2008 Benjamin Kosnik 25 | # Copyright (c) 2012 Zack Weinberg 26 | # Copyright (c) 2013 Roy Stogner 27 | # Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov 28 | # Copyright (c) 2015 Paul Norman 29 | # Copyright (c) 2015 Moritz Klammler 30 | # 31 | # Copying and distribution of this file, with or without modification, are 32 | # permitted in any medium without royalty provided the copyright notice 33 | # and this notice are preserved. This file is offered as-is, without any 34 | # warranty. 35 | 36 | #serial 17 37 | 38 | AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) 39 | AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])]) 40 | -------------------------------------------------------------------------------- /meta/autoconf/ax-cxx-compile-stdcxx.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check for baseline language coverage in the compiler for the specified 12 | # version of the C++ standard. If necessary, add switches to CXX and 13 | # CXXCPP to enable support. VERSION may be '11' (for the C++11 standard) 14 | # or '14' (for the C++14 standard). 15 | # 16 | # The second argument, if specified, indicates whether you insist on an 17 | # extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. 18 | # -std=c++11). If neither is specified, you get whatever works, with 19 | # preference for an extended mode. 20 | # 21 | # The third argument, if specified 'mandatory' or if left unspecified, 22 | # indicates that baseline support for the specified C++ standard is 23 | # required and that the macro should error out if no mode with that 24 | # support is found. If specified 'optional', then configuration proceeds 25 | # regardless, after defining HAVE_CXX${VERSION} if and only if a 26 | # supporting mode is found. 27 | # 28 | # LICENSE 29 | # 30 | # Copyright (c) 2008 Benjamin Kosnik 31 | # Copyright (c) 2012 Zack Weinberg 32 | # Copyright (c) 2013 Roy Stogner 33 | # Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov 34 | # Copyright (c) 2015 Paul Norman 35 | # Copyright (c) 2015 Moritz Klammler 36 | # 37 | # Copying and distribution of this file, with or without modification, are 38 | # permitted in any medium without royalty provided the copyright notice 39 | # and this notice are preserved. This file is offered as-is, without any 40 | # warranty. 41 | 42 | #serial 4 43 | 44 | dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro 45 | dnl (serial version number 13). 46 | 47 | AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl 48 | m4_if([$1], [11], [], 49 | [$1], [14], [], 50 | [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])], 51 | [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl 52 | m4_if([$2], [], [], 53 | [$2], [ext], [], 54 | [$2], [noext], [], 55 | [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl 56 | m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], 57 | [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], 58 | [$3], [optional], [ax_cxx_compile_cxx$1_required=false], 59 | [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) 60 | AC_LANG_PUSH([C++])dnl 61 | ac_success=no 62 | AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, 63 | ax_cv_cxx_compile_cxx$1, 64 | [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], 65 | [ax_cv_cxx_compile_cxx$1=yes], 66 | [ax_cv_cxx_compile_cxx$1=no])]) 67 | if test x$ax_cv_cxx_compile_cxx$1 = xyes; then 68 | ac_success=yes 69 | fi 70 | 71 | m4_if([$2], [noext], [], [dnl 72 | if test x$ac_success = xno; then 73 | for switch in -std=gnu++$1 -std=gnu++0x; do 74 | cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) 75 | AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, 76 | $cachevar, 77 | [ac_save_CXX="$CXX" 78 | CXX="$CXX $switch" 79 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], 80 | [eval $cachevar=yes], 81 | [eval $cachevar=no]) 82 | CXX="$ac_save_CXX"]) 83 | if eval test x\$$cachevar = xyes; then 84 | CXX="$CXX $switch" 85 | if test -n "$CXXCPP" ; then 86 | CXXCPP="$CXXCPP $switch" 87 | fi 88 | ac_success=yes 89 | break 90 | fi 91 | done 92 | fi]) 93 | 94 | m4_if([$2], [ext], [], [dnl 95 | if test x$ac_success = xno; then 96 | dnl HP's aCC needs +std=c++11 according to: 97 | dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf 98 | dnl Cray's crayCC needs "-h std=c++11" 99 | for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do 100 | cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) 101 | AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, 102 | $cachevar, 103 | [ac_save_CXX="$CXX" 104 | CXX="$CXX $switch" 105 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], 106 | [eval $cachevar=yes], 107 | [eval $cachevar=no]) 108 | CXX="$ac_save_CXX"]) 109 | if eval test x\$$cachevar = xyes; then 110 | CXX="$CXX $switch" 111 | if test -n "$CXXCPP" ; then 112 | CXXCPP="$CXXCPP $switch" 113 | fi 114 | ac_success=yes 115 | break 116 | fi 117 | done 118 | fi]) 119 | AC_LANG_POP([C++]) 120 | if test x$ax_cxx_compile_cxx$1_required = xtrue; then 121 | if test x$ac_success = xno; then 122 | AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) 123 | fi 124 | fi 125 | if test x$ac_success = xno; then 126 | HAVE_CXX$1=0 127 | AC_MSG_NOTICE([No compiler with C++$1 support was found]) 128 | else 129 | HAVE_CXX$1=1 130 | AC_DEFINE(HAVE_CXX$1,1, 131 | [define if the compiler supports basic C++$1 syntax]) 132 | fi 133 | AC_SUBST(HAVE_CXX$1) 134 | ]) 135 | 136 | 137 | dnl Test body for checking C++11 support 138 | 139 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], 140 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 141 | ) 142 | 143 | 144 | dnl Test body for checking C++14 support 145 | 146 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], 147 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 148 | _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 149 | ) 150 | 151 | 152 | dnl Tests for new features in C++11 153 | 154 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ 155 | 156 | // If the compiler admits that it is not ready for C++11, why torture it? 157 | // Hopefully, this will speed up the test. 158 | 159 | #ifndef __cplusplus 160 | 161 | #error "This is not a C++ compiler" 162 | 163 | #elif __cplusplus < 201103L 164 | 165 | #error "This is not a C++11 compiler" 166 | 167 | #else 168 | 169 | namespace cxx11 170 | { 171 | 172 | namespace test_static_assert 173 | { 174 | 175 | template 176 | struct check 177 | { 178 | static_assert(sizeof(int) <= sizeof(T), "not big enough"); 179 | }; 180 | 181 | } 182 | 183 | namespace test_final_override 184 | { 185 | 186 | struct Base 187 | { 188 | virtual void f() {} 189 | }; 190 | 191 | struct Derived : public Base 192 | { 193 | virtual void f() override {} 194 | }; 195 | 196 | } 197 | 198 | namespace test_double_right_angle_brackets 199 | { 200 | 201 | template < typename T > 202 | struct check {}; 203 | 204 | typedef check single_type; 205 | typedef check> double_type; 206 | typedef check>> triple_type; 207 | typedef check>>> quadruple_type; 208 | 209 | } 210 | 211 | namespace test_decltype 212 | { 213 | 214 | int 215 | f() 216 | { 217 | int a = 1; 218 | decltype(a) b = 2; 219 | return a + b; 220 | } 221 | 222 | } 223 | 224 | namespace test_type_deduction 225 | { 226 | 227 | template < typename T1, typename T2 > 228 | struct is_same 229 | { 230 | static const bool value = false; 231 | }; 232 | 233 | template < typename T > 234 | struct is_same 235 | { 236 | static const bool value = true; 237 | }; 238 | 239 | template < typename T1, typename T2 > 240 | auto 241 | add(T1 a1, T2 a2) -> decltype(a1 + a2) 242 | { 243 | return a1 + a2; 244 | } 245 | 246 | int 247 | test(const int c, volatile int v) 248 | { 249 | static_assert(is_same::value == true, ""); 250 | static_assert(is_same::value == false, ""); 251 | static_assert(is_same::value == false, ""); 252 | auto ac = c; 253 | auto av = v; 254 | auto sumi = ac + av + 'x'; 255 | auto sumf = ac + av + 1.0; 256 | static_assert(is_same::value == true, ""); 257 | static_assert(is_same::value == true, ""); 258 | static_assert(is_same::value == true, ""); 259 | static_assert(is_same::value == false, ""); 260 | static_assert(is_same::value == true, ""); 261 | return (sumf > 0.0) ? sumi : add(c, v); 262 | } 263 | 264 | } 265 | 266 | namespace test_noexcept 267 | { 268 | 269 | int f() { return 0; } 270 | int g() noexcept { return 0; } 271 | 272 | static_assert(noexcept(f()) == false, ""); 273 | static_assert(noexcept(g()) == true, ""); 274 | 275 | } 276 | 277 | namespace test_constexpr 278 | { 279 | 280 | template < typename CharT > 281 | unsigned long constexpr 282 | strlen_c_r(const CharT *const s, const unsigned long acc) noexcept 283 | { 284 | return *s ? strlen_c_r(s + 1, acc + 1) : acc; 285 | } 286 | 287 | template < typename CharT > 288 | unsigned long constexpr 289 | strlen_c(const CharT *const s) noexcept 290 | { 291 | return strlen_c_r(s, 0UL); 292 | } 293 | 294 | static_assert(strlen_c("") == 0UL, ""); 295 | static_assert(strlen_c("1") == 1UL, ""); 296 | static_assert(strlen_c("example") == 7UL, ""); 297 | static_assert(strlen_c("another\0example") == 7UL, ""); 298 | 299 | } 300 | 301 | namespace test_rvalue_references 302 | { 303 | 304 | template < int N > 305 | struct answer 306 | { 307 | static constexpr int value = N; 308 | }; 309 | 310 | answer<1> f(int&) { return answer<1>(); } 311 | answer<2> f(const int&) { return answer<2>(); } 312 | answer<3> f(int&&) { return answer<3>(); } 313 | 314 | void 315 | test() 316 | { 317 | int i = 0; 318 | const int c = 0; 319 | static_assert(decltype(f(i))::value == 1, ""); 320 | static_assert(decltype(f(c))::value == 2, ""); 321 | static_assert(decltype(f(0))::value == 3, ""); 322 | } 323 | 324 | } 325 | 326 | namespace test_uniform_initialization 327 | { 328 | 329 | struct test 330 | { 331 | static const int zero {}; 332 | static const int one {1}; 333 | }; 334 | 335 | static_assert(test::zero == 0, ""); 336 | static_assert(test::one == 1, ""); 337 | 338 | } 339 | 340 | namespace test_lambdas 341 | { 342 | 343 | void 344 | test1() 345 | { 346 | auto lambda1 = [](){}; 347 | auto lambda2 = lambda1; 348 | lambda1(); 349 | lambda2(); 350 | } 351 | 352 | int 353 | test2() 354 | { 355 | auto a = [](int i, int j){ return i + j; }(1, 2); 356 | auto b = []() -> int { return '0'; }(); 357 | auto c = [=](){ return a + b; }(); 358 | auto d = [&](){ return c; }(); 359 | auto e = [a, &b](int x) mutable { 360 | const auto identity = [](int y){ return y; }; 361 | for (auto i = 0; i < a; ++i) 362 | a += b--; 363 | return x + identity(a + b); 364 | }(0); 365 | return a + b + c + d + e; 366 | } 367 | 368 | int 369 | test3() 370 | { 371 | const auto nullary = [](){ return 0; }; 372 | const auto unary = [](int x){ return x; }; 373 | using nullary_t = decltype(nullary); 374 | using unary_t = decltype(unary); 375 | const auto higher1st = [](nullary_t f){ return f(); }; 376 | const auto higher2nd = [unary](nullary_t f1){ 377 | return [unary, f1](unary_t f2){ return f2(unary(f1())); }; 378 | }; 379 | return higher1st(nullary) + higher2nd(nullary)(unary); 380 | } 381 | 382 | } 383 | 384 | namespace test_variadic_templates 385 | { 386 | 387 | template 388 | struct sum; 389 | 390 | template 391 | struct sum 392 | { 393 | static constexpr auto value = N0 + sum::value; 394 | }; 395 | 396 | template <> 397 | struct sum<> 398 | { 399 | static constexpr auto value = 0; 400 | }; 401 | 402 | static_assert(sum<>::value == 0, ""); 403 | static_assert(sum<1>::value == 1, ""); 404 | static_assert(sum<23>::value == 23, ""); 405 | static_assert(sum<1, 2>::value == 3, ""); 406 | static_assert(sum<5, 5, 11>::value == 21, ""); 407 | static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); 408 | 409 | } 410 | 411 | // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae 412 | // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function 413 | // because of this. 414 | namespace test_template_alias_sfinae 415 | { 416 | 417 | struct foo {}; 418 | 419 | template 420 | using member = typename T::member_type; 421 | 422 | template 423 | void func(...) {} 424 | 425 | template 426 | void func(member*) {} 427 | 428 | void test(); 429 | 430 | void test() { func(0); } 431 | 432 | } 433 | 434 | } // namespace cxx11 435 | 436 | #endif // __cplusplus >= 201103L 437 | 438 | ]]) 439 | 440 | 441 | dnl Tests for new features in C++14 442 | 443 | m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ 444 | 445 | // If the compiler admits that it is not ready for C++14, why torture it? 446 | // Hopefully, this will speed up the test. 447 | 448 | #ifndef __cplusplus 449 | 450 | #error "This is not a C++ compiler" 451 | 452 | #elif __cplusplus < 201402L 453 | 454 | #error "This is not a C++14 compiler" 455 | 456 | #else 457 | 458 | namespace cxx14 459 | { 460 | 461 | namespace test_polymorphic_lambdas 462 | { 463 | 464 | int 465 | test() 466 | { 467 | const auto lambda = [](auto&&... args){ 468 | const auto istiny = [](auto x){ 469 | return (sizeof(x) == 1UL) ? 1 : 0; 470 | }; 471 | const int aretiny[] = { istiny(args)... }; 472 | return aretiny[0]; 473 | }; 474 | return lambda(1, 1L, 1.0f, '1'); 475 | } 476 | 477 | } 478 | 479 | namespace test_binary_literals 480 | { 481 | 482 | constexpr auto ivii = 0b0000000000101010; 483 | static_assert(ivii == 42, "wrong value"); 484 | 485 | } 486 | 487 | namespace test_generalized_constexpr 488 | { 489 | 490 | template < typename CharT > 491 | constexpr unsigned long 492 | strlen_c(const CharT *const s) noexcept 493 | { 494 | auto length = 0UL; 495 | for (auto p = s; *p; ++p) 496 | ++length; 497 | return length; 498 | } 499 | 500 | static_assert(strlen_c("") == 0UL, ""); 501 | static_assert(strlen_c("x") == 1UL, ""); 502 | static_assert(strlen_c("test") == 4UL, ""); 503 | static_assert(strlen_c("another\0test") == 7UL, ""); 504 | 505 | } 506 | 507 | namespace test_lambda_init_capture 508 | { 509 | 510 | int 511 | test() 512 | { 513 | auto x = 0; 514 | const auto lambda1 = [a = x](int b){ return a + b; }; 515 | const auto lambda2 = [a = lambda1(x)](){ return a; }; 516 | return lambda2(); 517 | } 518 | 519 | } 520 | 521 | namespace test_digit_seperators 522 | { 523 | 524 | constexpr auto ten_million = 100'000'000; 525 | static_assert(ten_million == 100000000, ""); 526 | 527 | } 528 | 529 | namespace test_return_type_deduction 530 | { 531 | 532 | auto f(int& x) { return x; } 533 | decltype(auto) g(int& x) { return x; } 534 | 535 | template < typename T1, typename T2 > 536 | struct is_same 537 | { 538 | static constexpr auto value = false; 539 | }; 540 | 541 | template < typename T > 542 | struct is_same 543 | { 544 | static constexpr auto value = true; 545 | }; 546 | 547 | int 548 | test() 549 | { 550 | auto x = 0; 551 | static_assert(is_same::value, ""); 552 | static_assert(is_same::value, ""); 553 | return x; 554 | } 555 | 556 | } 557 | 558 | } // namespace cxx14 559 | 560 | #endif // __cplusplus >= 201402L 561 | 562 | ]]) 563 | -------------------------------------------------------------------------------- /meta/autoconf/ax-gcc-version.m4: -------------------------------------------------------------------------------- 1 | dnl This macro was taken on Oct 5, 2017 from: 2 | dnl 3 | dnl 4 | dnl 5 | dnl and modified a bit. 6 | 7 | dnl AX_GCC_VERSION 8 | dnl 9 | dnl Takes no arguments. If the shell variable "GCC" is set to "yes", 10 | dnl this macro defines: 11 | dnl 12 | dnl - the cached shell variable "ax_cv_gcc_version"; 13 | dnl 14 | dnl - the shell variable "GCC_VERSION"; 15 | dnl 16 | dnl - the substitution for the symbol "GCC_VERSION"; 17 | dnl 18 | dnl the value of such variables and substitution is the version number 19 | dnl of "gcc". 20 | dnl 21 | AC_DEFUN([AX_GCC_VERSION], 22 | [AS_VAR_SET(GCC_VERSION,[$ax_cv_gcc_version]) 23 | AS_IF([test "x$GCC" = "xyes"], 24 | [AC_CACHE_CHECK([GCC version number],[ax_cv_gcc_version], 25 | [AS_VAR_SET(ax_cv_gcc_version,["`$CC -dumpversion`"]) 26 | AS_IF([test "x$ax_cv_gcc_version" = "x"], 27 | [AS_VAR_SET(ax_cv_gcc_version)]) 28 | AS_VAR_SET(GCC_VERSION,[$ax_cv_gcc_version])])]) 29 | AC_SUBST([GCC_VERSION])]) 30 | 31 | dnl end of file 32 | dnl Local Variables: 33 | dnl mode: autoconf 34 | dnl End: 35 | -------------------------------------------------------------------------------- /meta/autoconf/ax-is-release.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_is_release.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_IS_RELEASE(POLICY) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Determine whether the code is being configured as a release, or from 12 | # git. Set the ax_is_release variable to 'yes' or 'no'. 13 | # 14 | # If building a release version, it is recommended that the configure 15 | # script disable compiler errors and debug features, by conditionalising 16 | # them on the ax_is_release variable. If building from git, these 17 | # features should be enabled. 18 | # 19 | # The POLICY parameter specifies how ax_is_release is determined. It can 20 | # take the following values: 21 | # 22 | # * git-directory: ax_is_release will be 'no' if a '.git' 23 | # directory or git worktree exists 24 | # * minor-version: ax_is_release will be 'no' if the minor version number 25 | # in $PACKAGE_VERSION is odd; this assumes 26 | # $PACKAGE_VERSION follows the 'major.minor.micro' scheme 27 | # * micro-version: ax_is_release will be 'no' if the micro version number 28 | # in $PACKAGE_VERSION is odd; this assumes 29 | # $PACKAGE_VERSION follows the 'major.minor.micro' scheme 30 | # * dash-version: ax_is_release will be 'no' if there is a dash '-' 31 | # in $PACKAGE_VERSION, for example 1.2-pre3, 1.2.42-a8b9 32 | # or 2.0-dirty (in particular this is suitable for use 33 | # with git-version-gen) 34 | # * always: ax_is_release will always be 'yes' 35 | # * never: ax_is_release will always be 'no' 36 | # 37 | # Other policies may be added in future. 38 | # 39 | # LICENSE 40 | # 41 | # Copyright (c) 2015 Philip Withnall 42 | # Copyright (c) 2016 Collabora Ltd. 43 | # 44 | # Copying and distribution of this file, with or without modification, are 45 | # permitted in any medium without royalty provided the copyright notice 46 | # and this notice are preserved. 47 | 48 | #serial 8 49 | 50 | AC_DEFUN([AX_IS_RELEASE],[ 51 | AC_BEFORE([AC_INIT],[$0]) 52 | 53 | m4_case([$1], 54 | [git-directory],[ 55 | # $is_release = (.git directory does not exist) 56 | AS_IF([test -d ${srcdir}/.git || (test -f ${srcdir}/.git && grep \.git/worktrees ${srcdir}/.git)],[ax_is_release=no],[ax_is_release=yes]) 57 | ], 58 | [minor-version],[ 59 | # $is_release = ($minor_version is even) 60 | minor_version=`echo "$PACKAGE_VERSION" | sed 's/[[^.]][[^.]]*.\([[^.]][[^.]]*\).*/\1/'` 61 | AS_IF([test "$(( $minor_version % 2 ))" -ne 0], 62 | [ax_is_release=no],[ax_is_release=yes]) 63 | ], 64 | [micro-version],[ 65 | # $is_release = ($micro_version is even) 66 | micro_version=`echo "$PACKAGE_VERSION" | sed 's/[[^.]]*\.[[^.]]*\.\([[^.]]*\).*/\1/'` 67 | AS_IF([test "$(( $micro_version % 2 ))" -ne 0], 68 | [ax_is_release=no],[ax_is_release=yes]) 69 | ], 70 | [dash-version],[ 71 | # $is_release = ($PACKAGE_VERSION has a dash) 72 | AS_CASE([$PACKAGE_VERSION], 73 | [*-*], [ax_is_release=no], 74 | [*], [ax_is_release=yes]) 75 | ], 76 | [always],[ax_is_release=yes], 77 | [never],[ax_is_release=no], 78 | [ 79 | AC_MSG_ERROR([Invalid policy. Valid policies: git-directory, minor-version, micro-version, dash-version, always, never.]) 80 | ]) 81 | ]) 82 | -------------------------------------------------------------------------------- /meta/autoconf/ax-pthread.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_pthread.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # This macro figures out how to build C programs using POSIX threads. It 12 | # sets the PTHREAD_LIBS output variable to the threads library and linker 13 | # flags, and the PTHREAD_CFLAGS output variable to any special C compiler 14 | # flags that are needed. (The user can also force certain compiler 15 | # flags/libs to be tested by setting these environment variables.) 16 | # 17 | # Also sets PTHREAD_CC to any special C compiler that is needed for 18 | # multi-threaded programs (defaults to the value of CC otherwise). (This 19 | # is necessary on AIX to use the special cc_r compiler alias.) 20 | # 21 | # NOTE: You are assumed to not only compile your program with these flags, 22 | # but also link it with them as well. e.g. you should link with 23 | # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS 24 | # 25 | # If you are only building threads programs, you may wish to use these 26 | # variables in your default LIBS, CFLAGS, and CC: 27 | # 28 | # LIBS="$PTHREAD_LIBS $LIBS" 29 | # CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 30 | # CC="$PTHREAD_CC" 31 | # 32 | # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant 33 | # has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name 34 | # (e.g. PTHREAD_CREATE_UNDETACHED on AIX). 35 | # 36 | # Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the 37 | # PTHREAD_PRIO_INHERIT symbol is defined when compiling with 38 | # PTHREAD_CFLAGS. 39 | # 40 | # ACTION-IF-FOUND is a list of shell commands to run if a threads library 41 | # is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it 42 | # is not found. If ACTION-IF-FOUND is not specified, the default action 43 | # will define HAVE_PTHREAD. 44 | # 45 | # Please let the authors know if this macro fails on any platform, or if 46 | # you have any other suggestions or comments. This macro was based on work 47 | # by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help 48 | # from M. Frigo), as well as ac_pthread and hb_pthread macros posted by 49 | # Alejandro Forero Cuervo to the autoconf macro repository. We are also 50 | # grateful for the helpful feedback of numerous users. 51 | # 52 | # Updated for Autoconf 2.68 by Daniel Richard G. 53 | # 54 | # LICENSE 55 | # 56 | # Copyright (c) 2008 Steven G. Johnson 57 | # Copyright (c) 2011 Daniel Richard G. 58 | # 59 | # This program is free software: you can redistribute it and/or modify it 60 | # under the terms of the GNU General Public License as published by the 61 | # Free Software Foundation, either version 3 of the License, or (at your 62 | # option) any later version. 63 | # 64 | # This program is distributed in the hope that it will be useful, but 65 | # WITHOUT ANY WARRANTY; without even the implied warranty of 66 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 67 | # Public License for more details. 68 | # 69 | # You should have received a copy of the GNU General Public License along 70 | # with this program. If not, see . 71 | # 72 | # As a special exception, the respective Autoconf Macro's copyright owner 73 | # gives unlimited permission to copy, distribute and modify the configure 74 | # scripts that are the output of Autoconf when processing the Macro. You 75 | # need not follow the terms of the GNU General Public License when using 76 | # or distributing such scripts, even though portions of the text of the 77 | # Macro appear in them. The GNU General Public License (GPL) does govern 78 | # all other use of the material that constitutes the Autoconf Macro. 79 | # 80 | # This special exception to the GPL applies to versions of the Autoconf 81 | # Macro released by the Autoconf Archive. When you make and distribute a 82 | # modified version of the Autoconf Macro, you may extend this special 83 | # exception to the GPL to apply to your modified version as well. 84 | 85 | #serial 21 86 | 87 | AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) 88 | AC_DEFUN([AX_PTHREAD], [ 89 | AC_REQUIRE([AC_CANONICAL_HOST]) 90 | AC_LANG_PUSH([C]) 91 | ax_pthread_ok=no 92 | 93 | # We used to check for pthread.h first, but this fails if pthread.h 94 | # requires special compiler flags (e.g. on True64 or Sequent). 95 | # It gets checked for in the link test anyway. 96 | 97 | # First of all, check if the user has set any of the PTHREAD_LIBS, 98 | # etcetera environment variables, and if threads linking works using 99 | # them: 100 | if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then 101 | save_CFLAGS="$CFLAGS" 102 | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 103 | save_LIBS="$LIBS" 104 | LIBS="$PTHREAD_LIBS $LIBS" 105 | AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) 106 | AC_TRY_LINK_FUNC([pthread_join], [ax_pthread_ok=yes]) 107 | AC_MSG_RESULT([$ax_pthread_ok]) 108 | if test x"$ax_pthread_ok" = xno; then 109 | PTHREAD_LIBS="" 110 | PTHREAD_CFLAGS="" 111 | fi 112 | LIBS="$save_LIBS" 113 | CFLAGS="$save_CFLAGS" 114 | fi 115 | 116 | # We must check for the threads library under a number of different 117 | # names; the ordering is very important because some systems 118 | # (e.g. DEC) have both -lpthread and -lpthreads, where one of the 119 | # libraries is broken (non-POSIX). 120 | 121 | # Create a list of thread flags to try. Items starting with a "-" are 122 | # C compiler flags, and other items are library names, except for "none" 123 | # which indicates that we try without any flags at all, and "pthread-config" 124 | # which is a program returning the flags for the Pth emulation library. 125 | 126 | ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" 127 | 128 | # The ordering *is* (sometimes) important. Some notes on the 129 | # individual items follow: 130 | 131 | # pthreads: AIX (must check this before -lpthread) 132 | # none: in case threads are in libc; should be tried before -Kthread and 133 | # other compiler flags to prevent continual compiler warnings 134 | # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) 135 | # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) 136 | # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) 137 | # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) 138 | # -pthreads: Solaris/gcc 139 | # -mthreads: Mingw32/gcc, Lynx/gcc 140 | # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it 141 | # doesn't hurt to check since this sometimes defines pthreads too; 142 | # also defines -D_REENTRANT) 143 | # ... -mt is also the pthreads flag for HP/aCC 144 | # pthread: Linux, etcetera 145 | # --thread-safe: KAI C++ 146 | # pthread-config: use pthread-config program (for GNU Pth library) 147 | 148 | case ${host_os} in 149 | solaris*) 150 | 151 | # On Solaris (at least, for some versions), libc contains stubbed 152 | # (non-functional) versions of the pthreads routines, so link-based 153 | # tests will erroneously succeed. (We need to link with -pthreads/-mt/ 154 | # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather 155 | # a function called by this macro, so we could check for that, but 156 | # who knows whether they'll stub that too in a future libc.) So, 157 | # we'll just look for -pthreads and -lpthread first: 158 | 159 | ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" 160 | ;; 161 | 162 | darwin*) 163 | ax_pthread_flags="-pthread $ax_pthread_flags" 164 | ;; 165 | esac 166 | 167 | # Clang doesn't consider unrecognized options an error unless we specify 168 | # -Werror. We throw in some extra Clang-specific options to ensure that 169 | # this doesn't happen for GCC, which also accepts -Werror. 170 | 171 | AC_MSG_CHECKING([if compiler needs -Werror to reject unknown flags]) 172 | save_CFLAGS="$CFLAGS" 173 | ax_pthread_extra_flags="-Werror" 174 | CFLAGS="$CFLAGS $ax_pthread_extra_flags -Wunknown-warning-option -Wsizeof-array-argument" 175 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int foo(void);],[foo()])], 176 | [AC_MSG_RESULT([yes])], 177 | [ax_pthread_extra_flags= 178 | AC_MSG_RESULT([no])]) 179 | CFLAGS="$save_CFLAGS" 180 | 181 | if test x"$ax_pthread_ok" = xno; then 182 | for flag in $ax_pthread_flags; do 183 | 184 | case $flag in 185 | none) 186 | AC_MSG_CHECKING([whether pthreads work without any flags]) 187 | ;; 188 | 189 | -*) 190 | AC_MSG_CHECKING([whether pthreads work with $flag]) 191 | PTHREAD_CFLAGS="$flag" 192 | ;; 193 | 194 | pthread-config) 195 | AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) 196 | if test x"$ax_pthread_config" = xno; then continue; fi 197 | PTHREAD_CFLAGS="`pthread-config --cflags`" 198 | PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" 199 | ;; 200 | 201 | *) 202 | AC_MSG_CHECKING([for the pthreads library -l$flag]) 203 | PTHREAD_LIBS="-l$flag" 204 | ;; 205 | esac 206 | 207 | save_LIBS="$LIBS" 208 | save_CFLAGS="$CFLAGS" 209 | LIBS="$PTHREAD_LIBS $LIBS" 210 | CFLAGS="$CFLAGS $PTHREAD_CFLAGS $ax_pthread_extra_flags" 211 | 212 | # Check for various functions. We must include pthread.h, 213 | # since some functions may be macros. (On the Sequent, we 214 | # need a special flag -Kthread to make this header compile.) 215 | # We check for pthread_join because it is in -lpthread on IRIX 216 | # while pthread_create is in libc. We check for pthread_attr_init 217 | # due to DEC craziness with -lpthreads. We check for 218 | # pthread_cleanup_push because it is one of the few pthread 219 | # functions on Solaris that doesn't have a non-functional libc stub. 220 | # We try pthread_create on general principles. 221 | AC_LINK_IFELSE([AC_LANG_PROGRAM([#include 222 | static void routine(void *a) { a = 0; } 223 | static void *start_routine(void *a) { return a; }], 224 | [pthread_t th; pthread_attr_t attr; 225 | pthread_create(&th, 0, start_routine, 0); 226 | pthread_join(th, 0); 227 | pthread_attr_init(&attr); 228 | pthread_cleanup_push(routine, 0); 229 | pthread_cleanup_pop(0) /* ; */])], 230 | [ax_pthread_ok=yes], 231 | []) 232 | 233 | LIBS="$save_LIBS" 234 | CFLAGS="$save_CFLAGS" 235 | 236 | AC_MSG_RESULT([$ax_pthread_ok]) 237 | if test "x$ax_pthread_ok" = xyes; then 238 | break; 239 | fi 240 | 241 | PTHREAD_LIBS="" 242 | PTHREAD_CFLAGS="" 243 | done 244 | fi 245 | 246 | # Various other checks: 247 | if test "x$ax_pthread_ok" = xyes; then 248 | save_LIBS="$LIBS" 249 | LIBS="$PTHREAD_LIBS $LIBS" 250 | save_CFLAGS="$CFLAGS" 251 | CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 252 | 253 | # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. 254 | AC_MSG_CHECKING([for joinable pthread attribute]) 255 | attr_name=unknown 256 | for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do 257 | AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], 258 | [int attr = $attr; return attr /* ; */])], 259 | [attr_name=$attr; break], 260 | []) 261 | done 262 | AC_MSG_RESULT([$attr_name]) 263 | if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then 264 | AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], [$attr_name], 265 | [Define to necessary symbol if this constant 266 | uses a non-standard name on your system.]) 267 | fi 268 | 269 | AC_MSG_CHECKING([if more special flags are required for pthreads]) 270 | flag=no 271 | case ${host_os} in 272 | aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";; 273 | osf* | hpux*) flag="-D_REENTRANT";; 274 | solaris*) 275 | if test "$GCC" = "yes"; then 276 | flag="-D_REENTRANT" 277 | else 278 | # TODO: What about Clang on Solaris? 279 | flag="-mt -D_REENTRANT" 280 | fi 281 | ;; 282 | esac 283 | AC_MSG_RESULT([$flag]) 284 | if test "x$flag" != xno; then 285 | PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" 286 | fi 287 | 288 | AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], 289 | [ax_cv_PTHREAD_PRIO_INHERIT], [ 290 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], 291 | [[int i = PTHREAD_PRIO_INHERIT;]])], 292 | [ax_cv_PTHREAD_PRIO_INHERIT=yes], 293 | [ax_cv_PTHREAD_PRIO_INHERIT=no]) 294 | ]) 295 | AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"], 296 | [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])]) 297 | 298 | LIBS="$save_LIBS" 299 | CFLAGS="$save_CFLAGS" 300 | 301 | # More AIX lossage: compile with *_r variant 302 | if test "x$GCC" != xyes; then 303 | case $host_os in 304 | aix*) 305 | AS_CASE(["x/$CC"], 306 | [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], 307 | [#handle absolute path differently from PATH based program lookup 308 | AS_CASE(["x$CC"], 309 | [x/*], 310 | [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])], 311 | [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])]) 312 | ;; 313 | esac 314 | fi 315 | fi 316 | 317 | test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" 318 | 319 | AC_SUBST([PTHREAD_LIBS]) 320 | AC_SUBST([PTHREAD_CFLAGS]) 321 | AC_SUBST([PTHREAD_CC]) 322 | 323 | # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: 324 | if test x"$ax_pthread_ok" = xyes; then 325 | ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) 326 | : 327 | else 328 | ax_pthread_ok=no 329 | $2 330 | fi 331 | AC_LANG_POP 332 | ])dnl AX_PTHREAD 333 | -------------------------------------------------------------------------------- /meta/autoconf/ax-require-defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 2 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-c-headers-includes.m4: -------------------------------------------------------------------------------- 1 | ## mmux-c-headers-includes.m4 -- 2 | # 3 | # Define macros that expand into C preprocessor directives to include 4 | # the most common C language header files. We can use the expansion of 5 | # the macros as "INCLUDES" argument to other macros. 6 | # 7 | 8 | AC_DEFUN([MMUX_INCLUDE_UNISTD_H],[ 9 | #ifdef HAVE_UNISTD_H 10 | # include 11 | #endif 12 | ]) 13 | 14 | AC_DEFUN([MMUX_INCLUDE_ARPA_INET_H],[ 15 | #ifdef HAVE_ARPA_INET_H 16 | # include 17 | #endif 18 | ]) 19 | 20 | AC_DEFUN([MMUX_INCLUDE_DIRENT_H],[ 21 | #ifdef HAVE_DIRENT_H 22 | # include 23 | #endif 24 | ]) 25 | 26 | AC_DEFUN([MMUX_INCLUDE_ERRNO_H],[ 27 | #ifdef HAVE_ERRNO_H 28 | # include 29 | #endif 30 | ]) 31 | 32 | AC_DEFUN([MMUX_INCLUDE_FCNTL_H],[ 33 | #ifdef HAVE_FCNTL_H 34 | # include 35 | #endif 36 | ]) 37 | 38 | AC_DEFUN([MMUX_INCLUDE_GRP_H],[ 39 | #ifdef HAVE_GRP_H 40 | # include 41 | #endif 42 | ]) 43 | 44 | AC_DEFUN([MMUX_INCLUDE_LIMITS_H],[ 45 | #ifdef HAVE_LIMITS_H 46 | # include 47 | #endif 48 | ]) 49 | 50 | AC_DEFUN([MMUX_INCLUDE_LINUX_FS_H],[ 51 | #ifdef HAVE_LINUX_FS_H 52 | # include 53 | #endif 54 | ]) 55 | 56 | AC_DEFUN([MMUX_INCLUDE_NETINET_IN_H],[ 57 | #ifdef HAVE_NETINET_IN_H 58 | # include 59 | #endif 60 | ]) 61 | 62 | AC_DEFUN([MMUX_INCLUDE_NETDB_H],[ 63 | #ifdef HAVE_NETDB_H 64 | # include 65 | #endif 66 | ]) 67 | 68 | AC_DEFUN([MMUX_INCLUDE_PWD_H],[ 69 | #ifdef HAVE_PWD_H 70 | # include 71 | #endif 72 | ]) 73 | 74 | AC_DEFUN([MMUX_INCLUDE_SIGNAL_H],[ 75 | #ifdef HAVE_SIGNAL_H 76 | # include 77 | #endif 78 | ]) 79 | 80 | AC_DEFUN([MMUX_INCLUDE_SYS_SELECT_H],[ 81 | #ifdef HAVE_SYS_SELECT_H 82 | # include 83 | #endif 84 | ]) 85 | 86 | AC_DEFUN([MMUX_INCLUDE_SYS_SOCKET_H],[ 87 | #ifdef HAVE_SYS_SOCKET_H 88 | # include 89 | #endif 90 | ]) 91 | 92 | AC_DEFUN([MMUX_INCLUDE_SYS_SYSCALL_H],[ 93 | #ifdef HAVE_SYS_SYSCALL_H 94 | # include 95 | #endif 96 | ]) 97 | 98 | AC_DEFUN([MMUX_INCLUDE_SYS_UN_H],[ 99 | #ifdef HAVE_SYS_UN_H 100 | # include 101 | #endif 102 | ]) 103 | 104 | AC_DEFUN([MMUX_INCLUDE_STDDEF_H],[ 105 | #ifdef HAVE_STDDEF_H 106 | # include 107 | #endif 108 | ]) 109 | 110 | AC_DEFUN([MMUX_INCLUDE_STDIO_H],[ 111 | #include 112 | ]) 113 | 114 | AC_DEFUN([MMUX_INCLUDE_STDLIB_H],[ 115 | #ifdef HAVE_STDLIB_H 116 | # include 117 | #endif 118 | ]) 119 | 120 | AC_DEFUN([MMUX_INCLUDE_SYS_AUXV_H],[ 121 | #ifdef HAVE_SYS_AUXV_H 122 | # include 123 | #endif 124 | ]) 125 | 126 | AC_DEFUN([MMUX_INCLUDE_SYS_TYPES_H],[ 127 | #ifdef HAVE_SYS_TYPES_H 128 | # include 129 | #endif 130 | ]) 131 | 132 | AC_DEFUN([MMUX_INCLUDE_SYS_MMAN_H],[ 133 | #ifdef HAVE_SYS_MMAN_H 134 | # include 135 | #endif 136 | ]) 137 | 138 | AC_DEFUN([MMUX_INCLUDE_SYS_UIO_H],[ 139 | #ifdef HAVE_SYS_UIO_H 140 | # include 141 | #endif 142 | ]) 143 | 144 | AC_DEFUN([MMUX_INCLUDE_SYS_RESOURCE_H],[ 145 | #ifdef HAVE_SYS_RESOURCE_H 146 | # include 147 | #endif 148 | ]) 149 | 150 | AC_DEFUN([MMUX_INCLUDE_SYS_STAT_H],[ 151 | #ifdef HAVE_SYS_STAT_H 152 | # include 153 | #endif 154 | ]) 155 | 156 | AC_DEFUN([MMUX_INCLUDE_SYS_TIME_H],[ 157 | #ifdef HAVE_SYS_TIME_H 158 | # include 159 | #endif 160 | ]) 161 | 162 | AC_DEFUN([MMUX_INCLUDE_TIME_H],[ 163 | #ifdef HAVE_TIME_H 164 | # include 165 | #endif 166 | ]) 167 | 168 | AC_DEFUN([MMUX_INCLUDE_UNISTD_H],[ 169 | #ifdef HAVE_UNISTD_H 170 | # include 171 | #endif 172 | ]) 173 | 174 | AC_DEFUN([MMUX_INCLUDE_WAIT_H],[ 175 | #ifdef HAVE_WAIT_H 176 | # include 177 | #endif 178 | ]) 179 | 180 | ### end of file 181 | # Local Variables: 182 | # mode: autoconf 183 | # End: 184 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-check-page-shift.m4: -------------------------------------------------------------------------------- 1 | ### mmux-check-page-shift.m4 -- 2 | # 3 | # MMUX_CHECK_PAGE_SHIFT($PAGESIZE) 4 | # 5 | # Determine the number of bits to right-shift a pointer value to obtain 6 | # the index of the page (of size $PAGESIZE) it is in. Defaults to 12 7 | # which is the value for a page size of 4096 bytes. The test assumes 8 | # that the page size is an exact power of 2. 9 | # 10 | # Set to the value: the cached variable "mmux_cv_page_shift"; the 11 | # substitution symbol "MMUX_PAGE_SHIFT"; the preprocessor macro 12 | # "MMUX_PAGE_SHIFT". 13 | # 14 | # Arguments: 15 | # 16 | # $1 - The page size in bytes. This value must have been determined 17 | # with some other test. 18 | # 19 | AC_DEFUN([MMUX_CHECK_PAGE_SHIFT], 20 | [AC_CACHE_CHECK([page shift bit count], 21 | [mmux_cv_page_shift], 22 | [AC_RUN_IFELSE([AC_LANG_SOURCE([ 23 | int main (void) 24 | { 25 | int count=0; 26 | int roller=$1 - 1; 27 | FILE *f = fopen ("conftest.val", "w"); 28 | while (roller) { 29 | ++count; 30 | roller >>= 1; 31 | } 32 | fprintf(f, "%d", count); 33 | return ferror (f) || fclose (f) != 0; 34 | }])], 35 | [AS_VAR_SET([mmux_cv_page_shift],[`cat conftest.val`])], 36 | [AS_VAR_SET([mmux_cv_page_shift],[12])], 37 | dnl This is to allow cross-compilation. 38 | [AS_VAR_SET([mmux_cv_page_shift],[12])]) 39 | rm -f conftest.val], 40 | [AS_VAR_SET([mmux_cv_page_shift],[12])]) 41 | 42 | AC_SUBST([MMUX_PAGE_SHIFT],[$mmux_cv_page_shift]) 43 | AC_DEFINE_UNQUOTED([MMUX_PAGE_SHIFT],[$mmux_cv_page_shift],[Page shift bit count.])]) 44 | 45 | ### end of file 46 | # Local Variables: 47 | # mode: autoconf 48 | # End: 49 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-check-page-size.m4: -------------------------------------------------------------------------------- 1 | ### mm-check-page-size.m4 -- 2 | # 3 | # Inspect the system for the page size. Set to the value: the cached 4 | # variable "mmux_cv_page_size"; the substitution symbol 5 | # "MMUX_PAGE_SIZE"; the preprocessor macro "MMUX_PAGE_SIZE". 6 | # 7 | AC_DEFUN([MMUX_CHECK_PAGE_SIZE], 8 | [AC_CHECK_HEADERS([unistd.h]) 9 | AC_CACHE_CHECK([page size], 10 | [mmux_cv_page_size], 11 | [AC_COMPUTE_INT([mmux_cv_page_size],[sysconf(_SC_PAGE_SIZE)],[ 12 | #ifdef HAVE_UNISTD_H 13 | # include 14 | #endif 15 | ],[AS_VAR_SET([mmux_cv_page_size],[4096])])]) 16 | 17 | AC_SUBST([MMUX_PAGE_SIZE],[$mmux_cv_page_size]) 18 | AC_DEFINE_UNQUOTED([MMUX_PAGE_SIZE],[$mmux_cv_page_size],[Page size bit count.])]) 19 | 20 | ### end of file 21 | # Local Variables: 22 | # mode: autoconf 23 | # End: 24 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-check-pkg-config-macros.m4: -------------------------------------------------------------------------------- 1 | ### mmux-check-pkg-config-macros.m4 -- 2 | # 3 | # Test if the macro PKG_CHECK_MODULES is defined at macro-expansion 4 | # time. This test works only if the file "configure.ac" also contains 5 | # an actual expansion of PKG_CHECK_MODULES. 6 | # 7 | AC_DEFUN([MMUX_CHECK_PKG_CONFIG_MACROS], 8 | [AC_MSG_CHECKING([availability of pkg-config m4 macros]) 9 | AS_IF([test m4_ifdef([PKG_CHECK_MODULES],[yes],[no]) == yes], 10 | [AC_MSG_RESULT([yes])], 11 | [AC_MSG_RESULT([no]) 12 | AC_MSG_ERROR([pkg-config is required. See pkg-config.freedesktop.org])])]) 13 | 14 | ### end of file 15 | # Local Variables: 16 | # mode: autoconf 17 | # End: 18 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-check-re2.m4: -------------------------------------------------------------------------------- 1 | ### mmux-check-re2.m4 -- 2 | # 3 | # MMUX_CHECK_RE2 4 | # 5 | AC_DEFUN([MMUX_CHECK_RE2],[ 6 | AC_REQUIRE([AX_PTHREAD]) 7 | 8 | AC_LANG_PUSH([C++]) 9 | AC_CHECK_HEADERS([re2/re2.h],,[AC_MSG_ERROR([test for re2 header failed])]) 10 | AC_LANG_POP([C++]) 11 | 12 | AC_CACHE_CHECK([for re2 library], 13 | [mmux_cv_re2_libs], 14 | [AC_LANG_PUSH([C++]) 15 | AS_VAR_COPY([my_cre2_saved_cxxflags],[CXXFLAGS]) 16 | AS_VAR_COPY([my_cre2_saved_ldflags],[LDFLAGS]) 17 | AS_VAR_APPEND([CXXFLAGS],[" ${PTHREAD_CFLAGS}"]) 18 | AS_VAR_APPEND([LDFLAGS], [" ${PTHREAD_LIBS} -L${libdir} -lre2"]) 19 | AC_LINK_IFELSE([AC_LANG_PROGRAM([ 20 | #include 21 | #include 22 | ],[ 23 | RE2::Options opt; 24 | opt.set_never_nl(true); 25 | { 26 | RE2 re("ab[cd]+ef", opt); 27 | assert(re.ok()); 28 | assert(RE2::FullMatch("abcddcef", re)); 29 | assert(RE2::PartialMatch("abcddcef123", re)); 30 | } 31 | ])], 32 | [AS_VAR_SET([mmux_cv_re2_libs],["-L${libdir} -lre2"])], 33 | [AC_MSG_ERROR([test for re2 library failed])]) 34 | AS_VAR_COPY([LDFLAGS],[my_cre2_saved_ldflags]) 35 | AS_VAR_COPY([CXXFLAGS],[my_cre2_saved_cxxflags]) 36 | AC_LANG_POP([C++])]) 37 | AC_SUBST([RE2_LIBS],[$mmux_cv_re2_libs]) 38 | ]) 39 | 40 | ### end of file 41 | # Local Variables: 42 | # mode: autoconf 43 | # End: 44 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-check-target-os.m4: -------------------------------------------------------------------------------- 1 | ## mmux-check-target-os.m4 -- 2 | # 3 | # Inspect the value of the variable "target_os" and defines variables, 4 | # substitutions and Automake conditionals according to it. 5 | # 6 | # The following variables, substitutions and preprocessor macros are 7 | # defined: 8 | # 9 | # MMUX_ON_LINUX: set to 1 on a GNU+Linux system, otherwise set to 0. 10 | # 11 | # MMUX_ON_BSD: set to 1 on a BSD system, otherwise set to 0. 12 | # 13 | # MMUX_ON_CYGWIN: set to 1 on a CYGWIN system, otherwise set to 0. 14 | # 15 | # MMUX_ON_DARWIN: set to 1 on a Darwin system, otherwise set to 0. 16 | # 17 | # The following automake conditionals are defined: 18 | # 19 | # ON_LINUX: set to 1 on a GNU+Linux system, otherwise set to 0. 20 | # 21 | # ON_BSD: set to 1 on a BSD system, otherwise set to 0. 22 | # 23 | # ON_CYGWIN: set to 1 on a CYGWIN system, otherwise set to 0. 24 | # 25 | # ON_DARWIN: set to 1 on a Darwin system, otherwise set to 0. 26 | # 27 | 28 | AC_DEFUN([MMUX_CHECK_TARGET_OS], 29 | [AS_VAR_SET([MMUX_ON_LINUX], [0]) 30 | AS_VAR_SET([MMUX_ON_BSD], [0]) 31 | AS_VAR_SET([MMUX_ON_CYGWIN],[0]) 32 | AS_VAR_SET([MMUX_ON_DARWIN],[0]) 33 | 34 | AS_CASE("$target_os", 35 | [*linux*], 36 | [AS_VAR_SET([MMUX_ON_LINUX],[1]) 37 | AC_MSG_NOTICE([detected OS: linux])], 38 | [*bsd*], 39 | [AS_VAR_SET([MMUX_ON_BSD],[1]) 40 | AC_MSG_NOTICE([detected OS: BSD])], 41 | [*cygwin*], 42 | [AS_VAR_SET([MMUX_ON_CYGWIN],[1]) 43 | AC_MSG_NOTICE([detected OS: CYGWIN])], 44 | [*darwin*], 45 | [AS_VAR_SET([MMUX_ON_DARWIN],[1]) 46 | AC_MSG_NOTICE([detected OS: DARWIN])]) 47 | 48 | AM_CONDITIONAL([ON_LINUX], [test "x$MMUX_ON_LINUX" = x1]) 49 | AM_CONDITIONAL([ON_BSD], [test "x$MMUX_ON_BSD" = x1]) 50 | AM_CONDITIONAL([ON_CYGWIN],[test "x$MMUX_ON_CYGWIN" = x1]) 51 | AM_CONDITIONAL([ON_DARWIN],[test "x$MMUX_ON_DARWIN" = x1]) 52 | 53 | AC_SUBST([MMUX_ON_LINUX], [$MMUX_ON_LINUX]) 54 | AC_SUBST([MMUX_ON_BSD], [$MMUX_ON_BSD]) 55 | AC_SUBST([MMUX_ON_CYGWIN],[$MMUX_ON_CYGWIN]) 56 | AC_SUBST([MMUX_ON_DARWIN],[$MMUX_ON_DARWIN]) 57 | 58 | AC_DEFINE_UNQUOTED([MMUX_ON_LINUX], [$MMUX_ON_LINUX], [True if the underlying platform is GNU+Linux]) 59 | AC_DEFINE_UNQUOTED([MMUX_ON_BSD], [$MMUX_ON_BSD], [True if the underlying platform is BSD]) 60 | AC_DEFINE_UNQUOTED([MMUX_ON_CYGWIN],[$MMUX_ON_CYGWIN], [True if the underlying platform is Cygwin]) 61 | AC_DEFINE_UNQUOTED([MMUX_ON_DARWIN],[$MMUX_ON_DARWIN], [True if the underlying platform is Darwin]) 62 | ]) 63 | 64 | ### end of file 65 | # Local Variables: 66 | # mode: autoconf 67 | # End: 68 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-core.m4: -------------------------------------------------------------------------------- 1 | ## mmux-core.m4 -- 2 | # 3 | # Basic definitions for MMUX packages. 4 | # 5 | # LICENSE 6 | # 7 | # Copyright (c) 2018, 2019 Marco Maggi 8 | # 9 | # Copying and distribution of this file, with or without modification, 10 | # are permitted in any medium without royalty provided the copyright 11 | # notice and this notice are preserved. This file is offered as-is, 12 | # without any warranty. 13 | # 14 | 15 | 16 | # SYNOPSIS 17 | # 18 | # MMUX_PKG_VERSIONS([MAJOR_VERSION], [MINOR_VERSION], [PATCH_LEVEL], 19 | # [PRERELEASE_TAG], [BUILD_METADATA]) 20 | # 21 | # DESCRIPTION 22 | # 23 | # Define the appropriate m4 macros used to set various package 24 | # semantic version components. For the definition of semantic 25 | # versioning see: 26 | # 27 | # 28 | # 29 | # This macro is meant to be used right before AC_INIT as: 30 | # 31 | # MMUX_PKG_VERSIONS([MAJOR_VERSION], [MINOR_VERSION], [PATCH_LEVEL], 32 | # [PRERELEASE_TAG], [BUILD_METADATA]) 33 | # AC_INIT(..., MMUX_PACKAGE_VERSION, ...) 34 | # 35 | # the arguments PRERELEASE_TAG and BUILD_METADATA are optional. For 36 | # example: 37 | # 38 | # MMUX_PKG_VERSIONS([0],[1],[0],[devel.0],[x86_64]) 39 | # 40 | # The value of PRERELEASE_TAG must be a string like "devel.0", without 41 | # a leading dash. The value of BUILD_METADATA_TAG must be a string 42 | # like "x86_64", without a leading plus. 43 | # 44 | # This macro defines the following m4 macros: 45 | # 46 | # MMUX_PACKAGE_MAJOR_VERSION: the major version number. 47 | # 48 | # MMUX_PACKAGE_MINOR_VERSION: the minor version number. 49 | # 50 | # MMUX_PACKAGE_PATCH_LEVEL: the patch level number. 51 | # 52 | # MMUX_PACKAGE_PRERELEASE_TAG: the prerelease tag string as 53 | # specified by semantic versioning. 54 | # 55 | # MMUX_PACKAGE_BUILD_METADATA: the build metadata string as 56 | # specified by semantic versioning. 57 | # 58 | # MMUX_PACKAGE_VERSION: the package version string as required by 59 | # AC_INIT; it includes neither the prerelease tag nor the build 60 | # metadata. 61 | # 62 | # MMUX_PACKAGE_SEMANTIC_VERSION: the full semantic version string, 63 | # with a leading "v". 64 | # 65 | # MMUX_PACKAGE_PKG_CONFIG_VERSION: the version number to use in the 66 | # module file for "pkg-config". 67 | # 68 | m4_define([MMUX_PKG_VERSIONS],[ 69 | m4_define([MMUX_PACKAGE_MAJOR_VERSION], [$1]) 70 | m4_define([MMUX_PACKAGE_MINOR_VERSION], [$2]) 71 | m4_define([MMUX_PACKAGE_PATCH_LEVEL], [$3]) 72 | m4_define([MMUX_PACKAGE_PRERELEASE_TAG], [$4]) 73 | m4_define([MMUX_PACKAGE_BUILD_METADATA], [$5]) 74 | 75 | # If a prerelease tag argument is present: define the associated 76 | # component for the PACKAGE_VERSION variable; otherwise define the 77 | # component to the empty string. 78 | # 79 | # Note: "m4_ifval" is an Autoconf macro, see the documentation in the 80 | # node "Programming in M4sugar". 81 | m4_define([MMUX_PACKAGE_VERSION__COMPONENT_PRERELEASE_TAG], 82 | m4_ifval(MMUX_PACKAGE_PRERELEASE_TAG,[-]MMUX_PACKAGE_PRERELEASE_TAG)) 83 | 84 | # If a build metadata argument is present: define the associated 85 | # component for the PACKAGE_VERSION variable; otherwise define the 86 | # component to the empty string. 87 | # 88 | # Note: "m4_ifval" is an Autoconf macro, see the documentation in the 89 | # node "Programming in M4sugar". 90 | m4_define([MMUX_PACKAGE_VERSION__COMPONENT_BUILD_METADATA], 91 | m4_ifval(MMUX_PACKAGE_BUILD_METADATA,[+]MMUX_PACKAGE_BUILD_METADATA)) 92 | 93 | # Result variables. 94 | m4_define([MMUX_PACKAGE_VERSION],MMUX_PACKAGE_MAJOR_VERSION[.]MMUX_PACKAGE_MINOR_VERSION[.]MMUX_PACKAGE_PATCH_LEVEL[]MMUX_PACKAGE_VERSION__COMPONENT_PRERELEASE_TAG) 95 | m4_define([MMUX_PACKAGE_SEMANTIC_VERSION],[v]MMUX_PACKAGE_MAJOR_VERSION[.]MMUX_PACKAGE_MINOR_VERSION[.]MMUX_PACKAGE_PATCH_LEVEL[]MMUX_PACKAGE_VERSION__COMPONENT_PRERELEASE_TAG[]MMUX_PACKAGE_VERSION__COMPONENT_BUILD_METADATA) 96 | m4_define([MMUX_PACKAGE_PKG_CONFIG_VERSION],MMUX_PACKAGE_MAJOR_VERSION[.]MMUX_PACKAGE_MINOR_VERSION[.]MMUX_PACKAGE_PATCH_LEVEL) 97 | ]) 98 | 99 | 100 | # SYNOPSIS 101 | # 102 | # MMUX_INIT 103 | # 104 | # DESCRIPTION 105 | # 106 | # Initialisation code for MMUX macros. 107 | # 108 | AC_DEFUN([MMUX_INIT],[ 109 | AC_MSG_NOTICE([package major version:] MMUX_PACKAGE_MAJOR_VERSION) 110 | AC_MSG_NOTICE([package minor version:] MMUX_PACKAGE_MINOR_VERSION) 111 | AC_MSG_NOTICE([package patch level:] MMUX_PACKAGE_PATCH_LEVEL) 112 | AC_MSG_NOTICE([package prerelease tag:] MMUX_PACKAGE_PRERELEASE_TAG) 113 | AC_MSG_NOTICE([package build metadata:] MMUX_PACKAGE_BUILD_METADATA) 114 | AC_MSG_NOTICE([package version:] MMUX_PACKAGE_VERSION) 115 | AC_MSG_NOTICE([package semantic version:] MMUX_PACKAGE_SEMANTIC_VERSION) 116 | AC_MSG_NOTICE([package pkg-config module version:] MMUX_PACKAGE_PKG_CONFIG_VERSION) 117 | 118 | # This is used to generate TAGS files for the C language. 119 | AS_VAR_SET([MMUX_DEPENDENCIES_INCLUDES]) 120 | ]) 121 | 122 | 123 | # SYNOPSIS 124 | # 125 | # MMUX_OUTPUT 126 | # 127 | # DESCRIPTION 128 | # 129 | # Define what is needed to end the MMUX package preparations. This 130 | # macro is meant to be used right before AC_output, as follows: 131 | # 132 | # MMUX_OUTPUT 133 | # AC_OUTPUT 134 | # 135 | # This macro defines the following substitutions: 136 | # 137 | # MMUX_PKG_CONFIG_VERSION: the version string to be used in the 138 | # module for pkg-config. 139 | # 140 | # SLACKWARE_PACKAGE_VERSION: the version string to be used when 141 | # building a Slackware package file. 142 | # 143 | AC_DEFUN([MMUX_OUTPUT],[ 144 | AC_SUBST([MMUX_PKG_MAJOR_VERSION],MMUX_PACKAGE_MAJOR_VERSION) 145 | AC_SUBST([MMUX_PKG_MINOR_VERSION],MMUX_PACKAGE_MINOR_VERSION) 146 | AC_SUBST([MMUX_PKG_PATCH_LEVEL],MMUX_PACKAGE_PATCH_LEVEL) 147 | AC_SUBST([MMUX_PKG_PRERELEASE_TAG],MMUX_PACKAGE_PRERELEASE_TAG) 148 | AC_SUBST([MMUX_PKG_BUILD_METADATA],MMUX_PACKAGE_BUILD_METADATA) 149 | AC_SUBST([MMUX_PKG_VERSION],MMUX_PACKAGE_VERSION) 150 | AC_SUBST([MMUX_PKG_SEMANTIC_VERSION],MMUX_PACKAGE_SEMANTIC_VERSION) 151 | 152 | # This is the version stored in the pkg-config data file. 153 | AC_SUBST([MMUX_PKG_CONFIG_VERSION],MMUX_PACKAGE_PKG_CONFIG_VERSION) 154 | 155 | # This is the version number to be used when generating Slackware 156 | # packages. 157 | AC_SUBST([SLACKWARE_PACKAGE_VERSION],MMUX_PACKAGE_MAJOR_VERSION[.]MMUX_PACKAGE_MINOR_VERSION[.]MMUX_PACKAGE_PATCH_LEVEL[]MMUX_PACKAGE_PRERELEASE_TAG) 158 | 159 | # This is the build metadata string to be used when generating 160 | # Slackware packages. It should be something like "noarch" or 161 | # "x84_64". 162 | AC_SUBST([SLACKWARE_BUILD_METADATA],MMUX_PACKAGE_BUILD_METADATA) 163 | 164 | # This is used to generate TAGS files for the C language. 165 | AC_SUBST([MMUX_DEPENDENCIES_INCLUDES]) 166 | ]) 167 | 168 | ### end of file 169 | # Local Variables: 170 | # mode: autoconf 171 | # End: 172 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-determine-sizeof.m4: -------------------------------------------------------------------------------- 1 | dnl mmux-determine-sizeof.m4 -- 2 | dnl 3 | dnl MMUX_DETERMINE_SIZEOF(STEM, TYPE, INCLUDES) 4 | dnl 5 | dnl Determine the size in bytes of the C language type TYPE, using the 6 | dnl header files selected by the directives in INCLUDES. 7 | dnl 8 | dnl Define the variable variable "MMUX_SIZEOF_$STEM" and the cached 9 | dnl variable "mmux_cv_sizeof_$STEM" to the number of bytes. 10 | dnl 11 | dnl Define the preprocessor macro "MMUX_SIZEOF_$STEM" to the number of 12 | dnl bytes. 13 | dnl 14 | dnl Example, to determine the size of "size_t": 15 | dnl 16 | dnl MMUX_DETERMINE_SIZEOF([SIZE_T],[size_t],[ 17 | dnl #ifdef HAVE_STDDEF_H 18 | dnl # include 19 | dnl #endif 20 | dnl ]) 21 | dnl 22 | dnl Arguments: 23 | dnl 24 | dnl $1 - A stem used to build variable names. 25 | dnl $2 - The C language type of which we want to determine the size. 26 | dnl $3 - The preprocessor include directives we need to include the required headers. 27 | dnl 28 | AC_DEFUN([MMUX_DETERMINE_SIZEOF], 29 | [AS_VAR_SET([MMUX_SIZEOF_$1],[0]) 30 | AC_CACHE_CHECK([the size of '$2'], 31 | [mmux_cv_sizeof_$1], 32 | [AC_COMPUTE_INT([mmux_cv_sizeof_$1], 33 | [sizeof($2)], 34 | [$3], 35 | [mmux_cv_sizeof_$1=0])]) 36 | AS_VAR_SET([MMUX_SIZEOF_$1],["$mmux_cv_sizeof_$1"]) 37 | AC_DEFINE_UNQUOTED([MMUX_SIZEOF_$1],[$MMUX_SIZEOF_[]$1],[the size of '$2'])]) 38 | 39 | dnl end of file 40 | dnl Local Variables: 41 | dnl mode: autoconf 42 | dnl End: 43 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-lang-c99.m4: -------------------------------------------------------------------------------- 1 | ## mmux-lang-c99.m4 -- 2 | # 3 | # Define the appropriate flags to use the C99 standard language. Such 4 | # flags are appended to the current definition of the variable "CC". 5 | # 6 | # This macro is meant to be used as: 7 | # 8 | # AC_LANG([C]) 9 | # MMUX_LANG_C99 10 | # 11 | # If the variable "GCC" is set to "yes": select additional warning flags 12 | # to be handed to the C compiler. Such flags are appended to the 13 | # variable MMUX_CFLAGS, which is also configured as substitution (and so 14 | # it becomes a Makefile variable). We should use such variable to the 15 | # compile commands as follows, in "Makefile.am": 16 | # 17 | # AM_CFLAGS = $(MMUX_CFLAGS) 18 | # 19 | 20 | AC_DEFUN([MMUX_LANG_C99],[ 21 | AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) 22 | AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS]) 23 | AX_REQUIRE_DEFINED([AX_GCC_VERSION]) 24 | AC_REQUIRE([AX_IS_RELEASE]) 25 | 26 | AC_PROG_CC_C99 27 | 28 | AS_VAR_IF(GCC,'yes', 29 | [AX_GCC_VERSION]) 30 | 31 | AC_SUBST([MMUX_CFLAGS]) 32 | 33 | # These flags are for every compiler. 34 | AS_VAR_IF(ax_is_release,'no', 35 | [AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -pedantic], [MMUX_CFLAGS], [-Werror])]) 36 | 37 | # These flags are for GCC only. 38 | AS_VAR_IF(ax_is_release,'no', 39 | [AS_VAR_IF(GCC,'yes', 40 | [AX_APPEND_COMPILE_FLAGS([-Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict], [MMUX_CFLAGS], [-Werror]) 41 | AX_APPEND_COMPILE_FLAGS([-Wnull-dereference -Wjump-misses-init -Wdouble-promotion -Wshadow], [MMUX_CFLAGS], [-Werror]) 42 | AX_APPEND_COMPILE_FLAGS([-Wformat=2 -Wmisleading-indentation], [MMUX_CFLAGS], [-Werror])])]) 43 | ]) 44 | 45 | ### end of file 46 | # Local Variables: 47 | # mode: autoconf 48 | # End: 49 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-lang-cxx11.m4: -------------------------------------------------------------------------------- 1 | ## mmux-lang-cxx11.m4 -- 2 | # 3 | # Define the appropriate flags to use the C++11 standard language. Such 4 | # flags are appended to the current definition of the variable "CXX". 5 | # 6 | # This macro is meant to be used as: 7 | # 8 | # AC_LANG([C++]) 9 | # AC_PROG_CXX 10 | # MMUX_LANG_CXX11 11 | # AC_PROG_CXX_C_O 12 | # 13 | # If the variable "GCC" is set to "yes": select additional warning flags 14 | # to be handed to the C++ compiler. Such flags are appended to the 15 | # variable MMUX_CXXFLAGS, which is also configured as substitution (and 16 | # so it becomes a Makefile variable). We should use such variable to 17 | # the compile commands as follows, in "Makefile.am": 18 | # 19 | # AM_CXXFLAGS = $(MMUX_CXXFLAGS) 20 | # 21 | 22 | AC_DEFUN([MMUX_LANG_CXX11],[ 23 | AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) 24 | AX_REQUIRE_DEFINED([AX_APPEND_COMPILE_FLAGS]) 25 | AX_REQUIRE_DEFINED([AX_GCC_VERSION]) 26 | AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX_11]) 27 | AC_REQUIRE([AX_IS_RELEASE]) 28 | 29 | AX_CXX_COMPILE_STDCXX_11(noext,mandatory) 30 | 31 | AS_VAR_IF(GCC,'yes', 32 | [AX_GCC_VERSION]) 33 | 34 | AC_SUBST([MMUX_CXXFLAGS]) 35 | 36 | # These flags are for every compiler. 37 | AS_VAR_IF(ax_is_release,'no', 38 | [AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -pedantic], [MMUX_CXXFLAGS], [-Werror]) 39 | AX_APPEND_COMPILE_FLAGS([-Wno-unused-parameter -Wno-missing-field-initializers], [MMUX_CXXFLAGS], [-Werror])]) 40 | 41 | # These flags are for GCC only. 42 | AS_VAR_IF(ax_is_release,'no', 43 | [AS_VAR_IF(GCC,'yes', 44 | [AX_APPEND_COMPILE_FLAGS([-Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wrestrict], [MMUX_CXXFLAGS], [-Werror]) 45 | AX_APPEND_COMPILE_FLAGS([-Wnull-dereference -Wjump-misses-init -Wdouble-promotion -Wshadow], [MMUX_CXXFLAGS], [-Werror]) 46 | AX_APPEND_COMPILE_FLAGS([-Wformat=2 -Wmisleading-indentation], [MMUX_CXXFLAGS], [-Werror])])]) 47 | 48 | ]) 49 | 50 | ### end of file 51 | # Local Variables: 52 | # mode: autoconf 53 | # End: 54 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-libtool-library-versions.m4: -------------------------------------------------------------------------------- 1 | ## mmux-libtool-library-versions.m4 -- 2 | # 3 | # Set version numbers for libraries built with GNU Libtool. 4 | # 5 | # MMUX_LIBTOOL_LIBRARY_VERSIONS(stem,current,revision,age) 6 | # 7 | AC_DEFUN([MMUX_LIBTOOL_LIBRARY_VERSIONS], 8 | [$1_VERSION_INTERFACE_CURRENT=$2 9 | $1_VERSION_INTERFACE_REVISION=$3 10 | $1_VERSION_INTERFACE_AGE=$4 11 | AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_CURRENT], 12 | [$$1_VERSION_INTERFACE_CURRENT], 13 | [current interface number]) 14 | AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_REVISION], 15 | [$$1_VERSION_INTERFACE_REVISION], 16 | [current interface implementation number]) 17 | AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_AGE], 18 | [$$1_VERSION_INTERFACE_AGE], 19 | [current interface age number]) 20 | AC_DEFINE_UNQUOTED([$1_VERSION_INTERFACE_STRING], 21 | ["$$1_VERSION_INTERFACE_CURRENT.$$1_VERSION_INTERFACE_REVISION"], 22 | [library interface version]) 23 | AC_SUBST([$1_VERSION_INTERFACE_CURRENT]) 24 | AC_SUBST([$1_VERSION_INTERFACE_REVISION]) 25 | AC_SUBST([$1_VERSION_INTERFACE_AGE])]) 26 | 27 | ### end of file 28 | # Local Variables: 29 | # mode: autoconf 30 | # End: 31 | -------------------------------------------------------------------------------- /meta/autoconf/mmux-pkg-config-find-include-file.m4: -------------------------------------------------------------------------------- 1 | ## mmux-pkg-config-find-include-file.m4 -- 2 | # 3 | # Retrieve the full pathname of a packge header file and define a 4 | # substitution for it. To be used, for example, for TAGS generation. 5 | # 6 | # Arguments: 7 | # 8 | # $1 - The module name. 9 | # $2 - The header file name. 10 | # 11 | # Example: 12 | # 13 | # MMUX_PKG_CONFIG_FIND_INCLUDE_FILE([ccexceptions],[ccexceptions.h]) 14 | # 15 | # will declare the substitution "CCEXCEPTIONS_HEADER" to the result of: 16 | # 17 | # $(pkg-config ccexceptions --variable=includedir)/ccexceptions.h) 18 | # 19 | 20 | AC_DEFUN([MMUX_PKG_CONFIG_FIND_INCLUDE_FILE], 21 | [AC_CACHE_CHECK([include file for pkg-config module $1: $2], 22 | [mmux_cv_$1_[]AS_TR_CPP($2)[]include_file], 23 | [AS_IF([MMUX_PKG_CONFIG_MODULE_INCLUDEDIR=$(pkg-config $1 --variable=includedir)], 24 | [AS_VAR_SET([mmux_cv_$1_[]AS_TR_CPP($2)[]include_file],[$MMUX_PKG_CONFIG_MODULE_INCLUDEDIR/$2])], 25 | [AS_VAR_SET([mmux_cv_$1_[]AS_TR_CPP($2)[]include_file])])]) 26 | AC_SUBST(AS_TR_CPP([$1_HEADER]), [$mmux_cv_$1_[]AS_TR_CPP($2)[]include_file]) 27 | AS_VAR_APPEND([MMUX_DEPENDENCIES_INCLUDES]," $mmux_cv_$1_[]AS_TR_CPP($2)[]include_file")]) 28 | 29 | ### end of file 30 | # Local Variables: 31 | # mode: autoconf 32 | # End: 33 | -------------------------------------------------------------------------------- /meta/automake/mmux-makefile-rules: -------------------------------------------------------------------------------- 1 | # mmux-makefile-rules -- -*- mode: makefile-automake -*- 2 | # 3 | # This file is to be included in the main "Makefile.am" with the directive: 4 | # 5 | # include $(top_srcdir)/meta/automake/mmux-makefile-rules 6 | # 7 | 8 | # The following regexp has been generated under emacs by evaluating 9 | # this form: 10 | # 11 | # (regexp-opt 12 | # '("ccname_alloc" 13 | # "ccname_delete" 14 | # "ccname_final" 15 | # "ccname_iface_method" 16 | # "ccname_iface_method_type" 17 | # "ccname_iface_new" 18 | # "ccname_iface_new_type" 19 | # "ccname_iface_table" 20 | # "ccname_iface_table_type" 21 | # "ccname_init" 22 | # "ccname_is" 23 | # "ccname_method" 24 | # "ccname_method_type" 25 | # "ccname_new" 26 | # "ccname_release" 27 | # "ccname_table" 28 | # "ccname_table_type" 29 | # "ccname_type") 30 | # 'symbols) 31 | # 32 | AM_ETAGSFLAGS = $(MMUX_DEPENDENCIES_INCLUDES) \ 33 | --regex='{c}/"\\_<\\(ccname_\\(?:alloc\\|delete\\|final\\|i\\(?:face_\\(?:method\\(?:_type\\)?\\|new\\(?:_type\\)?\\|table\\(?:_type\\)?\\)\\|nit\\|s\\)\\|method\\(?:_type\\)?\\|new\\|\\(?:releas\\|t\\(?:abl\\(?:e_typ\\)?\\|yp\\)\\)e\\)\\)\\_>"/' 34 | 35 | 36 | #### testing under GDB 37 | 38 | $(builddir)/.gdbinit: 39 | ln -sv "$(top_srcdir)/gdbinit" "$(builddir)/.gdbinit" 40 | 41 | # This rule is meant to be used as: 42 | # 43 | # $ make all gdb-test FILE=tests/inspection CFLAGS='-g' 44 | # 45 | # after having created an appropriate file "$(top_srcdir)/.gdbinit". 46 | # 47 | gdb-test: $(builddir)/.gdbinit 48 | libtool --mode=execute gdb $$FILE 49 | 50 | 51 | #### Valgrind analysis 52 | # 53 | # First do this: 54 | # 55 | # make clean 56 | # make CFLAGS='-O0 -g' all check 57 | # 58 | # To use this rule on the file "tests/standard-allocator" we do: 59 | # 60 | # make valgrind file=standard-allocator 61 | # 62 | 63 | VALGRIND_PROGRAM = valgrind 64 | VALGRIND_FLAGS = --leak-check=yes --track-origins=yes 65 | VALGRIND_FULL_FLAGS = $(VALGRIND_FLAGS) --leak-check=full --show-leak-kinds=all 66 | 67 | .PHONY: valgrind valgrind-full 68 | 69 | valgrind: 70 | for f in $(builddir)/tests/$(file) ; \ 71 | do $(LIBTOOL) --mode=execute $(VALGRIND_PROGRAM) $(VALGRIND_FLAGS) $$f ; \ 72 | done 73 | 74 | valgrind-full: 75 | for f in $(builddir)/tests/$(file) ; \ 76 | do $(LIBTOOL) --mode=execute $(VALGRIND_PROGRAM) $(VALGRIND_FULL_FLAGS) $$f ; \ 77 | done 78 | 79 | 80 | #### Static analysis with Clang's Static Analyzer 81 | # 82 | # See the documentation for the command line tool at: 83 | # 84 | # 85 | # 86 | # To run the tool we must do: 87 | # 88 | # $ make clean 89 | # $ make clang-static-analysis 90 | # 91 | # The program "scan-build" works by overriding the CC and CXX 92 | # environment variables. 93 | # 94 | 95 | .PHONY: clang-static-analysis 96 | 97 | clang-static-analysis: 98 | scan-build make 99 | 100 | ### end of file 101 | -------------------------------------------------------------------------------- /meta/build/.gitignore: -------------------------------------------------------------------------------- 1 | *.bash 2 | -------------------------------------------------------------------------------- /meta/build/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile -- 2 | # 3 | # We can set "MBFLPP_FLAGS" on the command line of "make": 4 | # 5 | # $ make MBFLPP_FLAGS="..." 6 | # 7 | 8 | RM = /bin/rm --force --verbose 9 | 10 | .PHONY: all clean 11 | 12 | all: pod1 13 | 14 | clean: clean-script 15 | 16 | 17 | #### script 18 | 19 | MBFL_TARGETS = build-re2.bash 20 | MBFL_SOURCES = build-re2.bash.m4 21 | 22 | MBFL_LINKER_LIBRARY = /share/mbfl/libmbfl-linker.bash 23 | MBFLPP = mbflpp.bash 24 | MBFLPP_ENV = 25 | AM_MBFLPP_FLAGS = --add-bash --define=__LIBMBFL_LINKER__=$(MBFL_LINKER_LIBRARY) 26 | MBFLPP_COMPILE = $(MBFLPP_ENV) $(MBFLPP) $(AM_MBFLPP_FLAGS) $(MBFL_FLAGS) 27 | 28 | .PHONY: script clean-script 29 | 30 | script: $(MBFL_TARGETS) 31 | 32 | clean-script: 33 | $(RM) $(MBFL_TARGETS) 34 | 35 | %.bash : %.bash.m4 36 | $(MBFLPP_COMPILE) --output=$@ $< 37 | 38 | 39 | #### stuff for POD1 40 | 41 | POD1_PACKAGE_ABSEIL = abseil-cpp-20240722.0.tar.gz 42 | POD1_PACKAGE_GOOGLETEST = googletest-1.15.2.tar.gz 43 | POD1_PACKAGE_RE2 = re2-2024-07-02.tar.gz 44 | 45 | POD1_INSTALLDIR = /opt/re2/2024-07-02 46 | POD1_SHARED_INSTALLDIR = $(POD1_INSTALLDIR)/shared 47 | POD1_STATIC_INSTALLDIR = $(POD1_INSTALLDIR)/static 48 | 49 | .PHONY: pod1 50 | .PHONY: pod1-shared pod1-shared-abseil pod1-shared-googletest pod1-shared-re2 51 | .PHONY: pod1-static pod1-static-abseil pod1-static-googletest pod1-static-re2 52 | 53 | pod1: pod1-shared pod1-static 54 | 55 | # Watch out for the order of the prerequisites: it is left-to-right! 56 | pod1-shared: script pod1-shared-abseil pod1-shared-googletest pod1-shared-re2 57 | pod1-static: script pod1-static-abseil pod1-static-googletest pod1-static-re2 58 | 59 | ## ------------------------------------------------------------------------ 60 | 61 | pod1-shared-abseil: script 62 | bash ./build-re2.bash build abseil \ 63 | --builddir=POD1 \ 64 | --install-prefix=$(POD1_SHARED_INSTALLDIR) \ 65 | --tarball=./POD1/$(POD1_PACKAGE_ABSEIL) 66 | 67 | pod1-shared-googletest: script 68 | bash ./build-re2.bash build googletest \ 69 | --builddir=POD1 \ 70 | --install-prefix=$(POD1_SHARED_INSTALLDIR) \ 71 | --tarball=./POD1/$(POD1_PACKAGE_GOOGLETEST) 72 | 73 | pod1-shared-re2: script pod1-shared-abseil pod1-shared-googletest 74 | bash ./build-re2.bash build re2 \ 75 | --builddir=POD1 \ 76 | --install-prefix=$(POD1_SHARED_INSTALLDIR) \ 77 | --tarball=./POD1/$(POD1_PACKAGE_RE2) 78 | 79 | ### end of file 80 | -------------------------------------------------------------------------------- /meta/build/POD1/README: -------------------------------------------------------------------------------- 1 | -*- coding: utf-8-unix -*- 2 | 3 | This is the README file for the directory "$top_srcdir/meta/POD1"; in 4 | this directory we should put the following tarballs: 5 | 6 | abseil-cpp-20240722.0.tar.gz 7 | googletest-1.15.2.tar.gz 8 | re2-2024-07-02.tar.gz 9 | 10 | ### end of file 11 | # Local Variables: 12 | # mode: text 13 | # fill-column: 72 14 | # paragraph-start: "*" 15 | # ispell-local-dictionary: "en_GB-ise-w_accents" 16 | # End: 17 | -------------------------------------------------------------------------------- /meta/scripts/cre2.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | 4 | bindir=@bindir@ 5 | datarootdir=@datarootdir@ 6 | datadir=@datadir@ 7 | docdir=${prefix}/doc 8 | includedir=@includedir@ 9 | infodir=@infodir@ 10 | htmldir=${docdir} 11 | libdir=@libdir@ 12 | libexecdir=@libexecdir@ 13 | localstatedir=@localstatedir@ 14 | mandir=@mandir@ 15 | sbindir=@sbindir@ 16 | sharedstatedir=@sharedstatedir@ 17 | sysconfdir=@sysconfdir@ 18 | 19 | ## ------------------------------------------------------------ 20 | 21 | Name: @PACKAGE_NAME@ 22 | Description: C wrapper for re2, a regular expressions library 23 | Version: @MMUX_PKG_CONFIG_VERSION@ 24 | Requires: re2 >= 0.0.0 25 | Libs: -L${libdir} -lcre2 26 | Cflags: -I${includedir} 27 | 28 | ### end of file 29 | # Local Variables: 30 | # mode: script 31 | # End: 32 | -------------------------------------------------------------------------------- /src/cre2.h: -------------------------------------------------------------------------------- 1 | /* 2 | Header file for CRE2, a C language wrapper for RE2: a regular 3 | expressions library by Google. 4 | 5 | Copyright (c) 2012, 2015 Marco Maggi 6 | Copyright (c) 2011 Keegan McAllister 7 | All rights reserved. 8 | 9 | For the license notice see the COPYING file. 10 | */ 11 | 12 | #ifndef CRE2_H 13 | #define CRE2_H 1 14 | 15 | 16 | /** -------------------------------------------------------------------- 17 | ** Headers. 18 | ** ----------------------------------------------------------------- */ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #else 23 | #include 24 | #endif 25 | 26 | #include 27 | 28 | #ifndef cre2_decl 29 | # define cre2_decl extern 30 | #endif 31 | 32 | 33 | /** -------------------------------------------------------------------- 34 | ** Version functions. 35 | ** ----------------------------------------------------------------- */ 36 | 37 | cre2_decl const char * cre2_version_string (void); 38 | cre2_decl int cre2_version_interface_current (void); 39 | cre2_decl int cre2_version_interface_revision (void); 40 | cre2_decl int cre2_version_interface_age (void); 41 | 42 | 43 | /** -------------------------------------------------------------------- 44 | ** Regular expressions configuration options. 45 | ** ----------------------------------------------------------------- */ 46 | 47 | typedef void cre2_options_t; 48 | 49 | typedef enum cre2_encoding_t { 50 | CRE2_UNKNOWN = 0, /* should never happen */ 51 | CRE2_UTF8 = 1, 52 | CRE2_Latin1 = 2 53 | } cre2_encoding_t; 54 | 55 | cre2_decl cre2_options_t *cre2_opt_new (void); 56 | cre2_decl void cre2_opt_delete (cre2_options_t *opt); 57 | 58 | cre2_decl void cre2_opt_set_posix_syntax (cre2_options_t *opt, int flag); 59 | cre2_decl void cre2_opt_set_longest_match (cre2_options_t *opt, int flag); 60 | cre2_decl void cre2_opt_set_log_errors (cre2_options_t *opt, int flag); 61 | cre2_decl void cre2_opt_set_literal (cre2_options_t *opt, int flag); 62 | cre2_decl void cre2_opt_set_never_nl (cre2_options_t *opt, int flag); 63 | cre2_decl void cre2_opt_set_dot_nl (cre2_options_t *opt, int flag); 64 | cre2_decl void cre2_opt_set_never_capture (cre2_options_t *opt, int flag); 65 | cre2_decl void cre2_opt_set_case_sensitive (cre2_options_t *opt, int flag); 66 | cre2_decl void cre2_opt_set_perl_classes (cre2_options_t *opt, int flag); 67 | cre2_decl void cre2_opt_set_word_boundary (cre2_options_t *opt, int flag); 68 | cre2_decl void cre2_opt_set_one_line (cre2_options_t *opt, int flag); 69 | cre2_decl void cre2_opt_set_max_mem (cre2_options_t *opt, int64_t m); 70 | cre2_decl void cre2_opt_set_encoding (cre2_options_t *opt, cre2_encoding_t enc); 71 | 72 | cre2_decl int cre2_opt_posix_syntax (cre2_options_t *opt); 73 | cre2_decl int cre2_opt_longest_match (cre2_options_t *opt); 74 | cre2_decl int cre2_opt_log_errors (cre2_options_t *opt); 75 | cre2_decl int cre2_opt_literal (cre2_options_t *opt); 76 | cre2_decl int cre2_opt_never_nl (cre2_options_t *opt); 77 | cre2_decl int cre2_opt_dot_nl (cre2_options_t *opt); 78 | cre2_decl int cre2_opt_never_capture (cre2_options_t *opt); 79 | cre2_decl int cre2_opt_case_sensitive (cre2_options_t *opt); 80 | cre2_decl int cre2_opt_perl_classes (cre2_options_t *opt); 81 | cre2_decl int cre2_opt_word_boundary (cre2_options_t *opt); 82 | cre2_decl int cre2_opt_one_line (cre2_options_t *opt); 83 | cre2_decl int64_t cre2_opt_max_mem (cre2_options_t *opt); 84 | cre2_decl cre2_encoding_t cre2_opt_encoding (cre2_options_t *opt); 85 | 86 | 87 | /** -------------------------------------------------------------------- 88 | ** Precompiled regular expressions. 89 | ** ----------------------------------------------------------------- */ 90 | 91 | typedef struct cre2_string_t { 92 | const char * data; 93 | int length; 94 | } cre2_string_t; 95 | 96 | typedef void cre2_regexp_t; 97 | 98 | typedef struct cre2_named_groups_iter_t cre2_named_groups_iter_t; 99 | 100 | /* This definition must be kept in sync with the definition of "enum 101 | ErrorCode" in the file "re2.h" of the original RE2 distribution. */ 102 | typedef enum cre2_error_code_t { 103 | CRE2_NO_ERROR = 0, 104 | CRE2_ERROR_INTERNAL, /* unexpected error */ 105 | /* parse errors */ 106 | CRE2_ERROR_BAD_ESCAPE, /* bad escape sequence */ 107 | CRE2_ERROR_BAD_CHAR_CLASS, /* bad character class */ 108 | CRE2_ERROR_BAD_CHAR_RANGE, /* bad character class range */ 109 | CRE2_ERROR_MISSING_BRACKET, /* missing closing ] */ 110 | CRE2_ERROR_MISSING_PAREN, /* missing closing ) */ 111 | CRE2_ERROR_TRAILING_BACKSLASH,/* trailing \ at end of regexp */ 112 | CRE2_ERROR_REPEAT_ARGUMENT, /* repeat argument missing, e.g. "*" */ 113 | CRE2_ERROR_REPEAT_SIZE, /* bad repetition argument */ 114 | CRE2_ERROR_REPEAT_OP, /* bad repetition operator */ 115 | CRE2_ERROR_BAD_PERL_OP, /* bad perl operator */ 116 | CRE2_ERROR_BAD_UTF8, /* invalid UTF-8 in regexp */ 117 | CRE2_ERROR_BAD_NAMED_CAPTURE, /* bad named capture group */ 118 | CRE2_ERROR_PATTERN_TOO_LARGE, /* pattern too large (compile failed) */ 119 | } cre2_error_code_t; 120 | 121 | /* construction and destruction */ 122 | cre2_decl cre2_regexp_t * cre2_new (const char *pattern, int pattern_len, 123 | const cre2_options_t *opt); 124 | cre2_decl void cre2_delete (cre2_regexp_t *re); 125 | 126 | /* regular expression inspection */ 127 | cre2_decl const char * cre2_pattern (const cre2_regexp_t *re); 128 | cre2_decl int cre2_error_code (const cre2_regexp_t *re); 129 | cre2_decl int cre2_num_capturing_groups (const cre2_regexp_t *re); 130 | cre2_decl int cre2_program_size (const cre2_regexp_t *re); 131 | 132 | /* named capture information */ 133 | cre2_decl int cre2_find_named_capturing_groups (const cre2_regexp_t *re, const char *name); 134 | cre2_decl cre2_named_groups_iter_t * cre2_named_groups_iter_new(const cre2_regexp_t *re); 135 | cre2_decl bool cre2_named_groups_iter_next(cre2_named_groups_iter_t* iter, const char ** name, int *index); 136 | cre2_decl void cre2_named_groups_iter_delete(cre2_named_groups_iter_t *iter); 137 | 138 | /* invalidated by further re use */ 139 | cre2_decl const char *cre2_error_string(const cre2_regexp_t *re); 140 | cre2_decl void cre2_error_arg(const cre2_regexp_t *re, cre2_string_t * arg); 141 | 142 | 143 | /** -------------------------------------------------------------------- 144 | ** Main matching functions. 145 | ** ----------------------------------------------------------------- */ 146 | 147 | typedef enum cre2_anchor_t { 148 | CRE2_UNANCHORED = 1, 149 | CRE2_ANCHOR_START = 2, 150 | CRE2_ANCHOR_BOTH = 3 151 | } cre2_anchor_t; 152 | 153 | typedef struct cre2_range_t { 154 | long start; /* inclusive start index for bytevector */ 155 | long past; /* exclusive end index for bytevector */ 156 | } cre2_range_t; 157 | 158 | cre2_decl int cre2_match (const cre2_regexp_t * re, 159 | const char * text, int textlen, 160 | int startpos, int endpos, cre2_anchor_t anchor, 161 | cre2_string_t * match, int nmatch); 162 | 163 | cre2_decl int cre2_easy_match (const char * pattern, int pattern_len, 164 | const char * text, int text_len, 165 | cre2_string_t * match, int nmatch); 166 | 167 | cre2_decl void cre2_strings_to_ranges (const char * text, cre2_range_t * ranges, 168 | cre2_string_t * strings, int nmatch); 169 | 170 | 171 | /** -------------------------------------------------------------------- 172 | ** Other matching functions. 173 | ** ----------------------------------------------------------------- */ 174 | 175 | typedef int cre2_match_stringz_fun_t (const char * pattern, const cre2_string_t * text, 176 | cre2_string_t * match, int nmatch); 177 | 178 | typedef int cre2_match_stringz2_fun_t (const char * pattern, cre2_string_t * text, 179 | cre2_string_t * match, int nmatch); 180 | 181 | typedef int cre2_match_rex_fun_t (cre2_regexp_t * rex, const cre2_string_t * text, 182 | cre2_string_t * match, int nmatch); 183 | 184 | typedef int cre2_match_rex2_fun_t (cre2_regexp_t * rex, cre2_string_t * text, 185 | cre2_string_t * match, int nmatch); 186 | 187 | cre2_decl cre2_match_stringz_fun_t cre2_full_match; 188 | cre2_decl cre2_match_stringz_fun_t cre2_partial_match; 189 | cre2_decl cre2_match_stringz2_fun_t cre2_consume; 190 | cre2_decl cre2_match_stringz2_fun_t cre2_find_and_consume; 191 | 192 | cre2_decl cre2_match_rex_fun_t cre2_full_match_re; 193 | cre2_decl cre2_match_rex_fun_t cre2_partial_match_re; 194 | cre2_decl cre2_match_rex2_fun_t cre2_consume_re; 195 | cre2_decl cre2_match_rex2_fun_t cre2_find_and_consume_re; 196 | 197 | 198 | /** -------------------------------------------------------------------- 199 | ** Problematic functions. 200 | ** ----------------------------------------------------------------- */ 201 | 202 | /* Match the text in the buffer "text_and_target" against the rex in 203 | "pattern" or "rex". Mutate "text_and_target" so that it references a 204 | malloc'ed buffer holding the original text in which the first, and 205 | only the first, match is substituted with the text in "rewrite". 206 | Numeric backslash sequences (\1 to \9) in "rewrite" are substituted 207 | with the portions of text matching the corresponding parenthetical 208 | subexpressions. 209 | 210 | Return 0 if no match, 1 if successful match, -1 if error allocating 211 | memory. */ 212 | cre2_decl int cre2_replace (const char * pattern, 213 | cre2_string_t * text_and_target, 214 | cre2_string_t * rewrite); 215 | cre2_decl int cre2_replace_re (cre2_regexp_t * rex, 216 | cre2_string_t * text_and_target, 217 | cre2_string_t * rewrite); 218 | 219 | /* Match the text in the buffer "text_and_target" against the rex in 220 | "pattern" or "rex". Mutate "text_and_target" so that it references a 221 | malloc'ed buffer holding the original text in which the all the 222 | matching substrings are substituted with the text in "rewrite". 223 | Numeric backslash sequences (\1 to \9) in "rewrite" are substituted 224 | with the portions of text matching the corresponding parenthetical 225 | subexpressions. 226 | 227 | Return 0 if no match, positive integer representing the number of 228 | substitutions performed if successful match, -1 if error allocating 229 | memory. */ 230 | cre2_decl int cre2_global_replace (const char * pattern, 231 | cre2_string_t * text_and_target, 232 | cre2_string_t * rewrite); 233 | cre2_decl int cre2_global_replace_re (cre2_regexp_t * rex, 234 | cre2_string_t * text_and_target, 235 | cre2_string_t * rewrite); 236 | 237 | /* Match the text in the buffer "text" against the rex in "pattern" or 238 | "rex". Mutate "target" so that it references a malloc'ed buffer 239 | holding a copy of the text in "rewrite"; numeric backslash sequences 240 | (\1 to \9) in "rewrite" are substituted with the portions of text 241 | matching the corresponding parenthetical subexpressions. 242 | 243 | Non-matching text in "text" is ignored. 244 | 245 | Return 0 if no match, 1 if successful match, -1 if error allocating 246 | memory. */ 247 | cre2_decl int cre2_extract (const char * pattern, 248 | cre2_string_t * text, 249 | cre2_string_t * rewrite, 250 | cre2_string_t * target); 251 | 252 | cre2_decl int cre2_extract_re (cre2_regexp_t * rex, 253 | cre2_string_t * text, 254 | cre2_string_t * rewrite, 255 | cre2_string_t * target); 256 | 257 | /* ------------------------------------------------------------------ */ 258 | 259 | /* Allocate a zero-terminated malloc'ed buffer and fill it with the text 260 | from "original" having all the regexp meta characters quoted with 261 | single backslashes. Return 0 if successful, return -1 if an error 262 | allocating memory occurs. */ 263 | cre2_decl int cre2_quote_meta (cre2_string_t * quoted, cre2_string_t * original); 264 | 265 | /* Compute a "minimum" string and a "maximum" string matching the given 266 | regular expression. The min and max can in some cases be arbitrarily 267 | precise, so the caller gets to specify "maxlen" begin the maximum 268 | desired length of string returned. 269 | 270 | Assuming the call returns successfully, any string S that is an 271 | anchored match for this regexp satisfies: 272 | 273 | min <= S && S <= max. 274 | 275 | Note that this function will only consider the first copy of an 276 | infinitely repeated element (i.e., any regexp element followed by a 277 | '*' or '+' operator). Regexps with "{N}" constructions are not 278 | affected, as those do not compile down to infinite repetitions. 279 | 280 | "min_" and "max_" are mutated to reference zero-terminated malloc'ed 281 | buffers holding the min and max strings. 282 | 283 | Return 0 if failure, return 1 if successful, return -1 if an error 284 | allocating memory occurs. */ 285 | cre2_decl int cre2_possible_match_range (cre2_regexp_t * rex, 286 | cre2_string_t * min_, cre2_string_t * max_, 287 | int maxlen); 288 | 289 | /* Check that the given rewrite string is suitable for use with this 290 | regular expression. It checks that: 291 | 292 | * The regular expression has enough parenthesized subexpressions to 293 | satisfy all of the \N tokens in rewrite 294 | 295 | * The rewrite string doesn't have any syntax errors. E.g., '\' 296 | followed by anything other than a digit or '\'. 297 | 298 | A true return value guarantees that the replace and extract functions 299 | won't fail because of a bad rewrite string. 300 | 301 | In case of error: "errmsg" is mutated to reference a zero-terminated 302 | malloc'ed string describing the problem. 303 | 304 | Return 1 if the string is correct, return 0 if the string is 305 | incorrect, return -1 if an error occurred allocating memory. */ 306 | cre2_decl int cre2_check_rewrite_string (cre2_regexp_t * rex, 307 | cre2_string_t * rewrite, cre2_string_t * errmsg); 308 | 309 | 310 | /** -------------------------------------------------------------------- 311 | ** Set match. 312 | ** ----------------------------------------------------------------- */ 313 | 314 | /* Struct used to represent an RE2::Set object. */ 315 | struct cre2_set; 316 | typedef struct cre2_set cre2_set; 317 | 318 | /* RE2::Set constructor */ 319 | cre2_decl cre2_set *cre2_set_new(cre2_options_t *opt, cre2_anchor_t anchor); 320 | /* RE2::Set destructor */ 321 | cre2_decl void cre2_set_delete(cre2_set *set); 322 | 323 | /* Add a regex to the set. If invalid: store error message in error buffer. 324 | * Returns the index associated to this regex, -1 on error */ 325 | cre2_decl int cre2_set_add(cre2_set *set, const char *pattern, size_t pattern_len, 326 | char *error, size_t error_len); 327 | 328 | /* Add pattern without NULL byte. Discard error message. 329 | * Returns the index associated to this regex, -1 on error */ 330 | cre2_decl int cre2_set_add_simple(cre2_set *set, const char *pattern); 331 | 332 | /* Compile the regex set into a DFA. Must be called after add and before match. 333 | * Returns 1 on success, 0 on error */ 334 | cre2_decl int cre2_set_compile(cre2_set *set); 335 | 336 | /* Match the set of regex against text and store indices of matching regexes in match array. 337 | * Returns the number of regexes which match. */ 338 | cre2_decl size_t cre2_set_match(cre2_set *set, const char *text, size_t text_len, 339 | int *match, size_t match_len); 340 | 341 | 342 | /** -------------------------------------------------------------------- 343 | ** Done. 344 | ** ----------------------------------------------------------------- */ 345 | 346 | #ifdef __cplusplus 347 | } // extern "C" 348 | #endif 349 | 350 | #endif /* CRE2_H */ 351 | 352 | /* end of file */ 353 | -------------------------------------------------------------------------------- /tests/cre2-test.h: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: helpers for test files 4 | Date: Mon Feb 15, 2016 5 | 6 | Abstract 7 | 8 | Helpers for test files. 9 | 10 | Copyright (C) 2016 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #ifndef CRE2_TEST_H 16 | #define CRE2_TEST_H 1 17 | 18 | #if (defined CRE2_ENABLE_DEBUGGING) 19 | # define PRINTF(...) { printf(__VA_ARGS__); fflush(stdout); } 20 | # define FWRITE(...) { fwrite(__VA_ARGS__, stdout); fflush(stdout); } 21 | #else 22 | # define PRINTF(...) if (0) { printf(__VA_ARGS__); }; /* do nothing */ 23 | # define FWRITE(...) if (0) { fwrite(__VA_ARGS__, stdout); }; /* do nothing */ 24 | #endif 25 | 26 | #endif /* CRE2_TEST_H */ 27 | 28 | /* end of file */ 29 | -------------------------------------------------------------------------------- /tests/test-capture-names-iter.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for rex allocation 4 | Date: Sun May 5, 2019 5 | 6 | Abstract 7 | 8 | Test file for named capture group iteration. 9 | 10 | Copyright (C) 2019 Will Speak 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | #define CRE2_ENABLE_DEBUGGING 1 22 | 23 | int 24 | main (void) 25 | { 26 | { 27 | cre2_regexp_t * rex; 28 | cre2_named_groups_iter_t * it; 29 | bool ret; const char * name; int pos; 30 | 31 | rex = cre2_new("ciao", 4, NULL); 32 | if (!rex) 33 | goto error; 34 | it = cre2_named_groups_iter_new(rex); 35 | if (!it) 36 | goto error; 37 | ret = cre2_named_groups_iter_next(it, &name, &pos); 38 | if (ret) 39 | goto error; 40 | if (name != NULL) 41 | goto error; 42 | if (pos != -1) 43 | goto error; 44 | 45 | cre2_delete(rex); 46 | } 47 | /* ------------------------------------------------------------------ */ 48 | { 49 | cre2_regexp_t * rex; 50 | cre2_named_groups_iter_t * it; 51 | bool ret; const char * name; int pos; 52 | const char pat[] = "((.)(?P.))"; 53 | 54 | rex = cre2_new(pat, sizeof(pat), NULL); 55 | if (!rex) 56 | goto error; 57 | it = cre2_named_groups_iter_new(rex); 58 | if (!it) 59 | goto error; 60 | 61 | ret = cre2_named_groups_iter_next(it, &name, &pos); 62 | if (!ret) 63 | goto error; 64 | if (pos != 3) 65 | goto error; 66 | if (strcmp(name, "dot") != 0) 67 | goto error; 68 | 69 | ret = cre2_named_groups_iter_next(it, &name, &pos); 70 | if (ret) 71 | goto error; 72 | if (name != NULL) 73 | goto error; 74 | if (pos != -1) 75 | goto error; 76 | 77 | cre2_delete(rex); 78 | } 79 | /* ------------------------------------------------------------------ */ 80 | { 81 | cre2_regexp_t * rex; 82 | cre2_named_groups_iter_t * it; 83 | bool ret; const char * name; int pos; 84 | const char* names[5] = { 0 }; 85 | const char pat[] = "(unnamed_cap): (?P\\d{4})-(?P\\d{2})(-)(?P\\d{2})"; 86 | 87 | rex = cre2_new(pat, sizeof(pat), NULL); 88 | if (!rex) 89 | goto error; 90 | it = cre2_named_groups_iter_new(rex); 91 | if (!it) 92 | goto error; 93 | 94 | ret = cre2_named_groups_iter_next(it, &name, &pos); 95 | PRINTF("first group: %d, %s\n", pos, name); 96 | if (!ret) 97 | goto error; 98 | if (pos < 0 || pos > 5) 99 | goto error; 100 | names[pos - 1] = name; 101 | ret = cre2_named_groups_iter_next(it, &name, &pos); 102 | PRINTF("second group: %d, %s\n", pos, name); 103 | if (!ret) 104 | goto error; 105 | if (pos < 0 || pos > 5) 106 | goto error; 107 | names[pos - 1] = name; 108 | ret = cre2_named_groups_iter_next(it, &name, &pos); 109 | PRINTF("third group: %d, %s\n", pos, name); 110 | if (!ret) 111 | goto error; 112 | if (pos < 0 || pos > 5) 113 | goto error; 114 | names[pos - 1] = name; 115 | 116 | ret = cre2_named_groups_iter_next(it, &name, &pos); 117 | if (ret) 118 | goto error; 119 | if (name != NULL) 120 | goto error; 121 | if (pos != -1) 122 | goto error; 123 | 124 | if (strcmp(names[1], "year") != 0) 125 | goto error; 126 | if (strcmp(names[2], "month") != 0) 127 | goto error; 128 | if (strcmp(names[4], "day") != 0) 129 | goto error; 130 | 131 | cre2_delete(rex); 132 | } 133 | 134 | /* ------------------------------------------------------------------ */ 135 | /* This is an example for the documentation. */ 136 | { 137 | const char rex_pattern[] = "January:[[:blank:]]+(?P[[:digit:]]+)\n\ 138 | February:[[:blank:]]+(?P[[:digit:]]+)\n\ 139 | March:[[:blank:]]+(?P[[:digit:]]+)\n\ 140 | April:[[:blank:]]+(?P[[:digit:]]+)\n\ 141 | May:[[:blank:]]+(?P[[:digit:]]+)\n\ 142 | June:[[:blank:]]+(?P[[:digit:]]+)\n\ 143 | July:[[:blank:]]+(?P[[:digit:]]+)\n\ 144 | August:[[:blank:]]+(?P[[:digit:]]+)\n\ 145 | September:[[:blank:]]+(?P[[:digit:]]+)\n\ 146 | October:[[:blank:]]+(?P[[:digit:]]+)\n\ 147 | November:[[:blank:]]+(?P[[:digit:]]+)\n\ 148 | December:[[:blank:]]+(?P[[:digit:]]+)\n"; 149 | 150 | const char * text = "\ 151 | January: 8\n\ 152 | February: 3\n\ 153 | March: 3\n\ 154 | April: 4\n\ 155 | May: 9\n\ 156 | June: 4\n\ 157 | July: 7\n\ 158 | August: 5\n\ 159 | September: 9\n\ 160 | October: 2\n\ 161 | November: 1\n\ 162 | December: 6\n"; 163 | int text_len = strlen(text); 164 | 165 | int rv; 166 | int nmatch = 20; 167 | cre2_string_t match[nmatch]; 168 | 169 | cre2_regexp_t * rex = cre2_new(rex_pattern, strlen(rex_pattern), NULL); 170 | if (!rex) { 171 | fprintf(stderr, "error building rex\n"); 172 | goto done; 173 | } 174 | if (cre2_error_code(rex)) { 175 | fprintf(stderr, "error building rex\n"); 176 | goto done; 177 | } 178 | 179 | rv = cre2_match(rex, text, text_len, 0, text_len, CRE2_ANCHOR_BOTH, match, nmatch); 180 | if (! rv) { 181 | fprintf(stderr, "no match\n"); 182 | goto done; 183 | } 184 | 185 | { 186 | cre2_named_groups_iter_t * iter = cre2_named_groups_iter_new(rex); 187 | 188 | if (!iter) { 189 | fprintf(stderr, "error building iterator\n"); 190 | goto internal_done; 191 | } 192 | 193 | { 194 | char const *name; 195 | int index; 196 | 197 | while (cre2_named_groups_iter_next(iter, &name, &index)) { 198 | printf("group: %d, %s\n", index, name); 199 | } 200 | } 201 | 202 | internal_done: 203 | 204 | if (iter) { 205 | cre2_named_groups_iter_delete(iter); 206 | } 207 | } 208 | 209 | done: 210 | if (rex) { 211 | cre2_delete(rex); 212 | } 213 | } 214 | 215 | exit(EXIT_SUCCESS); 216 | 217 | error: 218 | exit(EXIT_FAILURE); 219 | } 220 | 221 | /* end of file */ 222 | -------------------------------------------------------------------------------- /tests/test-consume-match.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for consume match function 4 | Date: Tue Jan 3, 2012 5 | 6 | Abstract 7 | 8 | Test file for consume match function. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | { /* success, no parentheses, full consumed buffer */ 25 | const char * pattern = "ci.*ut"; 26 | const char * text = "ciao salut"; 27 | cre2_string_t input = { .data = text, .length = strlen(text) }; 28 | int result; 29 | result = cre2_consume(pattern, &input, NULL, 0); 30 | if (! result) 31 | goto error; 32 | if (0 != strncmp("", input.data, input.length)) 33 | goto error; 34 | } 35 | { /* success, no parentheses, partially consumed buffer */ 36 | const char * pattern = "ci.*ut"; 37 | const char * text = "ciao salut hello"; 38 | cre2_string_t input = { .data = text, .length = strlen(text) }; 39 | int result; 40 | result = cre2_consume(pattern, &input, NULL, 0); 41 | if (! result) 42 | goto error; 43 | if (0 != strncmp(" hello", input.data, input.length)) 44 | goto error; 45 | } 46 | { /* success, one parenthetical subexpression, one match entry */ 47 | const char * pattern = "(ciao) salut"; 48 | const char * text = "ciao salut hello"; 49 | cre2_string_t input = { .data = text, .length = strlen(text) }; 50 | int nmatch = 1; 51 | cre2_string_t match[nmatch]; 52 | int result; 53 | result = cre2_consume(pattern, &input, match, nmatch); 54 | if (! result) 55 | goto error; 56 | if (0 != strncmp(" hello", input.data, input.length)) 57 | goto error; 58 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 59 | goto error; 60 | PRINTF("match 0: "); 61 | FWRITE(match[0].data, match[0].length, 1); 62 | PRINTF("\n"); 63 | } 64 | { /* success, two parenthetical subexpressions, two match entries */ 65 | const char * pattern = "(ciao) (salut)"; 66 | const char * text = "ciao salut hello"; 67 | cre2_string_t input = { .data = text, .length = strlen(text) }; 68 | int nmatch = 2; 69 | cre2_string_t match[nmatch]; 70 | int result; 71 | result = cre2_consume(pattern, &input, match, nmatch); 72 | if (! result) 73 | goto error; 74 | if (0 != strncmp(" hello", input.data, input.length)) 75 | goto error; 76 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 77 | goto error; 78 | if (0 != strncmp("salut", match[1].data, match[1].length)) 79 | goto error; 80 | PRINTF("match 0: "); 81 | FWRITE(match[0].data, match[0].length, 1); 82 | PRINTF("\n"); 83 | PRINTF("match 1: "); 84 | FWRITE(match[1].data, match[1].length, 1); 85 | PRINTF("\n"); 86 | } 87 | { /* failure, no parentheses */ 88 | const char * pattern = "ci.*ut"; 89 | const char * text = "ciao hello"; 90 | cre2_string_t input = { .data = text, .length = strlen(text) }; 91 | int result; 92 | result = cre2_consume(pattern, &input, NULL, 0); 93 | if (result) 94 | goto error; 95 | } 96 | { /* failure, one parenthetical subexpression */ 97 | const char * pattern = "(ciao) salut"; 98 | const char * text = "ciao hello"; 99 | cre2_string_t input = { .data = text, .length = strlen(text) }; 100 | int nmatch = 1; 101 | cre2_string_t match[nmatch]; 102 | int result; 103 | result = cre2_consume(pattern, &input, match, nmatch); 104 | if (result) 105 | goto error; 106 | if (0 != strncmp(text, input.data, input.length)) 107 | goto error; 108 | } 109 | { /* success, one parenthetical subexpression, no match entries */ 110 | const char * pattern = "(ciao) salut"; 111 | const char * text = "ciao salut hello"; 112 | cre2_string_t input = { .data = text, .length = strlen(text) }; 113 | int result; 114 | result = cre2_consume(pattern, &input, NULL, 0); 115 | if (! result) 116 | goto error; 117 | if (0 != strncmp(" hello", input.data, input.length)) 118 | goto error; 119 | } 120 | { /* failure, one parenthetical subexpression, two match entries */ 121 | const char * pattern = "(ciao) salut"; 122 | const char * text = "ciao salut hello"; 123 | cre2_string_t input = { .data = text, .length = strlen(text) }; 124 | int nmatch = 2; 125 | cre2_string_t match[nmatch]; 126 | int result; 127 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 128 | result = cre2_consume(pattern, &input, match, nmatch); 129 | if (0 != result) 130 | goto error; 131 | } 132 | { /* success, two parenthetical subexpressions, one match entry */ 133 | const char * pattern = "(ciao) (salut)"; 134 | const char * text = "ciao salut hello"; 135 | cre2_string_t input = { .data = text, .length = strlen(text) }; 136 | int nmatch = 1; 137 | cre2_string_t match[nmatch]; 138 | int result; 139 | result = cre2_consume(pattern, &input, match, nmatch); 140 | if (! result) 141 | goto error; 142 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 143 | goto error; 144 | if (0 != strncmp(" hello", input.data, input.length)) 145 | goto error; 146 | PRINTF("match 0: "); 147 | FWRITE(match[0].data, match[0].length, 1); 148 | PRINTF("\n"); 149 | } 150 | { /* wrong regexp specification */ 151 | const char * pattern = "cia(o salut"; 152 | const char * text = "ciao hello"; 153 | cre2_string_t input = { .data = text, .length = strlen(text) }; 154 | int nmatch = 1; 155 | cre2_string_t match[nmatch]; 156 | int result; 157 | result = cre2_consume(pattern, &input, match, nmatch); 158 | if (0 != result) 159 | goto error; 160 | if (0 != strncmp(text, input.data, input.length)) 161 | goto error; 162 | } 163 | 164 | 165 | /* ------------------------------------------------------------------ */ 166 | 167 | { /* success, no parentheses, full buffer consumed */ 168 | const char * pattern = "ci.*ut"; 169 | cre2_regexp_t * rex; 170 | const char * text = "ciao salut"; 171 | cre2_string_t input = { .data = text, .length = strlen(text) }; 172 | int result; 173 | rex = cre2_new(pattern, strlen(pattern), NULL); 174 | result = cre2_consume_re(rex, &input, NULL, 0); 175 | cre2_delete(rex); 176 | if (! result) 177 | goto error; 178 | if (0 != strncmp(text, input.data, input.length)) 179 | goto error; 180 | } 181 | { /* success, no parentheses, partial buffer consumed */ 182 | const char * pattern = "ci.*ut"; 183 | cre2_regexp_t * rex; 184 | const char * text = "ciao salut hello"; 185 | cre2_string_t input = { .data = text, .length = strlen(text) }; 186 | int result; 187 | rex = cre2_new(pattern, strlen(pattern), NULL); 188 | result = cre2_consume_re(rex, &input, NULL, 0); 189 | cre2_delete(rex); 190 | if (! result) 191 | goto error; 192 | if (0 != strncmp(" hello", input.data, input.length)) 193 | goto error; 194 | } 195 | { /* success, one parenthetical subexpression, one match entry */ 196 | const char * pattern = "(ciao) salut"; 197 | cre2_regexp_t * rex; 198 | const char * text = "ciao salut hello"; 199 | cre2_string_t input = { .data = text, .length = strlen(text) }; 200 | int nmatch = 1; 201 | cre2_string_t match[nmatch]; 202 | int result; 203 | rex = cre2_new(pattern, strlen(pattern), NULL); 204 | result = cre2_consume_re(rex, &input, match, nmatch); 205 | cre2_delete(rex); 206 | if (! result) 207 | goto error; 208 | if (0 != strncmp(" hello", input.data, input.length)) 209 | goto error; 210 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 211 | goto error; 212 | PRINTF("match 0: "); 213 | FWRITE(match[0].data, match[0].length, 1); 214 | PRINTF("\n"); 215 | } 216 | { /* success, two parenthetical subexpressions, two match entries */ 217 | const char * pattern = "(ciao) (salut)"; 218 | cre2_regexp_t * rex; 219 | const char * text = "ciao salut hello"; 220 | cre2_string_t input = { .data = text, .length = strlen(text) }; 221 | int nmatch = 2; 222 | cre2_string_t match[nmatch]; 223 | int result; 224 | rex = cre2_new(pattern, strlen(pattern), NULL); 225 | result = cre2_consume_re(rex, &input, match, nmatch); 226 | cre2_delete(rex); 227 | if (! result) 228 | goto error; 229 | if (0 != strncmp(" hello", input.data, input.length)) 230 | goto error; 231 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 232 | goto error; 233 | if (0 != strncmp("salut", match[1].data, match[1].length)) 234 | goto error; 235 | PRINTF("match 0: "); 236 | FWRITE(match[0].data, match[0].length, 1); 237 | PRINTF("\n"); 238 | PRINTF("match 1: "); 239 | FWRITE(match[1].data, match[1].length, 1); 240 | PRINTF("\n"); 241 | } 242 | { /* failure, no parentheses */ 243 | const char * pattern = "ci.*ut"; 244 | cre2_regexp_t * rex; 245 | const char * text = "ciao hello"; 246 | cre2_string_t input = { .data = text, .length = strlen(text) }; 247 | int result; 248 | rex = cre2_new(pattern, strlen(pattern), NULL); 249 | result = cre2_consume_re(rex, &input, NULL, 0); 250 | cre2_delete(rex); 251 | if (result) 252 | goto error; 253 | } 254 | { /* failure, one parenthetical subexpression */ 255 | const char * pattern = "(ciao) salut"; 256 | cre2_regexp_t * rex; 257 | const char * text = "ciao hello"; 258 | cre2_string_t input = { .data = text, .length = strlen(text) }; 259 | int nmatch = 1; 260 | cre2_string_t match[nmatch]; 261 | int result; 262 | rex = cre2_new(pattern, strlen(pattern), NULL); 263 | result = cre2_consume_re(rex, &input, match, nmatch); 264 | cre2_delete(rex); 265 | if (result) 266 | goto error; 267 | if (0 != strncmp(text, input.data, input.length)) 268 | goto error; 269 | } 270 | { /* success, one parenthetical subexpression, no match entries */ 271 | const char * pattern = "(ciao) salut"; 272 | cre2_regexp_t * rex; 273 | const char * text = "ciao salut hello"; 274 | cre2_string_t input = { .data = text, .length = strlen(text) }; 275 | int result; 276 | rex = cre2_new(pattern, strlen(pattern), NULL); 277 | result = cre2_consume_re(rex, &input, NULL, 0); 278 | cre2_delete(rex); 279 | if (! result) 280 | goto error; 281 | if (0 != strncmp(" hello", input.data, input.length)) 282 | goto error; 283 | } 284 | { /* failure, one parenthetical subexpression, two match entries */ 285 | const char * pattern = "(ciao) salut"; 286 | cre2_regexp_t * rex; 287 | const char * text = "ciao salut"; 288 | cre2_string_t input = { .data = text, .length = strlen(text) }; 289 | int nmatch = 2; 290 | cre2_string_t match[nmatch]; 291 | int result; 292 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 293 | rex = cre2_new(pattern, strlen(pattern), NULL); 294 | result = cre2_consume_re(rex, &input, match, nmatch); 295 | cre2_delete(rex); 296 | if (0 != result) 297 | goto error; 298 | if (0 != strncmp(text, input.data, input.length)) 299 | goto error; 300 | } 301 | { /* success, two parenthetical subexpressions, one match entry */ 302 | const char * pattern = "(ciao) (salut)"; 303 | cre2_regexp_t * rex; 304 | const char * text = "ciao salut hello"; 305 | cre2_string_t input = { .data = text, .length = strlen(text) }; 306 | int nmatch = 1; 307 | cre2_string_t match[nmatch]; 308 | int result; 309 | rex = cre2_new(pattern, strlen(pattern), NULL); 310 | result = cre2_consume_re(rex, &input, match, nmatch); 311 | cre2_delete(rex); 312 | if (! result) 313 | goto error; 314 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 315 | goto error; 316 | if (0 != strncmp(" hello", input.data, input.length)) 317 | goto error; 318 | PRINTF("match 0: "); 319 | FWRITE(match[0].data, match[0].length, 1); 320 | PRINTF("\n"); 321 | } 322 | 323 | exit(EXIT_SUCCESS); 324 | error: 325 | exit(EXIT_FAILURE); 326 | } 327 | 328 | /* end of file */ 329 | -------------------------------------------------------------------------------- /tests/test-easy-matching.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for easy matching 4 | Date: Mon Jan 2, 2012 5 | 6 | Abstract 7 | 8 | Test file for regular expressions matching. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | const char * pattern; 25 | const char * text; 26 | 27 | /* ------------------------------------------------------------------ */ 28 | /* single match */ 29 | 30 | pattern = "ciao"; 31 | text = "ciao"; 32 | { 33 | cre2_string_t match; 34 | int nmatch = 1; 35 | cre2_easy_match(pattern, strlen(pattern), 36 | text, strlen(text), 37 | &match, nmatch); 38 | PRINTF("match: "); 39 | FWRITE(match.data, match.length, 1); 40 | PRINTF("\n"); 41 | if (0 != strncmp("ciao", match.data, match.length)) 42 | goto error; 43 | } 44 | 45 | /* ------------------------------------------------------------------ */ 46 | /* wrong pattern */ 47 | 48 | pattern = "ci(ao"; 49 | text = "ciao"; 50 | { 51 | cre2_string_t match; 52 | int nmatch = 1; 53 | int retval; 54 | retval = cre2_easy_match(pattern, strlen(pattern), 55 | text, strlen(text), 56 | &match, nmatch); 57 | if (2 != retval) 58 | goto error; 59 | } 60 | 61 | /* ------------------------------------------------------------------ */ 62 | /* two groups */ 63 | 64 | pattern = "(ciao) (hello)"; 65 | text = "ciao hello"; 66 | { 67 | int nmatch = 3; 68 | cre2_string_t match[nmatch]; 69 | cre2_easy_match(pattern, strlen(pattern), 70 | text, strlen(text), 71 | match, nmatch); 72 | PRINTF("full match: "); 73 | FWRITE(match[0].data, match[0].length, 1); 74 | PRINTF("\n"); 75 | PRINTF("first group: "); 76 | FWRITE(match[1].data, match[1].length, 1); 77 | PRINTF("\n"); 78 | PRINTF("second group: "); 79 | FWRITE(match[2].data, match[2].length, 1); 80 | PRINTF("\n"); 81 | if (0 != strncmp("ciao hello", match[0].data, match[0].length)) 82 | goto error; 83 | if (0 != strncmp("ciao", match[1].data, match[1].length)) 84 | goto error; 85 | if (0 != strncmp("hello", match[2].data, match[2].length)) 86 | goto error; 87 | } 88 | 89 | /* ------------------------------------------------------------------ */ 90 | 91 | exit(EXIT_SUCCESS); 92 | error: 93 | exit(EXIT_FAILURE); 94 | } 95 | 96 | /* end of file */ 97 | -------------------------------------------------------------------------------- /tests/test-find-and-consume-match.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for find and consume match function 4 | Date: Tue Jan 3, 2012 5 | 6 | Abstract 7 | 8 | Test file for find and consume match function. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | { /* success, no parentheses, full consumed buffer */ 25 | const char * pattern = "ci.*ut"; 26 | const char * text = "prefix ciao salut"; 27 | cre2_string_t input = { .data = text, .length = strlen(text) }; 28 | int result; 29 | result = cre2_find_and_consume(pattern, &input, NULL, 0); 30 | if (! result) 31 | goto error; 32 | if (0 != strncmp("", input.data, input.length)) 33 | goto error; 34 | } 35 | { /* success, no parentheses, partially consumed buffer */ 36 | const char * pattern = "ci.*ut"; 37 | const char * text = "prefix ciao salut hello"; 38 | cre2_string_t input = { .data = text, .length = strlen(text) }; 39 | int result; 40 | result = cre2_find_and_consume(pattern, &input, NULL, 0); 41 | if (! result) 42 | goto error; 43 | if (0 != strncmp(" hello", input.data, input.length)) 44 | goto error; 45 | } 46 | { /* success, one parenthetical subexpression, one match entry */ 47 | const char * pattern = "(ciao) salut"; 48 | const char * text = "prefix ciao salut hello"; 49 | cre2_string_t input = { .data = text, .length = strlen(text) }; 50 | int nmatch = 1; 51 | cre2_string_t match[nmatch]; 52 | int result; 53 | result = cre2_find_and_consume(pattern, &input, match, nmatch); 54 | if (! result) 55 | goto error; 56 | if (0 != strncmp(" hello", input.data, input.length)) 57 | goto error; 58 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 59 | goto error; 60 | PRINTF("match 0: "); 61 | FWRITE(match[0].data, match[0].length, 1); 62 | PRINTF("\n"); 63 | } 64 | { /* success, two parenthetical subexpressions, two match entries */ 65 | const char * pattern = "(ciao) (salut)"; 66 | const char * text = "prefix ciao salut hello"; 67 | cre2_string_t input = { .data = text, .length = strlen(text) }; 68 | int nmatch = 2; 69 | cre2_string_t match[nmatch]; 70 | int result; 71 | result = cre2_find_and_consume(pattern, &input, match, nmatch); 72 | if (! result) 73 | goto error; 74 | if (0 != strncmp(" hello", input.data, input.length)) 75 | goto error; 76 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 77 | goto error; 78 | if (0 != strncmp("salut", match[1].data, match[1].length)) 79 | goto error; 80 | PRINTF("match 0: "); 81 | FWRITE(match[0].data, match[0].length, 1); 82 | PRINTF("\n"); 83 | PRINTF("match 1: "); 84 | FWRITE(match[1].data, match[1].length, 1); 85 | PRINTF("\n"); 86 | } 87 | { /* failure, no parentheses */ 88 | const char * pattern = "ci.*ut"; 89 | const char * text = "prefix ciao hello"; 90 | cre2_string_t input = { .data = text, .length = strlen(text) }; 91 | int result; 92 | result = cre2_find_and_consume(pattern, &input, NULL, 0); 93 | if (result) 94 | goto error; 95 | } 96 | { /* failure, one parenthetical subexpression */ 97 | const char * pattern = "(ciao) salut"; 98 | const char * text = "prefix ciao hello"; 99 | cre2_string_t input = { .data = text, .length = strlen(text) }; 100 | int nmatch = 1; 101 | cre2_string_t match[nmatch]; 102 | int result; 103 | result = cre2_find_and_consume(pattern, &input, match, nmatch); 104 | if (result) 105 | goto error; 106 | if (0 != strncmp(text, input.data, input.length)) 107 | goto error; 108 | } 109 | { /* success, one parenthetical subexpression, no match entries */ 110 | const char * pattern = "(ciao) salut"; 111 | const char * text = "prefix ciao salut hello"; 112 | cre2_string_t input = { .data = text, .length = strlen(text) }; 113 | int result; 114 | result = cre2_find_and_consume(pattern, &input, NULL, 0); 115 | if (! result) 116 | goto error; 117 | if (0 != strncmp(" hello", input.data, input.length)) 118 | goto error; 119 | } 120 | { /* failure, one parenthetical subexpression, two match entries */ 121 | const char * pattern = "(ciao) salut"; 122 | const char * text = "prefix ciao salut hello"; 123 | cre2_string_t input = { .data = text, .length = strlen(text) }; 124 | int nmatch = 2; 125 | cre2_string_t match[nmatch]; 126 | int result; 127 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 128 | result = cre2_find_and_consume(pattern, &input, match, nmatch); 129 | if (0 != result) 130 | goto error; 131 | } 132 | { /* success, two parenthetical subexpressions, one match entry */ 133 | const char * pattern = "(ciao) (salut)"; 134 | const char * text = "prefix ciao salut hello"; 135 | cre2_string_t input = { .data = text, .length = strlen(text) }; 136 | int nmatch = 1; 137 | cre2_string_t match[nmatch]; 138 | int result; 139 | result = cre2_find_and_consume(pattern, &input, match, nmatch); 140 | if (! result) 141 | goto error; 142 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 143 | goto error; 144 | if (0 != strncmp(" hello", input.data, input.length)) 145 | goto error; 146 | PRINTF("match 0: "); 147 | FWRITE(match[0].data, match[0].length, 1); 148 | PRINTF("\n"); 149 | } 150 | { /* wrong regexp specification */ 151 | const char * pattern = "cia(o salut"; 152 | const char * text = "prefix ciao hello"; 153 | cre2_string_t input = { .data = text, .length = strlen(text) }; 154 | int nmatch = 1; 155 | cre2_string_t match[nmatch]; 156 | int result; 157 | result = cre2_find_and_consume(pattern, &input, match, nmatch); 158 | if (0 != result) 159 | goto error; 160 | if (0 != strncmp(text, input.data, input.length)) 161 | goto error; 162 | } 163 | 164 | 165 | /* ------------------------------------------------------------------ */ 166 | 167 | { /* success, no parentheses, full buffer consumed */ 168 | const char * pattern = "ci.*ut"; 169 | cre2_regexp_t * rex; 170 | const char * text = "prefix ciao salut"; 171 | cre2_string_t input = { .data = text, .length = strlen(text) }; 172 | int result; 173 | rex = cre2_new(pattern, strlen(pattern), NULL); 174 | result = cre2_find_and_consume_re(rex, &input, NULL, 0); 175 | cre2_delete(rex); 176 | if (! result) 177 | goto error; 178 | if (0 != strncmp(text, input.data, input.length)) 179 | goto error; 180 | } 181 | { /* success, no parentheses, partial buffer consumed */ 182 | const char * pattern = "ci.*ut"; 183 | cre2_regexp_t * rex; 184 | const char * text = "prefix ciao salut hello"; 185 | cre2_string_t input = { .data = text, .length = strlen(text) }; 186 | int result; 187 | rex = cre2_new(pattern, strlen(pattern), NULL); 188 | result = cre2_find_and_consume_re(rex, &input, NULL, 0); 189 | cre2_delete(rex); 190 | if (! result) 191 | goto error; 192 | if (0 != strncmp(" hello", input.data, input.length)) 193 | goto error; 194 | } 195 | { /* success, one parenthetical subexpression, one match entry */ 196 | const char * pattern = "(ciao) salut"; 197 | cre2_regexp_t * rex; 198 | const char * text = "prefix ciao salut hello"; 199 | cre2_string_t input = { .data = text, .length = strlen(text) }; 200 | int nmatch = 1; 201 | cre2_string_t match[nmatch]; 202 | int result; 203 | rex = cre2_new(pattern, strlen(pattern), NULL); 204 | result = cre2_find_and_consume_re(rex, &input, match, nmatch); 205 | cre2_delete(rex); 206 | if (! result) 207 | goto error; 208 | if (0 != strncmp(" hello", input.data, input.length)) 209 | goto error; 210 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 211 | goto error; 212 | PRINTF("match 0: "); 213 | FWRITE(match[0].data, match[0].length, 1); 214 | PRINTF("\n"); 215 | } 216 | { /* success, two parenthetical subexpressions, two match entries */ 217 | const char * pattern = "(ciao) (salut)"; 218 | cre2_regexp_t * rex; 219 | const char * text = "prefix ciao salut hello"; 220 | cre2_string_t input = { .data = text, .length = strlen(text) }; 221 | int nmatch = 2; 222 | cre2_string_t match[nmatch]; 223 | int result; 224 | rex = cre2_new(pattern, strlen(pattern), NULL); 225 | result = cre2_find_and_consume_re(rex, &input, match, nmatch); 226 | cre2_delete(rex); 227 | if (! result) 228 | goto error; 229 | if (0 != strncmp(" hello", input.data, input.length)) 230 | goto error; 231 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 232 | goto error; 233 | if (0 != strncmp("salut", match[1].data, match[1].length)) 234 | goto error; 235 | PRINTF("match 0: "); 236 | FWRITE(match[0].data, match[0].length, 1); 237 | PRINTF("\n"); 238 | PRINTF("match 1: "); 239 | FWRITE(match[1].data, match[1].length, 1); 240 | PRINTF("\n"); 241 | } 242 | { /* failure, no parentheses */ 243 | const char * pattern = "ci.*ut"; 244 | cre2_regexp_t * rex; 245 | const char * text = "prefix ciao hello"; 246 | cre2_string_t input = { .data = text, .length = strlen(text) }; 247 | int result; 248 | rex = cre2_new(pattern, strlen(pattern), NULL); 249 | result = cre2_find_and_consume_re(rex, &input, NULL, 0); 250 | cre2_delete(rex); 251 | if (result) 252 | goto error; 253 | } 254 | { /* failure, one parenthetical subexpression */ 255 | const char * pattern = "(ciao) salut"; 256 | cre2_regexp_t * rex; 257 | const char * text = "prefix ciao hello"; 258 | cre2_string_t input = { .data = text, .length = strlen(text) }; 259 | int nmatch = 1; 260 | cre2_string_t match[nmatch]; 261 | int result; 262 | rex = cre2_new(pattern, strlen(pattern), NULL); 263 | result = cre2_find_and_consume_re(rex, &input, match, nmatch); 264 | cre2_delete(rex); 265 | if (result) 266 | goto error; 267 | if (0 != strncmp(text, input.data, input.length)) 268 | goto error; 269 | } 270 | { /* success, one parenthetical subexpression, no match entries */ 271 | const char * pattern = "(ciao) salut"; 272 | cre2_regexp_t * rex; 273 | const char * text = "prefix ciao salut hello"; 274 | cre2_string_t input = { .data = text, .length = strlen(text) }; 275 | int result; 276 | rex = cre2_new(pattern, strlen(pattern), NULL); 277 | result = cre2_find_and_consume_re(rex, &input, NULL, 0); 278 | cre2_delete(rex); 279 | if (! result) 280 | goto error; 281 | if (0 != strncmp(" hello", input.data, input.length)) 282 | goto error; 283 | } 284 | { /* failure, one parenthetical subexpression, two match entries */ 285 | const char * pattern = "(ciao) salut"; 286 | cre2_regexp_t * rex; 287 | const char * text = "prefix ciao salut"; 288 | cre2_string_t input = { .data = text, .length = strlen(text) }; 289 | int nmatch = 2; 290 | cre2_string_t match[nmatch]; 291 | int result; 292 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 293 | rex = cre2_new(pattern, strlen(pattern), NULL); 294 | result = cre2_find_and_consume_re(rex, &input, match, nmatch); 295 | cre2_delete(rex); 296 | if (0 != result) 297 | goto error; 298 | if (0 != strncmp(text, input.data, input.length)) 299 | goto error; 300 | } 301 | { /* success, two parenthetical subexpressions, one match entry */ 302 | const char * pattern = "(ciao) (salut)"; 303 | cre2_regexp_t * rex; 304 | const char * text = "prefix ciao salut hello"; 305 | cre2_string_t input = { .data = text, .length = strlen(text) }; 306 | int nmatch = 1; 307 | cre2_string_t match[nmatch]; 308 | int result; 309 | rex = cre2_new(pattern, strlen(pattern), NULL); 310 | result = cre2_find_and_consume_re(rex, &input, match, nmatch); 311 | cre2_delete(rex); 312 | if (! result) 313 | goto error; 314 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 315 | goto error; 316 | if (0 != strncmp(" hello", input.data, input.length)) 317 | goto error; 318 | PRINTF("match 0: "); 319 | FWRITE(match[0].data, match[0].length, 1); 320 | PRINTF("\n"); 321 | } 322 | 323 | exit(EXIT_SUCCESS); 324 | error: 325 | exit(EXIT_FAILURE); 326 | } 327 | 328 | /* end of file */ 329 | -------------------------------------------------------------------------------- /tests/test-full-match.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for full match function 4 | Date: Tue Jan 3, 2012 5 | 6 | Abstract 7 | 8 | Test file for full match function. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | { /* success, no parentheses */ 25 | const char * pattern = "ci.*ut"; 26 | const char * text = "ciao salut"; 27 | cre2_string_t input = { .data = text, .length = strlen(text) }; 28 | int result; 29 | result = cre2_full_match(pattern, &input, NULL, 0); 30 | if (! result) 31 | goto error; 32 | if (0 != strncmp(text, input.data, input.length)) 33 | goto error; 34 | } 35 | { /* success, one parenthetical subexpression, one match entry */ 36 | const char * pattern = "(ciao) salut"; 37 | const char * text = "ciao salut"; 38 | cre2_string_t input = { .data = text, .length = strlen(text) }; 39 | int nmatch = 1; 40 | cre2_string_t match[nmatch]; 41 | int result; 42 | result = cre2_full_match(pattern, &input, match, nmatch); 43 | if (! result) 44 | goto error; 45 | if (0 != strncmp(text, input.data, input.length)) 46 | goto error; 47 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 48 | goto error; 49 | PRINTF("match 0: "); 50 | FWRITE(match[0].data, match[0].length, 1); 51 | PRINTF("\n"); 52 | } 53 | { /* success, two parenthetical subexpressions, two match entries */ 54 | const char * pattern = "(ciao) (salut)"; 55 | const char * text = "ciao salut"; 56 | cre2_string_t input = { .data = text, .length = strlen(text) }; 57 | int nmatch = 2; 58 | cre2_string_t match[nmatch]; 59 | int result; 60 | result = cre2_full_match(pattern, &input, match, nmatch); 61 | if (! result) 62 | goto error; 63 | if (0 != strncmp(text, input.data, input.length)) 64 | goto error; 65 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 66 | goto error; 67 | if (0 != strncmp("salut", match[1].data, match[1].length)) 68 | goto error; 69 | PRINTF("match 0: "); 70 | FWRITE(match[0].data, match[0].length, 1); 71 | PRINTF("\n"); 72 | PRINTF("match 1: "); 73 | FWRITE(match[1].data, match[1].length, 1); 74 | PRINTF("\n"); 75 | } 76 | { /* failure, no parentheses */ 77 | const char * pattern = "ci.*ut"; 78 | const char * text = "ciao hello"; 79 | cre2_string_t input = { .data = text, .length = strlen(text) }; 80 | int result; 81 | result = cre2_full_match(pattern, &input, NULL, 0); 82 | if (result) 83 | goto error; 84 | } 85 | { /* failure, one parenthetical subexpression */ 86 | const char * pattern = "(ciao) salut"; 87 | const char * text = "ciao hello"; 88 | cre2_string_t input = { .data = text, .length = strlen(text) }; 89 | int nmatch = 1; 90 | cre2_string_t match[nmatch]; 91 | int result; 92 | result = cre2_full_match(pattern, &input, match, nmatch); 93 | if (result) 94 | goto error; 95 | if (0 != strncmp(text, input.data, input.length)) 96 | goto error; 97 | } 98 | { /* success, one parenthetical subexpression, no match entries */ 99 | const char * pattern = "(ciao) salut"; 100 | const char * text = "ciao salut"; 101 | cre2_string_t input = { .data = text, .length = strlen(text) }; 102 | int result; 103 | result = cre2_full_match(pattern, &input, NULL, 0); 104 | if (! result) 105 | goto error; 106 | if (0 != strncmp(text, input.data, input.length)) 107 | goto error; 108 | } 109 | { /* failure, one parenthetical subexpression, two match entries */ 110 | const char * pattern = "(ciao) salut"; 111 | const char * text = "ciao salut"; 112 | cre2_string_t input = { .data = text, .length = strlen(text) }; 113 | int nmatch = 2; 114 | cre2_string_t match[nmatch]; 115 | int result; 116 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 117 | result = cre2_full_match(pattern, &input, match, nmatch); 118 | if (0 != result) 119 | goto error; 120 | } 121 | { /* success, two parenthetical subexpressions, one match entry */ 122 | const char * pattern = "(ciao) (salut)"; 123 | const char * text = "ciao salut"; 124 | cre2_string_t input = { .data = text, .length = strlen(text) }; 125 | int nmatch = 1; 126 | cre2_string_t match[nmatch]; 127 | int result; 128 | result = cre2_full_match(pattern, &input, match, nmatch); 129 | if (! result) 130 | goto error; 131 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 132 | goto error; 133 | if (0 != strncmp(text, input.data, input.length)) 134 | goto error; 135 | PRINTF("match 0: "); 136 | FWRITE(match[0].data, match[0].length, 1); 137 | PRINTF("\n"); 138 | } 139 | { /* wrong regexp specification */ 140 | const char * pattern = "cia(o salut"; 141 | const char * text = "ciao hello"; 142 | cre2_string_t input = { .data = text, .length = strlen(text) }; 143 | int nmatch = 1; 144 | cre2_string_t match[nmatch]; 145 | int result; 146 | result = cre2_full_match(pattern, &input, match, nmatch); 147 | if (0 != result) 148 | goto error; 149 | if (0 != strncmp(text, input.data, input.length)) 150 | goto error; 151 | } 152 | 153 | 154 | /* ------------------------------------------------------------------ */ 155 | 156 | { /* success, no parentheses */ 157 | const char * pattern = "ci.*ut"; 158 | cre2_regexp_t * rex; 159 | const char * text = "ciao salut"; 160 | cre2_string_t input = { .data = text, .length = strlen(text) }; 161 | int result; 162 | rex = cre2_new(pattern, strlen(pattern), NULL); 163 | result = cre2_full_match_re(rex, &input, NULL, 0); 164 | cre2_delete(rex); 165 | if (! result) 166 | goto error; 167 | if (0 != strncmp(text, input.data, input.length)) 168 | goto error; 169 | } 170 | { /* success, one parenthetical subexpression, one match entry */ 171 | const char * pattern = "(ciao) salut"; 172 | cre2_regexp_t * rex; 173 | const char * text = "ciao salut"; 174 | cre2_string_t input = { .data = text, .length = strlen(text) }; 175 | int nmatch = 1; 176 | cre2_string_t match[nmatch]; 177 | int result; 178 | rex = cre2_new(pattern, strlen(pattern), NULL); 179 | result = cre2_full_match_re(rex, &input, match, nmatch); 180 | cre2_delete(rex); 181 | if (! result) 182 | goto error; 183 | if (0 != strncmp(text, input.data, input.length)) 184 | goto error; 185 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 186 | goto error; 187 | PRINTF("match 0: "); 188 | FWRITE(match[0].data, match[0].length, 1); 189 | PRINTF("\n"); 190 | } 191 | { /* success, two parenthetical subexpressions, two match entries */ 192 | const char * pattern = "(ciao) (salut)"; 193 | cre2_regexp_t * rex; 194 | const char * text = "ciao salut"; 195 | cre2_string_t input = { .data = text, .length = strlen(text) }; 196 | int nmatch = 2; 197 | cre2_string_t match[nmatch]; 198 | int result; 199 | rex = cre2_new(pattern, strlen(pattern), NULL); 200 | result = cre2_full_match_re(rex, &input, match, nmatch); 201 | cre2_delete(rex); 202 | if (! result) 203 | goto error; 204 | if (0 != strncmp(text, input.data, input.length)) 205 | goto error; 206 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 207 | goto error; 208 | if (0 != strncmp("salut", match[1].data, match[1].length)) 209 | goto error; 210 | PRINTF("match 0: "); 211 | FWRITE(match[0].data, match[0].length, 1); 212 | PRINTF("\n"); 213 | PRINTF("match 1: "); 214 | FWRITE(match[1].data, match[1].length, 1); 215 | PRINTF("\n"); 216 | } 217 | { /* failure, no parentheses */ 218 | const char * pattern = "ci.*ut"; 219 | cre2_regexp_t * rex; 220 | const char * text = "ciao hello"; 221 | cre2_string_t input = { .data = text, .length = strlen(text) }; 222 | int result; 223 | rex = cre2_new(pattern, strlen(pattern), NULL); 224 | result = cre2_full_match_re(rex, &input, NULL, 0); 225 | cre2_delete(rex); 226 | if (result) 227 | goto error; 228 | } 229 | { /* failure, one parenthetical subexpression */ 230 | const char * pattern = "(ciao) salut"; 231 | cre2_regexp_t * rex; 232 | const char * text = "ciao hello"; 233 | cre2_string_t input = { .data = text, .length = strlen(text) }; 234 | int nmatch = 1; 235 | cre2_string_t match[nmatch]; 236 | int result; 237 | rex = cre2_new(pattern, strlen(pattern), NULL); 238 | result = cre2_full_match_re(rex, &input, match, nmatch); 239 | cre2_delete(rex); 240 | if (result) 241 | goto error; 242 | if (0 != strncmp(text, input.data, input.length)) 243 | goto error; 244 | } 245 | { /* success, one parenthetical subexpression, no match entries */ 246 | const char * pattern = "(ciao) salut"; 247 | cre2_regexp_t * rex; 248 | const char * text = "ciao salut"; 249 | cre2_string_t input = { .data = text, .length = strlen(text) }; 250 | int result; 251 | rex = cre2_new(pattern, strlen(pattern), NULL); 252 | result = cre2_full_match_re(rex, &input, NULL, 0); 253 | cre2_delete(rex); 254 | if (! result) 255 | goto error; 256 | if (0 != strncmp(text, input.data, input.length)) 257 | goto error; 258 | } 259 | { /* failure, one parenthetical subexpression, two match entries */ 260 | const char * pattern = "(ciao) salut"; 261 | cre2_regexp_t * rex; 262 | const char * text = "ciao salut"; 263 | cre2_string_t input = { .data = text, .length = strlen(text) }; 264 | int nmatch = 2; 265 | cre2_string_t match[nmatch]; 266 | int result; 267 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 268 | rex = cre2_new(pattern, strlen(pattern), NULL); 269 | result = cre2_full_match_re(rex, &input, match, nmatch); 270 | cre2_delete(rex); 271 | if (0 != result) 272 | goto error; 273 | } 274 | { /* success, two parenthetical subexpressions, one match entry */ 275 | const char * pattern = "(ciao) (salut)"; 276 | cre2_regexp_t * rex; 277 | const char * text = "ciao salut"; 278 | cre2_string_t input = { .data = text, .length = strlen(text) }; 279 | int nmatch = 1; 280 | cre2_string_t match[nmatch]; 281 | int result; 282 | rex = cre2_new(pattern, strlen(pattern), NULL); 283 | result = cre2_full_match_re(rex, &input, match, nmatch); 284 | cre2_delete(rex); 285 | if (! result) 286 | goto error; 287 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 288 | goto error; 289 | if (0 != strncmp(text, input.data, input.length)) 290 | goto error; 291 | PRINTF("match 0: "); 292 | FWRITE(match[0].data, match[0].length, 1); 293 | PRINTF("\n"); 294 | } 295 | 296 | exit(EXIT_SUCCESS); 297 | error: 298 | exit(EXIT_FAILURE); 299 | } 300 | 301 | /* end of file */ 302 | -------------------------------------------------------------------------------- /tests/test-matching.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for matching 4 | Date: Mon Jan 2, 2012 5 | 6 | Abstract 7 | 8 | Test file for regular expressions matching. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | cre2_regexp_t * rex; 25 | cre2_options_t * opt; 26 | const char * pattern; 27 | 28 | /* ------------------------------------------------------------------ */ 29 | /* single match */ 30 | 31 | pattern = "ciao"; 32 | opt = cre2_opt_new(); 33 | cre2_opt_set_posix_syntax(opt, 1); 34 | rex = cre2_new(pattern, strlen(pattern), opt); 35 | { 36 | if (cre2_error_code(rex)) 37 | goto error; 38 | cre2_string_t match; 39 | int nmatch = 1; 40 | int e; 41 | const char * text = "ciao"; 42 | int text_len = strlen(text); 43 | 44 | e = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, &match, nmatch); 45 | if (1 != e) 46 | goto error; 47 | PRINTF("match: retval=%d, ", e); 48 | FWRITE(match.data, match.length, 1); 49 | PRINTF("\n"); 50 | } 51 | cre2_delete(rex); 52 | cre2_opt_delete(opt); 53 | 54 | /* ------------------------------------------------------------------ */ 55 | /* two groups */ 56 | 57 | pattern = "(ciao) (hello)"; 58 | opt = cre2_opt_new(); 59 | rex = cre2_new(pattern, strlen(pattern), opt); 60 | { 61 | if (cre2_error_code(rex)) 62 | goto error; 63 | int nmatch = 3; 64 | cre2_string_t strings[nmatch]; 65 | cre2_range_t ranges[nmatch]; 66 | int e; 67 | const char * text = "ciao hello"; 68 | int text_len = strlen(text); 69 | 70 | e = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, strings, nmatch); 71 | if (1 != e) 72 | goto error; 73 | cre2_strings_to_ranges(text, ranges, strings, nmatch); 74 | PRINTF("full match: "); 75 | FWRITE(text+ranges[0].start, ranges[0].past-ranges[0].start, 1); 76 | PRINTF("\n"); 77 | PRINTF("first group: "); 78 | FWRITE(text+ranges[1].start, ranges[1].past-ranges[1].start, 1); 79 | PRINTF("\n"); 80 | PRINTF("second group: "); 81 | FWRITE(text+ranges[2].start, ranges[2].past-ranges[2].start, 1); 82 | PRINTF("\n"); 83 | } 84 | cre2_delete(rex); 85 | cre2_opt_delete(opt); 86 | 87 | /* ------------------------------------------------------------------ */ 88 | /* test literal option */ 89 | 90 | pattern = "(ciao) (hello)"; 91 | opt = cre2_opt_new(); 92 | cre2_opt_set_literal(opt, 1); 93 | rex = cre2_new(pattern, strlen(pattern), opt); 94 | { 95 | if (cre2_error_code(rex)) 96 | goto error; 97 | int nmatch = 0; 98 | int e; 99 | const char * text = "(ciao) (hello)"; 100 | int text_len = strlen(text); 101 | e = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, NULL, nmatch); 102 | if (0 == e) 103 | goto error; 104 | } 105 | cre2_delete(rex); 106 | cre2_opt_delete(opt); 107 | 108 | /* ------------------------------------------------------------------ */ 109 | /* test named groups */ 110 | 111 | pattern = "from (?P.*) to (?P.*)"; 112 | opt = cre2_opt_new(); 113 | rex = cre2_new(pattern, strlen(pattern), opt); 114 | { 115 | if (cre2_error_code(rex)) 116 | goto error; 117 | int nmatch = cre2_num_capturing_groups(rex) + 1; 118 | cre2_string_t strings[nmatch]; 119 | int e, SIndex, DIndex; 120 | const char * text = "from Montreal, Canada to Lausanne, Switzerland"; 121 | int text_len = strlen(text); 122 | e = cre2_match(rex, text, text_len, 0, text_len, CRE2_UNANCHORED, strings, nmatch); 123 | if (0 == e) 124 | goto error; 125 | SIndex = cre2_find_named_capturing_groups(rex, "S"); 126 | if (0 != strncmp("Montreal, Canada", strings[SIndex].data, strings[SIndex].length)) 127 | goto error; 128 | DIndex = cre2_find_named_capturing_groups(rex, "D"); 129 | if (0 != strncmp("Lausanne, Switzerland", strings[DIndex].data, strings[DIndex].length)) 130 | goto error; 131 | } 132 | cre2_delete(rex); 133 | cre2_opt_delete(opt); 134 | 135 | /* ------------------------------------------------------------------ */ 136 | 137 | 138 | 139 | exit(EXIT_SUCCESS); 140 | error: 141 | exit(EXIT_FAILURE); 142 | } 143 | 144 | /* end of file */ 145 | -------------------------------------------------------------------------------- /tests/test-misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for miscellaneous functions 4 | Date: Wed Jan 4, 2012 5 | 6 | Abstract 7 | 8 | Test file for miscellaneous functions. 9 | 10 | Copyright (C) 2012, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | { /* quote meta characters */ 25 | const char * pattern = "1.5-2.0?"; 26 | cre2_string_t original = { 27 | .data = pattern, 28 | .length = strlen(pattern) 29 | }; 30 | cre2_string_t quoted; 31 | int result; 32 | result = cre2_quote_meta("ed, &original); 33 | if (0 != result) 34 | goto error; 35 | if (0 != strncmp("1\\.5\\-2\\.0\\?", quoted.data, quoted.length)) 36 | goto error; 37 | free((void *)quoted.data); 38 | } 39 | 40 | /* ------------------------------------------------------------------ */ 41 | 42 | { /* minimum and maximum matching strings */ 43 | const char * pattern = "(?i)ABCdef"; 44 | cre2_regexp_t * rex; 45 | cre2_string_t min, max; 46 | int result; 47 | rex = cre2_new(pattern, strlen(pattern), NULL); 48 | { 49 | result = cre2_possible_match_range(rex, &min, &max, 1024); 50 | if (1 != result) 51 | goto error; 52 | if (0 != strncmp("ABCDEF", min.data, min.length)) 53 | goto error; 54 | if (0 != strncmp("abcdef", max.data, max.length)) 55 | goto error; 56 | } 57 | cre2_delete(rex); 58 | free((void *)min.data); 59 | free((void *)max.data); 60 | } 61 | 62 | /* ------------------------------------------------------------------ */ 63 | 64 | { /* successfully check rewrite string */ 65 | const char * pattern = "a(b)c"; 66 | const char * subst = "def"; 67 | cre2_string_t rewrite = { 68 | .data = subst, 69 | .length = strlen(subst) 70 | }; 71 | cre2_regexp_t * rex; 72 | cre2_string_t errmsg; 73 | int result; 74 | rex = cre2_new(pattern, strlen(pattern), NULL); 75 | { 76 | result = cre2_check_rewrite_string(rex, &rewrite, &errmsg); 77 | if (1 != result) 78 | goto error; 79 | } 80 | cre2_delete(rex); 81 | } 82 | { /* failed check rewrite string */ 83 | const char * pattern = "a(b)c"; 84 | const char * subst = "\\1 \\2"; 85 | cre2_string_t rewrite = { 86 | .data = subst, 87 | .length = strlen(subst) 88 | }; 89 | cre2_regexp_t * rex; 90 | cre2_string_t errmsg; 91 | int result; 92 | rex = cre2_new(pattern, strlen(pattern), NULL); 93 | { 94 | result = cre2_check_rewrite_string(rex, &rewrite, &errmsg); 95 | if (0 != result) 96 | goto error; 97 | PRINTF("error message: "); 98 | FWRITE(errmsg.data, errmsg.length, 1); 99 | PRINTF("\n"); 100 | } 101 | cre2_delete(rex); 102 | free((void *)errmsg.data); 103 | } 104 | 105 | /* ------------------------------------------------------------------ */ 106 | 107 | exit(EXIT_SUCCESS); 108 | error: 109 | exit(EXIT_FAILURE); 110 | } 111 | 112 | /* end of file */ 113 | -------------------------------------------------------------------------------- /tests/test-options.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for options 4 | Date: Mon Jan 2, 2012 5 | 6 | Abstract 7 | 8 | Test file for options objects. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include "cre2-test.h" 19 | 20 | int 21 | main (void) 22 | { 23 | cre2_options_t * opt; 24 | 25 | opt = cre2_opt_new(); 26 | { 27 | cre2_opt_set_posix_syntax(opt, 1); 28 | cre2_opt_set_longest_match(opt, 1); 29 | cre2_opt_set_log_errors(opt, 1); 30 | cre2_opt_set_literal(opt, 1); 31 | cre2_opt_set_never_nl(opt, 1); 32 | cre2_opt_set_dot_nl(opt, 1); 33 | cre2_opt_set_never_capture(opt, 1); 34 | cre2_opt_set_case_sensitive(opt, 1); 35 | cre2_opt_set_perl_classes(opt, 1); 36 | cre2_opt_set_word_boundary(opt, 1); 37 | cre2_opt_set_one_line(opt, 1); 38 | cre2_opt_set_encoding(opt, CRE2_UTF8); 39 | cre2_opt_set_encoding(opt, CRE2_Latin1); 40 | cre2_opt_set_max_mem(opt, 4096); 41 | } 42 | cre2_opt_delete(opt); 43 | exit(EXIT_SUCCESS); 44 | } 45 | 46 | /* end of file */ 47 | -------------------------------------------------------------------------------- /tests/test-partial-match.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for partial match function 4 | Date: Tue Jan 3, 2012 5 | 6 | Abstract 7 | 8 | Test file for partial match function. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | { /* success, no parentheses */ 25 | const char * pattern = "ci.*ut"; 26 | const char * text = "pre ciao salut post"; 27 | cre2_string_t input = { .data = text, .length = strlen(text) }; 28 | int result; 29 | result = cre2_partial_match(pattern, &input, NULL, 0); 30 | if (! result) 31 | goto error; 32 | if (0 != strncmp(text, input.data, input.length)) 33 | goto error; 34 | } 35 | { /* success, one parenthetical subexpression, one match entry */ 36 | const char * pattern = "(ciao) salut"; 37 | const char * text = "ciao salut"; 38 | cre2_string_t input = { .data = text, .length = strlen(text) }; 39 | int nmatch = 1; 40 | cre2_string_t match[nmatch]; 41 | int result; 42 | result = cre2_partial_match(pattern, &input, match, nmatch); 43 | if (! result) 44 | goto error; 45 | if (0 != strncmp(text, input.data, input.length)) 46 | goto error; 47 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 48 | goto error; 49 | PRINTF("match 0: "); 50 | FWRITE(match[0].data, match[0].length, 1); 51 | PRINTF("\n"); 52 | } 53 | { /* success, two parenthetical subexpressions, two match entries */ 54 | const char * pattern = "(ciao) (salut)"; 55 | const char * text = "ciao salut"; 56 | cre2_string_t input = { .data = text, .length = strlen(text) }; 57 | int nmatch = 2; 58 | cre2_string_t match[nmatch]; 59 | int result; 60 | result = cre2_partial_match(pattern, &input, match, nmatch); 61 | if (! result) 62 | goto error; 63 | if (0 != strncmp(text, input.data, input.length)) 64 | goto error; 65 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 66 | goto error; 67 | if (0 != strncmp("salut", match[1].data, match[1].length)) 68 | goto error; 69 | PRINTF("match 0: "); 70 | FWRITE(match[0].data, match[0].length, 1); 71 | PRINTF("\n"); 72 | PRINTF("match 1: "); 73 | FWRITE(match[1].data, match[1].length, 1); 74 | PRINTF("\n"); 75 | } 76 | { /* failure, no parentheses */ 77 | const char * pattern = "ci.*ut"; 78 | const char * text = "ciao hello"; 79 | cre2_string_t input = { .data = text, .length = strlen(text) }; 80 | int result; 81 | result = cre2_partial_match(pattern, &input, NULL, 0); 82 | if (result) 83 | goto error; 84 | } 85 | { /* failure, one parenthetical subexpression */ 86 | const char * pattern = "(ciao) salut"; 87 | const char * text = "ciao hello"; 88 | cre2_string_t input = { .data = text, .length = strlen(text) }; 89 | int nmatch = 1; 90 | cre2_string_t match[nmatch]; 91 | int result; 92 | result = cre2_partial_match(pattern, &input, match, nmatch); 93 | if (result) 94 | goto error; 95 | if (0 != strncmp(text, input.data, input.length)) 96 | goto error; 97 | } 98 | { /* success, one parenthetical subexpression, no match entries */ 99 | const char * pattern = "(ciao) salut"; 100 | const char * text = "ciao salut"; 101 | cre2_string_t input = { .data = text, .length = strlen(text) }; 102 | int result; 103 | result = cre2_partial_match(pattern, &input, NULL, 0); 104 | if (! result) 105 | goto error; 106 | if (0 != strncmp(text, input.data, input.length)) 107 | goto error; 108 | } 109 | { /* failure, one parenthetical subexpression, two match entries */ 110 | const char * pattern = "(ciao) salut"; 111 | const char * text = "ciao salut"; 112 | cre2_string_t input = { .data = text, .length = strlen(text) }; 113 | int nmatch = 2; 114 | cre2_string_t match[nmatch]; 115 | int result; 116 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 117 | result = cre2_partial_match(pattern, &input, match, nmatch); 118 | if (0 != result) 119 | goto error; 120 | } 121 | { /* success, two parenthetical subexpressions, one match entry */ 122 | const char * pattern = "(ciao) (salut)"; 123 | const char * text = "ciao salut"; 124 | cre2_string_t input = { .data = text, .length = strlen(text) }; 125 | int nmatch = 1; 126 | cre2_string_t match[nmatch]; 127 | int result; 128 | result = cre2_partial_match(pattern, &input, match, nmatch); 129 | if (! result) 130 | goto error; 131 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 132 | goto error; 133 | if (0 != strncmp(text, input.data, input.length)) 134 | goto error; 135 | PRINTF("match 0: "); 136 | FWRITE(match[0].data, match[0].length, 1); 137 | PRINTF("\n"); 138 | } 139 | { /* wrong regexp specification */ 140 | const char * pattern = "cia(o salut"; 141 | const char * text = "ciao hello"; 142 | cre2_string_t input = { .data = text, .length = strlen(text) }; 143 | int nmatch = 1; 144 | cre2_string_t match[nmatch]; 145 | int result; 146 | result = cre2_partial_match(pattern, &input, match, nmatch); 147 | if (0 != result) 148 | goto error; 149 | if (0 != strncmp(text, input.data, input.length)) 150 | goto error; 151 | } 152 | 153 | 154 | /* ------------------------------------------------------------------ */ 155 | 156 | { /* success, no parentheses */ 157 | const char * pattern = "ci.*ut"; 158 | cre2_regexp_t * rex; 159 | const char * text = "ciao salut"; 160 | cre2_string_t input = { .data = text, .length = strlen(text) }; 161 | int result; 162 | rex = cre2_new(pattern, strlen(pattern), NULL); 163 | result = cre2_partial_match_re(rex, &input, NULL, 0); 164 | cre2_delete(rex); 165 | if (! result) 166 | goto error; 167 | if (0 != strncmp(text, input.data, input.length)) 168 | goto error; 169 | } 170 | { /* success, one parenthetical subexpression, one match entry */ 171 | const char * pattern = "(ciao) salut"; 172 | cre2_regexp_t * rex; 173 | const char * text = "ciao salut"; 174 | cre2_string_t input = { .data = text, .length = strlen(text) }; 175 | int nmatch = 1; 176 | cre2_string_t match[nmatch]; 177 | int result; 178 | rex = cre2_new(pattern, strlen(pattern), NULL); 179 | result = cre2_partial_match_re(rex, &input, match, nmatch); 180 | cre2_delete(rex); 181 | if (! result) 182 | goto error; 183 | if (0 != strncmp(text, input.data, input.length)) 184 | goto error; 185 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 186 | goto error; 187 | PRINTF("match 0: "); 188 | FWRITE(match[0].data, match[0].length, 1); 189 | PRINTF("\n"); 190 | } 191 | { /* success, two parenthetical subexpressions, two match entries */ 192 | const char * pattern = "(ciao) (salut)"; 193 | cre2_regexp_t * rex; 194 | const char * text = "ciao salut"; 195 | cre2_string_t input = { .data = text, .length = strlen(text) }; 196 | int nmatch = 2; 197 | cre2_string_t match[nmatch]; 198 | int result; 199 | rex = cre2_new(pattern, strlen(pattern), NULL); 200 | result = cre2_partial_match_re(rex, &input, match, nmatch); 201 | cre2_delete(rex); 202 | if (! result) 203 | goto error; 204 | if (0 != strncmp(text, input.data, input.length)) 205 | goto error; 206 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 207 | goto error; 208 | if (0 != strncmp("salut", match[1].data, match[1].length)) 209 | goto error; 210 | PRINTF("match 0: "); 211 | FWRITE(match[0].data, match[0].length, 1); 212 | PRINTF("\n"); 213 | PRINTF("match 1: "); 214 | FWRITE(match[1].data, match[1].length, 1); 215 | PRINTF("\n"); 216 | } 217 | { /* failure, no parentheses */ 218 | const char * pattern = "ci.*ut"; 219 | cre2_regexp_t * rex; 220 | const char * text = "ciao hello"; 221 | cre2_string_t input = { .data = text, .length = strlen(text) }; 222 | int result; 223 | rex = cre2_new(pattern, strlen(pattern), NULL); 224 | result = cre2_partial_match_re(rex, &input, NULL, 0); 225 | cre2_delete(rex); 226 | if (result) 227 | goto error; 228 | } 229 | { /* failure, one parenthetical subexpression */ 230 | const char * pattern = "(ciao) salut"; 231 | cre2_regexp_t * rex; 232 | const char * text = "ciao hello"; 233 | cre2_string_t input = { .data = text, .length = strlen(text) }; 234 | int nmatch = 1; 235 | cre2_string_t match[nmatch]; 236 | int result; 237 | rex = cre2_new(pattern, strlen(pattern), NULL); 238 | result = cre2_partial_match_re(rex, &input, match, nmatch); 239 | cre2_delete(rex); 240 | if (result) 241 | goto error; 242 | if (0 != strncmp(text, input.data, input.length)) 243 | goto error; 244 | } 245 | { /* success, one parenthetical subexpression, no match entries */ 246 | const char * pattern = "(ciao) salut"; 247 | cre2_regexp_t * rex; 248 | const char * text = "ciao salut"; 249 | cre2_string_t input = { .data = text, .length = strlen(text) }; 250 | int result; 251 | rex = cre2_new(pattern, strlen(pattern), NULL); 252 | result = cre2_partial_match_re(rex, &input, NULL, 0); 253 | cre2_delete(rex); 254 | if (! result) 255 | goto error; 256 | if (0 != strncmp(text, input.data, input.length)) 257 | goto error; 258 | } 259 | { /* failure, one parenthetical subexpression, two match entries */ 260 | const char * pattern = "(ciao) salut"; 261 | cre2_regexp_t * rex; 262 | const char * text = "ciao salut"; 263 | cre2_string_t input = { .data = text, .length = strlen(text) }; 264 | int nmatch = 2; 265 | cre2_string_t match[nmatch]; 266 | int result; 267 | memset(match, '\0', nmatch * sizeof(cre2_string_t)); 268 | rex = cre2_new(pattern, strlen(pattern), NULL); 269 | result = cre2_partial_match_re(rex, &input, match, nmatch); 270 | cre2_delete(rex); 271 | if (0 != result) 272 | goto error; 273 | } 274 | { /* success, two parenthetical subexpressions, one match entry */ 275 | const char * pattern = "(ciao) (salut)"; 276 | cre2_regexp_t * rex; 277 | const char * text = "ciao salut"; 278 | cre2_string_t input = { .data = text, .length = strlen(text) }; 279 | int nmatch = 1; 280 | cre2_string_t match[nmatch]; 281 | int result; 282 | rex = cre2_new(pattern, strlen(pattern), NULL); 283 | result = cre2_partial_match_re(rex, &input, match, nmatch); 284 | cre2_delete(rex); 285 | if (! result) 286 | goto error; 287 | if (0 != strncmp("ciao", match[0].data, match[0].length)) 288 | goto error; 289 | if (0 != strncmp(text, input.data, input.length)) 290 | goto error; 291 | PRINTF("match 0: "); 292 | FWRITE(match[0].data, match[0].length, 1); 293 | PRINTF("\n"); 294 | } 295 | 296 | exit(EXIT_SUCCESS); 297 | error: 298 | exit(EXIT_FAILURE); 299 | } 300 | 301 | /* end of file */ 302 | -------------------------------------------------------------------------------- /tests/test-replace.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for replace 4 | Date: Wed Jan 4, 2012 5 | 6 | Abstract 7 | 8 | Test file for replacing. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | { /* replace all the buffer using the full match */ 25 | cre2_regexp_t * rex; 26 | const char * pattern = "ciao hello salut"; 27 | const char * text = "ciao hello salut"; 28 | const char * replace = "pre \\0 post"; 29 | cre2_string_t target = { 30 | .data = text, 31 | .length = strlen(text) 32 | }; 33 | cre2_string_t rewrite = { 34 | .data = replace, 35 | .length = strlen(replace) 36 | }; 37 | int result; 38 | rex = cre2_new(pattern, strlen(pattern), NULL); 39 | { 40 | result = cre2_replace_re(rex, &target, &rewrite); 41 | if (1 != result) 42 | goto error; 43 | if (0 != strncmp("pre ciao hello salut post", target.data, target.length)) 44 | goto error; 45 | if ('\0' != target.data[target.length]) 46 | goto error; 47 | PRINTF("rewritten to: "); 48 | FWRITE(target.data, target.length, 1); 49 | PRINTF("\n"); 50 | } 51 | cre2_delete(rex); 52 | free((void *)target.data); 53 | } 54 | { /* replace substring with fixed string */ 55 | cre2_regexp_t * rex; 56 | const char * pattern = "hello"; 57 | const char * text = "ciao hello salut"; 58 | const char * replace = "ohayo"; 59 | cre2_string_t target = { 60 | .data = text, 61 | .length = strlen(text) 62 | }; 63 | cre2_string_t rewrite = { 64 | .data = replace, 65 | .length = strlen(replace) 66 | }; 67 | int result; 68 | rex = cre2_new(pattern, strlen(pattern), NULL); 69 | { 70 | result = cre2_replace_re(rex, &target, &rewrite); 71 | if (1 != result) 72 | goto error; 73 | if (0 != strncmp("ciao ohayo salut", target.data, target.length)) 74 | goto error; 75 | if ('\0' != target.data[target.length]) 76 | goto error; 77 | PRINTF("rewritten to: "); 78 | FWRITE(target.data, target.length, 1); 79 | PRINTF("\n"); 80 | } 81 | cre2_delete(rex); 82 | free((void *)target.data); 83 | } 84 | 85 | /* ------------------------------------------------------------------ */ 86 | 87 | { /* global replace all the buffer using the full match */ 88 | cre2_regexp_t * rex; 89 | const char * pattern = "ciao hello salut"; 90 | const char * text = "ciao hello salut"; 91 | const char * replace = "pre \\0 post"; 92 | cre2_string_t target = { 93 | .data = text, 94 | .length = strlen(text) 95 | }; 96 | cre2_string_t rewrite = { 97 | .data = replace, 98 | .length = strlen(replace) 99 | }; 100 | int result; 101 | rex = cre2_new(pattern, strlen(pattern), NULL); 102 | { 103 | result = cre2_global_replace_re(rex, &target, &rewrite); 104 | if (1 != result) 105 | goto error; 106 | if (0 != strncmp("pre ciao hello salut post", target.data, target.length)) 107 | goto error; 108 | if ('\0' != target.data[target.length]) 109 | goto error; 110 | PRINTF("rewritten to: "); 111 | FWRITE(target.data, target.length, 1); 112 | PRINTF("\n"); 113 | } 114 | cre2_delete(rex); 115 | free((void *)target.data); 116 | } 117 | { /* global replace substring with fixed string */ 118 | cre2_regexp_t * rex; 119 | const char * pattern = "hello"; 120 | const char * text = "ciao hello salut"; 121 | const char * replace = "ohayo"; 122 | cre2_string_t target = { 123 | .data = text, 124 | .length = strlen(text) 125 | }; 126 | cre2_string_t rewrite = { 127 | .data = replace, 128 | .length = strlen(replace) 129 | }; 130 | int result; 131 | rex = cre2_new(pattern, strlen(pattern), NULL); 132 | { 133 | result = cre2_global_replace_re(rex, &target, &rewrite); 134 | if (1 != result) 135 | goto error; 136 | if (0 != strncmp("ciao ohayo salut", target.data, target.length)) 137 | goto error; 138 | if ('\0' != target.data[target.length]) 139 | goto error; 140 | PRINTF("rewritten to: "); 141 | FWRITE(target.data, target.length, 1); 142 | PRINTF("\n"); 143 | } 144 | cre2_delete(rex); 145 | free((void *)target.data); 146 | } 147 | { /* global replace multiple substrings with parametrised string */ 148 | cre2_regexp_t * rex; 149 | const char * pattern = "[a-z]+\\(([0-9]+)\\)"; 150 | const char * text = "ciao(1) hello(2) salut(3)"; 151 | const char * replace = "ohayo(\\1)"; 152 | cre2_string_t target = { 153 | .data = text, 154 | .length = strlen(text) 155 | }; 156 | cre2_string_t rewrite = { 157 | .data = replace, 158 | .length = strlen(replace) 159 | }; 160 | int result; 161 | rex = cre2_new(pattern, strlen(pattern), NULL); 162 | { 163 | result = cre2_global_replace_re(rex, &target, &rewrite); 164 | if (3 != result) /* 3 substitutions */ 165 | goto error; 166 | if (0 != strncmp("ohayo(1) ohayo(2) ohayo(3)", target.data, target.length)) 167 | goto error; 168 | if ('\0' != target.data[target.length]) 169 | goto error; 170 | PRINTF("result %d, rewritten to: ", result); 171 | FWRITE(target.data, target.length, 1); 172 | PRINTF("\n"); 173 | } 174 | cre2_delete(rex); 175 | free((void *)target.data); 176 | } 177 | 178 | /* ------------------------------------------------------------------ */ 179 | 180 | { /* extract all the buffer using the full match */ 181 | cre2_regexp_t * rex; 182 | const char * pattern = "ciao hello salut"; 183 | const char * text = "ciao hello salut"; 184 | const char * replace = "pre \\0 post"; 185 | cre2_string_t input = { 186 | .data = text, 187 | .length = strlen(text) 188 | }; 189 | cre2_string_t rewrite = { 190 | .data = replace, 191 | .length = strlen(replace) 192 | }; 193 | cre2_string_t target; 194 | int result; 195 | rex = cre2_new(pattern, strlen(pattern), NULL); 196 | { 197 | result = cre2_extract_re(rex, &input, &rewrite, &target); 198 | if (1 != result) 199 | goto error; 200 | if (0 != strncmp("pre ciao hello salut post", target.data, target.length)) 201 | goto error; 202 | if ('\0' != target.data[target.length]) 203 | goto error; 204 | PRINTF("rewritten to: "); 205 | FWRITE(target.data, target.length, 1); 206 | PRINTF("\n"); 207 | } 208 | cre2_delete(rex); 209 | free((void *)target.data); 210 | } 211 | { /* extract substring with fixed string */ 212 | cre2_regexp_t * rex; 213 | const char * pattern = "hello([0-9]+)"; 214 | const char * text = "ciao hello123 salut"; 215 | const char * replace = "ohayo\\1"; 216 | cre2_string_t input = { 217 | .data = text, 218 | .length = strlen(text) 219 | }; 220 | cre2_string_t rewrite = { 221 | .data = replace, 222 | .length = strlen(replace) 223 | }; 224 | cre2_string_t target; 225 | int result; 226 | rex = cre2_new(pattern, strlen(pattern), NULL); 227 | { 228 | result = cre2_extract_re(rex, &input, &rewrite, &target); 229 | if (1 != result) 230 | goto error; 231 | if (0 != strncmp("ohayo123", target.data, target.length)) 232 | goto error; 233 | if ('\0' != target.data[target.length]) 234 | goto error; 235 | PRINTF("rewritten to: "); 236 | FWRITE(target.data, target.length, 1); 237 | PRINTF("\n"); 238 | } 239 | cre2_delete(rex); 240 | free((void *)target.data); 241 | } 242 | 243 | /* ------------------------------------------------------------------ */ 244 | 245 | exit(EXIT_SUCCESS); 246 | error: 247 | exit(EXIT_FAILURE); 248 | } 249 | 250 | /* end of file */ 251 | -------------------------------------------------------------------------------- /tests/test-rex-alloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for rex allocation 4 | Date: Mon Jan 2, 2012 5 | 6 | Abstract 7 | 8 | Test file for regular expressions allocation. 9 | 10 | Copyright (C) 2012, 2016, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | int 22 | main (void) 23 | { 24 | cre2_regexp_t * rex; 25 | cre2_options_t * opt; 26 | opt = cre2_opt_new(); 27 | cre2_opt_set_posix_syntax(opt, 1); 28 | rex = cre2_new("ciao", 4, opt); 29 | { 30 | cre2_string_t S; 31 | PRINTF("pattern: %s\n", cre2_pattern(rex)); 32 | PRINTF("error code: %d\n", cre2_error_code(rex)); 33 | PRINTF("error string: \"%s\"\n", cre2_error_string(rex)); 34 | PRINTF("number of capturing groups: %d\n", cre2_num_capturing_groups(rex)); 35 | PRINTF("program size: %d\n", cre2_program_size(rex)); 36 | cre2_error_arg(rex, &S); 37 | PRINTF("error arg: len=%d, data=\"%s\"\n", S.length, S.data); 38 | if (cre2_error_code(rex)) 39 | goto error; 40 | if (cre2_num_capturing_groups(rex)) 41 | goto error; 42 | if (cre2_error_code(rex)) 43 | goto error; 44 | if (0 != strlen(cre2_error_string(rex))) 45 | goto error; 46 | if (0 != S.length) 47 | goto error; 48 | } 49 | cre2_delete(rex); 50 | cre2_opt_delete(opt); 51 | 52 | /* ------------------------------------------------------------------ */ 53 | /* no options object */ 54 | 55 | rex = cre2_new("ciao", 4, NULL); 56 | { 57 | if (cre2_error_code(rex)) 58 | goto error; 59 | } 60 | cre2_delete(rex); 61 | 62 | /* ------------------------------------------------------------------ */ 63 | 64 | opt = cre2_opt_new(); 65 | cre2_opt_set_posix_syntax(opt, 1); 66 | rex = cre2_new("ci(ao)", 6, opt); 67 | { 68 | PRINTF("error code: %d\n", cre2_error_code(rex)); 69 | PRINTF("number of capturing groups: %d\n", cre2_num_capturing_groups(rex)); 70 | PRINTF("program size: %d\n", cre2_program_size(rex)); 71 | if (cre2_error_code(rex)) 72 | goto error; 73 | if (1 != cre2_num_capturing_groups(rex)) 74 | goto error; 75 | } 76 | cre2_delete(rex); 77 | cre2_opt_delete(opt); 78 | 79 | /* ------------------------------------------------------------------ */ 80 | 81 | opt = cre2_opt_new(); 82 | cre2_opt_set_log_errors(opt, 0); 83 | rex = cre2_new("ci(ao", 5, opt); 84 | { 85 | int code = cre2_error_code(rex); 86 | const char * msg = cre2_error_string(rex); 87 | cre2_string_t S; 88 | cre2_error_arg(rex, &S); 89 | if (CRE2_ERROR_MISSING_PAREN != code) 90 | goto error; 91 | if (! msg) 92 | goto error; 93 | PRINTF("pattern: %s\n", cre2_pattern(rex)); 94 | PRINTF("error: code=%d, msg=\"%s\"\n", code, msg); 95 | PRINTF("error arg: len=%d, data=\"%s\"\n", S.length, S.data); 96 | } 97 | cre2_delete(rex); 98 | cre2_opt_delete(opt); 99 | 100 | exit(EXIT_SUCCESS); 101 | 102 | error: 103 | exit(EXIT_FAILURE); 104 | } 105 | 106 | /* end of file */ 107 | -------------------------------------------------------------------------------- /tests/test-set.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for Set 4 | Date: Thu Mar 3, 2016 5 | 6 | Abstract 7 | 8 | Test file for set of regular expressions matching. 9 | 10 | See the COPYING file. 11 | */ 12 | 13 | #define CRE2_ENABLE_DEBUGGING 1 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "cre2-test.h" 20 | 21 | #define FATAL(...) \ 22 | PRINTF(__VA_ARGS__);\ 23 | goto error 24 | 25 | int 26 | main (void) 27 | { 28 | /* ------------------------------------------------------------------ */ 29 | /* definition of patterns match */ 30 | 31 | const char * const pattern0 = "hello"; 32 | const char * const pattern1 = "world"; 33 | const char * const pattern2 = "po.*ar"; 34 | const char * const pattern3 = "(invalid"; 35 | char *text; 36 | int index; 37 | 38 | // create set 39 | cre2_options_t *opt = cre2_opt_new(); 40 | cre2_set *set = cre2_set_new(opt, CRE2_UNANCHORED); 41 | if (set == NULL) { 42 | FATAL("Error creating the cre2_set"); 43 | } 44 | 45 | // Add patterns 46 | index = cre2_set_add_simple(set, pattern0); 47 | if (0 == index) { 48 | PRINTF("Correctly added pattern0: %s\n", pattern0); 49 | } else { 50 | FATAL("Failed adding pattern %i to set. cre2_set_add_simple returned %i", 0, index); 51 | } 52 | index = cre2_set_add_simple(set, pattern1); 53 | if (1 == index) { 54 | PRINTF("Correctly added pattern1: %s\n", pattern1); 55 | } else { 56 | FATAL("Failed adding pattern %i to set. cre2_set_add_simple returned %i", 1, index); 57 | } 58 | index = cre2_set_add_simple(set, pattern2); 59 | if (2 == index) { 60 | PRINTF("Correctly added pattern2: %s\n", pattern2); 61 | } else { 62 | FATAL("Failed adding pattern %i to set. cre2_set_add_simple returned %i", 2, index); 63 | } 64 | 65 | // Try to add invalid pattern 66 | #define ERROR_LEN 100 67 | char error[ERROR_LEN]; 68 | index = cre2_set_add(set, pattern3, strlen(pattern3), error, ERROR_LEN); 69 | if (-1 == index) { 70 | PRINTF("Correct error message from cre2_set_add() for invalid pattern2: \"%s\"\n", error); 71 | } else { 72 | FATAL("Error: successfully added an invalid pattern3 to set."); 73 | } 74 | 75 | // Compile regex set 76 | if (!cre2_set_compile(set)) { 77 | FATAL("Failed to compile regex set."); 78 | } 79 | 80 | int match[3]; 81 | int count; 82 | 83 | // Test first match 84 | text = "hello world!"; 85 | count = cre2_set_match(set, text, strlen(text), match, 3); 86 | if (count != 2 || match[0] != 0 || match[1] != 1) { 87 | FATAL("Failed to match: %s", text); 88 | } else { 89 | PRINTF("Correctly matched: %s\n", text); 90 | } 91 | 92 | // Test second match 93 | text = "blabla hello polar bear!"; 94 | count = cre2_set_match(set, text, strlen(text), match, 3); 95 | if (count != 2 || match[0] != 0 || match[1] != 2) { 96 | FATAL("Failed to match: %s", text); 97 | } else { 98 | PRINTF("Correctly matched: %s\n", text); 99 | } 100 | 101 | // Test third match 102 | text = "this should not match anything"; 103 | count = cre2_set_match(set, text, strlen(text), match, 3); 104 | if (count != 0) { 105 | FATAL("Failed to match: %s", text); 106 | } else { 107 | PRINTF("Correctly not-matched: %s\n", text); 108 | } 109 | 110 | /* ------------------------------------------------------------------ */ 111 | 112 | cre2_opt_delete(opt); 113 | cre2_set_delete(set); 114 | exit(EXIT_SUCCESS); 115 | error: 116 | exit(EXIT_FAILURE); 117 | } 118 | 119 | /* end of file */ 120 | -------------------------------------------------------------------------------- /tests/test-version.c: -------------------------------------------------------------------------------- 1 | /* 2 | Part of: CRE2 3 | Contents: test for version functions 4 | Date: Mon Jan 2, 2012 5 | 6 | Abstract 7 | 8 | Test file for version functions. 9 | 10 | Copyright (C) 2012, 2017 Marco Maggi 11 | 12 | See the COPYING file. 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | int 20 | main (void) 21 | { 22 | printf("version number string: %s\n", cre2_version_string()); 23 | printf("libtool version number: %d:%d:%d\n", 24 | cre2_version_interface_current(), 25 | cre2_version_interface_revision(), 26 | cre2_version_interface_age()); 27 | exit(EXIT_SUCCESS); 28 | } 29 | 30 | /* end of file */ 31 | --------------------------------------------------------------------------------