3 # This library is no longer being maintained, and is included for backward
4 # compatibility with Perl 4 programs which may require it.
6 # In particular, this should not be used as an example of modern Perl
7 # programming techniques.
9 # Suggested alternative: Term::Complete
11 ;# @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91
13 ;# Author: Wayne Thompson
16 ;# This routine provides word completion.
17 ;# (TAB) attempts word completion.
18 ;# (^D) prints completion list.
19 ;# (These may be changed by setting $Complete'complete, etc.)
22 ;# Bell when word completion fails.
25 ;# The tty driver is put into raw mode.
30 ;# $input = &Complete('prompt_string', *completion_list);
32 ;# $input = &Complete('prompt_string', @completion_list);
47 local($prompt, @cmp_list, $return, @match, $l, $test, $cmp, $r);
48 if ($_[1] =~ /^StB\0/) {
56 system('stty raw -echo');
58 print($prompt, $return);
59 while (($_ = getc(STDIN
)) ne "\r") {
61 # (TAB) attempt completion
63 @match = grep(/^$return/, @cmp_lst);
64 $l = length($test = shift(@match));
65 unless ($#match < 0) {
66 foreach $cmp (@match) {
67 until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
73 print($test = substr($test, $r, $l - $r));
74 $r = length($return .= $test);
78 # (^D) completion list
79 $_ eq $complete && do {
80 print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n");
96 ($_ eq $erase1 || $_ eq $erase2) && do {
115 system('stty -raw echo');