Disaster cleanup- part 1

What have you guys done...
--The old api.c has been renamed to completely_messed_up_api.c. Anything
in there can still be found; it was left unchanged.
--Reverted to old api.c
--Fixed everything
--DO NOT revert this commit or change back to the old form. That code
was so ugly and had so many errors, I'd rather... well, anything,
really.

This is just part 1. By the time I'm done, the code will compile without
any problems, and all the fuckery will have been undone.