Diff
Not logged in

Differences From Artifact [75bdea63cb]:

To Artifact [83b24cf018]:


1
2
3
4
5
6
7






























8
9
10
11
12
13
14


15
16
17
18
19
20
21







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







+
+







/* 
 * 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$
 */

 /* ==================================================================
    FILE: "/home/joze/src/tclreadline/tclreadline.c"
    LAST MODIFIED: "Sun Feb 28 15:01:31 1999 (joze)"
    (C) 1998, 1999 by Johannes Zellner
    Johannes.Zellner@physik.uni-karlsruhe.de
    $Id$
    ---

    tclreadline -- gnu readline for tcl
    Copyright (C) 1999  Johannes Zellner

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    Johannes.Zellner@physik.uni-karlsruhe.de
    http://krisal.physik.uni-karlsruhe.de/~joze
    ================================================================== */  


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

#include <tclreadline.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)
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
73
74
75
76
77
78
79



80
81
82
83
84
85
86







-
-
-







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);
74
75
76
77
78
79
80






81
82
83
84
85
86
87
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115







+
+
+
+
+
+







int	TclReadlineEventHook	(void);
int	TclReadlineParse	(char **args, int maxargs, char *buf);


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


/*
 * Script to set the tclreadline library path in the
 * variable global "tclreadline_library"
 */



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                         */
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
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







+
+
+
+
+
+
+
+










-
+







    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 if (c == 'c'  && strncmp (argv[1], "complete", length) == 0) {
        if (argc != 3)
            goto BAD_COMMAND;
        else if (Tcl_CommandComplete (argv[2]))
            Tcl_AppendResult (interp, "1", (char *) NULL);
        else
            Tcl_AppendResult (interp, "0", (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;
    return (TCL_ERROR);

}

void TclReadlineDataAvailableHandler (ClientData clientData, int mask)
{
    if (mask & TCL_READABLE)
        rl_callback_read_char ();
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
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







+









+

-
-
-







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

    rl_readline_name = "tclreadline";
    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;