#!/bin/sh
# http://en.opensuse.org/YaST/yastdoc
self=`basename $0`
if [ "$1" = "--prefix" -o "$1" = "-p" ]; then
    shift
    PREFIX="$1"
    shift
fi
# run the tools that are in the same prefix as we are
if [ -z "$PREFIX" ]; then
    PREFIX=${0%/bin/$self}
fi

YASTDOCDIR=$PREFIX/share/doc/yastdoc/html

browse() {
    w3m "$@"
}

Q="${1-index}"

#ls -r is a heuristic to prefer the ycp section
for SECTIONDIR in `ls -dr $YASTDOCDIR/*`; do
    F="$SECTIONDIR/${Q//::/\/}.html"
    if [ -f "$F" ]; then
	browse "$F"
	break
    fi
done
