From 475bc25800451c76d9a721fb35628693758a15e0 Mon Sep 17 00:00:00 2001 From: data-man Date: Mon, 24 Jan 2022 07:34:59 +0500 Subject: Using Oniguruma library (optionally) --- Makefile | 10 ++++++++++ eval.c | 7 ++++++- expr.h | 7 ++++++- parse.c | 7 ++++++- util.c | 7 ++++++- util.h | 7 ++++++- 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 18a51d3..77de641 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,11 @@ ifeq ($(OS),Linux) LOCAL_LDFLAGS += -Wl,--as-needed LOCAL_LDLIBS += -lacl -lcap -lattr -lrt +ifdef USE_ONIGURUMA +LOCAL_LDLIBS += -lonig +LOCAL_CFLAGS += -DUSE_ONIGURUMA +endif + # These libraries are not built with msan, so disable them MSAN_CFLAGS += -DBFS_HAS_SYS_ACL=0 -DBFS_HAS_SYS_CAPABILITY=0 -DBFS_HAS_SYS_XATTR=0 @@ -82,6 +87,11 @@ endif ifeq ($(OS),NetBSD) LOCAL_LDLIBS += -lutil + +ifdef USE_ONIGURUMA +LOCAL_LDLIBS += -lonig +LOCAL_CFLAGS += -DUSE_ONIGURUMA +endif endif ifneq ($(filter asan,$(MAKECMDGOALS)),) diff --git a/eval.c b/eval.c index ec2701b..8dd8f75 100644 --- a/eval.c +++ b/eval.c @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -55,6 +54,12 @@ #include #include +#ifdef USE_ONIGURUMA + #include +#else + #include +#endif + struct eval_state { /** Data about the current file. */ const struct BFTW *ftwbuf; diff --git a/expr.h b/expr.h index c25d1ca..82df7bf 100644 --- a/expr.h +++ b/expr.h @@ -26,12 +26,17 @@ #include "exec.h" #include "printf.h" #include "stat.h" -#include #include #include #include #include +#ifdef USE_ONIGURUMA + #include +#else + #include +#endif + /** * Possible types of numeric comparison. */ diff --git a/parse.c b/parse.c index 8ff47c2..9ff2c2a 100644 --- a/parse.c +++ b/parse.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -60,6 +59,12 @@ #include #include +#ifdef USE_ONIGURUMA + #include +#else + #include +#endif + // Strings printed by -D tree for "fake" expressions static char *fake_and_arg = "-a"; static char *fake_false_arg = "-false"; diff --git a/util.c b/util.c index 71b3c53..b5ef8f8 100644 --- a/util.c +++ b/util.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,12 @@ #include #include +#ifdef USE_ONIGURUMA + #include +#else + #include +#endif + #if BFS_HAS_SYS_PARAM # include #endif diff --git a/util.h b/util.h index 37c03fa..213d514 100644 --- a/util.h +++ b/util.h @@ -23,12 +23,17 @@ #include #include -#include #include #include #include #include +#ifdef USE_ONIGURUMA + #include +#else + #include +#endif + // Some portability concerns #ifdef __has_feature -- cgit v1.2.3 From 09124f64f6eb332e49b4d13c4975fc36260f7f2b Mon Sep 17 00:00:00 2001 From: data-man Date: Mon, 24 Jan 2022 13:34:09 +0500 Subject: Simplifying --- eval.c | 7 +------ expr.h | 7 +------ parse.c | 7 +------ regexp.h | 26 ++++++++++++++++++++++++++ util.c | 7 +------ util.h | 8 +------- 6 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 regexp.h diff --git a/eval.c b/eval.c index 8dd8f75..b5dfeed 100644 --- a/eval.c +++ b/eval.c @@ -37,6 +37,7 @@ #include "time.h" #include "trie.h" #include "util.h" +#include "regexp.h" #include #include #include @@ -54,12 +55,6 @@ #include #include -#ifdef USE_ONIGURUMA - #include -#else - #include -#endif - struct eval_state { /** Data about the current file. */ const struct BFTW *ftwbuf; diff --git a/expr.h b/expr.h index 82df7bf..a4e6c0d 100644 --- a/expr.h +++ b/expr.h @@ -25,18 +25,13 @@ #include "eval.h" #include "exec.h" #include "printf.h" +#include "regexp.h" #include "stat.h" #include #include #include #include -#ifdef USE_ONIGURUMA - #include -#else - #include -#endif - /** * Possible types of numeric comparison. */ diff --git a/parse.c b/parse.c index 9ff2c2a..2bf5992 100644 --- a/parse.c +++ b/parse.c @@ -41,6 +41,7 @@ #include "time.h" #include "typo.h" #include "util.h" +#include "regexp.h" #include #include #include @@ -59,12 +60,6 @@ #include #include -#ifdef USE_ONIGURUMA - #include -#else - #include -#endif - // Strings printed by -D tree for "fake" expressions static char *fake_and_arg = "-a"; static char *fake_false_arg = "-false"; diff --git a/regexp.h b/regexp.h new file mode 100644 index 0000000..14da4d5 --- /dev/null +++ b/regexp.h @@ -0,0 +1,26 @@ +/**************************************************************************** + * bfs * + * Copyright (C) 2016-2022 Tavian Barnes * + * * + * Permission to use, copy, modify, and/or distribute this software for any * + * purpose with or without fee is hereby granted. * + * * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * + ****************************************************************************/ + +#ifndef BFS_REGEXP_H +#define BFS_REGEXP_H + +#ifdef USE_ONIGURUMA + #include +#else + #include +#endif + +#endif // BFS_REGEXP_H diff --git a/util.c b/util.c index b5ef8f8..9e221a8 100644 --- a/util.c +++ b/util.c @@ -16,6 +16,7 @@ #include "util.h" #include "dstring.h" +#include "regexp.h" #include #include #include @@ -29,12 +30,6 @@ #include #include -#ifdef USE_ONIGURUMA - #include -#else - #include -#endif - #if BFS_HAS_SYS_PARAM # include #endif diff --git a/util.h b/util.h index 213d514..893651e 100644 --- a/util.h +++ b/util.h @@ -20,7 +20,7 @@ #ifndef BFS_UTIL_H #define BFS_UTIL_H - +#include "regexp.h" #include #include #include @@ -28,12 +28,6 @@ #include #include -#ifdef USE_ONIGURUMA - #include -#else - #include -#endif - // Some portability concerns #ifdef __has_feature -- cgit v1.2.3 From 3cdf67e77da64ba1235265836f29b228deca3642 Mon Sep 17 00:00:00 2001 From: data-man Date: Mon, 24 Jan 2022 20:38:00 +0500 Subject: Apply suggestions from code review --- Makefile | 15 +++++---------- regexp.h | 5 +++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 77de641..8af4a99 100644 --- a/Makefile +++ b/Makefile @@ -72,11 +72,6 @@ ifeq ($(OS),Linux) LOCAL_LDFLAGS += -Wl,--as-needed LOCAL_LDLIBS += -lacl -lcap -lattr -lrt -ifdef USE_ONIGURUMA -LOCAL_LDLIBS += -lonig -LOCAL_CFLAGS += -DUSE_ONIGURUMA -endif - # These libraries are not built with msan, so disable them MSAN_CFLAGS += -DBFS_HAS_SYS_ACL=0 -DBFS_HAS_SYS_CAPABILITY=0 -DBFS_HAS_SYS_XATTR=0 @@ -87,11 +82,6 @@ endif ifeq ($(OS),NetBSD) LOCAL_LDLIBS += -lutil - -ifdef USE_ONIGURUMA -LOCAL_LDLIBS += -lonig -LOCAL_CFLAGS += -DUSE_ONIGURUMA -endif endif ifneq ($(filter asan,$(MAKECMDGOALS)),) @@ -121,6 +111,11 @@ ifneq ($(filter release,$(MAKECMDGOALS)),) CFLAGS := $(DEFAULT_CFLAGS) -O3 -flto -DNDEBUG endif +ifeq ($(USE_ONIGURUMA),1) +LOCAL_LDLIBS += -lonig +LOCAL_CFLAGS += -DBFS_USE_ONIGURUMA=1 +endif + ALL_CPPFLAGS = $(LOCAL_CPPFLAGS) $(CPPFLAGS) ALL_CFLAGS = $(ALL_CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) $(DEPFLAGS) ALL_LDFLAGS = $(ALL_CFLAGS) $(LOCAL_LDFLAGS) $(LDFLAGS) diff --git a/regexp.h b/regexp.h index 14da4d5..8654b58 100644 --- a/regexp.h +++ b/regexp.h @@ -1,6 +1,7 @@ /**************************************************************************** * bfs * - * Copyright (C) 2016-2022 Tavian Barnes * + * Copyright (C) 2022 Tavian Barnes and * + * BFS contributors * * * * Permission to use, copy, modify, and/or distribute this software for any * * purpose with or without fee is hereby granted. * @@ -17,7 +18,7 @@ #ifndef BFS_REGEXP_H #define BFS_REGEXP_H -#ifdef USE_ONIGURUMA +#if BFS_USE_ONIGURUMA == 1 #include #else #include -- cgit v1.2.3