Fix parsing @args.rsp compiler arguments

This commit is contained in:
Orivej Desh 2017-04-25 09:31:06 +00:00
parent 9f0de9522f
commit e9adf383e6

View File

@ -23,26 +23,55 @@ badPath() {
"${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP" "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP"
} }
expandResponseParams() { # @args.rsp parser.
local inparams=("$@") # Char classes: space, other, backslash, single quote, double quote.
local n=0 # States: 0 - outside, 1/2 - unquoted arg/slash, 3/4 - 'arg'/slash, 5/6 - "arg"/slash.
local p # State transitions:
params=() rspT=(01235 01235 11111 33413 33333 55651 55555)
while [ $n -lt ${#inparams[*]} ]; do # Push char on transition:
p=${inparams[n]} rspC[01]=1 rspC[11]=1 rspC[21]=1 rspC[33]=1 rspC[43]=1 rspC[55]=1 rspC[65]=1
case $p in
@*) rspParse() {
if [ -e "${p:1}" ]; then rsp=()
args=$(<"${p:1}") local s="$1"
eval 'for arg in '${args//$/\\$}'; do params+=("$arg"); done' local state=0
else local arg=''
params+=("$p")
fi for (( i=0; i<${#s}; i++ )); do
;; local c="${s:$i:1}"
*) local cls=1
params+=("$p") case "$c" in
;; ' ' | $'\t' | $'\r' | $'\n') cls=0 ;;
'\') cls=2 ;;
"'") cls=3 ;;
'"') cls=4 ;;
esac esac
n=$((n + 1)) local nextstates="${rspT[$state]}"
local nextstate="${nextstates:$cls:1}"
if [ "${rspC[$state$nextstate]}" ]; then
arg+="$c"
elif [ "$state$nextstate" = "10" ]; then
rsp+=("$arg")
arg=''
fi
state="$nextstate"
done
if [ "$state" -ne 0 ]; then
rsp+=("$arg")
fi
}
expandResponseParams() {
params=()
while [ $# -gt 0 ]; do
local p="$1"
shift
if [ "${p:0:1}" = '@' -a -e "${p:1}" ]; then
rspParse "$(<"${p:1}")"
set -- "${rsp[@]}" "$@"
else
params+=("$p")
fi
done done
} }