| 16 |
Documentation for PCRE |
Documentation for PCRE |
| 17 |
Contributions by users of PCRE |
Contributions by users of PCRE |
| 18 |
Building PCRE on non-Unix systems |
Building PCRE on non-Unix systems |
| 19 |
Building PCRE on a Unix-like system |
Building PCRE on Unix-like systems |
| 20 |
Retrieving configuration information on a Unix-like system |
Retrieving configuration information on Unix-like systems |
| 21 |
Shared libraries on Unix-like systems |
Shared libraries on Unix-like systems |
| 22 |
Cross-compiling on a Unix-like system |
Cross-compiling on Unix-like systems |
| 23 |
Using HP's ANSI C++ compiler (aCC) |
Using HP's ANSI C++ compiler (aCC) |
| 24 |
Making new tarballs |
Making new tarballs |
| 25 |
Testing PCRE |
Testing PCRE |
| 53 |
up the POSIX functions of the same name from the other library. |
up the POSIX functions of the same name from the other library. |
| 54 |
|
|
| 55 |
One way of avoiding this confusion is to compile PCRE with the addition of |
One way of avoiding this confusion is to compile PCRE with the addition of |
| 56 |
-Dregcomp=PCREregcomp (and similarly for the other functions) to the compiler |
-Dregcomp=PCREregcomp (and similarly for the other POSIX functions) to the |
| 57 |
flags (CFLAGS if you are using "configure" -- see below). This has the effect |
compiler flags (CFLAGS if you are using "configure" -- see below). This has the |
| 58 |
of renaming the functions so that the names no longer clash. Of course, you |
effect of renaming the functions so that the names no longer clash. Of course, |
| 59 |
have to do the same thing for your applications, or write them using the new |
you have to do the same thing for your applications, or write them using the |
| 60 |
names. |
new names. |
| 61 |
|
|
| 62 |
|
|
| 63 |
Documentation for PCRE |
Documentation for PCRE |
| 64 |
---------------------- |
---------------------- |
| 65 |
|
|
| 66 |
If you install PCRE in the normal way, you will end up with an installed set of |
If you install PCRE in the normal way on a Unix-like system, you will end up |
| 67 |
man pages whose names all start with "pcre". The one that is just called "pcre" |
with a set of man pages whose names all start with "pcre". The one that is just |
| 68 |
lists all the others. In addition to these man pages, the PCRE documentation is |
called "pcre" lists all the others. In addition to these man pages, the PCRE |
| 69 |
supplied in two other forms: |
documentation is supplied in two other forms: |
| 70 |
|
|
| 71 |
1. There are files called doc/pcre.txt, doc/pcregrep.txt, and |
1. There are files called doc/pcre.txt, doc/pcregrep.txt, and |
| 72 |
doc/pcretest.txt in the source distribution. The first of these is a |
doc/pcretest.txt in the source distribution. The first of these is a |
| 78 |
<prefix> is the installation prefix (defaulting to /usr/local). |
<prefix> is the installation prefix (defaulting to /usr/local). |
| 79 |
|
|
| 80 |
2. A set of files containing all the documentation in HTML form, hyperlinked |
2. A set of files containing all the documentation in HTML form, hyperlinked |
| 81 |
in various ways, and rooted in a file called index.html, is installed in |
in various ways, and rooted in a file called index.html, is distributed in |
| 82 |
the directory <prefix>/share/doc/pcre/html. |
doc/html and installed in <prefix>/share/doc/pcre/html. |
| 83 |
|
|
| 84 |
|
|
| 85 |
Contributions by users of PCRE |
Contributions by users of PCRE |
| 89 |
|
|
| 90 |
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib |
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib |
| 91 |
|
|
| 92 |
where there is also a README file giving brief descriptions of what they are. |
There is a README file giving brief descriptions of what they are. Some are |
| 93 |
Some are complete in themselves; others are pointers to URLs containing |
complete in themselves; others are pointers to URLs containing relevant files. |
| 94 |
relevant files. Some of this material is likely to be well out-of-date. In |
Some of this material is likely to be well out-of-date. In particular, several |
| 95 |
particular, several of the contributions provide support for compiling PCRE on |
of the contributions provide support for compiling PCRE on various flavours of |
| 96 |
various flavours of Windows (I myself do not use Windows), but it is hoped that |
Windows (I myself do not use Windows), but nowadays there is more Windows |
| 97 |
more Windows support will find its way into the standard distribution. |
support in the standard distribution. |
| 98 |
|
|
| 99 |
|
|
| 100 |
Building PCRE on non-Unix systems |
Building PCRE on non-Unix systems |
| 101 |
--------------------------------- |
--------------------------------- |
| 102 |
|
|
| 103 |
For a non-Unix system, read the comments in the file NON-UNIX-USE, though if |
For a non-Unix system, please read the comments in the file NON-UNIX-USE, |
| 104 |
the system supports the use of "configure" and "make" you may be able to build |
though if your system supports the use of "configure" and "make" you may be |
| 105 |
PCRE in the same way as for Unix-like systems. |
able to build PCRE in the same way as for Unix-like systems. |
| 106 |
|
|
| 107 |
PCRE has been compiled on many different operating systems. It should be |
PCRE has been compiled on many different operating systems. It should be |
| 108 |
straightforward to build PCRE on any system that has a Standard C compiler and |
straightforward to build PCRE on any system that has a Standard C compiler and |
| 109 |
library, because it uses only Standard C functions. |
library, because it uses only Standard C functions. |
| 110 |
|
|
| 111 |
|
|
| 112 |
Building PCRE on a Unix-like system |
Building PCRE on Unix-like systems |
| 113 |
----------------------------------- |
---------------------------------- |
| 114 |
|
|
| 115 |
If you are using HP's ANSI C++ compiler (aCC), please see the special note |
If you are using HP's ANSI C++ compiler (aCC), please see the special note |
| 116 |
in the section entitled "Using HP's ANSI C++ compiler (aCC)" below. |
in the section entitled "Using HP's ANSI C++ compiler (aCC)" below. |
| 119 |
PCRE distribution directory, with your current directory set to the directory |
PCRE distribution directory, with your current directory set to the directory |
| 120 |
where you want the files to be created. This command is a standard GNU |
where you want the files to be created. This command is a standard GNU |
| 121 |
"autoconf" configuration script, for which generic instructions are supplied in |
"autoconf" configuration script, for which generic instructions are supplied in |
| 122 |
INSTALL. |
the file INSTALL. |
| 123 |
|
|
| 124 |
Most commonly, people build PCRE within its own distribution directory, and in |
Most commonly, people build PCRE within its own distribution directory, and in |
| 125 |
this case, on many systems, just running "./configure" is sufficient. However, |
this case, on many systems, just running "./configure" is sufficient. However, |
| 191 |
--with-match-limit=500000 |
--with-match-limit=500000 |
| 192 |
|
|
| 193 |
on the "configure" command. This is just the default; individual calls to |
on the "configure" command. This is just the default; individual calls to |
| 194 |
pcre_exec() can supply their own value. There is discussion on the pcreapi |
pcre_exec() can supply their own value. There is more discussion on the |
| 195 |
man page. |
pcreapi man page. |
| 196 |
|
|
| 197 |
. There is a separate counter that limits the depth of recursive function calls |
. There is a separate counter that limits the depth of recursive function calls |
| 198 |
during a matching process. This also has a default of ten million, which is |
during a matching process. This also has a default of ten million, which is |
| 207 |
. The default maximum compiled pattern size is around 64K. You can increase |
. The default maximum compiled pattern size is around 64K. You can increase |
| 208 |
this by adding --with-link-size=3 to the "configure" command. You can |
this by adding --with-link-size=3 to the "configure" command. You can |
| 209 |
increase it even more by setting --with-link-size=4, but this is unlikely |
increase it even more by setting --with-link-size=4, but this is unlikely |
| 210 |
ever to be necessary. If you build PCRE with an increased link size, test 2 |
ever to be necessary. |
|
(and 5 if you are using UTF-8) will fail. Part of the output of these tests |
|
|
is a representation of the compiled pattern, and this changes with the link |
|
|
size. |
|
| 211 |
|
|
| 212 |
. You can build PCRE so that its internal match() function that is called from |
. You can build PCRE so that its internal match() function that is called from |
| 213 |
pcre_exec() does not call itself recursively. Instead, it uses blocks of data |
pcre_exec() does not call itself recursively. Instead, it uses memory blocks |
| 214 |
from the heap via special functions pcre_stack_malloc() and pcre_stack_free() |
obtained from the heap via the special functions pcre_stack_malloc() and |
| 215 |
to save data that would otherwise be saved on the stack. To build PCRE like |
pcre_stack_free() to save data that would otherwise be saved on the stack. To |
| 216 |
this, use |
build PCRE like this, use |
| 217 |
|
|
| 218 |
--disable-stack-for-recursion |
--disable-stack-for-recursion |
| 219 |
|
|
| 220 |
on the "configure" command. PCRE runs more slowly in this mode, but it may be |
on the "configure" command. PCRE runs more slowly in this mode, but it may be |
| 221 |
necessary in environments with limited stack sizes. This applies only to the |
necessary in environments with limited stack sizes. This applies only to the |
| 222 |
pcre_exec() function; it does not apply to pcre_dfa_exec(), which does not |
pcre_exec() function; it does not apply to pcre_dfa_exec(), which does not |
| 223 |
use deeply nested recursion. |
use deeply nested recursion. There is a discussion about stack sizes in the |
| 224 |
|
pcrestack man page. |
| 225 |
|
|
| 226 |
The "configure" script builds the following files for the basic C library: |
The "configure" script builds the following files for the basic C library: |
| 227 |
|
|
| 234 |
. RunTest is a script for running tests on the basic C library |
. RunTest is a script for running tests on the basic C library |
| 235 |
. RunGrepTest is a script for running tests on the pcregrep command |
. RunGrepTest is a script for running tests on the pcregrep command |
| 236 |
|
|
| 237 |
Versions of config.h and pcre.h are distributed in the PCRE tarballs. These are |
Versions of config.h and pcre.h are distributed in the PCRE tarballs under |
| 238 |
provided for the benefit of those who have to compile PCRE without the benefit |
the names config.h.generic and pcre.h.generic. These are provided for the |
| 239 |
of "configure". If you use "configure", the distributed copies are replaced. |
benefit of those who have to built PCRE without the benefit of "configure". If |
| 240 |
|
you use "configure", the .generic versions are not used. |
| 241 |
|
|
| 242 |
If a C++ compiler is found, the following files are also built: |
If a C++ compiler is found, the following files are also built: |
| 243 |
|
|
| 252 |
Once "configure" has run, you can run "make". It builds two libraries, called |
Once "configure" has run, you can run "make". It builds two libraries, called |
| 253 |
libpcre and libpcreposix, a test program called pcretest, a demonstration |
libpcre and libpcreposix, a test program called pcretest, a demonstration |
| 254 |
program called pcredemo, and the pcregrep command. If a C++ compiler was found |
program called pcredemo, and the pcregrep command. If a C++ compiler was found |
| 255 |
on your system, it also builds the C++ wrapper library, which is called |
on your system, "make" also builds the C++ wrapper library, which is called |
| 256 |
libpcrecpp, and some test programs called pcrecpp_unittest, |
libpcrecpp, and some test programs called pcrecpp_unittest, |
| 257 |
pcre_scanner_unittest, and pcre_stringpiece_unittest. |
pcre_scanner_unittest, and pcre_stringpiece_unittest. Building the C++ wrapper |
| 258 |
|
can be disabled by adding --disable-cpp to the "configure" command. |
| 259 |
|
|
| 260 |
The command "make check" runs all the appropriate tests. Details of the PCRE |
The command "make check" runs all the appropriate tests. Details of the PCRE |
| 261 |
tests are given below in a separate section of this document. |
tests are given below in a separate section of this document. |
| 276 |
|
|
| 277 |
Configuration information (lib/pkgconfig): |
Configuration information (lib/pkgconfig): |
| 278 |
libpcre.pc |
libpcre.pc |
| 279 |
libpcrecpp.ps (if C++ support is enabled) |
libpcrecpp.pc (if C++ support is enabled) |
| 280 |
|
|
| 281 |
Header files (include): |
Header files (include): |
| 282 |
pcre.h |
pcre.h |
| 315 |
remove any directories, because these are often shared with other programs. |
remove any directories, because these are often shared with other programs. |
| 316 |
|
|
| 317 |
|
|
| 318 |
Retrieving configuration information on a Unix-like system |
Retrieving configuration information on Unix-like systems |
| 319 |
---------------------------------------------------------- |
--------------------------------------------------------- |
| 320 |
|
|
| 321 |
Running "make install" installs the command pcre-config, which can be used to |
Running "make install" installs the command pcre-config, which can be used to |
| 322 |
recall information about the PCRE configuration and installation. For example: |
recall information about the PCRE configuration and installation. For example: |
| 355 |
libraries (by means of wrapper scripts in the case of shared libraries). When |
libraries (by means of wrapper scripts in the case of shared libraries). When |
| 356 |
you use "make install" to install shared libraries, pcregrep and pcretest are |
you use "make install" to install shared libraries, pcregrep and pcretest are |
| 357 |
automatically re-built to use the newly installed shared libraries before being |
automatically re-built to use the newly installed shared libraries before being |
| 358 |
installed themselves. However, the versions left in the source directory still |
installed themselves. However, the versions left in the build directory still |
| 359 |
use the uninstalled libraries. |
use the uninstalled libraries. |
| 360 |
|
|
| 361 |
To build PCRE using static libraries only you must use --disable-shared when |
To build PCRE using static libraries only you must use --disable-shared when |
| 367 |
build only shared libraries. |
build only shared libraries. |
| 368 |
|
|
| 369 |
|
|
| 370 |
Cross-compiling on a Unix-like system |
Cross-compiling on Unix-like systems |
| 371 |
------------------------------------- |
------------------------------------ |
| 372 |
|
|
| 373 |
You can specify CC and CFLAGS in the normal way to the "configure" command, in |
You can specify CC and CFLAGS in the normal way to the "configure" command, in |
| 374 |
order to cross-compile PCRE for some other host. However, during the building |
order to cross-compile PCRE for some other host. However, during the building |
| 385 |
---------------------------------- |
---------------------------------- |
| 386 |
|
|
| 387 |
Unless C++ support is disabled by specifying the "--disable-cpp" option of the |
Unless C++ support is disabled by specifying the "--disable-cpp" option of the |
| 388 |
"configure" script, you *must* include the "-AA" option in the CXXFLAGS |
"configure" script, you must include the "-AA" option in the CXXFLAGS |
| 389 |
environment variable in order for the C++ components to compile correctly. |
environment variable in order for the C++ components to compile correctly. |
| 390 |
|
|
| 391 |
Also, note that the aCC compiler on PA-RISC platforms may have a defect whereby |
Also, note that the aCC compiler on PA-RISC platforms may have a defect whereby |
| 409 |
Testing PCRE |
Testing PCRE |
| 410 |
------------ |
------------ |
| 411 |
|
|
| 412 |
To test PCRE on a Unix system, run the RunTest script that is created by the |
To test the basic PCRE library on a Unix system, run the RunTest script that is |
| 413 |
configuring process. There is also a script called RunGrepTest that tests the |
created by the configuring process. There is also a script called RunGrepTest |
| 414 |
options of the pcregrep command. If the C++ wrapper library is build, three |
that tests the options of the pcregrep command. If the C++ wrapper library is |
| 415 |
test programs called pcrecpp_unittest, pcre_scanner_unittest, and |
built, three test programs called pcrecpp_unittest, pcre_scanner_unittest, and |
| 416 |
pcre_stringpiece_unittest are also built. |
pcre_stringpiece_unittest are also built. |
| 417 |
|
|
| 418 |
Both the scripts and all the program tests are run if you obey "make check" or |
Both the scripts and all the program tests are run if you obey "make check" or |
| 419 |
"make test". For other systems, see the instructions in NON-UNIX-USE. |
"make test". For other systems, see the instructions in NON-UNIX-USE. |
| 420 |
|
|
| 421 |
The RunTest script runs the pcretest test program (which is documented in its |
The RunTest script runs the pcretest test program (which is documented in its |
| 422 |
own man page) on each of the testinput files (in the testdata directory) in |
own man page) on each of the testinput files in the testdata directory in |
| 423 |
turn, and compares the output with the contents of the corresponding testoutput |
turn, and compares the output with the contents of the corresponding testoutput |
| 424 |
files. A file called testtry is used to hold the main output from pcretest |
files. A file called testtry is used to hold the main output from pcretest |
| 425 |
(testsavedregex is also used as a working file). To run pcretest on just one of |
(testsavedregex is also used as a working file). To run pcretest on just one of |
| 435 |
The second set of tests check pcre_fullinfo(), pcre_info(), pcre_study(), |
The second set of tests check pcre_fullinfo(), pcre_info(), pcre_study(), |
| 436 |
pcre_copy_substring(), pcre_get_substring(), pcre_get_substring_list(), error |
pcre_copy_substring(), pcre_get_substring(), pcre_get_substring_list(), error |
| 437 |
detection, and run-time flags that are specific to PCRE, as well as the POSIX |
detection, and run-time flags that are specific to PCRE, as well as the POSIX |
| 438 |
wrapper API. It also uses the debugging flag to check some of the internals of |
wrapper API. It also uses the debugging flags to check some of the internals of |
| 439 |
pcre_compile(). |
pcre_compile(). |
| 440 |
|
|
| 441 |
If you build PCRE with a locale setting that is not the standard C locale, the |
If you build PCRE with a locale setting that is not the standard C locale, the |
| 470 |
The fifth test checks error handling with UTF-8 encoding, and internal UTF-8 |
The fifth test checks error handling with UTF-8 encoding, and internal UTF-8 |
| 471 |
features of PCRE that are not relevant to Perl. |
features of PCRE that are not relevant to Perl. |
| 472 |
|
|
| 473 |
The sixth and test checks the support for Unicode character properties. It it |
The sixth test checks the support for Unicode character properties. It it not |
| 474 |
not run automatically unless PCRE is built with Unicode property support. To to |
run automatically unless PCRE is built with Unicode property support. To to |
| 475 |
this you must set --enable-unicode-properties when running "configure". |
this you must set --enable-unicode-properties when running "configure". |
| 476 |
|
|
| 477 |
The seventh, eighth, and ninth tests check the pcre_dfa_exec() alternative |
The seventh, eighth, and ninth tests check the pcre_dfa_exec() alternative |
| 483 |
Character tables |
Character tables |
| 484 |
---------------- |
---------------- |
| 485 |
|
|
| 486 |
PCRE uses four tables for manipulating and identifying characters whose values |
For speed, PCRE uses four tables for manipulating and identifying characters |
| 487 |
are less than 256. The final argument of the pcre_compile() function is a |
whose code point values are less than 256. The final argument of the |
| 488 |
pointer to a block of memory containing the concatenated tables. A call to |
pcre_compile() function is a pointer to a block of memory containing the |
| 489 |
pcre_maketables() can be used to generate a set of tables in the current |
concatenated tables. A call to pcre_maketables() can be used to generate a set |
| 490 |
locale. If the final argument for pcre_compile() is passed as NULL, a set of |
of tables in the current locale. If the final argument for pcre_compile() is |
| 491 |
default tables that is built into the binary is used. |
passed as NULL, a set of default tables that is built into the binary is used. |
| 492 |
|
|
| 493 |
The source file called chartables.c contains the default set of tables. This is |
The source file called chartables.c contains the default set of tables. This is |
| 494 |
not supplied in the distribution, but is built by the program dftables |
not supplied in the distribution, but is built by the program dftables |
| 497 |
sources. This means that the default C locale which is set for your system will |
sources. This means that the default C locale which is set for your system will |
| 498 |
control the contents of these default tables. You can change the default tables |
control the contents of these default tables. You can change the default tables |
| 499 |
by editing chartables.c and then re-building PCRE. If you do this, you should |
by editing chartables.c and then re-building PCRE. If you do this, you should |
| 500 |
probably also edit Makefile to ensure that the file doesn't ever get |
take care to ensure that the file does not get automaticaly re-generated. |
|
re-generated. |
|
| 501 |
|
|
| 502 |
The first two 256-byte tables provide lower casing and case flipping functions, |
The first two 256-byte tables provide lower casing and case flipping functions, |
| 503 |
respectively. The next table consists of three 32-byte bit maps which identify |
respectively. The next table consists of three 32-byte bit maps which identify |