#!/usr/bin/env python import sys import os, os.path from optparse import OptionParser def quote_line (line): line = line.replace ('&', '&') line = line.replace ('<', '<') line = line.replace ('>', '>') line = line.replace ("'", ''') line = line.replace ('"', '"') return line def generate_listing (input_filename, title=None): inf = open (input_filename, "r") output_filename = os.path.basename (input_filename) + '.xml' outf = open (output_filename, "w") outf.write ('\n') # outf.write ('\n' % (input_filename,)) # if not title: # title = input_filename # outf.write ('') # outf.write (title) # outf.write ('\n') outf.write ('\n'); lineno = 0 for line in inf: line = line.expandtabs (8) line = quote_line (line) lineno = lineno + 1 outf.write ('%3d %s' % (lineno, line)) outf.write ('\n') # outf.write ('\n') def main (): for file in sys.argv[1:]: generate_listing (file) if __name__ == '__main__': main ()