tin  2.4.5
About: TIN is a threaded NNTP and spool based UseNet newsreader.
  Fossies Dox: tin-2.4.5.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

pcredemo.c File Reference
#include <stdio.h>
#include <string.h>
#include <pcre.h>
Include dependency graph for pcredemo.c:

Go to the source code of this file.


#define OVECCOUNT   30 /* should be a multiple of 3 */


int main (int argc, char **argv)

Macro Definition Documentation


#define OVECCOUNT   30 /* should be a multiple of 3 */


Definition at line 23 of file pcredemo.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 

First, sort out the command line. There is only one possible option at * the moment, "-g" to request repeated matching to find all occurrences, * like Perl's /g option. We set the variable find_all to a non-zero value * if the -g option is present. Apart from that, there must be exactly two * arguments. *

Now we are going to compile the regular expression pattern, and handle * and errors that are detected. *

If the compilation succeeded, we call PCRE again, in order to do a * pattern match against the subject string. This does just ONE match. If * further matching is needed, it will be done below. *

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. *

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 * repeated matches on the same subject. *

If the "-g" option was given on the command line, we want to continue * to search for additional matches in the subject string, in a similar * way to the /g option in Perl. This turns out to be trickier than you * might think because of the possibility of matching an empty string. * What happens is as follows: *

  • If the previous match was NOT for an empty string, we can just start * the next match at the end of the previous one. *
  • 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. *

Definition at line 26 of file pcredemo.c.