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