| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# `unicode_lint.sh' determines whether source files under ${dirs} directories |
| 4 |
# contain Unicode characters, and fails if any do. |
| 5 |
# |
| 6 |
# We don't recommend to call this script directly. |
| 7 |
# Instead of it, use `make lint-unicode` via root directory Makefile. |
| 8 |
|
| 9 |
# ${dirs} : target directories |
| 10 |
dirs=(./ ./cli ./tests ./tests/bench ./tests/collisions) |
| 11 |
|
| 12 |
SCRIPT_DIR="`dirname "${BASH_SOURCE[0]}"`" |
| 13 |
cd ${SCRIPT_DIR}/.. |
| 14 |
|
| 15 |
echo "Ensure no unicode character is present in source files *.{c,h}" |
| 16 |
pass=true |
| 17 |
|
| 18 |
# Scan each directory in ${dirs} for Unicode in source (*.c, *.h) files |
| 19 |
i=0 |
| 20 |
while [ $i -lt ${#dirs[@]} ] |
| 21 |
do |
| 22 |
dir=${dirs[$i]} |
| 23 |
echo dir=$dir |
| 24 |
result=$( |
| 25 |
find ${dir} -regex '.*\.\(c\|h\)$' -exec grep -P -n "[^\x00-\x7F]" {} \; -exec echo "{}: FAIL" \; |
| 26 |
) |
| 27 |
if [[ $result ]]; then |
| 28 |
echo "$result" |
| 29 |
pass=false |
| 30 |
fi |
| 31 |
i=`expr $i + 1` |
| 32 |
done |
| 33 |
|
| 34 |
|
| 35 |
# Result |
| 36 |
if [ "$pass" = true ]; then |
| 37 |
echo "All tests successful: no unicode character detected" |
| 38 |
echo "Result: PASS" |
| 39 |
exit 0 |
| 40 |
else |
| 41 |
echo "Result: FAIL" |
| 42 |
exit 1 |
| 43 |
fi |