Nilorea Library
C utilities for networking, threading, graphics
ex_pcre.c

Nilorea Library pcre api test.

Nilorea Library pcre api test

Author
Castagnier Mickael
Version
1.0
Date
04/12/2019
#include "nilorea/n_log.h"
#include "nilorea/n_pcre.h"
int main( int argc, char **argv )
{
n_log( LOG_INFO, "Starting !" );
if( argc < 3 )
{
n_log( LOG_ERR, "Not enough args\nUsage:\n %s \"regexp\" \"string\"", argv[ 0 ] );
exit( 1 );
}
N_PCRE *pcre = npcre_new( argv[ 1 ], 99, 0 );
if( npcre_match( argv[ 2 ], pcre ) == TRUE )
{
n_log( LOG_INFO, "MATCHED !" );
if( pcre -> captured > 1 )
{
n_log( LOG_INFO, "CAPTURED !" );
int it = 0 ;
while( pcre -> match_list[ it ] )
{
n_log( LOG_INFO, "Match[%d]:%s", it, pcre -> match_list[ it ] );
it ++ ;
}
}
}
else
{
n_log( LOG_INFO, "NO MATCH !" );
}
npcre_delete( &pcre );
exit( 0 );
}
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition: n_log.h:74
#define LOG_DEBUG
debug-level messages
Definition: n_log.h:66
#define LOG_ERR
error conditions
Definition: n_log.h:58
#define LOG_STDERR
internal, default LOG_TYPE
Definition: n_log.h:31
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition: n_log.c:97
#define LOG_INFO
informational
Definition: n_log.h:64
N_PCRE * npcre_new(char *str, int max_cap, int flags)
From pcre doc, the flag bits are: PCRE_ANCHORED Force pattern anchoring PCRE_AUTO_CALLOUT Compile aut...
Definition: n_pcre.c:59
int npcre_match(char *str, N_PCRE *pcre)
Return TRUE if str matches regexp, and make captures up to max_cap.
Definition: n_pcre.c:165
int npcre_delete(N_PCRE **pcre)
Free a N_PCRE pointer.
Definition: n_pcre.c:107
N_PCRE structure.
Definition: n_pcre.h:29
Generic log system.
PCRE helpers for regex matching.