Diff
Not logged in

Differences From Artifact [3dffb52a3c]:

To Artifact [26244269ef]:


1
2
3
4
5
6
7
8
9
10
11
12
..
32
33
34
35
36
37
38






39
40
41
42
43
44
45
..
61
62
63
64
65
66
67

68

69
70
71
72
73
74
75
...
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
...
304
305
306
307
308
309
310












311
312
313
314
315
316
317





318
















319
320
321
322
323
324
325

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

    FILE: "/home/joze/src/tclreadline/tclreadline.c"
    LAST MODIFICATION: "Tue Aug 31 03:22:55 1999 (joze)"
    (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
    $Id$
    ---

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

................................................................................
#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); ptr = 0; }

enum {
    _CMD_SET     = (1 << 0),
................................................................................
 */
char* stripleft(char* in);
char* stripright(char* in);
char* stripwhite(char* in);
char* TclReadlineQuote(char* text, char* quotechars);
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 *TclReadlineFilenameQuotingFunction(
    char *text, int match_type, char* quote_ptr);
int TclReadlineInitialize(Tcl_Interp* interp, char* historyfile);
int blank_line(char* str);
................................................................................
    length = strlen(argv[1]);

    if (c == 'r'  && strncmp(argv[1], "read", length) == 0) {
        
        char* expansion = (char*) NULL;
        int status;
        

        tclrl_line_complete = LINE_PENDING;
        tclrl_state = TCL_OK;
        rl_callback_handler_install(argc == 3 ? argv[2] : "%",
                TclReadlineLineCompleteHandler);

        Tcl_CreateFileHandler(0, TCL_READABLE,
                TclReadlineDataAvailableHandler, (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
         */
        while (LINE_PENDING == tclrl_line_complete
            && TCL_OK == tclrl_state && !rl_done) {
            Tcl_DoOneEvent(0);
            /*


            rl_inhibit_completion = 0;
            */
        }
        Tcl_DeleteFileHandler(0);

        if (TCL_OK != tclrl_state)
            return tclrl_state; /* !! */

	if ((LINE_EOF == tclrl_line_complete) && tclrl_eof_string) {
	    Tcl_Eval(interp, tclrl_eof_string);
            return tclrl_state;
	}





        status = history_expand(tclrl_line, &expansion);
        if (status >= 1) {
#if 0
            Tcl_Channel channel = Tcl_MakeFileChannel(stdout, TCL_WRITABLE);
            /* Tcl_RegisterChannel(interp, channel); */
            (void) Tcl_WriteChars(channel, expansion, -1);
................................................................................
    Tcl_AppendResult(interp,
        "wrong # args: should be \"readline option ?arg ...?\"",
        (char*) NULL);
    return TCL_ERROR;

}













void
TclReadlineDataAvailableHandler(ClientData clientData, int mask)
{
#if 0
    fprintf(stderr, "(TclReadlineDataAvailableHandler) mask = %d\n",  mask);
#endif
    if (mask & TCL_READABLE) {





        rl_callback_read_char();
















    }
}

void
TclReadlineLineCompleteHandler(char* ptr)
{
#if 1



|
|







 







>
>
>
>
>
>







 







>
|
>







 







>






|
>
>
>
>










|

>
>












>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>

|


|


>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
..
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
...
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
...
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

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

    FILE: "/diska/home/joze/src/tclreadline/tclreadline.c"
    LAST MODIFICATION: "Wed Sep  1 18:58:04 1999 (joze)"
    (C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
    $Id$
    ---

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

................................................................................
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define READLINE_LIBRARY
#include <readline.h>
#include <history.h>

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

#include "tclreadline.h"

#define MALLOC(size) Tcl_Alloc((int) size)
#define FREE(ptr) if (ptr) { Tcl_Free((char*) ptr); ptr = 0; }

enum {
    _CMD_SET     = (1 << 0),
................................................................................
 */
char* stripleft(char* in);
char* stripright(char* in);
char* stripwhite(char* in);
char* TclReadlineQuote(char* text, char* quotechars);
int TclReadlineCmd(ClientData clientData, Tcl_Interp* interp,
    int argc, char** argv);
int TclReadlineEventHook(void);
void TclReadlineReadHandler(ClientData clientData, int mask);
void TclReadlineWriteHandler(ClientData clientData, int mask);
void TclReadlineLineCompleteHandler(char* ptr);
int Tclreadline_SafeInit(Tcl_Interp* interp);
int Tclreadline_Init(Tcl_Interp* interp);
char *TclReadlineFilenameQuotingFunction(
    char *text, int match_type, char* quote_ptr);
int TclReadlineInitialize(Tcl_Interp* interp, char* historyfile);
int blank_line(char* str);
................................................................................
    length = strlen(argv[1]);

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

        Tcl_CreateFileHandler(0, TCL_READABLE,
                TclReadlineReadHandler, (ClientData) NULL);
        /*
        Tcl_CreateFileHandler(1, TCL_WRITABLE,
                TclReadlineWriteHandler, (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
         */
        while (LINE_PENDING == tclrl_line_complete
            && TCL_OK == tclrl_state && !rl_done) {
            Tcl_DoOneEvent(TCL_ALL_EVENTS);
            /*
            Tcl_DoOneEvent(0);
            fprintf (stderr, "(TclReadlineCmd) \n");
            rl_inhibit_completion = 0;
            */
        }
        Tcl_DeleteFileHandler(0);

        if (TCL_OK != tclrl_state)
            return tclrl_state; /* !! */

	if ((LINE_EOF == tclrl_line_complete) && tclrl_eof_string) {
	    Tcl_Eval(interp, tclrl_eof_string);
            return tclrl_state;
	}
#else
        rl_event_hook = TclReadlineEventHook;
        tclrl_line = readline(argc == 3 ? argv[2] : "%");
#endif

        status = history_expand(tclrl_line, &expansion);
        if (status >= 1) {
#if 0
            Tcl_Channel channel = Tcl_MakeFileChannel(stdout, TCL_WRITABLE);
            /* Tcl_RegisterChannel(interp, channel); */
            (void) Tcl_WriteChars(channel, expansion, -1);
................................................................................
    Tcl_AppendResult(interp,
        "wrong # args: should be \"readline option ?arg ...?\"",
        (char*) NULL);
    return TCL_ERROR;

}

int TclReadlineEventHook(void)
{
    Tcl_DoOneEvent(TCL_ALL_EVENTS | TCL_DONT_WAIT);
    /*
        TCL_DONT_WAIT
        TCL_WINDOW_EVENTS
        TCL_FILE_EVENTS
        TCL_TIMER_EVENTS
        TCL_IDLE_EVENTS
        TCL_ALL_EVENTS
    */
}
void
TclReadlineReadHandler(ClientData clientData, int mask)
{
#if 0
    fprintf(stderr, "(TclReadlineReadHandler) mask = %d\n",  mask);
#endif
    if (mask & TCL_READABLE) {
        /*
        fprintf(stderr, "(TclReadlineReadHandler) mask = readable\n");
        rl_event_hook = TclReadlineEventHook;
        while (!rl_done) {
        */
            rl_callback_read_char();
        /*
        }
        fflush(stdin);
        */
    }
}

void
TclReadlineWriteHandler(ClientData clientData, int mask)
{
    if (mask & TCL_WRITABLE) {
        /*
        fprintf(stderr, "(TclReadlineReadHandler) mask = writable\n");
        */
        fflush(stdout);
        rl_redisplay();
    }
}

void
TclReadlineLineCompleteHandler(char* ptr)
{
#if 1