I recently had to deal with tons of old and ugly C source code. Obviously many different people had worked on it over the years and the code used many different coding styles and had very weird and inconsistent indentation. Overall it was very hard to read and a pain to work with.
The tool that saved me is astyle and it works for C/C++ and Java according to the website. I’ve only used it on C so far but it really saved me tons of work. Debian and most likely many other Linux distros have a package so there’s no need to get it from the website.
You can customize that style you want it to convert the source to on the command line or just put the options into your ~/.astylerc file. Mine for C is here:
With the file in place you don’t need to worry about that anymore. Just get into the directory with all the ugly code and let astyle fix it for you:
astyle *.c *.h
The original files still exist named filename.orig, you may want to remove them if everything worked fine.