Browse code

- fixup_regex added

Jan Janak authored on 11/10/2005 16:50:15
Showing 2 changed files
... ...
@@ -42,6 +42,7 @@
42 42
 #include "mem/mem.h"
43 43
 #include "ut.h"
44 44
 
45
+#include <regex.h>
45 46
 #include <dlfcn.h>
46 47
 #include <strings.h>
47 48
 #include <stdlib.h>
... ...
@@ -580,3 +581,41 @@ int fixup_int_2(void** param, int param_no)
580 580
 	
581 581
 	return 0;
582 582
 }
583
+
584
+
585
+int fixup_regex_12(void** param, int param_no)
586
+{
587
+	regex_t* re;
588
+
589
+	if ((re=pkg_malloc(sizeof(regex_t)))==0) return E_OUT_OF_MEM;
590
+	if (regcomp(re, *param, REG_EXTENDED|REG_ICASE|REG_NEWLINE) ){
591
+		pkg_free(re);
592
+		LOG(L_ERR, "ERROR: fixup_regex_12: Bad regular expression '%s'\n", (char*)*param);
593
+		return E_BAD_RE;
594
+	}
595
+	/* free string */
596
+	pkg_free(*param);
597
+	/* replace it with the compiled re */
598
+	*param=re;
599
+	return 0;
600
+}
601
+
602
+
603
+int fixup_regex_1(void** param, int param_no)
604
+{
605
+	if (param_no == 1) {
606
+		return fixup_regex_12(param, param_no);
607
+	}
608
+
609
+	return 0;
610
+}
611
+
612
+
613
+int fixup_regex_2(void** param, int param_no)
614
+{
615
+	if (param_no == 2) {
616
+		return fixup_regex_12(param, param_no);
617
+	}
618
+
619
+	return 0;
620
+}
... ...
@@ -183,4 +183,13 @@ int fixup_int_1(void** param, int param_no);
183 183
 /* Convert second parameter from char* to long */
184 184
 int fixup_int_2(void** param, int param_no);
185 185
 
186
+/* Compile regular expressions in both parameters */
187
+int fixup_regex_12(void** param, int param_no);
188
+
189
+/* Compile regular expression in first parameter */
190
+int fixup_regex_1(void** param, int param_no);
191
+
192
+/* Compile regular expression in second parameter */
193
+int fixup_regex_2(void** param, int param_no);
194
+
186 195
 #endif /* sr_module_h */