DWK

General
+ Home
+ Links

Programming
+ My Programs

DWK's codeform

A code formatter and colourer [intended] for C and C++.

Here is the latest version of codeform, version 1.2.0. Other versions are:

History

Spending as much time as I do on message boards etc I eventually grew tired of reading code that wasn't colour-coded. I decided to write a program to colour code myself. (Not that there weren't programs to do this already, but I wanted to try it.) The result was codeform.

The first version of codeform I wrote (version 1.00) had all the keywords hard-coded into the program. It highlighted C keywords (all the same colour), strings, character quotes, and numbers. From there, I gradually added external data files, dynamic memory allocation, etc.

Since 1.00 there have been many versions of codeform. See the file HISTORY for a complete list. (Versions after 1.10 have two periods, such as 1.2.0, in case of over 10 subversions, such as 1.2.12.)

The file HISTORY also contains a partial list of features for codeform 1.2.0.

Download

Source is included in all distributions, along with executables for Windows (and usually Linux).

  • codeform.zip (156,531): codeform version 1.2.0, including source, Windows and Linux executables.
  • codeform110.zip (17,744): codeform v1.10, including source and Windows executable.

The current official page for codeform is at http://dwks.theprogrammingsite.com/myprogs/codeform.htm.

Usage

To run codeform under Windows, type "codeform" from the command line. For Linux, type "./codeform" or the appropriate directory (or, if it's in your path, just "codeform").

To get help on codeform's usage directly from the command line, use the --usage argument. (Versions 1.00 - 1.10 used different arguments.)

$ ./codeform --usage

codeform version 1.2.0 by DWK
Executable path: ./codeform

usage: codeform [-f rule-file] [-e inline-rule] [-o output]
                [--help] [-h] [--usage] [--version] [-v]
                [--] [rule-file-if-no-other-rules] [files...]

The arguments are very similar to sed's (and -o is from GCC).

Output can go to multiple files -- just specify more than one -o argument. With
no -o arguments (or if none of the output files could be opened), stdout is
used instead.

If no rules are specified, the first argument that isn't preceded by an option
is taken as a rules file instead of an input file. With no input files, stdin
is used.

A simple usage of codeform might look like the following:
    $ ./codeform -o codeform.htm rules/c_1_html codeform.c
This formats codeform.c according to the rules in rules/c_1_html, storing the
output in codeform.htm.
$

--help, -h, and --usage do the same thing; so do --version and -v.

If you want to colour Dev-C++ style C into inline CSS, use this:

$ ./codeform -o codeform.htm -f rules/_ilcss -f rules/c_devcpp codeform.c

If you want to emulate cat for some reason, use this:

$ ./codeform

Files

Here is a description of all of the files in the root of codeform's install directory. (The files in subdirectories are too numerous to cover here.) Files or folders marked with an asterisk (*) are covered in the next section.

doc/* Doxygen-generated technical documentation for the source.
rules/The highlighting rules files that come with codeform.
codeformLinux 32-bit executable for codeform.
codeform.cThe only source file for codeform, written in ANSI C89 C.
codeform.exeWindows 32-bit executable for codeform.
codeform.htmCodeform formatted into CSS with itself with rules/c_1_css.
COPYINGThe license agreement for codeform, the GNU GPL 2.
HISTORYFeatures of codeform and descriptions of previous versions.
make.bat* Batch file that uses passes make Makewin under Windows.
Makefile* Makefile to compile codeform under Windows.
Makewin* Makefile to compile codeform under Linux.
READMEThis readme file.
TODO* An incomplete todo list.

Technical documentation

Documentation for codeform's source (generated by Doxygen) is available in the source itself and in the doc/ subdirectory. A how-to for writing and interpreting rules file is located in rules/HOWTO.txt.

Codeform is written in ANSI C89-compatible C. A makefile is included, Makefile, to compile codeform for Linux with gcc. make.bat uses Makewin to compile for Windows using gcc as well (rm is assumed to exist for the clean target). Since codeform is an ANSI compatible program, however, you should have no problems compiling it on any platform with or without the makefiles.

There is an incomplete todo list in the file TODO. There is much more that I would like to do with codeform than the list would indicate.

Contact

If you have any questions or comments, you can email me at dwks #a=t# theprogrammingsite #d-o-t# %c\\o/m%. You can visit my website at http://dwks.theprogrammingsite.com/. Alternatively, you could post a question or PM me on one of the forums I frequent (such as http://board.theprogrammingsite.com/ or http://cboard.cprogramming.com/).

Credits

Thanks to all the people who helped me with this project, directly or indirectly; in particular, Richard Stallman and all advocates of free software, for making free software such as codeform possible.

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

The GNU General Public License version 2 is included in the file COPYING.

Example

Click here to see codeform formatted by itself with the following command line:

$ ./codeform -o codeform_self.htm rules\c_1_css codeform.c

Top