#!/bin/sh
# Do not echo anything because some scripts use the output as input"
usage()
{
echo
echo "usage: $0 <command> <from dir[+<field>|to dir[+]<field>> <bom file>"
echo
echo "examples: $0 "p4 sync" //build/$CODELINE/ jar.bom"
echo " will do like 'p4 sync //build/oware31/lib/oware.jar'"
echo " $0 sum d:/work/jarfiles jar.bom"
echo " will do like 'sum d:/work/jarfiles/lib/oware.jar'"
echo " $0 "cp -pr" d:/work/build+* d:/work/release raw.bom"
echo " will do like 'cp -pr d:/work/build/lib/* d:/work/release/lib'"
echo
}
if [ "$DEBUG" = 0 ]
then
set -vx
fi
dir1=`echo $2 | awk -F+ '{print $1}'`
dir1plus=`echo $2 | awk -F+ '{print $2}'`
dir2=`echo $3 | awk -F+ '{print $1}'`
dir2plus=`echo $3 | awk -F+ '{print $2}'`
# add / if missing
echo $dir1 | grep \/$ || dir1=$dir1/
echo $dir2 | grep \/$ || dir2=$dir2/
if [ $# -gt 4 -o $# -lt 3 ]
then
echo
echo error: incorrect number of parameters passed to bom_operator
usage
exit 1
elif [ $# -eq 3 ]
then
# Process unary commands
bom=$3
awk -v v1="$1" -v v2="$dir1" -v v3="$dir1plus" '{print v1,v2$1v3";\n"}' $3 >/tmp/oper.x
stat=$?
else
# Process binary commands
bom=$4
awk -v v1="$1" -v v2="$dir1" -v v3="$dir1plus" -v v4="$dir2" -v v5="$dir2plus" '{print v1,v2$1v3,v4$1v5";\n"}' $4 > /tmp/oper.x
stat=$?
fi
. /tmp/oper.x
stat=`expr $stat + $?`
rm -f /tmp/oper.x
exit $stat