Simplify control structures in update-readme script

pull/62/head
Michele Locati 2019-12-17 10:20:11 +01:00
parent fa85ee010c
commit 4bde79c65e
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
1 changed files with 25 additions and 50 deletions

View File

@ -21,14 +21,11 @@ getExtensionList () {
getExtensionList_extensions='' getExtensionList_extensions=''
IFS=' IFS='
' '
for getExtensionList_line in $(cat -- "${1}" | sort) for getExtensionList_line in $(cat -- "${1}" | sort); do
do
getExtensionList_extension='' getExtensionList_extension=''
IFS=' ' IFS=' '
for getExtensionList_chunk in ${getExtensionList_line} for getExtensionList_chunk in ${getExtensionList_line}; do
do if test -z "${getExtensionList_extensions}"; then
if test -z "${getExtensionList_extensions}"
then
getExtensionList_extensions="${getExtensionList_chunk}" getExtensionList_extensions="${getExtensionList_chunk}"
else else
getExtensionList_extensions="${getExtensionList_extensions} ${getExtensionList_chunk}" getExtensionList_extensions="${getExtensionList_extensions} ${getExtensionList_chunk}"
@ -51,20 +48,15 @@ getVersionList () {
getVersionList_versions='' getVersionList_versions=''
IFS=' IFS='
' '
for getVersionList_line in $(cat -- "${1}" | sort) for getVersionList_line in $(cat -- "${1}" | sort); do
do
getVersionList_extension='' getVersionList_extension=''
IFS=' ' IFS=' '
for getVersionList_chunk in ${getVersionList_line} for getVersionList_chunk in ${getVersionList_line}; do
do if test -z "${getVersionList_extension}"; then
if test -z "${getVersionList_extension}"
then
getVersionList_extension="${getVersionList_chunk}" getVersionList_extension="${getVersionList_chunk}"
elif test -z "${getVersionList_versions}" elif test -z "${getVersionList_versions}"; then
then
getVersionList_versions="${getVersionList_chunk}" getVersionList_versions="${getVersionList_chunk}"
elif ! stringInList "${getVersionList_chunk}" "${getVersionList_versions}" elif ! stringInList "${getVersionList_chunk}" "${getVersionList_versions}"; then
then
getVersionList_versions="${getVersionList_versions} ${getVersionList_chunk}" getVersionList_versions="${getVersionList_versions} ${getVersionList_chunk}"
fi fi
done done
@ -84,10 +76,8 @@ sortVersionList () {
sortVersionList_list='' sortVersionList_list=''
IFS=' IFS='
' '
for sortVersionList_version in $(printf '%s' "${1}" | tr ' ' '\n' | sort -t '.' -k 1,1n -k 2,2n -k 3,3n) for sortVersionList_version in $(printf '%s' "${1}" | tr ' ' '\n' | sort -t '.' -k 1,1n -k 2,2n -k 3,3n); do
do if test -z "${sortVersionList_list}"; then
if test -z "${sortVersionList_list}"
then
sortVersionList_list="${sortVersionList_version}" sortVersionList_list="${sortVersionList_version}"
else else
sortVersionList_list="${sortVersionList_list} ${sortVersionList_version}" sortVersionList_list="${sortVersionList_list} ${sortVersionList_version}"
@ -110,41 +100,33 @@ generateExtensionsTable () {
generateExtensionsTable_versions="$(getVersionList "${1}")" generateExtensionsTable_versions="$(getVersionList "${1}")"
printf '| Extension |' printf '| Extension |'
IFS=' ' IFS=' '
for generateExtensionsTable_version in ${generateExtensionsTable_versions} for generateExtensionsTable_version in ${generateExtensionsTable_versions}; do
do
printf ' PHP %s |' "${generateExtensionsTable_version}" printf ' PHP %s |' "${generateExtensionsTable_version}"
done done
printf '\n' printf '\n'
printf '|:---:|' printf '|:---:|'
for generateExtensionsTable_version in ${generateExtensionsTable_versions} for generateExtensionsTable_version in ${generateExtensionsTable_versions}; do
do
printf -- ':---:|' printf -- ':---:|'
done done
printf '\n' printf '\n'
IFS=' ' IFS=' '
for generateExtensionsTable_extension in ${generateExtensionsTable_extensions} for generateExtensionsTable_extension in ${generateExtensionsTable_extensions}; do
do
printf '| %s |' "${generateExtensionsTable_extension}" printf '| %s |' "${generateExtensionsTable_extension}"
IFS=' ' IFS=' '
for generateExtensionsTable_version in ${generateExtensionsTable_versions} for generateExtensionsTable_version in ${generateExtensionsTable_versions}; do
do
printf ' ' printf ' '
generateExtensionsTable_versionOk='' generateExtensionsTable_versionOk=''
IFS=' IFS='
' '
for generateExtensionsTable_dataLine in ${generateExtensionsTable_data} for generateExtensionsTable_dataLine in ${generateExtensionsTable_data}; do
do if stringInList "${generateExtensionsTable_extension}" "${generateExtensionsTable_dataLine}"; then
if stringInList "${generateExtensionsTable_extension}" "${generateExtensionsTable_dataLine}" if stringInList "${generateExtensionsTable_version}" "${generateExtensionsTable_dataLine}"; then
then
if stringInList "${generateExtensionsTable_version}" "${generateExtensionsTable_dataLine}"
then
generateExtensionsTable_versionOk='y' generateExtensionsTable_versionOk='y'
fi fi
break break
fi fi
done done
if test -n "${generateExtensionsTable_versionOk}" if test -n "${generateExtensionsTable_versionOk}"; then
then
printf 'V' printf 'V'
fi fi
printf ' |' printf ' |'
@ -165,10 +147,8 @@ generateSpecialRequirementsTable () {
generateSpecialRequirementsTable_started='' generateSpecialRequirementsTable_started=''
IFS=' IFS='
' '
for generateSpecialRequirementsTable_line in $(cat -- "${1}" | sort) for generateSpecialRequirementsTable_line in $(cat -- "${1}" | sort); do
do if test -z "${generateSpecialRequirementsTable_started}"; then
if test -z "${generateSpecialRequirementsTable_started}"
then
printf '| Extension | Requirements |\n' printf '| Extension | Requirements |\n'
printf '|:---:|:---:|\n' printf '|:---:|:---:|\n'
generateSpecialRequirementsTable_started='y' generateSpecialRequirementsTable_started='y'
@ -202,18 +182,14 @@ generateReadme () {
generateReadme_ph_SpecialStart='<!-- START OF SPECIAL REQUIREMENTS -->' generateReadme_ph_SpecialStart='<!-- START OF SPECIAL REQUIREMENTS -->'
generateReadme_ph_SpecialEnd='<!-- END OF SPECIAL REQUIREMENTS -->' generateReadme_ph_SpecialEnd='<!-- END OF SPECIAL REQUIREMENTS -->'
generateReadme_skip='' generateReadme_skip=''
while IFS= read -r generateReadme_line while IFS= read -r generateReadme_line; do
do if test "${generateReadme_line}" = "${generateReadme_ph_ExtensionsEnd}" || test "${generateReadme_line}" = "${generateReadme_ph_SpecialEnd}"; then
if test "${generateReadme_line}" = "${generateReadme_ph_ExtensionsEnd}" || test "${generateReadme_line}" = "${generateReadme_ph_SpecialEnd}"
then
generateReadme_skip='' generateReadme_skip=''
fi fi
if test -z "${generateReadme_skip}" if test -z "${generateReadme_skip}"; then
then
printf '%s\n' "${generateReadme_line}" printf '%s\n' "${generateReadme_line}"
fi fi
if test "${generateReadme_line}" = "${generateReadme_ph_ExtensionsStart}" if test "${generateReadme_line}" = "${generateReadme_ph_ExtensionsStart}"; then
then
generateReadme_skip='y' generateReadme_skip='y'
printf '<!-- ########################################################### -->\n' printf '<!-- ########################################################### -->\n'
printf '<!-- # # -->\n' printf '<!-- # # -->\n'
@ -223,8 +199,7 @@ generateReadme () {
printf '<!-- # # -->\n' printf '<!-- # # -->\n'
printf '<!-- ########################################################### -->\n' printf '<!-- ########################################################### -->\n'
generateExtensionsTable "${2}" generateExtensionsTable "${2}"
elif test "${generateReadme_line}" = "${generateReadme_ph_SpecialStart}" elif test "${generateReadme_line}" = "${generateReadme_ph_SpecialStart}"; then
then
generateReadme_skip='y' generateReadme_skip='y'
printf '<!-- ########################################################### -->\n' printf '<!-- ########################################################### -->\n'
printf '<!-- # # -->\n' printf '<!-- # # -->\n'