#!/bin/bash

BROWSER_CMD=""

if [ "${DISPLAY}" != "" ] ; then
    if ( which links | grep -q -G -e "^/usr" ) ; then
        BROWSER_CMD="links -g" ;
    elif ( which konqueror | grep -q -G -e "^/opt" ) ; then
        BROWSER_CMD="konqueror" ;
    elif ( which konqueror | grep -q -G -e "^/usr" ) ; then
        BROWSER_CMD="konqueror" ;
    elif ( which opera | grep -q -G -e "^/opt" ) ; then
        BROWSER_CMD="opera" ;
    elif ( which opera | grep -q -G -e "^/usr" ) ; then
        BROWSER_CMD="opera" ;
    elif ( which firefox | grep -q -G -e "^/usr" ) ; then
        BROWSER_CMD="firefox" ;
    elif ( which lynx | grep -q -G -e "^/usr" ) ; then
        BROWSER_CMD="lynx" ;
    fi ;
else
    if ( which links | grep -q -G -e "^/usr" ) ; then
        BROWSER_CMD="links" ;
    elif ( which lynx | grep -q -G -e "^/usr" ) ; then
        BROWSER_CMD="lynx" ;
    fi ;
fi

if [ "${BROWSER_CMD}" == "" ] ; then
    echo -e "No browser was found !"
    exit -1 ;
fi

if [ "$#" == "0" ] ; then
    echo -e -n "Opcode name: "
    read OPNAME ;
else
    OPNAME="${1}" ;
fi

exec ${BROWSER_CMD} "/usr/local/share/doc/csound/manual/${OPNAME}.html"

