Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_pcre.c
Go to the documentation of this file.
1
9#include "nilorea/n_log.h"
10#include "nilorea/n_pcre.h"
11
12int main(int argc, char** argv) {
15
16 n_log(LOG_INFO, "Starting !");
17
18 if (argc < 3) {
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 n_log(LOG_INFO, "MATCHED !");
25 if (pcre->captured > 1) {
26 n_log(LOG_INFO, "CAPTURED !");
27 int it = 0;
28 while (pcre->match_list[it]) {
29 n_log(LOG_INFO, "Match[%d]:%s", it, pcre->match_list[it]);
30 it++;
31 }
32 }
33 } else {
34 n_log(LOG_INFO, "NO MATCH !");
35 }
36
37 npcre_delete(&pcre);
38
39 exit(0);
40}
int main(void)
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition n_log.h:70
#define LOG_DEBUG
debug-level messages
Definition n_log.h:65
#define LOG_ERR
error conditions
Definition n_log.h:57
#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:104
#define LOG_INFO
informational
Definition n_log.h:63
int captured
flag for match_list cleaning
Definition n_pcre.h:43
const char ** match_list
populated match list if nPcreCapMatch is called
Definition n_pcre.h:41
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:150
int npcre_delete(N_PCRE **pcre)
Free a N_PCRE pointer.
Definition n_pcre.c:102
N_PCRE structure.
Definition n_pcre.h:28
Generic log system.
PCRE helpers for regex matching.