PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
[Bottom][Contents][Search][Prev]: HOOK_MSG_READING[Next]: HOOK_UNKNOWN_MACRO
\ -> Configuration -> Configuration Macros -> HOOK_OUTPUT

HOOK_OUTPUT

This configuration macro allows you to specify some rexx code which is executed as PPWIZARD changes output files (with #output).

The most common reason for doing this would be to help you to maintain some "state variables" per output file.

Any symbols in this macro are replaced before each use. The hook will not see any events for the main file (only nested).

The rexx code gets passed these variables:

Example

This example shows the hook being used to remember the number of blank lines encountered per output file:

;--- Hook to keep track of state information per output file! ---------------
#NextId
#NextId LOCK "MyTransformCode"
#RexxVar   @@Level          = 1        ;;Already processing a file!
#RexxVar   @@BlankLineCnt.1 = 0        ;;Init this files counter
#DefineRexx 'HOOK_OUTPUT'
   if OutputState = 'START' then
   do
       ;--- Starting new file with #output ----------------------------------
       call Debug "HOOK_OUTPUT:SAVE  - Level = " || @@level || ', Counter = ' || @@BlankLineCnt.@@Level;
       @@Level                = @@Level + 1
       @@BlankLineCnt.@@Level = 0
   end;
   if OutputState = 'END' then
   do
       ;--- Finished the file -----------------------------------------------
       @@Level = @@Level - 1
       call Debug "HOOK_OUTPUT:RESTORE - Level = " || @@level || ', Counter = ' || @@BlankLineCnt.@@Level;
   end;
#DefineRexx

;--- Define transform code --------------------------------------------------
#DefineRexx 'Rexx4#TRANSFORM=Max1BlankLine'
   ;--- Remove leading & trailing spaces ------------------------------------
   FileLine = strip(FileLine);

   ;--- Blank line logic ----------------------------------------------------
   if  FileLine = '' then
   do
       ;--- Always remove blank lines here ----------------------------------
       @@BlankLineCnt.@@Level = @@BlankLineCnt.@@Level + 1;
       Remove = 'Want at most one blank line (no trailing blank lines either!)!'
   end;
   else
   do
       ;--- Have a non-blank line (any blank lines to output?) --------------
       if  @@BlankLineCnt.@@Level <> 0 then
       do
           ;--- We need to output a single blank line -----------------------
           FileLine = MarksNewLine || FileLine;  ;;Add blank line to start
           @@BlankLineCnt.@@Level = 0
       end;
   end;
#DefineRexx
#define Max1BlankLine                                 \
        #RexxVar @@BlankLineCnt.@@Level = 0          -\
        #transform 'Rexx4#TRANSFORM=Max1BlankLine'
#define /Max1BlankLine \
        #transform
#NextId UNLOCK "MyTransformCode"


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

[Top][Contents][Search][Prev]: HOOK_MSG_READING[Next]: HOOK_UNKNOWN_MACRO


PPWIZARD Manual
My whole website and this manual itself was developed using PPWIZARD (free preprocessor written by Dennis Bareis)
Sunday November 05 2017 at 10:00am