#/bin/sh

set -e

for i in libburn libisofs libisoburn;
do
   N=defaultN
   if   [ -d $i/.svn ]; then
       N=`svn info $i | grep Revision | awk '{print $2}'`
   elif [ -d $i/.bzr ]; then
       N=`bzr info $i -v | grep -A1 Branch | tail -1 | awk '{print $1}'`
   else
       printf "UNKNOWN VCS\n"
       exit 1
   fi

   B=$i-rev${N}
   LOG=log
   ALL=all
   O=${B}-${ALL}.${LOG}

   date -u            >  ${O}
   cppcheck --version >> ${O}
   echo -e "----------------------------" >> ${O}
   cppcheck --template '{id}:{file}:{line} - {message} - {severity}' \
            --suppressions-list=suppressed.in \
            --enable=all \
	    -f -v -I $i/$i -I $i $i      2>> ${O}
   echo -e "----------------------------" >> ${O}

   # grep might return 0 or 1, ignore it rather than abruptly quiting
   set +e

   STY=sty
   grep -s "\- style$" ${O} > ${B}-${STY}.${LOG}

   ERR=err
   grep -s "\- error$" ${O} > ${B}-${ERR}.${LOG}

   set -e

done

