From d03e5fcf3b23d33d240acc356c3d5bd1f009d047 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 2 Oct 2021 21:23:45 -0400 Subject: switch to arrays The files we work with are supposed to be simple so this shouldn't super matter, but now that newer bash and tools have options to easily work with these, might as well switch over to fix quoting. Signed-off-by: Mike Frysinger --- build-docbook-catalog | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/build-docbook-catalog b/build-docbook-catalog index 0ecbc1c..b815bfc 100755 --- a/build-docbook-catalog +++ b/build-docbook-catalog @@ -14,7 +14,8 @@ ROOTCONFDIR="${EPREFIX}"/etc/xml ROOTCATALOG=${ROOTCONFDIR}/catalog CATALOG=${ROOTCONFDIR}/docbook DOCBOOKDIR="${EPREFIX}"/usr/share/sgml/docbook -DTDS= +DTDS=() +SIMPLE_DTDS=() LATEST_DTD= LATEST_DATE= VERBOSE=false @@ -56,7 +57,7 @@ main() { shift done - : ${ROOT:=/} + : "${ROOT:=/}" [[ ${ROOT} != */ ]] && ROOT="${ROOT}/" [[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}" if [[ ${ROOT} != "/" ]] ; then @@ -88,11 +89,11 @@ main() { clean_catalog "${DOCBOOKDIR}/xml\(-simple\)*-dtd-[^/\"']*/[^/\"']*" "${ROOTCATALOG}" if set_dtds; then - for d in ${DTDS}; do - populate_dtd ${d} + for d in "${DTDS[@]}"; do + populate_dtd "${d}" done - for d in ${SIMPLE_DTDS}; do - populate_simple_dtd ${d} + for d in "${SIMPLE_DTDS[@]}"; do + populate_simple_dtd "${d}" done populate_entities fi @@ -122,17 +123,17 @@ error() { # fill in the DTDS variable based on installed versions # set_dtds() { - DTDS= SIMPLE_DTS= + DTDS=() SIMPLE_DTDS=() local d=${ROOT}${DOCBOOKDIR} if [[ -d ${d} ]] ; then pushd "${d}" >/dev/null || return 1 - DTDS=$(find xml-dtd-*/ -name docbookx.dtd) - SIMPLE_DTDS=$(find xml-simple-dtd-*/ -name sdocbook.dtd) - popd >/dev/null + mapfile -d $'\0' DTDS < <(find xml-dtd-*/ -name docbookx.dtd -print0) + mapfile -d $'\0' SIMPLE_DTDS < <(find xml-simple-dtd-*/ -name sdocbook.dtd -print0) + popd >/dev/null || return 1 fi - if [[ -z ${DTDS} ]]; then + if [[ ${#DTDS[@]} -eq 0 ]]; then echo "No installed DocBook XML DTDs found" return 1 else @@ -346,10 +347,10 @@ populate_entities() { ) # here are the entities available; assume no spaces in filenames... - avail=($(ls "${ROOT}${isodir}" | sort)) + mapfile -d $'\0' avail < <(find "${ROOT}${isodir}" -maxdepth 1 -type f -printf '%f\0' | sort -z) # double-check the lists - verb " Populating ${CATALOG} with ISO DocBook entities" + verb " Populating ${CATALOG} with ${#avail[@]} ISO DocBook entities" i=0 ; j=0 while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do if [[ ${i} -ge ${#entities[@]} ]]; then @@ -358,13 +359,13 @@ populate_entities() { elif [[ ${j} -ge ${#avail[@]} ]]; then echo "Warning: Entities file not found: ${entities[i]}" : $(( i += 2 )) - elif [[ ${avail[j]} < ${entities[i]} ]]; then + elif [[ ${avail[j]} < "${entities[i]}" ]]; then echo "Warning: Extra ISO entities file: ${avail[j]}" : $(( j += 1 )) - elif [[ ${entities[i]} < ${avail[j]} ]]; then + elif [[ ${entities[i]} < "${avail[j]}" ]]; then echo "Warning: Entities file not found: ${entities[i]}" : $(( i += 2 )) - elif [[ ${entities[i]} == ${avail[j]} ]]; then + elif [[ ${entities[i]} == "${avail[j]}" ]]; then xmlcatalog --noout --add "public" "${entities[i+1]}" \ "file://${isodir}/${entities[i]}" "${ROOT}${CATALOG}" : $(( j += 1 )) -- cgit v1.2.3-65-gdbad