From: Rudolf Polzer Date: Thu, 5 Apr 2012 15:22:39 +0000 (+0200) Subject: detected unmatched #if/#else/#endif X-Git-Tag: xonotic-v0.7.0~58 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-maps.pk3dir.git;a=commitdiff_plain;h=99d49dcf855e05cd807575a79e3421e7bcdbc165;ds=sidebyside detected unmatched #if/#else/#endif --- diff --git a/scripts/shader-cpp.sh b/scripts/shader-cpp.sh index 28890ae3..4d0d4d85 100755 --- a/scripts/shader-cpp.sh +++ b/scripts/shader-cpp.sh @@ -7,6 +7,13 @@ case "$0" in esac . ./shader-parser.subr +set -e + +err() +{ + echo >&2 "(EE) $*" + exit 1 +} LF=" " @@ -71,47 +78,58 @@ shaderkill() } preprocess() { - condstack= - echo "$shadertext" | while IFS= read -r L; do - [ -n "$L" ] || continue - set -- $L - k=$1 - shift - case "$k" in - '#if') - case "$LF$conds$LF" in - *"$LF$*$LF"*) - condstack=0$condstack - ;; - *) - condstack=1$condstack - ;; - esac - ;; - '#else') - case "$condstack" in - 0*) - condstack=1${condstack#0} - ;; - 1*) - condstack=0${condstack#1} - ;; - esac - ;; - '#endif') - condstack=${condstack#?} - ;; - *) - case "$condstack" in - *0*) - ;; - *) - echo "${L% }" - ;; - esac - ;; - esac - done + echo "$shadertext" | { + condstack= + while IFS= read -r L; do + [ -n "$L" ] || continue + set -- $L + k=$1 + shift + case "$k" in + '#if') + case "$LF$conds$LF" in + *"$LF$*$LF"*) + condstack=0$condstack + ;; + *) + condstack=1$condstack + ;; + esac + ;; + '#else') + if [ -z "$condstack" ]; then + err "unmatched #else" + fi + case "$condstack" in + 0*) + condstack=1${condstack#0} + ;; + 1*) + condstack=0${condstack#1} + ;; + esac + ;; + '#endif') + if [ -z "$condstack" ]; then + err "unmatched #endif" + fi + condstack=${condstack#?} + ;; + *) + case "$condstack" in + *0*) + ;; + *) + echo "${L% }" + ;; + esac + ;; + esac + done + if [ -n "$condstack" ]; then + err "unmatched #if" + fi + } } conditionalize() {