File indexing completed on 2022-09-20 15:08:37

0001 #!/usr/bin/env bash
0002 
0003 camelcaseheadernames=(BibTeXEntries BibTeXFields Comment Element Encoder EncoderXML Entry File FileImporter FileImporterBibTeX KBibTeX Macro OnlineSearchAbstract Preamble Preferences Value XSLTransform)
0004 
0005 if [[ $# != 2 || $1 == "-h" || $1 == "--help" ]] ; then
0006         echo "Generate CamelCase headers in a target directory based on"
0007         echo "lower-case headers in a source directory."
0008         echo
0009         echo "Two parameters are expected:"
0010         echo " 1. The absolute path to KBibTeX's 'src/' directory."
0011         echo " 2. The absolute path to the the 'src/' directory inside"
0012         echo "    the build directory. If the directory does not yet"
0013         echo "    exist, it will be created."
0014         echo
0015         echo "Example:"
0016         echo "  ./generate-camelcase-headers.sh ~/git/kbibtex/src/ ~/git/build-bibsearch-SailfishOS_3_0_3_9_i486_in_Sailfish_OS_Build_Engine-Debug/src/"
0017         echo
0018         echo "The following CamelCase headers will be generated:"
0019         for camelcaseheadername in "${camelcaseheadernames[@]}" ; do echo "  ${camelcaseheadername}" ; done
0020         exit 1
0021 fi
0022 
0023 sourcedir="$1"
0024 destdir="$2"
0025 test -d "${sourcedir}" || { echo "Not a directory: '${sourcedir}'" >&2 ; exit 1 ; }
0026 test -d "${destdir}" || { echo "Creating directory: '${destdir}'" >&2 ; mkdir -p "${destdir}" ; }
0027 
0028 for camelcaseheadername in "${camelcaseheadernames[@]}" ; do
0029         lowercaseheadername="$(tr 'A-Z' 'a-z' <<<"${camelcaseheadername}").h"
0030         absolutelowercasefilename="$(find "${sourcedir}" -name "${lowercaseheadername}" | head -n 1)"
0031         test -s "${absolutelowercasefilename}" || { echo "No lowercase header name found for '${camelcaseheadername}': '${lowercaseheadername}'" >&2 ; exit 1 ; }
0032         absolutecamelcasefilename="$(dirname "${absolutelowercasefilename/$sourcedir/$destdir}")/${camelcaseheadername}"
0033         mkdir -p "$(dirname "${absolutecamelcasefilename}")" || exit 1
0034         echo "#include \"${lowercaseheadername}\"" >"${absolutecamelcasefilename}"
0035 done