Use those ubiquitous web browsers to advantage and show C or C++ code in a more readable format.
This program acts as a file filter that will convert a C or C++ source file into an HTML file, providing two enhancing formatting capabilities. The resulting HTML document displays regular code as bold, and it displays comments in italics.
The output of this filter can easily be inserted into an HTML World Wide Web document and provide a nicely annotated program listing. The utility properly understands strings and character constants in the source, as well as translating HTML-based special symbols (such as '<', '>', and '&') into their correct HTML characters.
To use the filter in either MS-DOS or UNIX, type the following at the command line:
C2HTML < in file > <output file>The program reads standard input and determines where the comments are, inserting in the output the appropriate HTML commands as it goes. Note that the filter is currently designed to automatically handle nested comment pairs (not all compilers support this).
The filter does not perform any checks on the source file, so it assumes the file is a syntactically correct program.
Since the processing of comments is very similar in the languages C/C++ and Pascal, I have included two separate versions for each of these languages. (The Pascal version is on the code disk and online sources.) The source modules are called C2HTML.C and PAS2HTML.C. o
Don Retzlaff is a tenured lecturer in the Computer Science Department at the University of North Texas. He has taught in the CS department at UNT for seventeen years and teaches the full range of courses in their undergraduate program. Don can be reached by e-mail at donr@gab.unt.edu, or by his homepage at http://hercule.csci.unt.edu/donr/.