[PATCH v2 15/24] dtoc: Move the main code into a function