This is by no means done, and needs more tests, docs and bugfixes, but push it early so we have a common base to work on. Based on work by Martin Sehnoutka. Signed-off-by: Tom Gundersen <teg@jklm.no>