3 exec guile
$GUILE_FLAGS -e '(@@ (guile-tools) main)' -s "$0" "$@"
6 ;;;; guile-tools
--- running scripts bundled with Guile
7 ;;;; Andy Wingo
<wingo@pobox.com
> --- April
2009
9 ;;;; Copyright
(C
) 2009 Free Software Foundation
, Inc.
11 ;;;; This library is free software
; you can redistribute it and
/or
12 ;;;; modify it under the terms of the GNU Lesser General Public
13 ;;;; License as published by the Free Software Foundation
; either
14 ;;;; version
3 of the License
, or
(at your option
) any later version.
16 ;;;; This library is distributed
in the hope that it will be useful
,
17 ;;;; but WITHOUT ANY WARRANTY
; without even the implied warranty of
18 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;;;; Lesser General Public License
for more details.
21 ;;;; You should have received a copy of the GNU Lesser General Public
22 ;;;; License along with this library
; if not
, write to the Free
23 ;;;; Software Foundation
, Inc.
, 51 Franklin Street
, Fifth Floor
,
24 ;;;; Boston
, MA
02110-1301 USA
26 (define-module
(guile-tools
))
28 ;; Hack to provide scripts with the bug-report address.
29 (module-define
! the-scm-module
30 '%guile-bug-report-address
31 "@PACKAGE_BUGREPORT@")
34 ;; We can't import srfi-1
, unfortunately
, as we are used early
in the
35 ;; boot process
, before the srfi-1 shlib is built.
37 (define
(fold kons seed
seq)
40 (fold kons
(kons
(car
seq) seed
) (cdr
seq))))
44 Usage: guile-tools --version
46 guile-tools PROGRAM [ARGS]
48 If PROGRAM is \"list\" or omitted, display available scripts, otherwise
49 PROGRAM is run with ARGS.
52 (define
(directory-files dir
)
53 (if (and
(file-exists? dir
) (file-is-directory? dir
))
54 (let ((dir-stream
(opendir dir
)))
55 (let loop
((new
(readdir dir-stream
))
61 (loop (readdir dir-stream)
62 (if (or (string=? "." new) ; ignore
63 (string=? ".." new)) ; ignore
68 (define
(strip-extensions path
)
71 (string-suffix? ext path
)
73 (- (string-length path
) (string-length ext
)))))
74 (append
%load-compiled-extensions
%load-extensions
)))
79 ((equal?
(car l
) (cadr l
)) (unique
(cdr l
)))
80 (else (cons
(car l
) (unique
(cdr l
))))))
83 (define
(append-map f l
)
84 (apply append
(map f l
)))
86 (define
(find-submodules
head)
87 (let ((shead
(map symbol-
>string
head)))
90 (append-map
(lambda
(path
)
91 (fold (lambda
(x rest
)
92 (let ((stripped
(strip-extensions x
)))
93 (if stripped
(cons stripped rest
) rest
)))
96 (fold (lambda (x y) (in-vicinity y x)) path shead))))
100 (define (list-scripts)
101 (for-each (lambda (x)
102 ;; would be nice to show a summary.
103 (format #t "~A\n" x))
104 (find-submodules '(scripts
))))
106 (define
(find-script s
)
107 (let ((m
(resolve-module
(append
'(scripts) (list (string->symbol s))))))
108 (and (module-public-interface m)
112 (if (or (equal? (cdr args) '())
113 (equal?
(cdr args
) '("list")))
115 (let ((mod (find-script (cadr args))))
116 (exit (apply (module-ref mod 'main
) (cddr args
))))))