2 ;# @(#)complete.pl 1.0 (sun!waynet) 11/11/88
4 ;# Author: Wayne Thompson
7 ;# This routine provides word completion.
8 ;# (TAB) attempts word completion.
9 ;# (^D) prints completion list.
10 ;# (These may be changed by setting $Complete'complete, etc.)
13 ;# Bell when word completion fails.
16 ;# The tty driver is put into raw mode.
21 ;# $input = do Complete('prompt_string', @completion_list);
36 local ($prompt) = shift (@_);
37 local ($c, $cmp, $l, $r, $ret, $return, $test);
40 system 'stty raw -echo';
42 print $prompt, $return;
43 while (($c = getc(stdin)) ne "\r") {
44 if ($c eq "\t") { # (TAB) attempt completion
46 foreach $cmp (@_cmp_lst) {
47 push (@_match, $cmp) if $cmp =~ /^$return/;
51 unless ($#_match == 0) {
53 foreach $cmp (@_match) {
54 until (substr ($cmp, 0, $l) eq substr ($test, 0, $l)) {
60 print $test = substr ($test, $r, $l - $r);
61 $r = length ($return .= $test);
63 elsif ($c eq $complete) { # (^D) completion list
65 foreach $cmp (@_cmp_lst) {
66 print "$cmp\r\n" if $cmp =~ /^$return/;
70 elsif ($c eq $kill && $r) { # (^U) kill
77 elsif ($c eq $erase1 || $c eq $erase2) {
84 elsif ($c =~ /\S/) { # printable char
91 system 'stty -raw echo';