2 ;# @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91
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 = &Complete('prompt_string', *completion_list);
23 ;# $input = &Complete('prompt_string', @completion_list);
38 local($prompt, @cmp_list, $return, @match, $l, $test, $cmp, $r);
39 if ($_[1] =~ /^StB\0/) {
47 system('stty raw -echo');
49 print($prompt, $return);
50 while (($_ = getc(STDIN)) ne "\r") {
52 # (TAB) attempt completion
54 @match = grep(/^$return/, @cmp_lst);
55 $l = length($test = shift(@match));
56 unless ($#match < 0) {
57 foreach $cmp (@match) {
58 until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
64 print($test = substr($test, $r, $l - $r));
65 $r = length($return .= $test);
69 # (^D) completion list
70 $_ eq $complete && do {
71 print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n");
87 ($_ eq $erase1 || $_ eq $erase2) && do {
106 system('stty -raw echo');