]> git.donarmstrong.com Git - lilypond.git/blob - guile18/scripts/display-commentary
Import guile-1.8 as multiple upstream tarball component
[lilypond.git] / guile18 / scripts / display-commentary
1 #!/bin/sh
2 # aside from this initial boilerplate, this is actually -*- scheme -*- code
3 main='(module-ref (resolve-module '\''(scripts display-commentary)) '\'main')'
4 exec ${GUILE-guile} -l $0 -c "(apply $main (cdr (command-line)))" "$@"
5 !#
6 ;;; display-commentary --- As advertized
7
8 ;;      Copyright (C) 2001, 2006 Free Software Foundation, Inc.
9 ;;
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or
13 ;; (at your option) any later version.
14 ;;
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this software; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301 USA
24
25 ;;; Author: Thien-Thi Nguyen
26
27 ;;; Commentary:
28
29 ;; Usage: display-commentary REF1 REF2 ...
30 ;;
31 ;; Display Commentary section from REF1, REF2 and so on.
32 ;; Each REF may be a filename or module name (list of symbols).
33 ;; In the latter case, a filename is computed by searching `%load-path'.
34
35 ;;; Code:
36
37 (define-module (scripts display-commentary)
38   :use-module (ice-9 documentation)
39   :export (display-commentary))
40
41 (define (display-commentary-one file)
42   (format #t "~A commentary:\n~A" file (file-commentary file)))
43
44 (define (module-name->filename-frag ls) ; todo: export or move
45   (let ((ls (map symbol->string ls)))
46     (let loop ((ls (cdr ls)) (acc (car ls)))
47       (if (null? ls)
48           acc
49           (loop (cdr ls) (string-append acc "/" (car ls)))))))
50
51 (define (display-module-commentary module-name)
52   (cond ((%search-load-path (module-name->filename-frag module-name))
53          => (lambda (file)
54               (format #t "module ~A\n" module-name)
55               (display-commentary-one file)))))
56
57 (define (display-commentary . refs)
58   (for-each (lambda (ref)
59               (cond ((string? ref)
60                      (if (equal? 0 (string-index ref #\())
61                          (display-module-commentary
62                           (with-input-from-string ref read))
63                          (display-commentary-one ref)))
64                     ((list? ref)
65                      (display-module-commentary ref))))
66             refs))
67
68 (define main display-commentary)
69
70 ;;; display-commentary ends here