CLEANUP: regex: Create regex_comp function that compiles regex using compilation options

The current file "regex.h" define an abstraction for the regex. It
provides the same struct name and the same "regexec" function for the
3 regex types supported: standard libc, basic pcre and jit pcre.

The regex compilation function is not provided by this file. If the
developper wants to use regex, he must write regex compilation code
containing "#define *JIT*".

This patch provides a unique regex compilation function according to
the compilation options.

In addition, the "regex.h" file checks the presence of the "#define
PCRE_CONFIG_JIT" when "USE_PCRE_JIT" is enabled. If this flag is not
present, the pcre lib doesn't support JIT and "#error" is emitted.
diff --git a/src/regex.c b/src/regex.c
index 1455fb4..a268996 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -122,7 +122,45 @@
 	return NULL;
 }
 
+int regex_comp(const char *str, regex *regex, int cs, int cap, char **err)
+{
+#ifdef USE_PCRE_JIT
+	int flags = 0;
+	const char *error;
+	int erroffset;
+
+	if (!cs)
+		flags |= PCRE_CASELESS;
+	if (!cap)
+		flags |= PCRE_NO_AUTO_CAPTURE;
+
+	regex->reg = pcre_compile(str, flags, &error, &erroffset, NULL);
+	if (!regex->reg) {
+		memprintf(err, "regex '%s' is invalid (error=%s, erroffset=%d)", str, error, erroffset);
+		return 0;
+	}
+
+	regex->extra = pcre_study(regex->reg, PCRE_STUDY_JIT_COMPILE, &error);
+	if (!regex->extra) {
+		pcre_free(regex->reg);
+		memprintf(err, "failed to compile regex '%s' (error=%s)", str, error);
+		return 0;
+	}
+#else
+	int flags = REG_EXTENDED;
+
+	if (!cs)
+		flags |= REG_ICASE;
+	if (!cap)
+		flags |= REG_NOSUB;
 
+	if (regcomp(regex, str, flags) != 0) {
+		memprintf(err, "regex '%s' is invalid", str);
+		return 0;
+	}
+#endif
+	return 1;
+}
 
 /*
  * Local variables: