3 # table-to-html.py -- convert char-separated table to html table
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
10 name = 'table-to-html'
22 return name + ' version ' + version;
25 sys.stdout.write (program_id () + '\n')
28 sys.stdout.write ("Usage: table-to-html [OPTION]... TABLE-FILE HTML-FILENAME\n"
29 + "Generate pretty table from char separated table\n\n"
31 + " -h, --help print this help\n"
32 + " -p, --package=DIR specify package\n"
33 + " -s, --separator=SEP specify separator [:]\n"
34 + " -t, --latex do latex output instead\n"
41 html.write ('<body bgcolor=white><table cellspacing=10>')
44 html.write ('</table></body>')
46 def convert_html (inname, outname, cols, separator, linesep):
49 html = open (outname, 'w')
53 for line in table.readlines ():
57 columns = split (line, separator)
58 html_line = '<tr><td>' + join (columns, '</td><td>') + '</td></tr>'
59 html_line= regsub.gsub (linesep, ' ',html_line)
60 html.write (html_line)
62 if len (columns) <> cols:
64 raise 'not enough cols'
71 def convert_tex (inname, outname, cols, separator, linesep):
73 html = open(outname, 'w')
76 for line in table.readlines ():
80 columns = split (line, separator)
81 if len (columns) <> cols:
83 raise 'not enough cols'
85 tex_line = '\\tableentry{' + join (columns, '}{') + '}\n'
86 tex_line = regsub.gsub (linesep, ' ', tex_line)
94 (options, files) = getopt.getopt (
95 sys.argv[1:], 'tl:o:hp:c:s:', ['columns=', 'help', 'latex', 'output=', 'package=', 'separator=', 'linesep='])
103 if o == '--separator' or o == '-s':
105 elif o== '--help' or o == '-h':
107 elif o=='--latex' or o == '-t':
109 elif o == '--output' or o == '-o':
111 elif o == '--package' or o == '-p':
113 elif o == '--linesep' or o == '-l':
115 elif o == '--columns' or o == '-c':
121 sys.path.append (topdir + '/stepmake/bin')
122 from packagepython import *
123 package = Package (topdir)
124 packager = Packager ()
129 convert_tex (files[0], output, cols, separator, linesep)
131 convert_html (files[0], output, cols, separator, linesep)