#!/usr/local/bin/python #usage: c2html.py myprog.c from sys import * # with this import sys.argv is simply argv import re #with this import re.sub is still re.sub infilename=argv[1] #get the infilename from the command line file=open(infilename) text=file.read() if re.search('\.c$',infilename) : #find .c extension at end ($) of filename print 'conversion of ',infilename,' to html:
' left='/*' #this string used below right='*/' #this strin used below text=re.sub('<','<',text) # < is special in html, convert to < text=re.sub('>','>',text) # > is special in html, convert to > text=re.sub('/\*',left,text) # turn on blue color at start of comments text=re.sub('\*/',right,text) # turn off blue color at end of comments else: #cannot do anything except for .c print 'cannot convert ',infilename exit(1) # print out preformatted html, with comments in blue print "
"
print text
print "
"