add figl/parse.scm
[clinton/guile-figl.git] / figl / parse.scm
1 ;;; figl
2 ;;; Copyright (C) 2013 Andy Wingo <wingo@pobox.com>
3 ;;;
4 ;;; Figl is free software: you can redistribute it and/or modify it
5 ;;; under the terms of the GNU Lesser General Public License as
6 ;;; published by the Free Software Foundation, either version 3 of the
7 ;;; License, or (at your option) any later version.
8 ;;;
9 ;;; Figl is distributed in the hope that it will be useful, but WITHOUT
10 ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 ;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 ;;; Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU Lesser General Public
15 ;;; License along with this program. If not, see
16 ;;; <http://www.gnu.org/licenses/>.
17
18 ;;; Commentary:
19 ;;
20 ;; figl is the Foreign Interface to GL.
21 ;;
22 ;;; Code:
23
24 (define-module (figl parse)
25 #:use-module (figl config)
26 #:use-module (sxml simple)
27 #:use-module (ice-9 ftw)
28 #:export ())
29
30 (define *man-sections*
31 '("man2" "man3" "man4"))
32
33 (define *namespaces*
34 '((mml . "http://www.w3.org/1998/Math/MathML")))
35
36 (define *entities*
37 '())
38
39 (define (default-entity-handler port name)
40 (format (current-warning-port)
41 "~a:~a:~a: undefined entitity: &~a;\n"
42 (or (port-filename port) "<unknown file>")
43 (port-line port) (port-column port)
44 name)
45 (symbol->string name))
46
47 (define (parse-man-xml section filename)
48 (call-with-input-file (in-vicinity (upstream-man-pages)
49 (in-vicinity section filename))
50 (lambda (port)
51 (xml->sxml port #:namespaces *namespaces* #:declare-namespaces? #t
52 #:entities *entities*
53 #:default-entity-handler default-entity-handler))))
54
55 (define (xml-files section)
56 (scandir (in-vicinity (upstream-man-pages) section)
57 (lambda (x) (string-suffix? ".xml" x))))
58