+
+/* Helper function to compile a PCRE regexp. */
+static pcre2_code *
+compile_re (const char *rex)
+{
+ int errorcode;
+ PCRE2_SIZE erroroffset;
+ char errormsg[256];
+ pcre2_code *ret;
+
+ ret = pcre2_compile ((PCRE2_SPTR) rex, PCRE2_ZERO_TERMINATED,
+ 0, &errorcode, &erroroffset, NULL);
+ if (ret == NULL) {
+ pcre2_get_error_message (errorcode,
+ (PCRE2_UCHAR *) errormsg, sizeof errormsg);
+ fprintf (stderr, "error: "
+ "failed to compile regular expression '%s': "
+ "%s at offset %zu\n",
+ rex, errormsg, erroroffset);
+ exit (EXIT_FAILURE);
+ }
+ return ret;
+}