Browse Source

Add setters for RE flags and use them

ttail_set_flag_re_ex() and ttail_set_flag_re_ci()
Yann Weber 7 years ago
parent
commit
e1391139ab
3 changed files with 56 additions and 8 deletions
  1. 1
    1
      src/include/ttail.h
  2. 12
    0
      src/include/ttail_init.h
  3. 43
    7
      src/ttail_init.c

+ 1
- 1
src/include/ttail.h View File

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

+ 12
- 0
src/include/ttail_init.h View File

@@ -180,6 +180,18 @@ int ttail_set_prefix(ttail_t*, const char*);
180 180
  */
181 181
 int ttail_set_fmt(ttail_t*, const char*);
182 182
 
183
+/**@brief Set the extended regex flag
184
+ *@param ttail ttail_t*
185
+ *@return -1 on error else 0
186
+ */
187
+int ttail_set_flag_re_ex(ttail_t*);
188
+
189
+/**@brief Set the case insensitive regex flag
190
+ *@param ttail ttail_t*
191
+ *@return -1 on error else 0
192
+ */
193
+int ttail_set_flag_re_ci(ttail_t*);
194
+
183 195
 /**@brief Set dates min/max
184 196
  *
185 197
  *After the call dates are free and set to NULL except if error

+ 43
- 7
src/ttail_init.c View File

@@ -63,16 +63,16 @@ to be > 0");
63 63
 				}
64 64
 				break;
65 65
 			case 'E':
66
+				if(ttail_set_flag_re_ex(res) < 0)
67
+				{
68
+					goto ttail_init_err;
69
+				}
70
+				break;
66 71
 			case 'I':
67
-				/**@todo checks */
68
-				if(res->flag & TTAIL_FLAG_PREFIX)
72
+				if(ttail_set_flag_re_ci(res) < 0)
69 73
 				{
70
-					fprintf(stderr, "-E & -I options \
71
-have to be set BEFORE -r option\n");
72 74
 					goto ttail_init_err;
73 75
 				}
74
-				res->flag |= c=='E'?TTAIL_FLAG_EXTENDED_RE:\
75
-					REG_ICASE;
76 76
 				break;
77 77
 			case 'f':
78 78
 				if(res->flag & TTAIL_FLAG_FORMAT)
@@ -248,7 +248,7 @@ int ttail_set_prefix(ttail_t* res, const char* regex)
248 248
 	{
249 249
 		cflags |= REG_EXTENDED;
250 250
 	}
251
-	if(res->flag & TTAIL_FLAG_EXTENDED_CI)
251
+	if(res->flag & TTAIL_FLAG_CI_RE)
252 252
 	{
253 253
 		cflags |= REG_ICASE;
254 254
 	}
@@ -298,6 +298,42 @@ int ttail_set_fmt(ttail_t* t, const char* fmt)
298 298
 	return 0;
299 299
 }
300 300
 
301
+/**@brief This function is used by bot @ref ttail_set_flag_re_ex() and
302
+ *ttail_set_flag_re_ci() function
303
+ *@param t ttail_t*
304
+ *@return -1 on error else 0
305
+ */
306
+static int _ttail_common_set_flag_re(ttail_t* ttail)
307
+{
308
+	if(ttail->flag & TTAIL_FLAG_PREFIX)
309
+	{
310
+		fprintf(stderr, "Regex flags has to be set BEFORE the \
311
+prefix\n");
312
+		return -1;
313
+	}
314
+	return 0;
315
+}
316
+
317
+int ttail_set_flag_re_ex(ttail_t* ttail)
318
+{
319
+	if(_ttail_common_set_flag_re(ttail) < 0)
320
+	{
321
+		return -1;
322
+	}
323
+	ttail->flag |= TTAIL_FLAG_EXTENDED_RE;
324
+	return 0;
325
+}
326
+
327
+int ttail_set_flag_re_ci(ttail_t* ttail)
328
+{
329
+	if(_ttail_common_set_flag_re(ttail) < 0)
330
+	{
331
+		return -1;
332
+	}
333
+	ttail->flag |= TTAIL_FLAG_CI_RE;
334
+	return 0;
335
+}
336
+
301 337
 int ttail_set_dates(ttail_t* res, char* dates[2])
302 338
 {
303 339
 	int c, ret;

Loading…
Cancel
Save