| 1 |
;; |
| 2 |
;; ndbm-suffix - find out what suffix(es) is/are used for ndbm database. |
| 3 |
;; write out the result into a file given to the argument |
| 4 |
;; in C source form. |
| 5 |
|
| 6 |
(use gauche.process) |
| 7 |
(use util.match) |
| 8 |
|
| 9 |
(define (main args) |
| 10 |
(match (cdr args) |
| 11 |
[(file) |
| 12 |
(receive (p tname) (sys-mkstemp "ndbmtest") |
| 13 |
(close-output-port p) |
| 14 |
(sys-unlink tname) |
| 15 |
(let1 p (run-process `("./ndbm-makedb" ,tname) :wait #t) |
| 16 |
(unless (zero? (process-exit-status p)) |
| 17 |
(print "ndbm-makedb failed") |
| 18 |
(exit 1)) |
| 19 |
;; NB: we cannot use file.util now, for it is being compiled. |
| 20 |
(let1 sfxs (map (cut rxmatch->string #/\.[^\.]+$/ <>) |
| 21 |
(glob #"~|tname|.*")) |
| 22 |
(with-output-to-file file |
| 23 |
(^[] |
| 24 |
(print "static const char *ndbm_suffixes[] = {") |
| 25 |
(for-each (cut format #t " ~s,\n" <>) sfxs) |
| 26 |
(print " NULL") |
| 27 |
(print "};")))) |
| 28 |
(for-each sys-unlink (glob #"~|tname|.*"))))] |
| 29 |
[else (print "Usage: gosh ndbm-suffixes.scm <outfile>") (exit 1)]) |
| 30 |
0) |