summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-12-18 20:11:28 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-12-18 20:11:28 +0000
commit2fc0e1b0bbcf143d0d3664d7ed9ba8d41e6fcb0d (patch)
treef161fc75cec4c8abcf018b1b91d0c556edccd9cb
parentf34b50f089383917ab527f3ab5f9c0a8144bbf0d (diff)
downloadpcre-2fc0e1b0bbcf143d0d3664d7ed9ba8d41e6fcb0d.tar.gz
Added --enable-pcretest-libreadline.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@287 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--ChangeLog2
-rw-r--r--NON-UNIX-USE2
-rw-r--r--README18
-rw-r--r--configure.ac88
-rw-r--r--doc/pcrebuild.315
-rw-r--r--doc/pcretest.18
-rw-r--r--pcretest.c61
7 files changed, 149 insertions, 45 deletions
diff --git a/ChangeLog b/ChangeLog
index 4e8bcb5..174ab38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -93,6 +93,8 @@ Version 7.5 12-Nov-07
17. Added --enable-pcregrep-libz and --enable-pcregrep-libbz2.
+18. Added --enable-pcretest-libreadline.
+
Version 7.4 21-Sep-07
---------------------
diff --git a/NON-UNIX-USE b/NON-UNIX-USE
index fe6cd02..9239838 100644
--- a/NON-UNIX-USE
+++ b/NON-UNIX-USE
@@ -84,7 +84,7 @@ The following are generic comments about building the PCRE C library "by hand".
ucptable.h
(5) Also ensure that you have the following file, which is #included as source
- when building a debugging version of PCRE and is also used by pcretest.
+ when building a debugging version of PCRE, and is also used by pcretest.
pcre_printint.src
diff --git a/README b/README
index 721354e..64156e2 100644
--- a/README
+++ b/README
@@ -258,11 +258,23 @@ library. You can read more about them in the pcrebuild man page.
This automatically implies --enable-rebuild-chartables (see above).
-. It is possible to compile pcregrep to use libz and/or libbz2 to read .gz
- and .bz2 files (respectively) by specifying one or both of
+. It is possible to compile pcregrep to use libz and/or libbz2, in order to
+ read .gz and .bz2 files (respectively), by specifying one or both of
--enable-pcregrep-libz
--enable-pcregrep-libbz2
+
+ Of course, the relevant libraries must be installed on your system.
+
+. It is possible to compile pcretest so that it links with the libreadline
+ library, by specifying
+
+ --enable-pcretest-libreadline
+
+ If this is done, when pcretest's input is from a terminal, it reads it using
+ the readline() function. This provides line-editing and history facilities.
+ Note that libreadline is GPL-licenced, so if you distribute a binary of
+ pcretest linked in this way, there may be licensing issues.
The "configure" script builds the following files for the basic C library:
@@ -731,4 +743,4 @@ The distribution should contain the following files:
Philip Hazel
Email local part: ph10
Email domain: cam.ac.uk
-Last updated: 17 December 2007
+Last updated: 18 December 2007
diff --git a/configure.ac b/configure.ac
index 0b5c51c..b9821ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -166,6 +166,12 @@ AC_ARG_ENABLE(pcregrep-libbz2,
[link pcregrep with libbz2 to handle .bz2 files]),
, enable_pcregrep_libbz2=no)
+# Handle --enable-pcretest-libreadline
+AC_ARG_ENABLE(pcretest-libreadline,
+ AS_HELP_STRING([--enable-pcretest-libreadline],
+ [link pcretest with libreadline]),
+ , enable_pcretest_libreadline=no)
+
# Handle --with-posix-malloc-threshold=NBYTES
AC_ARG_WITH(posix-malloc-threshold,
AS_HELP_STRING([--with-posix-malloc-threshold=NBYTES],
@@ -318,6 +324,12 @@ AC_CHECK_LIB([z], [gzopen], [HAVE_LIBZ=1])
AC_CHECK_HEADERS([bzlib.h], [HAVE_BZLIB_H=1])
AC_CHECK_LIB([bz2], [BZ2_bzopen], [HAVE_LIBBZ2=1])
+# Check for the availabiity of libreadline
+
+AC_CHECK_HEADERS([readline/readline.h], [HAVE_READLINE_H=1])
+AC_CHECK_HEADERS([readline/history.h], [HAVE_HISTORY_H=1])
+AC_CHECK_LIB([readline], [readline], [HAVE_LIB_READLINE=1])
+
# This facilitates -ansi builds under Linux
dnl AC_DEFINE([_GNU_SOURCE], [], [Enable GNU extensions in glibc])
@@ -363,6 +375,11 @@ if test "$enable_pcregrep_libbz2" = "yes"; then
able to handle .bz2 files.])
fi
+if test "$enable_pcretest_libreadline" = "yes"; then
+ AC_DEFINE([SUPPORT_LIBREADLINE], [], [
+ Define to allow pcretest to be linked with libreadline.])
+fi
+
AC_DEFINE_UNQUOTED([NEWLINE], [$ac_pcre_newline_value], [
The value of NEWLINE determines the newline character sequence. On
systems that support it, "configure" can be used to override the
@@ -505,6 +522,20 @@ if test "$enable_pcregrep_libbz2" = "yes"; then
if test "$LIBS" = ""; then LIBS=-lbz2; else LIBS="$LIBS -lbz2"; fi
fi
+# Similarly for --enable-pcretest-readline
+
+if test "$enable_pcretest_libreadline" = "yes"; then
+ if test "$HAVE_READLINE_H" != "1"; then
+ echo "** Cannot --enable-pcretest-readline because readline/readline.h was not found."
+ exit 1
+ fi
+ if test "$HAVE_HISTORY_H" != "1"; then
+ echo "** Cannot --enable-pcretest-readline because readline/history.h was not found."
+ exit 1
+ fi
+ if test "$LIBS" = ""; then LIBS=-lreadline; else LIBS="$LIBS -lreadline"; fi
+fi
+
# Produce these files, in addition to config.h.
AC_CONFIG_FILES(
Makefile
@@ -532,34 +563,35 @@ cat <<EOF
$PACKAGE-$VERSION configuration summary:
- Install prefix ............. : ${prefix}
- C preprocessor ............. : ${CPP}
- C compiler ................. : ${CC}
- C++ preprocessor ........... : ${CXXCPP}
- C++ compiler ............... : ${CXX}
- Linker ..................... : ${LD}
- C preprocessor flags ....... : ${CPPFLAGS}
- C compiler flags ........... : ${CFLAGS}
- C++ compiler flags ......... : ${CXXFLAGS}
- Linker flags ............... : ${LDFLAGS}
- Extra libraries ............ : ${LIBS}
-
- Build C++ library .......... : ${enable_cpp}
- Enable UTF-8 support ....... : ${enable_utf8}
- Unicode properties ......... : ${enable_unicode_properties}
- Newline char/sequence ...... : ${enable_newline}
- \R matches only ANYCRLF .... : ${enable_bsr_anycrlf}
- EBCDIC coding .............. : ${enable_ebcdic}
- Rebuild char tables ........ : ${enable_rebuild_chartables}
- Use stack recursion ........ : ${enable_stack_for_recursion}
- POSIX mem threshold ........ : ${with_posix_malloc_threshold}
- Internal link size ......... : ${with_link_size}
- Match limit ................ : ${with_match_limit}
- Match limit recursion ...... : ${with_match_limit_recursion}
- Build shared libs .......... : ${enable_shared}
- Build static libs .......... : ${enable_static}
- Link pcregrep with libz .... : ${enable_pcregrep_libz}
- Link pcregrep with libbz2 .. : ${enable_pcregrep_libbz2}
+ Install prefix .................. : ${prefix}
+ C preprocessor .................. : ${CPP}
+ C compiler ...................... : ${CC}
+ C++ preprocessor ................ : ${CXXCPP}
+ C++ compiler .................... : ${CXX}
+ Linker .......................... : ${LD}
+ C preprocessor flags ............ : ${CPPFLAGS}
+ C compiler flags ................ : ${CFLAGS}
+ C++ compiler flags .............. : ${CXXFLAGS}
+ Linker flags .................... : ${LDFLAGS}
+ Extra libraries ................. : ${LIBS}
+
+ Build C++ library ............... : ${enable_cpp}
+ Enable UTF-8 support ............ : ${enable_utf8}
+ Unicode properties .............. : ${enable_unicode_properties}
+ Newline char/sequence ........... : ${enable_newline}
+ \R matches only ANYCRLF ......... : ${enable_bsr_anycrlf}
+ EBCDIC coding ................... : ${enable_ebcdic}
+ Rebuild char tables ............. : ${enable_rebuild_chartables}
+ Use stack recursion ............. : ${enable_stack_for_recursion}
+ POSIX mem threshold ............. : ${with_posix_malloc_threshold}
+ Internal link size .............. : ${with_link_size}
+ Match limit ..................... : ${with_match_limit}
+ Match limit recursion ........... : ${with_match_limit_recursion}
+ Build shared libs ............... : ${enable_shared}
+ Build static libs ............... : ${enable_static}
+ Link pcregrep with libz ......... : ${enable_pcregrep_libz}
+ Link pcregrep with libbz2 ....... : ${enable_pcregrep_libbz2}
+ Link pcretest with libreadline .. : ${enable_pcretest_libreadline}
EOF
diff --git a/doc/pcrebuild.3 b/doc/pcrebuild.3
index 609604c..b6fe597 100644
--- a/doc/pcrebuild.3
+++ b/doc/pcrebuild.3
@@ -270,6 +270,19 @@ to the \fBconfigure\fP command. These options naturally require that the
relevant libraries are installed on your system. Configuration will fail if
they are not.
.
+.SH "PCRETEST OPTION FOR LIBREADLINE SUPPORT"
+.rs
+.sp
+If you add
+.sp
+ --enable-pcretest-libreadline
+.sp
+to the \fBconfigure\fP command, \fBpcretest\fP is linked with the
+\fBlibreadline\fP library, and when its input is from a terminal, it reads it
+using the \fBreadline()\fP function. This provides line-editing and history
+facilities. Note that \fBlibreadline\fP is GPL-licenced, so if you distribute a
+binary of \fBpcretest\fP linked in this way, there may be licensing issues.
+.
.
.SH "SEE ALSO"
.rs
@@ -291,6 +304,6 @@ Cambridge CB2 3QH, England.
.rs
.sp
.nf
-Last updated: 17 December 2007
+Last updated: 18 December 2007
Copyright (c) 1997-2007 University of Cambridge.
.fi
diff --git a/doc/pcretest.1 b/doc/pcretest.1
index 4012126..8660718 100644
--- a/doc/pcretest.1
+++ b/doc/pcretest.1
@@ -97,6 +97,12 @@ that file and writes to stdout. Otherwise, it reads from stdin and writes to
stdout, and prompts for each line of input, using "re>" to prompt for regular
expressions, and "data>" to prompt for data lines.
.P
+When \fBpcretest\fP is built, a configuration option can specify that it should
+be linked with the \fBlibreadline\fP library. When this is done, if the input
+is from a terminal, it is read using the \fBreadline()\fP function. This
+provides line-editing and history facilities. The output from the \fB-help\fP
+option states whether or not \fBreadline()\fP will be used.
+.P
The program handles any number of sets of input on a single input file. Each
set starts with a regular expression, and continues with any number of data
lines to be matched against the pattern.
@@ -711,6 +717,6 @@ Cambridge CB2 3QH, England.
.rs
.sp
.nf
-Last updated: 19 November 2007
+Last updated: 18 December 2007
Copyright (c) 1997-2007 University of Cambridge.
.fi
diff --git a/pcretest.c b/pcretest.c
index 3bfed06..b99ac84 100644
--- a/pcretest.c
+++ b/pcretest.c
@@ -48,6 +48,12 @@ POSSIBILITY OF SUCH DAMAGE.
#include <locale.h>
#include <errno.h>
+#ifdef SUPPORT_LIBREADLINE
+#include <unistd.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+#endif
+
/* A number of things vary for Windows builds. Originally, pcretest opened its
input and output without "b"; then I was told that "b" was needed in some
@@ -189,6 +195,7 @@ optimal way of handling this, but hey, this is just a test program!
Arguments:
f the file to read
start where in buffer to start (this *must* be within buffer)
+ prompt for stdin or readline()
Returns: pointer to the start of new data
could be a copy of start, or could be moved
@@ -196,7 +203,7 @@ Returns: pointer to the start of new data
*/
static uschar *
-extend_inputline(FILE *f, uschar *start)
+extend_inputline(FILE *f, uschar *start, const char *prompt)
{
uschar *here = start;
@@ -207,8 +214,36 @@ for (;;)
if (rlen > 1000)
{
int dlen;
- if (fgets((char *)here, rlen, f) == NULL)
- return (here == start)? NULL : start;
+
+ /* If libreadline support is required, use readline() to read a line if the
+ input is a terminal. Note that readline() removes the trailing newline, so
+ we must put it back again, to be compatible with fgets(). */
+
+#ifdef SUPPORT_LIBREADLINE
+ if (isatty(fileno(f)))
+ {
+ size_t len;
+ char *s = readline(prompt);
+ if (s == NULL) return (here == start)? NULL : start;
+ len = strlen(s);
+ if (len > 0) add_history(s);
+ if (len > rlen - 1) len = rlen - 1;
+ memcpy(here, s, len);
+ here[len] = '\n';
+ here[len+1] = 0;
+ free(s);
+ }
+ else
+#endif
+
+ /* Read the next line by normal means, prompting if the file is stdin. */
+
+ {
+ if (f == stdin) printf(prompt);
+ if (fgets((char *)here, rlen, f) == NULL)
+ return (here == start)? NULL : start;
+ }
+
dlen = (int)strlen((char *)here);
if (dlen > 0 && here[dlen - 1] == '\n') return start;
here += dlen;
@@ -728,7 +763,14 @@ return 0;
static void
usage(void)
{
-printf("Usage: pcretest [options] [<input> [<output>]]\n");
+printf("Usage: pcretest [options] [<input file> [<output file>]]\n\n");
+printf("Input and output default to stdin and stdout.\n");
+#ifdef SUPPORT_LIBREADLINE
+printf("If input is a terminal, readline() is used to read from it.\n");
+#else
+printf("This version of pcretest is not linked with readline().\n");
+#endif
+printf("\nOptions:\n");
printf(" -b show compiled code (bytecode)\n");
printf(" -C show PCRE compile-time options and exit\n");
printf(" -d debug: show compiled code and information (-b and -i)\n");
@@ -997,8 +1039,7 @@ while (!done)
use_utf8 = 0;
debug_lengths = 1;
- if (infile == stdin) printf(" re> ");
- if (extend_inputline(infile, buffer) == NULL) break;
+ if (extend_inputline(infile, buffer, " re> ") == NULL) break;
if (infile != stdin) fprintf(outfile, "%s", (char *)buffer);
fflush(outfile);
@@ -1114,8 +1155,7 @@ while (!done)
pp++;
}
if (*pp != 0) break;
- if (infile == stdin) printf(" > ");
- if ((pp = extend_inputline(infile, pp)) == NULL)
+ if ((pp = extend_inputline(infile, pp, " > ")) == NULL)
{
fprintf(outfile, "** Unexpected EOF\n");
done = 1;
@@ -1289,7 +1329,7 @@ while (!done)
{
for (;;)
{
- if (extend_inputline(infile, buffer) == NULL)
+ if (extend_inputline(infile, buffer, NULL) == NULL)
{
done = 1;
goto CONTINUE;
@@ -1684,8 +1724,7 @@ while (!done)
len = 0;
for (;;)
{
- if (infile == stdin) printf("data> ");
- if (extend_inputline(infile, buffer + len) == NULL)
+ if (extend_inputline(infile, buffer + len, "data> ") == NULL)
{
if (len > 0) break;
done = 1;