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
 	echo Timestamp > doxyfile.stamp
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
 clean-local:
16
 clean-local:
18
 	-rm -rf $(top_srcdir)/docs/html $(top_srcdir)/docs/man $(top_srcdir)/docs/doxygen_sqlite3.db
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
 #define TTAIL_FLAG_DATE_MIN 2
21
 #define TTAIL_FLAG_DATE_MIN 2
22
 #define TTAIL_FLAG_DATE_MAX 4
22
 #define TTAIL_FLAG_DATE_MAX 4
23
 #define TTAIL_FLAG_FORMAT 8
23
 #define TTAIL_FLAG_FORMAT 8
24
+#define TTAIL_FLAG_EXTENDED_RE 16
25
+#define TTAIL_FLAG_EXTENDED_CI 32
24
 
26
 
25
 #define TTAIL_DEFAULT_FORMATS {"%m",\
27
 #define TTAIL_DEFAULT_FORMATS {"%m",\
26
 "%A %B %d, %Y %H:%M:%S",\
28
 "%A %B %d, %Y %H:%M:%S",\

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

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

+ 23
- 1
src/ttail_init.c View File

60
 to be > 0");
60
 to be > 0");
61
 					goto ttail_init_err;
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
 			case 'f':
76
 			case 'f':
64
 				if(res->flag & TTAIL_FLAG_FORMAT)
77
 				if(res->flag & TTAIL_FLAG_FORMAT)
65
 				{
78
 				{
220
 
233
 
221
 int ttail_set_prefix(ttail_t* res, const char* regex)
234
 int ttail_set_prefix(ttail_t* res, const char* regex)
222
 {
235
 {
223
-	int ret;
236
+	int ret, cflags;
224
 	char *re_errbuff;
237
 	char *re_errbuff;
225
 	size_t re_errbuff_sz;
238
 	size_t re_errbuff_sz;
226
 
239
 
230
 		return 1;
243
 		return 1;
231
 	}
244
 	}
232
 	res->flag |= TTAIL_FLAG_PREFIX;
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
 	ret = regcomp(&res->date_prefix, regex, 0);
255
 	ret = regcomp(&res->date_prefix, regex, 0);
234
 	if(!ret)
256
 	if(!ret)
235
 	{
257
 	{

Loading…
Cancel
Save