3
3
4
4
from os .path import dirname , join
5
5
from os import sep
6
+ from re import compile
6
7
7
8
import subprocess
8
9
@@ -22,6 +23,14 @@ def generate_documentation(dirs, output_dir):
22
23
proc .stdin .close ()
23
24
proc .wait ()
24
25
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
+
25
34
if __name__ == "__main__" :
26
35
import sys
27
36
from os .path import abspath , dirname , join
@@ -41,13 +50,19 @@ def generate_documentation(dirs, output_dir):
41
50
with open (src ) as fd :
42
51
contents = fd .read ()
43
52
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 ))
45
57
for name , res in resources .features .iteritems ():
46
58
for src in res .headers :
47
59
with open (src ) as fd :
48
60
contents = fd .read ()
49
61
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 ))
51
66
52
67
generate_documentation (filter (lambda x : "targets" not in x , sum (map (lambda x :x .headers , resources .features .values ()), resources .headers )),
53
68
join (dirname (dirname (__file__ )), "mbed-docs" ))
0 commit comments