"Hema Seetharamaiah" <h...@treap.net> writes:

> Attached is a patch that provides a new option without-tre - which can be
> used to build elinks without libtre dependency.

With that patch, configure without any TRE-related option outputs here:

checking for TRE... checking for TRE in pkg-config... yes
checking for TRE header and library... yes
no

i.e. you have nested AC_MSG_CHECKING/AC_MSG_RESULT pairs, and the
final result is also incorrect.  I think the simplest solution
would be just

if test "$with_tre" = no; then
        AC_MSG_CHECKING([[for TRE]])
        AC_MSG_RESULT([[not used]])
else
        ... put the original tests here ...
fi

Your patch also contains spaces between tabs in indentation,
and a redundant use of EL_SAVE_FLAGS.

I'm attaching a revised patch that should fix these problems.
I also renamed HAVE_TRE_REGEX_H to CONFIG_TRE because it can
now be unset even if the header and library exist all right.

I should also ask about storage of personal data and licensing
of changes but it's getting too late here.

From 3fee12ca965f3e6269800f79b054e5d26c842fb9 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <k...@iki.fi>
Date: Sun, 26 Apr 2009 23:46:17 +0300
Subject: [PATCH] Add --without-tre option

elinks-lite in Debian does not depend on any libraries (except
gnutls and the usual libc and libgcc). Including this option
will allow elinks-lite to be built without libtre dependency.

Based on a patch by Hema Seetharamaiah <h...@treap.net>.
---
 configure.in             |   83 ++++++++++++++++++++++++++++------------------
 src/config/options.inc   |    2 +-
 src/elinks.h             |    2 +-
 src/viewer/text/search.c |   22 ++++++------
 4 files changed, 64 insertions(+), 45 deletions(-)

diff --git a/configure.in b/configure.in
index 631b605..bf56d95 100644
--- a/configure.in
+++ b/configure.in
@@ -933,43 +933,62 @@ fi
 # Check for TRE library
 # ===================================================================
 
-AC_MSG_CHECKING([[for TRE in pkg-config]])
-if pkg-config tre; then
-	TRE_CFLAGS=`pkg-config --cflags tre`
-	TRE_LIBS=`pkg-config --libs tre`
-	AC_MSG_RESULT([[yes]])
+AC_ARG_WITH([[tre]], [[  --without-tre           disable TRE regex search support]])
+if test "$with_tre" = no; then
+	AC_MSG_CHECKING([[for TRE]])
+	AC_MSG_RESULT([[disabled]])
+	tre_log="no (explicitly disabled)"
 else
-	# <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=513055>
-	# "libtre-dev: /usr/lib/pkgconfig/tre.pc missing"
-	# so we look for the library even if pkg-config doesn't know about it.
-	TRE_CFLAGS=
-	TRE_LIBS=-ltre
-	AC_MSG_RESULT([[no, but let's try defaults]])
-fi
+	AC_MSG_CHECKING([[for TRE in pkg-config]])
+	if pkg-config tre; then
+		TRE_CFLAGS=`pkg-config --cflags tre`
+		TRE_LIBS=`pkg-config --libs tre`
+		AC_MSG_RESULT([[yes]])
+	else
+		# <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=513055>
+		# "libtre-dev: /usr/lib/pkgconfig/tre.pc missing"
+		# so we look for the library even if pkg-config doesn't know about it.
+		TRE_CFLAGS=
+		TRE_LIBS=-ltre
+		AC_MSG_RESULT([[no, but let's try defaults]])
+	fi
 
-AC_MSG_CHECKING([[for TRE header and library]])
-EL_SAVE_FLAGS
-CFLAGS="$TRE_CFLAGS $CFLAGS"
-LIBS="$TRE_LIBS $LIBS"
-AC_TRY_LINK([#include <tre/regex.h>],
-	    [regex_t re;
-	     regmatch_t match[1];
-	     regwcomp(&re, L"zap", REG_ICASE);
-	     regwexec(&re, L"ELIZAPROGRAM", 1, match, 0);],
-	    [AC_MSG_RESULT([[yes]])
-	     AC_DEFINE([HAVE_TRE_REGEX_H], [1],
-		       [Define to 1 if you have the <tre/regex.h> header file.])
-	     # TRE_CFLAGS will be used only where needed.
-	     # TRE_LIBS will be kept in LIBS and used everywhere.
-	     EL_RESTORE_FLAGS
-	     LIBS="$TRE_LIBS $LIBS"],
-	    [AC_MSG_RESULT([[no]])
-	     TRE_CFLAGS=
-	     TRE_LIBS=
-	     EL_RESTORE_FLAGS])
+	AC_MSG_CHECKING([[for TRE header and library]])
+	EL_SAVE_FLAGS
+	CFLAGS="$TRE_CFLAGS $CFLAGS"
+	LIBS="$TRE_LIBS $LIBS"
+	AC_TRY_LINK([#include <tre/regex.h>],
+		    [regex_t re;
+		     regmatch_t match[1];
+		     regwcomp(&re, L"zap", REG_ICASE);
+		     regwexec(&re, L"ELIZAPROGRAM", 1, match, 0);],
+		    [AC_MSG_RESULT([[yes]])
+		     AC_DEFINE([CONFIG_TRE], [1],
+			       [Define as 1 to use the TRE library for regular expression searching.  This requires the <tre/regex.h> header file.])
+		     # TRE_CFLAGS will be used only where needed.
+		     # TRE_LIBS will be kept in LIBS and used everywhere.
+		     EL_RESTORE_FLAGS
+		     LIBS="$TRE_LIBS $LIBS"
+		     # Using TRE with UTF-8 in ELinks requires that wchar_t
+		     # has the same representation as unicode_val_T.  See
+		     # src/elinks.h for the check.  It would be nice to move
+		     # the check to this configure script, so that the result
+		     # could be logged, but the ac_cv_sizeof_wchar_t shell
+		     # variable set by AC_CHECK_SIZEOF is undocumented.
+		     tre_log="TRE (if wchar_t is suitable)"],
+		    [AC_MSG_RESULT([[no]])
+		     TRE_CFLAGS=
+		     TRE_LIBS=
+		     EL_RESTORE_FLAGS
+		     tre_log=no])
+fi
 AC_SUBST(TRE_CFLAGS)
 AC_SUBST(TRE_LIBS)
+EL_LOG_CONFIG([[CONFIG_TRE]], [[Regexp searching]], [[$tre_log]])
 
+# ELinks cares about SIZEOF_WCHAR_T only if it should use TRE.
+# However, the macro will be in config.h in any case,
+# so it seems safest to always find the right value.
 AC_CHECK_SIZEOF([wchar_t], [4], [[#include <wchar.h>]])
 
 # ===================================================================
diff --git a/src/config/options.inc b/src/config/options.inc
index b9c6a7f..163f7b9 100644
--- a/src/config/options.inc
+++ b/src/config/options.inc
@@ -407,7 +407,7 @@ static struct option_info config_options_info[] = {
 		N_("Whether the search should match the document text while "
 		"maintaining case sensitivity.")),
 
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 	INIT_OPT_INT("document.browse.search", N_("Regular expressions"),
 		"regex", 0, 0, 2, 0,
 		N_("Enable searching with regular expressions:\n"
diff --git a/src/elinks.h b/src/elinks.h
index 0e164a1..b6fa252 100644
--- a/src/elinks.h
+++ b/src/elinks.h
@@ -49,7 +49,7 @@
 
 #ifdef CONFIG_UTF8
 #if SIZEOF_WCHAR_T != 4
-#undef HAVE_TRE_REGEX_H
+#undef CONFIG_TRE
 #endif
 #endif
 
diff --git a/src/viewer/text/search.c b/src/viewer/text/search.c
index 83656dc..0cb673a 100644
--- a/src/viewer/text/search.c
+++ b/src/viewer/text/search.c
@@ -18,7 +18,7 @@
 #include <sys/types.h> /* FreeBSD needs this before regex.h */
 #include <stdlib.h>
 #include <string.h>
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 #include <tre/regex.h>
 #endif
 
@@ -270,7 +270,7 @@ get_range(struct document *document, int y, int height, int l,
 	return 0;
 }
 
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 /** Returns a string @c doc that is a copy of the text in the search
  * nodes from @a s1 to (@a s1 + @a doclen - 1) with the space at the
  * end of each line converted to a new-line character (LF). */
@@ -465,7 +465,7 @@ is_in_range_regex(struct document *document, int y, int height,
 
 	return common_ctx.found;
 }
-#endif /* HAVE_TRE_REGEX_H */
+#endif /* CONFIG_TRE */
 
 static UCHAR *
 memacpy_u(unsigned char *text, int textlen, int utf8)
@@ -602,7 +602,7 @@ is_in_range(struct document *document, int y, int height,
 	if (get_range(document, y, height, textlen, &s1, &s2))
 		return 0;
 
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 	if (get_opt_int("document.browse.search.regex"))
 		return is_in_range_regex(document, y, height, text, textlen,
 					 min, max, s1, s2, utf8);
@@ -681,7 +681,7 @@ srch_failed:
 	*pl = len;
 }
 
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 struct get_searched_regex_context {
 	int xoffset;
 	int yoffset;
@@ -749,7 +749,7 @@ get_searched_regex(struct document_view *doc_view, struct point **pt, int *pl,
 	*pt = ctx.points;
 	*pl = ctx.len;
 }
-#endif /* HAVE_TRE_REGEX_H */
+#endif /* CONFIG_TRE */
 
 static void
 get_searched(struct document_view *doc_view, struct point **pt, int *pl, int utf8)
@@ -773,7 +773,7 @@ get_searched(struct document_view *doc_view, struct point **pt, int *pl, int utf
 		return;
 	}
 
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 	if (get_opt_int("document.browse.search.regex"))
 		get_searched_regex(doc_view, pt, pl, l, s1, s2, utf8);
 	else
@@ -1594,7 +1594,7 @@ search_typeahead(struct session *ses, struct document_view *doc_view,
  * a nice cleanup target ;-). --pasky */
 
 enum search_option {
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 	SEARCH_OPT_REGEX,
 #endif
 	SEARCH_OPT_CASE,
@@ -1602,7 +1602,7 @@ enum search_option {
 };
 
 static struct option_resolver resolvers[] = {
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 	{ SEARCH_OPT_REGEX,	"regex" },
 #endif
 	{ SEARCH_OPT_CASE,	"case" },
@@ -1669,7 +1669,7 @@ search_dlg_do(struct terminal *term, struct memory_list *ml,
 			       hop->values, SEARCH_OPTIONS);
 	hop->data = data;
 
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 #define SEARCH_WIDGETS_COUNT 8
 #else
 #define SEARCH_WIDGETS_COUNT 5
@@ -1693,7 +1693,7 @@ search_dlg_do(struct terminal *term, struct memory_list *ml,
 	field = get_dialog_offset(dlg, SEARCH_WIDGETS_COUNT);
 	add_dlg_field(dlg, text, 0, 0, NULL, MAX_STR_LEN, field, history);
 
-#ifdef HAVE_TRE_REGEX_H
+#ifdef CONFIG_TRE
 	add_dlg_radio(dlg, _("Normal search", term), 1, 0, &hop->values[SEARCH_OPT_REGEX].number);
 	add_dlg_radio(dlg, _("Regexp search", term), 1, 1, &hop->values[SEARCH_OPT_REGEX].number);
 	add_dlg_radio(dlg, _("Extended regexp search", term), 1, 2, &hop->values[SEARCH_OPT_REGEX].number);
-- 
1.6.1.3.25.g2aacd6

Attachment: pgppmu9WhzYXS.pgp
Description: PGP signature

_______________________________________________
elinks-dev mailing list
elinks-dev@linuxfromscratch.org
http://linuxfromscratch.org/mailman/listinfo/elinks-dev

Reply via email to