forked from surge-synthesizer/sst-basic-blocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_header_guards.pl
80 lines (69 loc) · 1.52 KB
/
fix_header_guards.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
use File::Find;
use File::Basename;
find(
{
wanted => \&findfiles,
},
'include'
);
find(
{
wanted => \&findfiles,
},
'tests'
);
sub findfiles
{
$f = $File::Find::name;
if ($f =~ m/\.h$/)
{
#To search the files inside the directories
$hg = $f;
$hg =~ s:/:_:g;
$hg =~ s:\.:_:g;
$hg =~ s:-:_:g;
$hg =~ s:src:surge_src:;
$hg =~ s:tests:sst_basic_block_tests:;
$hg = uc($hg);
print "$f -> $hg\n";
print "$f -> ${f}.bak\n";
$q = basename($f);
print "$q\n";
open(IN, "<$q") || die "Cant open IN $!";
open(OUT, "> ${q}.bak") || die "Cant open BAK $!";
$tg = "notyet";
$pragmaOnce = 0;
$gotit = 0;
while(<IN>)
{
if (m/\#ifndef\s+(\S*)/ and !$gotit)
{
$tg = $1;
$gotit = 1;
print OUT "#ifndef $hg\n";
}
elsif (m/\#define\s+${tg}/)
{
print OUT "#define $hg\n";
}
elsif (m/#pragma\s*once/)
{
print OUT "#ifndef $hg\n#define $hg\n";
$gotit = 1;
$pragmaOnce = 1;
}
else
{
print OUT;
}
}
if ($pragmaOnce)
{
print OUT "\n#endif // $hg\n";
}
close(IN);
close(OUT);
system("mv ${q}.bak ${q}");
}
}