PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: #Info[Next]: #MacroSpace
\ -> Commands -> #intercept


This command allows you to filter a block of lines as they are read from the input file before ppwizard has done any real processing on them (for example before comments and blank lines have been removed). You can not nest intercept blocks.

When defining the start of the block you specify the name of a macro containing the rexx code to be executed for each line.

Great care must be taken if the intercept commands are used directly in an input file rather than via a macro as ppwizard will not detect the end of the block unless you are careful. When read from a file the end block command must be in the same case as the start block command (you can use this fact to your advantage if you wish to process ppwizard code which itself might contain the command!). When the end block command appears outside of a macro not only must be case be correct but the line must NOT have any inline comments.

The rexx code is passed the "current" line in the FileLine rexx variable.

The rexx code may modify the line and can include "<?NewLine>" codes to cause line breaks in the generated output file. If you had used newline codes ("d2c(10)") instead then any generated ppwizard commands after the first newline will be executed but these will not cause newlines to be generated in the output file.


[WhiteSpace]#intercept  [["]MacroContainingCodeName["]]

If the single parameter exists then this marks the start of the block, if missing it marks the end of the block. To start the block you need to supply the name of the macro that contains the transformation code.

Example #1

Silly example but shows the basics:

;--- Define the rexx code ---
#DefineRexx DoubleUp
            ;--- Stupid example to create 2nd line based on that from file ---
            FileLine = Fileline || '<?NewLine>   2nd Copy=>' || FileLine;

;--- Start block / 3 lines / End block ----
#IntercepT DoubleUp

You should note the leading whitespace that was not removed on the second lines.

Example #2

This shows how (bit primative maybe) you could use the existing example inclusion macros but ensure that long lines get wrapped (this might allow source code displayed in a browser to be printed without losing line ends).

;--- Configuration ----------------------------------------------------------
#define     SPLIT_MAX_POS        90
#define     SPLIT_MIN_POS        <$SPLIT_MAX_POS>-30       ;;Look back for space how far
#define     SplitEndOld          <FONT COLOR="RED">&lt;&lt;&lt;(line continued)</FONT>
#define     SplitStartNew        <FONT COLOR="RED">&gt;&gt;&gt;</FONT>
#define     SplitStartNewChars   3         ;;Represents space used in chars

;--- Define the rexx code ------------------------------------------------------------------------------------------------------------
#DefineRexx BreakupLongLines
            ;--- Incorrect packing would probably occur due to macros -------
            #Option PUSH AllowPack=NO

            ;--- QUICK check to see if any change required ------------------
            if length(FileLine) > <$SPLIT_MAX_POS> then
               ;--- Work out indenting of this line -------------------------
               NsPos = verify(FileLine, '2009'x);        ;;Skip past spaces and tabs
               if  NsPos <= 1 then
                   LineIndent = '';                      ;;No indent
                   LineIndent = left(FileLine, NsPos-1); ;;Use same whitespace (to ensure same tabs/spaces)

               ;--- Fudge set indent ----------------------------------------
               LineIndent = copies(' ', 4) || LineIndent;

               ;--- Now set up line breaks ----------------------------------
               Left   = '';
               Right  = FileLine;
               MinLng = <$SPLIT_MIN_POS>;
               MaxLng = <$SPLIT_MAX_POS>;
               do while length(Right) > MaxLng
                   ;--- Get left part of long line (try to break at space) --
                   LeftBit = left(Right, MaxLng);
                   SpcPos  = lastpos(' ', LeftBit);
                   if SpcPos >= MinLng then
                      BreakPos = SpcPos;           ;;Break at the space (Note I decided to not trim whitespace either side)
                      BreakPos = MaxLng;           ;;Can't break at a space

                   ;--- Need to split the line further ----------------------
                   Left  = Left || left(Right, BreakPos) || '*LineBreak*' || LineIndent || '*LineRest*';
                   Right = substr(Right, BreakPos+1);

                   ;--- Take care of 3 added chars that mark line continuation ---
                   MinLng = <$SPLIT_MIN_POS> - <$SplitStartNewChars>;
                   MaxLng = <$SPLIT_MAX_POS> - <$SplitStartNewChars>;
               FileLine = Left || Right;
            #Option POP

;--- After "<" and other chars converted, translate markers to tags etc -----
#AutoTagState +
#AutoTag      '*LineBreak*'    '<$SplitEndOld $$SQx2><?Newline>'
#AutoTag      '*LineRest*'     '<$SplitStartNew $$SQx2>'
#AsIs         SETUP  FixLineContinuation
#AutoTagState -

;--- Include header for example support -------------------------------------
#include "HTMLPRE.IH"

;--- Include the example (long lines get wrapped) ---------------------------
#IntercepT "BreakupLongLines"      ;;Note following line must be not be too long!!!!!
<$ExampleFile FILE="2.in" STATE=REMEMBER ASIS=FixLineContinuation>

email me  any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Search][Prev]: #Info[Next]: #MacroSpace

My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Saturday May 28 2022 at 2:55pm