summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-06 22:56:36 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-06 22:56:36 -0500
commit4bfae2f646237d21d2ab2714241fe5273759526c (patch)
tree93034dcde024a9aaa6770a1081ed36e89b0ec60c
parent5364889cb38e841a19f20097b117af8030a969c5 (diff)
pcre2
-rw-r--r--.gitignore3
-rw-r--r--Makefile15
-rw-r--r--README.md1
-rw-r--r--main.c38
4 files changed, 53 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index c3220c4..feb6ce6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,4 +10,7 @@ TAGS
*.pdb
*.ilk
*.res
+*.zip
+*.a
+pcre2-10.36
SDL2
diff --git a/Makefile b/Makefile
index 23fddd6..f51aa9b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,17 +1,17 @@
ALL_CFLAGS=$(CFLAGS) -Wall -Wextra -Wshadow -Wconversion -Wpedantic -pedantic -std=gnu11 \
-Wno-unused-function -Wno-fixed-enum-extension -Wimplicit-fallthrough -Wno-format-truncation -Wno-unknown-warning-option
-LIBS=-lSDL2 -lGL -ldl -lm
+LIBS=-lSDL2 -lGL -ldl -lm libpcre2-32.a -Ipcre2-10.36/build
DEBUG_CFLAGS=$(ALL_CFLAGS) -DDEBUG -O0 -g
RELEASE_CFLAGS=$(ALL_CFLAGS) -O3
PROFILE_CFLAGS=$(ALL_CFLAGS) -O3 -DPROFILE=1
GLOBAL_DATA_DIR=/usr/share/ted
LOCAL_DATA_DIR=/home/`logname`/.local/share/ted
INSTALL_BIN_DIR=/usr/bin
-ted: *.[ch]
+ted: *.[ch] libpcre2-32.a
$(CC) main.c -o ted $(DEBUG_CFLAGS) $(LIBS)
-release: *.[ch]
+release: *.[ch] libpcre2-32.a
$(CC) main.c -o ted $(RELEASE_CFLAGS) $(LIBS)
-profile: *.[ch]
+profile: *.[ch] libpcre2-32.a
$(CC) main.c -o ted $(PROFILE_CFLAGS) $(LIBS)
clean:
rm -f ted *.o
@@ -25,3 +25,10 @@ install: release
install -m 644 ted.cfg $(GLOBAL_DATA_DIR)
[ ! -e $(LOCAL_DATA_DIR)/ted.cfg ] && install -o `logname` -g `logname` -m 644 ted.cfg $(LOCAL_DATA_DIR) || :
install ted $(INSTALL_BIN_DIR)
+libpcre2-32.a: pcre2-10.36.zip
+ rm -rf pcre2-10.36
+ unzip $<
+ mkdir pcre2-10.36/build
+ cd pcre2-10.36/build && cmake -DPCRE2_BUILD_PCRE2_32=ON .. && $(MAKE) -j8
+ cp pcre2-10.36/build/$@ ./
+
diff --git a/README.md b/README.md
index 41e9497..7e17462 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,7 @@ sudo apt install gcc libsdl2-dev libgl-dev
Then run
```
+wget https://ftp.pcre.org/pub/pcre/pcre2-10.36.zip
sudo make install -j4
```
diff --git a/main.c b/main.c
index a7fbda0..cf0af05 100644
--- a/main.c
+++ b/main.c
@@ -18,6 +18,8 @@ no_warn_end
#if _WIN32
#include <shellapi.h>
#endif
+#define PCRE2_CODE_UNIT_WIDTH 32
+#include "pcre2.h"
#include "unicode.h"
#include "util.c"
@@ -115,6 +117,42 @@ int main(int argc, char **argv) {
#endif
setlocale(LC_ALL, ""); // allow unicode
+ int error = 0;
+ PCRE2_SIZE error_pos = 0;
+ pcre2_code *regex = pcre2_compile(U"a(.)b", 5, 0, &error, &error_pos, NULL);
+ if (regex) {
+ print("Compiled to %p\n",(void *)regex);
+ pcre2_match_data *match_data = pcre2_match_data_create(100, NULL);
+ if (match_data) {
+ int ret = pcre2_match(regex, U"acb", 3, 0, 0, match_data, NULL);
+ if (ret > 0) {
+ size_t group_count = (size_t)ret;
+ PCRE2_SIZE *groups = pcre2_get_ovector_pointer(match_data);
+ for (size_t i = 0; i < group_count; ++i) {
+ size_t start = (size_t)groups[2*i];
+ size_t end = (size_t)groups[2*i+1];
+ print("%zu-%zu\n", start, end);
+ }
+ print("Match\n");
+ } else {
+ print("No match\n");
+ }
+ pcre2_match_data_free(match_data);
+ } else {
+ print("Couldn't create match data.\n");
+ }
+ pcre2_code_free(regex);
+ } else {
+ char32_t buf[256] = {0};
+ size_t len = (size_t)pcre2_get_error_message(error, buf, sizeof buf - 1);
+ char *error_cstr = str32_to_utf8_cstr(str32(buf, len));
+ if (error_cstr) {
+ print("Error %d at %zu: %s\n", error, error_pos, error_cstr);
+ free(error_cstr);
+ }
+ }
+
+
// read command-line arguments
char const *starting_filename = NULL;
switch (argc) {