Imported Upstream version 3.0.21
[platform/upstream/gnutls.git] / doc / extract-guile-c-doc.scm
1 ;;; extract-c-doc.scm  --  Output Texinfo from "snarffed" C files.
2 ;;;
3 ;;; Copyright 2006-2012 Free Software Foundation, Inc.
4 ;;;
5 ;;;
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
10 ;;;
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19
20 ;;; Written by Ludovic Courtès <ludo@chbouib.org>.
21
22 (use-modules (system documentation c-snarf)
23              (system documentation output)
24
25              (srfi srfi-1))
26
27 (define (main file cpp+args cpp-flags . procs)
28   ;; Arguments:
29   ;;
30   ;; 1. C file to be processed;
31   ;; 2. how to invoke the CPP (e.g., "cpp -E");
32   ;; 3. additional CPP flags (e.g., "-I /usr/local/include");
33   ;; 4. optionally, a list of Scheme procedure names whose documentation is
34   ;;    to be output.  If no such list is passed, then documentation for
35   ;;    all the Scheme functions available in the C source file is issued.
36   ;;
37   (let* ((cpp+args  (string-tokenize cpp+args))
38          (cpp       (car cpp+args))
39          (cpp-flags (append (cdr cpp+args)
40                             (string-tokenize cpp-flags)
41                             (list "-DSCM_MAGIC_SNARF_DOCS "))))
42     ;;(format (current-error-port) "cpp-flags: ~a~%" cpp-flags)
43     (format (current-error-port) "extracting Texinfo doc from `~a'...  "
44             file)
45
46     ;; Don't mention the name of C functions.
47     (*document-c-functions?* #f)
48
49     (let ((proc-doc-list
50            (run-cpp-and-extract-snarfing file cpp cpp-flags)))
51       (display "@c Automatically generated, do not edit.\n")
52       (display (string-concatenate
53                 (map procedure-texi-documentation
54                      (if (null? procs)
55                          proc-doc-list
56                          (filter (lambda (proc-doc)
57                                    (let ((proc-name
58                                           (assq-ref proc-doc
59                                                     'scheme-name)))
60                                      (member proc-name procs)))
61                                  proc-doc-list))))))
62     (format (current-error-port) "done.~%")
63     (exit 0)))
64
65
66 ;;; Local Variables:
67 ;;; mode: scheme
68 ;;; coding: latin-1
69 ;;; End: