;# @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91
;# Author: Wayne Thompson
;# This routine provides word completion.
;# (TAB) attempts word completion.
;# (^D) prints completion list.
;# (These may be changed by setting $Complete'complete, etc.)
;# Bell when word completion fails.
;# The tty driver is put into raw mode.
;# $input = &Complete('prompt_string', *completion_list);
;# $input = &Complete('prompt_string', @completion_list);
system('stty raw -echo');
while (($_ = getc(STDIN
)) ne "\r") {
# (TAB) attempt completion
@match = grep(/^$return/, @cmp_lst);
$l = length($test = shift(@match));
until (substr($cmp, 0, $l) eq substr($test, 0, $l)) {
print($test = substr($test, $r, $l - $r));
$r = length($return .= $test);
print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n");
($_ eq $erase1 || $_ eq $erase2) && do {
system('stty -raw echo');