A portable Fortran module for the Perl compatible regular expressions (in Unix).
Notes for "pcreposix":
- PCRE: Perl-Compatible Regular Expressions
- POSIX: Portable Operating System Interface, where X may stand for Unix (??? :D)
1) Requires. Make sure that the libs of pcre and pcreposix (i.e. libpcre.a and libpcreposix.a) were installed in our system. For instance, in Debian 8 (Jessie), we can install it quickly using the apt-get command:
- sudo apt-get install libpcre3 libpcre3-dev
and we should have
- /usr/include/pcreposix.h
- /usr/lib/x86_64-linux-gnu/libpcreposix.a
Further ref. for Debian,
https://manpages.debian.org/jessie/libpcre3-dev/pcreposix.3.en.html
and for Centos,
https://centos.pkgs.org/7/centos-x86_64/pcre-8.32-17.el7.x86_64.rpm.html
2) Provides. Files:
- dep_pcreposix.c: C code wrapping the pcreposix functions
- mod_pcreposix.f90: Fortran module binding with the C code
- t_pcreposix_01.f90: A testing program. To compile, read its head or the make.sh. To know how to run, type the command ./t_pcreposix_01.exe without arguments.
- t_pcreposix_gen.sh: A Bash script to perform 30 test cases which are copied from
https://github.com/niklongstone/regular-expression-cheat-sheet
and some other cases from
The fortran_pcre package is excelent but this mod_pcreposix goes without the iso_c_binding module. It's just simple.
- make.sh: a Bash script. All (compiling, linking, running tests) will run after this command ./make.sh
3) Compiles.
- gcc -O3 -Wall -c dep_pcreposix.c
- gfortran -O3 -Wall -c mod_pcreposix.f90
- gfortran -O3 -Wall t_pcreposix_01.f90 *.o -lpcreposix -o t_pcreposix_01.exe
4) Tests. Run all the tests (30+ cases, or you can add more by yourself) by the command
- ./t_pcreposix_gen.sh ./t_pcreposix_01.exe
Make sure all the Bash scripts had the executable permission, or add it using the command
- chmod +x *.sh
5) Run all. To run all after this command
- ./make.sh
USAGE:
1. call pcre_regcomp ( preg, pattern, istat )
2. call pcre_regexec ( preg, str, pmatch, nmatch, nfound )
3. call pcre_regfree ( preg )
where
preg integer(kind=8)
pattern character(len=*)
istat integer(kind=4)
str character(len=*)
pmatch integer(kind=4), dimension(2,nmatch)
nmatch integer(kind=4)
nfound integer(kind=4)
The package was well tested in Debian 9 (4.9.0-12-amd64) with gcc version 6.3.0.
Report on any bug of this code at [email protected].
UPDATE:
-
exe_param.c: C code generating parameters for mod_pcreposix.f90 in-situ.
-
make.sh has been changed. At the very first time, run
./make.sh config
to revise mod_pcreposix.f90 accordingly to your local system, because the C code exe_param.c will be compiled so as it can generate values of the parameters within the region marked by
!@@@@@BeginParam
...
!@@@@@EndParam
in the Fortran file. Just do it only one time. In addition, run
./make.sh clean
to clean out.