#!/bin/bash
# Copyright (c) 1999 Fumitoshi UKAI <ukai@debian.or.jp>
# Copyright (c) 1999 Jacobo Tarrio Barreiro <jtarrio@iname.com>
# Copyright (c) 2001 SATO Satoru <ssato@redhat.com>
# This program is covered by the GNU General Public License version 2
#
# ChangeLog:
# * Fri Feb  9 2001 SATO Satoru <ssato@redhat.com>
# - ported from Debian sid
#
# * Fri Aug  9 2001 SATO Satoru <ssato@redhat.com>
# - the default rh's title page will be opened when empty URL is given for
#

## defaults
bindir=/usr/bin
ext="en"
w3m_bin=${bindir}/w3m-${ext}
http_home_dir="/usr/share/w3m"
http_home=${http_home_dir}/index-${ext}.html


[ -x ${bindir}/locale ] && eval `locale`
locale=${LC_ALL:-$LANG}

case X"$locale" in
 Xja|Xja_JP|Xja_JP.*)
    ext=ja
    ;;
 *)
    ext=en
    ;;
esac

[ -x ${bindir}/w3m-${ext} ] && w3m_bin=${bindir}/w3m-${ext}
[ -f ${http_home_dir}/index-${ext}.html ] && \
	http_home=${http_home_dir}/index-${ext}.html


## open http_home when empty URL is given for
if [ -f $http_home ]; then
  [ -z "$*" ] && exec $w3m_bin $http_home
fi


unset params
while [ $# -gt 0 ]
do
	case "$1" in
		-t | -l | -T | -bookmark | -cols | -ppc | -o | -config)
			params[${#params[@]}]="$1"
			params[${#params[@]}]="$2"
			shift ;;
		-* | +* | *://*)
			params[${#params[@]}]="$1"
			;;
		*)
			if [ -f "$1" -o -d "$1" ]
			then
				params[${#params[@]}]="$1"
			else
				params[${#params[@]}]="http://$1"
			fi ;;
	esac
	shift
done


exec $w3m_bin "${params[@]}"
