File: glext_procs.pl

package info (click to toggle)
libopengl-perl 0.7000%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,312 kB
  • sloc: perl: 10,177; ansic: 8,576; makefile: 113
file content (192 lines) | stat: -rwxr-xr-x 4,113 bytes parent folder | download
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
$|++;
my $file = '/usr/include/GL/glext.h';
die "Unable to read '$file'" if (!open(FILE,$file));

my $exts = '../glext_procs.h';
die "Unable to write to '$exts'" if (!open(EXTS,">$exts"));
binmode EXTS;

my $exts = '../glext_consts.h';
die "Unable to write to '$exts'" if (!open(CNST,">$exts"));
binmode CNST;

my $exts = '../glext_types.h';
die "Unable to write to '$exts'" if (!open(TYPE,">$exts"));
binmode TYPE;

my $exps = 'exports.txt';
die "Unable to read '$exps'" if (!open(EXPS,$exps));
my $exports = {};
foreach my $line (<EXPS>)
{
  $line =~ s|[\r\n]+||g;
  next if (!$line);
  $exports->{$line}++;
}
close(EXPS);

# Header
my $header = qq
{#ifndef %s
#define %s

#ifdef __cplusplus
extern "C" \{
#endif

/*
** This file is derived from glext.h and is subject to the same license
** restrictions as that file.
**
};

print EXTS sprintf $header, ("__glext_procs_h_") x 2;
print CNST sprintf $header, ("__glext_consts_h_") x 2;
print TYPE sprintf $header, ("__glext_types_h_") x 2;


# License
while (<FILE>)
{
  my $line = $_;
  next if ($line !~ m|^\*\* Copyright \(c\) 20\d\d-20\d\d The Khronos Group Inc\.|);
  print EXTS $line;
  print CNST $line;
  last;
}

# Handle extensions
while (<FILE>)
{
  my $line = $_;
  if ($line =~ m|^\#ifdef __cplusplus|)
  {
    print "Found end\n";
    print EXTS $line;
    print CNST $line;
    print TYPE $line;
    next;
  }
  elsif ($line =~ m|^\#ifndef GL_[^\s]+|)
  {
    my $next_line = <FILE>;

    if ($next_line !~ m|^\#define (GL_[^\s]+) 1|)
    {
      print EXTS $line.$next_line;
      print CNST $line.$next_line;
      next;
    }

    my $ext = $1;
    print "$ext\n";

    print EXTS qq
{#ifndef NO_$ext
#ifndef $ext
#define $ext 1
#endif
};
    print CNST "#ifndef NO_$ext\n";

    my @procs;
    my $in_PROTOTYPES;
    my $in_TYPES;
    my $proto_level;
    my $types_level;
    my $def_level = 1;
    while (<FILE>)
    {
      my $line2 = $_;

      if ($line2 =~ m/^#(if|ifdef|ifndef)/)
      {
        print EXTS $line2;
        if($line2 =~ /ifdef.*GL_GLEXT_PROTOTYPES/)
        {
          $proto_level = $def_level;
          $in_PROTOTYPES = 1;
        }
        if($line2 =~ /ifndef.*GLEXT_64_TYPES_DEFINED/)
        {
          $types_level = $def_level;
          $in_TYPES = 2;
        }
        print CNST $line2 if !$in_PROTOTYPES;
        print TYPE $line2 if $in_TYPES;
        $def_level++;
        next;
      }

      if ($line2 !~ m|^\#endif|)
      {
        print EXTS $line2;
        $in_TYPES-- if $in_TYPES == 1 and $line2 !~ m|^typedef|;
        print TYPE $line2 if $in_TYPES;
        print TYPE $line2 if !$in_TYPES and ($line2 =~ m|^typedef \w+ \w+;| or $line2 =~ m|^#include|);

        if ($line2 =~ m|APIENTRY (gl[^\s]+)|)
        {
          my $export = $1;
          if ($exports->{$export})
          {
            print "  Not a wgl export: $export\n";
          }
          else
          {
            push(@procs,'static PFN'.uc($1).'PROC '.$1." = NULL;\n");
          }
          next;
        }
        
        if ($line2 =~ m|^\#define (GL_[^\s]+)|)
        {
          print CNST "    i($1)\n";
          next;
        }
        
        # the #define here blocks GLEXT_64_TYPES_DEFINED, might be needed though
        next if $line2 =~ /^(#define|typedef|struct|#include) /;
        print CNST $line2;
        next;
      }
      $def_level--;

      if($def_level>0)
      {
        print EXTS $line2;
        print CNST $line2 if !$in_PROTOTYPES;
        print TYPE $line2 if $in_TYPES;

        $in_PROTOTYPES = 0 if $in_PROTOTYPES and $proto_level == $def_level;
        $in_TYPES-- if $in_TYPES and $types_level == $def_level;

        next;
      }

      if(@procs)
      {
        print EXTS "\#ifdef GL_GLEXT_PROCS\n";
        foreach my $proc (@procs)
        {
          print EXTS $proc;
        }
        print EXTS "\#endif /* GL_GLEXT_PROCS */\n";
      }

      print EXTS $line2;
      print CNST $line2;
      last;
    }
  }
  else
  {
    print EXTS $line;
    next if $line =~ /^(#include|#define) /;
    print CNST $line;
    print TYPE $line;
  }
}

close(EXTS);
close(FILE);