i always liked the approach of the plan9 script, bayesian in its approach (perhaps).
it is also admirably short.
-Steve
/usr/web/sources/plan9/rc/bin/doctype - Plan 9 from Bell Labs
9p.io