3 require 'generators/string-lispify'
6 BASE=File::dirname($0)+'/..'
9 open("#{BASE}/src/gl.spec","r") do |i|
12 when /^(\w+)\((.*)\)$/
17 function_name_map=function_names.lispify.inject(Hash.new) do |h,cl|
18 #puts "processing #{cl.inspect}"
19 lisp_name=cl[1..-1].join('-').gsub(/-+/,'-').sub(/-$/,'').downcase
20 #puts "injecting #{cl[0].inspect} as #{lisp_name.inspect}"
25 open("#{BASE}/src/gl.spec.lisp","w") do |o|
27 open("#{BASE}/src/gl.spec","r") do |i|
28 o.puts(";;;; File: gl.spec")
29 o.puts ":functions (("
32 when /^\s*(#+)(.*)/ then o.puts((';'*$1.length)+$2)
33 when /^[a-z-]*:/ then next
34 when /^(\w+)\((.*)\)$/
35 o.puts %{) (("#{$1}" #{function_name_map[$1]}) :args (#{$2.split(',').collect{|s|'|'+s.strip+'|'}.join(' ')})}
36 when /^\tparam\s+(\w+)\s+(\w+)\s+(in|out)\s+(array|value)\s*(.*)\s*$/i
37 o.write(%{:param (:name |#{$1}| :type |#{$2}| :direction :#{$3}})
40 if rest=$5.match(/\[(\S*)\](\s+retained)?/)
42 if size=rest[1].match(/COMPSIZE\(([^)]*)\)/)
43 computes=size[1].split(/\W+/)
45 o.write(%{ :size (#{computes.collect{|c|"|#{c}|"}.join(' ')})})
48 o.write(%{ :size #{rest[1]}})
51 o.write(%{ :retained t}) if rest[2] and rest[2]!=''
55 when /^\t([a-z0-9-]*)\s*(.*)/
56 o.puts(":"+$1+" ("+$2.split(/\s+/).compact.collect{|s|'"'+s+'"'}.join(' ')+")")
63 open(BASE+"/src/gl.tm","r") do |i|
64 o.puts(";;;; File: gl.tm")
68 when /^\s*(#+)(.*)/ then o.puts((';'*$1.length)+$2)
71 o.puts("|"+ts[0]+"| |"+ts[3].strip+"|")
79 for spec in ["enum.spec","enumext.spec"]
80 open(BASE+'/src/'+spec) do |i|
81 o.puts(";;;; File: #{spec}")
84 when /^Extensions define:$/
85 o.puts(':extensions (')
87 o.puts(') |'+$1.gsub(/\s+/,'-')+'| (')
88 when /^(?:\t| {4,})(\w+)\s*=\s*0x([a-fA-F0-9]+)/
89 o.puts(%{|#{$1}| #x#{$2}})
90 when /^(?:\t| {4,})(\w+)\s*=\s*GL_(\w+)(?:\s+#.*)?/
91 o.puts(%{|#{$1}| |#{$2}|})
92 when /^(?:\t| {4,})(\w+)\s*=\s*(\d+)(?:\s+#.*)?/
93 o.puts(%{|#{$1}| #{$2}})
94 when /^(?:\t| {4,})(\w+)\s*=\s*(.+)(?:\s+#.*)/
95 o.puts(%{|#{$1}| #{$2}})
96 when /^(?:\t| {4,})use\s+(\w+)\s+(\w+)/
97 o.puts(%{|#{$2}| (:use |#{$1}|)})
98 when /^(\w+)(,\*)*,\s+(\w+)(,\*)*/
99 o.puts(%{("#{$1}" "#{$3}")})
100 when /^\s*(#+)(.*)/ then o.puts((';'*$1.length)+$2)
101 when /^$/ then o.puts
102 else o.puts ";;? #{l}"