Andreas Wacknitz
2024-03-31 783118944874d559e30eea1600352e3feb5263a7
tools/license-detector
@@ -19,17 +19,19 @@
function usage
{
   [[ -n "$1" ]] && printf "ERROR: %s\n\n" "$1" >&2
   printf "Usage: license-detector [-d] LICENSE_FILE\n" >&2
   printf "Usage: license-detector [-d] [-l LICENSE] LICENSE_FILE\n" >&2
   [[ -n "$1" ]] && exit 1
   exit 0
}
DEBUG=0
while getopts ":hd" OPT ; do
LICENSE="*"
while getopts ":hdl:" OPT ; do
   case "$OPT" in
   "?"|"h")   usage ;;
   "d")      DEBUG=1 ;;
   "l")      LICENSE="*.$OPTARG" ;;
   esac
done
shift $((OPTIND - 1))
@@ -69,7 +71,7 @@
[[ -z "$TMPFILE" ]] && printf "ERROR: Temporary file creation failed\n" >&2 && exit 1
typeset -A matched
for l in "$WS_TOOLS"/licenses/* ; do
for l in "$WS_TOOLS"/licenses/$LICENSE ; do
   [[ -f "$l" ]] || continue
   # skip filters
   [[ "$l" != "${l%.filter}" ]] && continue
@@ -87,13 +89,21 @@
   cat <<#EOF > "$TMPFILE"
      dos2unix -ascii \\
         | tr -d '\\014' \\
         | LC_ALL=C sed -E -e 's/^[[:space:]]+\$//g' \\
         | awk '/^#/{next}/^\$/{\$0="\n"}1' ORS=' ' \\
         | sed -E -e 's/[[:space:]]+/ /g' -e 's/^ //' -e 's/ \$//' -e '/^\$/d' \\
         | LC_ALL=C sed -E -e 's/[[:space:]]+/ /g' -e 's/^ //' -e 's/ \$//' -e '/^\$/d' \\
   EOF
   # Remove some reStructuredText markup
   if [[ "${F%.rst}" != "$F" ]] ; then
      cat <<#EOF >> "$TMPFILE"
            | sed -e '/^\*\*\$/d' -e 's/^\*\*\([^*]\)/\1/' -e 's/\([^*]\)\*\*\$/\1/' -e 's/\([^*]\)\*\*\([^*]\)/\1\2/g' \\
      EOF
   fi
   # Apply filter if any
   [[ -x "$l.filter" ]] && printf '\t| LC_ALL=C %s \\\n' "$l.filter" >> "$TMPFILE"
   cat <<#EOF >> "$TMPFILE"
         | LC_ALL=C tr '[:upper:]' '[:lower:]' \\
         | sed -e 's|http://|https://|g' \
         | tr ' ' '\\n' | fmt
   EOF