-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert_gchords.pl
executable file
·59 lines (37 loc) · 1019 Bytes
/
convert_gchords.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
use strict;
use warnings;
my %dict;
open SETTINGS, "gchords_settings.tex";
for my $line (<SETTINGS>) {
chomp $line;
if ( $line =~ m|\\newcommand\{\\(.*)\}\{\\chord\{.*\}\{.*\}\{(.*)\}\}| ) {
my ($key, $value) = ($1, $2);
$value =~ s|\\||g;
$dict{$key} = $value;
}
}
close SETTINGS;
foreach my $file (<songs_gchords/*.tex>) {
open FILE, "$file";
# changes $file to converted name
$file =~ s|songs_gchords|songs|;
open NEWFILE, ">$file";
foreach my $line (<FILE>) {
my @chords = $line =~ m|\Ch\D?\{\\([^\}]*)\}|g;
my %valid_chords;
foreach my $chord (@chords) {
if ($dict{$chord}) {
$valid_chords{$chord} = 1;
} else {
die "Could not find $chord in the settings. Please add it.".$/;
}
}
foreach my $chord (keys %valid_chords) {
$line =~ s|\{\\$chord\}|\{$dict{$chord}\}|g;
}
print NEWFILE $line;
}
close FILE;
close NEWFILE;
}