display-commentary.scm 2.3 KB

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