#!/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.disableRuntimeCheck( ) 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 (restore-sekka-jisyo tsv-file target) (with-open tsv-file (lambda (f) (restore-sekka-jisyo-f f target)))) (define (display-help) (print "Usage : ") (print " sekka-jisyo convertA SKK-JISYO.X > SEKKA-JISYO.X ... output SEKKA-JISYO to STDOUT(AZIK data included)") (print " sekka-jisyo convertN SKK-JISYO.X > SEKKA-JISYO.X ... output SEKKA-JISYO to STDOUT(AZIK data excluded)") (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 load SEKKA-JISYO.X redis:[hostname] ... load SEKKA-JISYO to redis DB on [hostname]") (print " sekka-jisyo load SEKKA-JISYO.X redis: ... load SEKKA-JISYO to redis DB on localhost") (print " sekka-jisyo dump SEKKA-JISYO.X.tch ... dump Tokyo Cabinet DB to DUMPDATA(STDOUT)") (print " sekka-jisyo dump SEKKA-JISYO.X.db ... dump ndbm to DUMPDATA(STDOUT)") (print " sekka-jisyo dump redis:[hostname] ... dump redis DB on [hostname] to DUMPDATA(STDOUT)") (print " sekka-jisyo dump redis: ... dump redis DB on localhost to DUMPDATE(STDOUT)") (print " sekka-jisyo restore SEKKA-JISYO.X.tsv SEKKA-JISYO.X.tch ... restore Tokyo Cabinet DB from tsv-file") (print " sekka-jisyo restore SEKKA-JISYO.X.tsv redis:[hostname] ... restore redis DB on [hostname] from tsv-file") (print " sekka-jisyo restore SEKKA-JISYO.X.tsv redis: ... restore redis DB on localhost from tsv-file")) (define (analyze-kvs-type filename) (cond ((rxmatch #/[.]tch/ filename) (values 'tokyocabinet filename)) ((rxmatch #/[.]db$/ filename) (values 'dbm filename)) ((rxmatch #/^redis:(.*)$/ filename) => (lambda (m) (let1 str (rxmatch-substring m 1) (let1 hostname (if (< 0 (str.size)) str "localhost") (values 'redis hostname))))) (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? 'convertN command) (if (< (length argv) 2) (display-help) (begin (set! global-use-azik #f) (convert-skk-jisyo (second argv))))) ((eq? 'convertA command) (if (< (length argv) 2) (display-help) (convert-skk-jisyo (second argv)))) ((eq? 'load command) (let1 filename (third argv) (receive (type param) (analyze-kvs-type filename) (set-kvs-type type) (if (< (length argv) 3) (display-help) (load-sekka-jisyo (second argv) param))))) ((eq? 'dump command) (let1 filename (second argv) (receive (type param) (analyze-kvs-type filename) (set-kvs-type type) (if (< (length argv) 2) (display-help) (dump-sekka-jisyo param))))) ((eq? 'restore command) (if (< (length argv) 3) (display-help) (let1 target (third argv) (receive (type hostname) (analyze-kvs-type target) (set-kvs-type type) (restore-sekka-jisyo (second argv) hostname))))) (else (errorf "Error: no such command [%s] \n" command ))))))) (main *argv*) ;;END-OF-SCRIPT