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, separator):
51 html = File (outname, 'w')
55 while not table.eof ():
56 line = table.readline ()
60 columns = split (line, separator)
61 html_line = '<tr><td>' + join (columns, '</td><td>') + '</td></tr>'
62 html.write (html_line)
64 print inname + ': ' + str(i) + ':warning: not enough cols\n'
67 print inname + ': ' + str(i) + ':warning: too many cols\n'
74 def convert_tex (inname, outname, separator):
79 html = File (outname, 'w')
82 while not table.eof ():
83 line = table.readline ()
87 columns = split (line, separator)
89 print inname + ': ' + str(i) + ':warning: not enough cols\n'
92 print inname + ': ' + str(i) + ':warning: too many cols\n'
95 html_line = '\\tableentry{' + join (columns, '}{') + '}\n'
96 html.write (html_line)
102 (options, files) = getopt.getopt (
103 sys.argv[1:], 'to:hp:s:', ['help', 'latex', 'output=', 'package=', 'separator='])
110 if o == '--separator' or o == '-s':
112 elif o== '--help' or o == '-h':
114 elif o=='--latex' or o == '-t':
116 elif o == '--output' or o == '-o':
118 elif o == '--package' or o == '-p':
124 sys.path.append (topdir + '/stepmake/bin')
125 from packagepython import *
126 package = Package (topdir)
127 packager = Packager ()
132 convert_tex (files[0], output, separator)
134 convert_html (files[0], output, separator)