packet:xrouter:docs:parsing
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
packet:xrouter:docs:parsing [2025/04/22 02:48] – m0mzf | packet:xrouter:docs:parsing [2025/04/26 21:44] (current) – m0mzf | ||
---|---|---|---|
Line 15: | Line 15: | ||
# | # | ||
# This could also be done with groff > HTML > pandoc > ssml but pandoc' | # This could also be done with groff > HTML > pandoc > ssml but pandoc' | ||
- | # output format for SSML doesn' | + | # output format for SSML doesn' |
# don't know Lua. Yet. Maybe something like this with a custom output formatter: | # don't know Lua. Yet. Maybe something like this with a custom output formatter: | ||
# cat ${manpage} | groff -Thtml -P -l -mmandoc 2>/ | # cat ${manpage} | groff -Thtml -P -l -mmandoc 2>/ | ||
Line 24: | Line 24: | ||
# | # | ||
# - This script does not take any arguments | # - This script does not take any arguments | ||
- | # - The only required configuration is to set the wiki namespace | + | # - The only required configuration is to set the following path |
- | NAMESPACE=" | + | |
- | # and the working folder for the script | + | |
BASEPATH=/ | BASEPATH=/ | ||
+ | # and the Wiki namespace | ||
+ | NAMESPACE=" | ||
# This folder should contain the two directories " | # This folder should contain the two directories " | ||
# and " | # and " | ||
- | # called " | + | # called " |
# concatenated and reformatted files. These files should be pasted into | # concatenated and reformatted files. These files should be pasted into | ||
# wiki pages created by the index file. | # wiki pages created by the index file. | ||
Line 60: | Line 60: | ||
# 20250419 - Tidy up, more awk less bash, remove .MAN / .HLP from outputted headers | # 20250419 - Tidy up, more awk less bash, remove .MAN / .HLP from outputted headers | ||
# 20250422 - Tidy up, create an index of commands and create links to sections | # 20250422 - Tidy up, create an index of commands and create links to sections | ||
+ | # 20250425 - Tidy up, Create SEE ALSO links within manpages | ||
+ | # 20250426 - Refactor SEE ALSO links | ||
################################## | ################################## | ||
Line 68: | Line 70: | ||
OUTPUTDIR=" | OUTPUTDIR=" | ||
INDEXFILE=" | INDEXFILE=" | ||
- | |||
- | # Wiki MANPAGE namespace structure. We pass this into awk later but define it here | ||
- | |||
# Handy functions | # Handy functions | ||
Line 86: | Line 85: | ||
} | } | ||
- | # Use awk to: | + | # awk functions |
- | # strip whitespace out of the folder structure to make a docuwiki-compatible namespace | + | awkFormatIndexMANTitle=' |
- | # and ouput a #link to one of the headers created by the later parsing | + | |
- | awkFormatIndexTitle=' | + | |
{ | { | ||
- | gsub(" | + | gsub(/ |
- | print " | + | print " |
+ | } | ||
+ | ' | ||
+ | |||
+ | awkFormatIndexHLPTitle=' | ||
+ | { | ||
+ | gsub(" ", "" | ||
+ | print " | ||
} | } | ||
' | ' | ||
- | # Use awk to: | ||
- | # strip out comment lines and remove any <CR> from < | ||
- | # turn the MAN page header into a code block, it contains a revision date | ||
- | # find every subsequent MAN page header and turn it into a docuwiki header and | ||
- | # | ||
- | # | ||
- | # (the final encapsulation is done using " | ||
awkParseMan=' | awkParseMan=' | ||
{ | { | ||
+ | if (NR> | ||
+ | if (NR> | ||
+ | |||
if (NR==1 || NR==2) # For the first two lines | if (NR==1 || NR==2) # For the first two lines | ||
{ | { | ||
gsub(" | gsub(" | ||
if (/^;/ || NF==0) {next} # skip the subsequent print function for comment or empty lines | if (/^;/ || NF==0) {next} # skip the subsequent print function for comment or empty lines | ||
- | print "< | + | print "< |
} | } | ||
- | if (NR>=3) # For the other lines | + | if (NR> |
{ | { | ||
- | if (/ | + | FS=" |
+ | if (/^SEE ALSO/) # Only for the SEE ONLY line | ||
+ | { | ||
+ | lno=NR # | ||
+ | flag=1 # | ||
+ | print "</ | ||
+ | } | ||
+ | else if (NR>lno && NR<(recs -1) && NF>0) # If we are in SEE ALSO and are not EOF and have non-empty lines | ||
+ | { | ||
+ | line=$0 # | ||
+ | gsub(" | ||
+ | print " | ||
+ | lno++ | ||
+ | } | ||
+ | else | ||
{ | { | ||
starthead="</ | starthead="</ | ||
Line 123: | Line 137: | ||
else # else for all other lines | else # else for all other lines | ||
{ | { | ||
- | if (/^;/) {next} # skip comment lines | + | if (/^;/ || /^ ;/) {next} # skip comment lines |
gsub(" | gsub(" | ||
print $0 # and output the line | print $0 # and output the line | ||
Line 130: | Line 144: | ||
} | } | ||
' | ' | ||
- | # Use awk to: | + | |
- | # strip out comment lines (this is always line 1, sometime 2 and 3) and remove any <CR> from < | + | |
- | # insert a start code block in place of the now-empty line 1 | + | |
- | # (the final encapsulation is done using " | + | |
awkParseHlp=' | awkParseHlp=' | ||
{ | { | ||
Line 144: | Line 155: | ||
' | ' | ||
+ | # File enumerator / reader / writer | ||
parseFiles () { | parseFiles () { | ||
mkdir " | mkdir " | ||
- | echo "==== $1 Files ====" >> " | + | echo "===== $1 Files =====" >> " |
# Traverse folders, skipping files in base directory | # Traverse folders, skipping files in base directory | ||
for folder in " | for folder in " | ||
Line 154: | Line 166: | ||
# Use the section name to generate a file foreach section | # Use the section name to generate a file foreach section | ||
local outputpath=" | local outputpath=" | ||
+ | # and generate a numerical section number from the path | ||
+ | local sectionnumber=$(echo $folder | awk ' | ||
# Create formatted section for wiki namespace | # Create formatted section for wiki namespace | ||
- | echo "== $section ==" >> " | + | echo "==== $section |
# Format the section name as a docuWiki header | # Format the section name as a docuWiki header | ||
- | echo "====== | + | echo " |
# Spit some stuff out to the shell | # Spit some stuff out to the shell | ||
echoRed " | echoRed " | ||
Line 163: | Line 177: | ||
for file in " | for file in " | ||
do | do | ||
- | # Get file name from last filed file path | and strip file extension | ||
- | local title=$(echo $file | awk -F/ ' | ||
- | # Begin by writing a docuwiki header containing file name | ||
- | echo "==== $title ====" >> " | ||
- | # and write a path into the index file | ||
- | echo " | ||
case " | case " | ||
- | # For MAN files, after awk has done it's job we need to remove the last line; this last line breaks | + | MAN) |
- | # the following < | + | # Section 8 has links to actual real filenames which we want to keep |
- | MAN) awk "$awkParseMan" " | + | if [ $sectionnumber -eq 8 ]; then |
- | echo | + | # Get file name from last filed file path | and strip the last file extension but keep the penultimate one. |
+ | local title=$(echo $file | awk -F/ '{print $NF}' | awk -F. ' | ||
+ | # but all other sections have .MAN or .HLP extensions which we want to remove | ||
+ | else | ||
+ | # Get file name from last filed file path | and strip file extension | ||
+ | local title=$(echo $file | awk -F/ ' | ||
+ | fi | ||
+ | # Begin by writing a docuwiki header containing file name | ||
+ | echo | ||
+ | # Get line count for the file | ||
+ | recs=$(wc -l " | ||
+ | # Parse the file! | ||
+ | awk | ||
+ | # Add a link back to index page | ||
+ | echo "[[$NAMESPACE|< Back to Index]]" | ||
+ | # Add a line break after each MAN entry | ||
+ | echo -e "\n----" | ||
+ | # and add an entry to the index | ||
+ | echo " | ||
;; | ;; | ||
- | # For HLP files we don't want to remove the last line because that truly is real content | + | HLP) |
- | HLP) awk " | + | local title=$(echo $file | awk -F/ ' |
+ | echo "==== $title ====" >> " | ||
+ | awk " | ||
echo "</ | echo "</ | ||
+ | # Add a link back to index page | ||
+ | echo " | ||
+ | echo " | ||
+ | ;; | ||
+ | DOC) echoRed "No code to parse docs yet" | ||
;; | ;; | ||
- | # | ||
- | # ;; | ||
esac | esac | ||
done | done | ||
Line 190: | Line 221: | ||
mkdir " | mkdir " | ||
echo " | echo " | ||
- | echo "The content | + | echo "This content is auto-generated from the XRouter documentation using [[$NAMESPACE: |
- | echoGreen " | + | echoGreen " |
parseFiles MAN | parseFiles MAN | ||
- | echoGreen " | + | echoGreen " |
parseFiles HLP | parseFiles HLP | ||
- | #echoGreen " | + | #echoGreen " |
#parseFiles DOC | #parseFiles DOC | ||
</ | </ |
packet/xrouter/docs/parsing.1745290098.txt.gz · Last modified: by m0mzf