From 6fa4f83ff283860d297c128f471d3ca0c73396ed Mon Sep 17 00:00:00 2001 From: gorgone Date: Sat, 29 Feb 2020 02:46:18 +0100 Subject: [PATCH] cleanup support/functions/_arrays --- support/functions/_arrays | 125 ++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 47 deletions(-) diff --git a/support/functions/_arrays b/support/functions/_arrays index 86a2ad0..c549b51 100644 --- a/support/functions/_arrays +++ b/support/functions/_arrays @@ -1,54 +1,85 @@ #!/bin/bash _fill_tc_array(){ - unset AVAI_TCLIST; - unset INST_TCLIST; - tcempty=0; - cd "$tccfgdir"; - [ "$(ls -A "$tccfgdir")" ] && AVAI_TCLIST=(*) || echo "error fix it"; - cd "$tcdir"; - if [ "$(ls -A "$tcdir")" ];then - tmp_tclist=(*); - for t in "${tmp_tclist[@]}";do - for a in "${AVAI_TCLIST[@]}";do - [ "$t" == "$a" ] && INST_TCLIST+=($t); - done; - done; + unset AVAI_TCLIST + unset INST_TCLIST + tcempty=0 + + cd "$tccfgdir" + if [ "$(ls -A "$tccfgdir")" ] + then + AVAI_TCLIST=(*) + else + printf "\n error in _fill_tc_array()\n please report error\n\n" + exit + fi + + cd "$tcdir" + if [ "$(ls -A "$tcdir")" ] + then + tmp_tclist=(*) + for t in "${tmp_tclist[@]}" + do + for a in "${AVAI_TCLIST[@]}" + do + [ "$t" == "$a" ] && INST_TCLIST+=($t) + done + done else - tcempty=1; - fi; - if [ "$tcempty" == "1" ];then - MISS_TCLIST=$(echo ${AVAI_TCLIST[@]} |sort); + tcempty=1 + fi + + if [ "$tcempty" == "1" ] + then + MISS_TCLIST=$(echo ${AVAI_TCLIST[@]} |sort) else - MISS_TCLIST=($(for el in $(diff_array AVAI_TCLIST[@] INST_TCLIST[@]);do echo "$el";done |sort)); - fi; -}; + MISS_TCLIST=( + $(for el in $(diff_array AVAI_TCLIST[@] INST_TCLIST[@]) + do + printf "$el\n" + done |sort) + ) + fi +} + _create_module_arrays(){ - i=0; - for e in $(echo "$addons" | sed 's/WEBIF_//g;s/WITH_//g;s/MODULE_//g;s/CS_//g;s/HAVE_//g;s/_CHARSETS//g;s/CW_CYCLE_CHECK/CWCC/g;s/SUPPORT//g';);do - SHORT_ADDONS+=($e); - SHORT_MODULENAMES+=($e); - done; - for e in ${protocols//MODULE_/};do - SHORT_PROTOCOLS+=($e); - SHORT_MODULENAMES+=($e); - done; - for e in ${readers//READER_/};do - SHORT_READERS+=($e); - SHORT_MODULENAMES+=($e); - done; - for e in ${card_readers//CARDREADER_/};do - SHORT_CARD_READERS+=($e); - SHORT_MODULENAMES+=($e); - done; - for e in $addons $protocols $readers $card_readers;do - ALL_MODULES_LONG+=($e); - done; - for e in "${SHORT_MODULENAMES[@]}";do - INTERNAL_MODULES["$e"]="${ALL_MODULES_LONG[i]}"; - ((i++)); - done; -}; + i=0 + for e in $(echo "$addons" | sed 's/WEBIF_//g;s/WITH_//g;s/MODULE_//g;s/CS_//g;s/HAVE_//g;s/_CHARSETS//g;s/CW_CYCLE_CHECK/CWCC/g;s/SUPPORT//g';) + do + SHORT_ADDONS+=($e) + SHORT_MODULENAMES+=($e) + done + + for e in ${protocols//MODULE_/} + do + SHORT_PROTOCOLS+=($e) + SHORT_MODULENAMES+=($e) + done + + for e in ${readers//READER_/} + do + SHORT_READERS+=($e) + SHORT_MODULENAMES+=($e) + done + + for e in ${card_readers//CARDREADER_/} + do + SHORT_CARD_READERS+=($e) + SHORT_MODULENAMES+=($e) + done + + for e in $addons $protocols $readers $card_readers + do + ALL_MODULES_LONG+=($e) + done + + for e in "${SHORT_MODULENAMES[@]}" + do + INTERNAL_MODULES["$e"]="${ALL_MODULES_LONG[i]}" + ((i++)) + done +} + diff_array(){ - awk 'BEGIN{RS=ORS=" "}{NR==FNR?a[$0]++:a[$0]--}END{for(k in a)if(a[k])print k}' <(echo -n "${!1}") <(echo -n "${!2}"); -}; \ No newline at end of file + awk 'BEGIN{RS=ORS=" "}{NR==FNR?a[$0]++:a[$0]--}END{for(k in a)if(a[k])print k}' <(echo -n "${!1}") <(echo -n "${!2}") +}