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 productivity of programmers by 2 times!!
On Linux/Unixes there is a command called "indent" and "cb" . Refer to 'man indent' and 'man cb'. Note that indent and cb work for only "C" programs. For "C++" programs use "bcpp". Download the beautifier program from one of the following
BCPP was written by Steven De Toni at
For 100% assurance you need a SCIENTIFIC 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 bcpp, indent or cb is not damaging or changing the input source-code after formatting, you can use the shell script verification program or use the following technique -
Generate the object code from the original input source code using the compiler -
g++ -c myprogram.cpp
Save this file -
mv myprogram.o myprogram_orig.o
Now run bcpp -
bcpp myprogram.cpp
g++ -c myprogram.cpp
Now use the unix 'diff' command to compare the two object files -
diff myprogram.o myprogram_orig.o
Also you can use the assembler output instead of object output in compiler. Like -
g++ -S myprogram.cpp
diff myprogram.s myprogram_orig.s
It is strongly recommended that you do these two steps every time you run beautifier programs like bcpp, indent or cb.
Visit the following sites to get beautifiers for other languages like HTML, SQL, Java, Perl, Fortran.
To create presentation of codes to display using HTML -
This is a Korn shell script to verify beautifier program. Requires "pdksh*.rpm" from Linux 'contrib' cdrom. Save this file as 'text' file and chmod a+rx on it. You can re-write this shell script in PERL so that you can use it on Window 95/NT or MSDOS. Uncomment the PRGM variable to point to bcpp, cb or indent
#!/bin/ksh # Verification program to check C++ Beautifiers 'bcpp', 'indent' or cb ############################################################ # Copyright # The copyright policy is GNU/GPL. # Author: Al Dev (Alavoor Vasudevan) alavoor@yahoo.com ############################################################ check_beautify_now() { # Remove all the temp files.... \rm -f ${TMP_FILE} \rm -f ${TMP_CPPFILE}*.* FNAME=$1 if [ ! -f ${FNAME} ]; then print "\nError: The file ${FNAME} does not exist!!. Aborting now ...." exit fi \cp -f ${FNAME} ${TMP_CPPFILE}.cpp ${COMPILER} -c ${TMP_CPPFILE}.cpp if [ ! -f ${TMP_CPPFILE}.o ]; then print "Fatal Error: Failed to compile ${FNAME}. Aborting now... " exit fi \mv -f ${TMP_CPPFILE}.o ${TMP_CPPFILE}_orig.o aa=`basename $PRGM` print "\nRunning, verifying $aa on ${FNAME}" ${PRGM} ${TMP_CPPFILE}.cpp ${COMPILER} -c ${TMP_CPPFILE}.cpp \rm -f $TMP_FILE diff ${TMP_CPPFILE}.o ${TMP_CPPFILE}_orig.o 1> $TMP_FILE 2>> $TMP_FILE result="" result=`wc -c $TMP_FILE | awk '{print $1}' ` if [ "$result" = "0" ]; then print "Success!! Beautifier $aa is working properly!!\n" else print "Fatal Error: Something wrong!! Beautifier is not working!!" exit fi # ${COMPILER} -S ${TMP_CPPFILE}.cpp # diff ${TMP_CPPFILE}.s ${TMP_CPPFILE}_orig.s # Remove all the temp files.... \rm -f ${TMP_FILE} \rm -f ${TMP_CPPFILE}*.* } ########## Main of program begins here ##################3 #PRGM=/usr/bin/bcpp #PRGM=/usr/bin/cb PRGM=/usr/bin/indent COMPILER=/usr/bin/g++ TMP_FILE=beautify.tmp TMP_CPPFILE=beautify-tmp_cppfile print -n "Enter the C++ file name <default is *.cpp> : " read ans if [ "$ans" = "" -o "$ans" = " " ]; then ans="ALL" else FILENAME=$ans fi # Remove all the temp files.... \rm -f ${TMP_FILE} \rm -f ${TMP_CPPFILE}*.* if [ "$ans" != "ALL" ]; then check_beautify_now ${FILENAME} else ls *.cpp | while read FILENAME do check_beautify_now ${FILENAME} done fi
Visit following locators which are related to C, C++ -
This document is published in 11 different formats namely - DVI, Postscript, Latex, Adobe Acrobat PDF, LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages and SGML.
LaTeX documents may be converted into PDF files simply by producing a Postscript output using sgml2latex ( and dvips) and running the output through the Acrobat distill ( http://www.adobe.com) command as follows:
bash$ man sgml2latex bash$ sgml2latex filename.sgml bash$ man dvips bash$ dvips -o filename.ps filename.dvi bash$ distill filename.ps bash$ man ghostscript bash$ man ps2pdf bash$ ps2pdf input.ps output.pdf bash$ acroread output.pdf &
This howto document is located at -
Also you can find this document at the following mirrors sites -
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
man xdvi
And resize the window with mouse.
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 'ghostscript'. The ghostscript program is in ghostscript*.rpm package and gv program is in gv*.rpm package in Redhat Linux which can be located through ControlPanel | Applications | Graphics menu buttons. The gv program is much more user friendly than ghostscript. Also ghostscript and gv are available on other platforms like OS/2, Windows 95 and NT, you view this document even on those platforms.
To read postscript document give the command -
gv howto.ps
ghostscript howto.ps
You can read HTML format document using Netscape Navigator, Microsoft Internet explorer, Redhat Baron Web browser or any of the 10 other web browsers.
You can read the latex, LyX output using LyX a X-Windows front end to latex.
Copyright policy is GNU/GPL as per LDP (Linux Documentation project). LDP is a GNU/GPL project. Additional restrictions are - you must retain the author's name, email address and this copyright notice on all the copies. If you make any changes or additions to this document then you should intimate all the authors of this document.