2 # aside from this initial boilerplate, this is actually -*- scheme -*- code
3 main
='(module-ref (resolve-module '\''(scripts snarf-guile-m4-docs)) '\'main
')'
4 exec ${GUILE-guile} -l $0 -c "(apply $main (cdr (command-line)))" "$@"
6 ;;; snarf-guile-m4-docs
--- Parse guile.
m4 comments
for texi documentation
8 ;; Copyright
(C
) 2002 Free Software Foundation
, Inc.
10 ;; This program is free software
; you can redistribute it and
/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation
; either version
2, or
13 ;; (at your option
) any later version.
15 ;; This program is distributed
in the hope that it will be useful
,
16 ;; but WITHOUT ANY WARRANTY
; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License
for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this software
; see the
file COPYING. If not
, write to
22 ;; the Free Software Foundation
, Inc.
, 51 Franklin Street
, Fifth Floor
,
23 ;; Boston
, MA
02110-1301 USA
25 ;;; Author
: Thien-Thi Nguyen
<ttn@gnu.org
>
29 ;; Usage
: snarf-guile-m4-docs FILE
31 ;; Grep FILE
for comments preceding macro definitions
, massage
32 ;; them into valid texi
, and display to stdout. For each comment
,
33 ;; lines preceding
"^# Usage:" are discarded.
39 (define-module
(scripts snarf-guile-m4-docs
)
40 :use-module
(ice-9 rdelim
)
41 :export (snarf-guile-m4-docs
))
43 (define
(display-texi lines
)
44 (display
"@deffn {Autoconf Macro}")
45 (for-each
(lambda
(line
)
46 (display
(cond
((and
(>= (string-length line
) 2)
47 (string
=?
"# " (substring line
0 2)))
49 ((string
=?
"#" (substring line
0 1))
54 (display
"@end deffn")
57 (define
(prefix? line sub
)
59 (string
=? sub
(substring line
0 (string-length sub
)))))
61 (define
(massage-usage line
)
62 (let loop
((line
(string-
>list line
)) (acc
'()))
64 (list (list->string (reverse acc)))
66 (cons (case (car line)
67 ((#\( #\) #\,) #\space)
71 (define (snarf-guile-m4-docs . args)
72 (let* ((p (open-file (car args) "r"))
73 (next (lambda () (read-line p))))
74 (let loop ((line (next)) (acc #f))
75 (or (eof-object? line)
76 (cond ((prefix? line "# Usage:")
77 (loop (next) (massage-usage (substring line 8))))
78 ((prefix? line "AC_DEFUN")
79 (display-texi (reverse acc))
81 ((and acc (prefix? line "#"))
82 (loop (next) (cons line acc)))
84 (loop (next) #f)))))))
86 (define main snarf-guile-m4-docs)
88 ;;; snarf-guile-m4-docs ends here