#!/usr/bin/env csi
(use posix regex-case regex)
(define (get-files #!optional (patt #f))
(let ((files (glob (or patt "*.scm"))))
files))
(define (get-deps fname #!optional (data #f))
(let ((hdat (or data (make-hash-table)))
(modname (string-substitute ".scm" "" fname)))
;; (print "Processing " fname)
(hash-table-set! hdat fname '())
(with-input-from-file fname
(lambda ()
(let loop ((l (read-line)))
(if (eof-object? l)
data
(begin
(regex-case
l
("^\\s*\\(import\\s+([^\\s]+)\\).*" (x md )
(print "\"" md "\" -> \"" modname "\";")))
(loop (read-line)))))))))
(define (do-all-mod-files)
(let ((modfiles (get-files "*mod.scm")))
(for-each
(lambda (mfile)
(print "// " mfile)
(get-deps mfile))
modfiles)))
(do-all-mod-files)
(exit)