@@ -63,11 +63,11 @@ def find_ml_symbols(regexp, store):
63
63
def find_enums (block_regexp , symbol_regexp , store ):
64
64
for h in headers :
65
65
# remove comments
66
- content = re .sub (re .compile ("(\/\*(\*(?!\/)|[^*])*\*\/)" , re .S | re .M ), " " , open (h ).read ())
66
+ content = re .sub (re .compile (r "(\/\*(\*(?!\/)|[^*])*\*\/)" , re .S | re .M ), " " , open (h ).read ())
67
67
# remove preprocesor lines
68
68
clean_content = ""
69
69
for l in content .split ("\n " ):
70
- if re .match ("\s*#" , l ):
70
+ if re .match (r "\s*#" , l ):
71
71
continue
72
72
clean_content += l + "\n "
73
73
for i in block_regexp .finditer (clean_content ):
@@ -103,11 +103,11 @@ def lkl_prefix(w):
103
103
def replace (h ):
104
104
content = open (h ).read ()
105
105
for i in includes :
106
- search_str = "(#[ \t ]*include[ \t ]*[<\" ][ \t ]*)" + i + "([ \t ]*[>\" ])"
106
+ search_str = r "(#[ \t]*include[ \t]*[<\"][ \t]*)" + i + r "([ \t]*[>\"])"
107
107
replace_str = "\\ 1" + "lkl/" + i + "\\ 2"
108
108
content = re .sub (search_str , replace_str , content )
109
109
tmp = ""
110
- for w in re .split ("(\W+)" , content ):
110
+ for w in re .split (r "(\W+)" , content ):
111
111
if w in defines :
112
112
w = lkl_prefix (w )
113
113
tmp += w
@@ -116,11 +116,11 @@ def replace(h):
116
116
# XXX: cleaner way?
117
117
if s == 'TAG' :
118
118
continue
119
- search_str = "(\W?struct\s+)" + s + "(\W)"
119
+ search_str = r "(\W?struct\s+)" + s + r "(\W)"
120
120
replace_str = "\\ 1" + lkl_prefix (s ) + "\\ 2"
121
121
content = re .sub (search_str , replace_str , content , flags = re .MULTILINE )
122
122
for s in unions :
123
- search_str = "(\W?union\s+)" + s + "(\W)"
123
+ search_str = r "(\W?union\s+)" + s + r "(\W)"
124
124
replace_str = "\\ 1" + lkl_prefix (s ) + "\\ 2"
125
125
content = re .sub (search_str , replace_str , content , flags = re .MULTILINE )
126
126
open (h , 'w' ).write (content )
@@ -162,25 +162,25 @@ def replace(h):
162
162
structs = set ()
163
163
unions = set ()
164
164
165
- p = re .compile ("#[ \t ]*define[ \t ]*(\w+)" )
165
+ p = re .compile (r "#[ \t]*define[ \t]*(\w+)" )
166
166
find_symbols (p , defines )
167
- p = re .compile ("typedef.*(\(\*(\w+)\)\(.*\)\s*|\W+(\w+)\s*|\s+(\w+)\(.*\)\s*);" )
167
+ p = re .compile (r "typedef.*(\(\*(\w+)\)\(.*\)\s*|\W+(\w+)\s*|\s+(\w+)\(.*\)\s*);" )
168
168
find_symbols (p , defines )
169
- p = re .compile ("typedef\s+(struct|union)\s+\w*\s*{[^\\ {\}]*}\W*(\w+)\s*;" , re .M | re .S )
169
+ p = re .compile (r "typedef\s+(struct|union)\s+\w*\s*{[^\\{\}]*}\W*(\w+)\s*;" , re .M | re .S )
170
170
find_ml_symbols (p , defines )
171
171
defines .add ("siginfo_t" )
172
172
defines .add ("sigevent_t" )
173
- p = re .compile ("struct\s+(\w+)\s*\{" )
173
+ p = re .compile (r "struct\s+(\w+)\s*\{" )
174
174
find_symbols (p , structs )
175
175
structs .add ("iovec" )
176
- p = re .compile ("union\s+(\w+)\s*\{" )
176
+ p = re .compile (r "union\s+(\w+)\s*\{" )
177
177
find_symbols (p , unions )
178
- p = re .compile ("static\s+__inline__(\s+\w+)+\s+(\w+)\([^)]*\)\s" )
178
+ p = re .compile (r "static\s+__inline__(\s+\w+)+\s+(\w+)\([^)]*\)\s" )
179
179
find_symbols (p , defines )
180
- p = re .compile ("static\s+__always_inline(\s+\w+)+\s+(\w+)\([^)]*\)\s" )
180
+ p = re .compile (r "static\s+__always_inline(\s+\w+)+\s+(\w+)\([^)]*\)\s" )
181
181
find_symbols (p , defines )
182
- p = re .compile ("enum\s+(\w*)\s*{([^}]*)}" , re .M | re .S )
183
- q = re .compile ("(\w+)\s*(,|=[^,]*|$)" , re .M | re .S )
182
+ p = re .compile (r "enum\s+(\w*)\s*{([^}]*)}" , re .M | re .S )
183
+ q = re .compile (r "(\w+)\s*(,|=[^,]*|$)" , re .M | re .S )
184
184
find_enums (p , q , defines )
185
185
186
186
# needed for i386
@@ -190,11 +190,13 @@ def process_header(h):
190
190
print (" REPLACE\t %s" % (out_dir + "/" + os .path .basename (h )))
191
191
replace (h )
192
192
193
- p = multiprocessing .Pool (args .jobs )
194
- try :
195
- p .map_async (process_header , headers ).wait (999999 )
196
- p .close ()
197
- except :
198
- p .terminate ()
199
- finally :
200
- p .join ()
193
+ if __name__ == '__main__' :
194
+ multiprocessing .freeze_support ()
195
+ p = multiprocessing .Pool (args .jobs )
196
+ try :
197
+ p .map_async (process_header , headers ).wait (999999 )
198
+ p .close ()
199
+ except :
200
+ p .terminate ()
201
+ finally :
202
+ p .join ()
0 commit comments