Skip to content

Commit 9dffa04

Browse files
committed
Add inside namespaces
1 parent b6b72ca commit 9dffa04

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tools/docs_gen.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from os.path import dirname, join
55
from os import sep
6+
from re import compile
67

78
import subprocess
89

@@ -22,6 +23,14 @@ def generate_documentation(dirs, output_dir):
2223
proc.stdin.close()
2324
proc.wait()
2425

26+
MATCH_NAMESPACE = compile(r'^namespace.*')
27+
28+
def find_namespace(contents):
29+
for num, line in enumerate(contents.split("\n")):
30+
if MATCH_NAMESPACE.match(line):
31+
return num + 1
32+
return 0
33+
2534
if __name__ == "__main__":
2635
import sys
2736
from os.path import abspath, dirname, join
@@ -41,13 +50,19 @@ def generate_documentation(dirs, output_dir):
4150
with open(src) as fd:
4251
contents = fd.read()
4352
with open(src, "w+") as fd:
44-
fd.write("/** \\addtogroup {:s} */\n/** @{{*/\n{:s}\n/** @}}*/\n".format(name,contents))
53+
insert_at = find_namespace(contents)
54+
before = "\n".join(contents.split("\n")[:insert_at])
55+
after = "\n".join(contents.split("\n")[insert_at:])
56+
fd.write("{:s}\n/** \\addtogroup {:s} */\n/** @{{*/\n{:s}\n/** @}}*/\n".format(before,name,after))
4557
for name, res in resources.features.iteritems():
4658
for src in res.headers:
4759
with open(src) as fd:
4860
contents = fd.read()
4961
with open(src, "w+") as fd:
50-
fd.write("/** \\addtogroup FEATURE_{:s} */\n/** @{{*/\n{:s}\n/** @}}*/\n".format(name,contents))
62+
insert_at = find_namespace(contents)
63+
before = "\n".join(contents.split("\n")[:insert_at])
64+
after = "\n".join(contents.split("\n")[insert_at:])
65+
fd.write("{:s}\n/** \\addtogroup FEATURE_{:s} */\n/** @{{*/\n{:s}\n/** @}}*/\n".format(before,name,after))
5166

5267
generate_documentation(filter(lambda x: "targets" not in x, sum(map(lambda x:x.headers, resources.features.values()), resources.headers)),
5368
join(dirname(dirname(__file__)), "mbed-docs"))

0 commit comments

Comments
 (0)