![]() | ![]() | ![]() | ![]() | ![]() |
This command allows you to define a block of lines for which transformations (that you define) should take place.
I got the idea when creating some javascript to output html (using javascript's "document.writeln()" routine), this can be hard as the html code becomes less readable and you have problems with handling quotes.
I needed to use javascript to generate HTML controls that should only be available if the javascript they need can also be available.
What I wanted was an automated way of adding the "document.writeln()" code and taking care of any content issues such as handling quote characters. This way I just edit the easily readable html code and not worry about which quotes I'm allowed to use or what to do when I need both!
A transformation is one of the last things to occur before a line is generated into the output file.
To perform transformations you must first define the rexx code to modify the "current" line (in the FileLine variable). An example of code which handles the problem described above follows:
#DefineRexx DOC_WRITELN ;--- Escape any escape characters ------------------------------- FileLine = ReplaceString(FileLine, "\", "\\"); ;--- Escape any single quotes (we use this below) --------------- FileLine = ReplaceString(FileLine, "'", "\'"); ;--- Now wrap in javascript code to write it out ---------------- FileLine = "document.writeln('" || FileLine || "')"; #DefineRexx
Once you have defined the transformation code you can then mark the start and end of the block of lines that get transformed on output. You can not nest transformation blocks.
[WhiteSpace]#Transform [["]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.
This code show another larger chunk of rexx code being used to transform some html:
;--- Turn tracing off (or hugh debug output) -------------------------------- #define REXXTRACE OFF ;--- Define some transformation code ---------------------------------------- #DefineRexx HIDE_HTML ;--- Convert into codes ----------------------------------------- Before = FileLine; After = ''; do Posn = 1 to length(Before) ;--- Get the next byte --------------------------------------- ThisByte = substr(Before, Posn, 1); ;;Byte As Character ;--- Want Hex or Octal codes (Hex is default)? --------------- #ifndef HIDE_HTML_IN_OCTAL ;--- Calculate HEX code ---------------------------------- Code = '\x' || c2x(ThisByte); ;;Byte As Hex code #elseif ;--- Convert to code (octal) ----------------------------- ThisByte = c2d(ThisByte); ;;Byte As ASCII Code = ''; do while ThisByte <> 0 ;--- Add next digit ---------------------------------- Code = Code || (ThisByte // 8); ;--- Prepare for next loop --------------------------- ThisByte = ThisByte % 8; end; ;--- Add escape and put digits in correct order ---------- Code = left(Code, 3, '0'); ;;MUST be 3 digits Code = '\' || reverse(Code); ;;Byte As Octal code #endif ;--- Add to output (note I don't check max literal length!) -- After = After || Code; end; ;--- Now wrap in javascript code to write it out ---------------- FileLine = "document.writeln('" || After || "')"; #DefineRexx ;--- Start HTML ------------------------------------------------------------- <HTML> <BODY> ;--- Now create encoded body ------------------------------------------------ <SCRIPT LANGUAGE=JavaScript> #transform HIDE_HTML <H1>Simplest Hidden code Possible</H1> <P>This is a sample of the simplest way to hide code, of course it only works if user's browser can handle javascript. <P>You could get much more complicated and encrypt the code however anything you do can still be undone as of course while the codes can't be read directly the javascript can, one way out of this might be to include the javascript at runtime. <P>Note I have since realised that not all browsers show the source code, they show the "resultant" code instead, however this is still good demonstration code! #transform </SCRIPT> ;--- Show something if no javascript ---------------------------------------- <NOSCRIPT> <P>Sorry your browser does not handle javascript or you have it turned off! </NOSCRIPT> ;--- End of HTML ------------------------------------------------------------ </BODY> </HTML>
I wanted to be able to show as an example the output of a macro, however it generated html/xml code and would therefore not display correctly in a browser (it also generated characters that upset IPF code).
What I needed to do was "transform" the end result, this is what I did:
;--- Define required IPF & HTML transformations ----------------------------- #DefineRexx "MAKE_HTML_VIEWABLE" #if ['<$DocType>' = 'HTML'] FileLine = ReplaceString(FileLine, '<', '<'); ;;Hide HTML from browser #elseif FileLine = ReplaceString(FileLine, ':', '&colon.'); ;;For IPF - Hide ':' #endif #DefineRexx ;--- Show example ----------------------------------------------------------- <$ExampleFormatted> #transform MAKE_HTML_VIEWABLE <$WantToSeeWhatItExpandsTo> #transform <$eExampleFormatted>
![]() | ![]() | ![]() | ![]() | ![]() |