aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-01-18 01:18:48 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-01-18 01:18:48 +0100
commit94421639b0bb61dc14ea39028ee66c84e26814a7 (patch)
tree7e3bb3c4615be49a081c6679996ad24279f4a78d
parent77cc3a7ffd430486e856788dd89842b05712b927 (diff)
Add optional PCRE support
-rw-r--r--make.c9
-rw-r--r--src/grab.c14
2 files changed, 17 insertions, 6 deletions
diff --git a/make.c b/make.c
index ce566af..823eb3f 100644
--- a/make.c
+++ b/make.c
@@ -33,6 +33,8 @@ static char *_mkoutpath(const char **, size_t);
#define mkoutpath(...) \
_mkoutpath((const char **)_vtoa(__VA_ARGS__), lengthof(_vtoa(__VA_ARGS__)))
+static bool pflag;
+
int
main(int argc, char **argv)
{
@@ -43,11 +45,14 @@ main(int argc, char **argv)
cbsinit(argc, argv);
rebuild();
- while ((opt = getopt(argc, argv, "d")) != -1) {
+ while ((opt = getopt(argc, argv, "dp")) != -1) {
switch (opt) {
case 'd':
debug = true;
break;
+ case 'p':
+ pflag = true;
+ break;
default:
fputs("Usage: make [-d]\n", stderr);
exit(EXIT_FAILURE);
@@ -83,6 +88,8 @@ main(int argc, char **argv)
#ifdef CBS_IS_C23
cmdadd(&c, "-DGRAB_IS_C23=1");
#endif
+ if (pflag)
+ cmdadd(&c, "-DGRAB_DO_PCRE=1", "-lpcre2-posix");
if (debug)
cmdadd(&c, CFLAGS_DEBUG);
else
diff --git a/src/grab.c b/src/grab.c
index f04f75f..5695226 100644
--- a/src/grab.c
+++ b/src/grab.c
@@ -3,7 +3,6 @@
#include <libgen.h>
#include <limits.h>
#include <locale.h>
-#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -14,12 +13,17 @@
# define nullptr NULL
#endif
-#include "da.h"
-
-#ifndef REG_STARTEND
-# error "REG_STARTEND not defined"
+#if GRAB_DO_PCRE
+# include <pcre2posix.h>
+#else
+# include <regex.h>
+# ifndef REG_STARTEND
+# error "REG_STARTEND not defined"
+# endif
#endif
+#include "da.h"
+
#define die(...) err(EXIT_FAILURE, __VA_ARGS__);
#define diex(...) errx(EXIT_FAILURE, __VA_ARGS__);
#define warn(...) \