Keep less stuff in main.cc

I'd like to add some automated tests, and main.cc can't really be linked into
tests, so I'm moving the core functionality out.

Signed-off-by: Morten Hustveit <morten.hustveit@gmail.com>
Convert code to Google style

I prefer this style now, because it can be automatically indented using
clang-format --style=Google.

Signed-off-by: Morten Hustveit <morten.hustveit@gmail.com>