line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
;# $RCSfile: termcap.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:16 $ |
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::Cap |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
;# |
12
|
|
|
|
|
|
|
;# Usage: |
13
|
|
|
|
|
|
|
;# require 'ioctl.pl'; |
14
|
|
|
|
|
|
|
;# ioctl(TTY,$TIOCGETP,$foo); |
15
|
|
|
|
|
|
|
;# ($ispeed,$ospeed) = unpack('cc',$foo); |
16
|
|
|
|
|
|
|
;# require 'termcap.pl'; |
17
|
|
|
|
|
|
|
;# &Tgetent('vt100'); # sets $TC{'cm'}, etc. |
18
|
|
|
|
|
|
|
;# &Tputs(&Tgoto($TC{'cm'},$col,$row), 0, 'FILEHANDLE'); |
19
|
|
|
|
|
|
|
;# &Tputs($TC{'dl'},$affcnt,'FILEHANDLE'); |
20
|
|
|
|
|
|
|
;# |
21
|
1
|
|
|
1
|
|
1040
|
no warnings "ambiguous"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1226
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub Tgetent { |
24
|
0
|
|
|
0
|
|
|
local($TERM) = @_; |
25
|
0
|
|
|
|
|
|
local($TERMCAP,$_,$entry,$loop,$field); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# warn "Tgetent: no ospeed set" unless $ospeed; |
28
|
0
|
|
|
|
|
|
foreach $key (keys %TC) { |
29
|
0
|
|
|
|
|
|
delete $TC{$key}; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
0
|
|
|
|
|
$TERM = $ENV{'TERM'} unless $TERM; |
32
|
0
|
|
|
|
|
|
$TERM =~ s/(\W)/\\$1/g; |
33
|
0
|
|
|
|
|
|
$TERMCAP = $ENV{'TERMCAP'}; |
34
|
0
|
0
|
|
|
|
|
$TERMCAP = '/etc/termcap' unless $TERMCAP; |
35
|
0
|
0
|
|
|
|
|
if ($TERMCAP !~ m:^/:) { |
36
|
0
|
0
|
|
|
|
|
if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) { |
37
|
0
|
|
|
|
|
|
$TERMCAP = '/etc/termcap'; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
0
|
0
|
|
|
|
|
if ($TERMCAP =~ m:^/:) { |
41
|
0
|
|
|
|
|
|
$entry = ''; |
42
|
0
|
|
0
|
|
|
|
do { |
43
|
0
|
|
|
|
|
|
$loop = " |
44
|
|
|
|
|
|
|
open(TERMCAP,'<$TERMCAP') || die \"Can't open $TERMCAP\"; |
45
|
|
|
|
|
|
|
while () { |
46
|
|
|
|
|
|
|
next if /^#/; |
47
|
|
|
|
|
|
|
next if /^\t/; |
48
|
|
|
|
|
|
|
if (/(^|\\|)${TERM}[:\\|]/) { |
49
|
|
|
|
|
|
|
chop; |
50
|
|
|
|
|
|
|
while (chop eq '\\\\') { |
51
|
|
|
|
|
|
|
\$_ .= ; |
52
|
|
|
|
|
|
|
chop; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
\$_ .= ':'; |
55
|
|
|
|
|
|
|
last; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
close TERMCAP; |
59
|
|
|
|
|
|
|
\$entry .= \$_; |
60
|
|
|
|
|
|
|
"; |
61
|
0
|
|
|
|
|
|
eval $loop; |
62
|
|
|
|
|
|
|
} while s/:tc=([^:]+):/:/ && ($TERM = $1); |
63
|
0
|
|
|
|
|
|
$TERMCAP = $entry; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
foreach $field (split(/:[\s:\\]*/,$TERMCAP)) { |
67
|
0
|
0
|
|
|
|
|
if ($field =~ /^\w\w$/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$TC{$field} = 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif ($field =~ /^(\w\w)#(.*)/) { |
71
|
0
|
0
|
|
|
|
|
$TC{$1} = $2 if $TC{$1} eq ''; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
elsif ($field =~ /^(\w\w)=(.*)/) { |
74
|
0
|
|
|
|
|
|
$entry = $1; |
75
|
0
|
|
|
|
|
|
$_ = $2; |
76
|
0
|
|
|
|
|
|
s/\\E/\033/g; |
77
|
0
|
|
|
|
|
|
s/\\(200)/pack('c',0)/eg; # NUL character |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
s/\\(0\d\d)/pack('c',oct($1))/eg; # octal |
|
0
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
s/\\(0x[0-9A-Fa-f][0-9A-Fa-f])/pack('c',hex($1))/eg; # hex |
|
0
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
s/\\(\d\d\d)/pack('c',$1 & 0177)/eg; |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
s/\\n/\n/g; |
82
|
0
|
|
|
|
|
|
s/\\r/\r/g; |
83
|
0
|
|
|
|
|
|
s/\\t/\t/g; |
84
|
0
|
|
|
|
|
|
s/\\b/\b/g; |
85
|
0
|
|
|
|
|
|
s/\\f/\f/g; |
86
|
0
|
|
|
|
|
|
s/\\\^/\377/g; |
87
|
0
|
|
|
|
|
|
s/\^\?/\177/g; |
88
|
0
|
|
|
|
|
|
s/\^(.)/pack('c',ord($1) & 31)/eg; |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
s/\\(.)/$1/g; |
90
|
0
|
|
|
|
|
|
s/\377/^/g; |
91
|
0
|
0
|
|
|
|
|
$TC{$entry} = $_ if $TC{$entry} eq ''; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
0
|
0
|
|
|
|
|
$TC{'pc'} = "\0" if $TC{'pc'} eq ''; |
95
|
0
|
0
|
|
|
|
|
$TC{'bc'} = "\b" if $TC{'bc'} eq ''; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
@Tputs = (0,200,133.3,90.9,74.3,66.7,50,33.3,16.7,8.3,5.5,4.1,2,1,.5,.2); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub Tputs { |
101
|
0
|
|
|
0
|
|
|
local($string,$affcnt,$FH) = @_; |
102
|
0
|
|
|
|
|
|
local($ms); |
103
|
0
|
0
|
|
|
|
|
if ($string =~ /(^[\d.]+)(\*?)(.*)$/) { |
104
|
0
|
|
|
|
|
|
$ms = $1; |
105
|
0
|
0
|
|
|
|
|
$ms *= $affcnt if $2; |
106
|
0
|
|
|
|
|
|
$string = $3; |
107
|
0
|
|
|
|
|
|
$decr = $Tputs[$ospeed]; |
108
|
0
|
0
|
|
|
|
|
if ($decr > .1) { |
109
|
0
|
|
|
|
|
|
$ms += $decr / 2; |
110
|
0
|
|
|
|
|
|
$string .= $TC{'pc'} x ($ms / $decr); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
0
|
0
|
|
|
|
|
print $FH $string if $FH; |
114
|
0
|
|
|
|
|
|
$string; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub Tgoto { |
118
|
0
|
|
|
0
|
|
|
local($string) = shift(@_); |
119
|
0
|
|
|
|
|
|
local($result) = ''; |
120
|
0
|
|
|
|
|
|
local($after) = ''; |
121
|
0
|
|
|
|
|
|
local($code,$tmp) = @_; |
122
|
0
|
|
|
|
|
|
local(@tmp); |
123
|
0
|
|
|
|
|
|
@tmp = ($tmp,$code); |
124
|
0
|
|
|
|
|
|
local($online) = 0; |
125
|
0
|
|
|
|
|
|
while ($string =~ /^([^%]*)%(.)(.*)/) { |
126
|
0
|
|
|
|
|
|
$result .= $1; |
127
|
0
|
|
|
|
|
|
$code = $2; |
128
|
0
|
|
|
|
|
|
$string = $3; |
129
|
0
|
0
|
|
|
|
|
if ($code eq 'd') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$result .= sprintf("%d",shift(@tmp)); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
elsif ($code eq '.') { |
133
|
0
|
|
|
|
|
|
$tmp = shift(@tmp); |
134
|
0
|
0
|
0
|
|
|
|
if ($tmp == 0 || $tmp == 4 || $tmp == 10) { |
|
|
|
0
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if ($online) { |
136
|
0
|
0
|
|
|
|
|
++$tmp, $after .= $TC{'up'} if $TC{'up'}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
0
|
|
|
|
|
|
++$tmp, $after .= $TC{'bc'}; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
0
|
|
|
|
|
|
$result .= sprintf("%c",$tmp); |
143
|
0
|
|
|
|
|
|
$online = !$online; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
elsif ($code eq '+') { |
146
|
0
|
|
|
|
|
|
$result .= sprintf("%c",shift(@tmp)+ord($string)); |
147
|
0
|
|
|
|
|
|
$string = substr($string,1,99); |
148
|
0
|
|
|
|
|
|
$online = !$online; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
elsif ($code eq 'r') { |
151
|
0
|
|
|
|
|
|
($code,$tmp) = @tmp; |
152
|
0
|
|
|
|
|
|
@tmp = ($tmp,$code); |
153
|
0
|
|
|
|
|
|
$online = !$online; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
elsif ($code eq '>') { |
156
|
0
|
|
|
|
|
|
($code,$tmp,$string) = unpack("CCa99",$string); |
157
|
0
|
0
|
|
|
|
|
if ($tmp[0] > $code) { |
158
|
0
|
|
|
|
|
|
$tmp[0] += $tmp; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
elsif ($code eq '2') { |
162
|
0
|
|
|
|
|
|
$result .= sprintf("%02d",shift(@tmp)); |
163
|
0
|
|
|
|
|
|
$online = !$online; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
elsif ($code eq '3') { |
166
|
0
|
|
|
|
|
|
$result .= sprintf("%03d",shift(@tmp)); |
167
|
0
|
|
|
|
|
|
$online = !$online; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
elsif ($code eq 'i') { |
170
|
0
|
|
|
|
|
|
($code,$tmp) = @tmp; |
171
|
0
|
|
|
|
|
|
@tmp = ($code+1,$tmp+1); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
else { |
174
|
0
|
|
|
|
|
|
return "OOPS"; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
0
|
|
|
|
|
|
$result . $string . $after; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |