aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-11-12 10:02:20 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-11-12 10:02:20 +0100
commit57a3159d5c441837607866fea848075055e03c89 (patch)
treeb75e87adf8adc9ceb01ea70b6906f1b400e1418f /src
parent23905302b2e9f85135b062b12b20c65a413994b9 (diff)
Fix the display of PCRE2 error messages
Diffstat (limited to 'src')
-rw-r--r--src/main.c5
-rw-r--r--src/util.c6
-rw-r--r--src/work.c12
3 files changed, 14 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 0a3e391..72cc89c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -360,11 +360,12 @@ pattern_comp(u8view_t pat)
size_t eoff;
op.re = pcre2_compile(re.p, re.len, reopts, &ec, &eoff, nullptr);
if (op.re == nullptr) {
+ /* TODO: Print which regex failed to compile */
pcre2_bitch_and_die(
- ec, "failed to compile regex at byte offset %zu: %s", eoff);
+ ec, "failed to compile regex at byte offset %zu", eoff);
}
if ((ec = pcre2_jit_compile(op.re, PCRE2_JIT_COMPLETE)) != 0)
- pcre2_bitch_and_die(ec, "failed to JIT compile regex: %s");
+ pcre2_bitch_and_die(ec, "failed to JIT compile regex");
#if DEBUG
op.free_me = true;
#endif
diff --git a/src/util.c b/src/util.c
index a946119..fe87b73 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,6 +1,7 @@
#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdio.h>
#include <stdlib.h>
#include <errors.h>
@@ -27,7 +28,10 @@ pcre2_bitch_and_die(int ec, const char *fmt, ...)
} else {
va_list ap;
va_start(ap, fmt);
- vwarn(fmt, ap);
+ flockfile(stderr);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, ": %s\n", buf);
+ funlockfile(stderr);
exit(EXIT_FATAL);
}
}
diff --git a/src/work.c b/src/work.c
index 5bc8b24..feb7c96 100644
--- a/src/work.c
+++ b/src/work.c
@@ -193,7 +193,7 @@ DEFINE_OPERATOR(g)
if (n == PCRE2_ERROR_NOMATCH)
return;
if (n < 0)
- pcre2_bitch_and_die(n, "failed to match regex: %s");
+ pcre2_bitch_and_die(n, "failed to match regex");
operator_dispatch(opi + 1, sv, hl);
}
@@ -209,7 +209,7 @@ DEFINE_OPERATOR(G)
if (n == PCRE2_ERROR_NOMATCH)
operator_dispatch(opi + 1, sv, hl);
if (n < 0)
- pcre2_bitch_and_die(n, "failed to match regex: %s");
+ pcre2_bitch_and_die(n, "failed to match regex");
}
DEFINE_OPERATOR(h)
@@ -229,7 +229,7 @@ DEFINE_OPERATOR(h)
if (n == PCRE2_ERROR_NOMATCH)
break;
if (n < 0)
- pcre2_bitch_and_die(n, "failed to match regex: %s");
+ pcre2_bitch_and_die(n, "failed to match regex");
size_t *ov = pcre2_get_ovector_pointer(md);
array_push(hl, ((u8view_t){sv.p + ov[0], ov[1] - ov[0]}));
@@ -257,7 +257,7 @@ DEFINE_OPERATOR(H)
if (n == PCRE2_ERROR_NOMATCH)
break;
if (n < 0)
- pcre2_bitch_and_die(n, "failed to match regex: %s");
+ pcre2_bitch_and_die(n, "failed to match regex");
size_t *ov = pcre2_get_ovector_pointer(md);
array_push(hl, ((u8view_t){sv.p, ov[0]}));
@@ -278,7 +278,7 @@ DEFINE_OPERATOR(x)
if (n == PCRE2_ERROR_NOMATCH)
break;
if (n < 0)
- pcre2_bitch_and_die(n, "failed to match regex: %s");
+ pcre2_bitch_and_die(n, "failed to match regex");
size_t *ov = pcre2_get_ovector_pointer(md);
operator_dispatch(opi + 1, (u8view_t){sv.p + ov[0], ov[1] - ov[0]}, hl);
@@ -297,7 +297,7 @@ DEFINE_OPERATOR(X)
if (n == PCRE2_ERROR_NOMATCH)
break;
if (n < 0)
- pcre2_bitch_and_die(n, "failed to match regex: %s");
+ pcre2_bitch_and_die(n, "failed to match regex");
size_t *ov = pcre2_get_ovector_pointer(md);
if (ov[0] != 0)