15 """Change comments style of source files from // to /** */"""
21 print(
"Please provide at least one source file name as argument.")
24 for file_name
in sys.argv[1:]:
26 print(
"Modifying format of {file} comments in place...".
format(
31 with open(file_name,
"r")
as input_file:
32 lines = input_file.readlines()
48 output_lines.append(line)
51 with open(file_name,
"w")
as output_file:
52 for line
in output_lines:
53 output_file.write(line)
57 comment_regex =
r'^(\s*)//\s(.*)$'
60 return re.search(comment_regex, line)
71 match = re.search(comment_regex, line)
75 match = re.search(comment_regex, line)
79 if len(comment_block) == 0:
84 if len(comment_block) == 1:
85 return [indent +
"/** " +
content(comment_block[0]) +
" */\n"]
87 block = [
"/**"] + [
" * " +
content(line)
for line
in comment_block
89 return [indent + line.rstrip() +
"\n" for line
in block]