diff options
author | John MacFarlane <jgm@berkeley.edu> | 2014-11-30 10:19:24 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-11-30 10:19:24 -0800 |
commit | 7686b7dad5c80d494b993158def220aa8b61ac6e (patch) | |
tree | 09074d13fa0f8e76feb697a70657757481190f36 /man/make_man_page.py | |
parent | ec8683da993c3f73f6934769ea12911a293e15b0 (diff) |
Updated make_man_page.py to use C89 comments.
See #224.
TODO: change this to create the man page directly (not via markdown
intermediary) and parse signatures into .Ft, .Fo, .Fa, .Fc, .Fd.
Diffstat (limited to 'man/make_man_page.py')
-rw-r--r-- | man/make_man_page.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/man/make_man_page.py b/man/make_man_page.py index 19e1271..5ed5b0c 100644 --- a/man/make_man_page.py +++ b/man/make_man_page.py @@ -2,9 +2,9 @@ # Creates a man page from a C file. -# Lines beginning with /// are treated as Markdown. +# Comments beginning with `/**` are treated as Markdown. -# Non-blank lines immediately following a /// line are treated +# Non-blank lines immediately following a Markdown comment are treated # as function signatures or examples and included verbatim. The # immediately preceding markdown chunk is printed after the example # as a comment on it. @@ -20,7 +20,9 @@ else: print("Usage: make_man_page.py sourcefile") exit(1) -special_comment_re = re.compile('^\/\/\/ ?') +comment_start_re = re.compile('^\/\*\* ?') +comment_delim_re = re.compile('^[/ ]\** ?') +comment_end_re = re.compile('^ \**\/') blank_re = re.compile('^\s*$') macro_re = re.compile('CMARK_EXPORT *') @@ -33,7 +35,11 @@ with open(sourcefile, 'r') as cmarkh: for line in cmarkh: # state transition oldstate = state - if special_comment_re.match(line): + if comment_start_re.match(line): + state = 'markdown' + elif comment_end_re.match(line) and state == 'markdown': + continue + elif comment_delim_re.match(line) and state == 'markdown': state = 'markdown' elif blank_re.match(line): state = 'default' @@ -41,12 +47,12 @@ with open(sourcefile, 'r') as cmarkh: state = 'signature' # handle line - #if oldstate != state and len(mdlines) > 0 and mdlines[-1] != '\n': - # mdlines.append('\n') if state == 'markdown': - chunk.append(re.sub(special_comment_re, '', line)) + chunk.append(re.sub(comment_delim_re, '', line)) elif state == 'signature': - sig.append(' ' + re.sub(macro_re, '', line)) + ln = re.sub(macro_re, '', line) + if not re.match(blank_re, ln): + sig.append(' ' + ln) elif oldstate == 'signature' and state != 'signature': if len(mdlines) > 0 and mdlines[-1] != '\n': mdlines.append('\n') |