#!/usr/bin/env gosh ;;; ;;; Convert SKK dictionary to dbm format. ;;; - Read from standard input and write to spcified file. ;;; - Gauche script ;;; ;;; Usage: skktodbm.scm ;;; ;;; $Id: skktodbm,v 1.7 2003/12/21 10:13:15 hos Exp $ ;;; (use dbm) (define-macro (multi-use pattern) `(begin ,@(library-map pattern (lambda (m p) `(use ,m))))) (multi-use dbm.*) (define-macro (make-dbm-alist) (list 'quasiquote (library-map 'dbm.* (lambda (m p) (let* ((str ((#/^dbm\.(.*)$/ (symbol->string m)) 1)) (sym (string->symbol (string-append "<" str ">")))) `(,str . ,(list 'unquote sym))))))) (define dbm-alist (make-dbm-alist)) (define (skk->dbm in dbm) (cond ((rxmatch #/^[\x3b]/ in) ;comment line #f) ((rxmatch #/^([^ ]+) (.*)$/ in) => (lambda (m) (let ((key (rxmatch-substring m 1)) (val (rxmatch-substring m 2))) (dbm-put! dbm key val)))) (else (error "invalid format" in)))) (define (main args) (if (= (length args) 3) (let* ((dbm-type (cdr (assoc (cadr args) dbm-alist))) (dbm-path (caddr args)) (dbm #f)) (with-error-handler (lambda (e) (format (current-error-port) "~a: ~s\n" *program-name* (slot-ref e 'message)) (dbm-db-remove dbm-type dbm-path)) (lambda () (dynamic-wind (lambda () (set! dbm (dbm-open dbm-type :path dbm-path :rw-mode :create))) (lambda () (port-for-each (lambda (in) (skk->dbm in dbm)) read-line)) (lambda () (dbm-close dbm) )))) 0) (display (string-append (format #f "Usage: ~a \n" *program-name*) "\n" "DBM-TYPE:\n" " " (string-join (map car dbm-alist) ", ") "\n" ) (current-error-port)))) ;; Local variables: ;; mode: scheme ;; end: