fiss

Friedel's Initialization and Service Supervision
Log | Files | Refs | LICENSE

make-man.py (1323B)


      1 import sys
      2 import re
      3 
      4 infile = sys.stdin
      5 if len(sys.argv) >= 2:
      6     infile = open(sys.argv[1])
      7 
      8 def inline_convert(text):
      9     text = re.sub(r'\*(.+?)\*', r'\\fB\\fC\1\\fR', text)
     10     text = re.sub(r'_(.+?)_', r'\\fI\1\\fR', text)
     11     text = re.sub(r'\[(.*?)\]\((.*?)\)', r'\1', text)
     12     text = text.replace('&lt;', '<').replace('&gt;', '>')
     13     return text
     14 
     15 in_list = False
     16 
     17 for line in infile:
     18     line = line.strip()
     19     
     20     # is control
     21     if line.startswith("@man"):
     22         _, text = line.split(" ", 1)
     23         print(".TH " + text)
     24     elif line.startswith("@header"):
     25         pass
     26     elif line.startswith("@title"):
     27         _, id, text = line.split(" ", 2)
     28         print(".SH " + text.upper())    
     29     elif line.startswith("@code"):
     30         pass
     31     elif line.startswith("@endcode"):
     32         pass
     33     elif line.startswith("@list"):
     34         in_list = True
     35     elif line.startswith("@endlist"):
     36         in_list = False
     37 
     38     elif in_list and line.endswith('~'):
     39         sys.stdout.write(inline_convert(line[:-1]) + '\n')
     40     elif line.endswith('~'):
     41         sys.stdout.write(inline_convert(line[:-1]) + '\n.PP\n')
     42     elif line:
     43         sys.stdout.write(inline_convert(line) + ' ') 
     44     elif in_list: # is empty but in line
     45         sys.stdout.write("\n.PP\n")
     46     else: # is empty
     47         sys.stdout.write('\n.PP\n')