#!/bin/rc -e rfork E # htwrap -- create standalone HTML document flagfmt='t,C, c charset, d dir, l lang, v doctype' args='[file ...]' if(! ifs=() eval `{aux/getflags $*}){ aux/usage exit usage } switch($flagv){ case 5 echo '<!DOCTYPE html>' case 4 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">' case 4s echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' case x xhtml echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' case xs xhtmls echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' case '' echo '<!DOCTYPE html>' case * echo error: unknown doctype $flagv >[1=2] aux/usage exit usage } echo -n '<html' if(! ~ $#flagl 0) echo -n ' lang="'^$flagl^'"' if(! ~ $#flagd 0) echo -n ' dir="'^$flagd^'"' echo '>' if(~ $#flagC 0){ if(! ~ $#flagc 0) echo '<meta http-equiv="Content-Type" content="text/html; charset='^$flagc^'">' if not echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' } fn source{ if(! ~ $#* 0) cat $* if not cat } if(! ~ $#flagt 0) # try to retrieve title from <h1> on first line source $* | sed '1s/^<h1>(.*)<\/h1>/<title>\1<\/title>\n&/' if not source $* echo '</html>'