# $Id$ --*- sh -*-- # Copyright (C) 2003 Enrico Scholz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. _VS_LOGFILE= _VS_ERRFILE= _VS_NEWLINE=' ' declare -r _VS_NEWLINE=${_VS_NEWLINE:0-1} function findObject { local mod=$1 local var=$2 local file= local i=X shift 2 for i; do test "$i" || continue test ! $mod "$i" || { file=$i; break; } done test -z "$i" -o "$file" || { echo "Can not find file for '$var'; aborting" exit 1 } >&2 eval "$var=\"$file\"" } function findFile { findObject -f "$@" } function findDir { findObject -d "$@" } function findAndCopy { local dst=$1 test ! -s "$dst" || return 0 local tmp shift findFile tmp "$@" test "$tmp" -a -s "$tmp" || return 0 cp -af "$tmp" "$dst" } function getPhysicalDir { ( set -P && cd "$1" && pwd ) } ## Usage: logging function logging { if test "$_VS_LOGFILE"; then echo "$@" >>"$_VS_LOGFILE" else echo "$@" fi } ## Usage: warning function warning { if test "$_VS_ERRFILE"; then echo "$@" >>"$_VS_ERRFILE" else echo "$@" >&2 fi } ## Usage: panic function panic { if test "$_VS_ERRFILE"; then echo "$@" >>"$_VS_ERRFILE" else echo "$@" >&2 fi exit 1 } ## Usage: execute function execute { test -z "${DEBUG_EXEC:-}" || echo "$@" test "${DEBUG_EXEC:-}" = noexec || exec "$@" exit 0 } ## Usage: isNumber function isNumber { local tmp let tmp=$1+0 2>/dev/null || test -z "${1//0/}" -a "$1" || return 1 return 0 } ## Usage: colorize