--- code/trunk/pcredemo.c 2007/03/02 13:10:43 96 +++ code/trunk/pcredemo.c 2010/01/06 10:26:55 487 @@ -4,17 +4,37 @@ /* This is a demonstration program to illustrate the most straightforward ways of calling the PCRE regular expression library from a C program. See the -pcresample documentation for a short discussion. +pcresample documentation for a short discussion ("man pcresample" if you have +the PCRE man pages installed). -Compile thuswise: - gcc -Wall pcredemo.c -I/usr/local/include -L/usr/local/lib \ - -R/usr/local/lib -lpcre +In Unix-like environments, if PCRE is installed in your standard system +libraries, you should be able to compile this program using this command: + +gcc -Wall pcredemo.c -lpcre -o pcredemo + +If PCRE is not installed in a standard place, it is likely to be installed with +support for the pkg-config mechanism. If you have pkg-config, you can compile +this program using this command: + +gcc -Wall pcredemo.c `pkg-config --cflags --libs libpcre` -o pcredemo + +If you do not have pkg-config, you may have to use this: + +gcc -Wall pcredemo.c -I/usr/local/include -L/usr/local/lib \ + -R/usr/local/lib -lpcre -o pcredemo Replace "/usr/local/include" and "/usr/local/lib" with wherever the include and library files for PCRE are installed on your system. Only some operating systems (e.g. Solaris) use the -R option. -*/ +Building under Windows: + +If you want to statically link this program against a non-dll .a file, you must +define PCRE_STATIC before including pcre.h, otherwise the pcre_malloc() and +pcre_free() exported functions will be declared __declspec(dllimport), with +unwanted results. So in this environment, uncomment the following line. */ + +/* #define PCRE_STATIC */ #include #include @@ -128,8 +148,8 @@ /************************************************************************* * We have found the first match within the subject string. If the output * -* vector wasn't big enough, set its size to the maximum. Then output any * -* substrings that were captured. * +* vector wasn't big enough, say so. Then output any substrings that were * +* captured. * *************************************************************************/ /* The output vector wasn't big enough */ @@ -154,7 +174,7 @@ /************************************************************************** * That concludes the basic part of this demonstration program. We have * * compiled a pattern, and performed a single match. The code that follows * -* first shows how to access named substrings, and then how to code for * +* shows first how to access named substrings, and then how to code for * * repeated matches on the same subject. * **************************************************************************/ @@ -213,12 +233,12 @@ * * * If the previous match WAS for an empty string, we can't do that, as it * * would lead to an infinite loop. Instead, a special call of pcre_exec() * -* is made with the PCRE_NOTEMPTY and PCRE_ANCHORED flags set. The first * -* of these tells PCRE that an empty string is not a valid match; other * -* possibilities must be tried. The second flag restricts PCRE to one * -* match attempt at the initial string position. If this match succeeds, * -* an alternative to the empty string match has been found, and we can * -* proceed round the loop. * +* is made with the PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED flags set. * +* The first of these tells PCRE that an empty string at the start of the * +* subject is not a valid match; other possibilities must be tried. The * +* second flag restricts PCRE to one match attempt at the initial string * +* position. If this match succeeds, an alternative to the empty string * +* match has been found, and we can proceed round the loop. * *************************************************************************/ if (!find_all) @@ -241,7 +261,7 @@ if (ovector[0] == ovector[1]) { if (ovector[0] == subject_length) break; - options = PCRE_NOTEMPTY | PCRE_ANCHORED; + options = PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED; } /* Run the next matching operation */