%if !defined("NOSTDFUNC")
%if defined("INCLUDE")
. alanestd || exit 255
%else
############################################################
ALANESTD_VERSION="1.76"
############################################################
ALANESTD_VERSION="$Revision: 1.76 $"
ORIGDIR=$(/bin/pwd); export ORIGDIR
APPNAME=${0##*/};APPNAME=${APPNAME#-}; export APPNAME
test -z "$TMPDIR" && TMPDIR=/tmp; export TMPDIR
test -z "$HOSTNAME" && HOSTNAME=$(hostname); export HOSTNAME
OS=$(uname -s); OSREV=$(uname -r); export OS OSREV
true ${UID:=$(id|sed -e 's|^[^=]*=\([0-9]*\).*$|\1|')}
warn() { echo "[$APPNAME:$$]" "****" "$@";}
status() { echo "[$APPNAME:$$]" "===>" "$@";}
error() { echo "[$APPNAME:$$]" "ERROR:" "$@";}
die() { echo "[$APPNAME:$$]" "FATAL:" "$@"; exit 1;}
unset echo_n; test "X`echo -n`" = "X-n" \
    && echo_n() { echo "$@\c"; } || echo_n() { echo -n "$@"; }
status_n() { echo_n "[$APPNAME:$$]" "===>" "$@";}
log() { local cmd=$1;shift;echo_n $(date "+%Y%m%d.%T") "";$cmd "$@";}
qexpr() { expr "$@" >/dev/null 2>&1;}
qwd() { echo \""$@"\"; }
qws() { echo \'"$@"\'; }
qwfunc=qwd; export qwfunc
qw() { $qwfunc "$@"; }
listfiles() { ls -1 ${1:+"$@"} 2>/dev/null; }
whichre() { local n=$#; local s="$1"; shift; while test $# -ge 1; do 
	qexpr "$s" : "$1"&& echo $(($n - $#)) && return 0; shift; done; 
    	echo 0; return 1;}
matchre() { test $(whichre "$@") -gt 0; }
streq() { local s="$1"; shift; while test $# -ge 1; do 
	test "X$s" = "X$1" && return 0; shift; done; return 1;}
strtest() { expr "$1" "$2" "$3" >/dev/null 2>&1; }
strupper() {
    echo "$@"|tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
}
strlower() {
    echo "$@"|tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
}
Tommy_mode() { exec <$DEVNULL >$DEVNULL 2>&1; }
chdir() { cd "$1" || die cd $(qw $1) failed; }
absdir() { chdir "$1" && pwd; }
abspath() { local p=''; case "$1" in /*);; *)p="$(pwd)/";; esac; echo "$p$1"; }
case $OS in 
    *BSD) tmpfile() { mktemp -t .$APPNAME ${1:+"$@"}; };;
    *) tmpfile() { local b=$TMPDIR/.$APPNAME.$$. i=0 istr=''
	    while true; do istr=$(printf "%3d" $i | tr ' ' '0')
		test ! -f $b$istr && break; i=$(( $i + 1 )); done
	    cat /dev/null >$b$istr; echo $b$istr; };;
esac # case $OS
ask() {
    local d='' p=''
    case "$1" in -*) d=${1#-}; shift;; esac
    case "$1" in +*) v=${1#+}; shift;; *) return 254;; esac
    case $# in 0) return 255;; esac
    p=${d:+"[ENTER=$d]"}; REPLY=''
    while echo_n "$@" "($v) $p? "; do
	read REPLY; case "${REPLY:=$d}" in [$v]) break;; esac
    done; return 0
}
askyn() {
    local d=''
    case "$1" in -*) d=${1#-}; shift;; esac
    ask ${d:+-$d} +yYnN "$@"
    case $REPLY in [yY]) return 0;; esac; return 1
}
%endif # defined("INCLUDE")
%endif # !defined("NOSTDFUNC")
############################################################
# show version and exit
############################################################
VERSION='$Revision: 1.1.1.1 $'
VERSION=${VERSION#* }; VERSION=${VERSION% *}
version_() { 
    echo "This is '$APPNAME' v. $VERSION."
    echo "Copyright (c) <:YEAR> <:OWNER> <<:EMAIL>>."; echo
}
version() { version_; exit $1; }
############################################################
# show usage and exit
############################################################
usage() {
    version_
    cat <<EOF
Usage:	$APPNAME [options] [--] [args]
Options:
	-h,--help	Show this help.
	-V,--version	Show version number.
	-v,--verbose	Produce more verbose output.
	-x,--debug	Turn on shell command tracing.
	--		Stop option processing.
EOF
    exit $1
}
############################################################
# set default vars here
############################################################
DEBUG=0
VERBOSE=0
VFLG=''
# opt vars
#
############################################################
# do command line options
############################################################
while test $# -gt 0; do
    n=1; case "$1" in
	-h|--help) usage 0;;
	-V|--version) version 0;;
	-v|--verbose) VERBOSE=1;VFLG='-v';;
	-x|--debug) set -x;DEBUG=1;;
	# extra options here
	#
	# catch end-of-opts and bad opt
	--) shift; break;; -*) usage 1;; *) break;;
    esac; shift $n
done

############################################################
# main(): script execution begins here
############################################################

