<!doctype linuxdoc system> <!-- ************************** begin comment ***************************** The following is the HOW-TO for setting up C-C++Beautifier editor. This document is in the SGML format. You must use sgml package to process this document ************************* end of comment ***************************** --> <!-- ************************** SGML USER GUIDE ***************************** The SGML user guide on linux is located at /usr/doc/sgml-tools Read the example.sgml and guide.html documents. Usage: HTML sgml2html foo (Do not give extension .sgml here!!) Text sgml2txt foo.sgml Latex sgml2latex foo.sgml Note: Use 2 dashes - before language, error while compiling Postscript sgml2latex -language=english -o ps foo.sgml DVI sgml2latex -d foo.sgml Lyx sgml2lyx foo.sgml Richtext sgml2rtf foo.sgml gnuinfo sgml2info foo.sgml man sgml2txt -man foo.sgml SGML sgmlcheck foo.sgml ************************* end of comment ***************************** --> <article> <!-- Title information --> <title>C-C++ Beautifier HOW-TO <!-- chapt change C-C++ Beautifier HOW-TO --> <author>Al Dev (Alavoor Vasudevan) <htmlurl url="mailto:alavoor[AT]yahoo.com" name="alavoor[AT]yahoo.com"> <date>v16.2, 23 Jan 2003 <abstract> 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 standards. The information in this document applies to all the operating sytems that is - Linux, MS DOS, Apple Macintosh, Windows 95/NT/2000, BeOS, OS/2, IBM OSes, all flavors of Unix like Solaris, HPUX, AIX, SCO, Sinix, BSD, UnixWare, etc.. and to all other operating systems which support "C" compiler (it means almost all the operating systems on this planet!). </abstract> <!-- Table of contents --> <toc> <!-- Begin the document --> <sect>Introduction <p> <bf> (The latest version of this document is at <url url="http://www.milkywaygalaxy.freeservers.com">. You may want to check there for changes). </bf> 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 <bf>productivity</bf> of programmers by <bf>2 times</bf>!! On Linux/Unixes there is a command called <bf>"indent"</bf> and <bf>"cb"</bf> . Refer to 'man indent' and 'man cb'. Note that <bf>indent</bf> and <bf>cb</bf> work for only "C" programs. For "C++" programs use <bf>"bcpp"</bf>. <bf>Important NOTE:</bf> <it>To compile bcpp under unix, unpack bcpp.tar.gz and you <bf>MUST</bf> change directory to "code" and give a make. Do not change to "unix" directory and give a make. That will give lots of errors.</it> Download the beautifier program from one of the following <itemize> <item>If you are having trouble downloading software from any of the sites below, then download for a small cost from my site at <url url="http://www.milkywaygalaxy.freeservers.com">. The cost is very small to maintain this web site. Some of the free sites below are not maintained properly. <p> <item>C++ : BCPP site is at <url url="http://dickey.his.com/bcpp/bcpp.html"> or at <url url="http://www.clark.net/pub/dickey">. BCPP ftp site is at <url url="ftp://dickey.his.com/bcpp/bcpp.tar.gz"> <item>C++ : <url url="http://www.consultix-inc.com/c++b.html"> <item>C : <url url="http://www.chips.navy.mil/oasys/c/"> and mirror at <url name="Oasys" url="http://oasys.nctamslant.navy.mil/oasys/c"> <item>C++ : <url url="http://www.semdesigns.com/Products/DMS/DMSToolkit.html"> <item> C++, C, Java and Oracle Pro-C Beautifier <url url="http://www.geocities.com/~starkville/main.html"> <item> C++, C beautifier <url url="http://users.erols.com/astronaut/vim/ccb-1.07.tar.gz"> and site at <url url="http://users.erols.com/astronaut/vim/#vimlinks_src"> <item> C++, C, Java, Perl beautifier CBP <url url="http://www.prismtk.de/docs/cbp"> <item> GC! GreatCode! is a powerful C/C++ source code beautifier Windows 95/98/NT/2000 <url url="http://perso.club-internet.fr/cbeaudet"> <item> CbVan for C, C++ and Java at <url url="http://www.geocities.com/~starkville/main.html"> <item> Artistic Style beautifier for C, C++, Java at <url url="http://sourceforge.net/projects/astyle"> <url url="http://astyle.sourceforge.net">. </itemize> 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. BCPP was written by Steven De Toni at <htmlurl url="mailto: steve@alpha.ocbbs.gen.nz " name=" steve@alpha.ocbbs.gen.nz "> <sect> Installing BCPP <p> To install <url name="BCPP" url="http://dickey.his.com/bcpp/bcpp.html"> <code> Unpacking bcpp: tar zxvf bcpp.tar.gz Building bcpp: cd code make cp bcpp ~/local/bin/ cp bcpp.cfg ~/local/bin Usage: bcpp -h or bcpp -? Recommended: Always use spaces instead of tabs in indenting during beautifying. Use the option -s so that the code looks the same in all types of editors like vi, emacs, MS DOS edit, Notepad, Wordpad etc.. bcpp -s *.cpp In Solaris, you can also use: ls *.cpp | xargs -I{} -t bcpp -s {} in Linux, you can also use: ls *.cpp | xargs -i{} -t bcpp -s {} </code> <sect> How can I trust Beautifier programs??!! <p> For 100% assurance you need a <bf>SCIENTIFIC</bf> 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 <bf>bcpp</bf>, <bf>indent</bf> or <bf>cb</bf> is not damaging or changing the input source-code after formatting, you can use one of the following technique - <sect1> Method 1: Verfication Program for C++/C <label id="verifycpp1"> <p> <code> bash$ man diff bash$ diff -b --ignore-all-space originalfile formattedfile </code> <sect1> Method 2: Verfication Program for C++/C <label id="verifycpp"> <p> Generate the object code from the original input source code using the compiler - <code> g++ -c myprogram.cpp </code> Here g++ is GNU C++ compiler. This will create object output myprogram.o Save this file - <code> mv myprogram.o myprogram_orig.o </code> Now run bcpp - <code> bcpp myprogram.cpp </code> This will create the formatted output program file myprogram.cpp and move the original file to myprogram.cpp.orig. Compile the new file with - <code> g++ -c myprogram.cpp </code> Now use the unix 'diff' command to compare the two object files - <code> diff myprogram.o myprogram_orig.o </code> Both these files <bf>MUST BE IDENTICAL</bf>. This verifies that bcpp is working perfectly. On DOS or Windows 95 you may want to use the free <url name="Cygnus" url="http://www.cygnus.com"> Cygwin 'diff' or 'MKS' utilities. <bf><it>If for some reason you are not able to diff the object files then you MUST use the assembly output as described below.</it></bf> You can use the assembler output instead of object output from the C++ compiler for doing the comparison. Like - <code> g++ -S myprogram.cpp </code> This creates myprogram.s. Verify with - <code> diff myprogram.s myprogram_orig.s </code> 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 life term or long term <bf>WARRANTY</bf> on beautifier programs like 'bcpp', 'cb' or 'indent'. It is strongly recommended that you do these two steps every time you run beautifier programs like <bf>bcpp</bf>, <bf>indent</bf> or <bf>cb</bf>. <sect1> Method 3: Verfication Program for Java/C++/Others <label id="verify"> <p> Since you cannot compile the Java source code to machine code and you can compile Java source to byte-codes you cannot use the technique given in Method 2 above. When you do diff on Java class files it will always be different. In this method, a different technique will be given which can be used to validate any beautifier program for Java. Also this method is quite powerful and can be used to validate any beautifier program for any language like C, C++, PERL, SQL, HTML or Java. Since all beautifier program simply rearrange or insert whitespaces , you can strip all the whitespaces from original source file and dump it to a file called verify1.out and strip all the whitespaces from beautified source file and dump it to a file called verify2.out. Now, do a diff on verify1.out and verify2.out. If there is no difference, then beautifier program is working properly. The method is not 100% perfect and can catch atleast 98% of the errors/bugs in the beautifier program. Use this method in conjunction with other methods. But this method is better than not having a verification at all and blindly trusting the beautifier program!! Note: A whitespace can be one of following - blank space ' ', form-feed '\f', newline '\n', carriage return '\r', horizontal tab '\t' or vertical tab '\v'. <code> bash$ java StripWhitespaces sample.java > verify1.out bash$ java StripWhitespaces sample_beutified.java > verify2.out bash$ diff verify1.out verify2.out bash$ java StripWhitespaces sample.cpp > verify1.out bash$ java StripWhitespaces sample_beutified.cpp > verify2.out bash$ diff verify1.out verify2.out bash$ java StripWhitespaces sample.sql > verify1.out bash$ java StripWhitespaces sample_beutified.sql > verify2.out bash$ diff verify1.out verify2.out </code> The source code of StripWhitespaces Java program is not given here. It is left as an exercise for students (you) to write a small program in Java which will simply strip whitespaces from the input text file and output to standard console output. Students are also urged to write this small program (StripWhitespaces) in C, PERL, Unix shell script (Korn, Bourne) and AWK script. Students can see howto the same task can be accomplished in these five different languages and can do comparison of ease of programing. You should <it><bf>put a newline '\n' character after every 50 characters</bf> </it> while generating verify1.out and verify2.out so that when you do a diff you can see on which lines differences are coming up. Otherwise, verify*.out files will just contain one line and it will be difficult to pin-point where exactly the beautifier program is failing (got this point ???). <!-- <bf>WATCH OUT: </bf> You should make sure your "strip spaces program" will take care of cases like these: <code> printf("String continue at next \ line"); </code> You should take care of trailing back-slash escaping the new-line and should not strip trailing whitespace (the new line '\n') for this particular line. You should have a 'if there is a trailing back-slash' condition in your program to check this case. --> <sect1> Method 4: Shell script: Verfication Program for C++/C <label id="verifycpp"> <p> 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 <bf>bcpp</bf>, <bf>cb</bf> or <bf>indent</bf> <code> #!/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[AT]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 </code> <sect> Beautifiers for other Languages <p> Visit the following sites to get beautifiers for other languages like HTML, SQL, Java, Perl, Fortran. <itemize> <item> HTML : <url url="http://www.digital-mines.com/htb/"> <item> HTML : <url url="http://www.datacomm.ch/mwoog/software/perl/beautifier.html"> <item> HTML : <url url="http://www.watson-net.com/free/perl/s_fhtml.asp"> <p> <item> SQL : <url url="http://www.netbula.com/products/sqlb"> <item> Oracle PLSQL : <url name="http://www.revealnet.com" url="http://www.revealnet.com/Products/Formatter_Plus/formatter_plus.htm"> <p> <item> GPL <url url="http://www.geocities.com/~starkville/vancbj.html"> <item> GPL <url url="http://kevinkelley.mystarband.net/java/dent.html"> <item> Free <url url="http://www.tiobe.com/jacobe.htm"> <item> Free <url url="http://www.mmsindia.com/JPretty.html"> <item> Free <url url="http://members.magnet.at/johann.langhofer/products/jxbeauty/overview.html"> (has JBuilder support) <item> Free <url url="http://www.semdesigns.com/Products/Formatters/JavaFormatter.html"> <item> Commercial $24.99 <url url="http://smartbeautify.com"> <item> Commercial $129 <url url="http://www.jindent.com"> <item> Google <url url="http://directory.google.com/Top/Computers/Programming/Languages/Java/Development_Tools/Code_Beautifiers/?tc=1"> <p> <item> Java, SQL, HTML, C++ : <url url="http://www.semdesigns.com/Products/DMS/DMSToolkit.html"> <item> Java JIndent <url url="http://home.wtal.de/software-solutions/jindent"> <item> Java Pat <url url="http://javaregex.com/cgi-bin/pat/jbeaut.asp"> <item> Java JStyle <url url="http://www.redrival.com/greenrd/java/jstyle"> <item> Java JPrettyPrinter <url url="http://www.epoch.com.tw/download/ms/java/java.htm"> <item> Java JxBeauty <url url="http://members.nextra.at/johann.langhofer/download/jxbeauty"> and the <url name="JxBeauty Home" url="http://members.magnet.at/johann.langhofer/products/jxbeauty/overview.html"> <item> Java beautify <url name="percolator" url="http://www2.blaze.ca/~jspeton/percolator"> <item> Java list <url url="http://www.java.about.com/compute/java/library/weekly/aa102499.htm"> <item> Java html present <url name="VasJava2HTML" url="http://www.chez.com/vasile/java2/VasJava2HTML.html"> <item> Java code colorifier and beautifier <url url="http://www.mycgiserver.com/~lisali/jccb"> <p> <item> Perl : <url url="http://www.consultix-inc.com/www.consultix-inc.com/talk.htm"> <item> Perl : <url url="http://www.consultix-inc.com/www.consultix-inc.com/perl_beautifier.html"> <p> <item> Fortran beautifier : <url url="http://www.aeem.iastate.edu/Fortran/tools.html"> <p> <item>C++ : BCPP site is at <url url="http://dickey.his.com/bcpp/bcpp.html"> or at <url url="http://www.clark.net/pub/dickey">. BCPP ftp site is at <url url="ftp://dickey.his.com/bcpp/bcpp.tar.gz"> <item>C++ : <url url="http://www.consultix-inc.com/c++b.html"> <item>C : <url url="http://www.chips.navy.mil/oasys/c/"> and mirror at <url name="Oasys" url="http://oasys.nctamslant.navy.mil/oasys/c"> <item> C++, C, Java, Oracle Pro-C Beautifier <url url="http://www.geocities.com/~starkville/main.html"> <item> C++, C beautifier <url url="http://users.erols.com/astronaut/vim/ccb-1.07.tar.gz"> and site at <url url="http://users.erols.com/astronaut/vim/#vimlinks_src"> <item> GC! GreatCode! is a powerful C/C++ source code beautifier Windows 95/98/NT/2000 <url url="http://perso.club-internet.fr/cbeaudet"> <item> C++ beautifier 'SourceStyler' <url url="http://www.ochre.com.au"> </itemize> <itemize> <item>White paper on beautifier : <url url="http://www.consultix-inc.com/www.consultix-inc.com/talk.htm"> </itemize> To create presentation of codes to display using HTML - <itemize> <item>Presentation (C,C++,Java) to html : <url url="http://www.perlstudio.de/cbindex.html"> <p> <item> The GNU project: Source-Highlight: <url url="http://www.gnu.org/software/src-highlite"> and its KDE frontend Ksrc2html <url url="http://murphy.netsolution-net.de/Ksrc2.html"> </itemize> Also search the search engines like <url url="http://www.yahoo.com"> or <url url="http://www.lycos.com"> and search for keyword "beautfier". <sect> Beautifiers For SGML and XML <p> To beautify SGML and XML use one of these perl scripts. I used perl script from Kevin and it works fine for me. <sect1> SGML Auto-Indenter By Kevin <p> This script was written by Kevin M. Dunn <htmlurl url="mailto: kdunn@hsc.edu " name=" kdunn@hsc.edu "> Department of Chemistry Hampden-Sydney College HSC, VA 23943 (804) 223-6181 (804) 223-6374 (Fax) Several people have discussed the use of Tidy to indent sgml and xml sources, but does not work for SGML documents, as Tidy did not recognize the entities. Rather than fix Tidy, here is the perl script to indent anything with sgml-type tags. Only non-empty tags are indented, and text is justified at 80 characters/line (easily changed). Known problems: will break line-specific enviroments. So far, the script is quite general--it does not recognize specific tags and so could be used for any xml or sgml, not just docbook. Is there any way to recognize literal text independent of DTD? Leading whitespace, for example? Trailing whitespace? Or I could indent tags only, and leave all non-tag text unjustified and unindented. Note: In code below, you should remove the extra spaces I put between / g; in line 22. I put this to create Linuxdoc. <code> #!/usr/bin/perl -w # # sb: the sgml beautifier # indents non-empty sgml tags # usage: sb filename or sb < filename or | sb # author: Kevin M. Dunn (kdunn@hsc.edu) # license: anyone is free to use this for any purpose whatever # $jl = 80; #text will be justified to 80 characters/line $nl = 0; $sp = 0; $newline = ""; # hack to prevent extraneous blank first line $space[0] = ""; separate_tags(); get_tags(); indent_tags(); unlink ("$$.tmp"); # remove temporary file print "\n"; # add final newline to output sub separate_tags { open(FILETMP, ">$$.tmp"); while (<>){ $_ =~ s/</\n</ g; $_ =~ s/>/>\n/g; print FILETMP "$_"; } close(FILETMP); } sub get_tags { open(FILETMP, "$$.tmp"); while (<FILETMP>){ $word = $_; $word =~ s/[> ].*//; chomp($word); if ( $word =~ /^<\/.*/ ){; $tag2{$word} = 1; $word =~ s/\///; $tag1{$word} = 1; } } } sub indent_tags { open(FILETMP, "$$.tmp"); while (<FILETMP>){ chomp($_); $word = $_; $word =~ s/[> ].*//; if ( $tag1{$word} ){ print "\n$space[$sp]$_"; $nl = $jl; # force new line on next line of input $sp++; if ( ! $space[$sp] ){ $space[$sp] = $space[$sp-1] . " "; } } elsif ( $tag2{$word} ){ $sp--; print "\n$space[$sp]$_"; $nl = $jl; # force new line on next line of input } elsif ( $word =~ /<.*/ ) { print "$newline$space[$sp]$_"; $newline = "\n"; # hack to prevent extraneous blank first line $nl = $jl; # force new line on next line of input } elsif ( length($_) > 0 ) { justify(); } } } sub justify { @words = split; $nw = @words; for ($i = 0; $i < $nw; $i++ ){ $ll += length($words[$i]) + 1 + $nl; # line length if this word is added if ($ll < $jl){ # if short enough, print it print "$words[$i] "; $nl = 0; } else { # if line is too long, start a new one print "\n$space[$sp]$words[$i] "; $nl = 0; $ll = length($space[$sp] . $words[$i]) + 1; } } } </code> <sect1> SGML Auto-Indenter By Hector <p> Download from <url url="http://www.olea.org/tmp/indent-sgml-xml">. The author is at <htmlurl url="mailto: hector@debian.org " name=" hector@debian.org "> Note: In code below, you should remove the extra spaces I put between & indentar, & fin etc.. I put this to create Linuxdoc. <code> #!/usr/bin/perl -w # use XML::Parser::Expat; $|=1; if ( !$ARGV[0] ) { print "Argument missing\n"; exit 1; } $inline_tags = "acronym|ulink|link|citetitle|firstname|surname|application|guimenu|guisubmenu|guimenuitem|menuchoice|interface|guilabel|guibutton|glossterm|systemitem|filename|xref|emphasis|keycap|markup|email|command|inlinegraphic|entry|email|screeninfo|graphic"; $one_line = "title|member"; $todo = ""; $temp = ""; $ancho = " "; $indentacion = 0; #open IN , "<$ARGV[0]"; #my $todo = join ('', <IN>); #close (IN); $parser = new XML::Parser::Expat; $parser->setHandlers('Start' => \& inicio, 'End' => \& fin, 'Char' => \& cadena, 'Comment' => \& comentario); open(FOO, "$ARGV[0]") or die "Couldn't open"; $parser->parse(*FOO); close(FOO); $todo =~ s/\n+/\n/gm; $todo =~ s/\n *\n/\n/gm; print "$todo\n"; exit 1; sub inicio { my ($p, $el, %atts) = @_; my $tag = "<$el"; foreach my $key ( sort %atts) { if ( $atts{$key} ) { $tag .= " $key=\"$atts{$key}\""; } } $tag .= ">"; if ( !($el =~ /$inline_tags|$one_line/) ) { $temp = & indentar ($temp, $ indentacion); if ( $temp ) { $todo .= "$temp\n"; } my $pad = $ancho x $indentacion; $todo .= "$pad$tag\n"; $temp = ""; $indentacion++; } else { $temp .= $tag; } } sub fin { my ($p, $el) = @_; my $tag = "</$el>"; if ( !($el =~ /$inline_tags/) ) { $temp = & indentar ($temp, $indentacion); $temp =~ s/\n$// ; $todo .= "$temp"; if ( !($el =~ /$one_line/) ) { $indentacion--; if ( !($todo =~ /\n$/) ) { $todo .= "\n"; } my $pad = $ancho x $indentacion; $todo .= "$pad"; #$indentacion--; } $todo .= "$tag\n"; $temp = ""; # $indentacion++; } else { $temp .= "$tag"; } } sub cadena { my ($p, $str) = @_; $str =~ s/ +/ /g; #$str =~ s/^ //; #$str =~ s/ $//; $temp .= "$str"; } sub comentario { my ($p, $str) = @_; $todo .= "<!--\n $str \n-->\n"; } sub indentar () { my $linea = $_[0] ; # print ("Indentacion es $_[1]\nLinea $_[0]\n"); my $indentacion = $_[1]; my $cantidad = 75 - ( $indentacion * length($ancho)); my $pad = $ancho x $indentacion; my $temp = & cortar_linea ( $linea, $cantidad); $temp =~ s/\n/\n$pad/g; $temp =~ s/^ //; my $resultado = "$pad$temp\n"; return $resultado; } sub cortar_linea () { my $linea = $_[0]; #$linea =~ s/\n/ \n/; $linea .= " "; my $cantidad = $_[1]; $temp = ""; $temp2 = ""; #print "Llega $linea\n"; while ( $linea =~ /(.+?) / ) { if ( (length ($temp) + length ($+)) <= $cantidad ) { $temp .= "$+ "; $linea = $'; } elsif ( length ($+) >= $cantidad ) { $linea = $'; $temp2 .= "$temp\n$+"; $temp = ""; } else { $temp2 .= "$temp\n"; $temp = "$+ "; $linea = $'; } } $temp2 .= "$temp\n"; $temp2 =~ s/\n$//; $temp2 =~ s/ $//; # print "Sale\n##$temp2##\n"; return $temp2; } </code> <sect> Related URLs <p> Visit following locators which are related to C, C++ - <itemize> <item> <url url="http://metalab.unc.edu/LDP/HOWTO/Vim-HOWTO.html" name="Vim color text editor for C++, C"> <item> <url url="http://metalab.unc.edu/LDP/HOWTO/C++Programming-HOWTO.html" name="C++ Programming HOWTO"> <item> <url url="http://metalab.unc.edu/LDP/HOWTO/CVS-HOWTO.html" name="CVS HOWTO for C++ programs"> <item> Linux goodies <url url="http://www.milkywaygalaxy.freeservers.com"> and mirrors at <url url="http://aldev0.webjump.com">, <url name="angelfire" url="http://www.angelfire.com/country/aldev0">, <url name="geocities" url="http://www.geocities.com/alavoor/index.html">, <url name="virtualave" url="http://aldev0.virtualave.net">, <url name="50megs" url="http://aldev0.50megs.com">, <url name="theglobe" url="http://members.theglobe.com/aldev1/index.html">, <url name="NBCi" url="http://members.nbci.com/alavoor">, <url name="Terrashare" url="http://aldev.terrashare.com">, <url name="Fortunecity" url="http://members.fortunecity.com/aldev">, <url name="Freewebsites" url="http://aldev.freewebsites.com">, <url name="Tripod" url="http://members.tripod.lycos.com/aldev">, <url name="Spree" url="http://members.spree.com/technology/aldev">, <url name="Escalix" url="http://www.escalix.com/freepage/aldev">, <url name="Httpcity" url="http://www.httpcity.com/aldev/index.html">, <url name="Freeservers" url="http://aldev.freeservers.com">. </itemize> <sect> Other Formats of this Document <p> This document is published in 14 different formats namely - DVI, Postscript, Latex, Adobe Acrobat PDF, LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages, single HTML file, SGML (Linuxdoc format), SGML (Docbook format), MS WinHelp format. This howto document is located at - <itemize> <item> <url url="http://www.linuxdoc.org"> and click on HOWTOs and search for howto document name using CTRL+f or ALT+f within the web-browser. </itemize> You can also find this document at the following mirrors sites - <itemize> <item> <url url="http://www.caldera.com/LDP/HOWTO"> <item> <url url="http://www.linux.ucla.edu/LDP"> <item> <url url="http://www.cc.gatech.edu/linux/LDP"> <item> <url url="http://www.redhat.com/mirrors/LDP"> <item> Other mirror sites near you (network-address-wise) can be found at <url url="http://www.linuxdoc.org/mirrors.html"> select a site and go to directory /LDP/HOWTO/xxxxx-HOWTO.html </itemize> <itemize> <item> You can get this HOWTO document as a single file tar ball in HTML, DVI, Postscript or SGML formats from - <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO/other-formats/"> and <url url="http://www.linuxdoc.org/docs.html#howto"> <p> <item>Plain text format is in: <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO"> and <url url="http://www.linuxdoc.org/docs.html#howto"> <p> <item>Single HTML file format is in: <url url="http://www.linuxdoc.org/docs.html#howto"> <p> Single HTML file can be created with command (see man sgml2html) - sgml2html -split 0 xxxxhowto.sgml <p> <item>Translations to other languages like French, German, Spanish, Chinese, Japanese are in <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO"> and <url url="http://www.linuxdoc.org/docs.html#howto"> Any help from you to translate to other languages is welcome. </itemize> The document is written using a tool called "SGML-Tools" which can be got from - <url url="http://www.sgmltools.org"> Compiling the source you will get the following commands like <itemize> <item>sgml2html xxxxhowto.sgml (to generate html file) <item>sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file) <item>sgml2rtf xxxxhowto.sgml (to generate RTF file) <item>sgml2latex xxxxhowto.sgml (to generate latex file) </itemize> <sect1> Acrobat PDF format <label id="acrobatpdf"> <p> PDF file can be generated from postscript file using either acrobat <bf>distill</bf> or <bf>Ghostscript</bf>. And postscript file is generated from DVI which in turn is generated from LaTex file. You can download distill software from <url url="http://www.adobe.com">. Given below is a sample session: <code> 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 & </code> Or you can use Ghostscript command <bf>ps2pdf</bf>. ps2pdf is a work-alike for nearly all the functionality of Adobe's Acrobat Distiller product: it converts PostScript files to Portable Document Format (PDF) files. <bf>ps2pdf</bf> is implemented as a very small command script (batch file) that invokes Ghostscript, selecting a special "output device" called <bf>pdfwrite</bf>. In order to use ps2pdf, the pdfwrite device must be included in the makefile when Ghostscript was compiled; see the documentation on building Ghostscript for details. <sect1> Convert Linuxdoc to Docbook format <label id="linuxdoc2docbook"> <p> This document is written in linuxdoc SGML format. The Docbook SGML format supercedes the linuxdoc format and has lot more features than linuxdoc. The linuxdoc is very simple and is easy to use. To convert linuxdoc SGML file to Docbook SGML use the program <bf>ld2db.sh</bf> and some perl scripts. The ld2db output is not 100% clean and you need to use the <bf>clean_ld2db.pl</bf> perl script. You may need to manually correct few lines in the document. <itemize> <item> Download ld2db program from <url url="http://www.dcs.gla.ac.uk/~rrt/docbook.html"> or from <url name="Milkyway Galaxy site" url="http://www.milkywaygalaxy.freeservers.com"> <item> Download the cleanup_ld2db.pl perl script from from <url name="Milkyway Galaxy" url="http://www.milkywaygalaxy.freeservers.com"> </itemize> The ld2db.sh is not 100% clean, you will get lots of errors when you run <code> bash$ ld2db.sh file-linuxdoc.sgml db.sgml bash$ cleanup.pl db.sgml > db_clean.sgml bash$ gvim db_clean.sgml bash$ docbook2html db.sgml </code> And you may have to manually edit some of the minor errors after running the perl script. For e.g. you may need to put closing tag < /Para> for each < Listitem> <sect1> Convert to MS WinHelp format <label id="mswinhelp"> <p> You can convert the SGML howto document to Microsoft Windows Help file, first convert the sgml to html using: <code> bash$ sgml2html xxxxhowto.sgml (to generate html file) bash$ sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file) </code> Then use the tool <url name="HtmlToHlp" url="http://javadocs.planetmirror.com/htmltohlpe.html">. You can also use sgml2rtf and then use the RTF files for generating winhelp files. <sect1> Reading various formats <label id="readformats"> <p> 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 - <tscreen><verb> xdvi -geometry 80x90 howto.dvi man xdvi </verb></tscreen> 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. <itemize> <item>Get ghostscript for Windows 95, OS/2, and for all OSes from <url url="http://www.cs.wisc.edu/~ghost"> </itemize> To read postscript document give the command - <tscreen><verb> gv howto.ps ghostscript howto.ps </verb></tscreen> 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. <sect> Copyright <p> 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. </article>