diff --git a/util/fp-finder/spell.sh b/util/fp-finder/spell.sh old mode 100644 new mode 100755 index 77631d80c..bc51ac1c9 --- a/util/fp-finder/spell.sh +++ b/util/fp-finder/spell.sh @@ -1,20 +1,83 @@ #!/bin/bash -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +if ! command -v spell > /dev/null 2>&1; then + echo "This program requires spell to be installed. Aborting" + exit 1 +fi -RULES_DIR="${SCRIPT_DIR}/../../rules/" +check() { + local datafile="${1}" + local datafile_name="${datafile##*/}" -for datafile in "$RULES_DIR"*.data; do - DATAFILE_NAME=${datafile##*/} - - echo "-> checking ${DATAFILE_NAME}" + if ! ${MACHINE_READABLE}; then + echo "-> checking ${datafile_name}" + fi for word in $(grep -E '^[a-z]+$' "${datafile}" | uniq | sort); do IS_NOT_ENGLISH=$(echo "${word}" | spell | wc -l) if [ "${IS_NOT_ENGLISH}" -lt 1 ]; then - echo " \`- found English word: ${word}" + if ! ${MACHINE_READABLE}; then + printf " \`- found English word: " + fi + echo "${word}" fi done - echo "" + if ! ${MACHINE_READABLE}; then + echo "" + fi +} + +usage() { + cat < /dev/null && pwd ) + +RULES_DIR="${SCRIPT_DIR}/../../rules/" + +MACHINE_READABLE=false + +POSITIONAL_ARGS=() +while [[ $# -gt 0 ]]; do + # shellcheck disable=SC2221,SC2222 + case $1 in + -m|--machine) + MACHINE_READABLE=true + shift # past argument + ;; + -h|--help) + usage + exit 1 + ;; + -*|--*) + echo "Unknown option $1" + usage + exit 1 + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + shift # past argument + ;; + esac done + +set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters + + +if [ -n "${1}" ]; then + check "${1}" +else + for datafile in "${RULES_DIR}"*.data; do + check "${datafile}" + done +fi