User Tools

Site Tools


packet:xrouter:docs:parsing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
packet:xrouter:docs:parsing [2025/04/26 15:51] m0mzfpacket: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=/home/jason/radio/packet/xrouter/Xrouter BASEPATH=/home/jason/radio/packet/xrouter/Xrouter
-and the Wiki namespace+# and the Wiki namespace
 NAMESPACE="packet:xrouter:docs:" NAMESPACE="packet:xrouter:docs:"
-# 
 # This folder should contain the two directories "XRouter Help Files" # This folder should contain the two directories "XRouter Help Files"
 # and "XRouter Manual Files". A new directory will be created here # and "XRouter Manual Files". A new directory will be created here
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 - Tidy up, Create SEE ALSO links within manpages+20250425 - Tidy up, Create SEE ALSO links within manpages 
 +# 20250426 - Refactor SEE ALSO links
 ################################## ##################################
  
Line 70: Line 70:
 OUTPUTDIR="$BASEPATH/docuwiki-$DATE" OUTPUTDIR="$BASEPATH/docuwiki-$DATE"
 INDEXFILE="${OUTPUTDIR}"/index.docuwiki INDEXFILE="${OUTPUTDIR}"/index.docuwiki
- 
-# 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>=(recs - 1) && flag==0) {print "</code>" ; exit} # If we have EOF and didnt have a SEE ALSO section write code close and exit
 + if (NR>=(recs - 1) && flag==1) {print "" ; exit} # If we are EOF and have a SEE ALSO section write nothing and exit
 +
  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>=3 && NR<recs) # For the other items leading up to EOF
  {  {
- if (/^[A-Z]/ # If the line begins with a character+ FS="[()]" # Field separator so we can generate section & title 
 + if (/^SEE ALSO/) # Only for the SEE ONLY line 
 +
 + lno=NR # Set the counter to current record number 
 + flag=1 # Set the this file has a see also section flag 
 + print "</code> **SEE ALSO:** \\\\" # Output a reformatted see also line 
 +
 + 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 # Save the inital line to print later 
 + gsub(" ", "", $1) # Strip the whitespace out of field #1 (i.e. CONFIG.SYS) 
 + print "[["ns"MAN" $2"#"$1"|"line"]]"" \\\\" #and ouput the line as a docuWiki formatted link 
 + lno++ 
 +
 + else if (/^[A-Z]/ # If the line begins with a character
  {  {
- if(/^SEE ALSO/) { next } 
  starthead="</code> **" # end previous code block  starthead="</code> **" # end previous code block
  endhead="** <code>" # set bold and start code block  endhead="** <code>" # set bold and start code block
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("\r", "") # remove all carriage return chars  gsub("\r", "") # remove all carriage return chars
  print $0 # and output the line  print $0 # and output the line
Line 129: Line 143:
  }  }
 } }
-' 
- 
-awkCreateLinks=' # we have set globalvar ln=999999, will break if a man page has more than 1M lines 
-{ 
- line=$0 # Keep the original line before using the field separator, we print this later 
- FS="[()]" # Set the field separator so we have CONFIG.SYS and 8 separately 
- if (/^SEE ALSO/) # For the SEE ALSO line 
- { 
- ln=NR # Set ln to the current record number 
- print "</code> **SEE ALSO:** \\\\" # and output docuWiki formatted  title 
- } 
- if (NR>ln) # for lines after SEE ALSO 
- { 
- gsub(" ", "", $1) # Strip the whitespace out of field #1 (i.e. CONFIG.SYS) 
- print "[["ns"MAN" $2"#"$1"|"line"]]"" \\\\" #and ouput the line as a docuWiki formatted link 
- 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 "${OUTPUTDIR}/$1"  mkdir "${OUTPUTDIR}/$1"
- echo "==== $1 Files ====" >> "$INDEXFILE"+ echo "===== $1 Files =====" >> "$INDEXFILE"
  # Traverse folders, skipping files in base directory  # Traverse folders, skipping files in base directory
  for folder in "${!1}"/*/  for folder in "${!1}"/*/
Line 173: Line 169:
  local sectionnumber=$(echo $folder | awk '{gsub(/[^0-9]/, ""); print}')  local sectionnumber=$(echo $folder | awk '{gsub(/[^0-9]/, ""); print}')
  # Create formatted section for wiki namespace  # Create formatted section for wiki namespace
- echo "== $section ==" >> "$INDEXFILE"+ echo "==== $section ====" >> "$INDEXFILE"
  # Format the section name as a docuWiki header  # Format the section name as a docuWiki header
  echo "$section" | awk '{hdr="======"; print hdr $0 hdr}' >> "$outputpath"  echo "$section" | awk '{hdr="======"; print hdr $0 hdr}' >> "$outputpath"
Line 182: Line 178:
  do  do
  case "$1" in  case "$1" in
- # For MAN files, after awk has done it's job we need to remove the last two lines; this last line breaks 
- # the following <code> statement and is just an EOF message, the penultimate line is blank so we don't lose anything. 
  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 ====" >> "$outputpath" + echo "===== $title =====" >> "$outputpath" 
-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 -v ns="$NAMESPACE" "$awkCreateLinks" "$file" | awk "$awkParseMan" | head -n -2 >> "$outputpath"+ recs=$(wc -l "$file" | awk '{print $1}'
 + # Parse the file! 
 + awk -v flag=0 -v recs="$recs" -v lno=99999 -v ns="$NAMESPACE" "$awkParseMan" "$file" >> "$outputpath" 
 + # Add a link back to index page 
 + echo "[[$NAMESPACE|< Back to Index]]" >> "$outputpath"
  # Add a line break after each MAN entry  # Add a line break after each MAN entry
  echo -e "\n----" >> "$outputpath"  echo -e "\n----" >> "$outputpath"
Line 203: Line 201:
  echo "$section" | awk -v ns="$NAMESPACE" -v ti="$title" "$awkFormatIndexMANTitle" >> "$INDEXFILE"  echo "$section" | awk -v ns="$NAMESPACE" -v ti="$title" "$awkFormatIndexMANTitle" >> "$INDEXFILE"
  ;;  ;;
- # 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/ '{print $NF}' | awk -F. '{print $1}')  local title=$(echo $file | awk -F/ '{print $NF}' | awk -F. '{print $1}')
Line 209: Line 206:
  awk "$awkParseHlp" "$file" >> "$outputpath"  awk "$awkParseHlp" "$file" >> "$outputpath"
  echo "</code>" >> "$outputpath"  echo "</code>" >> "$outputpath"
 + # Add a link back to index page
 + echo "[[$NAMESPACE|< Back to Index]]" >> "$outputpath"
  echo "$section" | awk -v ns="$NAMESPACE" -v ti="$title" "$awkFormatIndexHLPTitle" >> "$INDEXFILE"  echo "$section" | awk -v ns="$NAMESPACE" -v ti="$title" "$awkFormatIndexHLPTitle" >> "$INDEXFILE"
  ;;  ;;
Line 222: Line 221:
 mkdir "$OUTPUTDIR" mkdir "$OUTPUTDIR"
 echo "======= XRouter Documentation =======" >> "$INDEXFILE" echo "======= XRouter Documentation =======" >> "$INDEXFILE"
-echo "The content below is auto-generated from the XRouter documentation using [[$NAMESPACE:parsing|this bash / awk script]] to parse MAN / HLP files into docuWiki some simple markup language" >> "$INDEXFILE" +echo "This content is auto-generated from the XRouter documentation using [[$NAMESPACE:parsing|this bash / awk script]] to parse MAN / HLP files into docuWiki some simple markup language" >> "$INDEXFILE" 
-echoGreen "Parsing MAN files from $MANFILES"+echoGreen "Parsing MAN files from $MAN"
 parseFiles MAN parseFiles MAN
-echoGreen "Parsing HLP files from $HLPFILES"+echoGreen "Parsing HLP files from $HLP"
 parseFiles HLP parseFiles HLP
-#echoGreen "Parsing DOC files from $DOCFILES"+#echoGreen "Parsing DOC files from $DOC"
 #parseFiles DOC #parseFiles DOC
 </file> </file>
packet/xrouter/docs/parsing.1745682678.txt.gz · Last modified: by m0mzf