User Tools

Site Tools


packet:xrouter:manpages: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:manpages:parsing [2025/04/20 07:06] m0mzfpacket:xrouter:manpages:parsing [2025/04/20 07:28] (current) m0mzf
Line 50: Line 50:
 OUTPUTDIR="$BASEPATH/docuwiki-$DATE" OUTPUTDIR="$BASEPATH/docuwiki-$DATE"
  
-Colourise output+Handy functions
 echoRed () { echoRed () {
  echo -e "\e[1;31m----$1----\e[0m"  echo -e "\e[1;31m----$1----\e[0m"
Line 57: Line 57:
  echo -e "\e[1;32m----$1----\e[0m"  echo -e "\e[1;32m----$1----\e[0m"
 } }
- 
 checkRoot () { checkRoot () {
- if [[ $UID -eq 0 ]];  + if [[ $UID -eq 0 ]]; then 
- then + echoRed "Don'run this as root please"
- echoError "This script must NOT be run as root!"+
  exit 1  exit 1
  fi  fi
Line 68: Line 66:
 # Use awk to: # Use awk to:
 #  strip out comment lines and remove any <CR> from <CR><LF> lines #  strip out comment lines and remove any <CR> from <CR><LF> lines
-#  turn the MAN page title into a code block+#  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 #  find every subsequent MAN page header and turn it into a docuwiki header and
 #   terminate the previous code block before the header, then #   terminate the previous code block before the header, then
 #   create a new code block after the header, thus encapsulating the subsection #   create a new code block after the header, thus encapsulating the subsection
 # (the final encapsulation is done using "echo" in the bash script below) # (the final encapsulation is done using "echo" in the bash script below)
-awkParseMan=' +awkParseMan='{
-{+
  if (NR==1 || NR==2) # For the first two lines  if (NR==1 || NR==2) # For the first two lines
  {  {
Line 104: Line 101:
 #  insert a start code block in place of the now-empty line 1 #  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) # (the final encapsulation is done using "echo" in the bash script below)
-awkParseHlp=' +awkParseHlp=' {
-{+
  endhead="<code>"  endhead="<code>"
  gsub("\r", "") # remove all carriage return chars  gsub("\r", "") # remove all carriage return chars
Line 113: Line 109:
 } }
 ' '
- 
 # Use awk to extract a section name from the directory structure # Use awk to extract a section name from the directory structure
 awkSectionHeader=' awkSectionHeader='
Line 122: Line 117:
 } }
 ' '
- 
 # Use awk to extract a name from the filename.extension # Use awk to extract a name from the filename.extension
 awkFileHeader=' awkFileHeader='
Line 138: Line 132:
  do  do
  # Get the penultimate field in file path, i.e. the section (folder) name  # Get the penultimate field in file path, i.e. the section (folder) name
- section=$(echo $folder | awk  -F/ '{print $(NF-1)}')+ local section=$(echo $folder | awk  -F/ '{print $(NF-1)}')
  # Format the section name as a docuWiki header  # Format the section name as a docuWiki header
  echo "$folder" | awk "$awkSectionHeader" >> "${OUTPUTDIR}"/"$1"/"${section}".docuwiki  echo "$folder" | awk "$awkSectionHeader" >> "${OUTPUTDIR}"/"$1"/"${section}".docuwiki
Line 147: Line 141:
  do  do
  # Get the last field in file path, i.e. file name  # Get the last field in file path, i.e. file name
- title=$(echo $file | awk -F/ '{print $NF}')+ local title=$(echo $file | awk -F/ '{print $NF}') 
 + local outputpath="${OUTPUTDIR}"/"$1"/"${section}".docuwiki
  # Format the file name as a docuwiki header  # Format the file name as a docuwiki header
- echo "$title" | awk "$awkFileHeader" >> "${OUTPUTDIR}"/"$1"/"${section}".docuwiki+ echo "$title" | awk "$awkFileHeader" >> "$outputpath"
  case "$1" in  case "$1" in
  # For MAN files, after awk has done it's job we need to remove the last line; this last line breaks  # For MAN files, after awk has done it's job we need to remove the last line; this last line breaks
  # the following <code> statement and is just an EOF message, so we don't lose anything.  # the following <code> statement and is just an EOF message, so we don't lose anything.
- MANFILES) awk "$awkParseMan" "$file" | head -n -1 >> "${OUTPUTDIR}"/"$1"/"${section}".docuwiki + MANFILES) awk "$awkParseMan" "$file" | head -n -1 >> "$outputpath
- echo -e "</code>\n----" >> "${OUTPUTDIR}"/"$1"/"${section}".docuwiki+ echo -e "</code>\n----" >> "$outputpath"
  ;;  ;;
  # For HLP files we don't want to remove the last line because that truly is real content  # For HLP files we don't want to remove the last line because that truly is real content
- HLPFILES) awk "$awkParseHlp" "$file" >> "${OUTPUTDIR}"/"$1"/"${section}".docuwiki + HLPFILES) awk "$awkParseHlp" "$file" >> "$outputpath
- echo -e "</code>" >> "${OUTPUTDIR}"/"$1"/"${section}".docuwiki+ echo -e "</code>" >> "$outputpath"
  ;;  ;;
  esac  esac
packet/xrouter/manpages/parsing.1745132818.txt.gz · Last modified: 2025/04/20 07:06 by m0mzf