1
2
3
4
5
6
7
8
9
10
11
12
|
/* ==================================================================
FILE: "/diska/home/joze/src/tclreadline/tclreadline.c"
LAST MODIFICATION: "Wed Sep 8 20:53:23 1999 (joze)"
(C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
$Id$
---
tclreadline -- gnu readline for tcl
Copyright (C) 1999 Johannes Zellner
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
|
/* ==================================================================
FILE: "/home/joze/src/tclreadline/tclreadline.c"
LAST MODIFICATION: "Fri Sep 10 02:57:55 1999 (joze)"
(C) 1998, 1999 by Johannes Zellner, <johannes@zellner.org>
$Id$
---
tclreadline -- gnu readline for tcl
Copyright (C) 1999 Johannes Zellner
|
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
}
#endif
int
TclReadlineInitialize(Tcl_Interp* interp, char* historyfile)
{
rl_readline_name = "tclreadline";
rl_special_prefixes = "${\"";
/**
* default is " \t\n\"\\'`@$><=;|&{("
* removed "(" <-- arrays
* removed "{" <-- `${' variables
* added "[]"
*/
rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&[]";
rl_completer_quote_characters = "\"";
/*
rl_filename_quote_characters
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
rl_filename_quoting_function
= (CPFunction*) TclReadlineFilenameQuotingFunction;
*/
|
>
|
>
>
|
>
|
|
462
463
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
|
}
#endif
int
TclReadlineInitialize(Tcl_Interp* interp, char* historyfile)
{
rl_readline_name = "tclreadline";
// rl_special_prefixes = "${\"[";
rl_special_prefixes = "$";
/**
* default is " \t\n\"\\'`@$><=;|&{("
* removed "(" <-- arrays
* removed "{" <-- `${' variables
* removed "<" <-- completion lists with < ... >
* added "[]"
* added "}"
*/
rl_basic_word_break_characters = " \t\n\"\\@$}>=;|&[]";
// rl_basic_quote_characters = "\"{"; // XXX ??? XXX
// rl_completer_quote_characters = "\"";
/*
rl_filename_quote_characters
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
rl_filename_quoting_function
= (CPFunction*) TclReadlineFilenameQuotingFunction;
*/
|
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
return 1;
}
char**
TclReadlineCompletion(char* text, int start, int end)
{
char** matches = (char**) NULL;
rl_attempted_completion_over = 0;
#if 0
fprintf(stderr, "DEBUG> TclReadlineCompletion: text=|%s|\n", text);
fprintf(stderr, "DEBUG> TclReadlineCompletion: start=|%d|\n", start);
fprintf(stderr, "DEBUG> TclReadlineCompletion: end=|%d|\n", end);
#endif
|
>
|
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
return 1;
}
char**
TclReadlineCompletion(char* text, int start, int end)
{
char** matches = (char**) NULL;
int status;
// rl_attempted_completion_over = 0;
#if 0
fprintf(stderr, "DEBUG> TclReadlineCompletion: text=|%s|\n", text);
fprintf(stderr, "DEBUG> TclReadlineCompletion: start=|%d|\n", start);
fprintf(stderr, "DEBUG> TclReadlineCompletion: end=|%d|\n", end);
#endif
|
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
if (history_event)
#endif
if (text && ('!' == text[0]
|| (start && rl_line_buffer[start - 1] == '!' /* for '$' */))) {
char* expansion = (char*) NULL;
int oldlen = strlen(rl_line_buffer);
int status = history_expand(rl_line_buffer, &expansion);
if (status >= 1) {
rl_extend_line_buffer(strlen(expansion) + 1);
strcpy(rl_line_buffer, expansion);
rl_end = strlen(expansion);
rl_point += strlen(expansion) - oldlen;
FREE(expansion);
/* rl_redisplay(); */
|
|
|
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
if (history_event)
#endif
if (text && ('!' == text[0]
|| (start && rl_line_buffer[start - 1] == '!' /* for '$' */))) {
char* expansion = (char*) NULL;
int oldlen = strlen(rl_line_buffer);
status = history_expand(rl_line_buffer, &expansion);
if (status >= 1) {
rl_extend_line_buffer(strlen(expansion) + 1);
strcpy(rl_line_buffer, expansion);
rl_end = strlen(expansion);
rl_point += strlen(expansion) - oldlen;
FREE(expansion);
/* rl_redisplay(); */
|
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
FREE(quoted_text);
FREE(quoted_rl_line_buffer);
if (TCL_OK != tclrl_state) {
rl_callback_handler_remove();
Tcl_AppendResult (tclrl_interp, " `", tclrl_custom_completer,
" \"", quoted_text, "\" ", start_s, " ", end_s,
" \"", quoted_rl_line_buffer, "\"' failed.", (char*) NULL);
#if 0
fprintf(stderr, "\n|%s|\n", Tcl_GetStringResult(tclrl_interp));
#endif
return matches;
}
obj = Tcl_GetObjResult(tclrl_interp);
Tcl_ListObjGetElements(tclrl_interp, obj, &objc, &objv);
/* fprintf (stderr, "(TclReadlineCompletion) objc = %d\n", objc); */
if (objc) {
int i, length;
matches = (char**) MALLOC(sizeof(char*) * (objc + 1));
for (i = 0; i < objc; i++) {
matches[i] = strdup(Tcl_GetStringFromObj(objv[i], &length));
if (1 == objc && !strlen(matches[i])) {
rl_attempted_completion_over = 1;
FREE(matches[i]);
FREE(matches);
return (char**) NULL;
}
/*
fprintf (stderr, "(TclReadlineCompletion) len[%s]=%d\n",
matches[i], strlen(matches[i]));
|
>
>
>
|
<
<
|
>
>
|
|
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
|
FREE(quoted_text);
FREE(quoted_rl_line_buffer);
if (TCL_OK != tclrl_state) {
rl_callback_handler_remove();
Tcl_AppendResult (tclrl_interp, " `", tclrl_custom_completer,
" \"", quoted_text, "\" ", start_s, " ", end_s,
" \"", quoted_rl_line_buffer, "\"' failed.", (char*) NULL);
return matches;
}
#if 0
fprintf(stderr, "\nscript returned |%s|\n",
Tcl_GetStringResult(tclrl_interp));
#endif
obj = Tcl_GetObjResult(tclrl_interp);
status = Tcl_ListObjGetElements(tclrl_interp, obj, &objc, &objv);
if (TCL_OK != status)
return matches;
/* fprintf (stderr, "(TclReadlineCompletion) objc = %d\n", objc); */
if (objc) {
int i, length;
matches = (char**) MALLOC(sizeof(char*) * (objc + 1));
for (i = 0; i < objc; i++) {
matches[i] = strdup(Tcl_GetStringFromObj(objv[i], &length));
if (1 == objc && !strlen(matches[i])) {
// rl_attempted_completion_over = 1;
FREE(matches[i]);
FREE(matches);
return (char**) NULL;
}
/*
fprintf (stderr, "(TclReadlineCompletion) len[%s]=%d\n",
matches[i], strlen(matches[i]));
|