Modified version of dim's patch, where most of the stuff moves into a REINPLACE_CMD called from post-patch. Submitted by: dim