Added grading of student recordings
[sgc2.git] / praat_module / ManPages2CPP.pl
blob524d9f5554396c35fcfd99d0631ff07617dbd520
1 #!/usr/bin/perl
2 #
3 # Convert Praat ManPages files to the equivalent CPP code.
4 # If no target file is given, uses STDOUT
5 #
6 # Use:
7 # perl ManPages2CPP.pl <source-file> [target-file]
9 my $TargetFile = "-";
10 open(FILEOUT, ">$TargetFile") || die "$TargetFile: $!\n";
12 my @currentTime = localtime(time);
13 my $currentYear = $currentTime[5] + 1900;
14 # Print file header
15 my $Header <<= "
16 /* manual_Exp.c
18 * Copyright (C) ${currentYear} R.J.J.H. van Son
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or (at
23 * your option) any later version.
25 * This program is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 * See the GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 #include \"ManPagesM.h\"
37 void manual_TEanalysis_init (ManPages me);
38 void manual_TEanalsyis_init (ManPages me) {
42 #print FILEOUT $Header;
44 # Process all files
45 while (my $SourceFile = shift(@ARGV))
47 open(FILEIN, "<$SourceFile") || die "$SourceFile: $!\n";
49 my $line = <FILEIN>;
50 chomp($line);
51 if($line ne "ManPagesTextFile")
53 die "$SourceFile is not a valid Praat ManPage\n";
55 $line = <FILEIN>;
56 chomp($line);
57 my ($Title, $Author, $Date, $Time);
58 if($line =~ /^\"([^\"]+)\" \"([^\"]*)\"\s+(\d{8,8})\s+(\d+)\s*$/)
60 $Title = $1;
61 $Author = $2;
62 $Date = $3;
63 $Time = $4;
65 else
67 die "$SourceFile is not a valid Praat ManPage\n";
70 # Create output text
71 my $ManPageText = "";
72 while(<FILEIN>)
74 # Skip empty lines
75 next unless /\S/;
76 chomp;
77 my $Macro = "\t";
78 my $Text = "";
79 my ($Startmarker, $Endmarker) = ("\"", "\"");
80 if(/^\s*\<([^\>]+)\>\s+(\".*)$/)
82 $Macro = uc($1);
83 $Text = $2;
85 else
87 $Text = $_;
90 $Text =~ s/\\/\\\\/g;
91 # Handle start quotes
92 if($Text =~ /^\s*\"[^\"]/)
94 $Startmarker = "(L\"";
95 $Text =~ s/^\s*\"//g;
97 # Handle end quotes
98 if($Text =~ /[^\"]\"\s*$/)
100 $Endmarker = "\")";
101 $Text =~ s/\"\s*$//g;
104 $ManPageText .= "$Macro $Startmarker$Text$Endmarker\n";
107 print FILEOUT "MAN_BEGIN (L\"$Title\", L\"$Author\", $Date)\n";
108 print FILEOUT $ManPageText;
109 print FILEOUT "MAN_END\n\n";
112 # Tail
113 # print FILEOUT "}\n";
114 # Clean up
115 close(FILEOUT);