-sections = []
-
-def add_section(text, literal):
- global sections
-
- if literal:
- sections.append(text)
- else:
- sections.append(compile(text, "-", "exec"))
-
-def read_template(fn):
- global typemap
- global iomap
- global functions
-
- literal = True
- text = ""
- for line in open(fn):
- if line[0]=='#':
- continue
- elif line[0]=='^':
- parts = line[1:].split()
- if parts[0]=="typemap":
- typemap = Typemap(parts[1])
- elif parts[0]=="iomap":
- iomap = IOmap(parts[1])
- elif parts[0]=="spec":
- functions = read_spec(parts[2], parts[1])
- elif line[0]==':':
- if not literal and text:
- add_section(text, literal)
- text = ""
- text += line[1:]
- literal = True
- else:
- if literal and text:
- add_section(text, literal)
- text = ""
- text += line
- literal = False
- if text:
- add_section(text, literal)
-
-def compsize(func, size, btype):
- if not size:
- return
-
- res = ""
- have_type = False
- for c in size.replace(',', '/').split('/'):
- param = func.get_param(c)
- if not param:
- sys.stderr.write("Compsize '%s' for function '%s' failed: No parameter '%s'\n"%(size, func.name, c))
- return
-
- if res:
- res += "*"
-
- cn = strip_name(param.type)
- if cn.endswith("Type"):
- res += "typesize(%s)"%param.name
- have_type = True
- elif cn.endswith("Format"):
- res += "formatsize(%s)"%param.name
- elif cn.endswith(("Parameter", "ParameterPName", "ParameterName")) or cn=="GetPName":
- res += "paramsize(%s)"%param.name
- elif cn=="MapTarget":
- res += "mapsize(%s)"%param.name
- elif (cn=="SizeI" or cn.endswith("Int32")) and not param.size:
- res += param.name
- else:
- sys.stderr.write("Compsize '%s' for function '%s' failed: Parameter '%s' has unknown type '%s'\n"%(size, func.name, param.name, param.type))
- return
- if not have_type:
- res += "*sizeof(%s)"%param.ctype
- return res
-
-read_template(sys.argv[1])
-
-def write(str, *args):
- sys.stdout.write(str%args)
-
-def writeln(str, *args):
- sys.stdout.write(str%args+"\n")
-
-for sect in sections:
- if type(sect)==str:
- print sect
- else:
- for func in functions:
- globals = {
- "w": write,
- "wl": writeln,
- "func": func,
- "ret": func.ret,
- "params": func.params
- }
- eval(sect, globals)
+for i in sys.argv[2:]:
+ files = Files(i)
+
+ typemap = Typemap(files.typemap)
+ iomap = IOmap(files.iomap)
+ for s in files.specs:
+ funcs = read_spec(s, files.prefix)
+ funcs = [f for f in funcs if f.name not in files.ignore_funcs and f.category not in files.ignore_categs]
+ for f in funcs:
+ f.finalize()
+ names = [f.name for f in funcs]
+ functions = [f for f in functions if f.name not in names]+funcs
+
+template.process(functions)