Fix a bunch of type warnings and duplicate variable names.

While testing compiling with g++, several issues were exposed
with missing type casts and duplicate variable names in several
files due to copying code around.  g++ isn't as forgiving of
these as gcc is, so this commit fixes all the issues to allow
g++ to be used to compile and make gcc usage safer.

We are evaluating switching to C++ to allow us to use classes
for handling strings and other data structures as well as
some 3rd party libraries for things such as meta-data handling.
This commit makes it easier to test or switch over after the
next release.

If you want to test compiling with g++, uncomment the g++ line
a the top of the Makefile.