#!/bin/mksh #use read -r throughout; '\' cannot break this. #discard : advance position of read by n lines discard(){ for i in `seq $1` do read -r header done } #use in pipes to delete leading whitespace chompws(){ sed -e 's/^[[:space:]]*//' } mainparser(){ while read -r line; do case "$line" in ( NAME | SYNOPSIS | DESCRIPTION | RETURN*VALUE | ERRORS | EXAMPLES | APPLICATION*USAGE | RATIONALE | FUTURE*DIRECTIONS | CHANGE*HISTORY ) printf ".SH $line\n.LP\n" ;; (SEE*ALSO) printf ".SH $line\n.LP\n" ;; ('['*']') echo '.TP 7' echo -n '.B ' echo "$line" |tr -d [:punct:] ;; (*#include*) printf "$line\n" |sed -e 's/.*#include/#include/' ;; (----*) ;; (The*following*sections*informative*) echo -n '\\fI' echo -n "$line" echo '\\fP' ;; (End*informative*) break ;; (*) echo "$line" ;; esac done } nameof(){ echo `basename $1 .html` } discard 4 for line in 1 2 3 do read -r line echo -n '.\"' printf " $line\n" done echo -n '.TH '`nameof $1 |tr [a-z] [A-Z]`' P 2013 "IEEE/The Open Group" "POSIX Programmers Manual"' discard 2 mainparser discard 11 echo '.SH COPYRIGHT' echo '.LP' read -r line echo "$line"