blob: dc42c24577ab1da3fe61e4b5c18acc61d4c361e8 [file] [log] [blame]
Daniel Veillardb8478642001-10-12 17:29:10 +00001#! /usr/bin/env python
2###
3#
4# build_glob.py : Build the global_functions.h and global_functions.c
5# files which are required to implement the user
6# interface to global variables now that thread specific
7# data (TSD) is used to emulate global state.
8#
9# See Copyright for the status of this software.
10# Gary.Pennington@sun.com
11###
12import os, string
13
14class globvar:
15 def __init__(self, type, name):
16 self.type=type
17 self.name=name
18
19def writeline(file, line=None):
20 if line:
21 file.write(line)
22 file.write(os.linesep)
23
24if __name__ == "__main__":
25 globals={}
26 global_data=open("global.data").readlines()
27 global_code=open("globals.c").readlines()
28 global_hdr=open("include/libxml/globals.h").readlines()
29 global_functions_hdr=open("include/libxml/globals.h", "w+")
30 global_functions_impl=open("globals.c", "w+")
31
32 #
33 # Rebuild the beginning of the file up to the
34 # Automatically generated string
35 #
36 for line in global_hdr:
37 if line[-len(os.linesep):] == os.linesep:
38 line = line[:-len(os.linesep)]
39 if line == " * Automatically generated by build_glob.py.":
40 break
41 writeline(global_functions_hdr, line)
42
43 writeline(global_functions_hdr, " * Automatically generated by build_glob.py.")
44 writeline(global_functions_hdr, " * Do not modify the previous line.")
45 writeline(global_functions_hdr, " */")
46 writeline(global_functions_hdr)
47
48 for line in global_code:
49 if line[-len(os.linesep):] == os.linesep:
50 line = line[:-len(os.linesep)]
51 if line == " * Automatically generated by build_glob.py.":
52 break
53 writeline(global_functions_impl, line)
54
55 writeline(global_functions_impl, " * Automatically generated by build_glob.py.")
56 writeline(global_functions_impl, " * Do not modify the previous line.")
57 writeline(global_functions_impl, " */")
58 writeline(global_functions_impl)
59
60 # Now process the data and write it to the appropriate output file
61 for line in global_data:
62 if line[0]=='#':
63 continue
64 if line[-len(os.linesep):] == os.linesep:
65 line = line[:-len(os.linesep)]
66 fields = string.split(line, ",")
67 # Update the header file
68 writeline(global_functions_hdr)
Daniel Veillardb8478642001-10-12 17:29:10 +000069 global_functions_hdr.write("extern "+fields[0]+" *")
70 if len(fields) == 3:
71 global_functions_hdr.write("(*")
72 global_functions_hdr.write("__"+fields[1]+"(void)")
73 if len(fields) == 3:
74 global_functions_hdr.write(")"+fields[2])
75 writeline(global_functions_hdr,";")
Daniel Veillard0ba59232002-02-10 13:20:39 +000076 writeline(global_functions_hdr, "#ifdef LIBXML_THREAD_ENABLED")
Daniel Veillardb8478642001-10-12 17:29:10 +000077 writeline(global_functions_hdr,"#define "+fields[1]+" \\")
78 writeline(global_functions_hdr,"(*(__"+fields[1]+"()))")
79 writeline(global_functions_hdr,"#else")
80 if len(fields) == 3:
Daniel Veillardd0463562001-10-13 09:15:48 +000081 writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+fields[2]+";")
Daniel Veillardb8478642001-10-12 17:29:10 +000082 else:
Daniel Veillardd0463562001-10-13 09:15:48 +000083 writeline(global_functions_hdr,"LIBXML_DLL_IMPORT extern "+fields[0]+" "+fields[1]+";")
Daniel Veillardb8478642001-10-12 17:29:10 +000084 writeline(global_functions_hdr,"#endif")
85 # Update the implementation file
86 writeline(global_functions_impl)
Daniel Veillard0ba59232002-02-10 13:20:39 +000087# writeline(global_functions_impl, "extern "+fields[0]+" "+fields[1]+";")
Daniel Veillardb8478642001-10-12 17:29:10 +000088 writeline(global_functions_impl, "#undef\t"+fields[1])
89 writeline(global_functions_impl, fields[0]+" *")
90 if len(fields) == 3:
91 global_functions_impl.write("(*")
92 global_functions_impl.write("__"+fields[1]+"(void)")
93 if len(fields) == 3:
94 writeline(global_functions_impl, ")[]")
95 writeline(global_functions_impl, " {")
96 writeline(global_functions_impl, " if (IS_MAIN_THREAD)")
97 writeline(global_functions_impl, "\treturn (&"+fields[1]+");")
98 writeline(global_functions_impl, " else")
Daniel Veillardd0463562001-10-13 09:15:48 +000099 writeline(global_functions_impl, "\treturn (&xmlGetGlobalState()->"+fields[1]+");")
Daniel Veillardb8478642001-10-12 17:29:10 +0000100 writeline(global_functions_impl, "}")
101 # Terminate the header file with appropriate boilerplate
102 writeline(global_functions_hdr)
103 writeline(global_functions_hdr, "#ifdef __cplusplus")
104 writeline(global_functions_hdr, "}")
105 writeline(global_functions_hdr, "#endif")
106 writeline(global_functions_hdr)
107 writeline(global_functions_hdr, "#endif /* __XML_GLOBALS_H */")