#!/bin/sh
# $Id: debpackages,v 1.2 2001/12/23 10:15:18 proff Exp $
# elvis: debpackages	-- Search debian packages (packages.debian.org)
. surfraw || exit 1

w3_config_hook () {
def   SURFRAW_debian_release all
def   SURFRAW_debian_distro stable
def   SURFRAW_debian_search cgi-bin/search_packages.pl
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Surfraw search debian packages (packages.debian.org)
Local options:
  -release=			Specialized search on release
  	  all		|	all releases
  	  main		|	main release
  	  non-US	|	packages restricted in US
  	  contrib	|	contrib
  	  non-free	|	packages not meeting FSG
                                Default: $SURFRAW_debian_release
                                Environment: SURFRAW_debian_release
  -distro=                      Specific distribution
          stable        |       Stable
          testing       |       Testing
          unstable      |       Unstable
                                Default: $SURFRAW_debian_distro
                                Environment: SURFRAW_debian_distro
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-release=*) setopt   SURFRAW_debian_release $optarg	;;
	-distro=*)  setopt   SURFRAW_debian_distro  $optarg	;;
	*) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
if test -z "$w3_args"; then
    w3_browse_url "http://packages.debian.org/#search_packages"
else
    escaped_args=`w3_url_of_arg $w3_args`
    w3_browse_url "http://packages.debian.org/${SURFRAW_debian_search}?keywords=${escaped_args}&searchon=names&subword=1&version=${SURFRAW_debian_distro}&release=${SURFRAW_debian_release}"
fi
