X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/fea1bafcec18f9858dccbca7326fe60ca5f88816..7e2694d5ab50af05aa373974ab781d6e26cf05cc:/user/mw_wc2sp.sh?ds=inline diff --git a/user/mw_wc2sp.sh b/user/mw_wc2sp.sh index 421adb7..ab412b3 100755 --- a/user/mw_wc2sp.sh +++ b/user/mw_wc2sp.sh @@ -4,14 +4,16 @@ # Input: arg1 path input wikicode file # Output: files wikicode file tree # Depends: Bash 5.1.16, GNU Coreutils 8.32 -# Version: 0.0.1 +# Version: 0.2.0 re_sp='^()$'; # subpage marker pattern d_out=./wikicode/; # default output dir -f_spl="subpage_list.txt"; -p_spl="${d_out}/${f_spl}"; -f_splv="subpage_list_validated.txt"; -p_splv="${d_out}/${f_splv}"; +f_spl="subpage_list.txt"; # subpage title list +p_spl="${d_out}/subpages/${f_spl}"; +f_splv="subpage_list_validated.txt"; # subpage title list (validated) +p_splv="${d_out}/subpages/${f_splv}"; +f_splwc="subpages.wc"; # subpage list wikicode +p_splwc="${d_out}/${f_splwc}"; yell() { echo "$0: $*" >&2; } # print script path and all args to stderr die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status @@ -187,7 +189,7 @@ assemble_subpage_ftree() { yell "STATUS:Running assemble_subpage_ftree()."; # debug - spc_path="${d_out}/presubpage.content"; # default destination for content before subpage detected + spc_path="${d_out}/subpages/presubpage.content"; # default destination for content before subpage detected ## Process input line-by-line while read -r line; do @@ -198,7 +200,7 @@ assemble_subpage_ftree() { sp_path="$(echo "$line" | sed -E -e "s/${re_sp}/\2/" -e 's/[ ]*$//'; )"; # declare -p sp_path; # debug #### Update subpage content file path - spc_path="${d_out}/${sp_path}.content"; + spc_path="${d_out}/subpages/${sp_path}.content"; spc_dir="$(dirname "$spc_path"; )"; #declare -p spc_path spc_dir; # debug #### Prepare file destination @@ -220,6 +222,20 @@ assemble_subpage_ftree() { yell "STATUS:Finished assemble_subpage_ftree()."; # debug }; # process input wikicode into subpage content files and subpage list +print_wc_content() { + # Input: var p_spc path subpage content + # Output: stdout + printf -- "\n----\n"; + cat "$p_spc"; + printf -- "\n----\n"; +}; # print wikicode content +print_wc_footer() { + # Output: stdout + printf -- "\n==References==\n\n" + printf -- "\n==Footnotes==\n\n"; + printf -- "\n==Comments==\n\n"; + printf -- "\n"; +}; # print wikicode footer create_output_wikicode() { # Desc: Use subpage list and subpage content files to create # output subpage wikicode. @@ -252,6 +268,10 @@ create_output_wikicode() { die "FATAL:Different line counts for subpage lists:$(declare -p lc_spl lc_splv;)"; fi; declare -p lc_spl lc_splv; # debug + + # Initialize subpage list wikicode file + must touch "$p_splwc"; + printf "==Stats==\n\n==Subpages==\n" >> "$p_splwc"; # Read content files according to subpage list file # Note: $i corresponds to “next” line ($lnext). Therefore, use @@ -263,7 +283,7 @@ create_output_wikicode() { # Check subpage content files f_spc="${lines_spl[i-1]}.content"; - p_spc="${d_out}/${f_spc}"; + p_spc="${d_out}/subpages/${f_spc}"; declare -p f_spc p_spc; ## Exit if subpage content file missing if [[ "$i" -gt 0 ]] && [[ ! -f "$p_spc" ]]; then @@ -271,9 +291,13 @@ create_output_wikicode() { # Prepare output subpage wikicode files f_spwc="${lines_splv[i-1]}.wc"; - p_spwc="${d_out}/${f_spwc}"; # use validated subpage name + p_spwc="${d_out}/subpages/${f_spwc}"; # use validated subpage name declare -p f_spwc p_spwc; # debug - if [[ "$i" -gt 0 ]]; then must touch "$p_spwc"; fi; + if [[ "$i" -gt 0 ]]; then + must touch "$p_spwc"; + ## Append subpage list wikicode file + printf "* [[/%s]]\n" "${lines_splv[i-1]}" >> "$p_splwc"; + fi; # Advance input lines lprev="$lcurr"; @@ -323,13 +347,8 @@ create_output_wikicode() { fi; # Print subpage content - printf -- "\n----\n" >> "$p_spwc"; - cat "$p_spc" >> "$p_spwc"; - printf -- "\n----\n" >> "$p_spwc"; - printf -- "\n==References==\n\n" >> "$p_spwc"; - printf -- "\n==Footnotes==\n\n" >> "$p_spwc"; - printf -- "\n==Comments==\n\n" >> "$p_spwc"; - printf -- "\n"; >> "$p_spwc"; + print_wc_content >> "$p_spwc"; + print_wc_footer >> "$p_spwc"; declare -p i lprev lcurr lnext lprev_hier lcurr_hier lnext_hier; # debug declare -p fork_level_next fork_level_prev relups_next relups_prev; # debug @@ -337,6 +356,9 @@ create_output_wikicode() { printf "====================\n" # debug done; + # Add footer to subpage list wikicode file + print_wc_footer >> "$p_splwc"; + yell "STATUS:Finished create_output_wikicode()."; # debug }; # generate output subpage wikicode main() {