3 exec guile
$GUILE_FLAGS -e '(@@ (guile-tools) main)' -s "$0" "$@"
6 ;;;; guile-tools
--- running scripts bundled with Guile
7 ;;;; Jim Blandy
<jim@red-bean.com
> --- September
1997
9 ;;;; Copyright
(C
) 1998, 2001, 2004, 2005, 2006, 2008, 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
2.1 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 Software
23 ;;;; Foundation
, Inc.
, 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301 USA
25 (define-module
(guile-tools
))
27 ;; We can
't import srfi-1, unfortunately, as we are used early in the
28 ;; boot process, before the srfi-1 shlib is built.
30 (define (fold kons seed seq)
33 (fold kons (kons (car seq) seed) (cdr seq))))
37 Usage: guile-tools --version
39 guile-tools PROGRAM [ARGS]
41 If PROGRAM is \"list\" or omitted, display available scripts, otherwise
42 PROGRAM is run with ARGS.
45 (define (directory-files dir)
46 (if (and (file-exists? dir) (file-is-directory? dir))
47 (let ((dir-stream (opendir dir)))
48 (let loop ((new (readdir dir-stream))
54 (loop
(readdir dir-stream
)
55 (if (or
(string
=?
"." new
) ; ignore
56 (string
=?
".." new
)) ; ignore
61 (define (strip-extensions path)
64 (string-suffix? ext path)
66 (- (string-length path) (string-length ext)))))
67 (append %load-compiled-extensions %load-extensions)))
72 ((equal? (car l) (cadr l)) (unique (cdr l)))
73 (else (cons (car l) (unique (cdr l))))))
76 (define (append-map f l)
77 (apply append (map f l)))
79 (define (find-submodules head)
80 (let ((shead (map symbol->string head)))
83 (append-map (lambda (path)
84 (fold (lambda (x rest)
85 (let ((stripped (strip-extensions x)))
86 (if stripped (cons stripped rest) rest)))
89 (fold (lambda
(x y
) (in-vicinity y x
)) path shead
))))
93 (define
(list-scripts
)
95 ;; would be nice to show a summary.
97 (find-submodules
'(scripts))))
99 (define (find-script s)
100 (let ((m (resolve-module (append '(scripts
) (list
(string-
>symbol s
))))))
101 (and
(module-public-interface m
)
105 (if (or
(equal?
(cdr args
) '())
106 (equal? (cdr args) '("list")))
108 (let ((mod
(find-script
(cadr args
))))
109 (exit (apply
(module-ref mod
'main) (cddr args))))))