From e196fe2c81e69a08dad7c834556461d2cc6465fb Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 17 Oct 2023 15:50:27 +0300 Subject: [s1] awk scripts are combined and awk libraries are extracted only when AWKSCRIPTS isn't empty string --- csg | 63 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/csg b/csg index d571e88..cc0f9eb 100755 --- a/csg +++ b/csg @@ -156,40 +156,43 @@ do mv "$file" "${file%md}html" done -overwriteLine "[Stage 1] Combining awk scripts" +if [ -n "$AWKSCRIPTS" ] +then + overwriteLine "[Stage 1] Combining awk scripts" -scr_path=() -scr_recip=() -while read -r reg; read -r scripts -do - cat $scripts > "$CSG_TMP_DIR/csg-${#scr_path[@]}.awk" - scr_path+=("$CSG_TMP_DIR/csg-${#scr_path[@]}.awk") - scr_recip+=("$(find $DESTINATION -type f -regex "$reg")") -done < <($CSG_AWK ' -{ - # Remove first field - $1=""; sub(FS, "") - # Associate current file with regex - if (awks[$0] == "") awks[$0] = FILENAME - else awks[$0] = awks[$0] " " FILENAME - - nextfile -} -END { - for (reg in awks) { - print reg - print awks[reg] + scr_path=() + scr_recip=() + while read -r reg; read -r scripts + do + cat $scripts > "$CSG_TMP_DIR/csg-${#scr_path[@]}.awk" + scr_path+=("$CSG_TMP_DIR/csg-${#scr_path[@]}.awk") + scr_recip+=("$(find $DESTINATION -type f -regex "$reg")") + done < <($CSG_AWK ' + { + # Remove first field + $1=""; sub(FS, "") + # Associate current file with regex + if (awks[$0] == "") awks[$0] = FILENAME + else awks[$0] = awks[$0] " " FILENAME + + nextfile } -} -' $(find $AWKSCRIPTS -type f -name "[A-Z]*.awk")) + END { + for (reg in awks) { + print reg + print awks[reg] + } + } + ' $(find $AWKSCRIPTS -type f -name "[A-Z]*.awk")) -overwriteLine "[Stage 1] Finding awk libraries" + overwriteLine "[Stage 1] Finding awk libraries" -scr_libs="" -while read -r file -do - scr_libs+=" -f $file " -done < <(find $AWKSCRIPTS -type f -name "#*.awk") + scr_libs="" + while read -r file + do + scr_libs+=" -f $file " + done < <(find $AWKSCRIPTS -type f -name "#*.awk") +fi endTimer "[Stage 1] Done" -- cgit v1.3.1-23-gd82d