Browse Source

Add regex flags support

For extended & case insensitive regex
Yann Weber 7 years ago
parent
commit
38d7ad4d90
4 changed files with 29 additions and 4 deletions
  1. 1
    2
      docs/Makefile.am
  2. 2
    0
      src/include/ttail.h
  3. 3
    1
      src/include/ttail_init.h
  4. 23
    1
      src/ttail_init.c

+ 1
- 2
docs/Makefile.am View File

@@ -11,8 +11,7 @@ doxyfile.stamp:
11 11
 	echo Timestamp > doxyfile.stamp
12 12
 
13 13
 
14
-all-local: doxyfile.stamp doc
15
-doc: doxyfile.stamp
14
+html-local: doxyfile.stamp
16 15
 
17 16
 clean-local:
18 17
 	-rm -rf $(top_srcdir)/docs/html $(top_srcdir)/docs/man $(top_srcdir)/docs/doxygen_sqlite3.db

+ 2
- 0
src/include/ttail.h View File

@@ -21,6 +21,8 @@ typedef struct _ttail_s ttail_t;
21 21
 #define TTAIL_FLAG_DATE_MIN 2
22 22
 #define TTAIL_FLAG_DATE_MAX 4
23 23
 #define TTAIL_FLAG_FORMAT 8
24
+#define TTAIL_FLAG_EXTENDED_RE 16
25
+#define TTAIL_FLAG_EXTENDED_CI 32
24 26
 
25 27
 #define TTAIL_DEFAULT_FORMATS {"%m",\
26 28
 "%A %B %d, %Y %H:%M:%S",\

+ 3
- 1
src/include/ttail_init.h View File

@@ -17,6 +17,8 @@
17 17
 #define TTAIL_LONG_OPT {\
18 18
 	{"verbose", no_argument, 0, 'v'},\
19 19
 	{"re-prefix", required_argument, 0, 'r'},\
20
+	{"re-extended", no_argument, 0, 'E'},\
21
+	{"re-case-insensitive", no_argument, 0, 'I'},\
20 22
 	{"prefix-len", required_argument, 0, 'p'},\
21 23
 	{"date-format", required_argument, 0, 'f'},\
22 24
 	{"date-min", required_argument, 0, 'd'},\
@@ -24,7 +26,7 @@
24 26
 	{"logfile", required_argument, 0, 'l'},\
25 27
 	{0,	0,	0,	0 }\
26 28
 }
27
-#define TTAIL_SHORT_OPT "r:p:f:d:l:m:"
29
+#define TTAIL_SHORT_OPT "r:EIp:f:d:l:m:"
28 30
 
29 31
 /**@brief Parse cli arguments and return a ttail_t
30 32
  *@param int argc

+ 23
- 1
src/ttail_init.c View File

@@ -60,6 +60,19 @@ set\n");
60 60
 to be > 0");
61 61
 					goto ttail_init_err;
62 62
 				}
63
+				break;
64
+			case 'E':
65
+			case 'I':
66
+				/**@todo checks */
67
+				if(res->flag & TTAIL_FLAG_PREFIX)
68
+				{
69
+					fprintf(stderr, "-E & -I options \
70
+have to be set BEFORE -r option\n");
71
+					goto ttail_init_err;
72
+				}
73
+				res->flag |= c=='E'?TTAIL_FLAG_EXTENDED_RE:\
74
+					REG_ICASE;
75
+				break;
63 76
 			case 'f':
64 77
 				if(res->flag & TTAIL_FLAG_FORMAT)
65 78
 				{
@@ -220,7 +233,7 @@ int ttail_add_logfile(ttail_t* res, const char* filename)
220 233
 
221 234
 int ttail_set_prefix(ttail_t* res, const char* regex)
222 235
 {
223
-	int ret;
236
+	int ret, cflags;
224 237
 	char *re_errbuff;
225 238
 	size_t re_errbuff_sz;
226 239
 
@@ -230,6 +243,15 @@ int ttail_set_prefix(ttail_t* res, const char* regex)
230 243
 		return 1;
231 244
 	}
232 245
 	res->flag |= TTAIL_FLAG_PREFIX;
246
+	cflags = 0; /** @todo checks */
247
+	if(res->flag & TTAIL_FLAG_EXTENDED_RE)
248
+	{
249
+		cflags |= REG_EXTENDED;
250
+	}
251
+	if(res->flag & TTAIL_FLAG_EXTENDED_CI)
252
+	{
253
+		cflags |= REG_ICASE;
254
+	}
233 255
 	ret = regcomp(&res->date_prefix, regex, 0);
234 256
 	if(!ret)
235 257
 	{

Loading…
Cancel
Save