line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
;# |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This library is no longer being maintained, and is included for backward |
4
|
|
|
|
|
|
|
# compatibility with Perl 4 programs which may require it. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# In particular, this should not be used as an example of modern Perl |
7
|
|
|
|
|
|
|
# programming techniques. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# Suggested alternative: Term::Complete |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
;# @(#)complete.pl,v1.1 (me@anywhere.EBay.Sun.COM) 09/23/91 |
12
|
|
|
|
|
|
|
;# |
13
|
|
|
|
|
|
|
;# Author: Wayne Thompson |
14
|
|
|
|
|
|
|
;# |
15
|
|
|
|
|
|
|
;# Description: |
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.) |
20
|
|
|
|
|
|
|
;# |
21
|
|
|
|
|
|
|
;# Diagnostics: |
22
|
|
|
|
|
|
|
;# Bell when word completion fails. |
23
|
|
|
|
|
|
|
;# |
24
|
|
|
|
|
|
|
;# Dependencies: |
25
|
|
|
|
|
|
|
;# The tty driver is put into raw mode. |
26
|
|
|
|
|
|
|
;# |
27
|
|
|
|
|
|
|
;# Bugs: |
28
|
|
|
|
|
|
|
;# |
29
|
|
|
|
|
|
|
;# Usage: |
30
|
|
|
|
|
|
|
;# $input = &Complete('prompt_string', *completion_list); |
31
|
|
|
|
|
|
|
;# or |
32
|
|
|
|
|
|
|
;# $input = &Complete('prompt_string', @completion_list); |
33
|
|
|
|
|
|
|
;# |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
CONFIG: { |
36
|
|
|
|
|
|
|
package Complete; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$complete = "\004"; |
39
|
|
|
|
|
|
|
$kill = "\025"; |
40
|
|
|
|
|
|
|
$erase1 = "\177"; |
41
|
|
|
|
|
|
|
$erase2 = "\010"; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub Complete { |
45
|
|
|
|
|
|
|
package Complete; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
|
|
local($prompt, @cmp_list, $return, @match, $l, $test, $cmp, $r); |
48
|
0
|
0
|
|
|
|
|
if ($_[1] =~ /^StB\0/) { |
49
|
0
|
|
|
|
|
|
($prompt, *_) = @_; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
0
|
|
|
|
|
|
$prompt = shift(@_); |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
@cmp_lst = sort(@_); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
system('stty raw -echo'); |
57
|
|
|
|
|
|
|
LOOP: { |
58
|
0
|
|
|
|
|
|
print($prompt, $return); |
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
while (($_ = getc(STDIN)) ne "\r") { |
60
|
|
|
|
|
|
|
CASE: { |
61
|
|
|
|
|
|
|
# (TAB) attempt completion |
62
|
0
|
0
|
|
|
|
|
$_ eq "\t" && do { |
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
@match = grep(/^$return/, @cmp_lst); |
64
|
0
|
|
|
|
|
|
$l = length($test = shift(@match)); |
65
|
0
|
0
|
|
|
|
|
unless ($#match < 0) { |
66
|
0
|
|
|
|
|
|
foreach $cmp (@match) { |
67
|
0
|
|
|
|
|
|
until (substr($cmp, 0, $l) eq substr($test, 0, $l)) { |
68
|
0
|
|
|
|
|
|
$l--; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
print("\a"); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
print($test = substr($test, $r, $l - $r)); |
74
|
0
|
|
|
|
|
|
$r = length($return .= $test); |
75
|
0
|
|
|
|
|
|
last CASE; |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# (^D) completion list |
79
|
0
|
0
|
|
|
|
|
$_ eq $complete && do { |
80
|
0
|
|
|
|
|
|
print(join("\r\n", '', grep(/^$return/, @cmp_lst)), "\r\n"); |
81
|
0
|
|
|
|
|
|
redo LOOP; |
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# (^U) kill |
85
|
0
|
0
|
|
|
|
|
$_ eq $kill && do { |
86
|
0
|
0
|
|
|
|
|
if ($r) { |
87
|
0
|
|
|
|
|
|
undef $r; |
88
|
0
|
|
|
|
|
|
undef $return; |
89
|
0
|
|
|
|
|
|
print("\r\n"); |
90
|
0
|
|
|
|
|
|
redo LOOP; |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
last CASE; |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# (DEL) || (BS) erase |
96
|
0
|
0
|
0
|
|
|
|
($_ eq $erase1 || $_ eq $erase2) && do { |
97
|
0
|
0
|
|
|
|
|
if($r) { |
98
|
0
|
|
|
|
|
|
print("\b \b"); |
99
|
0
|
|
|
|
|
|
chop($return); |
100
|
0
|
|
|
|
|
|
$r--; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
last CASE; |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# printable char |
106
|
0
|
0
|
|
|
|
|
ord >= 32 && do { |
107
|
0
|
|
|
|
|
|
$return .= $_; |
108
|
0
|
|
|
|
|
|
$r++; |
109
|
0
|
|
|
|
|
|
print; |
110
|
0
|
|
|
|
|
|
last CASE; |
111
|
|
|
|
|
|
|
}; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
system('stty -raw echo'); |
116
|
0
|
|
|
|
|
|
print("\n"); |
117
|
0
|
|
|
|
|
|
$return; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |