| 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 | \f |
| 20 | ;;; |
| 21 | ;;; Read Texinfo fragments from stdin (docstrings of Guile's primitives |
| 22 | ;;; in the format of `guile-procedures.texi'), and write to stdout a |
| 23 | ;;; textual rendering thereof. The output preserves page breaks (^L) |
| 24 | ;;; found in the input, as per the Guile Documentation Format |
| 25 | ;;; version 2---see (ice-9 documentation). |
| 26 | ;;; |
| 27 | |
| 28 | (use-modules (texinfo) |
| 29 | (texinfo plain-text) |
| 30 | (srfi srfi-1) |
| 31 | (ice-9 match) |
| 32 | (rnrs io ports)) |
| 33 | |
| 34 | (define (docstring-fragments->strings str) |
| 35 | "Return the list resulting from the split of STR at each page |
| 36 | break (^L)" |
| 37 | (string-tokenize str (char-set-complement (char-set #\page)))) |
| 38 | |
| 39 | (match (command-line) |
| 40 | ((_ texi-file) |
| 41 | (let* ((fragments (remove (compose string-null? string-trim-both) |
| 42 | (call-with-input-file texi-file |
| 43 | (compose docstring-fragments->strings |
| 44 | get-string-all)))) |
| 45 | (stexi (map texi-fragment->stexi fragments))) |
| 46 | (format #t "Produced by GNU Guile ~a from `~a'.~%~%" |
| 47 | (version) texi-file) |
| 48 | (for-each (lambda (stexi) |
| 49 | (display #\page) |
| 50 | (display (stexi->plain-text stexi))) |
| 51 | stexi))) |
| 52 | ((command args ...) |
| 53 | (format (current-error-port) "invalid arguments: ~s~%" args) |
| 54 | (format (current-error-port) "Usage: ~a TEXINFO-FILE~%" command) |
| 55 | (exit 1))) |