MAINT: f2py: rewrite fortran_doc

Should not use sprintf, and certainly not with incorrect error checking
(gh-5044). Entirely rewritten for readability.

Also replaced a few sprintf calls that were just copying strings without
interpretation by the simpler and possibly faster strcpy/strcat.
(These need to be replaced by something more sensible.)