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, 2010, 2011 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
)
27 #:use-module ((srfi srfi-1) #:select (fold append-map)))
29 ;; Hack to provide scripts with the bug-report address.
30 (module-define
! the-scm-module
31 '%guile-bug-report-address
32 "@PACKAGE_BUGREPORT@")
35 (define (display-help)
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 (display-version)
46 (format #t "guile-tools (GNU Guile ~A) ~A
47 Copyright (C) 2010 Free Software Foundation, Inc.
48 License LGPLv3+: GNU LGPL version 3 or later <http://gnu.org/licenses/lgpl.html>
49 This is free software: you are free to change and redistribute it.
50 There is NO WARRANTY, to the extent permitted by law.
51 " (version) (effective-version)))
53 (define (directory-files dir)
54 (if (and (file-exists? dir) (file-is-directory? dir))
55 (let ((dir-stream (opendir dir)))
56 (let loop ((new (readdir dir-stream))
62 (loop
(readdir dir-stream
)
63 (if (or
(string
=?
"." new
) ; ignore
64 (string
=?
".." new
)) ; ignore
69 (define (strip-extensions path)
72 (string-suffix? ext path)
74 (- (string-length path) (string-length ext)))))
75 (append %load-compiled-extensions %load-extensions)))
80 ((equal? (car l) (cadr l)) (unique (cdr l)))
81 (else (cons (car l) (unique (cdr l))))))
83 (define (find-submodules head)
84 (let ((shead (map symbol->string head)))
87 (append-map (lambda (path)
88 (fold (lambda (x rest)
89 (let ((stripped (strip-extensions x)))
90 (if stripped (cons stripped rest) rest)))
93 (fold (lambda
(x y
) (in-vicinity y x
)) path shead
))))
97 (define
(list-scripts
)
99 ;; would be nice to show a summary.
100 (format
#t "~A\n" x))
101 (find-submodules
'(scripts))))
103 (define (find-script s)
104 (let ((m (resolve-module (append '(scripts
) (list
(string-
>symbol s
))))))
105 (and
(module-public-interface m
)
109 (setlocale LC_ALL
"")
111 ((or
(equal?
(cdr args
) '())
112 (equal? (cdr args) '("list")))
114 ((string-prefix?
"-" (cadr args
))
115 (let ((option
(cadr args
)))
117 ((equal? option
"--help")
120 ((equal? option
"--version")
124 (format
(current-error-port
) "Unrecognized option: ~an" option
)
127 (let ((mod
(find-script
(cadr args
))))
128 (exit (apply
(module-ref mod
'main) (cddr args)))))))