aligned Patch file with new Praat version
[sgc2.git] / praat_module / expandPraatScripts.pl
blob895cc15ca2f553c199e9da5b69335896d5cc83e2
1 #!/usr/bin/perl
3 # Expand include files in praat script.
4 # Writes the expanded script to STDOUT.
5 # Concatenates all arguments.
7 # Use:
8 # perl expandPraatScripts.pl <file1> ...
10 add_build_SHA();
12 foreach my $input (@ARGV)
14 expand($input);
17 sub expand # (filename)
19 my $filename = shift;
20 my $directory = `dirname $filename`;
21 chomp($directory);
22 open(FILE, "<$filename") || die "$!: $filename\n";
23 my @CurrentScript = <FILE>;
24 close(FILE);
25 foreach my $line (@CurrentScript) {
26 if($line =~ /^([^\#]*)include\s+(\S+)/){
27 my ($previous, $match, $following) = ($1, $2, $');
28 print "$previous\n" if $previous =~ /\S/;
29 # Insert included file
30 expand("$directory/$match");
31 print "$following" if $following =~ /\S/;
33 else
35 print $line;
40 # Add git SHA1 commit
41 sub add_build_SHA
43 if(-d "../.git"){
44 open(HEAD, "<../.git/HEAD");
45 my $headRef = <HEAD>;
46 close(HEAD);
47 if($headRef =~ /^\s*ref\:\s+/){
48 $refPtr = $';
49 chomp($refPtr);
50 open(HEAD, "<../.git/$refPtr");
51 $headSHA = <HEAD>;
52 $headSHA =~ s/s//g;
53 $headSHA = uc(substr($headSHA, 0, 10));
55 else {
56 $headSHA = $headRef;
58 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime();
59 $year = ${year}+1900;
60 ${mon} = sprintf("%02d",${mon}+1);
61 ${mday} = sprintf("%02d",${mday});
62 ${hour} = sprintf("%02d",${hour});
63 ${min} = sprintf("%02d",${min});
64 ${sec} = sprintf("%02d",${sec});
65 $UTCstring = "${year}-${mon}-${mday}T${hour}:${min}:${sec}Z";
66 print "\nbuild_SHA\$ = \"$headSHA $UTCstring\"\n";