main: refactor main routine
main: refactor main routine

Most of the code is split into the functions application_init,
application_run and application_destroy.

The initialization and destruction of all objects is also simplified.
Everything is initialized even if earlier initializations failed. As all
object are now in a defined state, it is possible to also destroy the
objects unconditionally.

cglindkamp/dfm