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