summaryrefslogtreecommitdiff
path: root/man/make_man_page.py
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-11-29 18:57:29 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-11-29 18:59:04 -0800
commitb004ef0330ece7767bd9b57aa16bfe36e8fcc350 (patch)
tree6eda5417b29084dd37f89504052e5be7b6a5d988 /man/make_man_page.py
parent9fedb89af38b5a43eb0f7944e938dbbdb17a499d (diff)
Added make_man_page.py script.
Diffstat (limited to 'man/make_man_page.py')
-rw-r--r--man/make_man_page.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/man/make_man_page.py b/man/make_man_page.py
new file mode 100644
index 0000000..526a717
--- /dev/null
+++ b/man/make_man_page.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+# Creates a man page from a C file.
+# Lines beginning with /// are treated as Markdown.
+# Non-blank lines immediately following a /// line are treated
+# as function signatures or examples and included verbatim.
+# That's about it!
+
+import sys
+import re
+
+special_comment_re = re.compile('\/\/\/');
+blank_re = re.compile('^\s*$');
+
+mdlines = []
+
+with open('../src/cmark.h', 'r') as cmarkh:
+ state = 'default'
+ for line in cmarkh:
+ # state transition
+ oldstate = state
+ if special_comment_re.match(line):
+ state = 'markdown'
+ elif blank_re.match(line):
+ state = 'default'
+ elif state == 'markdown':
+ state = 'signature'
+
+ # handle line
+ if oldstate != state and len(mdlines) > 0 and mdlines[-1] != '\n':
+ mdlines.append('\n')
+ if state == 'markdown':
+ mdlines.append(line[4:])
+ elif state == 'signature':
+ mdlines.append(' ' + line)
+
+sys.stdout.write(''.join(mdlines))