#!/bin/sh
# elvis: sourceforge	-- Search SourceForge (www.sourceforge.net)
# $Id$
. surfraw || exit 1

# version 0.2 ianb@erislabs.net 20030910
# added -exact and -type

# version 0.1
# this great work has been achieved by Caiaphas Pechorin (caiaphas@operamail.com)

w3_config_hook () {
defyn SURFRAW_sourceforge_exact       no
def   SURFRAW_sourceforge_searchtype  soft
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Surfraw search SourceForge (www.sourceforge.net)
Local options:
  -exact=yes|no                 Require all words
                                Default: $SURFRAW_sourceforge_exact
                                Environment: SURFRAW_sourceforge_exact
  -type=
          soft         |        Software / Group
          people       |        People
          freshmeat             Freshmeat
                                Default: $SURFRAW_sourceforge_searchtype
                                Environment: SURFRAW_sourceforge_searchtype
EOF
    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
	-e*=*)      setoptyn SURFRAW_sourceforge_exact     $optarg ;;
	-e*)        setoptyn SURFRAW_sourceforge_exact     yes     ;;
	-t*=*)      setopt SURFRAW_sourceforge_searchtype  $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://www.sourceforge.net/"
else
    escaped_args=`w3_url_of_arg $w3_args`
	if  `yesno SURFRAW_sourceforge_exact` 
	then
		isexact=1
	else
		isexact=0
	fi
    w3_browse_url "http://sourceforge.net/search/?words=${escaped_args}&exact=$isexact&type_of_search=$SURFRAW_sourceforge_searchtype"
fi
