+ output_file.write(table_footer)
+ if not exclude_headers:
+ output_file.write(html_footer)
+
+
+def usage():
+ print '''
+diff2html.py [-i file] [-o file] [-x]
+diff2html.py -h
+
+Transform a unified diff from stdin to a colored side-by-side HTML
+page on stdout.
+
+ -i file set input file, else use stdin
+ -o file set output file, else use stdout
+ -x exclude html header and footer
+ -t tabsize set tab size (default 8)
+ -l linesize set maximum line size is there is no word break (default 20)
+ -r show \\r characters
+ -k show hunk infos
+ -h show help and exit
+'''
+
+def main():
+ global linesize, tabsize
+ global input_file, output_file
+ global exclude_headers, show_CR, show_hunk_infos
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:], "hi:o:xt:l:rk",
+ ["help", "input=", "output=",
+ "exclude-html-headers", "tabsize=",
+ "linesize=", "show-cr", "show-hunk-infos"])
+ except getopt.GetoptError, err:
+ print str(err) # will print something like "option -a not recognized"
+ usage()
+ sys.exit(2)
+ output = None
+ verbose = False
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage()
+ sys.exit()
+ elif o in ("-i", "--input"):
+ input_file = open(a, "r")
+ elif o in ("-o", "--output"):
+ output_file = open(a, "w")
+ elif o in ("-x", "--exclude-html-headers"):
+ exclude_headers = True
+ elif o in ("-t", "--tabsize"):
+ tabsize = int(a)
+ elif o in ("-l", "--linesize"):
+ linesize = int(a)
+ elif o in ("-r", "--show-cr"):
+ show_CR = True
+ elif o in ("-k", "--show-hunk-infos"):
+ show_hunk_infos = True
+ else:
+ assert False, "unhandled option"
+ parse_input()