]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/sys/gllog/logfunc.py
hello world
[icculus/iodoom3.git] / neo / sys / gllog / logfunc.py
1 #!/usr/bin/env python
2 # generate logging code
3 # this requires an analysis of the parameters for verbose and do actual call
4
5 import sys, string, re
6 from read import read_gl
7
8 def do_logfunc(f_in, f_out):
9
10         (gl, wgl, glX) = read_gl(f_in)
11
12         for l in (gl, glX):
13                 for t in l:
14                         # process ret type to strip trailing spaces
15                         t[0] = string.strip(t[0])
16                         f_out.write('static %s APIENTRY log%s(%s) {\n' % ( t[0], t[2], t[3] ))
17                         # work on parameters
18                         base_params = string.split(t[3], ',')
19                         #f_out.write('// %s\n' % repr(base_params))
20                         # init format string and parameter list
21                         params = []
22                         format = t[1][1:] + t[2]
23                         # a general help list
24                         types = []
25                         names = []
26                         for i in base_params:
27                                 regex = re.compile('([a-zA-Z0-9]*)$')
28                                 name = regex.search(i).group(1)
29                                 type = string.strip(i[0:len(i)-len(name)])                              
30                                 # catch type with no name
31                                 if (len(type) == 0):
32                                         type = name
33                                         name = ''
34                                 #f_out.write('// type: "%s" name: "%s"\n' % (type, name))
35                                 types.append(type)
36                                 names.append(name)
37                                 # verbose the types
38                                 if (type == 'GLenum'):
39                                         format += ' %s'
40                                         params.append( 'EnumString(' + name + ')' )
41                                 elif (type == 'GLfloat' or type == 'GLclampf' or type == 'GLdouble'):
42                                         format += ' %g'
43                                         params.append( name )
44                                 elif (type == 'GLint' or type == 'GLuint' or type == 'GLsizei' or type == 'GLbyte' or type == 'GLshort'
45                                         or type == 'GLubyte' or type == 'GLushort'):
46                                         format += ' %d'
47                                         params.append( name )
48                                 elif (type == 'GLboolean'):
49                                         format += ' %s'
50                                         params.append( name + ' ? "Y" : "N"' )
51                                 elif (type == 'void'):
52                                         pass
53                                 else:
54                                         f_out.write('// unknown type: "%s" name: "%s"\n' % (type, name))
55                                         format += ' \'' + type + ' ' + name + '\''
56                         f_out.write('\tfprintf( tr.logFile, "' + format + '\\n"')
57                         for par in params:
58                                 f_out.write(', ' + par)
59                         f_out.write(' );\n')
60                         if (t[0] != 'void'):
61                                 f_out.write('\treturn dll%s(' % t[2])
62                         else:
63                                 f_out.write('\tdll%s(' % t[2])
64                         started = 0
65                         for i in names:
66                                 if (started):
67                                         f_out.write(', ')
68                                 else:
69                                         started = 1
70                                 f_out.write(i)
71                         f_out.write(');\n')
72                         f_out.write('}\n\n')
73                         
74 if __name__ == '__main__':
75         do_logfunc(sys.stdin, sys.stdout)