packet:xrouter:manpages:parsing
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
packet:xrouter:manpages:parsing [2025/04/19 18:30] – m0mzf | packet:xrouter:manpages:parsing [2025/04/22 02:40] (current) – removed m0mzf | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== G8PZT MAN page parsing script ======= | ||
- | Does what it says on the tin :) | ||
- | < | ||
- | #!/bin/bash | ||
- | ################################## | ||
- | # by Jason M0MZF (not a programmer!) | ||
- | # bash / awk / hammer / nail etc. | ||
- | # License - MIT. Crack on people. | ||
- | # | ||
- | # Script to parse Paula G8PZT' | ||
- | # "some simple markup language" | ||
- | # https:// | ||
- | # | ||
- | # The intention is to parse all MAN / HLP files within the folders and | ||
- | # write them with appropriate formatting to files which can then be | ||
- | # copypasta' | ||
- | # | ||
- | # This could also be done with groff > HTML > pandoc > ssml but pandoc' | ||
- | # output format for SSML doesn' | ||
- | # don't know Lua. Yet. | ||
- | # | ||
- | # | ||
- | ################################## | ||
- | # Instructions (destructions? | ||
- | # | ||
- | # - This script does not take any arguments | ||
- | # - The only required configuration is to set the following path | ||
- | # | ||
- | BASEPATH=/ | ||
- | # | ||
- | # This folder should contain the two directories " | ||
- | # and " | ||
- | # called " | ||
- | # concatenated and reformatted files. A manually-created | ||
- | # index page exists in https:// | ||
- | # top-level contents, and the pages linked therein have their contents | ||
- | # copypasta' | ||
- | # | ||
- | ################################## | ||
- | # Changelog | ||
- | # 20250418 - Implemented MAN page parsing | ||
- | # 20250419 - Implemented HLP page parsing | ||
- | # 20250419 - Tidy up, more awk less bash, remove .MAN / .HLP | ||
- | ################################## | ||
- | |||
- | # Globals | ||
- | DATE=$(date +" | ||
- | MANFILES=" | ||
- | HLPFILES=" | ||
- | OUTPUTDIR=" | ||
- | |||
- | # Colourise output | ||
- | echoRed () { | ||
- | echo -e " | ||
- | } | ||
- | echoGreen () { | ||
- | echo -e " | ||
- | } | ||
- | |||
- | checkRoot () { | ||
- | if [[ $UID -eq 0 ]]; | ||
- | then | ||
- | echoError "This script must NOT be run as root!" | ||
- | exit 1 | ||
- | fi | ||
- | } | ||
- | |||
- | awkParseMan=' | ||
- | { | ||
- | if (NR==1 || NR==2) # For the first two lines | ||
- | { | ||
- | gsub(" | ||
- | if (/^;/ || NF==0) {next} # skip comment or empty line | ||
- | print "< | ||
- | } | ||
- | |||
- | if (NR> | ||
- | { | ||
- | if (/^[A-Z]/) # If the line begins with a character | ||
- | { | ||
- | endcode="</ | ||
- | startcode=" | ||
- | gsub(" | ||
- | print endcode $0 startcode # and output the line | ||
- | } | ||
- | else # else for all other lines | ||
- | { | ||
- | if (/^;/) {next} # skip comment lines | ||
- | gsub(" | ||
- | print $0 # and output the line | ||
- | } | ||
- | } | ||
- | } | ||
- | ' | ||
- | |||
- | awkParseHlp=' | ||
- | { | ||
- | header1="< | ||
- | gsub(" | ||
- | if (NR==1) {print header1} # | ||
- | if (/^;/ || NF==0) {next} # skip comment / empty lines | ||
- | print $0 | ||
- | } | ||
- | ' | ||
- | |||
- | awkSectionHeader=' | ||
- | BEGIN { FS="/" | ||
- | { | ||
- | header=" | ||
- | print header $(NF-1) header # we need the penultimate field as that | ||
- | } # is the folder name / | ||
- | ' | ||
- | |||
- | awkFileHeader=' | ||
- | BEGIN { FS=" | ||
- | { # to separate out the .MAN .HLP | ||
- | header=" | ||
- | print header $1 header # output first field with headers | ||
- | } | ||
- | ' | ||
- | |||
- | parseFiles () { | ||
- | mkdir -p " | ||
- | # Traverse folders, skipping files in base directory | ||
- | for folder in " | ||
- | do | ||
- | # Get the penultimate field in file path, i.e. the section (folder) name | ||
- | section=$(echo $folder | awk -F/ ' | ||
- | # Prepend the section name as a docuWiki header | ||
- | echo " | ||
- | # Spit some stuff out to the shell | ||
- | echoRed " | ||
- | # Traverse through files | ||
- | for file in " | ||
- | do | ||
- | # Get the last field in file path, i.e. file name | ||
- | title=$(echo $file | awk -F/ ' | ||
- | # Prepend the file name as a docuwiki header | ||
- | echo " | ||
- | case " | ||
- | # For MAN files, after awk has done it's job we need to remove the last line; this last line breaks | ||
- | # the following < | ||
- | MANFILES) awk " | ||
- | echo -e "</ | ||
- | ;; | ||
- | # For HLP files we don't want to remove the last line because that truly is real content | ||
- | HLPFILES) awk " | ||
- | echo -e "</ | ||
- | ;; | ||
- | esac | ||
- | done | ||
- | done | ||
- | } | ||
- | |||
- | #Let's go! | ||
- | checkRoot | ||
- | echoGreen " | ||
- | parseFiles MANFILES | ||
- | echoGreen " | ||
- | parseFiles HLPFILES | ||
- | |||
- | </ |
packet/xrouter/manpages/parsing.1745087430.txt.gz · Last modified: by m0mzf