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