#!/bin/sh set -eu src="${TMPDIR-/tmp}/mcpu-cpp-scan-$$.c" out="${TMPDIR-/tmp}/mcpu-cpp-scan-$$.out" err="${TMPDIR-/tmp}/mcpu-cpp-scan-$$.err" bom="${TMPDIR-/tmp}/mcpu-cpp-bom-$$.c" nul="${TMPDIR-/tmp}/mcpu-cpp-nul-$$.c" trap 'rm -f "$src" "$out" "$err" "$bom" "$nul"' EXIT HUP INT TERM cat > "$src" <<'EOT' const char *a = "/* not a comment"; #lang "diff" y' = 1; const char *b = "*/ still not a comment"; #endlang const char *c = "// not a comment"; /* real comment starts here #lang "alg" */ int c_side; EOT "$MCPU_CPP" --no-config "$src" -o "$out" grep '#lang "diff"' "$out" >/dev/null grep "y' = 1" "$out" >/dev/null grep 'int c_side' "$out" >/dev/null # UTF-8 BOM is accepted and removed at the external text boundary. printf '\357\273\277int bom_ok;\n' > "$bom" "$MCPU_CPP" --no-config "$bom" -o "$out" grep 'int bom_ok' "$out" >/dev/null # Embedded NUL is not text and must never be silently truncated. printf 'int before;\000int after;\n' > "$nul" if "$MCPU_CPP" --no-config "$nul" -o "$out" 2>"$err"; then exit 1 fi grep 'NUL character is not allowed' "$err" >/dev/null