Commit | Line | Data |
---|---|---|
d928d47f TTN |
1 | ;;; snarf-guile-m4-docs --- Parse guile.m4 comments for texi documentation |
2 | ||
a1a2ed53 | 3 | ;; Copyright (C) 2002, 2006, 2011 Free Software Foundation, Inc. |
d928d47f TTN |
4 | ;; |
5 | ;; This program is free software; you can redistribute it and/or | |
83ba2d37 NJ |
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 | |
d928d47f TTN |
8 | ;; (at your option) any later version. |
9 | ;; | |
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 | |
83ba2d37 | 13 | ;; Lesser General Public License for more details. |
d928d47f | 14 | ;; |
83ba2d37 NJ |
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 | |
d928d47f TTN |
19 | |
20 | ;;; Author: Thien-Thi Nguyen <ttn@gnu.org> | |
21 | ||
22 | ;;; Commentary: | |
23 | ||
24 | ;; Usage: snarf-guile-m4-docs FILE | |
25 | ;; | |
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. | |
29 | ;; | |
30 | ;; TODO: Generalize. | |
31 | ||
32 | ;;; Code: | |
33 | ||
34 | (define-module (scripts snarf-guile-m4-docs) | |
35 | :use-module (ice-9 rdelim) | |
36 | :export (snarf-guile-m4-docs)) | |
37 | ||
a1a2ed53 AW |
38 | (define %include-in-guild-list #f) |
39 | (define %summary "Snarf out texinfo documentation from .m4 files.") | |
40 | ||
d928d47f TTN |
41 | (define (display-texi lines) |
42 | (display "@deffn {Autoconf Macro}") | |
43 | (for-each (lambda (line) | |
27c54e0b NJ |
44 | (display (cond ((and (>= (string-length line) 2) |
45 | (string=? "# " (substring line 0 2))) | |
46 | (substring line 2)) | |
47 | ((string=? "#" (substring line 0 1)) | |
48 | (substring line 1)) | |
49 | (else line))) | |
d928d47f TTN |
50 | (newline)) |
51 | lines) | |
52 | (display "@end deffn") | |
53 | (newline) (newline)) | |
54 | ||
55 | (define (prefix? line sub) | |
56 | (false-if-exception | |
57 | (string=? sub (substring line 0 (string-length sub))))) | |
58 | ||
59 | (define (massage-usage line) | |
60 | (let loop ((line (string->list line)) (acc '())) | |
61 | (if (null? line) | |
62 | (list (list->string (reverse acc))) | |
63 | (loop (cdr line) | |
64 | (cons (case (car line) | |
65 | ((#\( #\) #\,) #\space) | |
66 | (else (car line))) | |
67 | acc))))) | |
68 | ||
fb380779 | 69 | (define (snarf-guile-m4-docs . args) |
d928d47f TTN |
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)) | |
78 | (loop (next) #f)) | |
79 | ((and acc (prefix? line "#")) | |
80 | (loop (next) (cons line acc))) | |
81 | (else | |
82 | (loop (next) #f))))))) | |
83 | ||
84 | (define main snarf-guile-m4-docs) | |
85 | ||
86 | ;;; snarf-guile-m4-docs ends here |