apple: Initial import of libGL for OSX from AppleSGLX svn repository.
[mesa.git] / src / glx / apple / gen_defs.tcl
1 #This parses and generates #defines from an enum.spec type of file.
2
3 proc main {argc argv} {
4 if {2 != $argc} {
5 puts stderr "syntax is: [info script] input.spec output.h"
6 exit 1
7 }
8
9 set fd [open [lindex $argv 0] r]
10 set data [read $fd]
11 close $fd
12
13 set fd [open [lindex $argv 1] w]
14
15 set state ""
16
17 puts $fd "#define GL_VERSION_1_1 1"
18 puts $fd "#define GL_VERSION_1_2 1"
19 puts $fd "#define GL_VERSION_1_3 1"
20 puts $fd "#define GL_VERSION_1_4 1"
21 puts $fd "#define GL_VERSION_1_5 1"
22 puts $fd "#define GL_VERSION_2_0 1"
23 #puts $fd "#define GL_VERSION_3_0 1"
24
25 set mask ""
26 array set ar {}
27
28 foreach line [split $data \n] {
29 if {[regexp {^\S*#.*} $line] > 0} {
30 #puts COMMENT:$line
31 set state ""
32 } elseif {"enum" eq $state} {
33 if {[string match "\t*" $line]} {
34 if {[regexp {^\tuse.*} $line] > 0} {
35 lassign [split [string trim $line]] use usemask def
36 set usemask [string trim $usemask]
37 set def [string trim $def]
38 puts $fd "/* GL_$def */"
39 } else {
40 lassign [split [string trim $line] =] def value
41 set def [string trim $def]
42 set value [string trim $value]
43
44 #Trim out the data like: 0x0B00 # 4 F
45 set value [lindex [split $value] 0]
46
47 puts $fd "#define GL_$def $value"
48
49 #Save this association with the value.
50 set d $ar($mask)
51 dict set d $def $value
52 set ar($mask) $d
53 }
54 } else {
55 set state ""
56 }
57 } elseif {[string match "* enum:*" $line]} {
58 lassign [split $line] mask _
59 puts $fd "\n/*[string trim $mask]*/"
60 set ar($mask) [dict create]
61 set state enum
62 }
63 }
64
65 close $fd
66 }
67 main $::argc $::argv