C++ FAQ Celebrating Twenty-One Years of the C++ FAQ!!!
(Click here for a personal note from Marshall Cline.)
Section 40:
[40.3] Are there any pretty-printers that reformat C++ source code?

In alphabetical order:

  • A2PS is a Unix-based pretty-printer. It is available from www.infres.enst.fr/~demaille/a2ps/
  • Artistic Style is a reindenter and reformatter of C++, C and Java source code. It is available from astyle.sourceforge.net/
  • C++2LaTeX is a LaTeX pretty printer. It is available from roederberg.dyndns.org/~arnold/cpp2latex
  • C-Clearly by V Communications, Inc. is a Windows program that comes with standard formatting templates and also allows you to customize your own. www.mixsoftware.com/product/ccl.htm
  • GNU indent program may help. It's available at www.arceneaux.com/indent.html. You can also find an "official" GNU mirror site by looking at www.gnu.org/order/ftp.html or perhaps the original GNU site, prep.ai.mit.edu/pub/gnu/ (e.g., if the current version is 1.9.1 you could use prep.ai.mit.edu/pub/gnu/indent-1.9.1.tar.gz).
  • "HPS Beauty" is reported to be a Windows 95/98/NT4/NT2000 utility that beautifies C/C++ source code based on rules. The interface is entirely GUI, but HPS Beauty may also be run from the command line. It supports style files, which allow you to save and restore groups of settings. HPS Beauty also offers an optional visual results window, that shows both the before and the after file. Optional HTML output allows you to view source code with syntax highlighting in your browser. www.highplains.net.
  • "ProFactor StyleManager" has lots of options, and is integrated with Microsoft Visual C++. It is a commercial product with a free 14-day trial period. www.profactor.co.uk/products.php.
  • "Source Styler for C++" has lots of bells and whistles. It is a commercial product with a free 15-day trial period. It seems to offer control over tons of different features. www.sourcestyler.com/.
  • tgrind is a Unix based pretty printer. It usually comes with the public distribution of TeX and LaTeX in the directory "...tex82/contrib/van/tgrind". A more up-to-date version of tgrind by Jerry Leichter can be found on: venus.ycc.yale.edu/pub in [.TGRIND]. [Note: If anyone has an updated URL for tgrind, please let me know (cline@parashift.com).]
  • uncrustify from uncrustify.sourceforge.net.
Finally, you might consider lgrind which is another C++ to LaTeX translator (check for the closest mirror site of the ctan archive). The following is a grind definition for C++ (but this one doesn't recognize some new keywords such as bool or wchar_t, and it doesn't recognize a file ending with .cpp as C++):
   :kw=asm auto break case cdecl char continue default do double else\
   enum extern far float for fortran goto huge if int interrupt long\
   near pascal register return short signed sizeof static struct\
   switch typedef union unsigned while void\
   #define #else #endif #if #ifdef #ifndef #include #undef # define\
   endif ifdef ifndef include undef defined #pragma\
   class const delete friend inline new operator overload private\
   protected public template this virtual: