File: make-encoding.pl

package info (click to toggle)
enscript 1.6.5.90-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,456 kB
  • sloc: ansic: 33,708; sh: 5,383; makefile: 649; yacc: 457; lex: 428; perl: 340; lisp: 109; sed: 16
file content (106 lines) | stat: -rwxr-xr-x 2,637 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/local/bin/perl
#
# Create encoding files from the `*.txt' encoding files.
# Copyright (c) 1995-1998 Markku Rossi.
# Author: Markku Rossi <mtr@iki.fi>
#

#
# This file is part of GNU Enscript.
#
# Enscript is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Enscript is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Enscript.  If not, see <http://www.gnu.org/licenses/>.
#

#
# Handle arguments
#

if (@ARGV != 1) {
    print "usage: make-encoding.pl encfile\n";
    exit(1);
}

$file = shift(@ARGV);

open(FP, $file) || die "couldn't open input file `$file': $!\n";

# Find the start of the table.
$found = 0;
while (<FP>) {
    if ($_ =~ /^-+$/) {
	$found = 1;
	last;
    }
}

if (!$found) {
    die "file `$file' is not a valid encoding file: couldn't find table\n";
}

$file =~ s/\.txt$//g;
$file =~ s/.*\///g;

# Print header.

print <<"EOF";
/*
 * AFM $file encoding.
 *
 * This file is automatically generated from file \`$file.txt\'.  If you
 * have any corrections to this file, please, edit file \`$file.txt\' instead.
 */

/*
 * Enscript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Enscript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Enscript.  If not, see <http://www.gnu.org/licenses/>.
 */

EOF

print "#include \"afmint.h\"\n\n";

printf("AFMEncodingTable afm_%s_encoding[] =\n{\n",
       $file);

# Process file.
while (<FP>) {
    @cols = split;
    if ($_ =~ /^\s*$/) {
	next;
    } elsif ($_ =~ /non-printable/) {
	print "  {@cols[1], AFM_ENC_NONE},\n";
    } elsif (@cols[2] =~ /-/) {
	print "  {@cols[1], AFM_ENC_NON_EXISTENT},\n";
    } else {
	$name = @cols[2];
	$name =~ s/\///g;
	print "  {@cols[1], \"$name\"},\n";
    }
}

# Print trailer.

printf("  {-1,   NULL},\n};\n");

close(FP);