Created
December 17, 2012 22:17
-
-
Save hauptmech/4322844 to your computer and use it in GitHub Desktop.
Help convert troff manpage source files to asciidoc. Some hand editing of the file is needed afterwards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
""" | |
A little helper to speed up converting troff files to adoc. | |
usage: | |
./troff2adoc.py manpage.man.in | |
typical post conversion tasks: | |
clean up bolded items outside the OPTIONS section. | |
clean up SYNOPSIS | |
""" | |
import sys | |
import re | |
Nargs = len(sys.argv) | |
if Nargs == 2: | |
myfilename = sys.argv[1] | |
else: | |
print(""" | |
Usage: process <filename> | |
""" | |
) | |
print Nargs | |
quit() | |
myfile = open(myfilename) | |
outfile = open(myfilename[:-3]+".adoc",'w') | |
for line in myfile: | |
rline = line.replace('\-','-') | |
rline = rline.replace(r'\fB','*') | |
rline = rline.replace(r'\fP','*') | |
if rline[:3]==".SH": | |
outfile.write("\n"+rline[4:]) | |
outfile.write("-"*(len(rline)-4)+"\n") | |
elif rline[:2]==".B": | |
outfile.write("*"+rline[3:-1]+"*::"+"\n") | |
elif rline[:3]==".TP": | |
outfile.write("\n") | |
elif rline[:3]==".TH": | |
l = rline[4:].split() | |
outfile.write(l[0]+"("+l[1]+")"+"\n") | |
outfile.write('='*(len(l[0])+3)+"\n") | |
outfile.write(":doctype: manpage\n") | |
outfile.write(":revdate: "+l[2].strip('"')+"\n") | |
outfile.write(":revnumber: "+l[3].strip('"')+"\n") | |
outfile.write(":manpurpose: "+l[4].strip('"')+"\n\n") | |
elif rline[:3]==r'.\"': | |
outfile.write("//"+rline[3:]) | |
elif rline[:3]=='.pc': | |
outfile.write("//"+rline[3:]) | |
elif rline[:3]=='.RI': | |
outfile.write('\t'+rline[3:]) | |
elif rline[:3]=="'\\\"": | |
pass | |
else: | |
outfile.write(rline) | |
outfile.close() | |
myfile.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment