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