# $MirOS: src/scripts/roff2htm,v 1.77 2013/01/01 20:49:09 tg Exp $ # $ekkoBSD: catman2html.sh,v 1.2 2004/03/07 03:02:53 stephen Exp $ #- # Copyright (c) 2004, 2005, 2006, 2007, 2011, 2012 # Thorsten “mirabilos” Glaser # Original version for ekkoBSD by: # Copyright (c) 2004 # Stephen Paskaluk # Parts of the regular expression set below are based upon work by: # Copyright (c) 1995 # Panagiotis J. Christias # # Provided that these terms and disclaimer and all copyright notices # are retained or reproduced in an accompanying document, permission # is granted to deal in this work without restriction, including un- # limited rights to use, publicly perform, distribute, sell, modify, # merge, give away, or sublicence. # # Advertising materials mentioning features or use of this work must # display the following acknowledgement: # This product includes material provided by Thorsten Glaser. # # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to # the utmost extent permitted by applicable law, neither express nor # implied; without malicious intent or gross negligence. In no event # may a licensor, author or contributor be held liable for indirect, # direct, other damage, loss, or other issues arising in any way out # of dealing in the work, even if advised of the possibility of such # damage or existence of a defect, except proven that it results out # of said person's immediate fault when using the work as intended. #- # Routines for converting catman pages and nrcon(1)d papers to HTML. # ATTENTION: this file contains embedded white-, backspace and high- # bit-on control characters! Use “jupp --asis $0” to edit # Note: this file contains magic and can’t be edited as UTF-8 either. # Note: this script assumes MirBSD filesystem interna: ino_t=uint32_t # check if mksh R31:2007/10/18 or up if [[ $KSH_VERSION = @(\@\(#\)MIRBSD KSH R)@(3[2-9]|[4-9][0-9]|[1-9][0-9][0-9])\ +([0-9])/+([0-9])/+([0-9])?(\ *) ]]; then i=0 elif [[ $KSH_VERSION = @(\@\(#\)MIRBSD KSH R31)* ]]; then eval $(print "$KSH_VERSION" | sed 's#^.*R31 \([0-9]*\)/\([0-9]*\)/\([0-9]*\)\( .*\)*$#y=\1 m=\2 d=\3#') (( i = y < 2007 ? 1 : y > 2007 ? 0 : m < 10 ? 1 : m > 10 ? 0 : d < 18 ? 1 : 0 )) unset y m d else i=1 fi # we need an mksh version with uint32_t array indicēs if (( i )); then print -u2 Error: your mksh is not recent enough. print -u2 Please upgrade to at least mksh R32. exit 1 fi unset i # initialise globals roff2htm_gendate=$(date +"%F %T") # current time set -A roff2htm_inodecache # inode cache (empty) roff2htm_machine=$(uname -m) # i386, sparc function set_conversion_man { function do_convert { do_convert_man "$@" } } function set_conversion_paper { function do_convert { do_convert_paper "$@" } } set_conversion_man function set_target_absolute { roff2htm_rel=https://www.mirbsd.org/ } function set_target_relative { roff2htm_rel=../ } set_target_relative function do_convert_man { local -i _nl=0 col -x | sed \ -e '/-$/N { s/\([0-9A-z][-.,0-9A-z:]*\)-\n\( *\)\([0-9A-z][-.,0-9A-z:]*([1-9][A-z]*)\)\([^ ]*\) /\1\3\4\ \2/ }' \ -e 's#<_#≤#g' -e 's#>_#≥#g' \ -e 'y#&<>##' \ \ -e 's#[Oo][Oo]++#•#g' \ -e 's#_||#_|_|#g' \ -e 's#+_#±#g' \ \ -e 's#^[A-z][ 0-9A-z]*$#

&

#'		\
	    -e 's#^  \([A-z][ -%'\''-;=?-~]*\)$#

\1

#'	\
									\
	    -e 's#\([^~<>-][-]*\)~#\1̅#g'				\
	    -e 's#\([^]\)~_#\1_̅ #g'					\
	    -e 's#\([^]\)\([^<>_-][-]*\)\([̅]*\)_#\1_\2\3#g'	\
	    -e 's#\([^<>-]\)[-]*\([̅]*\)\([^<>-][-]*\)#<\1<\3\2>#g'	\
	    -e 's#\(<_<\([^>_]*\)>\)\1#\2#g'			\
	    -e 's#<_<\([^>_]*\)>#\1#g'				\
	    -e 's#<.<\([^>]*\)>#\1#g'				\
	    -e 's###g'							\
									\
	    -e '/##g'					\
	    -e 's#<\1>##g'					\
	    -e 's#\([- -*./:;?@^_~]*\)<\1>#\2#g'		\
	    -e 's#\([- 0-9A-z]\)\([$/_-]*\)\(<[biG]>\)#\1\3\2#g'	\
	    -e 's#\(\)\([)$/_-]*\)\([- 0-9A-z]\)#\2\1\3#g'	\
									\
	    -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(\(3p\))#&#g' \
	    -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(\([1-9]\)\(/[/0-9A-Za-z]*\)*)#&#g' \
	    -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(\([PSU][MS][DM]\))#&#g' \
	    -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(\(PAPERS\))#&#g' \
	    -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(GNU)#&#g' \
	    -e 's#)\(\)\([- 0-9A-z]\)#\1)\2#g'			\
									\
	    -e 's//\&/g'						\
	    -e 's//\</g'						\
	    -e 's//\>/g'						\
									\
	    -e 's###g' -e 's###g'			\
	    -e 's###g'						\
									\
	    -e '1s#^#
#'						\
	    -e '$s#$#
#' \ -e 's#
##g'					\
	    -e 's#
##g'					\
	| while IFS= read -r line; do
		if [[ -n $line ]]; then
			(( _nl )) && [[ $line != '
'* ]] && print print -r -- "$line" _nl=0 else _nl=1 fi done } function do_convert_paper { local -i _nl=0 col -x | sed \ -e '/-$/N { s/\([0-9A-z][-.,0-9A-z:]*\)-\n\( *\)\([0-9A-z][-.,0-9A-z:]*([1-9][A-z]*)\)\([^ ]*\) /\1\3\4\ \2/ }' \ -e 's#<_#≤#g' -e 's#>_#≥#g' \ -e 'y#&<>##' \ \ -e 's#[Oo][Oo]++#•#g' \ -e 's#_||#_|_|#g' \ -e 's#+_#±#g' \ \ -e 's#\([^~<>-][-]*\)~#\1̅#g' \ -e 's#\([^]\)~_#\1_̅ #g' \ -e 's#\([^]\)\([^<>_-][-]*\)\([̅]*\)_#\1_\2\3#g' \ -e 's#\([^<>-]\)[-]*\([̅]*\)\([^<>-][-]*\)#<\1<\3\2>#g' \ -e 's#\(<_<\([^>_]*\)>\)\1#\2#g' \ -e 's#<_<\([^>_]*\)>#\1#g' \ -e 's#<.<\([^>]*\)>#\1#g' \ -e 's###g' \ \ -e 's#<\1>##g' \ -e 's#\([- -*./:;?@^_~]*\)<\1>#\2#g' \ -e 's#\([- 0-9A-z]\)\([$/_-]*\)\(<[biG]>\)#\1\3\2#g' \ -e 's#\(\)\([)$/_-]*\)\([- 0-9A-z]\)#\2\1\3#g' \ \ -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(\([1-9]\)[/0-9A-Za-z]*)#&#g' \ -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(\([PSU][MS][DM]\))#&#g' \ -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(\(PAPERS\))#&#g' \ -e '/^ /s#\([0-9A-z][-.,0-9A-z:]*\)(GNU)#&#g' \ -e 's#)\(\)\([- 0-9A-z]\)#\1)\2#g' \ \ -e 's//\&/g' \ -e 's//\</g' \ -e 's//\>/g' \ \ -e 's###g' -e 's###g' \ -e 's###g' \ \ -e '1s#^#
#'						\
	    -e '$s#$#
#' \ -e 's#
##g'					\
	    -e 's#
##g'					\
	| while IFS= read -r line; do
		if [[ -n $line ]]; then
			(( _nl )) && [[ $line != '
'* ]] && print print -r -- "$line" _nl=0 else _nl=1 fi done } function output_header { print ' RTFM '$1\($2')

MirOS Manual: '$1\($2')

' } function output_footer { print '

Generated on' $roff2htm_gendate 'by $MirOS: src/scripts/roff2htm,v 1.77 2013/01/01 20:49:09 tg Exp $

These manual pages and other documentation are copyrighted by their respective writers; their source is available at our CVSweb, AnonCVS, and other mirrors. The rest is Copyright © 2002‒2013 The MirOS Project, Germany.
This product includes material provided by Thorsten Glaser.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report – diffs preferred.

' } function do_conversion { output_header ${1:-missing-pagename} ${2:-0} do_convert ${2:-0} output_footer } # do_conversion_verbose title section infile outfile function do_conversion_verbose { print -nru2 -- $3 → $4 do_conversion $1 $2 <$3 >$4 print -u2 } # convert_page /path/to/man.cat1 /targetpath function convert_page { local fn=$1 page sect tn local -Uui ino=$(stat -Lf %i $fn 2>/dev/null) page=${fn##*/} # basename page=${page%.0} # manual page name sect=${fn%/*} # dirname sect=${sect##*/cat} # archsection sect=${sect%%/*} # section tn=man${sect}/${page}.htm # target file if (( ino )) && [[ -n ${roff2htm_inodecache[ino]} ]]; then # source file is linked to a file we know print -ru2 -- $tn ← ${roff2htm_inodecache[ino]} ln -f $2/${roff2htm_inodecache[ino]} $2/$tn # patch in the additional name(s) ed -s $2/$tn <<-EOF //s##, $page($sect)&# /

/s#

#, $page($sect)&# wq EOF else # store target filename in the inode cache roff2htm_inodecache[ino]=$tn do_conversion_verbose $page $sect $fn $2/$tn fi } # output_htaccess >…/.htaccess function output_htaccess { print DirectoryIndex /dev/null print "AddType 'text/html; charset=utf-8' htm" } # convert_all /path/to/share/man /targetpath function convert_all { local tp=${2:-$(pwd)/mbsdman} # target basepath local x f (find ${1:-/usr/share/man}/cat{[1-9],3p} -name \*.0 2>&- | sort -f) |& for x in 1 2 3 3p 4 5 6 7 8 9; do mkdir -p $tp/man$x # one per section output_htaccess >$tp/man$x/.htaccess done while read -p f; do convert_page $f $tp # any subpages done }