#!/bin/sh
# $Id: openbsd,v 1.1.1.1 2003/08/01 09:07:52 bagpuss Exp $
# elvis: openbsd		-- Search OpenBSD related information (www.openbsd.org)
. surfraw || exit 1

w3_config_hook () {
defyn   SURFRAW_openbsd_mail	no
defyn   SURFRAW_openbsd_pr	no
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search-string | PR-number]
Description:
  Surfraw search OpenBSD related information
Local options:
  -mail[=(yes|no)]		Search OpenBSD mailinglists
  				Default: $SURFRAW_openbsd_mail
  				Environment: SURFRAW_openbsd_mail
  -pr[=(yes|no)]		Query Problem Reports
  				Default: $SURFRAW_openbsd_pr
  				Environment: SURFRAW_openbsd_pr
Examples:
  $w3_argv0 			Teleport to the OpenBSD website
  $w3_argv0 mycroft		Search OpenBSD website for odeur de mycroft
  $w3_argv0 -mail  		Teleport to the mail-index Query form
  $w3_argv0 -mail proff		Search mailing-list archives for odeur de proff
  $w3_argv0 -pr			Query Problem Report form
  $w3_argv0 -pr 666		Display PR 666
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-mail)	setoptyn	SURFRAW_openbsd_mail		yes	;;
	-mail=*) setoptyn	SURFRAW_openbsd_mail		$optarg	;;
	-pr)	setoptyn	SURFRAW_openbsd_pr		yes	;;
	-pr=*)	setoptyn	SURFRAW_openbsd_pr		$optarg	;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
test -z "$w3_args" || escaped_args=`w3_url_of_arg $w3_args`

if ok SURFRAW_openbsd_pr; then
    if test -z "$escaped_args"; then
        w3_browse_url "http://cvs.openbsd.org/cgi-bin/wwwgnats.pl"
    else
        w3_browse_url "http://cvs.openbsd.org/cgi-bin/wwwgnats.pl/full?pr=${escaped_args}"
    fi
    exit $?
fi
if ok SURFRAW_openbsd_mail; then
    if test -z "$escaped_args"; then
        w3_browse_url "http://www.openbsd.org/mail.html"
    else
	w3_browse_url "http://groups.google.com/groups?q=group%3Amailing.openbsd.*+${escaped_args}&hl=en"
    fi
    exit $?
fi
if test -z "$escaped_args"; then
    w3_browse_url "http://www.openbsd.org/"
else
    w3_browse_url "http://www.google.com/search?q=site:openbsd.org+${escaped_args}"
fi
exit $?
