C to HTML converter, version 1

c2html


The program c2html is a simple C to HTML compiler. Given a C code it creates the HTML file containing the C code plus the target tags for every define, type, variable and/or function.

Moreover, it establish a link for every known function call, variable, type or contant use.


Index

  1. Introduction
  2. Usage
  3. Limits
  4. Examples
  5. Future plans
  6. Download

Introduction

Writing documentation is often a hard work. Maintaing is even worse.

The main purpose of this project is to have a program that automatically generates a HTML file from a C file, with the target tags before any define, type, variable and/or function. In this way the links to the code can be done even by hand and if code changes, only the C code have to be converted to HTML again.

c2html does exactly this. Given a C file, generates a HTML file with the target tags on the right place, plus the code is automatically linked whenever possible and some constructs are colored.

The program is based on a parsing routine, so addign some color was a simple job. If necessary, other constructs can be colored without problems, but I think this is enough.


Usage

c2html is based on a C parser routine, so no particular formatting is needed. However, the C language is too complex to be handled completly, not every C program can be converted to HTML using this program.
See
limits for details.

The syntax of the program is simple:

c2html [options] filename [outdir] [indir]

where:

options is any sequence of
-p
write all input in stderr
-p-
do not write any input (defualt)
-l file
link function prototypes to the file
-l-
do not link function prototypes (default)
-u file
link functions without prototype to the file
-u-
do not link functions without prototype (default)
-m file
link macros to the file
-m-
no not link macros (default)
-c dir
create the chi file in dir
-c-
do not create the chi file (default)
-I path
add path to the include path
-h, -?, ?
write the help screen
filename
name of the C file (without path)
outdir
directory where to write the HTML file (default current dir)
indir
directory where to find the C file (defaul current dir)

The result of the operation is the HTML file in the outdir directory with a slightly modified filename.html

i.e.:
c2html c2html.c

generates the file
c2html_c.html

Another output file, the chi file can be obtained using the -c option. This files are used by the c2html to link different source code files.

i.e.:
c2html -c chidir a.c
c2html -I chidir main.c

links all the functions used in the main.c and defined in the a.c.


Limits

As stated before, this program is based on a parser of the C code, but as you can immagine, the C language is very complicated. More, the normal compilation is done in two passes, so the real C compilers does not know anything about preprocessing.

This is not the case with c2html. It must preserve the program structure. So the parser parses the preprocessor commands too.

This makes parsing every possible C program nearly impossible. For this reason c2html recognise only a subset of the C programs. It should be capable of parsing any well written C program.

Follows the list of known incompatibilities, that will not be resolved:


Examples

I know that the best type of documentation are the examples. So let begin.

Here is a list of functions defined within c2html.c:

Here is a list of variables defined within chtmldefs.h: Here is a type define within chtmldefs.h: Here is a list of defines defined within chtmldefs.h: Here is a list of functions defined within chtmlidfs.h: Here is a list of functions defined within chtmlprocs.c: You are wondering where are the examples?

Well this page is an example. The page is written by hand, while source code files were generated using c2html.


Future plans

This version should be the final one. It has everything I needed.

If you need something more, send me a mail. If I will have some time, maybe I will extend the program.

However, you can download the source code, so you can add your own extensions, if you want. If someone will extend it, please let me know.


Download

You can download the source code:
After then, simply compile c2html.c with the -ll option (lex must be present in the system)


Top of the page.
Send comments to: Igor Sfiligoi

Created:13.2.1997
Last modified:4.4.1997