4 # Copyright (C) 2009 Edwin Groothuis. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 Usage: $0 -c <term1> <term2>
36 Compares the entries in the termcap.src for <term1> and <term2> and
37 print the keys and definitions on the screen. This can be used to reduce
38 the size of two similar termcap entries with the "tc" option.
41 Show all lengths or the ones for terminals matching [term]
44 Print all information about <term>
47 Print all relations from and to <term>
52 my $command = $ARGV[0];
56 open(FIN, "termcap.src");
64 foreach my $l (@lines) {
69 next if ($l =~ /\\$/);
73 my @a = split(/:/, $tc);
75 my @b = split(/\|/, $a[0]);
81 if (length($tc) - length($a[0]) > 1023) {
82 print "$a[0] has a length of ", length($tc) - length($a[0]), "\n";
93 for my $tcs (keys(%tcs)) {
96 foreach my $tc (split(/:/, $tcs{$tcs})) {
98 foreach my $ref (split(/\|/, $tc)) {
103 next if ($tc =~ /^\\/);
104 $tc{$tcs}{$tc} = 0 if (!defined $tc{$tcs}{$tc});
106 $len{$tcs} += length($tc) + 1;
111 $tca = $refs{$tca} if (defined $tca && defined $refs{$tca});
112 $tcb = $refs{$tcb} if (defined $tcb && defined $refs{$tca});
114 die "Cannot find definitions for $tca" if (defined $tca && !defined $tcs{$tca});
115 die "Cannot find definitions for $tcb" if (defined $tcb && !defined $tcs{$tcb});
117 if ($command eq "-c") {
118 foreach my $key (sort(keys(%keys))) {
119 next if (!defined $tc{$tca}{$key} && !defined $tc{$tcb}{$key});
120 printf("%-3s %-3s %s\n",
121 defined $tc{$tca}{$key} ? "+" : "",
122 defined $tc{$tcb}{$key} ? "+" : "",
127 print "$len{$tca} - $len{$tcb}\n";
130 if ($command eq "-l") {
131 foreach my $tcs (sort(keys(%tcs))) {
132 next if (defined $tca && $tcs !~ /$tca/);
133 printf("%4d %s\n", $len{$tcs}, $tcs);
137 if ($command eq "-p") {
138 printf("%s (%d bytes)\n", $tca, $len{$tca});
139 foreach my $key (sort(keys(%keys))) {
140 next if (!defined $tc{$tca}{$key});
141 printf("%s\n", $key);
145 if ($command eq "-r") {
146 foreach my $key (keys(%{$tc{$tca}})) {
147 next if ($key !~ /^tc=/);
149 print "Links to:\t$key\n";
152 foreach my $ref (sort(keys(%refs))) {
153 next if ($refs{$ref} ne $tca);
154 foreach my $tc (sort(keys(%tcs))) {
155 if (defined $tc{$tc}{"tc=$ref"}) {
157 print "Links from:\t";
161 print "$ref -> $tc\n";