Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 159 lines (138 sloc) 3.857 kB
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
1 #!/usr/bin/env perl
2
3 use Getopt::Long;
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
4
5 # Convert the templates to either GTK2 or GTK3 version.
6 # In the high-level modules, differences between the GTK2.x and GTK3.x
7 # versions of the code are maintained in files called <name>-tmpl.f90 where
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
8 # Lines only to be used in specific versions are prefixed by
9 # (e.g.) !!$GTK<=3.0.0! or !!$GLIB>2.32!
10 # GTK specifies a GTK/GDK version, GLIB a GLIB version, others will be
11 # added as needed. Allowed operators are >, <, >=, <=.
12 # This routine removes the relevant comment
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
13 # flags and generates <name>.f90. If <name>.f90 already exists, then
14 # it is renamed to <name>.f90.old.
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
15 #
16 # Usage:
17 # mk_gtk_hl.pl --gtk=<gtkver> --glib=<glibver> <template files>
18
19 my @gtkver;
20 my @glibver;
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
21
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
22 my $gtkvers, $glibvers;
23 my $tmpl, $f90, $tflag, $op, $cmp, $line;
24 my @flist, @vers;
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
25
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
26 GetOptions('gtk=s' => \$gtkvers,
27 'glib=s' => \$glibvers);
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
28
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
29 if (!defined($gtkvers)) {
30 print "Enter target GTK+ version:_";
31 chomp($gtkvers = <STDIN>);
32 }
33 @gtkver = &extend_version(split(/\./, $gtkvers));
34 if (!defined($glibvers)) {
35 print "Enter target GLIB version:_";
36 chomp($glibvers = <STDIN>);
37 }
38 @glibver = &extend_version(split(/\./, $glibvers));
2aa75c8 @jtappin Remove duplicate code for sliders and spin button, tidy API of choose…
jtappin authored
39
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
40 if ($#ARGV < 0) {
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
41 opendir(DIR,'.') || die "Failed to open current directory: $!\n";
42 @flist=readdir(DIR);
43 closedir(DIR);
44 } else {
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
45 @flist = @ARGV[0 .. $#ARGV];
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
46 }
47
48 # Loop over the files
49 foreach (@flist) {
50 /^(.+)-tmpl\.f90$/ || next; # If it's not a template file then continue
51
52 # Generate the input & output names
53 $tmpl = $_;
54 $f90 = $1.".f90";
55 $tflag = 0;
56
57 print "Input: $tmpl, Output: $f90\n";
58
59 # Make a backup of the existing file (Just in case the program is broken)
60
61 if (-e $f90) {
62 rename($f90, "$f90.old") ||
63 die "Failed to rename $f90: $!\n";
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
64 print "Renamed $f90 to $f90.old\n";
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
65 }
66
67 open(IN, $tmpl) || die "Failed to open $tmpl: $!\n";
68 open(OUT, '>'.$f90) || die "Failed to open $f90: $!\n";
69
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
70 $line = 0;
71 while (<IN>) {
72 $line++;
73 if (/^!!\$T/) {
74 if ($tflag == 0) {
75 &put_message;
76 $tflag=1;
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
77 }
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
78 next;
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
79 }
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
80 if (/^!!\$(G[A-Z]+) *([<>=]+) *([\.0-9]+)!(.+)/) {
81 @vers = &extend_version(split(/\./, $3));
82 $op = $2;
83 if ($1 eq 'GTK') {
84 $cmp = &compare_versions(@gtkver, @vers);
85 } elsif ($1 eq 'GLIB') {
86 $cmp = &compare_versions(@glibver, @vers);
87 } else {
88 print "Unknown conditional $1 at line $line in $tmpl\n";
89 }
90
91 if ($op eq ">") {
92 if ($cmp == 1) {
93 print OUT $4,"\n";
94 } else {
95 print OUT $_;
96 }
97 } elsif ($op eq ">=") {
98 if ($cmp >= 0) {
99 print OUT $4,"\n";
100 } else {
101 print OUT $_;
102 }
103 } elsif ($op eq "<=") {
104 if ($cmp <= 0) {
105 print OUT $4,"\n";
106 } else {
107 print OUT $_;
108 }
109 } elsif ($op eq "<") {
110 if ($cmp == -1) {
111 print OUT $4,"\n";
112 } else {
113 print OUT $_;
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
114 }
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
115 } else {
116 print "Unknown operator $op at line $line in $tmpl\n";
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
117 }
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
118 } else {
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
119 print OUT $_;
120 }
121 }
122 close(IN);
123 close(OUT);
124 }
125
126 sub put_message {
127 print OUT "! --------------------------------------------------------\n";
128 print OUT "! $f90\n";
129 print OUT "! Generated: ".gmtime." GMT\n";
130 print OUT "! Please do not edit this file directly,\n";
131 print OUT "! Edit $tmpl, and use $0 to regenerate.\n";
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
132 print OUT "! Generated for GTK+ version: $gtkver[0].$gtkver[1].$gtkver[2].\n";
133 print OUT "! Generated for GLIB version: $glibver[0].$glibver[1].$glibver[2].\n";
5dc9ac0 @jtappin * Split high-level code into submodules
jtappin authored
134 print OUT "! --------------------------------------------------------\n";
135 }
585e643 @jtappin Update syntax for conditional lines in high-level templates.
jtappin authored
136
137 sub compare_versions {
138 my @a1 = @_[0..2];
139 my @a2 = @_[3..5];
140
141 for ($i = 0; $i < 3; $i++) {
142 if ($a1[$i] > $a2[$i]) {
143 return(1);
144 } elsif ($a1[$i] < $a2[$i]) {
145 return(-1);
146 }
147 }
148 return(0);
149 }
150
151 sub extend_version {
152 my @vn = @_;
153
154 while ($#vn < 2) {
155 @vn[$#vn+1] = "0";
156 }
157 return(@vn);
158 }
Something went wrong with that request. Please try again.