#!/bin/sh
exec ${GUILE-guile} -s $0 "$@" # -*- scheme -*-
!#
;;; usage: mkexcuse NOTES-TDT

;; Copyright (C) 2005, 2008, 2009, 2011, 2013 Thien-Thi Nguyen
;;
;; 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 3 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., 51 Franklin Street, Fifth Floor,
;; Boston, MA  02110-1301  USA

(use-modules ((guile-baux common) #:select (fso))
             ((guile-baux text-db-table) #:select (read-text-db-table))
             ((srfi srfi-11) #:select (let-values))
             ((ice-9 common-list) #:select (uniq)))

(define META #f)
(define *notes* (let-values (((recs meta) (read-text-db-table
                                           (cadr (command-line)))))
                  (set! META meta)
                  recs))

(define (fln s . args)
  (apply fso s args)
  (newline))

(define (table title blurb get present)
  (fln "@section ~A" title)
  (newline)
  (and blurb (fln "~A\n" blurb))
  (fln "@table @code")
  (for-each present (if get (get) *notes*))
  (fln "@end table"))

(fln "@node Excuses")
(fln "@chapter Excuses")

(fln "
Here are some notes on interface elements from
@file{/usr/include/SDL/*.h} that are not yet
wrapped by Guile-SDL.  As things progress elements
will be removed until an irreducible set remains.

Interface elements have zero or more @dfn{attributes},
some of which indicate irreducibility (such as @code{probably-never}).
Following the attribute groupings are specific notes on those
elements that are particular in some way.  The presentation order
is not significant.
")

(table "Categories"
       (string-append
        "For brevity, we omit the @code{SDL_} prefix in the groupings.\n"
        "There are two speical cases: @code{(N)} stands for @code{SDLNet_},\n"
        "and @code{(M)} stands for @code{Mix_}.")
       (lambda ()
         (uniq (apply append (map (lambda (note)
                                    (assq-ref note #:attributes))
                                  *notes*))))
       (lambda (attr)
         (newline)
         (fln "@item ~A" attr)
         (newline)
         (for-each (lambda (s)
                     (fln "~A" s))
                   (assq-ref META attr))
         (newline)
         (fln "@verbatim")
         (let ((col 0))
           (for-each (lambda (note)
                       (and (memq attr (assq-ref note #:attributes))
                            (let* ((n (assq-ref note #:name))
                                   (s (symbol->string n))
                                   (len (1+ (string-length s))))
                              (cond ((char=? #\M (string-ref s 0))
                                     (fso "  (M)~A" (substring s 4)))
                                    ((char=? #\N (string-ref s 3))
                                     (fso "  (N)~A" (substring s 7)))
                                    (else
                                     (fso "  ~A" (substring s 4))))
                              (set! col (if (> 30 col)
                                            (+ col len)
                                            (begin
                                              (newline)
                                              0))))))
                     *notes*)
           (or (zero? col) (newline)))
         (fln "@end verbatim")))

(newline)

(table "Specific Notes" #f #f
       (lambda (note)
         (let ((s (assq-ref note #:notes)))
           (or (string-null? s)
               (begin
                 (newline)
                 (fln "@item ~A" (assq-ref note #:name))
                 (fln "@verbatim")
                 (fln "~A" s)
                 (fln "@end verbatim"))))))

;;; mkexcuse ends here
