#!/bin/sh
# $Id: netbsd,v 1.2 2001/12/23 10:15:19 proff Exp $
# elvis: netbsd		-- Search NetBSD related information (www.netbsd.org)
. surfraw || exit 1

w3_config_hook () {
defyn   SURFRAW_netbsd_mail	no
defyn   SURFRAW_netbsd_pr	no
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search-string | PR-number]
Description:
  Surfraw search NetBSD related information
Local options:
  -mail[=(yes|no)]		Search netbsd mailinglists
  				Default: $SURFRAW_netbsd_mail
  				Environment: SURFRAW_netbsd_mail
  -pr[=(yes|no)]		Query Problem Reports
  				Default: $SURFRAW_netbsd_pr
  				Environment: SURFRAW_netbsd_pr
Examples:
  $w3_argv0 			Teleport to the NetBSD website
  $w3_argv0 mycroft		Search NetBSD 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_netbsd_mail		yes	;;
	-mail=*) setoptyn	SURFRAW_netbsd_mail		$optarg	;;
	-pr)	setoptyn	SURFRAW_netbsd_pr		yes	;;
	-pr=*)	setoptyn	SURFRAW_netbsd_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_netbsd_pr; then
    if test -z "$escaped_args"; then
        w3_browse_url "http://www.netbsd.org/Misc/query-pr.html"
    else
        w3_browse_url "http://www.NetBSD.org/cgi-bin/query-pr-single.pl?number=${escaped_args}"
    fi
    exit $?
fi
if ok SURFRAW_netbsd_mail; then
    if test -z "$escaped_args"; then
        w3_browse_url "http://mail-index.netbsd.org/"
    else
	w3_browse_url "http://mail-index.netbsd.org/cgi-bin/htsearch?method=and&format=builtin-long&sort=score&config=htdig&words=${escaped_args}"
    fi
    exit $?
fi
if test -z "$escaped_args"; then
    w3_browse_url "http://www.netbsd.org/"
else
    w3_browse_url "http://www.google.com/custom?q=${escaped_args}&cof=LW%3A247%3BL%3Ahttp%3A%2F%2Fwww.netbsd.org%2Fimages%2FNetBSD-smaller.jpg%3BLH%3A241%3BAH%3Acenter%3BAWFID%3A4f6b0499f0f58d2c%3B&domains=netbsd.org&sitesearch=netbsd.org"
fi
exit $?
