10
10
Class = collections .namedtuple ('Class' , ['name' , 'purpose' ])
11
11
12
12
13
- FILE_HEADER = """
14
- // Copyright 2001-2017,
15
- // Daniel Kroening (Computer Science Department, University of Oxford
16
- // and Diffblue Ltd),
17
- // Edmund Clarke (Computer Science Department, Carnegie Mellon University),
18
- // DiffBlue Ltd.
19
- """ .strip ()
20
-
21
-
22
13
def warn (message ):
23
14
""" Print a labelled message to stderr. """
24
15
sys .stderr .write ('Warning: %s\n ' % message )
@@ -96,7 +87,7 @@ def format_module(self, header):
96
87
subbed = self .whitespace_re .sub (' ' , header .module )
97
88
# The file directive must be followed by a newline in order to refer to
98
89
# the current file
99
- return self . indented_wrapper . fill ( '\\ file\n %s' % subbed )
90
+ return '\\ file\n ' + self . indented_wrapper . fill ( subbed )
100
91
101
92
def is_block_valid (self , block ):
102
93
return has_field (block , 'Module' )
@@ -204,10 +195,13 @@ def replace_block(
204
195
"""
205
196
Replace an old-style documentation block with the doxygen equivalent
206
197
"""
207
- block = Block ({f .name : f .contents for f in parse_fields (block_contents )})
198
+ block = Block (
199
+ {f .name : f .contents for f in parse_fields (block_contents .group (1 ))})
208
200
209
201
if header_formatter .is_block_valid (block ):
210
- return header_formatter .convert (header_from_block (block ))
202
+ return '%s%s\n ' % (
203
+ block_contents .group (0 ),
204
+ header_formatter .convert (header_from_block (block )))
211
205
212
206
if class_formatter .is_block_valid (block ):
213
207
return class_formatter .convert (class_from_block (block ))
@@ -216,7 +210,7 @@ def replace_block(
216
210
return function_formatter .convert (function_from_block (block ))
217
211
218
212
warn ('block in "%s" has unrecognised format:\n %s' %
219
- (file , block_contents ))
213
+ (file , block_contents . group ( 1 ) ))
220
214
221
215
return ''
222
216
@@ -236,15 +230,12 @@ def convert_file(file, inplace):
236
230
r'^/\*+\\$(.*?)^\\\*+/$\s*' , re .MULTILINE | re .DOTALL )
237
231
new_contents = block_re .sub (
238
232
lambda match : replace_block (
239
- match . group ( 1 ) ,
233
+ match ,
240
234
file ,
241
235
header_formatter ,
242
236
class_formatter ,
243
237
function_formatter ), contents )
244
238
245
- if not re .search (FILE_HEADER , new_contents ):
246
- new_contents = FILE_HEADER + '\n \n ' + new_contents
247
-
248
239
if inplace :
249
240
with open (file , 'w' ) as f :
250
241
f .write (new_contents )
0 commit comments