# $WordDic: worddic/make-html.rb,v 1.9 2002/12/05 05:44:23 tshiozak Exp $ # Copyright (c) 2002 Takuya SHIOZAKI, # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. =begin make html file from dic file. TBD =end require 'parsearg' require 'DicRecords' require 'DicReader' require 'ToHTML' # zebra formatter class CustomLineFormatter def format(rec) if @cls == 0 then className = "even" @cls = 1 else className = "odd" @cls = 0 end ""+ ". "+rec.name+"\n"+ rec.contents+"\n" end def reset @cls = 0; end def initialize reset end end # alphabetic record sorter class CustomSorter def each_sorted(byname, byid, byord, &blk) (byname.values.sort { |a, b| a.name <=> b.name }).each &blk end end def usage $stderr.printf("usage: "+ "%s [-H header] [-F footer] [-i infile] [-o outfile] "+ "[-A]\n"); $stderr.printf(" -H header : specify a file to be prepended.\n") $stderr.printf(" -F header : specify an file to be appended.\n") $stderr.printf(" -i infile : specify a dictionaly file.\n") $stderr.printf(" -o outfile : specify an output file.\n") $stderr.printf(" -A : sorted by the code order of the keys.\n") end $USAGE='usage' parseArgs(0, nil, "A", "H:", "F:", "i:", "o:") begin dicFactory = WordDic::DictionaryFactory::FromFile.new toHtml = WordDic::ToHTML.new toHtml.lineFormatter = CustomLineFormatter.new # toHtml.header = if $OPT_H.nil? then "" else File.new($OPT_H, "r") end toHtml.footer = if $OPT_F.nil? then "" else File.new($OPT_F, "r") end ifh = if $OPT_i.nil? then $stdin else File.new($OPT_i, "r") end ofh = if $OPT_o.nil? then $stdout else File.new($OPT_o, "w") end # dic = dicFactory.read(ifh) unless ($OPT_A.nil?) then dic.sorter = CustomSorter.new end toHtml.write(ofh, dic) end