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