snarf-guile-m4-docs.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ;;; snarf-guile-m4-docs --- Parse guile.m4 comments for texi documentation
  2. ;; Copyright (C) 2002, 2006, 2011 Free Software Foundation, Inc.
  3. ;;
  4. ;; This program is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public License
  6. ;; as published by the Free Software Foundation; either version 3, or
  7. ;; (at your option) any later version.
  8. ;;
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this software; see the file COPYING.LESSER. If
  16. ;; not, write to the Free Software Foundation, Inc., 51 Franklin
  17. ;; Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. ;;; Author: Thien-Thi Nguyen <ttn@gnu.org>
  19. ;;; Commentary:
  20. ;; Usage: snarf-guile-m4-docs FILE
  21. ;;
  22. ;; Grep FILE for comments preceding macro definitions, massage
  23. ;; them into valid texi, and display to stdout. For each comment,
  24. ;; lines preceding "^# Usage:" are discarded.
  25. ;;
  26. ;; TODO: Generalize.
  27. ;;; Code:
  28. (define-module (scripts snarf-guile-m4-docs)
  29. :use-module (ice-9 rdelim)
  30. :export (snarf-guile-m4-docs))
  31. (define %include-in-guild-list #f)
  32. (define %summary "Snarf out texinfo documentation from .m4 files.")
  33. (define (display-texi lines)
  34. (display "@deffn {Autoconf Macro}")
  35. (for-each (lambda (line)
  36. (display (cond ((and (>= (string-length line) 2)
  37. (string=? "# " (substring line 0 2)))
  38. (substring line 2))
  39. ((string=? "#" (substring line 0 1))
  40. (substring line 1))
  41. (else line)))
  42. (newline))
  43. lines)
  44. (display "@end deffn")
  45. (newline) (newline))
  46. (define (prefix? line sub)
  47. (false-if-exception
  48. (string=? sub (substring line 0 (string-length sub)))))
  49. (define (massage-usage line)
  50. (let loop ((line (string->list line)) (acc '()))
  51. (if (null? line)
  52. (list (list->string (reverse acc)))
  53. (loop (cdr line)
  54. (cons (case (car line)
  55. ((#\( #\) #\,) #\space)
  56. (else (car line)))
  57. acc)))))
  58. (define (snarf-guile-m4-docs . args)
  59. (let* ((p (open-file (car args) "r"))
  60. (next (lambda () (read-line p))))
  61. (let loop ((line (next)) (acc #f))
  62. (or (eof-object? line)
  63. (cond ((prefix? line "# Usage:")
  64. (loop (next) (massage-usage (substring line 8))))
  65. ((prefix? line "AC_DEFUN")
  66. (display-texi (reverse acc))
  67. (loop (next) #f))
  68. ((and acc (prefix? line "#"))
  69. (loop (next) (cons line acc)))
  70. (else
  71. (loop (next) #f)))))))
  72. (define main snarf-guile-m4-docs)
  73. ;;; snarf-guile-m4-docs ends here