snarf-guile-m4-docs 3.0 KB

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