Welcome to DIPP, the Delphi Inspiration Pascal Preprocessor!
What is DIPP?
DIPP is a Pascal Preprocessor. The purpose of DIPP is to manipulate Pascal
source code files.
DIPP can
- remove comments
- process compiler directives and switches
- remove compiler conditionals by wild card masks
- remove compiler directives by wild card masks
- insert, read, or skip include files by wild card masks
- extract units' interface sections
DIPP is useful
- to insert multiple (nested) include files into a single source file
- to simplify debugging by removing unnecessary conditionals
- to prepare your Pascal source code to be shared with 3rd parties
- to target Pascal sources at specific compiler versions for distribution
- to remove conditionals unsupported by some (old) compilers
- to provide 3rd parties with the interface section of precompiled units
DIPP is a tiny console application suitable for batch processing. It returns
an exit code <> 0 on error. DIPP reads, processes and writes one file
at a time, performing minimal syntax check as it goes. Output files can then
be passed on to Pascal compilers.
DIPP Usage and Syntax
Since DIPP is a console application, you usually run DIPP from the command
line. Open a console window and type DIPP
and press Enter
.
Called without options, DIPP displays its help screen:
C:\DIPP>DIPP
The Delphi Inspiration Pascal Preprocessor Version 1.1
Copyright (c) 2003 The Delphi Inpiration, Ralf Junker
http://www.zeitungsjunge.de/delphi/
Syntax: DIPP.exe [options] <INFILE> <OUTFILE>
-$[<+|-><sym>[;<sym>]] Remove directives / keep/remove by wildcards
-ai[<file>[;<file>]] Add / insert include files [specific files]
-C[1] Remove comments [but keep 1st comment]
-c Process Conditionals
-d<sym>[;<sym>] Define conditionals
-h[<+|-><sym>[;<sym>]] Remove conditionals / keep/remove by wildcards
-i<path>[;<path>] Include directories
-n Interface only (up to implementation identifier)
-o Overwrite existing file
-p<Pascal compiler> Imitate Pascal compiler conditional defines:
Delphi: D, D32, D1-7
Kylix: K, K1-3
C++Builder: C, C32, C1, C3-6
-ri[<FILE>[;<FILE>]] Read Include files [specific files]
-si[<FILE>[;<FILE>]] Skip Include files [specific files]
-t[i] Time stamp outfile to infile [or latest include]
|
Preprocessing Pascal files with DIPP requires you to enter both an input file
and an output file. DIPP reads from the input file and writes the processed
Pascal source code to the output file:
C:\DIPP>DIPP infile.pas outfile.pas
The Delphi Inspiration Pascal Preprocessor Version 1.1
Copyright (c) 2003 The Delphi Inpiration, Ralf Junker
http://www.zeitungsjunge.de/delphi/
In: infile.pas
Out: outfile.pas
Processed 6523 lines in 10 ms.
|
Without options, DIPP doesn't really process infile.pas except for some minor
formatting like removing multiple line breaks. To turn on real preprocessing,
you need to specify one or more of the following options:
-$ |
Remove Compiler Directives
Removing compiler directives can be used to adjust Pascal
sources to older compilers which do not support all directives of
the latest Pascal versions. Directives do not include conditionals
and switches.
|
-$ |
Removes all compiler directives. |
-$-HPPEMIT |
Removes {$HPPEMIT ...} directives only. |
-$+HINT |
Removes all directives except for {$HINT ...} . |
Multiple directives can be separated by semicolon ';' :
|
-$-HPPEMIT;NODEFINE |
Removes {$HPPEMIT ...} and {$NODEFINE ...}
directives only. |
-$+HINT;WARN |
Removes all directives except for {$HINT ...} and {$WARN
...} . |
Directive names can also contain wildcards '*' and
'?' . Wildcards allow to remove groups of directives
with start or end with particular characters.
|
-$-HPP*;*DEFINE |
Removes only those directives which start with 'HPP'
or end with 'DEFINE' . |
-$+HPP*;*DEFINE |
Removes all directives which do not start with 'HPP'
or end with 'DEFINE' . |
|
-c |
Process Conditionals
Enables processing of conditional compiler directives. With conditionals
enabled, DIPP skips over code enclosed by undefined conditionals,
inserts include files depending on defined conditionals. In other
words: DIPP treats your sources like a Pascal compiler would.
Conditional directives include:
{$DEFINE ... }
{$UNDEF ... }
{$IFDEF ... }
{$IFNDEF ... }
{$ELSE ... }
{$IFOPT ... }
Do not confuse -c (lower case) with the -C
(upper case) option, which remove comments.
|
|
-C |
Remove Comments
-C |
Removes all comments. |
-C1 |
Removes all comments but keeps the 1st comment in the file. This
can be used to keep an initial copyright or license comment present
in many Pascal source code files. |
Do not confuse -C (upper case) with the -c
(lower case) option, which enables processing conditionals. |
|
-d |
Define Conditionals
Defines conditional symbols, just like the DCC32 command
line compiler. Separate multiple defines with a semicolon ';' .
|
-DDebug |
Defines the conditional symbol 'Debug' . |
-DDebug;Console |
Defines the conditional symbols 'Debug' and 'Console' . |
|
-h |
Remove Conditionals
Removing compiler directives from Pascal sources can
be used to clean them up for easier debugging or to create sources
for specific Pascal compilers. Conditionals do not include directives
and switches.
|
-H |
Removes all conditional directives. |
-H-Debug |
Removes 'Debug' conditionals only. |
-H+Debug |
Removes all conditionals except for 'Debug' . |
Multiple directives can be separated by semicolon ';' :
|
-H-Debug;Console |
Removes 'Debug' and 'Console' conditionals
only. |
-H+Debug;Console |
Removes all conditionals except for 'Debug' and 'Console' . |
Directive names can also contain wildcards '*' and
'?' . Wildcards allow to remove groups of conditionals
with start or end with particular characters.
|
-H-MyID_* |
Removes all conditionals starting with 'MyID_' . |
-H+MyID_* |
Removes all conditionals not starting with 'MyID_' . |
|
-i |
Include Directories
The -I option lets you specify a list of
directories in which DIPP searches for include files. Separate multiple
defines with a semicolon ';' . DIPP starts searching for
include files at the current directory, then at the first directory
sepcified, then the 2nd, and so on.
|
-Ic:\pascal\include |
Searches for include files in 'c:\pascal\include' . |
|
-n |
Interface Only
-n |
Outputs the interface part of a Pascal unit only. The implementation
part will not be included. |
|
-p |
Pascal Compiler
Causes DIPP to imitate a particular Pascal compiler
by setting and selected conditional compiler symbols.
|
-PD6 |
DIPP imitates Delphi 6. |
-PD32 |
DIPP imitates a general Delphi 32 compiler. |
-PK2 |
DIPP imitates Kylix 2. |
|
-ai |
Add / Insert Include Files
-ai is one of the options to specify handling
of include files. -ai causes DIPP to insert all include
files into the output file. If enabled, DIPP processes
conditionals for all inserted include files.
|
-ai |
Inserts all include files. |
You can fine-tune the -ai option by appending one or multipe file
names, separated by semicolon ';' , which instructs DIPP
to insert only those include files specified. Include file names may
contain wildcards.
|
-aiSymbols.inc |
Inserts the include file 'Symbols.inc' only. |
-aiSymbols.inc;abc*.inc |
Inserts the include file 'Symbols.inc' plus all file
matching the wildcard 'abc*.inc' . |
If DIPP can not find an include file and open it for reading, it will
terminated with an error. To solve the problem, set the include
directories. |
|
-ri |
Read Include Files
-ri causes DIPP to read the contents of.
If enabled, DIPP processes conditionals
for all include files which DIPP reads. However, simply reading will
not insert the include files' contents
into the output file.
|
-ri |
Reads all include files. |
You can fine-tune the -ri option by appending one or
multipe file names, separated by semicolon ';' , which
instructs DIPP to read only those include files specified. Include
file names may contain wildcards.
|
-aiSymbols.inc |
Reads the include file 'Symbols.inc' only. |
-aiSymbols.inc;abc*.inc |
Reads the include file 'Symbols.inc' plus all file
matching the wildcard 'abc*.inc' . |
If DIPP can not find an include file and open it for reading, it will
terminated with an error. To solve the problem, set the include
directories. |
|
-si |
Skip Include Files
-si causes DIPP to skip all include files.
|
-ri |
Skips all include files. |
You can fine-tune the -si option by appending one or
multipe file names, separated by semicolon ';' , which
instructs DIPP to skip only those include files specified. Include
file names may contain wildcards.
|
-aiSymbols.inc |
Skips the include file 'Symbols.inc' only. |
-aiSymbols.inc;abc*.inc |
Skips the include file 'Symbols.inc' plus all file
matching the wildcard 'abc*.inc' . |
Skipping an include file does not require DIPP to be able to locate
it and open it for reading. |
|
-t |
Time Stamp Output File
The -t option instructs DIPP to set the
time stamp of the output file to that of the input file.
|
-t |
Time stamp output file to input file. |
With the additional option -ti , DIPP calculates the new
timestamp from the input file as well as all include files inserted
and read.
|
-ti |
Time stamp output file to the latest of time of input file or include
files. |
|
DIPP Examples
The following example file contains comments, conditional defines, compiler
directives and an implementation section. Let's see how we can use DIPP to modify
it.
{ Copyright (c) 2003 The Delphi Inspiration, Ralf Junker }
{ This is a test unit for DIPP. }
unit Test;
{$HPPEMIT '#include "common.h"'}
{$IMAGEBASE $00400000}
interface
{$IFDEF MSWINDOWS}
const
OS = 'MS Windows';
{$ENDIF}
{$IFDEF LINUX}
const
OS = 'Linux';
{$ENDIF}
implementation
{$IFDEF Debug}
initialization
WriteLn('!!! Debug Mode !!!');
{$ENDIF}
end.
|
Removing all comments, the file looks like:
C:\DIPP>DIPP -C test.pas out.pas |
unit Test;
{$HPPEMIT '#include "common.h"'}
{$IMAGEBASE $00400000}
interface
<SNIP>
|
Removing all but the 1st comment, the file looks like:
C:\DIPP>DIPP -C1 test.pas out.pas
|
{ Copyright (c) 2003 The Delphi Inspiration, Ralf Junker }
unit Test;
{$HPPEMIT '#include "common.h"'}
{$IMAGEBASE $00400000}
interface
<SNIP>
|
This will remove all comments but the 1st, and also remove the {$HPPEMIT
... }
compiler directive.
C:\DIPP>DIPP -C1 -$-HPPEMIT test.pas out.pas
|
{ Copyright (c) 2003 The Delphi Inspiration, Ralf Junker }
unit Test;
{$IMAGEBASE $00400000}
interface
<SNIP>
|
Next we want to remove all comments (-C
) and all compiler directives
(-$
). We also want to remove all conditionals (-h
),
so we also enable processing of conditionals (-c
)
.
Let's see what's left, if no conditional symbols are defined:
C:\DIPP>DIPP -C -$ -h -c test.pas out.pas
|
unit Test;
interface
implementation
end.
|
Why is the file almost empty? DIPP does, by default, not know about the Pascal
compiler. Imitating Delphi 6 (-pD6
) defines the MSWINDOWS
conditional symbol and DIPP outputs the following:
C:\DIPP>DIPP -C -$ -h -c -pD6 test.pas out.pas
|
unit Test;
interface
const
OS = 'MS Windows';
implementation
end.
|
Now imagine creating a Debug build by defining the Debug
conditional
symbol at the command prompt with -DDebug
:
C:\DIPP>DIPP -C -$ -h -c -pD6 -DDebug test.pas out.pas
|
unit Test;
interface
const
OS = 'MS Windows';
implementation
initialization
WriteLn('!!! Debug Mode !!!');
end.
|
Last but not least, we will create an interface file for Kylix (-pK
)
with all comments after the 1st and all conditionals removed. We will, however,
not remove the compiler directives:
C:\DIPP>DIPP -C1 -h -c -pK test.pas out.pas
|
{ Copyright (c) 2003 The Delphi Inspiration, Ralf Junker }
unit Test;
{$HPPEMIT '#include "common.h"'}
{$IMAGEBASE $00400000}
interface
const
OS = 'Linux';
implementation
|
DIPP History
DIPP 1.2
- Added recognition of recursive include files to prevent indefinite loops.
- Added
'.pas'
default extension for include files with no extension
specified.
{$IFNDEF ...}
compiler directive was not negated. Fixed.
DIPP 1.1
- Added
-$
remove directives option.
- Added
-n
interface only option.
- Added
-o
overwrite existing file option. Changed the default
not to overwrite an existing file.
- Added
-p
Pascal compiler option.
- Added
-t
time stamp option.
- Added processing of compiler switches.
- Added Help file.
- Bug fixes.
DIPP 1.0
Initial, limited release.
Contact
DIPP is Copyright (c) 2003 The Delphi Inspiration, Ralf Junker
Internet: http://www.zeitungsjunge.de/delphi/
E-Mail: delphi@zeitungsjunge.de