Htmlc: variables expansion. File created the 3rd of March 2003.

The Caml masquotte Htmlc : an HTML files generator

Compilation

This file can be compiled using:

htmlc -I ../../doc_src/Includes/ -env env0 -c example-eng.html

Defining the compiling environment

Environment files are lists of bindings. A binding defines a name (``an identifier'') to a constant value. A constant value could be an integer, a floating point number, a character, a character string, a boolean (either true or false), or a previously bound identifier.

Lexical conventions for constants and identifiers follow those of the Caml language.

Bindings may have one of the two following syntactic flavors:

Free style syntax
A binding has one of the two following forms:
ident value
or
ident = value
Comments start with a sharp sign # and spread to the end of line.
Caml style syntax
A binding is a simple Caml binding of the form
let ident = value;;
Caml comments are properly skipped.
Bindings should end with at least one newline.
Mixing the two flavors of bindings into the same environment file is strongly discouraged.

Examples of compiling environment files

The environment file env0 is free style:


The environment file env1.ml is Caml style:


So that the Htmlc'c environment variable \$X is expanded as $X, and the variable \$Y as an integer ($Y).

And similarly, the system variable <\$HOME> is now found to be <$HOME> in the user's global environment.

As usual, the hôtel \$hotel is situated at \$hotel_address.

Note that aliases are possible, as the definition of \$long_def which is properly bound to the value of \$a_long_definition_can_spread_on_more_than_one_line, which is:

$long_def
In the environment file, we purposedly choose to name the last variable defined \$last_variable and it is bound to the value true: we can check that its value is effectively ``$last_variable''.

Note that \$adresse_hotel is :
\$adresse_hotel. Meaning that the value bound to a variable can refer to the value of another variable.

As usual, the hôtel $hotel is situated at $hotel_address.

File inclusion

Here, we include the file included-eng.html.

Here is the beginning of the file included-eng.html.

Here is the end of the file included-eng.html.

Executing arbitrary commands: exec

If command name is the name of a Unix command accessible to the compiler, then write

<!--#exec cmd="command name"-->
to include the output of the command in your document. For instance, using "ls", we get the contents of the test directory of the compiler's source:

So for instance, you get the date of compilation with the following line:
<!--#exec cmd="date"-->

Size of files: fsize

An easy way to have the size of a file is to ask it to the underlying file system, using:

<!--#fsize file="example-eng.html"-->
for instance, (the source file of) this file is bytes long.

Printing names: echo

The command echo let's you output the value bound to a variable:

<!--#echo var="\$myvar"-->

Defining names: set and define

You can define variables in your document using the command define as follows:

<!--#define myvar="myvalue"-->
You can bind names to constants
<!--#define myvar="Pierre Weis, INRIA researcher"-->

Then <!--#echo var="\$myvar"--> gives you:
You can also bind names to constants computed at compile time
<!--#define myvar_with_quotes="«\$myvar»"-->

Then <!--#echo var="\$myvar_with_quotes"--> gives you:
Usinig set, you can bind names to arbitrary values computed at file expansion time
Using exec, you compute the value you want to bind via set:
<!--#set thefiles="<!--#exec cmd=\"ls results/*.htm\"-->"-->
"-->
This way, the value of the variable \$thefiles is set to the list of files in the results sub-directory, at the time of compilation of this very source file. The value given to \$thefiles is also obtained by calling echo:
<!--#echo var="\$thefiles"-->
that is: