]> granicus.if.org Git - jq/commitdiff
Make Oniguruma/regexp optional
authorNicolas Williams <nico@cryptonector.com>
Sat, 14 Feb 2015 19:31:34 +0000 (13:31 -0600)
committerNicolas Williams <nico@cryptonector.com>
Mon, 16 Feb 2015 00:32:01 +0000 (18:32 -0600)
Tests won't pass if built without Oniguruma.  We don't have a way to
make a test optional yet.  That will come later.  For now the ability to
reduce build-time dependencies could really help some users.

builtin.c
configure.ac

index 40108da741768964b692cd89cb20f794c6502305..a07b97261b985d79d998085bc29b2dfd7830ac36 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -1,7 +1,9 @@
 #include <assert.h>
 #include <limits.h>
 #include <math.h>
+#ifdef HAVE_ONIGURUMA
 #include <oniguruma.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 #include "builtin.h"
@@ -535,6 +537,7 @@ static jv f_group_by_impl(jq_state *jq, jv input, jv keys) {
   }
 }
 
+#ifdef HAVE_ONIGURUMA
 static int f_match_name_iter(const UChar* name, const UChar *name_end, int ngroups,
     int *groups, regex_t *reg, void *arg) {
   jv captures = *(jv*)arg;
@@ -551,7 +554,6 @@ static int f_match_name_iter(const UChar* name, const UChar *name_end, int ngrou
   return 0;
 }
 
-
 static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
   int test = jv_equal(testmode, jv_true());
   jv result;
@@ -742,6 +744,7 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
   jv_free(regex);
   return result;
 }
+#endif /* HAVE_ONIGURUMA */
 
 static jv minmax_by(jv values, jv keys, int is_min) {
   if (jv_get_kind(values) != JV_KIND_ARRAY)
@@ -961,7 +964,9 @@ static const struct cfunction function_list[] = {
   {(cfunction_ptr)f_get_search_list, "get_search_list", 1},
   {(cfunction_ptr)f_get_prog_origin, "get_prog_origin", 1},
   {(cfunction_ptr)f_get_jq_origin, "get_jq_origin", 1},
+#ifdef HAVE_ONIGURUMA
   {(cfunction_ptr)f_match, "_match_impl", 4},
+#endif
   {(cfunction_ptr)f_modulemeta, "modulemeta", 1},
   {(cfunction_ptr)f_input, "_input", 1},
   {(cfunction_ptr)f_debug, "debug", 1},
@@ -1076,6 +1081,7 @@ static const char* const jq_builtins[] = {
   "def flatten: reduce .[] as $i ([]; if $i | type == \"array\" then . + ($i | flatten) else . + [$i] end);",
   "def flatten($x): reduce .[] as $i ([]; if $i | type == \"array\" and $x > 0 then . + ($i | flatten($x-1)) else . + [$i] end);",
   "def range($x): range(0;$x);",
+#ifdef HAVE_ONIGURUMA
   "def match(re; mode): _match_impl(re; mode; false)|.[];",
   "def match($val): ($val|type) as $vt | if $vt == \"string\" then match($val; null)"
   "   elif $vt == \"array\" and ($val | length) > 1 then match($val[0]; $val[1])"
@@ -1145,7 +1151,8 @@ static const char* const jq_builtins[] = {
   "         end"
   "     end ;"
   "  [match($re; flags + \"g\")] as $edits | _stredit($edits; s) ;",
-  "def gsub($re; s): gsub($re; s; \"\");"
+  "def gsub($re; s): gsub($re; s; \"\");",
+#endif /* HAVE_ONIGURUMA */
 
   //#######################################################################
   // range/3, with a `by` expression argument
index 93d4074893ef19d6f32c16d8969033edc90bf635..5364985a2dac5e92a505192c22752b0b49d8c429 100644 (file)
@@ -76,7 +76,8 @@ AC_CHECK_HEADER("oniguruma.h",
 if test $HAVE_ONIGURUMA != 1; then
     AC_MSG_NOTICE([Oniguruma was not found.])
     AC_MSG_NOTICE([ Try setting the location using '--with-oniguruma=PREFIX' ])
-    AC_MSG_ERROR([ oniguruma is required to build jq.])
+else
+    AC_DEFINE([HAVE_ONIGURUMA],1,[Define to 1 if Oniguruma is installed])
 fi