Diff
Not logged in

Differences From Artifact [83b24cf018]:

To Artifact [73a4a8f6a3]:


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


+
-
-
-
+
+
+
-




















-
-
+
+







+








+
-
-
-
+
+
+
+



-
-
-
+
+
+








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

    FILE: "/home/joze/src/tclreadline/tclreadline.c"
    LAST MODIFIED: "Sun Feb 28 15:01:31 1999 (joze)"
    (C) 1998, 1999 by Johannes Zellner
    FILE: "/krispc6/home/joze/src/tclreadline/tclreadline.c"
    LAST MODIFICATION: "Sat May  8 16:20:59 1999 (joze)"
    (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
    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
    <johannes@zellner.org>, http://www.zellner.org/tclreadline/

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


#include <tcl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define READLINE_LIBRARY
#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)

enum {
#define _CMD_SET	(1 << 0)
#define _CMD_GET	(1 << 1)
#define _CMD_SUB_GET	(1 << 2)
    _CMD_SET     = (1 << 0),
    _CMD_GET     = (1 << 1),
    _CMD_SUB_GET = (1 << 2)
};


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


#define STRIPLEFT(ptr)          \
do {                            \
    char *tmp = ptr;            \
    while (*tmp && *tmp <= ' ') \
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
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







-
-
-



-
+

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







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





/*
 * forward declarations.
 */
int	TclReadlineCmd	(ClientData clientData, Tcl_Interp *interp,
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);
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;


/*
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
122
123
124
125
126
127
128

129
130
131
132
133
134
135







-







	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;
        
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
225
226
227
228
229
230
231

232
233

234
235
236
237
238
239
240







-


-







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";
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
413
414
415
416
417
418
419




420
421
422




423
424
425
426
427
428
429
430







-
-
-
-



-
-
-
-








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

}