Added master SHA to expanded praat script output
[sgc2.git] / praat_module / expandPraatScripts.pl
bloba56f9083bd3bd5923fc08f642412d0b1cf0c963b
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_master_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_master_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;
54 else {
55 $headSHA = $headRef;
58 print "\nmaster_SHA\$ = \"$headSHA\"\n";