#!/usr/local/bin/snow -f
;;;;							-*- scheme -*-
;;;;
;;;; d o c 2 t e x i			-- Build texi file from documentation
;;;; 
;;;; Copyright  2000 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;; 
;;;; 
;;;; This program 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 of the License, or
;;;; (at your option) any later version.
;;;; 
;;;; This program 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 program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
;;;; USA.
;;;; 
;;;;           Author: Erick Gallesio [eg@unice.fr]
;;;;    Creation date: 11-Apr-2000 12:12 (eg)
;;;; Last file update: 11-Apr-2000 12:47 (eg)
;;;;

(require "regexp")

(define rgxp (string->regexp "\\|([^|]+)\\|"))

(define (rewrite-definition def)
  (regexp-replace-all rgxp def "@t{\\1}"))


(define (generate in)
  (do ((l (read in) (read in)))
      ((eof-object? l))
    (let ((type (get-keyword :type (cdr l)))
	  (syn  (get-keyword :synopsys (cdr l)))
	  (def  (get-keyword :description (cdr l))))
      (format #t "@deffn ~A ~A\n" type syn)
      (format #t "~A\n" (rewrite-definition def))
      (format #t "@end deffn\n")))
  (close-input-port in))


(define (main files)
  (format #t "@c Automatically generated. DO NOT EDIT!  -*-texinfo-*-\n\n")
  (for-each (lambda (f) (generate (open-input-file f)))
	    files)
  (format #t "@ EOF\n"))

(main *argv*)

