# -*-mode: shell-script-*- # # mkbody-inc.sh # # Copyright (c) 2002 Alan Eldridge. # All rights reserved. # # # 2002/09/26 alane@geeksrus.net # ############################################################ ALANESTD_VERSION="1.73" ############################################################ 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;} qw() { echo \""$@"\"; } 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 } 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 ############################################################ # show usage and exit ############################################################ usage() { cat <"body.inc@sh" echo "%if !defined(\"NOSTDFUNC\")" echo "%if defined(\"INCLUDE\")" echo ". alanestd || exit 255" echo "%else" include /home/alane/sw/bin/alanestd echo "%endif # defined(\"INCLUDE\")" echo "%endif # !defined(\"NOSTDFUNC\")" cat <<"EOFEOF" ############################################################ # 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 <