routine for applying patch to file