/
mk_gtk_hl.pl
executable file
·88 lines (74 loc) · 2.29 KB
/
mk_gtk_hl.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
81
82
83
84
85
86
87
88
#!/usr/bin/perl
# Convert the templates to either GTK2 or GTK3 version.
# In the high-level modules, differences between the GTK2.x and GTK3.x
# versions of the code are maintained in files called <name>-tmpl.f90 where
# Lines only to be used in GTK2 are prefixed with "!!$2" and those for GTK3
# only are prefixed with "!!$3". This routine removes the relevant comment
# flags and generates <name>.f90. If <name>.f90 already exists, then
# it is renamed to <name>.f90.old.
die "No version given.\nUsage:\n $0 {2|3} [tmplfile...]\n" if ($#ARGV < 0);
my $tmpl, $f90, $tflag, @flist;
# Get the list of files in the current directory.
die "Invalid version argument: $ARGV[0]\n" if ( $ARGV[0] !~/[23]/ );
if ($#ARGV == 0) {
opendir(DIR,'.') || die "Failed to open current directory: $!\n";
@flist=readdir(DIR);
closedir(DIR);
} else {
@flist = @ARGV[1 .. $#ARGV];
}
# Loop over the files
foreach (@flist) {
/^(.+)-tmpl\.f90$/ || next; # If it's not a template file then continue
# Generate the input & output names
$tmpl = $_;
$f90 = $1.".f90";
$tflag = 0;
print "Input: $tmpl, Output: $f90\n";
# Make a backup of the existing file (Just in case the program is broken)
if (-e $f90) {
rename($f90, "$f90.old") ||
die "Failed to rename $f90: $!\n";
}
open(IN, $tmpl) || die "Failed to open $tmpl: $!\n";
open(OUT, '>'.$f90) || die "Failed to open $f90: $!\n";
if ($ARGV[0] == '2') { # Making GTK2 version
while (<IN>) {
if (/!!\$T/) {
if ($tflag == 0) {
&put_message;
$tflag=1;
}
next;
}
s/!!\$2//;
print OUT $_;
}
} elsif ($ARGV[0] == '3') { # Making GTK3 version
while (<IN>) {
if (/!!\$T/) {
if ($tflag == 0) {
&put_message;
$tflag=1;
}
next;
}
s/!!\$3//;
print OUT $_;
}
} else { # Bad version number
close(IN);
close(OUT);
die "Invalid version $ARGV[0]\n";
}
close(IN);
close(OUT);
}
sub put_message {
print OUT "! --------------------------------------------------------\n";
print OUT "! $f90\n";
print OUT "! Generated: ".gmtime." GMT\n";
print OUT "! Please do not edit this file directly,\n";
print OUT "! Edit $tmpl, and use $0 to regenerate.\n";
print OUT "! --------------------------------------------------------\n";
}