#!/bin/sh
#
# Time-stamp: <2007/06/22 13:58:26 BST luca@gismo.pca.it>
#
# make-pdf.sh -- generate ParenScript documentation from lisp sources
#                via the pbook.py script and pdflatex
#
# (C) 2006 Luca Capello <luca@pca.it> http://luca.pca.it
#
# 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, or (at your option)
# any later version.
#
# You can find the GPL at /usr/share/common-licenses/GPL


USR_SHARE="/usr/share"
USR_DOC="$USR_SHARE/doc/cl-parenscript/scripts"
USR_SOURCE="$USR_SHARE/common-lisp/source/parenscript"

usage () {
    echo "Usage: sh $0 \$FILE \$OUTPUT_FOLDER"
    echo
    echo "\$FILE is one of introduction.lisp, reference.lisp or tutorial.lisp."
    echo
    echo "If not specified, \$OUTPUT_FOLDER is equal to \$HOME."
    echo
    echo "You need the texlive-latex-base, texlive-latex-recommended,"
    echo "texlive-fonts-recommended and python packages."
    echo
    exit 1
}

test -x /usr/bin/pdflatex || usage
test -x /usr/bin/python || usage
test ! -z $1 || usage

LISP_FILE="introduction.lisp reference.lisp tutorial.lisp"
for ARG1 in $LISP_FILE; do
    if test "$1" == "$ARG1"; then
        CONTINUE=1
    fi
done
test "$CONTINUE" == "1" || usage

PDF_OUTPUT="`basename $1 .lisp`.pdf"
if test -z $2; then
    OUTPUT="$HOME/$PDF_OUTPUT"
else
    OUTPUT="$OUTPUT/$PDF_OUTPUT"
fi

cp -f $USR_DOC/pbook.py.gz /tmp/
gunzip /tmp/pbook.py.gz
python /tmp/pbook.py -o $OUTPUT $USR_SOURCE/docs/$1
rm -rf /tmp/pbook.py

exit 0
