#!/usr/bin/env mzscheme ; Copyright (C) 2007 Dave Griffiths ; ; 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. ;; auto documentation generator for fluxus ;; (c) 2006 Dave Griffiths ;; ;; parses helpmap scheme list files and converts all the ;; functions into texi formatted text #lang scheme/base (require scheme/file) (require scheme/path) (display "start\n") (define (build-menu helpmap output) (display "* " output) (display (caar helpmap) output) (display ":: " output) (display #\newline output) (if (null? (cdr helpmap)) 0 (build-menu (cdr helpmap) output))) (define (parse-helpmap helpmap output) (parse-section (car helpmap) output) (if (null? (cdr helpmap)) 0 (parse-helpmap (cdr helpmap) output))) (define (parse-section section output) ;(display section)(newline) (display "@node " output) (if (pair? section) (display (car section) output) (display section output)) (display #\newline output) (display "@chapter " output) (if (pair? section) (display (car section) output) (display section output)) (display #\newline output) (when (pair? section) (display (list-ref (cadr section) 0) output) (display #\newline output)) (display "@subsubheading Example" output) (display #\newline output) (display "@lisp" output) (display #\newline output) (when (pair? section) (display (list-ref (cadr section) 1) output) (display #\newline output)) (display "@end lisp" output) (display #\newline output) (when (and (pair? section) (pair? (car (list-ref (cadr section) 2)))) (parse-functions (list-ref (cadr section) 2) output))) (define (parse-functions funcmap output) (display "@section (" output) (display (car (car funcmap)) output) (let ((arguments (list-ref (list-ref (car funcmap) 1) 0))) (cond ((not (zero? (string-length arguments))) (display " " output) (display arguments output)))) (display ")" output) (display #\newline output) (display "@subsubheading Returns" output) (display #\newline output) (display (list-ref (list-ref (car funcmap) 1) 1) output) (display #\newline output) (display "@subsubheading Description" output) (display #\newline output) (display (list-ref (list-ref (car funcmap) 1) 2) output) (display #\newline output) (display "@subsubheading Example" output) (display #\newline output) (display "@lisp" output) (display #\newline output) (display (list-ref (list-ref (car funcmap) 1) 3) output) (display #\newline output) (display "@end lisp" output) (display #\newline output) (display #\newline output) (if (null? (cdr funcmap)) 0 (parse-functions (cdr funcmap) output))) (define (help->texi helpmapfilename texifilename boilerplatefilename) (let ((file (open-input-file helpmapfilename)) (outfile (open-output-file texifilename #:exists 'replace))) (let ((boilerplate (open-input-file boilerplatefilename))) (display (read-string 9999999 boilerplate) outfile) (display #\newline outfile) (close-input-port boilerplate)) (let ((helpmap (read file))) (display "@menu" outfile) (display #\newline outfile) (build-menu helpmap outfile) (display "@end menu" outfile) (display #\newline outfile) (parse-helpmap helpmap outfile) (close-output-port outfile)) (close-input-port file))) (help->texi "helpmap.scm" "fluxus-all.texi" "fluxus.texi")