texi-fragments-to-docstrings 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. ;;; -*- mode: scheme; coding: utf-8; -*-
  2. ;;;
  3. ;;; Copyright (C) 2013 Free Software Foundation, Inc.
  4. ;;;
  5. ;;; This library is free software; you can redistribute it and/or
  6. ;;; modify it under the terms of the GNU Lesser General Public
  7. ;;; License as published by the Free Software Foundation; either
  8. ;;; version 3 of the License, or (at your option) any later version.
  9. ;;;
  10. ;;; This library 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 library; if not, write to the Free Software
  17. ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. ;;;
  19. ;;; Read Texinfo fragments from stdin (docstrings of Guile's primitives
  20. ;;; in the format of `guile-procedures.texi'), and write to stdout a
  21. ;;; textual rendering thereof. The output preserves page breaks (^L)
  22. ;;; found in the input, as per the Guile Documentation Format
  23. ;;; version 2---see (ice-9 documentation).
  24. ;;;
  25. (use-modules (texinfo)
  26. (texinfo plain-text)
  27. (srfi srfi-1)
  28. (ice-9 match)
  29. (rnrs io ports))
  30. (define (docstring-fragments->strings str)
  31. "Return the list resulting from the split of STR at each page
  32. break (^L)"
  33. (string-tokenize str (char-set-complement (char-set #\page))))
  34. (match (command-line)
  35. ((_ texi-file)
  36. (let* ((fragments (remove (compose string-null? string-trim-both)
  37. (call-with-input-file texi-file
  38. (compose docstring-fragments->strings
  39. get-string-all))))
  40. (stexi (map texi-fragment->stexi fragments)))
  41. (format #t "Produced by GNU Guile ~a from `~a'.~%~%"
  42. (version) texi-file)
  43. (for-each (lambda (stexi)
  44. (display #\page)
  45. (display (stexi->plain-text stexi)))
  46. stexi)))
  47. ((command args ...)
  48. (format (current-error-port) "invalid arguments: ~s~%" args)
  49. (format (current-error-port) "Usage: ~a TEXINFO-FILE~%" command)
  50. (exit 1)))