1 | #!/usr/local/bin/perl |
---|
2 | # |
---|
3 | # Create encoding vectors from the `*.txt' encoding files. |
---|
4 | # Copyright (c) 1995-1998 Markku Rossi |
---|
5 | # |
---|
6 | # Author: Markku Rossi <mtr@iki.fi> |
---|
7 | # |
---|
8 | |
---|
9 | # |
---|
10 | # This file is part of GNU enscript. |
---|
11 | # |
---|
12 | # This program is free software; you can redistribute it and/or modify |
---|
13 | # it under the terms of the GNU General Public License as published by |
---|
14 | # the Free Software Foundation; either version 2, or (at your option) |
---|
15 | # any later version. |
---|
16 | # |
---|
17 | # This program is distributed in the hope that it will be useful, |
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | # GNU General Public License for more details. |
---|
21 | # |
---|
22 | # You should have received a copy of the GNU General Public License |
---|
23 | # along with this program; see the file COPYING. If not, write to |
---|
24 | # the Free Software Foundation, 59 Temple Place - Suite 330, |
---|
25 | # Boston, MA 02111-1307, USA. |
---|
26 | # |
---|
27 | |
---|
28 | # |
---|
29 | # Handle arguments |
---|
30 | # |
---|
31 | |
---|
32 | if (@ARGV != 1) { |
---|
33 | print "usage: $0 encfile\n"; |
---|
34 | exit(1); |
---|
35 | } |
---|
36 | |
---|
37 | $file = shift(@ARGV); |
---|
38 | |
---|
39 | open(FP, $file) || die "couldn't open input file `$file': $!\n"; |
---|
40 | |
---|
41 | # Find the start of the table. |
---|
42 | $found = 0; |
---|
43 | while (<FP>) { |
---|
44 | if ($_ =~ /^-+$/) { |
---|
45 | $found = 1; |
---|
46 | last; |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | if (!$found) { |
---|
51 | die "file `$file' is not a valid encoding file: couldn't find table\n"; |
---|
52 | } |
---|
53 | |
---|
54 | $file =~ s/\.txt$//g; |
---|
55 | $file =~ s/.*\///g; |
---|
56 | |
---|
57 | # Print header. |
---|
58 | |
---|
59 | print <<"EOF"; |
---|
60 | % |
---|
61 | % $file encoding vector. |
---|
62 | % |
---|
63 | % This file is automatically generated from file \`$file.txt\'. If you |
---|
64 | % have any corrections to this file, please, edit file \`$file.txt\' instead. |
---|
65 | % |
---|
66 | |
---|
67 | % |
---|
68 | % This file is part of GNU enscript. |
---|
69 | % |
---|
70 | % This program is free software; you can redistribute it and/or modify |
---|
71 | % it under the terms of the GNU General Public License as published by |
---|
72 | % the Free Software Foundation; either version 2, or (at your option) |
---|
73 | % any later version. |
---|
74 | % |
---|
75 | % This program is distributed in the hope that it will be useful, |
---|
76 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
77 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
78 | % GNU General Public License for more details. |
---|
79 | % |
---|
80 | % You should have received a copy of the GNU General Public License |
---|
81 | % along with this program; see the file COPYING. If not, write to |
---|
82 | % the Free Software Foundation, 59 Temple Place - Suite 330, |
---|
83 | % Boston, MA 02111-1307, USA. |
---|
84 | % |
---|
85 | |
---|
86 | % -- code follows this line -- |
---|
87 | /encoding_vector [ |
---|
88 | EOF |
---|
89 | |
---|
90 | $inum = 0; |
---|
91 | $names_per_row = 4; |
---|
92 | sub print_item { |
---|
93 | ($name) = @_; |
---|
94 | |
---|
95 | printf("%-14s\t", $name); |
---|
96 | if ((++$inum % $names_per_row) == 0) { |
---|
97 | printf("\n"); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | # Process file. |
---|
102 | while (<FP>) { |
---|
103 | @cols = split; |
---|
104 | if ($_ =~ /^\s*$/) { |
---|
105 | next; |
---|
106 | } elsif ($_ =~ /non-printable/) { |
---|
107 | $fields{hex(@cols[1])} = "/.notdef"; |
---|
108 | } elsif (@cols[2] =~ /-/) { |
---|
109 | $fields{hex(@cols[1])} = "/.notdef"; |
---|
110 | } else { |
---|
111 | $fields{hex(@cols[1])} = @cols[2]; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | # Dump mapping. |
---|
116 | for ($i = 0; $i < 256; $i++) { |
---|
117 | if (!defined($fields{$i})) { |
---|
118 | print "* code $i is not defined, assuming `.notdef'\n"; |
---|
119 | $name = "/.notdef"; |
---|
120 | } else { |
---|
121 | $name = $fields{$i}; |
---|
122 | } |
---|
123 | print_item($name); |
---|
124 | } |
---|
125 | |
---|
126 | # Print trailer. |
---|
127 | if (($inum % $names_per_row) != 0) { |
---|
128 | printf("\n"); |
---|
129 | } |
---|
130 | print "\] def\n"; |
---|
131 | |
---|
132 | close(FP); |
---|