Skip to content

Commit aed3c25

Browse files
committed
Modify reformatting script to retain existing headers
1 parent 69dacac commit aed3c25

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

scripts/reformat_docs.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010
Class = collections.namedtuple('Class', ['name', 'purpose'])
1111

1212

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-
2213
def warn(message):
2314
""" Print a labelled message to stderr. """
2415
sys.stderr.write('Warning: %s\n' % message)
@@ -96,7 +87,7 @@ def format_module(self, header):
9687
subbed = self.whitespace_re.sub(' ', header.module)
9788
# The file directive must be followed by a newline in order to refer to
9889
# the current file
99-
return self.indented_wrapper.fill('\\file\n%s' % subbed)
90+
return '\\file\n' + self.indented_wrapper.fill(subbed)
10091

10192
def is_block_valid(self, block):
10293
return has_field(block, 'Module')
@@ -204,10 +195,13 @@ def replace_block(
204195
"""
205196
Replace an old-style documentation block with the doxygen equivalent
206197
"""
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))})
208200

209201
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)))
211205

212206
if class_formatter.is_block_valid(block):
213207
return class_formatter.convert(class_from_block(block))
@@ -216,7 +210,7 @@ def replace_block(
216210
return function_formatter.convert(function_from_block(block))
217211

218212
warn('block in "%s" has unrecognised format:\n%s' %
219-
(file, block_contents))
213+
(file, block_contents.group(1)))
220214

221215
return ''
222216

@@ -236,15 +230,12 @@ def convert_file(file, inplace):
236230
r'^/\*+\\$(.*?)^\\\*+/$\s*', re.MULTILINE | re.DOTALL)
237231
new_contents = block_re.sub(
238232
lambda match: replace_block(
239-
match.group(1),
233+
match,
240234
file,
241235
header_formatter,
242236
class_formatter,
243237
function_formatter), contents)
244238

245-
if not re.search(FILE_HEADER, new_contents):
246-
new_contents = FILE_HEADER + '\n\n' + new_contents
247-
248239
if inplace:
249240
with open(file, 'w') as f:
250241
f.write(new_contents)

0 commit comments

Comments
 (0)