C-C++ Beautifier HOW-TO Al Dev (Alavoor Vasudevan) alavoor@yahoo.com v1.0, 7 February 2000 This document will help you to format (beautify) the C/C++ programs so that it is more readable and confirms to your site C/C++ coding stan- dards. The information in this document applies to all the operating sytems that is - Linux, MS DOS, Windows 95/NT, all flavors of Unix like Solaris, HPUX, AIX, SCO, Sinix, BSD, SCO, etc.. and to all other operating systems which support "C" compiler. ______________________________________________________________________ Table of Contents 1. Introduction 2. How can I trust Beautifier programs??!! 3. Beautifiers for other Languages 4. Other Formats of this Document 5. Copyright ______________________________________________________________________ 11.. IInnttrroodduuccttiioonn Coding standards for C/C++ or any language is required in order to make the programs more readable/understandable by programmers. There are C/C++ beautifiers (formating tools) to accomplish this goal. Formatted (beautified) code improves the pprroodduuccttiivviittyy of programmers by 22 ttiimmeess!! On Linux/Unixes there is a command called ""iinnddeenntt"" and ""ccbb"" . Refer to 'man indent' and 'man cb'. Note that iinnddeenntt and ccbb work for only "C" programs. For "C++" programs use ""bbccpppp"". Download the beautifier program from one of the following +o C++ : BCPP site is at +o C++ : +o C : I used BCPP to format the C++ programs and it worked fine for me. You may want to check other tools and use the one which you may like the most. 22.. HHooww ccaann II ttrruusstt BBeeaauuttiiffiieerr pprrooggrraammss????!!!! For 100% assurance you need a SSCCIIEENNTTIIFFIICC way to validate and trust a beautifier program. The method described in this section will enable the beautifier program to be accepted as "trust-worthy" and reliable. In order to verify that beautifier programs like bbccpppp, iinnddeenntt or ccbb is not damaging or changing the input source-code after formatting, use the following technique - Generate the object code from the original input source code using the compiler - ______________________________________________________________________ g++ -c myprogram.cpp ______________________________________________________________________ Here g++ is GNU C++ compiler. This will create object output mypro- gram.o Save this file - ______________________________________________________________________ mv myprogram.o myprogram_orig.o ______________________________________________________________________ Now run bcpp - ______________________________________________________________________ bcpp myprogram.cpp ______________________________________________________________________ This will create the formatted output program file myprogram.cpp and move the original file to myprogram.cpp.orig. Compile the new file with - ______________________________________________________________________ g++ -c myprogram.cpp ______________________________________________________________________ Now use the unix 'diff' command to compare the two object files - ______________________________________________________________________ diff myprogram.o myprogram_orig.o ______________________________________________________________________ Both these files MMUUSSTT BBEE IIDDEENNTTIICCAALL. This verifies that bcpp is working perfectly. On DOS or Windows 95 you may want to use the free Cygnus Cygwin Also you can use the assembler output instead of object output in compiler. Like - ______________________________________________________________________ g++ -S myprogram.cpp ______________________________________________________________________ This creates myprogram.s. Verify with - ______________________________________________________________________ diff myprogram.s myprogram_orig.s ______________________________________________________________________ This step gives 100% guarantee that your valuable source code is intact and bcpp is JUST doing ONLY formatting and is NOT changing or damaging your code in any way. This method gives you 100% quality assurance and long term WWAARRRRAANNTTYY on beautifier programs like 'bcpp', It is strongly recommended that you do these two steps every time you run beautifier programs like bbccpppp, iinnddeenntt or ccbb. 33.. BBeeaauuttiiffiieerrss ffoorr ootthheerr LLaanngguuaaggeess Visit the following sites to get beautifiers for other languages like HTML, SQL, Java, Perl, Fortran. +o HTML : +o HTML : +o HTML : +o SQL : +o Java : +o Perl : +o Perl : +o Fortran beautifier : +o C++ : BCPP site is at +o C++ : +o C : +o White paper on beautifier : To create presentation of codes to display using HTML - +o Presentation (C,C++,Java) to html : Also search the search engines like or and search for keyword "beautfier". 44.. OOtthheerr FFoorrmmaattss ooff tthhiiss DDooccuummeenntt This document is published in 10 different formats namely - DVI, Postscript, Latex, LyX, GNU-info, HTML, RTF(Rich Text Format), Plain- text, Unix man pages and SGML. +o You can get this HOWTO document as a single file tar ball in HTML, DVI, Postscript or SGML formats from - or +o Plain text format is in: or +o Translations to other languages like French, German, Spanish, Chinese, Japanese are in or Any help from you to translate to other languages is welcome. The document is written using a tool called "SGML tool" which can be got from - Compiling the source you will get the following commands like +o sgml2html C-C++Beautifier-howto.sgml (to generate html file) +o sgml2rtf C-C++Beautifier-howto.sgml (to generate RTF file) +o sgml2latex C-C++Beautifier-howto.sgml (to generate latex file) This document is located at - +o Also you can find this document at the following mirrors sites - +o +o +o +o +o Other mirror sites near you (network-address-wise) can be found at select a site and go to directory /LDP/HOWTO/C-C++Beautifier-HOWTO.html In order to view the document in dvi format, use the xdvi program. The xdvi program is located in tetex-xdvi*.rpm package in Redhat Linux which can be located through ControlPanel | Applications | Publishing | TeX menu buttons. To read dvi document give the command - xdvi -geometry 80x90 howto.dvi And resize the window with mouse. See man page on xdvi. To navigate use Arrow keys, Page Up, Page Down keys, also you can use 'f', 'd', 'u', 'c', 'l', 'r', 'p', 'n' letter keys to move up, down, center, next page, previous page etc. To turn off expert menu press 'x'. You can read postscript file using the program 'gv' (ghostview) or The ghostscript program is in ghostscript*.rpm package and gv program is in gv*.rpm package in Redhat Linux which can be located through Con- trolPanel | Applications | Graphics menu buttons. The gv program is much more user friendly than ghostscript. Ghostscript and gv are also available on other platforms like OS/2, Windows 95 and NT. To read postscript document give the command - gv howto.ps To use ghostscript give - ghostscript howto.ps You can read HTML format document using Netscape Navigator, Microsoft Internet explorer, Redhat Baron Web browser or any other web browsers. You can read the latex, LyX output using LyX a "X-Windows" front end to latex. 55.. CCooppyyrriigghhtt Copyright is GNU GPL but it is requested that you retain the author's name and email on all copies.