1 ;;; snarf-guile-m4-docs --- Parse guile.m4 comments for texi documentation
3 ;; Copyright (C) 2002, 2006, 2011 Free Software Foundation, Inc.
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU Lesser General Public License
7 ;; as published by the Free Software Foundation; either version 3, or
8 ;; (at your option) any later version.
10 ;; This program 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.
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with this software; see the file COPYING.LESSER. If
17 ;; not, write to the Free Software Foundation, Inc., 51 Franklin
18 ;; Street, Fifth Floor, Boston, MA 02110-1301 USA
20 ;;; Author: Thien-Thi Nguyen <ttn@gnu.org>
24 ;; Usage: snarf-guile-m4-docs FILE
26 ;; Grep FILE for comments preceding macro definitions, massage
27 ;; them into valid texi, and display to stdout. For each comment,
28 ;; lines preceding "^# Usage:" are discarded.
34 (define-module (scripts snarf-guile-m4-docs)
35 :use-module (ice-9 rdelim)
36 :export (snarf-guile-m4-docs))
38 (define %include-in-guild-list #f)
39 (define %summary "Snarf out texinfo documentation from .m4 files.")
41 (define (display-texi lines)
42 (display "@deffn {Autoconf Macro}")
43 (for-each (lambda (line)
44 (display (cond ((and (>= (string-length line) 2)
45 (string=? "# " (substring line 0 2)))
47 ((string=? "#" (substring line 0 1))
52 (display "@end deffn")
55 (define (prefix? line sub)
57 (string=? sub (substring line 0 (string-length sub)))))
59 (define (massage-usage line)
60 (let loop ((line (string->list line)) (acc '()))
62 (list (list->string (reverse acc)))
64 (cons (case (car line)
65 ((#\( #\) #\,) #\space)
69 (define (snarf-guile-m4-docs . args)
70 (let* ((p (open-file (car args) "r"))
71 (next (lambda () (read-line p))))
72 (let loop ((line (next)) (acc #f))
73 (or (eof-object? line)
74 (cond ((prefix? line "# Usage:")
75 (loop (next) (massage-usage (substring line 8))))
76 ((prefix? line "AC_DEFUN")
77 (display-texi (reverse acc))
79 ((and acc (prefix? line "#"))
80 (loop (next) (cons line acc)))
82 (loop (next) #f)))))))
84 (define main snarf-guile-m4-docs)
86 ;;; snarf-guile-m4-docs ends here