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/26 15:51] – m0mzf | packet:xrouter:docs:parsing [2025/04/26 21:44] (current) – m0mzf | ||
---|---|---|---|
Line 26: | Line 26: | ||
# - The only required configuration is to set the following path | # - The only required configuration is to set the following path | ||
BASEPATH=/ | BASEPATH=/ | ||
- | # - and the Wiki namespace | + | # and the Wiki namespace |
NAMESPACE=" | NAMESPACE=" | ||
- | # | ||
# This folder should contain the two directories " | # This folder should contain the two directories " | ||
# and " | # and " | ||
Line 61: | 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 | ||
- | # 20250426 | + | # 20250425 |
+ | # 20250426 - Refactor SEE ALSO links | ||
################################## | ################################## | ||
Line 70: | 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 88: | Line 85: | ||
} | } | ||
+ | # awk functions | ||
awkFormatIndexMANTitle=' | awkFormatIndexMANTitle=' | ||
{ | { | ||
Line 104: | Line 102: | ||
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 | ||
{ | { | ||
Line 111: | Line 112: | ||
} | } | ||
- | 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 | ||
{ | { | ||
- | if(/^SEE ALSO/) { next } | ||
starthead="</ | starthead="</ | ||
endhead=" | endhead=" | ||
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 129: | Line 143: | ||
} | } | ||
} | } | ||
- | ' | ||
- | |||
- | awkCreateLinks=' | ||
- | { | ||
- | line=$0 # | ||
- | FS=" | ||
- | if (/^SEE ALSO/) # For the SEE ALSO line | ||
- | { | ||
- | ln=NR # | ||
- | print "</ | ||
- | } | ||
- | if (NR> | ||
- | { | ||
- | gsub(" | ||
- | print " | ||
- | ln++ | ||
- | } | ||
- | else {print $0} # else just output the line to the next awk pass. Fortunately SEE ALSO: is at the | ||
- | } # bottom of the file, we dont need to find its start and end, just its start. Phew | ||
' | ' | ||
Line 160: | 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 173: | Line 169: | ||
local sectionnumber=$(echo $folder | awk ' | 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 " | ||
Line 182: | Line 178: | ||
do | do | ||
case " | case " | ||
- | # For MAN files, after awk has done it's job we need to remove the last two lines; this last line breaks | ||
- | # the following < | ||
MAN) | MAN) | ||
# Section 8 has links to actual real filenames which we want to keep | # Section 8 has links to actual real filenames which we want to keep | ||
Line 195: | Line 189: | ||
fi | fi | ||
# Begin by writing a docuwiki header containing file name | # Begin by writing a docuwiki header containing file name | ||
- | echo "==== $title ====" >> " | + | echo "===== $title |
- | # First pass through awk creates links in the SEE ALSO section, second pass docuWiki-fys it. | + | # Get line count for the file |
- | awk -v ln=999999 | + | recs=$(wc |
+ | # Parse the file! | ||
+ | awk -v flag=0 -v recs=" | ||
+ | # Add a link back to index page | ||
+ | echo " | ||
# Add a line break after each MAN entry | # Add a line break after each MAN entry | ||
echo -e " | echo -e " | ||
Line 203: | Line 201: | ||
echo " | echo " | ||
;; | ;; | ||
- | # For HLP files we don't want to remove the last line because that truly is real content | ||
HLP) | HLP) | ||
local title=$(echo $file | awk -F/ ' | local title=$(echo $file | awk -F/ ' | ||
Line 209: | Line 206: | ||
awk " | awk " | ||
echo "</ | echo "</ | ||
+ | # Add a link back to index page | ||
+ | echo " | ||
echo " | echo " | ||
;; | ;; | ||
Line 222: | 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.1745682678.txt.gz · Last modified: by m0mzf