glapigen revision 53238bddeab7b4633bfdb59fac67b0af1211955a
1#! /usr/bin/perl
2#
3# Copyright (C) 2008 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17use strict;
18
19my $lineNum = 0;
20while (my $line = <>) {
21  $lineNum += 1;
22  next if $line =~ /^\//;
23  next if $line =~ /^#/;
24  next if $line =~ /^\s*$/;
25  if ($line !~ /^GL_ENTRY\(([^,]+),\s*([^,]+),\s*([^)]+)\)/) {
26    printf STDERR "Cannot parse line number $lineNum:\n$line";
27    next;
28  }
29  my $type = $1;
30  my $name = $2;
31  my $args = $3;
32
33  printf("%s API_ENTRY(%s)(", $type, $name);
34  my @args = split ',', $args;
35
36  my $len = scalar(@args);
37  for (my $num = 0; $num < $len; $num++) {
38    print ", " if $num > 0;
39    my $arg = $args[$num];
40    if ($arg =~ /([^]]+)(\[[^]]\])/) {
41      my $argtype = $1;
42      my $array = $2;
43      printf("%s arg%d%s", $argtype, $num, $array);
44    } else {
45      if ($arg eq "void") {
46        printf("void");
47      } else {
48        printf("%s arg%d", $arg, $num);
49      }
50    }
51  }
52  printf(") {\n");
53  if ($type eq "void") {
54    printf("    CALL_GL_API(%s", $name);
55  } else {
56    printf("    CALL_GL_API_RETURN(%s", $name);
57  }
58  for (my $num = 0; $num < $len; $num++) {
59    if ($args[$num] ne "void") {
60      print ", ";
61      printf("arg%d", $num);
62    }
63  }
64  printf(");\n}\n\n");
65}
66