Fixes for compiling under C89 mode

* Move for-loop declarations to top of methods
* Use C89-style comments
* Additionally fix a few signedness issues

Signed-off-by: Eddie Ringle <eddie@eringle.net>
Merged patch.