mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
Make Oniguruma/regexp optional
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.
This commit is contained in:
11
builtin.c
11
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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user