Skip to content

Commit 47cb4f7

Browse files
committed
extract utils/common.pl
1 parent 8037124 commit 47cb4f7

File tree

4 files changed

+44
-60
lines changed

4 files changed

+44
-60
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ t/02_auto_error_check.t
2525
t/02_glew_version_accessors.t
2626
t/02_glGetShaderInfoLog.t
2727
typemap
28+
utils/common.pl
2829
utils/feature-reuse.txt
2930
utils/generate-registry.pl
3031
utils/generate-XS.pl

utils/common.pl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use strict;
2+
use warnings;
3+
4+
# The functions where we specify manual implementations or prototypes
5+
# These could also be read from Modern.xs, later maybe
6+
my @manual_list = qw(
7+
glGetString
8+
glShaderSource_p
9+
);
10+
11+
my %manual;
12+
@manual{@manual_list} = ( 1 ) x @manual_list;
13+
14+
sub is_manual { $manual{$_[0]} }
15+
sub manual_list { @manual_list }
16+
17+
sub slurp {
18+
my $filename = $_[0];
19+
open my $old_fh, '<:raw', $filename
20+
or die "Couldn't read '$filename': $!";
21+
join '', <$old_fh>;
22+
}
23+
24+
sub save_file {
25+
my ( $filename, $new ) = @_;
26+
my $old = -e $filename ? slurp( $filename ) : "";
27+
if ( $new ne $old ) {
28+
print "Saving new version of $filename\n";
29+
open my $fh, '>:raw', $filename
30+
or die "Couldn't write new version of '$filename': $!";
31+
print $fh $new;
32+
}
33+
}
34+
35+
1;

utils/generate-XS.pl

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use strict;
22
use warnings;
33
use OpenGL::Modern::Registry;
4+
require './utils/common.pl';
45

56
=head1 PURPOSE
67
@@ -14,15 +15,6 @@ =head1 PURPOSE
1415
1516
=cut
1617

17-
# The functions where we specify manual implementations or prototypes
18-
# These could also be read from Modern.xs, later maybe
19-
my @manual_list = qw(
20-
glGetString
21-
glShaderSource_p
22-
);
23-
24-
my %manual;
25-
@manual{@manual_list} = ( 1 ) x @manual_list;
2618
our %signature;
2719
*signature = \%OpenGL::Modern::Registry::registry;
2820

@@ -45,7 +37,7 @@ sub generate_glew_xs {
4537
my $content;
4638
for my $name (@_ ? @_ : sort keys %signature) {
4739
my $item = $signature{$name};
48-
if ( $manual{$name} ) {
40+
if ( is_manual($name) ) {
4941
print "Skipping $name, already implemented in Modern.xs\n";
5042
next;
5143
}
@@ -79,23 +71,5 @@ sub generate_glew_xs {
7971
return $content;
8072
}
8173

82-
sub slurp {
83-
my $filename = $_[0];
84-
open my $old_fh, '<:raw', $filename
85-
or die "Couldn't read '$filename': $!";
86-
join '', <$old_fh>;
87-
}
88-
89-
sub save_file {
90-
my ( $filename, $new ) = @_;
91-
my $old = -e $filename ? slurp( $filename ) : "";
92-
if ( $new ne $old ) {
93-
print "Saving new version of $filename\n";
94-
open my $fh, '>:raw', $filename
95-
or die "Couldn't write new version of '$filename': $!";
96-
print $fh $new;
97-
}
98-
}
99-
10074
my $xs_code = generate_glew_xs(@ARGV);
10175
save_file( 'auto-xs.inc', $xs_code );

utils/generate-registry.pl

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@ =head1 PURPOSE
88
99
=cut
1010

11+
require './utils/common.pl';
1112
my %upper2data;
1213
my %case_map;
1314
my %alias;
1415

15-
# The functions where we specify manual implementations or prototypes
16-
# These could also be read from Modern.xs, later maybe
17-
my @manual_list = qw(
18-
glGetString
19-
glShaderSource_p
20-
);
21-
22-
my %manual;
23-
@manual{@manual_list} = ( 1 ) x @manual_list;
24-
my @exported_functions = @manual_list; # names the module exports
16+
my @exported_functions = manual_list(); # names the module exports
2517
my %constants;
2618

2719
for my $file ("include/GL/glew.h") {
@@ -116,7 +108,7 @@ =head1 PURPOSE
116108
sub preprocess_for_registry {
117109
for my $name (@_ ? @_ : sort keys %signature) {
118110
my $item = $signature{$name};
119-
next if $manual{$name};
111+
next if is_manual($name);
120112
my $args = delete $item->{signature};
121113
die "No args for $name" unless $args;
122114
my @argdata;
@@ -146,38 +138,20 @@ sub preprocess_for_registry {
146138
}
147139
}
148140

149-
sub slurp {
150-
my $filename = $_[0];
151-
open my $old_fh, '<:raw', $filename
152-
or die "Couldn't read '$filename': $!";
153-
join '', <$old_fh>;
154-
}
155-
156-
sub save_file {
157-
my ( $filename, $new ) = @_;
158-
my $old = -e $filename ? slurp( $filename ) : "";
159-
if ( $new ne $old ) {
160-
print "Saving new version of $filename\n";
161-
open my $fh, '>:raw', $filename
162-
or die "Couldn't write new version of '$filename': $!";
163-
print $fh $new;
164-
}
165-
}
166-
167141
preprocess_for_registry(@ARGV);
168142

169143
my %feature2version;
170-
for (grep $_, split /\n/, slurp 'utils/feature-reuse.txt') {
144+
for (grep $_, split /\n/, slurp('utils/feature-reuse.txt')) {
171145
my ($v, $f) = split /\s+/;
172146
$feature2version{$f}{$v} = undef;
173147
}
174148
@feature2version{keys %feature2version} = map +(keys %$_)[0], values %feature2version;
175-
$signature{$_}{core_removed} = 1 for grep $_, split /\s+/, slurp 'utils/removed.txt';
149+
$signature{$_}{core_removed} = 1 for grep $_, split /\s+/, slurp('utils/removed.txt');
176150
my (%features, %gltags);
177151
for my $name (sort {uc$a cmp uc$b} keys %signature) {
178152
my $s = $signature{$name};
179153
my $binding_name = $s->{has_ptr_arg} ? $name . '_c' : $name;
180-
push @exported_functions, $binding_name if !$manual{$name};
154+
push @exported_functions, $binding_name if !is_manual($name);
181155
next if !$s->{feature};
182156
for ($s->{feature}, grep defined, $feature2version{$s->{feature}}) {
183157
$gltags{$_}{$binding_name} = undef;

0 commit comments

Comments
 (0)