Nilorea Library
C utilities for networking, threading, graphics
ex_pcre.c
1
7#include "nilorea/n_log.h"
8#include "nilorea/n_pcre.h"
9
10int main( int argc, char **argv )
11{
14
15 n_log( LOG_INFO, "Starting !" );
16
17 if( argc < 3 )
18 {
19 n_log( LOG_ERR, "Not enough args\nUsage:\n %s \"regexp\" \"string\"", argv[ 0 ] );
20 exit( 1 );
21 }
22 N_PCRE *pcre = npcre_new( argv[ 1 ], 99, 0 );
23 if( npcre_match( argv[ 2 ], pcre ) == TRUE )
24 {
25 n_log( LOG_INFO, "MATCHED !" );
26 if( pcre -> captured > 1 )
27 {
28 n_log( LOG_INFO, "CAPTURED !" );
29 int it = 0 ;
30 while( pcre -> match_list[ it ] )
31 {
32 n_log( LOG_INFO, "Match[%d]:%s", it, pcre -> match_list[ it ] );
33 it ++ ;
34 }
35 }
36 }
37 else
38 {
39 n_log( LOG_INFO, "NO MATCH !" );
40 }
41
42 npcre_delete( &pcre );
43
44 exit( 0 );
45}
46
47
#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.