RECOMMENT
Convert comments from C to C++ form


RECOMMENT is a C++ program which converts C style comments to C++ style comments.

Recall that C style comments begin (anywhere) with the marker /* and end (anywhere) with the marker */. C++ comments begin anywhere with the string // and continue to the end of the current line.

This code incorporates suggestions and coding provided on 28 April 2005 by Steven Martin of JDS Uniphase, Melbourne Florida. These suggestions allow the program to ignore the internal contents of strings, (which might otherwise seem to begin or end comments), to handle lines of code with trailing comments, and to handle comments with trailing bits of code.

Warning: a number of operating systems pretend to honor the difference between capital and lowercase letters but for various reasons of "convenience" do not actually do a proper job. My current complaint is about Macintosh OSX; when you set up your hard drive, you have one chance to choose whether it is "case sensitive" or not. After that, you can't change the option without wiping the disk. A consequence is that, although you can name a file "fred.c" or "Fred.C" and see the letters in the case you chose, at certain points, the operating system makes no distinction between upper and lower case. In particular, it is common to use "fred.c" to denote a C file and "fred.C" to denote a C++ file. On a Macintosh OSX system without strict case sensitivity, this means that a disaster will occur should you issue the command

recomment fred.c fred.C
As far as the operating system is concerned, you have asked it to read and write using the same file. And so...it doesn't create the output file, and it overwrites the input file...yes, it's gone! For this reason, the program has been modified to refuse to accept an output file which is identical to the input file except for case.

Usage:

recomment old.c new.c
where

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

RECOMMENT is available in a C++ version.

Related Programs:

C_COMMENT, a FORTRAN90 program which makes a copy of a file in which C++ style comments have been replaced by C-style comments.

CR2LF, a C++ program which reads a text file and replaces carriage returns by line feeds.

CRRM, a C++ program which reads a text file and removes carriage returns.

DEBLANK, a C++ program which makes a copy of a text file which contains no blank lines.

DECOMMENT, a C++ program which removes every comment line (beginning with a "#") from a file.

FILUM, a C++ library which performs various operations on files.

REFORMAT, a FORTRAN90 program which reads a text file that contains only real values, and writes a copy which has a fixed number of real values on each line.

REWORD, a C++ program which reads a text file and writes a copy which has a fixed number of "words" per line.

UNCONTROL, a C++ program which makes a copy of a text file which contains no control characters

WRAP, a C++ program which makes a copy of a text file in which no line is longer than a user-specified wrap length.

WRAP2, a C++ program which wraps long lines in a text file, but wraps some lines "early", so as to avoid breaking words.

Source Code:

Examples and Tests:

List of Routines:

You can go up one level to the C++ source codes.


Last revised on 27 October 2007.