Diff
Not logged in

Differences From Artifact [8df3bd02ad]:

To Artifact [fb738417f9]:


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

#ifdef EXECUTING_MACRO_HACK
/**
 * this prototype is 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* _rl_executing_macro;
#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;








|







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

#ifdef EXECUTING_MACRO_HACK
/**
 * this prototype is 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;

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

    switch (obj_idx) {

	case TCLRL_READ:

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

	    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;

	    while (!TclReadlineLineComplete()) {
#ifdef EXECUTING_MACRO_HACK
		/**
		 * check first, if more characters are
		 * available from _rl_executing_macro,
		 * because Tcl_DoOneEvent() will (naturally)
		 * not detect this `event'.
		 */
		if (_rl_executing_macro)
		    TclReadlineReadHandler((ClientData) NULL, TCL_READABLE);
		else
#endif
		    Tcl_DoOneEvent(TCL_ALL_EVENTS);
	    }

	    Tcl_DeleteFileHandler(0);







|














|






|







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

    switch (obj_idx) {

	case TCLRL_READ:

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

	    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;

	    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
#endif
		    Tcl_DoOneEvent(TCL_ALL_EVENTS);
	    }

	    Tcl_DeleteFileHandler(0);
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

}

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

static void
TclReadlineLineCompleteHandler(char* ptr)
{







|



|





|







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

}

static void
TclReadlineReadHandler(ClientData clientData, int mask)
{
    if (mask & TCL_READABLE) {
#ifdef EXECUTING_MACRO_NAME
	do {
#endif
	    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());
#endif
    }
}

static void
TclReadlineLineCompleteHandler(char* ptr)
{
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
	 * The calling script is responsible for handling
	 * empty strings.
	 */

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

	if (status >= 1) {
	    /* TODO: make this a valid tcl output */
	    printf("%s\n", expansion);



	} else if (-1 == status) {
	    Tcl_AppendResult
	    (tclrl_interp, "error in history expansion\n", (char*) NULL);
	    TclReadlineTerminate(TCL_ERROR);
	}
	/**


	 * TODO: status == 2 ...
	 */

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


#ifdef EXECUTING_MACRO_HACK
	/**
	 * don't stuff macro lines
	 * into readline's history.
	 */
	if(!_rl_executing_macro) {
#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_HACK
	}
#endif
	/**
	 * tell the calling routines to terminate.
	 */
	TclReadlineTerminate(LINE_COMPLETE);
	FREE(ptr);







|


>
>
>
|

|

<
<
>
>
|
<
|
|
|
>
|




|














|







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
	 * The calling script is responsible for handling
	 * empty strings.
	 */

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

#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);
695
696
697
698
699
700
701
702
703
704
705
706
707
708


709
710




711
712
713
714
715
716
717
	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);
	FREE(quoted_text);
	FREE(quoted_rl_line_buffer);
	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);


	    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;







<
<





>
>


>
>
>
>







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
	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);
	quoted_rl_line_buffer = NULL;
	obj = Tcl_GetObjResult(tclrl_interp);
	status = Tcl_ListObjGetElements(tclrl_interp, obj, &objc, &objv);
	if (TCL_OK != status)
	    return matches;

	if (objc) {
	    int i, length;