#!/usr/bin/env ruby # -*- mode: nendo; syntax: scheme ; coding: utf-8 -*- require 'nendo' $LOAD_PATH.push( File.dirname(__FILE__) + "/../lib" ) core = Nendo::Core.new() core.setArgv( ARGV ) core.loadInitFile core.evalStr( <<";;END-OF-SCRIPT" ) ;;; ;;; sekka-jisyo - Sekkaの辞書メンテナンスツール ;;; ;;; Copyright (c) 2010 Kiyoka Nishiyama ;;; ;;; 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. ;;; ;;; 3. Neither the name of the authors nor the names of its contributors ;;; may be used to endorse or promote products derived from this ;;; software without specific prior written permission. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT ;;; OWNER 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. ;;; ;;; $Id: ;;; (use sekka.convert-jisyo) (use sekka.jisyo-db) (define (convert-skk-jisyo filename) (let1 lines (with-open filename (lambda (f) (convert-skk-jisyo-f f))) (for-each print lines))) (define (load-sekka-jisyo sekka-file target) (with-open sekka-file (lambda (f) (load-sekka-jisyo-f f (target.gsub #/[.]db$/ "") ;; drop ".db" suffix )))) (define (dump-sekka-jisyo sekka-file) (dump-sekka-jisyo-f STDOUT sekka-file)) (define (display-help) (print "Usage : ") (print " sekka-jisyo convert SKK-JISYO.X > SEKKA-JISYO.X ... output SEKKA-JISYO to STDOUT") (print " sekka-jisyo load SEKKA-JISYO.X SEKKA-JISYO.X.tch ... load SEKKA-JISYO to Tokyo Cabinet DB") (print " sekka-jisyo load SEKKA-JISYO.X SEKKA-JISYO.X.db ... load SEKKA-JISYO to ndbm DB") (print " sekka-jisyo dump SEKKA-JISYO.X.tch ... dump Tokyo Cabinet DB to SEKKA-JISYO(STDOUT)") (print " sekka-jisyo dump SEKKA-JISYO.X.db ... dump ndbm DB to SEKKA-JISYO(STDOUT)")) (define (analyze-kvs-type filename) (cond ((rxmatch #/[.]tch$/ filename) 'tokyocabinet) ((rxmatch #/[.]db$/ filename) 'dbm) (else (errorf "Error: analyze-kvs-type() got unsupported filename [%s] \n" filename)))) (define (main argv) (cond ((= 0 (length argv)) (display-help)) (else (let1 command (string->symbol (first argv)) (cond ((eq? 'convert command) (if (< (length argv) 2) (display-help) (convert-skk-jisyo (second argv)))) ((eq? 'load command) (let1 filename (third argv) (set-kvs-type (analyze-kvs-type filename)) (if (< (length argv) 3) (display-help) (load-sekka-jisyo (second argv) filename)))) ((eq? 'dump command) (let1 filename (second argv) (set-kvs-type (analyze-kvs-type filename)) (if (< (length argv) 2) (display-help) (dump-sekka-jisyo filename)))) (else (errorf "Error: no such command [%s] \n" command ))))))) (main *argv*) ;;END-OF-SCRIPT