Clootie graphics pages - Articles

 Pascal preprocessor / description
This is description of parameters and demos supplied with Pascal preprocessor v.0.9 beta release
  • About
  • Command line parameters
  • Examples of usage
  • Where to find it?

  • About

    Pascal Preprocessor is preprocessing utility what is targetted to be able to do any preprocessing what can be done with Delphi5 preprocessor.
    Utility can
  • it really can preprocess source pascal files;
  • remove comments;
  • remove pointer additional compiler directives, like {$HPPEMIT xxx};
  • treat passed symbols as "defined" or on the contrary treat all symbols except passed as "defined";
  • can skip pointed symbols during preprocessing - leaving them in output (or on the contrary process only pointer symbold) - this is independant on previous point so symbol can be marked as "undefined" and "to be precessed" in the same time;
  • expand INC files or leave them as directives (but looking inside them);
  • have options to leave/replace original files, their timestamps;
  • "intelligently" remove lines with preprocessed directives to produce "right" formatted texts;
  • count statistics on how preprocessing directives are used in source files;
  • have predefined preprocessor states for different compilers
  • To be done to 1.0 release version
  • add correct handling of {$IFOPT} directives
  • What it can't do?
  • currently preprocessor can't handle Delphi6 and Kylix enhanced {$IF xxx} directive (and this is not planned for 1.0 release)

  • Parameters

       ppp.exe [-options] <input files>...

    Option Description
    h, ? help screen
    c Process conditional directives
    sxxx Simulates one of pascal compilers (initial state of options and defined symbols). Currently supported: "-sDelphi" - Delphi (generic; "-sDelphi5" - 5.0; "-sDelphi6" - 6.0); generic Kylix - "-sKylix"; "-sTMT" - TMT pascal ("-sTMT3" - 3.0; "-sTMT4" - 4.0) (see ppp.ini file)
    i Process include files (inserting their contents in source file)
    C Strip comments from source file
    t Assign old timestamps to output files
    r Rename old files to .bak and write new files to original filename (by default generated files saved with "pi" extention)
    u Count statistics on define usage (have to be used with "c" switch). In this case only "i,c,p,b,xp,xb" options are meaningfull/
    pxxx Add "xxx" to include path
    dxxx Define "xxx" as a preprocessor conditional symbol (in addition to standart - already defined if you are used "-sxxx" switch)
    gxxx Passthrough any conditional defines using "xxx" symbol
    bxxx Process includes with filanemes xxx for defines, but bypass include text and leave in source original include compiler directive
    yxxx Strip xxx compiler directives. This option let you remove non-needed compiler directives. For example Delphi 4 and later allows {$NODEFINE} etc. class of compiler directives, but Delphi3 and pre versions will not compile source file with these directives treating them as errors
    xd, xg, xb Invert meanings of "d, g, b" options so they mean: all but defined.
  • Options "-i -c -C" are assumed if nothing is selected.
  • Preprocessed files will be written to new files with extension .pi
  • WARNING: If the new filenames already exist, they will be deleted without warning.

  • Examples of usage

    All examples can be found in pascal preprocessor redistributive (link to it can be found at bottom of the page). Examples are placed in "ExN" directories (N - is example number).

    Example 1
    This is example of simplest usage. Just point pascal source file to preprocess. Just:
       ppp.exe _test.pas

    After executing "test.bat" file you can see output in "_test.pi" file. Look inside it and compare this file to it source "_test.pas".

    Example 2
    This is example uses the same "_test.pas" source file, but with extended command line options:
       ppp.exe -sDelphi6 -c -t -dMMM -gMMM _test.pas

    So we simulate Delphi6 compiler (-sDelphi6) with preprocessing conditional defines (-c), creating output file with same timestamp as original source file (-t). Next we define "MMM" symbol (-dMMM) - this is the same as you add "-%<dir>" directive to Delphi command line compiler. Adn finally instruct preprocesssor to leave directives with "MMM" in original source file.

    After executing "test.bat" file you could point your attention to what happened to lines of source file guarded by {$IFDEF KKK} - they got included in output file! This is because we defined "MMM" symbol and althrow we leave it in output file, but internal block guarded by {$IFDEF MMM} directive still parsed and {$DEFINE KKK} directive take action.

    Example 3
    This is example still uses the same "_test.pas" source file and once more extended set of parameters:
       ppp.exe -sDelphi6 -c -t -i -xb -dMMM -gMMM _test.pas

    This time we add "-i" and "-xb" switches. If you look at previous example you should see what althrow we added switch to simulate Delphi6 compiler preprocessor (-sDelphi6) output file still contains "Delphi5 or lower" string. This is because "" file was not preprocessed.

    Now we pass "-i" to preprocess INC files what preprocessor will meet in source file. And "-xb" to let demonstrate usage of "inverting" options, so this invertion forced preprocessor not include source of all INC files except pointed by "-bXXX" parameter ("bypass" them) in main PAS file. In normal - not inverted - mode preprocessor should only "bypass" INC files pointer by "-bXXX" parameter.

    Example 4
    This time I'll show how to use statistic counting mode. It can be usefull to collect statistics on many files at once:
       ppp.exe -c -u *.pas

    Just look at console output.

    Example 5
    Comment removing feature:
       ppp.exe -C _test.pas

    "No comments." - in both means

    Example 6
    Unneeded preprocessor definitions removing:
       ppp.exe -yEXTERNALSYM -yHPPEMIT -yNODEFINE -yNOINCLUDE _test.pas

    And: no unsupported by Delphi3 and pre versions of Delphi nasty preprocessor directives.

    Where to find it?

    Original redistributive of pascal preprocessor can be found at: this link
    If you have any suggestions or bug-reports, contact me: Alexey Barkovoy

    Please inform me of any grammar or general errors, contained on these pages, Alexey Barkovoy
    Last updated: 21-Mar-2002