Skip to content

Instantly share code, notes, and snippets.

@hauptmech
Created December 17, 2012 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hauptmech/4322844 to your computer and use it in GitHub Desktop.
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
#!/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