Correct merged gerber file

The D10 should should not be reused, extract from the gerber file spec:
"Once a D-code number is assigned it cannot be re-assigned. "
adapt to kicad generated files

Kicad generates extraneous G05 and G90 which should be ignored

Kicad terminates the file with a T0 (Tool 0) which is not defined
before, most likely it resets the tooling