(This example was inspired by the book The Pragmatic
Programmer by Andrew Hunt and David Thomas.)
Most software allows the user to enter parameters to
configure the software's behaviour. These parameters often have
a default value. For example, the program xbiff (which
informs users when new mail arrives) has an update rate which
tells xbiff how often it should check for new mail. The
user can specify a value for this option when starting the
program. If no value is specified a default is used. The default
value will be documented somewhere, normally in a man page and
possibly in any other documentation which comes with the
program. If the developer changes the default value in the code,
they must also remember to change the value wherever it appears
in the documentation. filepp can be used to automate
these changes.
When setting default values in a C program, it is normal to
#define them, as the value may be needed in more than
one place. For example: xbiff's update rate may be
needed in the piece of code that does the actual updating and in
the command line help. As filepp understands the
#define keyword, it can also read the include file
containing the default value. The include file could appear
something like this:
/* Include file "default.h".
// Contains all default values for program. Read by cpp and filepp */
/* default update rate (seconds) */
#define UPDATE_RATE 30
|
This file can be included in all C and C++ files wherever it
is needed. It can also be used in any ASCII documentation (man
page, HTML, LaTeX, etc.) and pre-processed by filepp
provided care is taken over the handling of the comments. For
example, in a HTML file the include file could be embedded in a
HTML comment, eg:
<!--
#include "defaults.h"
-->
|
This allows filepp to parse the include file, but as
the contents of the include file are hidden in a HTML comment
they will not appear in the actual web page produced. However,
as filepp has parsed the #define line, it will
replace all occurrences of the macro UPDATE_RATE with
the definition 30.
A different way of hiding the C comments is to use
filepp to convert them into the file's native comment
style. For example, all LaTeX comments start with the character
%. So for the above example, if filepp is run
with the following command line:
- filepp -D"/*=%" -D"//=%" userguide.tex.in -o
userguide.tex
it will convert all C and C++ comments of the form
"/*" and "//" to LaTeX comments: "%".
|