Blame doc/extract-guile-c-doc.scm

Packit aea12f
;;; extract-c-doc.scm  --  Output Texinfo from "snarffed" C files.
Packit aea12f
;;;
Packit aea12f
;;; Copyright 2006-2012 Free Software Foundation, Inc.
Packit aea12f
;;;
Packit aea12f
;;;
Packit aea12f
;;; This program is free software; you can redistribute it and/or modify
Packit aea12f
;;; it under the terms of the GNU General Public License as published by
Packit aea12f
;;; the Free Software Foundation; either version 3 of the License, or
Packit aea12f
;;; (at your option) any later version.
Packit aea12f
;;;
Packit aea12f
;;; This program is distributed in the hope that it will be useful,
Packit aea12f
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit aea12f
;;; GNU General Public License for more details.
Packit aea12f
;;;
Packit aea12f
;;; You should have received a copy of the GNU General Public License
Packit aea12f
;;; along with this program; if not, write to the Free Software
Packit aea12f
;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
Packit aea12f
Packit aea12f
;;; Written by Ludovic Courtès <ludo@chbouib.org>.
Packit aea12f
Packit aea12f
(use-modules (system documentation c-snarf)
Packit aea12f
             (system documentation output)
Packit aea12f
Packit aea12f
             (srfi srfi-1))
Packit aea12f
Packit aea12f
(define (main file cpp+args cpp-flags . procs)
Packit aea12f
  ;; Arguments:
Packit aea12f
  ;;
Packit aea12f
  ;; 1. C file to be processed;
Packit aea12f
  ;; 2. how to invoke the CPP (e.g., "cpp -E");
Packit aea12f
  ;; 3. additional CPP flags (e.g., "-I /usr/local/include");
Packit aea12f
  ;; 4. optionally, a list of Scheme procedure names whose documentation is
Packit aea12f
  ;;    to be output.  If no such list is passed, then documentation for
Packit aea12f
  ;;    all the Scheme functions available in the C source file is issued.
Packit aea12f
  ;;
Packit aea12f
  (let* ((cpp+args  (string-tokenize cpp+args))
Packit aea12f
         (cpp       (car cpp+args))
Packit aea12f
         (cpp-flags (append (cdr cpp+args)
Packit aea12f
                            (string-tokenize cpp-flags)
Packit aea12f
                            (list "-DSCM_MAGIC_SNARF_DOCS "))))
Packit aea12f
    ;;(format (current-error-port) "cpp-flags: ~a~%" cpp-flags)
Packit aea12f
    (format (current-error-port) "extracting Texinfo doc from `~a'...  "
Packit aea12f
            file)
Packit aea12f
Packit aea12f
    ;; Don't mention the name of C functions.
Packit aea12f
    (*document-c-functions?* #f)
Packit aea12f
Packit aea12f
    (let ((proc-doc-list
Packit aea12f
           (run-cpp-and-extract-snarfing file cpp cpp-flags)))
Packit aea12f
      (display "@c Automatically generated, do not edit.\n")
Packit aea12f
      (display (string-concatenate
Packit aea12f
                (map procedure-texi-documentation
Packit aea12f
                     (if (null? procs)
Packit aea12f
                         proc-doc-list
Packit aea12f
                         (filter (lambda (proc-doc)
Packit aea12f
                                   (let ((proc-name
Packit aea12f
                                          (assq-ref proc-doc
Packit aea12f
                                                    'scheme-name)))
Packit aea12f
                                     (member proc-name procs)))
Packit aea12f
                                 proc-doc-list))))))
Packit aea12f
    (format (current-error-port) "done.~%")
Packit aea12f
    (exit 0)))
Packit aea12f
Packit aea12f
Packit aea12f
;;; Local Variables:
Packit aea12f
;;; mode: scheme
Packit aea12f
;;; coding: latin-1
Packit aea12f
;;; End: