#!/bin/bash

# read the input *.vcxproj
if [ "$1" == "" ]; then
    exit 0
fi
CONTENT=`cat $1`

# extract all cpp files
PATTERN='<ClCompile[[:space:]]+Include="(\$\(MSBuildThisFileDirectory\))?([^"]+.cpp)"[[:space:]]*/?[[:space:]]*>'
COMPILES=`echo "${CONTENT}" | grep -E "${PATTERN}"`
CPPS=`echo "${COMPILES}" | sed -E -e 's%[[:space:]]*'${PATTERN}'[[:space:]]*%\2%g'`

# refine file names
CPPS=`echo "${CPPS}" | sed -e 's%[\]%/%g'`
CPPS=`echo "${CPPS}" | sed -e 's%^%'${PWD}/$(dirname $1)/'%g'`
if [ "$(uname -s)" == "Darwin" ]; then
    REALPATH=grealpath
else
    REALPATH=realpath
fi
echo "${CPPS}" | while read -r CPP; do
    "${REALPATH}" --relative-to="${PWD}" "${CPP}"
done
