]> git.donarmstrong.com Git - lilypond.git/blob - bin/mf-to-table.in
patch::: 0.1.15.jcn2: leesvoer
[lilypond.git] / bin / mf-to-table.in
1 #!@PERL@ -w
2 # -*-perl-*-
3
4 =head1 TODO
5
6 rename me!
7
8 Ugh . Perl sux. Anybody for Python?
9     
10 =cut    
11
12 $mf_to_table_version = 0.1;
13
14 use Getopt::Long;
15
16 sub last_conversion
17 {
18     my @v = &versions;
19     return pop @v;
20 }
21 sub identify
22 {
23     
24     print STDERR "This is mf-to-table " . $mf_to_table_version . "\n";
25 }
26   
27 sub usage
28 {
29     print STDERR "Usage: mf-to-table [options] LOG..\n"
30     . "Generate mozarella metrics table from preparated metafont log\n\n"
31     . "Options:\n"
32     . "  -h, --help             print this help\n"
33     . "  -o, --output=FILE      name output file\n"
34 }
35
36 sub make_table
37 {
38     my $line;
39     my $indent = 0;
40     while ($line = <IN>) {
41         if ($line =~ /^@@/) {
42             $line =~ s/^@@(.*)@@/$1/;
43             chop ($line);
44             my @fields = split (/:/,$line);
45             my $label = $fields [0];
46             my $name = $fields [1];
47             print OUT "\t" x $indent;
48             if ($label eq "font") {
49                 print OUT "% $name=\\symboltables {\n";
50                 $indent++;
51             } elsif ($label eq "group") {
52                 print OUT "\"$name\" = \\table {\n";
53                 $indent++;
54             } elsif ($label eq "puorg") {
55                 print OUT "}\n";
56                 $indent--;
57             } elsif ($label eq "tnof") {
58                 print OUT "%  } % $name\n";
59                 $indent--;
60             } elsif ($label eq "char") {
61                 my $c = $fields [2];
62                 my $w = $fields [3];
63                 my $h = $fields [4];
64                 my $d = $fields [5];
65                 my $id = $fields [6];
66                 my $texstr = $fields [7];
67                 print OUT sprintf( "\"%s\"\t\"\\%s\"\t%.2f\\pt\t%.2f\\pt\t%.2f\\pt\t%.2f\\pt\n", $id, $texstr, 0, $w, $h, $d );
68             } else {
69                 print STDERR "mf-to-table: unknown label: \`$label\'\n";
70             }
71         }
72     }
73 }
74       
75 sub  set_files 
76 {
77     $infile = "-";
78     $outfile = "-";
79     $outfile = $opt_output if (defined($opt_output));
80
81     if ($ARGV [0])  {
82         $infile = $ARGV[0];
83     } 
84     if (( ! -f $infile) && (! $infile =~ /\\.log$/s ) ){
85         $infile .= ".log";
86     }
87     print STDERR "Input ", (($infile eq "-") ?"STDIN" : $infile), " .. \n";
88 }
89
90 sub do_one_arg
91 {
92     set_files;
93
94     die "can't open \`$infile\'" unless open IN,$infile ;
95     die "can't open \`$outfile\'" unless open OUT, ">$outfile";
96     print OUT "% generated at " . localtime() . " from $infile\n";
97     print OUT "% changes will be lost\n";
98     
99     make_table;
100
101     close IN;
102     close OUT;
103 }
104
105 ## "main"
106
107 identify;
108
109 #GetOptions ("help", "output=s", "from=i", "to=i", "minor=i", "edit", "show-rules");
110 GetOptions ("help", "output=s");
111
112 if ($opt_help) {
113     usage();
114     $opt_help = 0;      # to extinguish typo check.
115     exit 0;
116 }
117
118 local ($infile,$outfile);
119 my $processed_one=0;
120
121 while (defined($ARGV[0])) {
122     do_one_arg;
123     shift @ARGV;
124     $processed_one = 1;
125 }
126 do_one_arg unless ($processed_one);
127