2024-03-14 07:09:49 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
## SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
|
|
##
|
|
|
|
## SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
##
|
|
|
|
## Finds Unicode recursively and prints in hexadecimal format.
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2024-08-06 12:15:24 -04:00
|
|
|
command -v git >/dev/null ||
|
|
|
|
{ printf '%s\n' "Missing program: git" >&2; exit 1; }
|
2024-07-10 08:36:05 -04:00
|
|
|
repo_toplevel="$(git rev-parse --show-toplevel)"
|
|
|
|
test -d "${repo_toplevel}" || exit 1
|
2024-07-19 09:29:17 -04:00
|
|
|
cd "${repo_toplevel}"
|
2024-07-10 08:36:05 -04:00
|
|
|
unset repo_toplevel
|
2024-03-14 07:09:49 -04:00
|
|
|
|
|
|
|
files=""
|
|
|
|
if test -n "${1-}"; then
|
|
|
|
files="${*}"
|
|
|
|
if test -z "${files}"; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-08-06 12:15:24 -04:00
|
|
|
files="$(printf '%s\n' "${files}" | sort -u)"
|
2024-03-14 07:09:49 -04:00
|
|
|
# shellcheck disable=SC2086
|
|
|
|
unicode_match="$(grep -oPrHn --exclude-dir=.git --exclude-dir=LICENSES \
|
2024-07-08 11:26:34 -04:00
|
|
|
-e "[^\x00-\x7F]" -- ${files} || true)"
|
2024-03-14 07:09:49 -04:00
|
|
|
|
|
|
|
match_found=""
|
|
|
|
if test -n "${unicode_match}"; then
|
|
|
|
for line in ${unicode_match}; do
|
2024-08-06 12:15:24 -04:00
|
|
|
line_file="$(printf '%s\n' "${line}" | cut -d ":" -f1)"
|
2024-03-14 07:09:49 -04:00
|
|
|
case "${line_file}" in
|
|
|
|
git/*|LICENSES/*|.reuse/dep5|*.asc) continue;;
|
2024-07-10 08:36:05 -04:00
|
|
|
*) ;;
|
2024-03-14 07:09:49 -04:00
|
|
|
esac
|
2024-08-06 12:15:24 -04:00
|
|
|
line_number="$(printf '%s\n' "${line}" | cut -d ":" -f2)"
|
|
|
|
line_unicode="$(printf '%s\n' "${line}" | cut -d ":" -f3 | od -A n -vt c)"
|
|
|
|
printf '%s\n' "${line_file}:${line_number}:${line_unicode}"
|
2024-03-14 07:09:49 -04:00
|
|
|
match_found="1"
|
|
|
|
done
|
|
|
|
if test "${match_found}" = 1; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 0
|