aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Mikhirev2014-11-14 15:17:09 +0300
committerDmitry Mikhirev2014-11-14 15:17:09 +0300
commit1f913a978aa1d9c1f797623c414752df15ba36ca (patch)
tree2f20da2eb987823d6d8b3c1dbb2c3af5dd6aa43a
downloadmake_pcre-1f913a978aa1d9c1f797623c414752df15ba36ca.tar.gz
make_pcre-1f913a978aa1d9c1f797623c414752df15ba36ca.tar.bz2
make_pcre-1f913a978aa1d9c1f797623c414752df15ba36ca.tar.xz
make_pcre-1f913a978aa1d9c1f797623c414752df15ba36ca.zip
initial commit
-rw-r--r--.gitignore4
-rw-r--r--GNUmakefile17
-rw-r--r--pcre.c42
3 files changed, 63 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8b90876
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+*.o
+*.so
+tags
+.vimrc
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644
index 0000000..91d3616
--- /dev/null
+++ b/GNUmakefile
@@ -0,0 +1,17 @@
+-load pcre.so
+
+MAKE_INCLUDE_DIR := $(HOME)/src/make-4.1
+CFLAGS += -I$(MAKE_INCLUDE_DIR)
+
+pcre.so: CFLAGS += $(shell pcre-config --cflags)
+pcre.so: LDFLAGS += $(shell pcre-config --libs)
+pcre.so: pcre.c
+ $(CC) $(CFLAGS) -fPIC $(LDFLAGS) -shared -o $@ $<
+
+ifeq ($(m ^pattern$,pattern), pattern)
+check:
+ @echo test PASSED
+else
+check:
+ @echo test FAILED
+endif
diff --git a/pcre.c b/pcre.c
new file mode 100644
index 0000000..d8129ef
--- /dev/null
+++ b/pcre.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <string.h>
+
+#include <gnumake.h>
+#include <pcre.h>
+
+int plugin_is_GPL_compatible;
+
+const int MAX_CAP = 256;
+
+char *match(const char *name, int argc, char **argv)
+{
+ pcre *re;
+ const char *err;
+ int erroffset;
+ int ncap = 0;
+ int ovec[MAX_CAP*3];
+ char *retstr = NULL;
+
+ re = pcre_compile(argv[0], 0, &err, &erroffset, NULL);
+ if (err != NULL) {
+ fprintf(stderr, "%s: %d: %s\n", name, erroffset, err);
+ goto end_match;
+ }
+
+ ncap = pcre_exec(re, NULL, argv[1], strlen(argv[1]), 0, 0, ovec, MAX_CAP*3);
+
+end_match:
+ if (ncap) {
+ int len = ovec[1] - ovec[0];
+ retstr = gmk_alloc(len + 1);
+ strncpy(retstr, argv[1] + ovec[0], len);
+ retstr[len + 1] = '\0';
+ }
+ return retstr;
+}
+
+int pcre_gmk_setup()
+{
+ gmk_add_function("m", (gmk_func_ptr)match, 2, 2, GMK_FUNC_NOEXPAND);
+ return 1;
+}