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/22 02:46] m0mzfpacket: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's # This could also be done with groff > HTML > pandoc > ssml but pandoc's
-# output format for SSML doesn't sort out proper ====headers==== and I +# output format for SSML doesn't sort out proper ====headers==== and I
 # 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>/dev/null | pandoc -f html -t dokuwiki -o "$manpage".txt # cat ${manpage} | groff -Thtml -P -l -mmandoc 2>/dev/null | pandoc -f html -t dokuwiki -o "$manpage".txt
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="packet:xrouter:docs:" +
-#   and the working folder for the script+
 BASEPATH=/home/jason/radio/packet/xrouter/Xrouter BASEPATH=/home/jason/radio/packet/xrouter/Xrouter
 +# and the Wiki namespace
 +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
-# called "docuwiki-date" and contains two directories for the +# called "docuwiki-date" and contains two directories for the
 # 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="$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 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(/[^0-9]/, "") # Strip out any character which is NaN 
- print "[[" ns $0 "#" ti "|" ti  "]]"+ print "[["ns"MAN"$0"#"ti"|"ti"]]"" | " # and ouptut a namespace link to the MAN entry 
 +
 +
 + 
 +awkFormatIndexHLPTitle=' 
 +
 + gsub(" ", "") # Strip out any whitespace 
 + print "[["ns$0"#"ti"|"ti"]]"" | " # and output a namespace link to the HLP entry
 } }
 ' '
  
-# Use awk to: 
-#  strip out comment lines and remove any <CR> from <CR><LF> lines 
-#  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 
-#   terminate the previous code block before the header, then 
-#   create a new code block after the header, thus encapsulating the subsection 
-# (the final encapsulation is done using "echo" in the bash script below) 
 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
  {  {
  gsub("\r", "") # remove all carriage return chars  gsub("\r", "") # remove all carriage return chars
  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 "<code>" $0 # annd output the line prepended with a code block start+ print "<code>" $0 # and output the line prepended with a code block start
  }  }
  
- 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
  {  {
  starthead="</code> **" # end previous code block  starthead="</code> **" # end previous 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 130: Line 144:
 } }
 ' '
-# Use awk to: +
-#  strip out comment lines (this is always line 1, sometime 2 and 3) and remove any <CR> from <CR><LF> lines +
-#  insert a start code block in place of the now-empty line 1 +
-# (the final encapsulation is done using "echo" in the bash script below)+
 awkParseHlp=' awkParseHlp='
 { {
Line 144: 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 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="${OUTPUTDIR}"/"$1"/"${section}".docuwiki  local outputpath="${OUTPUTDIR}"/"$1"/"${section}".docuwiki
 + # and generate a numerical section number from the path
 + 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 163: Line 177:
  for file in "$folder"*  for file in "$folder"*
  do  do
- # Get file name from last filed file path        | and strip file extension 
- local title=$(echo $file | awk -F/ '{print $NF}' | awk -F. '{print $1}') 
- # Begin by writing a docuwiki header containing file name 
- echo "==== $title ====" >> "$outputpath" 
- # and write a path into the index file 
- echo "$section" | awk -v ns="$NAMESPACE" -v ti="$title" "$awkFormatIndexTitle" >> "$INDEXFILE" 
  case "$1" in  case "$1" in
- # For MAN files, after awk has done it's job we need to remove the last linethis last line breaks + MAN
- the following <code> statement and is just an EOF message, so we don't lose anything+ # Section 8 has links to actual real filenames which we want to keep 
- MAN) awk "$awkParseMan" "$file"head -->> "$outputpath" + if [ $sectionnumber -eq 8 ]then 
- echo -e "</code>\n----" >> "$outputpath"+ 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'{print $1 "." $2 }') 
 + # 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/ '{print $NF}' | awk -F. '{print $1}'
 + fi 
 + # Begin by writing a docuwiki header containing file name 
 + echo "===== $title =====>> "$outputpath" 
 + # Get line count for the file 
 + 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 
 + echo -e "\n----" >> "$outputpath
 + # and add an entry to the index 
 + 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) awk "$awkParseHlp" "$file" >> "$outputpath"+ local title=$(echo $file | awk -F/ '{print $NF}' | awk -F. '{print $1}') 
 + echo "==== $title ====" >> "$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"
 + ;;
 + DOC) echoRed "No code to parse docs yet"
  ;;  ;;
-# DOC) echoRed "No code to parse docs yet" 
-# ;; 
  esac  esac
  done  done
Line 190: 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.1745289979.txt.gz · Last modified: by m0mzf