diff options
author | Preston Pan <preston@nullring.xyz> | 2023-02-04 13:09:27 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-02-04 13:09:27 -0800 |
commit | b97c7811c7fd1131ae931d65460fbe1a0986e726 (patch) | |
tree | dfc279380fe1c92c8bc474a2884325b5b90ef3bf /process_file | |
parent | 06283e800a81f632037f4930008434dc41cef081 (diff) |
what the fuck
Diffstat (limited to 'process_file')
-rwxr-xr-x | process_file | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/process_file b/process_file index 82b6aa2..a96f9e8 100755 --- a/process_file +++ b/process_file @@ -22,13 +22,13 @@ template_replacement() echo "$r_templates" | while read -r i do # Escapes special characters from line containing $$INCLUDE call - keyword_regexp="$(printf '%s' "$i" | -e sed 's/[]\/$*.^|[]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" + keyword_regexp="$(printf '%s' "$i" | -e gsed 's/[]\/$*.^|[]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" r_tname="$TEMPLATE_DIR/$(echo "$i" | cut -d ' ' -f 2).html" # Get contents of file then escapes special characters f_contents="$(cat "$r_tname")" - replacement_regexp="$(printf '%s' "$f_contents" | sed -e 's/[\/&]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" - #Finally do the sed replace to replace the $$INCLUDE line with the contents of the included template file - sed -i "s/$keyword_regexp/$replacement_regexp/g" "$TEMPLATE_BUILD_DIR/$(basename "$1")" # BUG: This shit does not work + replacement_regexp="$(printf '%s' "$f_contents" | gsed -e 's/[\/&]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" + #Finally do the gsed replace to replace the $$INCLUDE line with the contents of the included template file + gsed -i "s/$keyword_regexp/$replacement_regexp/g" "$TEMPLATE_BUILD_DIR/$(basename "$1")" # BUG: This shit does not work # Then we do it all again on the same file. template_replacement "$1" done @@ -66,23 +66,23 @@ echo "$vars" | while read -r var; do # Get the name of the variable name="$(echo "$var" | cut -d ' ' -f 2 | tr -d '\n')" - keyword_regexp="$(printf '%s' "$var" | sed -e 's/[]\/$*.^|[]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" + keyword_regexp="$(printf '%s' "$var" | gsed -e 's/[]\/$*.^|[]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" # Get the endpoint of the variable var_end="\$\$END $name" - end_regexp="$(printf '%s' "$var_end" | sed -e 's/[\/&]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" + end_regexp="$(printf '%s' "$var_end" | gsed -e 's/[\/&]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" # Get the value of the variable - value="$(< "$BUILD_DIR/$1" sed -n "/$keyword_regexp/,/$end_regexp/p" "$1")" - value_regexp="$(printf '%s' "$value" | sed -e 's/[]\/$*.^|[]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" + value="$(< "$BUILD_DIR/$1" gsed -n "/$keyword_regexp/,/$end_regexp/p" "$1")" + value_regexp="$(printf '%s' "$value" | gsed -e 's/[]\/$*.^|[]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" # Get the string to replace replacement="\$\$VAR $name" - replacement_regexp="$(printf '%s' "$replacement" | sed -e 's/[\/&]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" + replacement_regexp="$(printf '%s' "$replacement" | gsed -e 's/[\/&]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" # Then do the replacement - sed -i "s/$replacement_regexp/$value_regexp/g" "$BUILD_DIR/$1" # BUG: Doesn't work on openBSD + gsed -i "s/$replacement_regexp/$value_regexp/g" "$BUILD_DIR/$1" # BUG: Doesn't work on openBSD done # For some reason I can't trim these inside the loop (i tried) so this works. -sed -i '/\$\$START/d' "$BUILD_DIR/$1" -sed -i '/\$\$END/d' "$BUILD_DIR/$1" +gsed -i '/\$\$START/d' "$BUILD_DIR/$1" +gsed -i '/\$\$END/d' "$BUILD_DIR/$1" debug="$(< "$BUILD_DIR/$1" grep "\$\$SCRIPT")" printf "$debug\n" @@ -93,9 +93,9 @@ then do name="$(echo "$line" | cut -d ' ' -f 2 | tr -d '\n')" output="$(./"$PLUG_DIR/$name" "$1" "$template")" - keyword_regexp="$(printf '%s' "$line" | sed -e 's/[]\/$*.^|[]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" - replacement_regexp="$(printf '%s' "$output" | sed -e 's/[\/&]/\\&/g' | sed ':a;N;$!ba;s,\n,\\n,g')" + keyword_regexp="$(printf '%s' "$line" | gsed -e 's/[]\/$*.^|[]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" + replacement_regexp="$(printf '%s' "$output" | gsed -e 's/[\/&]/\\&/g' | gsed ':a;N;$!ba;s,\n,\\n,g')" - sed -i "s/$keyword_regexp/$replacement_regexp/g" "$BUILD_DIR/$1" # BUG: doesn't work with openBSD + gsed -i "s/$keyword_regexp/$replacement_regexp/g" "$BUILD_DIR/$1" # BUG: doesn't work with openBSD done fi |