aboutsummaryrefslogtreecommitdiff
path: root/man/make_man_page.py
blob: 526a717005cf835ed93eeee63a32b281f8450a5f (plain)
  1. #!/usr/bin/env python
  2. # Creates a man page from a C file.
  3. # Lines beginning with /// are treated as Markdown.
  4. # Non-blank lines immediately following a /// line are treated
  5. # as function signatures or examples and included verbatim.
  6. # That's about it!
  7. import sys
  8. import re
  9. special_comment_re = re.compile('\/\/\/');
  10. blank_re = re.compile('^\s*$');
  11. mdlines = []
  12. with open('../src/cmark.h', 'r') as cmarkh:
  13. state = 'default'
  14. for line in cmarkh:
  15. # state transition
  16. oldstate = state
  17. if special_comment_re.match(line):
  18. state = 'markdown'
  19. elif blank_re.match(line):
  20. state = 'default'
  21. elif state == 'markdown':
  22. state = 'signature'
  23. # handle line
  24. if oldstate != state and len(mdlines) > 0 and mdlines[-1] != '\n':
  25. mdlines.append('\n')
  26. if state == 'markdown':
  27. mdlines.append(line[4:])
  28. elif state == 'signature':
  29. mdlines.append(' ' + line)
  30. sys.stdout.write(''.join(mdlines))