#! /bin/sh
exec ../src/sizzle -s $0 $*
!#
;; scripts/make-autoloads.scm
;;
;; Copyright (C) 2000 Martin Grabmueller <mgrabmue@cs.tu-berlin.de>
;;
;; This is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; 
;; This software is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;; 
;; You should have received a copy of the GNU General Public License
;; along with this package; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.  

;; This scripts generates autoload statements for all top-level
;; defines in the given scheme script.
;;
;; Right now, only definitions of the form
;;   (define x (lambda ... ))
;; and
;;   (define (x) ... )
;; are recognized.  More complicated defines, such as function
;; definitions in let-constructs can not be recognized without
;; evaluation, and that could cause unwanted side effects.

(define (help)
  (display "Usage: make-autoloads.scm [-h] [--help] FILE\n"))

(define (make-autoload expr filename)
  (if (and (pair? expr) (eq? (car expr) 'define))
      (cond ((and (= (length expr) 3)
		  (pair? (caddr expr))
		  (symbol? (cadr expr))
		  (eq? (car (caddr expr)) 'lambda))
	     (display "(autoload '")
	     (display (cadr expr))
	     (display " ")
	     (write filename)
	     (display ")")
	     (newline))
	    ((and (> (length expr) 1)
		  (pair? (cadr expr))
		  (symbol? (car (cadr expr))))
	     (display "(autoload '")
	     (display (car (cadr expr)))
	     (display " ")
	     (write filename)
	     (display ")")
	     (newline))
	    (else #t))))

(define (make-autoloads in-port filename)
  (let loop ((expr (read in-port)))
    (cond ((eof-object? expr) #t)
	  (else (make-autoload expr filename) (loop (read in-port))))))

(define (handle-command-line command-line)
  (cond ((or (< (length command-line) 2)
	     (member "-h" command-line)
	     (member "--help" command-line))
	 (help))
	(else 
	 (for-each (lambda (x) (make-autoloads (open-input-file x) x))
		   (cdr command-line)))))

(handle-command-line (command-line))

