Index: Makefile.am ================================================================== --- Makefile.am +++ Makefile.am @@ -18,10 +18,11 @@ include_HEADERS = tclreadline.h INCLUDES = -I$(TCL_INCLUDE_DIR) -I$(READLINE_INCLUDE_DIR) ## libtclreadline_la_LIBADD = $(LIBS) +libtclreadline_la_LIBADD = $(TCL_LIB_SPEC) -lreadline libtclreadline_la_LDFLAGS = -release $(MAJOR).$(MINOR).$(PATCHLEVEL) tclrldir = @TCLRL_DIR@ tclrl_SCRIPTS = pkgIndex.tcl tclreadlineCompleter.tcl tclreadlineInit.tcl tclreadlineSetup.tcl INSTALL_SCRIPT = ${INSTALL_DATA} ADDED configure.ac Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -0,0 +1,266 @@ +dnl -*- autoconf -*- +dnl FILE: "/home/joze/src/tclreadline/configure.in" +dnl LAST MODIFICATION: "Mit, 10 Jan 2001 06:26:43 +0100 (joze)" +dnl (C) 1998 - 2001 by Johannes Zellner, +dnl $Id$ +dnl --- +dnl tclreadline -- gnu readline for tcl +dnl http://www.zellner.org/tclreadline/ +dnl Copyright (c) 1998 - 2001, Johannes Zellner +dnl This software is copyright under the BSD license. + +AC_INIT(tclreadline.c) +AC_CONFIG_HEADERS(config.h) +AC_PREREQ(2.13) +AC_REVISION($Revision$) +AC_CONFIG_AUX_DIR(./aux) + +MAJOR=2 +MINOR=1 +PATCHLEVEL=1 +VERSION=$MAJOR.$MINOR +PATCHLEVEL_STR=$VERSION.$PATCHLEVEL + +AC_SUBST(MAJOR) +AC_SUBST(MINOR) +AC_SUBST(PATCHLEVEL) +AC_SUBST(VERSION) +AC_SUBST(PATCHLEVEL_STR) + +AM_INIT_AUTOMAKE(tclreadline, $PATCHLEVEL_STR) + + +AC_PROG_MAKE_SET + +dnl AM_INIT_AUTOMAKE(tclreadline, $VERSION) + +AC_CANONICAL_HOST +AC_PROG_CC +AC_EXEEXT +dnl AC_LIBTOOL_DLOPEN +AM_PROG_LIBTOOL +AC_SUBST(LIBTOOL_DEPS) + +AC_C_CONST +AC_PROG_INSTALL +AC_PROG_RANLIB +AC_PROG_LN_S + + +# -- WHICH TCL TO USE +AC_ARG_WITH( + tcl, + [ --with-tcl=DIR where to look for tclConfig.sh], + tcl_search=$withval, + tcl_search="" +) + +AC_MSG_CHECKING([which tclConfig.sh to use]) +TCL_LIB_DIR="" +for dir in $tcl_search /usr/lib /usr/local/lib $exec_prefix/lib /usr/local/lib/unix /opt/tcl/lib; do + if test -r $dir/tclConfig.sh; then + TCL_LIB_DIR=$dir + break + fi +done + +if test -z "$TCL_LIB_DIR"; then + AC_MSG_ERROR(Can't find Tcl libraries. Use --with-tcl to specify the directory containing tclConfig.sh on your system.) +fi + +. $TCL_LIB_DIR/tclConfig.sh +AC_MSG_RESULT($TCL_LIB_DIR/tclConfig.sh) +AC_MSG_CHECKING([for your tcl version]) +AC_MSG_RESULT([$TCL_VERSION, patchlevel $TCL_PATCH_LEVEL]) + +# Check, if tcl_version is > 8.0 +if test $TCL_MAJOR_VERSION -lt 8; then + AC_MSG_ERROR(need tcl 8.0 or higher.) +fi + + +# ----------------------------------------------------------------------- +# Set up a new default --prefix. +# ----------------------------------------------------------------------- + +# this is the default anyway: +# AC_PREFIX_DEFAULT(/usr/local) + +if test "${prefix}" = "NONE"; then + prefix=$TCL_PREFIX +fi +TCLRL_LIBDIR="${prefix}/lib" +AC_SUBST(TCLRL_LIBDIR) +TCLRL_DIR="${TCLRL_LIBDIR}/tclreadline$VERSION" +AC_SUBST(TCLRL_DIR) + +# HEADERS +AC_HEADER_STDC +AC_CHECK_HEADERS(string.h) + +#-------------------------------------------------------------------- +# Check for tcl.h +#-------------------------------------------------------------------- + +AC_ARG_WITH(tcl-includes, + [ --with-tcl-includes=DIR where to look for tcl.h], + tcl_includes=$withval, tcl_includes=$prefix/include) + +AC_MSG_CHECKING([where to look for tcl.h]) +TCL_INCLUDE_DIR="" +for dir in $tcl_includes $prefix/include/ /usr/include; do + if test -r $dir/tcl.h; then + TCL_INCLUDE_DIR=$dir + break + fi +done + +if test -z "$TCL_INCLUDE_DIR"; then + AC_MSG_ERROR([ + Can't find tcl.h. Use --with-tcl-includes to specify the directory + containing tcl.h on your system.]) +else + AC_MSG_RESULT($TCL_INCLUDE_DIR/tcl.h) +fi +#-------------------------------------------------------------------- +# Check for readline.h +#-------------------------------------------------------------------- + +AC_ARG_WITH(readline-includes, + [ --with-readline-includes=DIR readline include files in DIR], + rl_includes=$withval, rl_includes="") + +dnl look for readline/readline.h +dnl ^^^^^^^^ +AC_MSG_CHECKING([where to look for readline.h]) +READLINE_INCLUDE_DIR="" +for dir in $rl_includes /usr/local/include /usr/include ; do + if test -r $dir/readline/readline.h; then + READLINE_INCLUDE_DIR=$dir + break + fi +done + +dnl look directly in the include dirs for readline.h +if test -z "$READLINE_INCLUDE_DIR"; then + for dir in $rl_includes /usr/local/include /usr/include ; do + if test -r $dir/readline.h; then + READLINE_INCLUDE_DIR=$dir + AC_DEFINE_UNQUOTED(READLINE_LIBRARY, 1, [ Define if we have libreadline. ]) + break + fi + done +fi + +if test -z "$READLINE_INCLUDE_DIR"; then + AC_MSG_ERROR([ + Can't find readline.h. + Use --with-readline-includes to specify the directory + containing readline.h on your system.]) +fi + +AC_ARG_WITH(readline-library, + [ --with-readline-library=DIR + lib spec to readline (e.g. '-L/usr/local/lib -lreadline')], + LIBS="$LIBS $withval", + AC_SEARCH_LIBS(rl_callback_read_char, readline, , + AC_MSG_RESULT([ + Your readline version does not support readline's alternate interface. + Please upgrade to readline >= 2.2 and retry. + ]) + exit + ) +) + + + +# check for readline's rl_executing_macro +# (could be macro.c's private variable _rl_executing_macro). + +AC_CHECK_DECL(rl_executing_macro +, AC_DEFINE(EXECUTING_MACRO_NAME, rl_executing_macro, + [ Define the name of the executing macro variable in libreadline. ]) +, AC_MSG_CHECKING([for _rl_executing_macro in -lreadline]) + AC_TRY_LINK(,[ + extern char* _rl_executing_macro; + _rl_executing_macro = (char*) 0; + ] + , AC_MSG_RESULT(yes) + AC_DEFINE(EXECUTING_MACRO_HACK, 1, + [ Define if EXECUTING_MACRO_NAME is resolved in libreadline. ]) + AC_DEFINE(EXECUTING_MACRO_NAME, _rl_executing_macro, + [ Define the name of the executing macro variable in libreadline. ]) + , AC_MSG_RESULT(no)) +, [AC_INCLUDES_DEFAULT +#include "$READLINE_INCLUDE_DIR/readline.h"]) + +# check for readline's rl_cleanup_after_signal + +AC_MSG_CHECKING([for rl_cleanup_after_signal() in -lreadline]) +AC_TRY_LINK(,[ + extern void rl_cleanup_after_signal(); + rl_cleanup_after_signal(); +], + AC_MSG_RESULT(yes); + AC_DEFINE(CLEANUP_AFER_SIGNAL, 1, + [ Define if rl_cleanup_after_signal is resolved in libreadline. ]), + AC_MSG_RESULT(no)) + + +AC_MSG_CHECKING([for the readline version number]) +AC_TRY_RUN([ +#include +int main () { + FILE *fp = fopen("conftestversion", "w"); + extern char *rl_library_version; + fprintf(fp, "%s", rl_library_version); + close(fp); + return 0; +}], + READLINE_VERSION=`cat conftestversion` + AC_MSG_RESULT($READLINE_VERSION), + AC_MSG_RESULT(failed), + AC_MSG_RESULT(no cross compiling) +) + + +AC_ARG_ENABLE(tclshrl, + [ --enable-tclshrl build statically linked tclshrl], + [dnl action if given + case "${enableval}" in + yes) enable_static=true ;; + no) enable_static=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-static) ;; + esac + ], + [dnl action if not given + enable_static=false + ] +) +AM_CONDITIONAL(STATIC_TCLSHRL, test x$enable_static = xtrue) + +AC_ARG_ENABLE(wishrl, + [ --enable-wishrl build statically linked wishrl], + [dnl action if given + case "${enableval}" in + yes) + enable_static=true + dnl source the tkConfig.sh which defines TK_LIB_SPEC + . $TCL_LIB_DIR/tkConfig.sh + AC_SUBST(TK_LIB_SPEC) + ;; + no) enable_static=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-static) ;; + esac + ], + [dnl action if not given + enable_static=false + ] +) +AM_CONDITIONAL(STATIC_WISHRL, test x$enable_static = xtrue) + + +AC_SUBST(TCL_INCLUDE_DIR) +AC_SUBST(TCL_LIB_SPEC) +AC_SUBST(READLINE_INCLUDE_DIR) +AC_OUTPUT(Makefile tclreadline.h tclreadlineInit.tcl tclreadlineSetup.tcl tclreadline.n pkgIndex.tcl) DELETED configure.in Index: configure.in ================================================================== --- configure.in +++ configure.in @@ -1,259 +0,0 @@ -dnl -*- autoconf -*- -dnl FILE: "/home/joze/src/tclreadline/configure.in" -dnl LAST MODIFICATION: "Mit, 10 Jan 2001 06:26:43 +0100 (joze)" -dnl (C) 1998 - 2001 by Johannes Zellner, -dnl $Id$ -dnl --- -dnl tclreadline -- gnu readline for tcl -dnl http://www.zellner.org/tclreadline/ -dnl Copyright (c) 1998 - 2001, Johannes Zellner -dnl This software is copyright under the BSD license. - -AC_INIT(tclreadline.c) -AM_CONFIG_HEADER(config.h) -AC_PREREQ(2.13) -AC_REVISION($Revision$) -AC_CONFIG_AUX_DIR(./aux) - -MAJOR=2 -MINOR=1 -PATCHLEVEL=1 -VERSION=$MAJOR.$MINOR -PATCHLEVEL_STR=$VERSION.$PATCHLEVEL - -AC_SUBST(MAJOR) -AC_SUBST(MINOR) -AC_SUBST(PATCHLEVEL) -AC_SUBST(VERSION) -AC_SUBST(PATCHLEVEL_STR) - -AM_INIT_AUTOMAKE(tclreadline, $PATCHLEVEL_STR) - - -AC_PROG_MAKE_SET - -dnl AM_INIT_AUTOMAKE(tclreadline, $VERSION) - -AC_CANONICAL_HOST -AC_PROG_CC -AC_EXEEXT -dnl AC_LIBTOOL_DLOPEN -AM_PROG_LIBTOOL -AC_SUBST(LIBTOOL_DEPS) - -AC_C_CONST -AC_PROG_INSTALL -AC_PROG_RANLIB -AC_PROG_LN_S - - -# -- WHICH TCL TO USE -AC_ARG_WITH( - tcl, - [ --with-tcl=DIR where to look for tclConfig.sh], - tcl_search=$withval, - tcl_search="" -) - -AC_MSG_CHECKING([which tclConfig.sh to use]) -TCL_LIB_DIR="" -for dir in $tcl_search /usr/lib /usr/local/lib $exec_prefix/lib /usr/local/lib/unix /opt/tcl/lib; do - if test -r $dir/tclConfig.sh; then - TCL_LIB_DIR=$dir - break - fi -done - -if test -z "$TCL_LIB_DIR"; then - AC_MSG_ERROR(Can't find Tcl libraries. Use --with-tcl to specify the directory containing tclConfig.sh on your system.) -fi - -. $TCL_LIB_DIR/tclConfig.sh -AC_MSG_RESULT($TCL_LIB_DIR/tclConfig.sh) -AC_MSG_CHECKING([for your tcl version]) -AC_MSG_RESULT([$TCL_VERSION, patchlevel $TCL_PATCH_LEVEL]) - -# Check, if tcl_version is > 8.0 -if test $TCL_MAJOR_VERSION -lt 8; then - AC_MSG_ERROR(need tcl 8.0 or higher.) -fi - - -# ----------------------------------------------------------------------- -# Set up a new default --prefix. -# ----------------------------------------------------------------------- - -# this is the default anyway: -# AC_PREFIX_DEFAULT(/usr/local) - -if test "${prefix}" = "NONE"; then - prefix=$TCL_PREFIX -fi -TCLRL_LIBDIR="${prefix}/lib" -AC_SUBST(TCLRL_LIBDIR) -TCLRL_DIR="${TCLRL_LIBDIR}/tclreadline$VERSION" -AC_SUBST(TCLRL_DIR) - -# HEADERS -AC_HEADER_STDC -AC_CHECK_HEADERS(string.h) - -#-------------------------------------------------------------------- -# Check for tcl.h -#-------------------------------------------------------------------- - -AC_ARG_WITH(tcl-includes, - [ --with-tcl-includes=DIR where to look for tcl.h], - tcl_includes=$withval, tcl_includes=$prefix/include) - -AC_MSG_CHECKING([where to look for tcl.h]) -TCL_INCLUDE_DIR="" -for dir in $tcl_includes $prefix/include/ /usr/include; do - if test -r $dir/tcl.h; then - TCL_INCLUDE_DIR=$dir - break - fi -done - -if test -z "$TCL_INCLUDE_DIR"; then - AC_MSG_ERROR([ - Can't find tcl.h. Use --with-tcl-includes to specify the directory - containing tcl.h on your system.]) -else - AC_MSG_RESULT($TCL_INCLUDE_DIR/tcl.h) -fi -#-------------------------------------------------------------------- -# Check for readline.h -#-------------------------------------------------------------------- - -AC_ARG_WITH(readline-includes, - [ --with-readline-includes=DIR readline include files in DIR], - rl_includes=$withval, rl_includes="") - -dnl look for readline/readline.h -dnl ^^^^^^^^ -AC_MSG_CHECKING([where to look for readline.h]) -READLINE_INCLUDE_DIR="" -for dir in $rl_includes /usr/local/include /usr/include ; do - if test -r $dir/readline/readline.h; then - READLINE_INCLUDE_DIR=$dir - break - fi -done - -dnl look directly in the include dirs for readline.h -if test -z "$READLINE_INCLUDE_DIR"; then - for dir in $rl_includes /usr/local/include /usr/include ; do - if test -r $dir/readline.h; then - READLINE_INCLUDE_DIR=$dir - AC_DEFINE_UNQUOTED(READLINE_LIBRARY, 1, [ Define if we have libreadline. ]) - break - fi - done -fi - -if test -z "$READLINE_INCLUDE_DIR"; then - AC_MSG_ERROR([ - Can't find readline.h. - Use --with-readline-includes to specify the directory - containing readline.h on your system.]) -fi - -AC_ARG_WITH(readline-library, - [ --with-readline-library=DIR - lib spec to readline (e.g. '-L/usr/local/lib -lreadline')], - LIBS="$LIBS $withval", - AC_CHECK_LIB(readline, rl_callback_read_char, , - AC_MSG_RESULT([ - Your readline version does not support readline's alternate interface. - Please upgrade to readline >= 2.2 and retry. - ]) - exit - ) -) - - - -# check for readline's (macro.c) private variable -# _rl_executing_macro. - -AC_MSG_CHECKING([for _rl_executing_macro in -lreadline]) -AC_TRY_LINK(,[ - extern char* _rl_executing_macro; - _rl_executing_macro = (char*) 0; -], - AC_MSG_RESULT(yes); - AC_DEFINE(EXECUTING_MACRO_HACK, 1, - [ Define if _rl_executing_macro is resolved in libreadline. ]), - AC_MSG_RESULT(no)) - -# check for readline's rl_cleanup_after_signal - -AC_MSG_CHECKING([for rl_cleanup_after_signal() in -lreadline]) -AC_TRY_LINK(,[ - extern void rl_cleanup_after_signal(); - rl_cleanup_after_signal(); -], - AC_MSG_RESULT(yes); - AC_DEFINE(CLEANUP_AFER_SIGNAL, 1, - [ Define if rl_cleanup_after_signal is resolved in libreadline. ]), - AC_MSG_RESULT(no)) - - -AC_MSG_CHECKING([for the readline version number]) -AC_TRY_RUN([ -#include -int main () { - FILE *fp = fopen("conftestversion", "w"); - extern char *rl_library_version; - fprintf(fp, "%s", rl_library_version); - close(fp); - return 0; -}], - READLINE_VERSION=`cat conftestversion` - AC_MSG_RESULT($READLINE_VERSION), - AC_MSG_RESULT(failed), - AC_MSG_RESULT(no cross compiling) -) - - -AC_ARG_ENABLE(tclshrl, - [ --enable-tclshrl build statically linked tclshrl], - [dnl action if given - case "${enableval}" in - yes) enable_static=true ;; - no) enable_static=false ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-static) ;; - esac - ], - [dnl action if not given - enable_static=false - ] -) -AM_CONDITIONAL(STATIC_TCLSHRL, test x$enable_static = xtrue) - -AC_ARG_ENABLE(wishrl, - [ --enable-wishrl build statically linked wishrl], - [dnl action if given - case "${enableval}" in - yes) - enable_static=true - dnl source the tkConfig.sh which defines TK_LIB_SPEC - . $TCL_LIB_DIR/tkConfig.sh - AC_SUBST(TK_LIB_SPEC) - ;; - no) enable_static=false ;; - *) AC_MSG_ERROR(bad value ${enableval} for --enable-static) ;; - esac - ], - [dnl action if not given - enable_static=false - ] -) -AM_CONDITIONAL(STATIC_WISHRL, test x$enable_static = xtrue) - - -AC_SUBST(TCL_INCLUDE_DIR) -AC_SUBST(TCL_LIB_SPEC) -AC_SUBST(READLINE_INCLUDE_DIR) -AC_OUTPUT(Makefile tclreadline.h tclreadlineInit.tcl tclreadlineSetup.tcl tclreadline.n pkgIndex.tcl) Index: tclreadline.c ================================================================== --- tclreadline.c +++ tclreadline.c @@ -39,11 +39,11 @@ /** * this prototype is private in readline's file `macro.c'. * We need it here to decide, if we should read more * characters from a macro. Dirty, but it should work. */ -extern char* _rl_executing_macro; +extern char* EXECUTING_MACRO_NAME; #endif #include "tclreadline.h" static const char* tclrl_library = TCLRL_LIBRARY; static const char* tclrl_version_str = TCLRL_VERSION_STR; @@ -232,11 +232,11 @@ case TCLRL_READ: rl_callback_handler_install( objc == 3 ? Tcl_GetStringFromObj(objv[2], 0) - : "%", TclReadlineLineCompleteHandler); + : "% ", TclReadlineLineCompleteHandler); Tcl_CreateFileHandler(0, TCL_READABLE, TclReadlineReadHandler, (ClientData) NULL); /** @@ -247,18 +247,18 @@ * readline in a defined state. XXX */ tclrl_state = LINE_PENDING; while (!TclReadlineLineComplete()) { -#ifdef EXECUTING_MACRO_HACK +#ifdef EXECUTING_MACRO_NAME /** * check first, if more characters are * available from _rl_executing_macro, * because Tcl_DoOneEvent() will (naturally) * not detect this `event'. */ - if (_rl_executing_macro) + if (EXECUTING_MACRO_NAME) TclReadlineReadHandler((ClientData) NULL, TCL_READABLE); else #endif Tcl_DoOneEvent(TCL_ALL_EVENTS); } @@ -466,21 +466,21 @@ static void TclReadlineReadHandler(ClientData clientData, int mask) { if (mask & TCL_READABLE) { -#ifdef EXECUTING_MACRO_HACK +#ifdef EXECUTING_MACRO_NAME do { #endif rl_callback_read_char(); -#ifdef EXECUTING_MACRO_HACK +#ifdef EXECUTING_MACRO_NAME /** * check, if we're inside a macro and * if so, read all macro characters * until the next eol. */ - } while (_rl_executing_macro && !TclReadlineLineComplete()); + } while (EXECUTING_MACRO_NAME && !TclReadlineLineComplete()); #endif } } static void @@ -501,30 +501,33 @@ */ char* expansion = (char*) NULL; int status = history_expand(ptr, &expansion); - if (status >= 1) { + if (status >= 2) { /* TODO: make this a valid tcl output */ printf("%s\n", expansion); - } else if (-1 == status) { + free(ptr); + free(expansion); + return; + } else if (status <= -1) { Tcl_AppendResult - (tclrl_interp, "error in history expansion\n", (char*) NULL); + (tclrl_interp, "error in history expansion: ", expansion, "\n", (char*) NULL); TclReadlineTerminate(TCL_ERROR); - } - /** - * TODO: status == 2 ... - */ - - Tcl_AppendResult(tclrl_interp, expansion, (char*) NULL); - -#ifdef EXECUTING_MACRO_HACK + free(ptr); + free(expansion); + return; + } else { + Tcl_AppendResult(tclrl_interp, expansion, (char*) NULL); + } + +#ifdef EXECUTING_MACRO_NAME /** * don't stuff macro lines * into readline's history. */ - if(!_rl_executing_macro) { + if(!EXECUTING_MACRO_NAME) { #endif /** * don't stuff empty lines * into readline's history. * don't stuff twice the same @@ -535,11 +538,11 @@ add_history(expansion); } if (tclrl_last_line) free(tclrl_last_line); tclrl_last_line = strdup(expansion); -#ifdef EXECUTING_MACRO_HACK +#ifdef EXECUTING_MACRO_NAME } #endif /** * tell the calling routines to terminate. */ @@ -697,19 +700,23 @@ sprintf(end_s, "%d", end); Tcl_ResetResult(tclrl_interp); /* clear result space */ state = Tcl_VarEval(tclrl_interp, tclrl_custom_completer, " \"", quoted_text, "\" ", start_s, " ", end_s, " \"", quoted_rl_line_buffer, "\"", (char*) NULL); - FREE(quoted_text); - FREE(quoted_rl_line_buffer); if (TCL_OK != state) { Tcl_AppendResult (tclrl_interp, " `", tclrl_custom_completer, " \"", quoted_text, "\" ", start_s, " ", end_s, " \"", quoted_rl_line_buffer, "\"' failed.", (char*) NULL); TclReadlineTerminate(state); + free(quoted_text); + free(quoted_rl_line_buffer); return matches; } + free(quoted_text); + quoted_text = NULL; + free(quoted_rl_line_buffer); + quoted_rl_line_buffer = NULL; obj = Tcl_GetObjResult(tclrl_interp); status = Tcl_ListObjGetElements(tclrl_interp, obj, &objc, &objv); if (TCL_OK != status) return matches;