| 1 |
;; -*- mode:scheme -*- |
| 2 |
;; |
| 3 |
;; A script to dump dbm content in S-expr |
| 4 |
;; |
| 5 |
;; Usage: gosh dbm/dump [-o <outfile>][-t <type>] <dbmname> |
| 6 |
;; |
| 7 |
|
| 8 |
(use gauche.parseopt) |
| 9 |
(use dbm) |
| 10 |
(use util.match) |
| 11 |
(use file.filter) |
| 12 |
|
| 13 |
(define (main args) |
| 14 |
(let-args (cdr args) ([ofile "o=s" #f] |
| 15 |
[type "t=y" 'gdbm] |
| 16 |
[else _ (usage)] |
| 17 |
. args) |
| 18 |
(let1 class (dbm-type->class type) |
| 19 |
(unless class (exit 1 "dbm type `~a' unknown" type)) |
| 20 |
(match args |
| 21 |
[(dbmname) (do-dump dbmname class (or ofile (current-output-port)))] |
| 22 |
[else (usage)])) |
| 23 |
0)) |
| 24 |
|
| 25 |
(define (usage) |
| 26 |
(print "Usage: gosh dbm/dump [-o outfile][-t type] dbmname") |
| 27 |
(exit 0)) |
| 28 |
|
| 29 |
(define (do-dump name class output) |
| 30 |
(let1 dbm (guard (e [else (exit 1 "couldn't open dbm database: ~a" |
| 31 |
(~ e'message))]) |
| 32 |
(dbm-open class :path name :rw-mode :read)) |
| 33 |
(file-filter |
| 34 |
(^(in out) |
| 35 |
(dbm-for-each dbm (^(k v) (write (cons k v) out) (newline out)))) |
| 36 |
:output output :temporary-file output) |
| 37 |
(dbm-close dbm))) |