Add duplicate abbr check (r8, r7, r6, r5)
Add a check for duplicate :abbr: anchor strings to prebuild phase and error on duplicates. Change-Id: I034c321a3c83aa4c0cbcf551fd90161e9e221c18 Signed-off-by: Ron Stone <ronald.stone@windriver.com>
This commit is contained in:
63
_utils.sh
63
_utils.sh
@@ -1,13 +1,14 @@
|
||||
|
||||
declare RED='\033[0;31m'
|
||||
declare OG="\033[93m"
|
||||
declare GR='\033[0;32m'
|
||||
declare NC='\033[0m'
|
||||
|
||||
# Output functions. Colorize various types of messages.
|
||||
message () { echo -e "$@" 1>&2; }
|
||||
confirmation () { message $GR$@$NC; }
|
||||
warn () { message $RED$@$NC; }
|
||||
error () { message $RED$@$NC; exit 1; }
|
||||
warn () { message $OG$@$NC; }
|
||||
error () { message $RED$0:$?: $@$NC; exit 1; }
|
||||
|
||||
# Check for and exit if file dependancies are not met. Takes a list of full or
|
||||
# relative paths.
|
||||
@@ -52,4 +53,62 @@ trimspaces () {
|
||||
echo $_s
|
||||
}
|
||||
|
||||
# Sets a global hash of acronyms and definitions from rst :abbr: defs. Also
|
||||
# sets an array of hash keys to facilitate sorting.
|
||||
#
|
||||
# Takes path to the file to parse. Optional "1" flag as second option
|
||||
# suppresses plural forms such as "PVCs".
|
||||
get_abbrs () {
|
||||
|
||||
local ABBREVS
|
||||
declare -a -g acro_keys
|
||||
declare -A -g acro_keyvals
|
||||
local regex=":abbr:\`([A-Za-z]+)\s+\((.*)\)\`"
|
||||
|
||||
[[ ! -z ${1+x} ]] && [[ -e $1 ]] && ABBREVS="$1" \
|
||||
|| error "Can't find abbrevs file $1"
|
||||
|
||||
[[ ! -z $2{+x} ]] && [[ ${2} == "1" ]] \
|
||||
&& local strip_plurals=$2
|
||||
|
||||
while IFS= read -r line
|
||||
do
|
||||
if [[ $line =~ $regex ]]; then
|
||||
|
||||
if [[ ${strip_plurals} -eq 1 ]] && [[ ${BASH_REMATCH[1]:0-1} == "s" ]]; then
|
||||
message " Skipping pluralization \"${BASH_REMATCH[1]}\""
|
||||
continue
|
||||
fi
|
||||
acro_keys+=("${BASH_REMATCH[1]}")
|
||||
acro_keyvals["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}"
|
||||
fi
|
||||
done < "$ABBREVS" || error "Cannot read $ABBREVS"
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Report duplicate :abbr: anchor strings. (Duplicate placeholders cause
|
||||
# Sphinx warnings.)
|
||||
#
|
||||
# Takes an array of anchor strings. Echos duplicates and returns a duplicate
|
||||
# count
|
||||
check_abbr_dups () {
|
||||
|
||||
local -a _anchors=("$@")
|
||||
declare -a dups; declare -i _dup_count=0
|
||||
IFS=$'\n'; dups=($(sort -f <<<"${_anchors[*]}")); unset IFS
|
||||
|
||||
message "... Checking for duplicate anchor strings"
|
||||
|
||||
for ((i=0; i < ${#dups[@]}; i++)); do
|
||||
if [[ ${dups[$i]} == ${dups[$i-1]} ]]; then
|
||||
warn " Duplicate anchor string \"${dups[$i]}\" found"
|
||||
((_dup_count=$_dup_count+1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo $_dup_count
|
||||
|
||||
}
|
||||
|
||||
declare utils_loaded=1
|
Reference in New Issue
Block a user