Check-in [5f3ab55c4a]
Not logged in
Overview
Comment:Harmonize file headers, indent and whitespace in all files
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | origin/devel
Files: files | file ages | folders
SHA1: 5f3ab55c4ac7b9891b42f188cb0f9175f3588409
User & Date: quentin@minster.io on 2014-02-26 00:38:52
Other Links: branch diff | manifest | tags
Context
2014-02-26
22:37
Cleanup of compilation warnings * Add the -Wall compilation flag * Use rl_ding() instead of undeclared ding() check-in: a9511ba2db user: quentin@minster.io tags: trunk, origin/devel
00:38
Harmonize file headers, indent and whitespace in all files check-in: 5f3ab55c4a user: quentin@minster.io tags: trunk, origin/devel
2014-02-19
00:07
Apply the Gentoo patchset Gentoo ebuild: dev-tcltk/tclreadline-2.1.0-r4 Fully applied patches: * direct sed patches from the ebuild * tclreadline-2.1.0-gold.patch * tclreadline-2.1.0-rl-executing-macro.patch * tclreadline-2.1.0-rl-history-expand.patch * tclreadline-2.1.0-rl-prompt.patch Partially applied patches: * tclreadline-2.1.0-alloc-free.patch check-in: f61c58e424 user: quentin@minster.io tags: trunk, origin/devel
Changes

Modified COPYING from [a7c8b5b8da] to [c1821e21e0].

1
2


3
4

5
6
7
8

9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29


1
2
3

4
5
6
7

8
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
-
-
+
+

-
+



-
+








-
+












   
   Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>

   Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
   All rights reserved.
   

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:
   

     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
     * Neither the name of Johannes Zellner nor the names of contributors
       to this software may be used to endorse or promote products derived
       from this software without specific prior written permission.
       

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Modified Makefile.am from [e10a890a98] to [45d2bf5cbc].

1
2

3
4
5
6
7
8
9

10
11
12
13
14
15
16
1

2


3
4
5
6

7
8
9
10
11
12
13
14

-
+
-
-




-
+







## -*- automake -*-
## FILE: "/home/joze/src/tclreadline/Makefile.am"
## FILE: Makefile.am
## LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:33 +0100 (joze)"
## (C) 2000 - 2001 by Johannes Zellner, <johannes@zellner.org>
## $Id$
## ---
## tclreadline -- gnu readline for tcl
## http://www.zellner.org/tclreadline/
## Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
## Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
## This software is copyright under the BSD license.
## ---

## AUTOMAKE_OPTIONS = foreign

lib_LTLIBRARIES = libtclreadline.la

Modified README from [58b66551a6] to [cd868e87e1].

1

2
3
4
5
6
7
8
9

10
11


12
13
14
15
16
17
18

1


2
3

4
5

6

7
8
9
10
11
12
13
14
15
16
-
+
-
-


-


-
+
-

+
+







FILE: "/home/joze/src/tclreadline/README"
FILE: README
LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:33 +0100 (joze)"
(C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
$Id$
---

tclreadline -- gnu readline for tcl
http://www.zellner.org/tclreadline/
Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>

This software is copyright under the BSD license.
---



tclreadline


1. Introduction
---------------
48
49
50
51
52
53
54
55

56
57
58
59
60
61





62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83


84
85
86

87
88
89
90
91


92
93

94
95
96
97
98
99
100



101
102
103

104
105
106
107
108
109
110
111
112




113
114
115
116
117



118
119
120
121
122
123
124
46
47
48
49
50
51
52

53
54





55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79


80
81
82
83

84
85
86
87


88
89
90

91
92
93
94
95



96
97
98
99
100

101
102
103
104
105
106




107
108
109
110
111
112



113
114
115
116
117
118
119
120
121
122







-
+

-
-
-
-
-
+
+
+
+
+


-
+

















-
-
+
+


-
+



-
-
+
+

-
+




-
-
-
+
+
+


-
+





-
-
-
-
+
+
+
+


-
-
-
+
+
+








    (c) The usual ./configure; make; make install sequence should do the rest.

    (d) Optionally (or additionally) you can build the executables
        tclshrl and / or wishrl which are a readline enhanced replacement
        for tclsh and wish. To compile these executable you should type

	    ./configure --enable-tclshrl --enable-wishrl
        ./configure --enable-tclshrl --enable-wishrl

	(or one of these if you want just tclshrl or wishrl).
	NOTE that these executables need an installed version of
	tclreadline because they need some script files to run
	so you can't test tclshrl/wishrl before installing
	the tclreadline scripts.
    (or one of these if you want just tclshrl or wishrl).
    NOTE that these executables need an installed version of
    tclreadline because they need some script files to run
    so you can't test tclshrl/wishrl before installing
    the tclreadline scripts.

        Building statically linked executables is DISCOURAGED
	but necessary on systems which don't support shared libs.
    but necessary on systems which don't support shared libs.


4. Using tclreadline for interactive tcl scripting.
---------------------------------------------------

copy the sample.tclshrc to $HOME/.tclshrc. If you use another interpreter
like wish, you should copy the file sample.tclshrc to $HOME/.wishrc
(or whatever the manual page of your interpreter says.) If you have
installed tclreadline properly, you are just ready to start:
start your favorite interpreter. The tclreadlineSetup.tcl script
does the rest.


4. History and Changes.
-----------------------

tclreadline-1.2 0: (Mar 2000)
	switched to a BSD type license, introduced a new read-only
	variable `license' in the tclreadline namespace.
    switched to a BSD type license, introduced a new read-only
    variable `license' in the tclreadline namespace.

tclreadline-1.1 0: (Mar 2000)
	code cleanup and checked that it compiles with tcl8.3
    code cleanup and checked that it compiles with tcl8.3

tclreadline-1.0.1: (Sep 1999)

	changes:
	    - tclreadline::readline bell.
    changes:
        - tclreadline::readline bell.
          Ring the terminal bell, obeying the setting
		  of bell-style -- audible or visible.
          of bell-style -- audible or visible.


tclreadline-1.0.0: (Sep 1999)

	note:
	    - the script completer procs are written.
		  this is `sort of a first usable release'.
    note:
        - the script completer procs are written.
          this is `sort of a first usable release'.

    fixes:
	    - some minor configure.in fixes.
        - some minor configure.in fixes.


tclreadline-0.9.3: (Sep 1999)

    changes:
	    - tk completion.
		- multiple fallback completion routines for unknown
		  commands.
		- readline reset-terminal sub-function.
        - tk completion.
        - multiple fallback completion routines for unknown
          commands.
        - readline reset-terminal sub-function.

    fixes:
	    - another revision of procession events and macros.
		  includes a hack using a readline's internal
		  variable _rl_executing_macro.
        - another revision of procession events and macros.
          includes a hack using a readline's internal
          variable _rl_executing_macro.


tclreadline-0.9.2: (Aug 1999)

    changes:
        - history event `!' expansion on <Tab>
        - if tclreadline::historyLength >= 0,
159
160
161
162
163
164
165
166

167
168

169
170
171
172
173
174
175
157
158
159
160
161
162
163

164
165

166
167
168
169
170
171
172
173







-
+

-
+







        - tclreadline::readline customcompleter
        - tclreadline::readline builtincompleter
        - tclreadline::readline eofchar
        - variable, array and '[' command completion by the script
          tclreadline::ScriptCompleter. See the man page or try
          typing "puts $env<TAB>" ... Command completion currently only
          works, if a '[' preceeds immediately a non-white character.
        - the redefinition of the command `cd' was removed due to 
        - the redefinition of the command `cd' was removed due to
          multiple requests. This redefinition can be found in the
          file `sample.tclshrc' and can be uncommented, if desired. 
          file `sample.tclshrc' and can be uncommented, if desired.
        - the definition of the command `ls' was moved outside the
          proc tclreadline::Setup and can be used with the command
          namespace import tclreadline::ls (see sample.tclshrc).

    bug fixes:
        - lines added to tcl's history. (were only in readline's hist.)
        - macro mappings didn't work. (only when hitting

Modified SCENARIO from [797d1f2bf8] to [704bad2f7f].

1
2
3
4
5
6
7
8
9
10
11

12
13
14


15
16
17
18
19
20
21
22

23
24
25

26
27
28
1
2
3
4
5
6
7
8
9
10

11
12


13
14
15
16
17
18
19
20
21

22
23
24

25
26
27
28










-
+

-
-
+
+







-
+


-
+




YOU TYPE:                         YOU GET:


=== SCENARIO 1 ===

puts $<tab>                       puts $
                                      + a list of all variables ...
puts $t<tab>                      puts $t
                                      + a list of all variables
									    beginning with t ...
                                        beginning with t ...
puts $tcl_pl<tab>                 puts $tcl_platform(
	                                  + a list of all array names of
									    tcl_platform
                                      + a list of all array names of
                                        tcl_platform
puts $tcl_platform(b<tab>         puts $tcl_platform(byteOrder)



=== SCENARIO 2 ===

button .b                         button .b
.b co<tab>                        .b configure 
.b co<tab>                        .b configure
.b co<tab><tab>                   .b configure
                                      + a list of all button options ...
.b co<tab><tab>-r<tab>            .b configure -relief 
.b co<tab><tab>-r<tab>            .b configure -relief
.b co<tab><tab>-r<tab>g<tab>      .b configure -relief groove


Modified autogen.sh from [e610613007] to [8923c07aed].

1
2

3
4
5






6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23





24
25
26
27
28
29
30
31





32
33
34
35

36
37
38
39
40


41
42
43
44
45


46
47
48
49



50
51
52
53
54
55
56
57
58
59
60
61
62
1

2


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22





23
24
25
26
27
28
29
30





31
32
33
34
35
36
37
38

39
40
41
42


43
44
45
46
47


48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

-
+
-
-

+
+
+
+
+
+













-
-
-
-
-
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+



-
+



-
-
+
+



-
-
+
+



-
+
+
+













#!/bin/sh
# FILE: "/home/joze/src/tclreadline/autogen.sh"
# FILE: autogen.sh
# LAST MODIFICATION: "Mit, 10 Jan 2001 06:28:43 +0100 (joze)"
# (C) 2000 - 2001 by Johannes Zellner, <johannes@zellner.org>
# $Id$
# ---
# tclreadline -- gnu readline for tcl
# http://www.zellner.org/tclreadline/
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# This software is copyright under the BSD license.
# ---

srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.

ORIGDIR=`pwd`
cd $srcdir
PROJECT=tclreadline
TEST_TYPE=-f
FILE=tclreadline.c

DIE=0

(autoconf --version) < /dev/null > /dev/null 2>&1 || {
	echo
	echo "You must have autoconf installed to compile $PROJECT."
	echo "Download the appropriate package for your distribution,"
	echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
	DIE=1
    echo
    echo "You must have autoconf installed to compile $PROJECT."
    echo "Download the appropriate package for your distribution,"
    echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
    DIE=1
}

(automake --version) < /dev/null > /dev/null 2>&1 || {
	echo
	echo "You must have automake installed to compile $PROJECT."
	echo "Get ftp://sourceware.cygnus.com/pub/automake/automake-1.4.tar.gz"
	echo "(or a newer version if it is available)"
	DIE=1
    echo
    echo "You must have automake installed to compile $PROJECT."
    echo "Get ftp://sourceware.cygnus.com/pub/automake/automake-1.4.tar.gz"
    echo "(or a newer version if it is available)"
    DIE=1
}

if test "$DIE" -eq 1; then
	exit 1
    exit 1
fi

test $TEST_TYPE $FILE || {
	echo "You must run this script in the top-level $PROJECT directory"
	exit 1
    echo "You must run this script in the top-level $PROJECT directory"
    exit 1
}

if test -z "$*"; then
	echo "I am going to run ./configure with no arguments - if you wish "
        echo "to pass any to it, please specify them on the $0 command line."
    echo "I am going to run ./configure with no arguments - if you wish "
    echo "to pass any to it, please specify them on the $0 command line."
fi

case $CC in
*xlc | *xlc\ * | *lcc | *lcc\ *) am_opt=--include-deps;;
    *xlc | *xlc\ * | *lcc | *lcc\ *)
        am_opt=--include-deps
        ;;
esac

aclocal $ACLOCAL_FLAGS

# optionally feature autoheader
(autoheader --version)  < /dev/null > /dev/null 2>&1 && autoheader

automake -a $am_opt
autoconf
cd $ORIGDIR

$srcdir/configure --enable-maintainer-mode "$@"

Modified aux/tcltags from [14371eb7a9] to [f7acdd7bce].

1
2

3
4
5





6
7
8
9

10
11
12
13
14
15
16
1

2

3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20

-
+
-


+
+
+
+
+



-
+







#!/usr/local/bin/tclsh
# FILE: "/home/joze/bin/script/tcltags"
# FILE: aux/tcltags
# LAST MODIFIED: "Mon Sep 28 10:09:29 1998 (joze)"
# $Id$
# ---
# tclreadline -- gnu readline for tcl
# http://www.zellner.org/tclreadline/
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# This software is copyright under the BSD license.
# ---

set tags [open "tags" a+]
#set tags stdout
#_BoxHandle	Z_Box.c	/^int _BoxHandle (Box *boxPtr, Tcl_Interp *interp, int argc, char **argv)$/;"	f
#_BoxHandle Z_Box.c /^int _BoxHandle (Box *boxPtr, Tcl_Interp *interp, int argc, char **argv)$/;"   f

foreach file "$argv" {

    if {[file exists $file]} {

        set source [open $file r]
        if {$source == 0} {

Modified aux/vimtags from [f85b0cc88e] to [3390267426].

1
2
3

4
5
6
7





8

9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
1
2

3



4
5
6
7
8
9

10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27


-
+
-
-
-

+
+
+
+
+
-
+






-
+










#!/usr/local/bin/tclsh
# ==================================================================
# FILE: "/home/joze/bin/script/vimtags"
# FILE: aux/vimtags
# LAST MODIFIED: "Thu Oct 01 13:20:11 1998 (joze)"
# (c) 1998 by Johannes Zellner
# Johannes.Zellner@physik.uni-karlsruhe.de
# $Id$
# ---
# tclreadline -- gnu readline for tcl
# http://www.zellner.org/tclreadline/
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# This software is copyright under the BSD license.
# ================================================================== 
# ==================================================================


if [file readable tags] {
    set tags [open tags r]
    set vim [open tags.vim w]
    while {[gets $tags line] != -1} {
        if [regexp "^\(\[^ 	!\]*\)\[ 	\]" $line all proc] {
        if [regexp "^\(\[^  !\]*\)\[    \]" $line all proc] {
            set proc [string trim $proc]
            if {$proc != ""} {
                puts $vim "syntax keyword Tag $proc"
            }
        }
    }
    close $tags
    close $vim
}

Modified configure.ac from [84c8e6ef95] to [d1e0c2eb78].

1
2

3
4
5
6
7
8
9

10

11
12
13
14
15
16
17
1

2


3
4
5
6

7
8
9
10
11
12
13
14
15
16

-
+
-
-




-
+

+







dnl -*- autoconf -*-
dnl FILE: "/home/joze/src/tclreadline/configure.in"
dnl FILE: configure.in
dnl LAST MODIFICATION: "Mit, 10 Jan 2001 06:26:43 +0100 (joze)"
dnl (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
dnl $Id$
dnl ---
dnl tclreadline -- gnu readline for tcl
dnl http://www.zellner.org/tclreadline/
dnl Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
dnl Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
dnl This software is copyright under the BSD license.
dnl ---

AC_INIT(tclreadline.c)
AC_CONFIG_HEADERS(config.h)
AC_PREREQ(2.13)
AC_REVISION($Revision$)
AC_CONFIG_AUX_DIR(./aux)

140
141
142
143
144
145
146
147
148
149
150
151





152
153
154
155
156
157
158
159
160
161
162
163
164

165
166
167
168
169
170
171





172
173
174
175
176
177
178
139
140
141
142
143
144
145





146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165





166
167
168
169
170
171
172
173
174
175
176
177







-
-
-
-
-
+
+
+
+
+












-
+


-
-
-
-
-
+
+
+
+
+







        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
    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')],
          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
        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).
223
224
225
226
227
228
229
230
231
232
233
234





235
236
237

238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254










255
256
257

258
259
260
261
262
263
264
265
266
222
223
224
225
226
227
228





229
230
231
232
233
234
235

236
237
238
239
240
241
242
243










244
245
246
247
248
249
250
251
252
253
254
255

256
257
258
259
260
261
262
263
264
265







-
-
-
-
-
+
+
+
+
+


-
+







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
+









    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
    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
    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
    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
    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)

Modified pkgIndex.tcl.in from [e32c88be89] to [ebbb8f66db].

1

2
3
4
5
6
7
8

9

10
11
12

1


2
3
4
5

6
7
8
9
10
11
-
+
-
-




-
+

+



# FILE: "/home/joze/src/tclreadline/pkgIndex.tcl.in"
# FILE: pkgIndex.tcl.in
# LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:33 +0100 (joze)"
# (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
# $Id$
# ---
# tclreadline -- gnu readline for tcl
# http://www.zellner.org/tclreadline/
# Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# This software is copyright under the BSD license.
# ---

package ifneeded tclreadline @VERSION@ \
    [list source [file join $dir tclreadlineInit.tcl]]

Modified sample.tclshrc from [25ec261415] to [d65998f0e1].

1
2

3
4
5






6


7
8
9
10
11
12
13
1

2


3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18

-
+
-
-

+
+
+
+
+
+
-
+
+







#!/bin/sh
# FILE: "/home/joze/src/tclreadline/sample.tclshrc"
# FILE: sample.tclshrc
# LAST MODIFICATION: "Thu, 23 Mar 2000 21:13:08 +0100 (joze)"
# (C) 1998 - 2000 by Johannes Zellner, <johannes@zellner.org>
# $Id$
# ---
# tclreadline -- gnu readline for tcl
# http://www.zellner.org/tclreadline/
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# This software is copyright under the BSD license.
# ---
# vim:set ft=tcl: \

# exec with tclsh \
exec tclsh "$0" "$@"


if {$tcl_interactive} {

    package require tclreadline

54
55
56
57
58
59
60

59
60
61
62
63
64
65
66







+
    # ::tclreadline::readline customcompleter ""

    # go to tclrealdine's main loop.
    #
    tclreadline::Loop
}

# vim:set ft=tcl:

Modified tclreadline.c from [fb738417f9] to [eb4c3e5998].

1
2
3

4
5
6
7
8
9
10

11
12

13
14
15

16
17
18
19
20
21
22
23
24
25


26
27
28


29
30
31
32
33

34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53


54
55
56
57
58
59
60

1

2


3
4
5
6

7
8

9
10
11

12
13
14
15
16
17
18
19
20


21
22
23


24
25
26
27
28
29

30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48


49
50
51
52
53
54
55
56
57
-

-
+
-
-




-
+

-
+


-
+








-
-
+
+

-
-
+
+




-
+






-
+











-
-
+
+








 /* ==================================================================
    FILE: "/home/joze/src/tclreadline/tclreadline.c"
    FILE: tclreadline.c
    LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:33 +0100 (joze)"
    (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
    $Id$
    ---
    tclreadline -- gnu readline for tcl
    http://www.zellner.org/tclreadline/
    Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
    Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
    This software is copyright under the BSD license.
    ================================================================== */  
    ================================================================== */

#ifdef HAVE_CONFIG_H
#   include "config.h"
#  include "config.h"
#endif

#include <tcl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if defined (READLINE_LIBRARY)
#   include <readline.h>
#   include <history.h>
#  include <readline.h>
#  include <history.h>
#else
#   include <readline/readline.h>
#   include <readline/history.h>
#  include <readline/readline.h>
#  include <readline/history.h>
#endif


/*
 * this prototype is missing
 * this prototype may be missing
 * in readline.h
 */
void rl_extend_line_buffer(int len);

#ifdef EXECUTING_MACRO_HACK
/**
 * this prototype is private in readline's file `macro.c'.
 * this prototype may be 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* EXECUTING_MACRO_NAME;
#endif

#include "tclreadline.h"
static const char* tclrl_library = TCLRL_LIBRARY;
static const char* tclrl_version_str = TCLRL_VERSION_STR;
static const char* tclrl_patchlevel_str = TCLRL_PATCHLEVEL_STR;

#define MALLOC(size) malloc((int) size)
#define FREE(ptr) if (ptr) { free((char*) ptr); ptr = 0; }
#define MALLOC(size) malloc(size)
#define FREE(ptr) free(ptr); ptr = NULL

enum {
    _CMD_SET     = (1 << 0),
    _CMD_GET     = (1 << 1)
};


82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93







-
+







static int blank_line(char* str);
static char** TclReadlineCompletion(char* text, int start, int end);
static char* TclReadline0generator(char* text, int state);
static char* TclReadlineKnownCommands(char* text, int state, int mode);
static int TclReadlineParse(char** args, int maxargs, char* buf);


enum { 
enum {
    LINE_PENDING = -1,
    LINE_EOF = (1 << 8),
    LINE_COMPLETE = (1 << 9)
};

/**
 * global variables
135
136
137
138
139
140
141
142

143
144

145
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
132
133
134
135
136
137
138

139
140

141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157







-
+

-
+








-
+









static char*
stripleft(char* in)
{
    char* ptr = in;
    while (*ptr && *ptr <= ' ')
	ptr++;
        ptr++;
    if (in != ptr)
	memmove(in, ptr, strlen(ptr) + 1);
        memmove(in, ptr, strlen(ptr) + 1);
    return in;
}

static char*
stripright(char* in)
{
    char* ptr;
    for (ptr = strchr(in, '\0') - 1; ptr >= in && *ptr <= ' '; ptr--)
	*ptr = '\0';
        *ptr = '\0';
    return in;
}

static char*
stripwhite(char* in)
{
    stripleft(in);
181
182
183
184
185
186
187
188
189
190
191
192
193
194







195
196
197
198
199

200
201


202
203
204
205
206
207
208
209




210
211
212
213
214



215
216
217
218
219
220
221


222
223
224
225

226
227
228
229



230
231
232
233

234
235
236
237



238
239
240


241
242
243
244
245
246
247
248
249








250
251

252
253
254
255
256
257
258
259
260
261









262
263
264


265
266

267
268

269
270

271
272
273
274



275
276
277
278
279
280
281
282







283
284
285
286
287
288
289






290
291
292
293
294
295
296
297
298
299









300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315















316
317
318
319
320
321
322
323
324
325
326
327











328
329
330
331
332
333
334
335
336
337
338










339
340
341
342
343
344
345
346
347
348
349
350
351
352













353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373




















374
375
376
377
378
379
380
381
382
383
384
385
386
387













388
389
390
391
392
393
394
395
396
397
398
399
400
401
402














403
404
405


406
407
408


409
410
411
412
413
414





415
416
417
418
419
420




421
422
423


424
425
426
427
428
429




430
431

432
433
434
435



436
437

438
439
440
441
442
443
444




445
446
447
448
449




450
451
452
453
454




455
456
457
458
459
460
461
462


463
464
465
466
467
468
469
470
471
472

473
474

475
476
477
478
479
480
481






482
483
484
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499
500
501







502
503
504


505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
















522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551





























552
553
554
555
556
557
558
559
560
561
562
563
564
565
566

567
568
569
570


571
572
573
574


575
576
577


578
579
580


581
582
583


584
585
586
587


588
589
590


591
592
593


594
595
596
597
598
599
600
601
602
603
604
605
606
607

608
609
610
611
612
613
614
178
179
180
181
182
183
184







185
186
187
188
189
190
191
192
193
194
195
196
197


198
199
200
201
202
203




204
205
206
207
208
209



210
211
212
213
214
215
216
217


218
219
220
221
222

223
224



225
226
227

228
229

230
231



232
233
234
235


236
237
238








239
240
241
242
243
244
245
246
247

248
249









250
251
252
253
254
255
256
257
258
259


260
261
262

263
264

265
266

267




268
269
270
271







272
273
274
275
276
277
278
279






280
281
282
283
284
285
286









287
288
289
290
291
292
293
294
295
296















297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312











313
314
315
316
317
318
319
320
321
322
323
324










325
326
327
328
329
330
331
332
333
334
335













336
337
338
339
340
341
342
343
344
345
346
347
348
349




















350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370













371
372
373
374
375
376
377
378
379
380
381
382
383
384














385
386
387
388
389
390
391
392
393
394
395
396
397
398
399


400
401
402


403
404
405





406
407
408
409
410
411
412




413
414
415
416
417


418
419
420
421




422
423
424
425
426

427
428



429
430
431
432

433
434
435
436




437
438
439
440
441




442
443
444
445
446




447
448
449
450
451
452
453
454
455
456


457
458
459
460
461
462
463
464
465
466
467

468
469

470
471






472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490







491
492
493
494
495
496
497
498


499
500
501
















502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518





























519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561

562
563
564


565
566
567
568


569
570
571


572
573
574


575
576
577


578
579
580
581


582
583
584


585
586
587


588
589
590
591
592
593
594
595
596
597
598
599
600
601
602

603
604
605
606
607
608
609
610







-
-
-
-
-
-
-
+
+
+
+
+
+
+





+
-
-
+
+




-
-
-
-
+
+
+
+


-
-
-
+
+
+





-
-
+
+



-
+

-
-
-
+
+
+
-


-
+

-
-
-
+
+
+

-
-
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+

-
+

-
+
-
-
-
-
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+


-
-
-
-
+
+
+
+

-
-
+
+


-
-
-
-
+
+
+
+

-
+

-
-
-
+
+
+

-
+



-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+






-
-
+
+









-
+

-
+

-
-
-
-
-
-
+
+
+
+
+
+









-
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+














-
+


-
-
+
+


-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+


-
-
+
+

-
-
+
+

-
-
+
+













-
+







    char* ptr;
    char* result_c;
    int i, len = strlen(quotechars);
    Tcl_DString result;

    Tcl_DStringInit(&result);
    for (ptr = text; ptr && *ptr; ptr++) {
	for (i = 0; i < len; i++) {
	    if (quotechars[i] == *ptr) {
		Tcl_DStringAppend(&result, "\\", 1);
		break;
	    }
	}
	Tcl_DStringAppend(&result, ptr, 1);
        for (i = 0; i < len; i++) {
            if (quotechars[i] == *ptr) {
                Tcl_DStringAppend(&result, "\\", 1);
                break;
            }
        }
        Tcl_DStringAppend(&result, ptr, 1);
    }
    result_c = strdup(Tcl_DStringValue(&result));
    return result_c;
}

static int
static int TclReadlineCmd(ClientData clientData, Tcl_Interp *interp, int objc,
			  Tcl_Obj *CONST objv[])
TclReadlineCmd(ClientData clientData, Tcl_Interp *interp, int objc,
               Tcl_Obj *CONST objv[])
{
    int obj_idx, status;

    static char *subCmds[] = {
	"read", "initialize", "write", "add", "complete",
	"customcompleter", "builtincompleter", "eofchar",
	"reset-terminal", "bell", "text", "update",
	(char *) NULL
        "read", "initialize", "write", "add", "complete",
        "customcompleter", "builtincompleter", "eofchar",
        "reset-terminal", "bell", "text", "update",
        (char *) NULL
    };
    enum SubCmdIdx {
	TCLRL_READ, TCLRL_INITIALIZE, TCLRL_WRITE, TCLRL_ADD, TCLRL_COMPLETE,
	TCLRL_CUSTOMCOMPLETER, TCLRL_BUILTINCOMPLETER, TCLRL_EOFCHAR,
	TCLRL_RESET_TERMINAL, TCLRL_BELL, TCLRL_TEXT, TCLRL_UPDATE
        TCLRL_READ, TCLRL_INITIALIZE, TCLRL_WRITE, TCLRL_ADD, TCLRL_COMPLETE,
        TCLRL_CUSTOMCOMPLETER, TCLRL_BUILTINCOMPLETER, TCLRL_EOFCHAR,
        TCLRL_RESET_TERMINAL, TCLRL_BELL, TCLRL_TEXT, TCLRL_UPDATE
    };

    Tcl_ResetResult(interp); /* clear the result space */

    if (objc < 2) {
	Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
	return TCL_ERROR;
        Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?");
        return TCL_ERROR;
    }

    status = Tcl_GetIndexFromObj
    (interp, objv[1], subCmds, "option", 0, (int *) &obj_idx);
        (interp, objv[1], subCmds, "option", 0, (int *) &obj_idx);

    if (status != TCL_OK) {
	return status;
    }
    if (status != TCL_OK)
        return status;


    switch (obj_idx) {

	case TCLRL_READ:
        case TCLRL_READ:

	    rl_callback_handler_install(
			       objc == 3 ? Tcl_GetStringFromObj(objv[2], 0)
			       : "% ", TclReadlineLineCompleteHandler);
            rl_callback_handler_install(
                       objc == 3 ? Tcl_GetStringFromObj(objv[2], 0)
                       : "% ", TclReadlineLineCompleteHandler);

	    Tcl_CreateFileHandler(0, TCL_READABLE,
		TclReadlineReadHandler, (ClientData) NULL);
            Tcl_CreateFileHandler(0, TCL_READABLE,
                TclReadlineReadHandler, (ClientData) NULL);

	    /**
	     * Main Loop.
	     * XXX each modification of the global variables
	     *     which terminates the main loop must call
	     *     rl_callback_handler_remove() to leave
	     *     readline in a defined state.          XXX
	     */
	    tclrl_state = LINE_PENDING;
            /**
             * Main Loop.
             * XXX each modification of the global variables
             *     which terminates the main loop must call
             *     rl_callback_handler_remove() to leave
             *     readline in a defined state.          XXX
             */
            tclrl_state = LINE_PENDING;

	    while (!TclReadlineLineComplete()) {
            while (!TclReadlineLineComplete()) {
#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 (EXECUTING_MACRO_NAME)
		    TclReadlineReadHandler((ClientData) NULL, TCL_READABLE);
		else
                /**
                 * check first, if more characters are
                 * available from _rl_executing_macro,
                 * because Tcl_DoOneEvent() will (naturally)
                 * not detect this `event'.
                 */
                if (EXECUTING_MACRO_NAME)
                    TclReadlineReadHandler((ClientData) NULL, TCL_READABLE);
                else
#endif
		    Tcl_DoOneEvent(TCL_ALL_EVENTS);
	    }
                    Tcl_DoOneEvent(TCL_ALL_EVENTS);
            }

	    Tcl_DeleteFileHandler(0);
            Tcl_DeleteFileHandler(0);

	    switch (tclrl_state) {
            switch (tclrl_state) {

		case LINE_COMPLETE:
                case LINE_COMPLETE:

		    return TCL_OK;
		    /* NOTREACHED */
		    break;
                    return TCL_OK;
                    /* NOTREACHED */
                    break;

		case LINE_EOF:
		    if (tclrl_eof_string)
			return Tcl_Eval(interp, tclrl_eof_string);
		    else
			return TCL_OK;
		    /* NOTREACHED */
		    break;
                case LINE_EOF:
                    if (tclrl_eof_string)
                    return Tcl_Eval(interp, tclrl_eof_string);
                    else
                    return TCL_OK;
                    /* NOTREACHED */
                    break;

		default:
		    return tclrl_state;
		    /* NOTREACHED */
		    break;
	    }
	    break;
                default:
                    return tclrl_state;
                    /* NOTREACHED */
                    break;
            }
            break;

	case TCLRL_INITIALIZE:
	    if (3 != objc) {
		Tcl_WrongNumArgs(interp, 2, objv, "historyfile");
		return TCL_ERROR;
	    } else {
		return TclReadlineInitialize(interp,
					     Tcl_GetStringFromObj(objv[2], 0));
	    }
	    break;
        case TCLRL_INITIALIZE:
            if (3 != objc) {
                Tcl_WrongNumArgs(interp, 2, objv, "historyfile");
                return TCL_ERROR;
            } else {
                return TclReadlineInitialize(interp,
                                 Tcl_GetStringFromObj(objv[2], 0));
            }
            break;

	case TCLRL_WRITE:
	    if (3 != objc) {
		Tcl_WrongNumArgs(interp, 2, objv, "historyfile");
		return TCL_ERROR;
	    }  else if (write_history(Tcl_GetStringFromObj(objv[2], 0))) {
		Tcl_AppendResult(interp, "unable to write history to `",
		    Tcl_GetStringFromObj(objv[2], 0), "'\n", (char*) NULL);
		return TCL_ERROR;
	    }
	    if (tclrl_history_length >= 0) {
		history_truncate_file(Tcl_GetStringFromObj(objv[2], 0),
				      tclrl_history_length);
	    }
	    return TCL_OK;
	    break;
        case TCLRL_WRITE:
            if (3 != objc) {
                Tcl_WrongNumArgs(interp, 2, objv, "historyfile");
                return TCL_ERROR;
            }  else if (write_history(Tcl_GetStringFromObj(objv[2], 0))) {
                Tcl_AppendResult(interp, "unable to write history to `",
                    Tcl_GetStringFromObj(objv[2], 0), "'\n", (char*) NULL);
                return TCL_ERROR;
            }
            if (tclrl_history_length >= 0) {
                history_truncate_file(Tcl_GetStringFromObj(objv[2], 0),
                              tclrl_history_length);
            }
            return TCL_OK;
            break;

	case TCLRL_ADD:
	    if (3 != objc) {
		Tcl_WrongNumArgs(interp, 2, objv, "completerLine");
		return TCL_ERROR;
	    } else if (TclReadlineKnownCommands(
				     Tcl_GetStringFromObj(objv[2], 0),
				     (int) 0, _CMD_SET)) {
		Tcl_AppendResult(interp, "unable to add command \"",
		    Tcl_GetStringFromObj(objv[2], 0), "\"\n", (char*) NULL);
	    }
	    break;
        case TCLRL_ADD:
            if (3 != objc) {
                Tcl_WrongNumArgs(interp, 2, objv, "completerLine");
                return TCL_ERROR;
            } else if (TclReadlineKnownCommands(
                         Tcl_GetStringFromObj(objv[2], 0),
                         (int) 0, _CMD_SET)) {
                Tcl_AppendResult(interp, "unable to add command \"",
                    Tcl_GetStringFromObj(objv[2], 0), "\"\n", (char*) NULL);
            }
            break;

	case TCLRL_COMPLETE:
	    if (3 != objc) {
		Tcl_WrongNumArgs(interp, 2, objv, "line");
		return TCL_ERROR;
	    } else if (Tcl_CommandComplete(Tcl_GetStringFromObj(objv[2], 0))) {
		Tcl_AppendResult(interp, "1", (char*) NULL);
	    } else {
		Tcl_AppendResult(interp, "0", (char*) NULL);
	    }
	    break;
        case TCLRL_COMPLETE:
            if (3 != objc) {
                Tcl_WrongNumArgs(interp, 2, objv, "line");
                return TCL_ERROR;
            } else if (Tcl_CommandComplete(Tcl_GetStringFromObj(objv[2], 0))) {
                Tcl_AppendResult(interp, "1", (char*) NULL);
            } else {
                Tcl_AppendResult(interp, "0", (char*) NULL);
            }
            break;

	case TCLRL_CUSTOMCOMPLETER:
	    if (objc > 3) {
		Tcl_WrongNumArgs(interp, 2, objv, "?scriptCompleter?");
		return TCL_ERROR;
	    } else if (3 == objc) {
		if (tclrl_custom_completer)
		    FREE(tclrl_custom_completer);
		if (!blank_line(Tcl_GetStringFromObj(objv[2], 0)))
		    tclrl_custom_completer =
		         stripwhite(strdup(Tcl_GetStringFromObj(objv[2], 0)));
	    }
	    Tcl_AppendResult(interp, tclrl_custom_completer, (char*) NULL);
	    break;
        case TCLRL_CUSTOMCOMPLETER:
            if (objc > 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "?scriptCompleter?");
                return TCL_ERROR;
            } else if (3 == objc) {
                if (tclrl_custom_completer)
                    FREE(tclrl_custom_completer);
                if (!blank_line(Tcl_GetStringFromObj(objv[2], 0)))
                    tclrl_custom_completer =
                         stripwhite(strdup(Tcl_GetStringFromObj(objv[2], 0)));
            }
            Tcl_AppendResult(interp, tclrl_custom_completer, (char*) NULL);
            break;

	case TCLRL_BUILTINCOMPLETER:
	    if (objc > 3) {
		Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
		return TCL_ERROR;
	    } else if (3 == objc) {
		int bool = tclrl_use_builtin_completer;
		if (TCL_OK != Tcl_GetBoolean(interp,
					     Tcl_GetStringFromObj(objv[2], 0),
					     &bool)) {
		    Tcl_AppendResult(interp,
			"wrong # args: should be a boolean value.",
			(char*) NULL);
		    return TCL_ERROR;
		} else {
		    tclrl_use_builtin_completer = bool;
		}
	    }
	    Tcl_AppendResult(interp, tclrl_use_builtin_completer ? "1" : "0",
		(char*) NULL);
	    break;
        case TCLRL_BUILTINCOMPLETER:
            if (objc > 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "?boolean?");
                return TCL_ERROR;
            } else if (3 == objc) {
                int bool = tclrl_use_builtin_completer;
                if (TCL_OK != Tcl_GetBoolean(interp,
                                 Tcl_GetStringFromObj(objv[2], 0),
                                 &bool)) {
                    Tcl_AppendResult(interp,
                        "wrong # args: should be a boolean value.",
                        (char*) NULL);
                    return TCL_ERROR;
                } else {
                    tclrl_use_builtin_completer = bool;
                }
            }
            Tcl_AppendResult(interp, tclrl_use_builtin_completer ? "1" : "0",
                (char*) NULL);
            break;

	case TCLRL_EOFCHAR:
	    if (objc > 3) {
		Tcl_WrongNumArgs(interp, 2, objv, "?script?");
		return TCL_ERROR;
	    } else if (3 == objc) {
		if (tclrl_eof_string)
		    FREE(tclrl_eof_string);
		if (!blank_line(Tcl_GetStringFromObj(objv[2], 0)))
		    tclrl_eof_string = 
		        stripwhite(strdup(Tcl_GetStringFromObj(objv[2], 0)));
	    }
	    Tcl_AppendResult(interp, tclrl_eof_string, (char*) NULL);
	    break;
        case TCLRL_EOFCHAR:
            if (objc > 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "?script?");
                return TCL_ERROR;
            } else if (3 == objc) {
                if (tclrl_eof_string)
                    FREE(tclrl_eof_string);
                if (!blank_line(Tcl_GetStringFromObj(objv[2], 0)))
                    tclrl_eof_string =
                        stripwhite(strdup(Tcl_GetStringFromObj(objv[2], 0)));
            }
            Tcl_AppendResult(interp, tclrl_eof_string, (char*) NULL);
            break;

	case TCLRL_RESET_TERMINAL:
	    /* TODO: add this to the completer */
	    if (objc > 3) {
		Tcl_WrongNumArgs(interp, 2, objv, "?terminal-name?");
		return TCL_ERROR;
	    }
	    if (3 == objc) {
		/*
		 * - tcl8.0 doesn't have Tcl_GetStringFromObj()
		 * - rl_reset_terminal() might be defined
		 *   to take no arguments. This might produce
		 *   a compiler warning.
		 */
		rl_reset_terminal(Tcl_GetStringFromObj(objv[2], 0));
        case TCLRL_RESET_TERMINAL:
            /* TODO: add this to the completer */
            if (objc > 3) {
                Tcl_WrongNumArgs(interp, 2, objv, "?terminal-name?");
                return TCL_ERROR;
            }
            if (3 == objc) {
                /*
                 * - tcl8.0 doesn't have Tcl_GetStringFromObj()
                 * - rl_reset_terminal() might be defined
                 *   to take no arguments. This might produce
                 *   a compiler warning.
                 */
                rl_reset_terminal(Tcl_GetStringFromObj(objv[2], 0));
#ifdef CLEANUP_AFER_SIGNAL
	    } else {
		rl_cleanup_after_signal();
            } else {
                rl_cleanup_after_signal();
#endif
	    }
	    break;
            }
            break;

	case TCLRL_BELL:
	    if (objc != 2) {
		Tcl_WrongNumArgs(interp, 2, objv, "");
		return TCL_ERROR;
	    }
        case TCLRL_BELL:
            if (objc != 2) {
                Tcl_WrongNumArgs(interp, 2, objv, "");
                return TCL_ERROR;
            }


	    /*
	     * ring the terminal bell obeying the current
	     * settings -- audible or visible.
	     */
            /*
             * ring the terminal bell obeying the current
             * settings -- audible or visible.
             */

	    ding();
	    break;
            ding();
            break;

        case TCLRL_UPDATE:
	    if (objc != 2) {
		Tcl_WrongNumArgs(interp, 2, objv, "");
		return TCL_ERROR;
	    }
            if (objc != 2) {
                Tcl_WrongNumArgs(interp, 2, objv, "");
                return TCL_ERROR;
            }

	    /* Update the input line */
            /* Update the input line */

	    if (rl_line_buffer) {
	        rl_forced_update_display();
	    }
            if (rl_line_buffer) {
                rl_forced_update_display();
            }

	    break;
            break;


        case TCLRL_TEXT:
	    if (objc != 2) {
		Tcl_WrongNumArgs(interp, 2, objv, "");
		return TCL_ERROR;
	    }
            if (objc != 2) {
                Tcl_WrongNumArgs(interp, 2, objv, "");
                return TCL_ERROR;
            }

	    /* Return the current input line */
	    Tcl_SetObjResult(interp,
		   Tcl_NewStringObj(rl_line_buffer ? rl_line_buffer : "", -1));
	    break;
            /* Return the current input line */
            Tcl_SetObjResult(interp,
               Tcl_NewStringObj(rl_line_buffer ? rl_line_buffer : "", -1));
            break;

	default:
	    goto BAD_COMMAND;
	    /* NOTREACHED */
	    break;
        default:
            goto BAD_COMMAND;
            /* NOTREACHED */
            break;
    }

    return TCL_OK;

BAD_COMMAND:
    Tcl_AppendResult(interp,
	"wrong # args: should be \"readline option ?arg ...?\"",
	(char*) NULL);
        "wrong # args: should be \"readline option ?arg ...?\"",
        (char*) NULL);
    return TCL_ERROR;

}

static void
TclReadlineReadHandler(ClientData clientData, int mask)
{
    if (mask & TCL_READABLE) {
#ifdef EXECUTING_MACRO_NAME
	do {
        do {
#endif
	    rl_callback_read_char();
            rl_callback_read_char();
#ifdef EXECUTING_MACRO_NAME
	    /**
	     * check, if we're inside a macro and
	     * if so, read all macro characters
	     * until the next eol.
	     */
	} while (EXECUTING_MACRO_NAME && !TclReadlineLineComplete());
        /**
         * check, if we're inside a macro and
         * if so, read all macro characters
         * until the next eol.
         */
        } while (EXECUTING_MACRO_NAME && !TclReadlineLineComplete());
#endif
    }
}

static void
TclReadlineLineCompleteHandler(char* ptr)
{
    if (!ptr) { /* <c-d> */

	TclReadlineTerminate(LINE_EOF);
        TclReadlineTerminate(LINE_EOF);

    } else {

	/**
	 * From version 0.9.3 upwards, all lines are
	 * returned, even empty lines. (Only non-empty
	 * lines are stuffed in readline's history.)
	 * The calling script is responsible for handling
	 * empty strings.
	 */
        /**
         * From version 0.9.3 upwards, all lines are
         * returned, even empty lines. (Only non-empty
         * lines are stuffed in readline's history.)
         * The calling script is responsible for handling
         * empty strings.
         */

	char* expansion = (char*) NULL;
	int status = history_expand(ptr, &expansion);
        char* expansion = (char*) NULL;
        int status = history_expand(ptr, &expansion);

	if (status >= 2) {
	    /* TODO: make this a valid tcl output */
	    printf("%s\n", expansion);
		free(ptr);
		free(expansion);
		return;
	} else if (status <= -1) {
	    Tcl_AppendResult
	    (tclrl_interp, "error in history expansion: ", expansion, "\n", (char*) NULL);
	    TclReadlineTerminate(TCL_ERROR);
		free(ptr);
		free(expansion);
		return;
	} else {
        Tcl_AppendResult(tclrl_interp, expansion, (char*) NULL);
    }
        if (status >= 2) {
            /* TODO: make this a valid tcl output */
            printf("%s\n", expansion);
            FREE(ptr);
            FREE(expansion);
            return;
        } else if (status <= -1) {
            Tcl_AppendResult
                (tclrl_interp, "error in history expansion: ", expansion, "\n", (char*) NULL);
                TclReadlineTerminate(TCL_ERROR);
            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(!EXECUTING_MACRO_NAME) {
#endif
	    /**
	     * don't stuff empty lines
	     * into readline's history.
	     * don't stuff twice the same
	     * line into readline's history.
	     */
	    if (expansion && *expansion && (!tclrl_last_line ||
		    strcmp(tclrl_last_line, expansion))) {
		add_history(expansion);
	    }
	    if (tclrl_last_line)
		free(tclrl_last_line);
	    tclrl_last_line = strdup(expansion);
#ifdef EXECUTING_MACRO_NAME
	}
#endif
	/**
	 * tell the calling routines to terminate.
	 */
	TclReadlineTerminate(LINE_COMPLETE);
	FREE(ptr);
	FREE(expansion);
    #ifdef EXECUTING_MACRO_NAME
        /**
         * don't stuff macro lines
         * into readline's history.
         */
        if(!EXECUTING_MACRO_NAME) {
    #endif
            /**
             * don't stuff empty lines
             * into readline's history.
             * don't stuff twice the same
             * line into readline's history.
             */
            if (expansion && *expansion && (!tclrl_last_line ||
                    strcmp(tclrl_last_line, expansion))) {
                add_history(expansion);
            }
            if (tclrl_last_line)
                FREE(tclrl_last_line);
            tclrl_last_line = strdup(expansion);
    #ifdef EXECUTING_MACRO_NAME
        }
    #endif
        /**
         * tell the calling routines to terminate.
         */
        TclReadlineTerminate(LINE_COMPLETE);
        FREE(ptr);
        FREE(expansion);
    }
}

int
Tclreadline_SafeInit(Tcl_Interp *interp)
{
    return Tclreadline_Init(interp);
}

int
Tclreadline_Init(Tcl_Interp *interp)
{
    int status;
    Tcl_CreateObjCommand(interp, "::tclreadline::readline", TclReadlineCmd,
	(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
        (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
    tclrl_interp = interp;
    if (TCL_OK != (status = Tcl_LinkVar(interp, "::tclreadline::historyLength",
		(char*) &tclrl_history_length, TCL_LINK_INT)))
	return status;
            (char*) &tclrl_history_length, TCL_LINK_INT)))
        return status;

    if (TCL_OK != (status = Tcl_LinkVar(interp, "::tclreadline::library",
		(char*) &tclrl_library, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
	return status;
            (char*) &tclrl_library, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
        return status;
    if (TCL_OK != (status = Tcl_LinkVar(interp, "::tclreadline::version",
		(char*) &tclrl_version_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
	return status;
            (char*) &tclrl_version_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
        return status;
    if (TCL_OK != (status = Tcl_LinkVar(interp, "::tclreadline::patchLevel",
		(char*) &tclrl_patchlevel_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
	return status;
            (char*) &tclrl_patchlevel_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
        return status;
    if (TCL_OK != (status = Tcl_LinkVar(interp, "::tclreadline::license",
		(char*) &tclrl_license, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
	return status;
            (char*) &tclrl_license, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
        return status;

    if (TCL_OK != (status = Tcl_LinkVar(interp, "tclreadline_library",
		(char*) &tclrl_library, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
	return status;
            (char*) &tclrl_library, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
        return status;
    if (TCL_OK != (status = Tcl_LinkVar(interp, "tclreadline_version",
		(char*) &tclrl_version_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
	return status;
            (char*) &tclrl_version_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
        return status;
    if (TCL_OK != (status = Tcl_LinkVar(interp, "tclreadline_patchLevel",
		(char*) &tclrl_patchlevel_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
	return status;
            (char*) &tclrl_patchlevel_str, TCL_LINK_STRING | TCL_LINK_READ_ONLY)))
        return status;

    return Tcl_PkgProvide(interp, "tclreadline", (char*)tclrl_version_str);
}

static int
TclReadlineInitialize(Tcl_Interp* interp, char* historyfile)
{
    rl_readline_name = "tclreadline";
    /*    rl_special_prefixes = "${\"["; */
    rl_special_prefixes = "$";
    /**
     * default is " \t\n\"\\'`@$><=;|&{("
     * removed "(" <-- arrays
     * removed "{" <-- `${' variables 
     * removed "{" <-- `${' variables
     * removed "<" <-- completion lists with < ... >
     * added "[]"
     * added "}"
     */
    /* 11.Sep rl_basic_word_break_characters = " \t\n\"\\@$}=;|&[]"; */
    /* besser (11. Sept) 2. (removed \") */
    /* rl_basic_word_break_characters = " \t\n\\@$}=;|&[]"; */
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
642
643
644
645
646




647
648
649
650
651
652
653
654
655
656
657


658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688



















689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714























715
716

717
718
719
720
721




722
723
724
725
726
727
728
729
730
731
732
733
734












735
736
737
738
739
740
741
742
743
744
745
746
747












748
749
750
751



752
753
754
755

756
757
758
759
760
761
762
623
624
625
626
627
628
629

630
631
632
633
634
635
636
637
638




639
640
641
642
643
644
645
646
647
648
649
650
651


652
653
654
655
656
657
658
659
660
661
662
663
664
665



















666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687























688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710


711





712
713
714
715
716












717
718
719
720
721
722
723
724
725
726
727
728
729












730
731
732
733
734
735
736
737
738
739
740
741
742



743
744
745
746
747
748

749
750
751
752
753
754
755
756







-
+








-
-
-
-
+
+
+
+









-
-
+
+












-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+



-
+







     */
    /*
       rl_filename_quoting_desired = 1;
     */

    using_history();
    if (!tclrl_eof_string)
	tclrl_eof_string = strdup("puts {}; exit");
        tclrl_eof_string = strdup("puts {}; exit");

    /*
     * try to read historyfile in home
     * directory. If this failes, this
     * is *not* an error.
     */
    rl_attempted_completion_function = (CPPFunction *) TclReadlineCompletion;
    if (read_history(historyfile)) {
	if (write_history(historyfile)) {
	    Tcl_AppendResult (interp, "warning: `",
		historyfile, "' is not writable.", (char*) NULL);
	}
        if (write_history(historyfile)) {
            Tcl_AppendResult (interp, "warning: `",
                historyfile, "' is not writable.", (char*) NULL);
        }
    }
    return TCL_OK;
}

static int
blank_line(char* str)
{
    char* ptr;
    for (ptr = str; ptr && *ptr; ptr++) {
	if (!ISWHITE(*ptr))
	    return 0;
        if (!ISWHITE(*ptr))
            return 0;
    }
    return 1;
}

static char**
TclReadlineCompletion(char* text, int start, int end)
{
    char** matches = (char**) NULL;
    int status;
    rl_completion_append_character = ' '; /* reset, just in case ... */

    if (text && ('!' == text[0]
	    || (start && rl_line_buffer[start - 1] == '!' /* for '$' */))) {
	char* expansion = (char*) NULL;
	int oldlen = strlen(rl_line_buffer);
	status = history_expand(rl_line_buffer, &expansion);
	if (status >= 1) {
	    rl_extend_line_buffer(strlen(expansion) + 1);
	    strcpy(rl_line_buffer, expansion);
	    rl_end = strlen(expansion);
	    rl_point += strlen(expansion) - oldlen;
	    FREE(expansion);
	    /*
	     * TODO:
	     * because we return 0 == matches,
	     * the filename completer will still beep.
	     rl_inhibit_completion = 1;
	     */
	    return matches;
	}
	FREE(expansion);
            || (start && rl_line_buffer[start - 1] == '!' /* for '$' */))) {
        char* expansion = (char*) NULL;
        int oldlen = strlen(rl_line_buffer);
        status = history_expand(rl_line_buffer, &expansion);
        if (status >= 1) {
            rl_extend_line_buffer(strlen(expansion) + 1);
            strcpy(rl_line_buffer, expansion);
            rl_end = strlen(expansion);
            rl_point += strlen(expansion) - oldlen;
            FREE(expansion);
            /*
             * TODO:
             * because we return 0 == matches,
             * the filename completer will still beep.
             rl_inhibit_completion = 1;
             */
            return matches;
        }
        FREE(expansion);
    }

    if (tclrl_custom_completer) {
	char start_s[BUFSIZ], end_s[BUFSIZ];
	Tcl_Obj* obj;
	Tcl_Obj** objv;
	int objc;
	int state;
	char* quoted_text = TclReadlineQuote(text, "$[]{}\"");
	char* quoted_rl_line_buffer = TclReadlineQuote(rl_line_buffer, "$[]{}\"");
	sprintf(start_s, "%d", start);
	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);
	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);
        char start_s[BUFSIZ], end_s[BUFSIZ];
        Tcl_Obj* obj;
        Tcl_Obj** objv;
        int objc;
        int state;
        char* quoted_text = TclReadlineQuote(text, "$[]{}\"");
        char* quoted_rl_line_buffer = TclReadlineQuote(rl_line_buffer, "$[]{}\"");
        sprintf(start_s, "%d", start);
        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);
        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);
        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;
        obj = Tcl_GetObjResult(tclrl_interp);
        status = Tcl_ListObjGetElements(tclrl_interp, obj, &objc, &objv);
        if (TCL_OK != status)
            return matches;

	if (objc) {
	    int i, length;
	    matches = (char**) MALLOC(sizeof(char*) * (objc + 1));
	    for (i = 0; i < objc; i++) {
		matches[i] = strdup(Tcl_GetStringFromObj(objv[i], &length));
		if (1 == objc && !strlen(matches[i])) {
		    FREE(matches[i]);
		    FREE(matches);
		    Tcl_ResetResult(tclrl_interp); /* clear result space */
		    return (char**) NULL;
		}
	    }
        if (objc) {
            int i, length;
            matches = (char**) MALLOC(sizeof(char*) * (objc + 1));
            for (i = 0; i < objc; i++) {
                matches[i] = strdup(Tcl_GetStringFromObj(objv[i], &length));
                if (1 == objc && !strlen(matches[i])) {
                    FREE(matches[i]);
                    FREE(matches);
                    Tcl_ResetResult(tclrl_interp); /* clear result space */
                    return (char**) NULL;
                }
            }

	    /**
	     * this is a special one:
	     * if the script returns exactly two arguments
	     * and the second argument is the empty string,
	     * the rl_completion_append_character is set
	     * temporaryly to NULL.
	     */
	    if (2 == objc && !strlen(matches[1])) {
		i--;
		FREE(matches[1]);
		rl_completion_append_character = '\0';
	    }
            /**
             * this is a special one:
             * if the script returns exactly two arguments
             * and the second argument is the empty string,
             * the rl_completion_append_character is set
             * temporarily to NULL.
             */
            if (2 == objc && !strlen(matches[1])) {
                i--;
                FREE(matches[1]);
                rl_completion_append_character = '\0';
            }

	    matches[i] = (char*) NULL; /* terminate */
	}
	Tcl_ResetResult(tclrl_interp); /* clear result space */
            matches[i] = (char*) NULL; /* terminate */
        }
        Tcl_ResetResult(tclrl_interp); /* clear result space */
    }

    if (!matches && tclrl_use_builtin_completer) {
	matches = rl_completion_matches(text, (rl_compentry_func_t *)TclReadline0generator);
        matches = rl_completion_matches(text, (rl_compentry_func_t *)TclReadline0generator);
    }

    return matches;
}

static char*
TclReadline0generator(char* text, int state)
776
777
778
779
780
781
782
783

784
785
786


787
788
789
790



791
792
793
794
795




796
797
798


799
800

801
802
803


804
805

806
807
808



809
810
811

812
813
814


815
816
817
818
819
820
821
822
823
824
825
826
827












828
829

830
831
832


833
834
835
836
837
838





839
840
841


842
843

844
845
846
847
848




849
850
851
852
853
854
855
856








857
858
859
860
861




862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879







880
881
882


883
884
885


886
887
888


889
890
891
892
893

770
771
772
773
774
775
776

777
778


779
780
781



782
783
784





785
786
787
788
789


790
791
792

793
794


795
796
797

798
799


800
801
802
803
804

805
806


807
808
809












810
811
812
813
814
815
816
817
818
819
820
821
822

823
824


825
826
827





828
829
830
831
832
833


834
835
836

837
838




839
840
841
842
843







844
845
846
847
848
849
850
851
852




853
854
855
856
857
858

859
860
861
862
863
864
865
866







867
868
869
870
871
872
873
874


875
876
877


878
879
880


881
882
883
884
885
886
887
888







-
+

-
-
+
+

-
-
-
+
+
+
-
-
-
-
-
+
+
+
+

-
-
+
+

-
+

-
-
+
+

-
+

-
-
+
+
+


-
+

-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+


-








-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
+
+

-
-
+
+

-
-
+
+





+

    char* local_line = (char*) NULL;
    int sub;


    switch (mode) {

	case _CMD_SET:
        case _CMD_SET:

	    new = (cmds_t *) MALLOC(sizeof(cmds_t));
	    new->next = (cmds_t *) NULL;
            new = (cmds_t *) MALLOC(sizeof(cmds_t));
            new->next = (cmds_t *) NULL;

	    if (!cmds) {
		cmds = new;
		cmds->prev = new;
            if (!cmds) {
                cmds = new;
                cmds->prev = new;
	    }
	    else {
		cmds->prev->next = new;
		cmds->prev = new;
	    }
            } else {
                cmds->prev->next = new;
                cmds->prev = new;
            }

	    tmp = strdup(text);
	    argc = TclReadlineParse(args, sizeof(args), tmp);
            tmp = strdup(text);
            argc = TclReadlineParse(args, sizeof(args), tmp);

	    new->cmd = (char**) MALLOC(sizeof(char*) * (argc + 1));
            new->cmd = (char**) MALLOC(sizeof(char*) * (argc + 1));

	    for (i = 0; i < argc; i++)
		new->cmd[i] = args[i];
            for (i = 0; i < argc; i++)
                new->cmd[i] = args[i];

	    new->cmd[argc] = (char*) NULL;
            new->cmd[argc] = (char*) NULL;

	    return (char*) NULL;
	    break;
            return (char*) NULL;
            /* NOTREACHED */
            break;


	case _CMD_GET:
        case _CMD_GET:

	    local_line = strdup(rl_line_buffer);
	    sub = TclReadlineParse(args, sizeof(args), local_line);
            local_line = strdup(rl_line_buffer);
            sub = TclReadlineParse(args, sizeof(args), local_line);

	    if (0 == sub || (1 == sub && '\0' != text[0])) {
		if (!state) {
		    new = cmds;
		    len = strlen(text);
		}
		while (new && (name = new->cmd)) {
		    new = new->next;
		    if (!strncmp(name[0], text, len))
			return strdup(name[0]);
		}
		return (char*) NULL;
	    } else {
            if (0 == sub || (1 == sub && '\0' != text[0])) {
                if (!state) {
                    new = cmds;
                    len = strlen(text);
                }
                while (new && (name = new->cmd)) {
                    new = new->next;
                    if (!strncmp(name[0], text, len))
                        return strdup(name[0]);
                }
                return (char*) NULL;
            } else {

		if (!state) {
                if (!state) {

		    new = cmds;
		    len = strlen(text);
                    new = cmds;
                    len = strlen(text);

		    while (new && (name = new->cmd)) {
			if (!strcmp(name[0], args[0]))
			    break;
			new = new->next;
		    }
                    while (new && (name = new->cmd)) {
                        if (!strcmp(name[0], args[0]))
                            break;
                        new = new->next;
                    }

		    if (!new)
			return (char*) NULL;
                    if (!new)
                        return (char*) NULL;

		    for (i = 0; new->cmd[i]; i++) /* EMPTY */;
                    for (i = 0; new->cmd[i]; i++) /* EMPTY */;

		    if (sub < i && !strncmp(new->cmd[sub], text, len))
			return strdup(new->cmd[sub]);
		    else
			return (char*) NULL;
                    if (sub < i && !strncmp(new->cmd[sub], text, len))
                        return strdup(new->cmd[sub]);
                    else
                        return (char*) NULL;

		}
		else
		    return (char*) NULL;

		/* NOTREACHED */
		break;
	    }
                }
                else
                    return (char*) NULL;
            }

            /* NOTREACHED */
            break;



	default:
	    return (char*) NULL;
	    break;
        default:
            return (char*) NULL;
            /* NOTREACHED */
            break;

    }
    /* NOTREACHED */
}

static int
TclReadlineParse(char** args, int maxargs, char* buf)
{
    int nr = 0;

    while (*buf != '\0' && nr < maxargs) {
	/*
	 * Strip whitespace.  Use nulls, so
	 * that the previous argument is terminated
	 * automatically.
	 */
	while (ISWHITE(*buf))
	    *buf++ = '\0';
        /*
         * Strip whitespace.  Use nulls, so
         * that the previous argument is terminated
         * automatically.
         */
        while (ISWHITE(*buf))
            *buf++ = '\0';

	if (!(*buf)) /* don't count the terminating NULL */
	    break;
        if (!(*buf)) /* don't count the terminating NULL */
            break;

	*args++ = buf;
	nr++;
        *args++ = buf;
        nr++;

	while (('\0' != *buf) && !ISWHITE(*buf))
	    buf++;
        while (('\0' != *buf) && !ISWHITE(*buf))
            buf++;
    }

    *args = '\0';
    return nr;
}

Modified tclreadline.h.in from [7eccbb5738] to [d85f8fea8d].

1
2
3

4
5
6
7
8
9
10
11

12
13

14
15
16
17
18
19
20

1

2


3

4
5
6

7
8

9
10
11
12
13
14
15
16
-

-
+
-
-

-



-
+

-
+








 /* ==================================================================
    FILE: "/home/joze/src/tclreadline/tclreadline.h.in"
    FILE: tclreadline.h.in
    LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:33 +0100 (joze)"
    (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
    $Id$
    vim:set ft=c:
    ---
    tclreadline -- gnu readline for tcl
    http://www.zellner.org/tclreadline/
    Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
    Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
    This software is copyright under the BSD license.
    ================================================================== */  
    ================================================================== */

#ifndef TCLREADLINE_H_
#define TCLREADLINE_H_

#include <tcl.h>

#define TCLRL_LIBRARY        "@TCLRL_DIR@"

Modified tclreadline.n.in from [561d62d80a] to [ec7927137d].

1
2
3

4
5
6
7
8
9
10

11

12
13
14

15
16
17
18
19
20

21
22
23
24
25
26
27
1
2

3


4
5
6
7

8
9
10
11
12

13
14
15
16
17
18

19
20
21
22
23
24
25
26


-
+
-
-




-
+

+


-
+





-
+







.TH tclreadline n "@PATCHLEVEL_STR@" "Johannes Zellner"

.\" FILE: "/home/joze/src/tclreadline/tclreadline.n.in"
.\" FILE: tclreadline.n.in
.\" LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:33 +0100 (joze)"
.\" (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
.\" $Id$
.\" ---
.\" tclreadline -- gnu readline for tcl
.\" http://www.zellner.org/tclreadline/
.\" Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
.\" Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
.\" This software is copyright under the BSD license.
.\" ---


.\"	# CS - begin code excerpt
.\" # CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
..
.\"	# CE - end code excerpt
.\" # CE - end code excerpt
.de CE
.fi
.RE
..

.SH "NAME"
tclreadline \- gnu readline for the tcl scripting language
193
194
195
196
197
198
199
200

201
202
203
204
205

206
207
208
209
210
211
212
192
193
194
195
196
197
198

199
200
201
202
203

204
205
206
207
208
209
210
211







-
+




-
+







arguments, it returns the current setting.

.TP 5
\fB::tclreadline::Loop\fP [\fIhistoryfile\fP]
enter the tclreadline main loop. This command is typically called from
the startup resource file (something .tclshrc, depending on the interpreter
you use, see the file `sample.tclshrc'). The main loop sets up some
completion characteristics as variable -- try something like "puts $b<TAB>" -- 
completion characteristics as variable -- try something like "puts $b<TAB>" --
and command completion -- try "puts [in<TAB>".
If the optional argument \fIhistoryfile\fP is given, this file will
be used for reading and writing the command history instead of the
default \fB.tclsh-history\fP.
\fB::tclreadline::Loop\fP will normally not return. 
\fB::tclreadline::Loop\fP will normally not return.
If you want to write your own main loop and/or own custom completers,
it is probably a good idea to start with tclreadline::Loop
(see the file tclreadlineSetup.tcl).

.TP 5
\fB::tclreadline::prompt1\fP
a proc which is called by ::tclreadline::Loop and returns a string
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
294
295
296
297
298
299
300

301
302
303
304
305
306
307
308







-
+







handler, which will write the history on <ctrl-c> before exiting.

.PP
the \fB.inputrc\fP file in the users HOME directory. This file
is used normally for all programs which use the gnu readline (e.g.  bash).
The `global' readline settings there will be valid also for
\fBtclreadline\fP. Additionally the .inputrc might hold conditional
settings for the implementation name \fBtclreadline\fP. Example of 
settings for the implementation name \fBtclreadline\fP. Example of
some lines in your .inputrc:
.CS
    $if tclreadline
    "\\C-xp": "puts $env(PATH)"
    $endif
.CE

Modified tclreadlineCompleter.tcl from [cf379af2f8] to [1ea8a61e03].

more than 10,000 changes

Modified tclreadlineInit.tcl.in from [56eefa1686] to [554b1c74c7].

1

2
3
4
5
6
7
8

9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24






25
26
27
28
29
30
31
32
33
34

1


2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17






18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-
+
-
-




-
+

+









-
-
-
-
-
-
+
+
+
+
+
+










# FILE: "/home/joze/src/tclreadline/tclreadlineInit.tcl.in"
# FILE: tclreadlineInit.tcl.in
# LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:33 +0100 (joze)"
# (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
# $Id$
# ---
# tclreadline -- gnu readline for tcl
# http://www.zellner.org/tclreadline/
# Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# This software is copyright under the BSD license.
# ---

package provide tclreadline @VERSION@

namespace eval tclreadline:: {
    namespace export Init
}

proc ::tclreadline::Init {} {
    uplevel #0 {
	if ![info exists tclreadline::library] {
	    if [catch {load [file join @TCLRL_LIBDIR@ libtclreadline[info sharedlibextension]]} msg] {
		puts stderr $msg
		exit 2
	    }
	}
    if ![info exists tclreadline::library] {
        if [catch {load [file join @TCLRL_LIBDIR@ libtclreadline[info sharedlibextension]]} msg] {
        puts stderr $msg
        exit 2
        }
    }
    }
}

tclreadline::Init
::tclreadline::readline customcompleter ::tclreadline::ScriptCompleter

source [file join [file dirname [info script]] tclreadlineSetup.tcl]

set auto_index(::tclreadline::ScriptCompleter) \
[list source [file join [file dirname [info script]] tclreadlineCompleter.tcl]]

Modified tclreadlineSetup.tcl.in from [91dcec21a3] to [601cc4d255].

1

2
3
4
5
6
7
8

9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

























52
53
54
55
56
57
58
59
60








61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93





























94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113



















114
115
116
117
118
119
120
121
122
123
124
125
126
127





128
129
130
131
132
133
134
135
136



137
138

139
140
141
142



143
144
145
146
147
148
149
150
151
152









153
154

155
156
157
158
159
160
161
162







163
164
165
166
167
168
169
170
171








172
173

174
175
176
177
178
179
180
181







182
183

184
185
186


187
188

189
190
191
192
193
194
195






196
197
198
199
200
201
202






203
204
205
206
207
208
209
210







211
212
213
214
215
216
217
218
219
220
221
222
223
224







225
226
227
228
229
230





231
232
233
234

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258






259
260
261
262
263
264
265
266
267
268
269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295





















296
297
298
299
300
301
302
303
304
305
306
307
308












309
310
311
312
313
314
315
316
317
318
319










320
321

322
323
324
325
326
327
328

329
330
331

332
333

334
335
336
337
338


339
340
341

342
343
344
345
346
347
348
349
350
351
352

353
354
355
356
357
358
359

1


2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

























26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51








52
53
54
55
56
57
58
59
60
61
62
63





























64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93



















94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121





122
123
124
125
126
127
128
129
130
131
132



133
134
135
136

137
138



139
140
141
142









143
144
145
146
147
148
149
150
151
152

153
154







155
156
157
158
159
160
161
162








163
164
165
166
167
168
169
170
171

172
173







174
175
176
177
178
179
180
181

182
183


184
185
186

187
188






189
190
191
192
193
194
195






196
197
198
199
200
201
202







203
204
205
206
207
208
209
210
211
212
213
214
215
216







217
218
219
220
221
222
223
224





225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251






252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273





















274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295












296
297
298
299
300
301
302
303
304
305
306
307
308










309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326

327
328
329

330
331

332
333
334
335


336
337
338
339

340
341
342
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
-
+
-
-




-
+

+

















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+




-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
+
+
+
+
+






-
-
-
+
+
+

-
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+

-
-
+
+

-
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+







-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+



-
+


















-
-
-
-
-
-
+
+
+
+
+
+














-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+






-
+


-
+

-
+



-
-
+
+


-
+










-
+







# FILE: "/home/joze/src/tclreadline/tclreadlineSetup.tcl.in"
# FILE: tclreadlineSetup.tcl.in
# LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:34 +0100 (joze)"
# (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
# $Id$
# ---
# tclreadline -- gnu readline for tcl
# http://www.zellner.org/tclreadline/
# Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
# Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>
# This software is copyright under the BSD license.
# ---


package provide tclreadline @VERSION@

proc unknown args {

    global auto_noexec auto_noload env unknown_pending tcl_interactive
    global errorCode errorInfo

    # Save the values of errorCode and errorInfo variables, since they
    # may get modified if caught errors occur below.  The variables will
    # be restored just before re-executing the missing command.

    set savedErrorCode $errorCode
    set savedErrorInfo $errorInfo
    set name [lindex $args 0]
    if ![info exists auto_noload] {
	#
	# Make sure we're not trying to load the same proc twice.
	#
	if [info exists unknown_pending($name)] {
	    return -code error "self-referential recursion in \"unknown\" for command \"$name\""
	}
	set unknown_pending($name) pending
	set ret [catch {auto_load $name [uplevel 1 {namespace current}]} msg]
	unset unknown_pending($name)
	if {$ret != 0} {
	    return -code $ret -errorcode $errorCode \
	    "error while autoloading \"$name\": $msg"
	}
	if ![array size unknown_pending] {
	    unset unknown_pending
	}
	if $msg {
	    set errorCode $savedErrorCode
	    set errorInfo $savedErrorInfo
	    set code [catch {uplevel 1 $args} msg]
	    if {$code ==  1} {
		#
		# Strip the last five lines off the error stack (they're
		    # from the "uplevel" command).
		#
    #
    # Make sure we're not trying to load the same proc twice.
    #
    if [info exists unknown_pending($name)] {
        return -code error "self-referential recursion in \"unknown\" for command \"$name\""
    }
    set unknown_pending($name) pending
    set ret [catch {auto_load $name [uplevel 1 {namespace current}]} msg]
    unset unknown_pending($name)
    if {$ret != 0} {
        return -code $ret -errorcode $errorCode \
        "error while autoloading \"$name\": $msg"
    }
    if ![array size unknown_pending] {
        unset unknown_pending
    }
    if $msg {
        set errorCode $savedErrorCode
        set errorInfo $savedErrorInfo
        set code [catch {uplevel 1 $args} msg]
        if {$code ==  1} {
        #
        # Strip the last five lines off the error stack (they're
            # from the "uplevel" command).
        #

		set new [split $errorInfo \n]
		set new [join [lrange $new 0 [expr [llength $new] - 6]] \n]
		return -code error -errorcode $errorCode \
		-errorinfo $new $msg
	    } else {
		return -code $code $msg
	    }
	}
        set new [split $errorInfo \n]
        set new [join [lrange $new 0 [expr [llength $new] - 6]] \n]
        return -code error -errorcode $errorCode \
        -errorinfo $new $msg
        } else {
        return -code $code $msg
        }
    }
    }

    # REMOVED THE [info script] TEST (joze, SEP 98)
    if {([info level] == 1) && [info exists tcl_interactive] && $tcl_interactive} {
	if ![info exists auto_noexec] {
	    set new [auto_execok $name]
	    if {$new != ""} {
		set errorCode $savedErrorCode
		set errorInfo $savedErrorInfo
		set redir ""
		if {[info commands console] == ""} {
		    set redir ">&@stdout <@stdin"
		}
		# LOOK FOR GLOB STUFF IN $ARGS (joze, SEP 98)
		return [uplevel eval exec $redir $new \
		[::tclreadline::Glob [lrange $args 1 end]]]
	    }
	}
	set errorCode $savedErrorCode
	set errorInfo $savedErrorInfo
	if {$name == "!!"} {
	    set newcmd [history event]
	} elseif {[regexp {^!(.+)$} $name dummy event]} {
	    set newcmd [history event $event]
	} elseif {[regexp {^\^([^^]*)\^([^^]*)\^?$} $name dummy old new]} {
	    set newcmd [history event -1]
	    catch {regsub -all -- $old $newcmd $new newcmd}
	}
	if [info exists newcmd] {
	    tclLog $newcmd
	    history change $newcmd 0
	    return [uplevel $newcmd]
	}
    if ![info exists auto_noexec] {
        set new [auto_execok $name]
        if {$new != ""} {
        set errorCode $savedErrorCode
        set errorInfo $savedErrorInfo
        set redir ""
        if {[info commands console] == ""} {
            set redir ">&@stdout <@stdin"
        }
        # LOOK FOR GLOB STUFF IN $ARGS (joze, SEP 98)
        return [uplevel eval exec $redir $new \
        [::tclreadline::Glob [lrange $args 1 end]]]
        }
    }
    set errorCode $savedErrorCode
    set errorInfo $savedErrorInfo
    if {$name == "!!"} {
        set newcmd [history event]
    } elseif {[regexp {^!(.+)$} $name dummy event]} {
        set newcmd [history event $event]
    } elseif {[regexp {^\^([^^]*)\^([^^]*)\^?$} $name dummy old new]} {
        set newcmd [history event -1]
        catch {regsub -all -- $old $newcmd $new newcmd}
    }
    if [info exists newcmd] {
        tclLog $newcmd
        history change $newcmd 0
        return [uplevel $newcmd]
    }

	set ret [catch {set cmds [info commands $name*]} msg]
	if {[string compare $name "::"] == 0} {
	    set name ""
	}
	if {$ret != 0} {
	    return -code $ret -errorcode $errorCode \
	    "error in unknown while checking if \"$name\" is a unique command abbreviation: $msg"
	}
	if {[llength $cmds] == 1} {
	    return [uplevel [lreplace $args 0 0 $cmds]]
	}
	if {[llength $cmds] != 0} {
	    if {$name == ""} {
		return -code error "empty command name \"\""
	    } else {
		return -code error \
		"ambiguous command name \"$name\": [lsort $cmds]"
	    }
	}
    set ret [catch {set cmds [info commands $name*]} msg]
    if {[string compare $name "::"] == 0} {
        set name ""
    }
    if {$ret != 0} {
        return -code $ret -errorcode $errorCode \
        "error in unknown while checking if \"$name\" is a unique command abbreviation: $msg"
    }
    if {[llength $cmds] == 1} {
        return [uplevel [lreplace $args 0 0 $cmds]]
    }
    if {[llength $cmds] != 0} {
        if {$name == ""} {
        return -code error "empty command name \"\""
        } else {
        return -code error \
        "ambiguous command name \"$name\": [lsort $cmds]"
        }
    }
    }
    return -code error "invalid command name \"$name\""
}

namespace eval tclreadline {

namespace export Setup Loop InitTclCmds InitTkCmds Print ls

proc ls {args} {
	if {[exec uname -s] == "Linux"} {
		eval exec ls --color -FC [Glob $args]
	} else {
		eval exec ls -FC [Glob $args]
	}
    if {[exec uname -s] == "Linux"} {
        eval exec ls --color -FC [Glob $args]
    } else {
        eval exec ls -FC [Glob $args]
    }
}

proc Setup {args} {

    uplevel #0 {

	if {"" == [info commands ::tclreadline::readline]} {
	    ::tclreadline::Init
	}
    if {"" == [info commands ::tclreadline::readline]} {
        ::tclreadline::Init
    }

	if {"" == [info procs ::tclreadline::prompt1] && [info nameofexecutable] != ""} {
    if {"" == [info procs ::tclreadline::prompt1] && [info nameofexecutable] != ""} {

	    namespace eval ::tclreadline {
		variable prompt_string
		set base [file tail [info nameofexecutable]]
        namespace eval ::tclreadline {
        variable prompt_string
        set base [file tail [info nameofexecutable]]

		if {[string match tclsh* $base] && [info exists tcl_version]} {
		    set prompt_string \
		    "\[0;31mtclsh$tcl_version\[0m"
		} elseif {[string match wish* $base] \
		    && [info exists tk_version]} {
			set prompt_string "\[0;34mwish$tk_version\[0m"
		    } else {
			set prompt_string "\[0;31m$base\[0m"
		    }
        if {[string match tclsh* $base] && [info exists tcl_version]} {
            set prompt_string \
            "\[0;31mtclsh$tcl_version\[0m"
        } elseif {[string match wish* $base] \
            && [info exists tk_version]} {
            set prompt_string "\[0;34mwish$tk_version\[0m"
            } else {
            set prompt_string "\[0;31m$base\[0m"
            }

	    }
        }

	    if {"" == [info procs ::tclreadline::prompt1]} {
		proc ::tclreadline::prompt1 {} {
		    variable prompt_string
		    global env
		    if {[catch {set pwd [pwd]} tmp]} {
			set pwd "unable to get pwd"
		    }
        if {"" == [info procs ::tclreadline::prompt1]} {
        proc ::tclreadline::prompt1 {} {
            variable prompt_string
            global env
            if {[catch {set pwd [pwd]} tmp]} {
            set pwd "unable to get pwd"
            }

		    if [info exists env(HOME)] {
			regsub $env(HOME) $pwd "~" pwd
		    }
		    return "$prompt_string \[$pwd\]"
		}
	    }
	    # puts body=[info body ::tclreadline::prompt1]
	}
            if [info exists env(HOME)] {
            regsub $env(HOME) $pwd "~" pwd
            }
            return "$prompt_string \[$pwd\]"
        }
        }
        # puts body=[info body ::tclreadline::prompt1]
    }

	if {"" == [info procs ::tclreadline::prompt2] && [info nameofexecutable] != ""} {
    if {"" == [info procs ::tclreadline::prompt2] && [info nameofexecutable] != ""} {

	    if {"" == [info procs ::tclreadline::prompt2]} {
		proc ::tclreadline::prompt2 {} {
		    return ">"
		}
	    }
	    # puts body=[info body ::tclreadline::prompt2]
	}
        if {"" == [info procs ::tclreadline::prompt2]} {
        proc ::tclreadline::prompt2 {} {
            return ">"
        }
        }
        # puts body=[info body ::tclreadline::prompt2]
    }

	if {"" == [info procs exit]} {
    if {"" == [info procs exit]} {

	    catch {rename ::tclreadline::Exit ""}
	    rename exit ::tclreadline::Exit
        catch {rename ::tclreadline::Exit ""}
        rename exit ::tclreadline::Exit

	    proc exit {args} {
        proc exit {args} {

		if {[catch {
		    ::tclreadline::readline write \
		    [::tclreadline::HistoryFileGet]
		} ::tclreadline::errorMsg]} {
		    puts stderr $::tclreadline::errorMsg
		}
        if {[catch {
            ::tclreadline::readline write \
            [::tclreadline::HistoryFileGet]
        } ::tclreadline::errorMsg]} {
            puts stderr $::tclreadline::errorMsg
        }

		# this call is ignored, if tclreadline.c
		# was compiled with CLEANUP_AFER_SIGNAL
		# not defined. This is the case for
		# older versions of libreadline.
		#
		::tclreadline::readline reset-terminal
        # this call is ignored, if tclreadline.c
        # was compiled with CLEANUP_AFER_SIGNAL
        # not defined. This is the case for
        # older versions of libreadline.
        #
        ::tclreadline::readline reset-terminal

		if [catch "eval ::tclreadline::Exit $args" message] {
		    puts stderr "error:"
		    puts stderr "$message"
		}
		# NOTREACHED
	    }
	}
        if [catch "eval ::tclreadline::Exit $args" message] {
            puts stderr "error:"
            puts stderr "$message"
        }
        # NOTREACHED
        }
    }

    }

    global env
    variable historyfile

    if {[string trim [llength ${args}]]} {
	set historyfile ""
	catch {
	    set historyfile [file nativename [lindex ${args} 0]]
	}
	if {"" == [string trim $historyfile]} {
	    set historyfile [lindex ${args} 0]
	}
    set historyfile ""
    catch {
        set historyfile [file nativename [lindex ${args} 0]]
    }
    if {"" == [string trim $historyfile]} {
        set historyfile [lindex ${args} 0]
    }
    } else {
	if [info exists env(HOME)] {
	    set historyfile  $env(HOME)/.tclsh-history
	} else {
	    set historyfile  .tclsh-history
	}
    if [info exists env(HOME)] {
        set historyfile  $env(HOME)/.tclsh-history
    } else {
        set historyfile  .tclsh-history
    }
    }
    set ::tclreadline::errorMsg [readline initialize $historyfile]
    if {$::tclreadline::errorMsg != ""} {
	puts stderr $::tclreadline::errorMsg
    puts stderr $::tclreadline::errorMsg
    }

    # InitCmds

    rename Setup ""
}

proc HistoryFileGet {} {
    variable historyfile
    return $historyfile
}

# obsolete
#
proc Glob {string} {

    set commandstring ""
    foreach name $string {
	set replace [glob -nocomplain -- $name]
	if {$replace == ""} {
	    lappend commandstring $name
	} else {
	    lappend commandstring $replace
	}
    set replace [glob -nocomplain -- $name]
    if {$replace == ""} {
        lappend commandstring $name
    } else {
        lappend commandstring $replace
    }
    }
    # return $commandstring
    # Christian Krone <krischan@sql.de> proposed
    return [eval concat $commandstring]
}



proc Loop {args} {

    eval Setup ${args}

    uplevel #0 {

	while {1} {
    while {1} {

	    if {[catch {
		if {"" != [namespace eval ::tclreadline {info procs prompt1}]} {
		    set ::tclreadline::LINE [::tclreadline::readline read \
		    [::tclreadline::prompt1]]
		} else {
		    set ::tclreadline::LINE [::tclreadline::readline read %]
		}
		while {![::tclreadline::readline complete $::tclreadline::LINE]} {
		    append ::tclreadline::LINE "\n"
		    if {"" != [namespace eval ::tclreadline {info procs prompt2}]} {
			append ::tclreadline::LINE \
			    [tclreadline::readline read [::tclreadline::prompt2]]
		    } else {
			append ::tclreadline::LINE [tclreadline::readline read >]
		    }
		}
	    } ::tclreadline::errorMsg]} {
		puts stderr [list tclreadline::Loop: error. \
		$::tclreadline::errorMsg]
		continue
	    }
        if {[catch {
        if {"" != [namespace eval ::tclreadline {info procs prompt1}]} {
            set ::tclreadline::LINE [::tclreadline::readline read \
            [::tclreadline::prompt1]]
        } else {
            set ::tclreadline::LINE [::tclreadline::readline read %]
        }
        while {![::tclreadline::readline complete $::tclreadline::LINE]} {
            append ::tclreadline::LINE "\n"
            if {"" != [namespace eval ::tclreadline {info procs prompt2}]} {
            append ::tclreadline::LINE \
                [tclreadline::readline read [::tclreadline::prompt2]]
            } else {
            append ::tclreadline::LINE [tclreadline::readline read >]
            }
        }
        } ::tclreadline::errorMsg]} {
        puts stderr [list tclreadline::Loop: error. \
        $::tclreadline::errorMsg]
        continue
        }

	    # Magnus Eriksson <magnus.eriksson@netinsight.se> proposed
	    # to add the line also to tclsh's history.
	    #
	    # I decided to add only lines which are different from
	    # the previous one to the history. This is different
	    # from tcsh's behaviour, but I found it quite convenient
	    # while using mshell on os9.
	    #
	    if {[string length $::tclreadline::LINE] && \
		    [history event 0] != $::tclreadline::LINE} {
		history add $::tclreadline::LINE
	    }
        # Magnus Eriksson <magnus.eriksson@netinsight.se> proposed
        # to add the line also to tclsh's history.
        #
        # I decided to add only lines which are different from
        # the previous one to the history. This is different
        # from tcsh's behaviour, but I found it quite convenient
        # while using mshell on os9.
        #
        if {[string length $::tclreadline::LINE] && \
            [history event 0] != $::tclreadline::LINE} {
        history add $::tclreadline::LINE
        }

	    if [catch {
		set ::tclreadline::result [eval $::tclreadline::LINE]
		if {$::tclreadline::result != "" && [tclreadline::Print]} {
		    puts $::tclreadline::result
		}
		set ::tclreadline::result ""
	    } ::tclreadline::errorMsg] {
		puts stderr $::tclreadline::errorMsg
		puts stderr [list while evaluating $::tclreadline::LINE]
	    }
        if [catch {
        set ::tclreadline::result [eval $::tclreadline::LINE]
        if {$::tclreadline::result != "" && [tclreadline::Print]} {
            puts $::tclreadline::result
        }
        set ::tclreadline::result ""
        } ::tclreadline::errorMsg] {
        puts stderr $::tclreadline::errorMsg
        puts stderr [list while evaluating $::tclreadline::LINE]
        }

	}
    }
    }
}

proc Print {args} {
    variable PRINT
    if ![info exists PRINT] {
	set PRINT yes
    set PRINT yes
    }
    if [regexp -nocase \(true\|yes\|1\) $args] {
	set PRINT yes
    set PRINT yes
    } elseif [regexp -nocase \(false\|no\|0\) $args] {
	set PRINT no
    set PRINT no
    }
    return $PRINT
}
# 
# 
#
#
# proc InitCmds {} {
#     # XXX
#     return 
#     return
#     # XXX
#     global tcl_version tk_version
#     if {[info exists tcl_version]} {
#         InitTclCmds
#     }
#     if {[info exists tk_version]} {
#         InitTkCmds
#     }
#     rename InitCmds ""
# }
# 
#
# proc InitTclCmds {} {
#     variable known_cmds
#     foreach line {
#         "after option ?arg arg ...?"
#         "append varName ?value value ...?"
#         "array option arrayName ?arg ...?"
#         "bgerror"
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
406
407
408
409
410
411
412

413
414
415
416
417
418
419
420







-
+







#         "while test command"
#     } {
#         readline add $line
#         set known_cmds([lindex $line 0]) ${line}
#     }
#     rename InitTclCmds ""
# }
# 
#
# proc InitTkCmds {} {
#     variable known_cmds
#     foreach line {
#         "bind window ?pattern? ?command?"
#         "bindtags window ?tags?"
#         "button pathName ?options?"
#         "canvas pathName ?options?"
450
451
452
453
454
455
456
457

458
459
460
449
450
451
452
453
454
455

456
457
458
459







-
+



#         "wm option window ?arg ...?"
#     } {
#         readline add $line
#         set known_cmds([lindex $line 0]) ${line}
#     }
#     rename InitTkCmds ""
# }
# 
#


}; # namespace tclreadline

Modified tclshrl.c from [6604055b46] to [c7e5e71138].

1
2
3

4
5
6
7
8
9
10
11
12

13
14
15
16

17
18
19
20
21
22
23

1

2



3
4

5
6

7

8


9
10
11
12
13
14
15
16
-

-
+
-
-
-


-


-
+
-

-
-
+








 /* ==================================================================

    FILE: tclshrl.c
    FILE: "/home/joze/src/tclreadline/tclshrl.c"
    LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:34 +0100 (joze)"
    (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
    $Id$
    ---

    tclreadline -- gnu readline for tcl
    http://www.zellner.org/tclreadline/
    Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
    Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>

    This software is copyright under the BSD license.

    ================================================================== */  
    ================================================================== */

#ifdef HAVE_CONFIG_H
#   include "config.h"
#endif

#include <tcl.h>
#include <tclreadline.h>
34
35
36
37
38
39
40
41

42
43
44

45
46
47

48
49
50
51
52
53
54
55
56


57
58
59
60
61
62
63
64
65
66
27
28
29
30
31
32
33

34
35
36

37
38
39

40
41
42
43
44
45
46
47


48
49
50
51
52
53
54
55
56
57
58
59







-
+


-
+


-
+







-
-
+
+










{
    char file[0xff];
    int status;
#if 0
    assert(Tcl_InitStubs(interp, TCL_VERSION, 0));
#endif
    if (TCL_ERROR == Tcl_Init(interp)) {
	return TCL_ERROR;
        return TCL_ERROR;
    }
    if (TCL_ERROR == Tclreadline_Init(interp)) {
	return TCL_ERROR;
        return TCL_ERROR;
    }
    Tcl_StaticPackage(interp, "tclreadline",
	Tclreadline_Init, Tclreadline_SafeInit);
    Tclreadline_Init, Tclreadline_SafeInit);
#if (TCL_MAJOR_VERSION == 7) && (TCL_MINOR_VERSION == 4)
    tcl_RcFileName = "~/.tclshrc";
#else
    Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
#endif
    sprintf(file, "%s/tclreadlineInit.tcl", TCLRL_LIBRARY);
    if ((status = Tcl_EvalFile(interp, file))) {
	fprintf(stderr, "(TclreadlineAppInit) unable to eval %s\n", file);
	exit (1);
        fprintf(stderr, "(TclreadlineAppInit) unable to eval %s\n", file);
        exit (1);
    }
    return TCL_OK;
}

int
main(int argc, char *argv[])
{
    Tcl_Main(argc, argv, TclreadlineAppInit);
    return 0;
}

Modified wishrl.c from [fd844d639f] to [d3a28cc973].

1
2
3

4
5
6
7
8
9
10
11
12

13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39

40
41
42

43
44
45

46
47
48
49
50
51
52
53
54


55
56
57
58
59
60
61
62
63
64

1

2



3
4

5
6

7

8


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

29
30
31

32
33
34

35
36
37

38
39
40
41
42
43
44
45


46
47
48
49
50
51
52
53
54
55
56
57
-

-
+
-
-
-


-


-
+
-

-
-
+



















-
+


-
+


-
+


-
+







-
-
+
+











 /* ==================================================================

    FILE: wishrl.c
    FILE: "/home/joze/src/tclreadline/wishrl.c"
    LAST MODIFICATION: "Mit, 10 Jan 2001 06:29:34 +0100 (joze)"
    (C) 1998 - 2001 by Johannes Zellner, <johannes@zellner.org>
    $Id$
    ---

    tclreadline -- gnu readline for tcl
    http://www.zellner.org/tclreadline/
    Copyright (c) 1998 - 2001, Johannes Zellner <johannes@zellner.org>
    Copyright (c) 1998 - 2014, Johannes Zellner <johannes@zellner.org>

    This software is copyright under the BSD license.

    ================================================================== */  
    ================================================================== */

#ifdef HAVE_CONFIG_H
#   include "config.h"
#endif

#include <tcl.h>
#include <tk.h>
#include <tclreadline.h>

extern int Tclreadline_Init(Tcl_Interp *interp);
extern int Tclreadline_SafeInit(Tcl_Interp *interp);

int
TclreadlineAppInit(Tcl_Interp* interp)
{
    char file[0xff];
    int status;

    if (TCL_ERROR == Tcl_Init(interp)) {
	return TCL_ERROR;
        return TCL_ERROR;
    }
    if (TCL_ERROR == Tk_Init(interp)) {
	return TCL_ERROR;
        return TCL_ERROR;
    }
    if (TCL_ERROR == Tclreadline_Init(interp)) {
	return TCL_ERROR;
        return TCL_ERROR;
    }
    Tcl_StaticPackage(interp, "tclreadline",
	Tclreadline_Init, Tclreadline_SafeInit);
    Tclreadline_Init, Tclreadline_SafeInit);
#if (TCL_MAJOR_VERSION == 7) && (TCL_MINOR_VERSION == 4)
    tcl_RcFileName = "~/.wishrc";
#else
    Tcl_SetVar(interp, "tcl_rcFileName", "~/.wishrc", TCL_GLOBAL_ONLY);
#endif
    sprintf(file, "%s/tclreadlineInit.tcl", TCLRL_LIBRARY);
    if ((status = Tcl_EvalFile(interp, file))) {
	fprintf(stderr, "(TclreadlineAppInit) unable to eval %s\n", file);
	exit (1);
        fprintf(stderr, "(TclreadlineAppInit) unable to eval %s\n", file);
        exit (1);
    }
    return TCL_OK;
}

int
main(int argc, char *argv[])
{
    Tk_Main(argc, argv, TclreadlineAppInit);
    return 0;
}