portability B)

This commit is contained in:
Emma Tebibyte 2022-11-12 03:11:20 -05:00
parent 359b6897a7
commit 31d8bb1fd6
2 changed files with 35 additions and 3 deletions

26
\ Normal file
View File

@ -0,0 +1,26 @@
#!/bin/sh
set -e
# check usage
if ! test -n "$1"; then
printf "Usage: %s [file...]\n" "$0" 1>&2
exit 64 # sysexits(3) EX_USAGE
fi
# check if we have rg(1); if not, use find(1) and sed(1) instead
if ! command -v rg >/dev/null 2>&1; then
files="$(find "$PWD" -name "$1")"
for file in $files; do
if ! test -n \
"$(sed -n \
'\|Copyright\|p' \
<"$file")"
then
! test "$file" = "$1" && printf "%s\n" "$file"
fi
done
else
rg --multiline --files-without-match --glob "$1" --pcre2 \
'(?<!\n)((//)|(#)) Copyright \(c\) \d+ [A-z, ]+\n((//)|(#)) SPDX-License-Identifier: .*\n'
fi

View File

@ -8,10 +8,16 @@ if ! test -n "$1"; then
exit 64 # sysexits(3) EX_USAGE
fi
# check if we have rg(1)
# check if we have rg(1); if not, use find(1) and sed(1) instead
if ! command -v rg >/dev/null 2>&1; then
printf "%s: Missing dependency: rg(1)\n" "$0" 1>&2
exit 69 # sysexits(3) EX_UNAVAILABLE
files="$(find "$PWD" -name "$1")"
for file in $files; do
if ! test -n \
"$(sed -n '\|// SPDX-License-Identifier: .*|p' <"$file")"
then
! test "$file" = "$1" && printf "%s\n" "$file"
fi
done
else
rg --multiline --files-without-match --glob "$1" --pcre2 \
'(?<!\n)((//)|(#)) Copyright \(c\) \d+ [A-z, ]+\n((//)|(#)) SPDX-License-Identifier: .*\n'