/[pcre]/code/trunk/pcredemo.c
ViewVC logotype

Diff of /code/trunk/pcredemo.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 315 by ph10, Fri Jan 25 17:23:16 2008 UTC revision 487 by ph10, Wed Jan 6 10:26:55 2010 UTC
# Line 4  Line 4 
4    
5  /* This is a demonstration program to illustrate the most straightforward ways  /* This is a demonstration program to illustrate the most straightforward ways
6  of calling the PCRE regular expression library from a C program. See the  of calling the PCRE regular expression library from a C program. See the
7  pcresample documentation for a short discussion ("man pcresample" if you have  pcresample documentation for a short discussion ("man pcresample" if you have
8  the PCRE man pages installed).  the PCRE man pages installed).
9    
10  In Unix-like environments, compile this program thuswise:  In Unix-like environments, if PCRE is installed in your standard system
11    libraries, you should be able to compile this program using this command:
12    
13    gcc -Wall pcredemo.c -I/usr/local/include -L/usr/local/lib \  gcc -Wall pcredemo.c -lpcre -o pcredemo
14      -R/usr/local/lib -lpcre  
15    If PCRE is not installed in a standard place, it is likely to be installed with
16    support for the pkg-config mechanism. If you have pkg-config, you can compile
17    this program using this command:
18    
19    gcc -Wall pcredemo.c `pkg-config --cflags --libs libpcre` -o pcredemo
20    
21    If you do not have pkg-config, you may have to use this:
22    
23    gcc -Wall pcredemo.c -I/usr/local/include -L/usr/local/lib \
24      -R/usr/local/lib -lpcre -o pcredemo
25    
26  Replace "/usr/local/include" and "/usr/local/lib" with wherever the include and  Replace "/usr/local/include" and "/usr/local/lib" with wherever the include and
27  library files for PCRE are installed on your system. You don't need -I and -L  library files for PCRE are installed on your system. Only some operating
 if PCRE is installed in the standard system libraries. Only some operating  
28  systems (e.g. Solaris) use the -R option.  systems (e.g. Solaris) use the -R option.
29    
30  Building under Windows:  Building under Windows:
# Line 223  if (namecount <= 0) printf("No named sub Line 233  if (namecount <= 0) printf("No named sub
233  *                                                                        *  *                                                                        *
234  * If the previous match WAS for an empty string, we can't do that, as it *  * If the previous match WAS for an empty string, we can't do that, as it *
235  * would lead to an infinite loop. Instead, a special call of pcre_exec() *  * would lead to an infinite loop. Instead, a special call of pcre_exec() *
236  * is made with the PCRE_NOTEMPTY and PCRE_ANCHORED flags set. The first  *  * is made with the PCRE_NOTEMPTY_ATSTART and PCRE_ANCHORED flags set.    *
237  * of these tells PCRE that an empty string is not a valid match; other   *  * The first of these tells PCRE that an empty string at the start of the *
238  * possibilities must be tried. The second flag restricts PCRE to one     *  * subject is not a valid match; other possibilities must be tried. The   *
239  * match attempt at the initial string position. If this match succeeds,  *  * second flag restricts PCRE to one match attempt at the initial string  *
240  * an alternative to the empty string match has been found, and we can    *  * position. If this match succeeds, an alternative to the empty string   *
241  * proceed round the loop.                                                *  * match has been found, and we can proceed round the loop.               *
242  *************************************************************************/  *************************************************************************/
243    
244  if (!find_all)  if (!find_all)
# Line 251  for (;;) Line 261  for (;;)
261    if (ovector[0] == ovector[1])    if (ovector[0] == ovector[1])
262      {      {
263      if (ovector[0] == subject_length) break;      if (ovector[0] == subject_length) break;
264      options = PCRE_NOTEMPTY | PCRE_ANCHORED;      options = PCRE_NOTEMPTY_ATSTART | PCRE_ANCHORED;
265      }      }
266    
267    /* Run the next matching operation */    /* Run the next matching operation */

Legend:
Removed from v.315  
changed lines
  Added in v.487

  ViewVC Help
Powered by ViewVC 1.1.5