Check-in [5789b12712]
Not logged in
Overview
Comment:ci after porting this to configure
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | descendants | trunk
Files: files | file ages | folders
SHA1: 5789b127126f2fc03721352e00b62ba1b770d9b5
User & Date: johannes@zellner.org on 1998-10-05 13:46:37
Other Links: manifest | tags
Context
1999-02-28
16:52
ci after porting this to configure check-in: eb8595aabf user: johannes@zellner.org tags: trunk
1998-10-05
13:46
ci after porting this to configure check-in: 5789b12712 user: johannes@zellner.org tags: trunk
Changes

Added Makefile.in version [d8642a2e4f].










































































































































































































































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

# ==================================================================
# FILE: "/home/joze/tmp/tclreadline/Makefile.in"
# LAST MODIFIED: "Mon Oct 05 15:46:31 1998 (joze)"
# (c) 1998 by Johannes Zellner
# Johannes.Zellner@physik.uni-karlsruhe.de
# $Id$
# ==================================================================

MAJOR_VERSION = @TCLREADLINE_MAJOR_VERSION@
MINOR_VERSION = @TCLREADLINE_MINOR_VERSION@
VERSION = @TCLREADLINE_VERSION@

#host = @host@
#host_cpu = @host_cpu@
#host_vendor = @host_vendor@
#host_os = @host_os@

srcdir=@srcdir@
VPATH=@srcdir@

#----------------------------------------------------------------
# Things you can change to personalize the Makefile for your own
# site (you can make these changes in either Makefile.in or
# Makefile, but changes to Makefile will get lost if you re-run
# the configuration script).
#----------------------------------------------------------------

# Default top-level directories in which to install architecture-
# specific files (exec_prefix) and machine-independent files such
# as scripts (prefix).  The values specified here may be overridden
# at configure-time with the --exec-prefix and --prefix options
# to the "configure" script.

prefix =		@prefix@
exec_prefix =		@exec_prefix@

# The following definition can be set to non-null for special systems
# like AFS with replication.  It allows the pathnames used for installation
# to be different than those used for actually reference files at
# run-time.  INSTALL_ROOT is prepended to $prefix and $exec_prefix
# when installing files.
INSTALL_ROOT =

# Directory from which applications will reference the library of Tcl
# scripts (note: you can set the TCLREADLINE_LIBRARY environment variable at
# run-time to override the compiled-in location):
TCLREADLINE_LIBRARY = $(prefix)/lib/tclreadline$(VERSION)

# Path name to use when installing library scripts:
SCRIPT_INSTALL_DIR =	$(INSTALL_ROOT)$(TCLREADLINE_LIBRARY)

# Directory in which to install the archive libitk.a:
LIB_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/lib

# Path to use at runtime to refer to LIB_INSTALL_DIR:
LIB_RUNTIME_DIR =	$(exec_prefix)/lib

# Top-level directory for manual entries:
MAN_INSTALL_DIR =	$(INSTALL_ROOT)$(prefix)/man

# Directory in which to install manual entries for the built-in
# Tcl commands implemented by Tk:
MANN_INSTALL_DIR =	$(MAN_INSTALL_DIR)/mann


# To change the compiler switches, for example to change from -O
# to -g, change the following line:
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@

# To disable ANSI-C procedure prototypes reverse the comment characters
# on the following lines:
PROTO_FLAGS =
#PROTO_FLAGS = -DNO_PROTOTYPE


# Some versions of make, like SGI's, use the following variable to
# determine which shell to use for executing commands:
SHELL =		/bin/sh

# Tk used to let the configure script choose which program to use
# for installing, but there are just too many different versions of
# "install" around;  better to use the install-sh script that comes
# with the distribution, which is slower but guaranteed to work.

INSTALL = $(TOP_DIR)/config/install-sh -c
INSTALL_PROGRAM =	${INSTALL}
INSTALL_DATA =		${INSTALL} -m 644
MKINSTALLDIRS =		$(TOP_DIR)/config/mkinstalldirs

# The symbols below provide support for dynamic loading and shared
# libraries.  The values of the symbols are normally set by the
# configure script.  You shouldn't normally need to modify any of
# these definitions by hand.

SHLIB_CFLAGS = @SHLIB_CFLAGS@


# The symbol below provides support for dynamic loading and shared
# libraries.  See configure.in for a description of what it means.
# The values of the symbolis normally set by the configure script.

SHLIB_LD = @SHLIB_LD@

#----------------------------------------------------------------
# The information below is modified by the configure script when
# Makefile is generated from Makefile.in.  You shouldn't normally
# modify any of this stuff by hand.
#----------------------------------------------------------------

RANLIB =		@RANLIB@
TOP_DIR =		@srcdir@
TCL_INCLUDE_DIR =	@TCL_INCLUDE_DIR@
TCLREADLINE_LIB_FILE =	@TCLREADLINE_LIB_FILE@

#----------------------------------------------------------------
# The information below should be usable as is.  The configure
# script won't modify it and you shouldn't need to modify it
# either.
#----------------------------------------------------------------


CC = @CC@
CC_SWITCHES = $(CFLAGS) $(SHLIB_CFLAGS) -I$(TOP_DIR) \
        -I$(TCL_INCLUDE_DIR) -DREADLINE_LIBRARY \
        -DTCLREADLINE_VERSION=\"$(VERSION)\"

OBJS = tclreadline.o

CSRCS = $(TOP_DIR)/tclreadline.c
TCLFILES = tclreadlineInit.tcl tclreadlineSetup.tcl

SOURCES = \
    Makefile.in \
    configure.in \
    tclreadline.c \
    tclreadline.h \
    tclreadlineConfig.sh.in \
    tclreadlineInit.tcl.in \
    tclreadlineSetup.tcl

CIFLAGS = -t-"gnu readline for tcl" -m"ci after porting this to configure"

PHONY: all clean distclean ctags tcltags vimtags tags ci co
SUFFIXES: .c .o .so .sl .tcl

all: $(TCLREADLINE_LIB_FILE)

# The following target is configured by autoconf to generate either
# a shared library or non-shared library for [incr Tk].

@TCLREADLINE_LIB_FILE@: ${OBJS}
	rm -f $(TCLREADLINE_LIB_FILE)
	@MAKE_LIB@
	$(RANLIB) $(TCLREADLINE_LIB_FILE)

install: install-binaries install-libraries install-man

install-binaries: $(TCLREADLINE_LIB_FILE)
	@$(MKINSTALLDIRS) $(SCRIPT_INSTALL_DIR)
	@echo "Installing $(TCLREADLINE_LIB_FILE)"
	@$(INSTALL_DATA) $(TCLREADLINE_LIB_FILE) \
            $(SCRIPT_INSTALL_DIR)/$(TCLREADLINE_LIB_FILE)
	@(cd $(SCRIPT_INSTALL_DIR); $(RANLIB) $(TCLREADLINE_LIB_FILE))
	chmod 555 $(SCRIPT_INSTALL_DIR)/$(TCLREADLINE_LIB_FILE)


install-libraries:
	@$(MKINSTALLDIRS) $(SCRIPT_INSTALL_DIR)
	@echo "Installing tclreadlineInit.tcl"
	@$(INSTALL_DATA) tclreadlineInit.tcl $(SCRIPT_INSTALL_DIR)
	@$(INSTALL_DATA) tclreadlineSetup.tcl $(SCRIPT_INSTALL_DIR)
	@$(INSTALL_DATA) pkgIndex.tcl $(SCRIPT_INSTALL_DIR)

install-man:
	@$(MKINSTALLDIRS) $(MANN_INSTALL_DIR)
	@cd $(TOP_DIR)/doc; for i in *.n; \
	    do \
	    echo "Installing doc/$$i"; \
	    rm -f $(MANN_INSTALL_DIR)/$$i; \
	    sed -e '/man\.macros/r man.macros' -e '/man\.macros/d' \
		    $$i > $(MANN_INSTALL_DIR)/$$i; \
	    chmod 444 $(MANN_INSTALL_DIR)/$$i; \
	    done;

pkgIndex.tcl:
	@echo "eval pkg_mkIndex $(TOP_DIR) tclreadline*.tcl" | tclsh

Makefile: $(TOP_DIR)/Makefile.in
	$(SHELL) config.status

clean:
	rm -f *.a *.o core errs *~ \#* tags *.E a.out errors

distclean: clean
	rm -f \
	Makefile pkgIndex.tcl tclreadlineInit.tcl \
	config.status config.log config.cache

depend:
	makedepend -- $(CC_SWITCHES) -- $(CSRCS)

configure: configure.in
	autoconf

.c.o:
	$(CC) -c $(CC_SWITCHES) $<

tclreadline.o:	$(TOP_DIR)/tclreadline.c Makefile
	$(CC) -c $(CC_SWITCHES) $(TOP_DIR)/tclreadline.c


ctags:
	ctags -R

tcltags: ctags $(TCLFILES)
	tcltags $(TCLFILES)

vimtags: tcltags
	vimtags

tags: vimtags


ci: $(SOURCES)
	ci  -r"0.1"  -l  $(CIFLAGS) $(SOURCES)

co: $(SOURCES)
	co -l $(SOURCES)


# DO NOT DELETE THIS LINE -- make depend depends on it.

Added tclreadline.c version [75bdea63cb].























































































































































































































































































































































































































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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/* 
 * FILE: "/home/joze/tmp/tclreadline/tclreadline.c"
 * LAST MODIFIED: "Sat Oct 03 03:06:54 1998 (joze)"
 * (c) 1998 by Johannes Zellner
 * Johannes.Zellner@physik.uni-karlsruhe.de
 * $Id$
 */

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

#define MALLOC(size) Tcl_Alloc ((int) size)
#define FREE(ptr) if (ptr) Tcl_Free ((char *) ptr)

#define _CMD_SET	(1 << 0)
#define _CMD_GET	(1 << 1)
#define _CMD_SUB_GET	(1 << 2)


typedef struct cmds_t {
    struct cmds_t *prev;
    char **cmd;
    struct cmds_t *next;
} cmds_t;


#define STRIPLEFT(ptr)          \
do {                            \
    char *tmp = ptr;            \
    while (*tmp && *tmp <= ' ') \
        tmp ++;                 \
    strcpy (ptr, tmp);          \
} while (0)

#define STRIPRIGHT(ptr)                                \
do {                                                   \
    char *__tmp__;                                     \
    for (__tmp__ = strchr (ptr, '\0') - 1;             \
         __tmp__ >= ptr && *__tmp__ <= ' '; __tmp__--) \
        *__tmp__ = '\0';                               \
} while (0)

#define STRIPWHITE(ptr) \
do {                    \
    STRIPLEFT (ptr);    \
    STRIPRIGHT (ptr);   \
} while (0)



    /*
extern char *rl_readline_name = "tclreadline";
    */


/*
 * forward declarations.
 */
int	TclReadlineCmd	(ClientData clientData, Tcl_Interp *interp,
                         int argc, char **argv);
void	TclReadlineDataAvailableHandler	(ClientData clientData, int mask);
void	TclReadlineLineCompleteHandler	(char *ptr);
int	Tclreadline_SafeInit	(Tcl_Interp *interp);
int	Tclreadline_Init	(Tcl_Interp *interp);
char	*TclReadlineInitialize	(char *historyfile);
char	**TclReadlineCompletion	(char *text, int start, int end);
char	*TclReadline0generator	(char *text, int state);
char	*TclReadline1generator	(char *text, int state);
char	*TclReadlineKnownCommands	(char *text, int state, int mode);
int	TclReadlineEventHook	(void);
int	TclReadlineParse	(char **args, int maxargs, char *buf);


static int line_complete = 0;
static char *line = (char *) NULL;



int TclReadlineCmd (clientData, interp, argc, argv)
    ClientData clientData;	/* Main window associated with interpreter  */
    Tcl_Interp *interp;		/* Current interpreter                      */
    int argc;			/* Number of arguments                      */
    char **argv;		/* Argument strings                         */
{
    int		c, length;
    

    if (argc < 2) {
	interp->result = "wrong # args";
	for (c = 0; c < argc; c++)
	    fprintf (stderr, "argv[%d] = %s\n", c, argv[c]);
	return TCL_ERROR;
    }

    c = argv[1][0];
    length = strlen(argv[1]);



    if (c == 'r'  && strncmp (argv[1], "read", length) == 0) {
        
        char *expansion = (char *) NULL;
        int status;
        
        line_complete = 0;
        rl_callback_handler_install (argc == 3 ? argv[2] : "%",
                TclReadlineLineCompleteHandler);

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

        while (!line_complete) {
            Tcl_DoOneEvent (0);
        }

        Tcl_DeleteFileHandler (0);

        status = history_expand (line, &expansion);
        if (status == 1)
            printf ("%s\n", expansion);
        else if (status == -1)
            Tcl_AppendResult (interp, "error in history expansion\n",
                    (char *) NULL);
        
        if (expansion && *expansion)
            add_history (expansion);

        Tcl_AppendResult (interp, expansion, (char *) NULL);

        FREE (line);
        FREE (expansion);
        return (TCL_OK);

    }
    else if (c == 'i'  && strncmp (argv[1], "initialize", length) == 0) {
        if (argc != 3)
            goto BAD_COMMAND;
        else
            Tcl_AppendResult (interp, TclReadlineInitialize (argv[2]),
                    (char *) NULL);
    }
    else if (c == 'w'  && strncmp (argv[1], "write", length) == 0) {
        if (argc != 3)
            goto BAD_COMMAND;
        else if (write_history (argv[2]))
            Tcl_AppendResult (interp, "unable to write history to \"",
                    argv[2], "\"\n", (char *) NULL);
    }
    else if (c == 'a'  && strncmp (argv[1], "add", length) == 0) {
        if (argc != 3)
            goto BAD_COMMAND;
        else if (TclReadlineKnownCommands (argv[2], (int) 0, _CMD_SET))
            Tcl_AppendResult (interp, "unable to add command \"",
                    argv[2], "\"\n", (char *) NULL);
    }
    else
        goto BAD_COMMAND;


    return TCL_OK;

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

}

void TclReadlineDataAvailableHandler (ClientData clientData, int mask)
{
    if (mask & TCL_READABLE)
        rl_callback_read_char ();
}

void TclReadlineLineCompleteHandler (char *ptr)
{
    if (ptr && *ptr) {
        line_complete = 1;
        rl_callback_handler_remove ();
        line = ptr;
    }
}


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

int Tclreadline_Init (Tcl_Interp *interp)
{
    Tcl_CreateCommand (interp, "::tclreadline::readline", TclReadlineCmd,
	    (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);

    return (Tcl_PkgProvide (interp, "tclreadline", TCLREADLINE_VERSION));
}

char *TclReadlineInitialize (char *historyfile)
{

    using_history ();
    /*
    rl_event_hook = TclReadlineEventHook;
    */

    /*
     * 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))
        return ("unable to read history file");
    
    else
        return ("");
}

char **TclReadlineCompletion (char *text, int start, int end)
{
    char **matches = (char **) NULL;
    static char local_line[BUFSIZ];
       
    strcpy (local_line, rl_line_buffer);
    
    STRIPWHITE (local_line);
    
    /*
    fprintf (stderr, "DEBUG> TclReadlineCompletion: text=|%s|\n", text);
    fprintf (stderr, "DEBUG> TclReadlineCompletion: start=|%d|\n", start);
    fprintf (stderr, "DEBUG> TclReadlineCompletion: end=|%d|\n", end);
    */

    if (start == 0 || !strlen (local_line))
        matches = completion_matches (text, TclReadline0generator);
    else
        matches = completion_matches (text, TclReadline1generator);
    
    return (matches);
}

char *TclReadline0generator (char *text, int state)
{
    return (TclReadlineKnownCommands (text, state, _CMD_GET));
}

char *TclReadline1generator (char *text, int state)
{
    return (TclReadlineKnownCommands (text, state, _CMD_SUB_GET));
}

char *TclReadlineKnownCommands (char *text, int state, int mode)
{
    static int len;
    static cmds_t *cmds = (cmds_t *) NULL, *new;
    char *tmp, *args[256];
    int i, argc;
    char **name;
    
    switch (mode) {
        
        case _CMD_SET:

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

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

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

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

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

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

            return (char *) NULL;
            break;


        case _CMD_GET:


            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;
            break;

        case _CMD_SUB_GET:
            

            if (!state) {

                int sub;
                char *local_line = strdup (rl_line_buffer);
                
                len = strlen (local_line);
                STRIPRIGHT (local_line);

                if (len != strlen (local_line))
                    sub = TclReadlineParse (args, sizeof (args), local_line);
                else
                    sub = TclReadlineParse (args,
                                            sizeof (args), local_line) - 1;
                
                new = cmds;
                len = strlen (text);
                
                while (new && (name = new->cmd)) {
                    if (!strcmp (name[0], args[0]))
                        break;
                    new = new->next;
                }
                
                if (!new)
                    return (char *) NULL;

                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;

            }
            else
                return (char *) NULL;

            /* NOTREACHED */
            break;


        default:
            return (char *) NULL;
            break;

    }
    
    /* NOTREACHED */

}

int TclReadlineEventHook (void)
{
    Tcl_DoOneEvent (TCL_ALL_EVENTS | TCL_DONT_WAIT);
    return (TCL_OK);
}

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 ((*buf == ' ') || (*buf == '\t') || (*buf == '\n'))
            *buf++ = '\0';

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

        /* -----------------
         * Save the argument.
         * -----------------
         */
        *args++ = buf;
        nr++;

        /* ----------------------
         * Skip over the argument.
         * ----------------------
         */
        while ((*buf!='\0') && (*buf!=' ') && (*buf!='\t') && (*buf!='\n'))
            buf++;
    }

    *args = '\0';
    return nr;

}

Added tclreadlineConfig.sh.in version [627accf60a].









































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

# ==================================================================
# FILE: "/home/joze/tmp/tclreadline/tclreadlineConfig.sh.in"
# LAST MODIFIED: "Sat Oct 03 00:01:19 1998 (joze)"
# (c) 1998 by Johannes Zellner
# Johannes.Zellner@physik.uni-karlsruhe.de
# $Id$
# ==================================================================
# 
# This shell script (for sh) is generated automatically by tclreadline's
# configure script.  It will create shell variables for most of
# the configuration options discovered by the configure script.
# This script is intended to be included by the configure scripts
# for tclreadline extensions so that they don't have to figure this all
# out for themselves.  This file does not duplicate information
# already provided by tclConfig.sh, so you may need to use that
# file in addition to this one.
#
# The information in this file is specific to a single platform.

# tclreadline's version number.
TCLREADLINE_VERSION='@TCLREADLINE_VERSION@'
TCLREADLINE_MAJOR_VERSION='@TCLREADLINE_MAJOR_VERSION@'
TCLREADLINE_MINOR_VERSION='@TCLREADLINE_MINOR_VERSION@'

# The name of the tclreadline library
# (may be either a .a file or a shared library):
TCLREADLINE_LIB_FILE=@TCLREADLINE_LIB_FILE@

# String to pass to linker to pick up the tclreadline library from its
# build directory.
TCLREADLINE_BUILD_LIB_SPEC='@TCLREADLINE_BUILD_LIB_SPEC@'

# String to pass to linker to pick up the tclreadline library from its
# installed directory.
TCLREADLINE_LIB_SPEC='@TCLREADLINE_LIB_SPEC@'

# Location of the top-level source directories from which tclreadline
# was built.
TCLREADLINE_SRC_DIR='@srcdir@'

Added tclreadlineInit.tcl.in version [e886e245f9].
























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#!/usr/local/bin/tclsh
# ==================================================================
# FILE: "/home/joze/tmp/tclreadline/tclreadlineInit.tcl.in"
# LAST MODIFIED: "Sat Oct 03 02:31:48 1998 (joze)"
# (c) 1998 by Johannes Zellner
# Johannes.Zellner@physik.uni-karlsruhe.de
# $Id$
# ==================================================================

package provide tclreadline @TCLREADLINE_VERSION@

namespace eval tclreadline:: {

    proc Init {} {
        catch {load @TERMCAP_LOAD_PATH@}
        catch {load @READLINE_LOAD_PATH@}
        if {[catch {load @TCLREADLINE_LIB_FILE@} msg]} {
            puts stderr $msg
            exit 2
        }
    }

}

Added tclreadlineSetup.tcl version [ed16deb2b2].



























































































































































































































































































































































































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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#!/usr/local/bin/tclsh
# ==================================================================
# FILE: "/home/joze/tmp/tclreadline/tclreadlineSetup.tcl"
# LAST MODIFIED: "Mon Oct 05 15:15:42 1998 (joze)"
# (c) 1998 by Johannes Zellner
# Johannes.Zellner@physik.uni-karlsruhe.de
# $Id$
# ================================================================== 

package provide tclreadline 1.0

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

                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]
        }

        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 Glob Loop InitCmds InitTclCmds InitTkCmds
}

proc ::tclreadline::Setup {} {

    uplevel #0 {


        if {[info exists tk_version]} {
            set readlinePrompt "\[0;94mwish$tk_version\[0m"
        } else {
            set readlinePrompt "\[0;91mtclsh$tcl_version\[0m"
        }

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

        if {[info procs cd] == ""} {
            catch {rename ::tclreadline::Cd ""}
            rename cd ::tclreadline::Cd
            proc cd {args} {
                if {[catch {eval ::tclreadline::Cd $args} message]} {
                    puts stderr "$message"
                }
                ls
            }
        }

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

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

            proc exit {args} {

                catch {::tclreadline::readline write 
                    [::tclreadline::HistoryFileGet]}

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



        global pi
        set pi 3.1415926535897931
        set tcl_precision 17


        global env
        variable historyfile

        if {[info exists env(HOME)]} {
            set historyfile  $env(HOME)/.tclsh-history
            set env(INPUTRC) $env(HOME)/.tclsh-inputrc
        } else {
            set historyfile  .tclsh-history
        }
        set msg [::tclreadline::readline initialize $historyfile]
        if {$msg != ""} {
            puts stderr "$msg"
        }

        ::tclreadline::InitCmds
    }

    rename ::tclreadline::Setup ""
}

proc ::tclreadline::HistoryFileGet {} {
    variable historyfile
    puts stderr "::tclreadline::HistoryFileGet: entered"
    return $historyfile
}

proc ::tclreadline::Glob {string} {

    set commandstring ""
    foreach name $string {
        set replace [glob -nocomplain -- $name]
        if {$replace == ""} {
            lappend commandstring $name
        } else {
            lappend commandstring $replace
        }
    }
    return $commandstring
}



proc ::tclreadline::Loop {} {

    ::tclreadline::Setup

    uplevel #0 {
        while {1} {
            if {[catch {
                if {[info exists tk_version]} {
                    update
                }
                regsub $env(HOME) [pwd] "" prompt2
                set line [::tclreadline::readline read "$readlinePrompt \[$prompt2\]"]
                set result [eval $line]
                if {$result != ""} {
                    puts $result
                }
                set result ""
            } msg]} {
#                puts stderr $msg
            }
        }
    }
}


proc ::tclreadline::InitCmds {} {
    global tcl_version tk_version
    if {[info exists tcl_version]} {
        ::tclreadline::InitTclCmds
    }
    if {[info exists tk_version]} {
        ::tclreadline::InitTkCmds
    }
    rename tclreadline::InitCmds ""
}

proc ::tclreadline::InitTclCmds {} {
::tclreadline::readline add "after option ?arg arg ...?"
::tclreadline::readline add "append varName ?value value ...?"
::tclreadline::readline add "array option arrayName ?arg ...?"
::tclreadline::readline add "binary option ?arg arg ...?"
::tclreadline::readline add "catch command ?varName?"
::tclreadline::readline add "clock option ?arg ...?"
::tclreadline::readline add "close channelId"
::tclreadline::readline add "eof channelId"
::tclreadline::readline add "error message ?errorInfo? ?errorCode?"
::tclreadline::readline add "eval arg ?arg ...?"
::tclreadline::readline add "exec ?switches? arg ?arg ...?"
::tclreadline::readline add "expr arg ?arg ...?"
::tclreadline::readline add "fblocked channelId"
::tclreadline::readline add "fconfigure channelId ?optionName? ?value? ?optionName value?..."
::tclreadline::readline add "fcopy input output ?-size size? ?-command callback?"
::tclreadline::readline add "file option ?arg ...?"
::tclreadline::readline add "fileevent channelId event ?script?"
::tclreadline::readline add "flush channelId"
::tclreadline::readline add "for start test next command"
::tclreadline::readline add "foreach varList list ?varList list ...? command"
::tclreadline::readline add "format formatString ?arg arg ...?"
::tclreadline::readline add "gets channelId ?varName?"
::tclreadline::readline add "glob ?switches? name ?name ...?"
::tclreadline::readline add "global varName ?varName ...?"
::tclreadline::readline add "incr varName ?increment?"
::tclreadline::readline add "info option ?arg arg ...?"
::tclreadline::readline add "interp cmd ?arg ...?"
::tclreadline::readline add "join list ?joinString?"
::tclreadline::readline add "lappend varName ?value value ...?"
::tclreadline::readline add "lindex list index"
::tclreadline::readline add "linsert list index element ?element ...?"
::tclreadline::readline add "llength list"
::tclreadline::readline add "load fileName ?packageName? ?interp?"
::tclreadline::readline add "lrange list first last"
::tclreadline::readline add "lreplace list first last ?element element ...?"
::tclreadline::readline add "lsearch ?mode? list pattern"
::tclreadline::readline add "lsort ?options? list"
::tclreadline::readline add "namespace subcommand ?arg ...?"
::tclreadline::readline add "open fileName ?access? ?permissions?"
::tclreadline::readline add "package option ?arg arg ...?"
::tclreadline::readline add "proc name args body"
::tclreadline::readline add "puts ?-nonewline? ?channelId? string"
::tclreadline::readline add "read ?-nonewline? channelId"
::tclreadline::readline add "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"
::tclreadline::readline add "regsub ?switches? exp string subSpec varName"
::tclreadline::readline add "rename oldName newName"
::tclreadline::readline add "scan string format ?varName varName ...?"
::tclreadline::readline add "seek channelId offset ?origin?"
::tclreadline::readline add "set varName ?newValue?"
::tclreadline::readline add "socket ?-myaddr addr? ?-myport myport? ?-async? host port"
::tclreadline::readline add "socket -server command ?-myaddr addr? port"
::tclreadline::readline add "source fileName"
::tclreadline::readline add "split string ?splitChars?"
::tclreadline::readline add "string option arg ?arg ...?"
::tclreadline::readline add "subst ?-nobackslashes? ?-nocommands? ?-novariables? string"
::tclreadline::readline add "switch ?switches? string pattern body ... ?default body?"
::tclreadline::readline add "tell channelId"
::tclreadline::readline add "time command ?count?"
::tclreadline::readline add "trace option \[arg arg ...\]"
::tclreadline::readline add "unset varName ?varName ...?"
::tclreadline::readline add "uplevel ?level? command ?arg ...?"
::tclreadline::readline add "upvar ?level? otherVar localVar ?otherVar localVar ...?"
::tclreadline::readline add "vwait name"
::tclreadline::readline add "while test command"
rename tclreadline::InitTclCmds ""

}

proc ::tclreadline::InitTkCmds {} {
::tclreadline::readline add "bind window ?pattern? ?command?"
::tclreadline::readline add "bindtags window ?tags?"
::tclreadline::readline add "button pathName ?options?"
::tclreadline::readline add "canvas pathName ?options?"
::tclreadline::readline add "checkbutton pathName ?options?"
::tclreadline::readline add "clipboard option ?arg arg ...?"
::tclreadline::readline add "entry pathName ?options?"
::tclreadline::readline add "event option ?arg1?"
::tclreadline::readline add "font option ?arg?"
::tclreadline::readline add "frame pathName ?options?"
::tclreadline::readline add "grab option ?arg arg ...?"
::tclreadline::readline add "grid option arg ?arg ...?"
::tclreadline::readline add "image option ?args?"
::tclreadline::readline add "label pathName ?options?"
::tclreadline::readline add "listbox pathName ?options?"
::tclreadline::readline add "lower window ?belowThis?"
::tclreadline::readline add "menu pathName ?options?"
::tclreadline::readline add "menubutton pathName ?options?"
::tclreadline::readline add "message pathName ?options?"
::tclreadline::readline add "option cmd arg ?arg ...?"
::tclreadline::readline add "pack option arg ?arg ...?"
::tclreadline::readline add "radiobutton pathName ?options?"
::tclreadline::readline add "raise window ?aboveThis?"
::tclreadline::readline add "scale pathName ?options?"
::tclreadline::readline add "scrollbar pathName ?options?"
::tclreadline::readline add "selection option ?arg arg ...?"
::tclreadline::readline add "send ?options? interpName arg ?arg ...?"
::tclreadline::readline add "text pathName ?options?"
::tclreadline::readline add "tk option ?arg?"
::tclreadline::readline add "tkwait variable|visibility|window name"
::tclreadline::readline add "toplevel pathName ?options?"
::tclreadline::readline add "winfo option ?arg?"
::tclreadline::readline add "wm option window ?arg ...?"
rename tclreadline::InitTkCmds ""
}




# ***** invalid command name "Tcl"
# ***** invalid command name "bgerror"
# ***** invalid command name "contents"
# ***** invalid command name "filename"
# ***** invalid command name "http"
# ***** wrong # args: no expression after "if" argument
# ***** invalid command name "library"
# ***** 4940
# ***** invalid command name "pkgMkIndex"
# ***** /home/joze
# ***** invalid command name "registry"
# ***** invalid command name "resource"
# ***** invalid command name "safe"
# ***** wrong # args: should be either:
# ***** invalid command name "tclvars"
# ***** invalid command name ""