#!/bin/sh
# if there is an argument, find maxima_toc.html

if [ "$OSTYPE" = "cygwin" ] ; then EXT='.bat'; else EXT=''; fi
MAXIMA=`which maxima$EXT 2>/dev/null`
if [ $? -eq 0 ]
then
  if [ "$OSTYPE" = "cygwin" ]
  then
    if [ "$1" ]
    then
      maxima -d | grep -F 'maxima-htmldir=' | \
        sed -e 's/maxima-htmldir=/"/' -e 's|$|/maxima_toc.html"|' | \
	cygpath -f -
    else
      echo '("cygwin")'
    fi
  else
    if [ "$1" ]
    then
      maxima -d | grep -F 'maxima-htmldir=' |\
        sed -e 's/maxima-htmldir=/"/' -e 's|$|/maxima_toc.html"|'
    else
      echo '('
      maxima --list-avail |\
        grep '^version [A-Za-z0-9\.][A-Za-z0-9\.]*, lisp [A-Za-z0-9][A-Za-z0-9]*$' |\
        sed -e 's/^version \([A-Za-z0-9\.][A-Za-z0-9\.]*\), lisp \([A-Za-z0-9][A-Za-z0-9]*\)$/"\1 \2"/'
      echo ')'
    fi
  fi
else
  # maxima not found
  echo '#f'
fi
