#!/usr/local/bin/gawk -f # # $Header: /home/srilm/CVS/srilm/man/scripts/man2html.gawk,v 1.9 2007/12/20 20:29:10 stolcke Exp $ # function getargs() { delete args; j = 1; for (i = 2; i <= NF; i ++) { if ($i ~ /^"/) { args[j] = substr($i, 2); for (i++; i <= NF; i++) { if ($i ~ /"$/) { args[j] = args[j] " " substr($i, 1, length($i)-1); break; } else { args[j] = args[j] " " $i; } } } else { args[j] = $i; } j++; } $1 = ""; allargs = ""; if (j >= 1) { for (k = 1; k <= j; k ++) { allargs = allargs " " args[k]; } } return j - 1; } function finishitem() { if (initem) { print ""; initem = 0; } } function finishlist() { finishitem(); if (inlist) { print ""; inlist -= 1; } } function makelinks() { for (i = 1; i <= NF; i ++) { if ($i ~ /^http:/) { url = $i; sub("[,;.]$", "", url); $i = "" $i ""; } } } function printline() { if (text ~ /\\c/) { sub("\\\\c", "", text); oldtext = oldtext text; } else { if (inlabel) { print "
" oldtext text; print "
"; inlabel = 0; initem = 1; oldtext = ""; } else { print oldtext text; oldtext = ""; } } } # comments $0 ~ /^\.\\\"/ { $1 = ""; print ""; next; } # # Note: check two-letter macros before one-letter ones # # title $0 ~ /^\.TH/ { getargs() name = args[1]; print ""; print "
"; print "" name ""; print "" print "

" name "

"; next; } # section header $0 ~ /^\.SH/ { finishlist(); getargs(); print "

" allargs "

"; next; } $0 ~ /^\.SS/ { finishlist(); getargs(); print "

" allargs "

"; next; } $0 ~ /^\.PP/ || $0 ~ /^\.LP/ { finishlist(); print "

"; next; } $0 ~ /^\.br/ { print "
"; next; } # labeled list item $0 ~ /^\.TP/ { if (!inlist) { print "

"; inlist += 1; } inlabel = 1; next; } # labeled list item $0 ~ /^\.IP/ { getargs(); print "
"; print allargs; print "
"; next; } # nested lists $0 ~ /^\.RS/ { print "
"; inlist += 1; next; } $0 ~ /^\.RE/ { finishlist(); next; } $0 ~ /^\.BR/ { getargs(); text = "" args[1] "" args[2] "" args[3] "" args[4] "" args[5] "" args[6] "" args[7] ""; printline(); next; } $0 ~ /^\.BI/ { getargs(); text = "" args[1] "" args[2] "" args[3] "" args[4] "" args[5] "" args[6] "" args[7] ""; printline(); next; } $0 ~ /^\.B/ { if (getargs() > 0) { text = "" allargs ""; } else { text = ""; newfont="B"; } printline(); next; } $0 ~ /^\.IR/ { getargs(); text = "" args[1] "" args[2] "" args[3] "" args[4] "" args[5] "" args[6] "" args[7] ""; printline(); next; } $0 ~ /^\.IB/ { getargs(); text = "" args[1] "" args[2] "" args[3] "" args[4] "" args[5] "" args[6] "" args[7] ""; printline(); next; } $0 ~ /^\.I/ { if (getargs() > 0) { text = "" allargs ""; } else { text = ""; newfont="I"; } printline(); next; } $0 ~ /^\.P/ { text = ""; printline(); next; } $0 ~ /^\.RB/ { getargs(); text = args[1] "" args[2] "" args[3] "" args[4] "" args[5] "" args[6] "" args[7]; printline(); next; } $0 ~ /^\.RI/ { getargs(); text = args[1] "" args[2] "" args[3] "" args[4] "" args[5] "" args[6] "" args[7]; printline(); next; } $0 ~ /^\.nf/ { print "
";
	next;
}
$0 ~ /^\.fi/ {
	print "
"; next; } $0 ~ /^\.[A-Za-z]/ { print "unknown macro " $1 > "/dev/stderr"; next; } { makelinks(); text = $0; printline(); next; } END { print ""; print ""; }