Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commite857a26b70ec0338ee748388ef2d10ad4395edb4 (patch)
Author
 Syndamia <kamen@syndamia.com>
2023-10-23 15:09:03 +0300
Committer
 Syndamia <kamen@syndamia.com>
2023-10-23 15:09:03 +0300
Files9fa4b9f69fb401d604230da21ae8e66e4f9c89f4
csg-e857a26b70ec0338ee748388ef2d10ad4395edb4.tar
csg-e857a26b70ec0338ee748388ef2d10ad4395edb4.tar.gz
csg-e857a26b70ec0338ee748388ef2d10ad4395edb4.zip
Parent89d2ba57b9aa09f50740a3760ddcf2a1946496f4 (diff)
[s2] Put awk scripts logic inside a single variable and moved scripts variable inside transform_file
This way we improve efficiency significantly and make the whole script portable
1 files changed, 11 insertions, 17 deletions
-rwxr-xr-xcsg28
diff --git a/csg b/csg
index 5806738..6b97d6a 100755
--- a/csg
+++ b/csg
@@ -171,14 +171,7 @@ 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 '
+ awk_scr="$($CSG_AWK -v TMP_DIR="$CSG_TMP_DIR" '
{
# Remove first field
$1=""; sub(FS, "")
@@ -191,10 +184,12 @@ then
END {
for (reg in awks) {
print reg
- print awks[reg]
+ outf = TMP_DIR "/csg-" (awkcount++) ".awk"
+ print outf
+ system("cat " awks[reg] " > " outf)
}
}
- ' $(find $AWKSCRIPTS -type f -name "[A-Z]*.awk"))
+ ' $(find $AWKSCRIPTS -type f -name "[A-Z]*.awk"))"
overwriteLine "[Stage 1] Finding awk libraries"
@@ -216,7 +211,6 @@ startTimer "[Stage 2] Transforming Markdown to HTML"
transform_file() {
local file="$1"
local outf="${file%md}html"
- local scripts="$2"
# Gets special information from the file
local title descr words
@@ -263,6 +257,12 @@ EOF
$CSG_MD_TO_HTML "$file" > "$outf"
# Run custom awk scripts
+ local scripts="$(printf "$awk_scr" | $CSG_AWK -v file="$outf" '
+ capture == 1 { capture = 0; printf " -f " $0; next; }
+ capture == 2 { capture = 0; next; }
+ { capture = 1 + !match(file, $0) }
+ ')"
+
$CSG_AWK \
-v title="$title" \
-v description="$descr" \
@@ -293,12 +293,6 @@ echo '$0 != 0 {print}' > "$CSG_TMP_DIR/csg-print.awk"
while read -r file
do
- scripts=""
- for i in ${!scr_recip[@]}
- do
- [ "${scr_recip[$i]}" != "${scr_recip[$i]/${file%md}html/}" ] && scripts+=" -f ${scr_path[$i]} "
- done
-
transform_file "$file" "$scripts" &
done << EOF
$(find "$DESTINATION" -type f -name "*.md")