dtoc: Move the output code into its own function