blob: 773968fc94693ac10975d51e2394756d6fb0fb82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/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
|