Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting syntax highlighted sources / REXX and regular expressions /

Status
Not open for further replies.

mikrom

Programmer
Mar 27, 2002
2,985
SK
Some times ago I thought about how to color my source-codes posted here at Tek-Tips.

The possible way consists of 2 steps:
1. Converting syntax highlighted source into HTML.
2. Translating HTML into TGML.

The 1.step will be done with my editor Vim, which I use for almost all coding.

The 2.step is a task for a scripting language.
I first wrote such a script in Perl, but then I thought: Why not do it in REXX? It would be a good exercise to look at the regular expression supported in ooREXX.
So, I done it and here is the script tek_tips_poster.rex:
Code:
[COLOR=#0000ff]/*****************************************************************************/[/color]
[COLOR=#0000ff]/* Usage example:                                                            */[/color]
[COLOR=#0000ff]/*   [rexx] tek_tips_poster.rex < matrices.rex.html > post.txt               */[/color]
[COLOR=#0000ff]/*****************************************************************************/[/color]

[COLOR=#0000ff]/* define regular expressions for tags which should be skipped */[/color]
re_doc [COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'<!DOCTYPE HTML?+">'[/color][COLOR=#008080])[/color]
re_html[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'<\/*html>'[/color][COLOR=#008080])[/color]
re_head[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'<\/*head>'[/color][COLOR=#008080])[/color]
re_title[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'<\/*title>?*'[/color][COLOR=#008080])[/color]
re_meta[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'<meta?+">'[/color][COLOR=#008080])[/color]
re_body[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'?*<\/*body?*>'[/color][COLOR=#008080])[/color]

[COLOR=#0000ff]/* define regular expression for <font color="#804040"> */[/color]
re_font [COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'<font color="#[:XDIGIT:]+">'[/color][COLOR=#008080])[/color]
[COLOR=#0000ff]/* define regular expression for <span style="background-color: #ffff00"> */[/color]
re_span [COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'<span style="background-color: #[:XDIGIT:]+">'[/color][COLOR=#008080])[/color]
re_xdigit [COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff].RegularExpression[/color][COLOR=#804040][b]~[/b][/color][COLOR=#008080]new[/color][COLOR=#008080]([/color][COLOR=#ff00ff]'#[:XDIGIT:]+'[/color][COLOR=#008080])[/color]

[COLOR=#804040][b]do[/b][/color][COLOR=#804040][b] while [/b][/color][COLOR=#008080]lines()[/color] [COLOR=#804040][b]\=[/b][/color] 0
  [COLOR=#804040][b]parse linein[/b][/color] line
  res[COLOR=#804040][b]=[/b][/color]re_doc[COLOR=#804040][b]~[/b][/color][COLOR=#008080]match[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color] [COLOR=#804040][b]|[/b][/color] re_html[COLOR=#804040][b]~[/b][/color][COLOR=#008080]match[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color] [COLOR=#804040][b]|[/b][/color] re_head[COLOR=#804040][b]~[/b][/color][COLOR=#008080]match[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color] [COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
      re_title[COLOR=#804040][b]~[/b][/color][COLOR=#008080]match[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color] [COLOR=#804040][b]|[/b][/color] re_meta[COLOR=#804040][b]~[/b][/color][COLOR=#008080]match[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color] [COLOR=#804040][b]|[/b][/color] re_body[COLOR=#804040][b]~[/b][/color][COLOR=#008080]match[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color] 
[COLOR=#804040][b]  if res = 1 then do[/b][/color]
    [COLOR=#0000ff]/* skip document definition, header, footer, .. etc */[/color]
    [COLOR=#804040][b]iterate[/b][/color]
  [COLOR=#804040][b]end[/b][/color]
  [COLOR=#0000ff]/* process other lines */[/color]
  [COLOR=#804040][b]call[/b][/color][COLOR=#008080] process_line[/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]exit[/b][/color]

[COLOR=#0000ff]/*************************** Procedures/Functions ****************************/[/color]
[COLOR=#008080]process_line[/color]:
  font_not_found [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'FALSE'[/color]
  [COLOR=#0000ff]/* do until <font color="#..."> not found */[/color]
  [COLOR=#804040][b]do[/b][/color][COLOR=#804040][b] until [/b][/color]font_not_found [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'TRUE'[/color]
    font_first[COLOR=#804040][b]=[/b][/color]re_font[COLOR=#804040][b]~[/b][/color][COLOR=#008080]pos[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color]  [COLOR=#0000ff]/* first position of <font color="#..."> */[/color]
[COLOR=#804040][b]    if font_first > 0 then do[/b][/color]
      font_last[COLOR=#804040][b]=[/b][/color]re_font[COLOR=#804040][b]~[/b][/color][COLOR=#008080]position[/color]  [COLOR=#0000ff]/* last  position of <font color="#..."> */[/color]
      [COLOR=#0000ff]/* extract font_str substring from line */[/color]
      len [COLOR=#804040][b]=[/b][/color] font_last [COLOR=#804040][b]-[/b][/color] font_first [COLOR=#804040][b]+[/b][/color] 1 
      font_str[COLOR=#804040][b]=[/b][/color][COLOR=#008080]substr([/color]line[COLOR=#804040][b],[/b][/color] font_first[COLOR=#804040][b],[/b][/color] len[COLOR=#008080])[/color]
      [COLOR=#0000ff]/* extract xdigit substring from font_str */[/color]
      xdigit_first [COLOR=#804040][b]=[/b][/color] re_xdigit[COLOR=#804040][b]~[/b][/color][COLOR=#008080]pos[/color][COLOR=#008080]([/color]font_str[COLOR=#008080])[/color] [COLOR=#0000ff]/* first position of xdigit */[/color]
[COLOR=#804040][b]      if xdigit_first > 0 then do[/b][/color]
        xdigit_last  [COLOR=#804040][b]=[/b][/color] re_xdigit[COLOR=#804040][b]~[/b][/color][COLOR=#008080]position[/color]    [COLOR=#0000ff]/* last position of xdigit */[/color]
        len [COLOR=#804040][b]=[/b][/color] xdigit_last [COLOR=#804040][b]-[/b][/color] xdigit_first [COLOR=#804040][b]+[/b][/color] 1 
        xdigit_str[COLOR=#804040][b]=[/b][/color][COLOR=#008080]substr([/color]font_str[COLOR=#804040][b],[/b][/color] xdigit_first[COLOR=#804040][b],[/b][/color] len[COLOR=#008080])[/color]      
        [COLOR=#0000ff]/* construct new_font_str for replacing */[/color]
        new_font_str [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"[COLOR="[/color][COLOR=#804040][b]||[/b][/color]xdigit_str[COLOR=#804040][b]||[/b][/color][COLOR=#ff00ff]"]"[/color]
        [COLOR=#0000ff]/* replace  <font color="#..."> with [COLOR=#...] */[/color]
        line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color]font_str[COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] new_font_str[COLOR=#008080])[/color]
      [COLOR=#804040][b]end[/b][/color]
    [COLOR=#804040][b]end[/b][/color] 
[COLOR=#804040][b]    else [/b][/color]do
      [COLOR=#0000ff]/* no more <font color="#..."> in the line */[/color]
      font_not_found [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'TRUE'[/color]
    [COLOR=#804040][b]end[/b][/color]
  [COLOR=#804040][b]end[/b][/color] [COLOR=#0000ff]/* do until */[/color]

  span_not_found [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'FALSE'[/color]
  [COLOR=#0000ff]/* do until <span style="background-color: #..."> not found */[/color]
  [COLOR=#804040][b]do[/b][/color][COLOR=#804040][b] until [/b][/color]span_not_found [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'TRUE'[/color]
    span_first[COLOR=#804040][b]=[/b][/color]re_span[COLOR=#804040][b]~[/b][/color][COLOR=#008080]pos[/color][COLOR=#008080]([/color]line[COLOR=#008080])[/color]  [COLOR=#0000ff]/* first position of <span style="..."> */[/color]
[COLOR=#804040][b]    if span_first > 0 then do[/b][/color]
      span_last[COLOR=#804040][b]=[/b][/color]re_span[COLOR=#804040][b]~[/b][/color][COLOR=#008080]position[/color]  [COLOR=#0000ff]/* last  position of <span style="..."> */[/color]
      [COLOR=#0000ff]/* extract span_str substring from line */[/color]
      len [COLOR=#804040][b]=[/b][/color] span_last [COLOR=#804040][b]-[/b][/color] span_first [COLOR=#804040][b]+[/b][/color] 1 
      span_str[COLOR=#804040][b]=[/b][/color][COLOR=#008080]substr([/color]line[COLOR=#804040][b],[/b][/color] span_first[COLOR=#804040][b],[/b][/color] len[COLOR=#008080])[/color]
      [COLOR=#0000ff]/* extract xdigit substring from span_str */[/color]
      xdigit_first [COLOR=#804040][b]=[/b][/color] re_xdigit[COLOR=#804040][b]~[/b][/color][COLOR=#008080]pos[/color][COLOR=#008080]([/color]span_str[COLOR=#008080])[/color] [COLOR=#0000ff]/* first position of xdigit */[/color]
[COLOR=#804040][b]      if xdigit_first > 0 then do[/b][/color]
        xdigit_last  [COLOR=#804040][b]=[/b][/color] re_xdigit[COLOR=#804040][b]~[/b][/color][COLOR=#008080]position[/color]    [COLOR=#0000ff]/* last position of xdigit */[/color]
        len [COLOR=#804040][b]=[/b][/color] xdigit_last [COLOR=#804040][b]-[/b][/color] xdigit_first [COLOR=#804040][b]+[/b][/color] 1 
        xdigit_str[COLOR=#804040][b]=[/b][/color][COLOR=#008080]substr([/color]span_str[COLOR=#804040][b],[/b][/color] xdigit_first[COLOR=#804040][b],[/b][/color] len[COLOR=#008080])[/color]      
        [COLOR=#0000ff]/* construct new_span_str for replacing */[/color]
        new_span_str [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"[highlight "[/color][COLOR=#804040][b]||[/b][/color]xdigit_str[COLOR=#804040][b]||[/b][/color][COLOR=#ff00ff]"]"[/color]
        [COLOR=#0000ff]/* replace  <span style="background-color: #..."> with [COLOR=#...] */[/color]
        line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color]span_str[COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] new_span_str[COLOR=#008080])[/color]
      [COLOR=#804040][b]end[/b][/color]
    [COLOR=#804040][b]end[/b][/color] 
[COLOR=#804040][b]    else [/b][/color]do
      [COLOR=#0000ff]/* no more <span style="..."> in the line */[/color]
      span_not_found [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'TRUE'[/color]
    [COLOR=#804040][b]end[/b][/color]
  [COLOR=#804040][b]end[/b][/color] [COLOR=#0000ff]/* do until */[/color]

  [COLOR=#0000ff]/* replace strings */[/color] 
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'</font>'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'[/color]'[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'</span>'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'[/highlight]'[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'<b>'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'[b]'[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'</b>'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'[/b]'[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'&nbsp;'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]' '[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'<br>'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]''[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'&quot;'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'"'[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'&lt;'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'<'[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'&gt;'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'>'[/color][COLOR=#008080])[/color]
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'&amp;'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'&'[/color][COLOR=#008080])[/color] 
  [COLOR=#804040][b]say[/b][/color] line
[COLOR=#804040][b]return[/b][/color]

[COLOR=#0000ff]/****************************** Required Packages ****************************/[/color]
[COLOR=#804040][b]::requires [/b][/color][COLOR=#a020f0]"rxregexp.cls"[/color]

Now how it works?
For example I wrote this simple script io.rexx:
Code:
[COLOR=#804040][b]do[/b][/color][COLOR=#804040][b] while [/b][/color][COLOR=#008080]lines()[/color] [COLOR=#804040][b]\=[/b][/color] 0
  [COLOR=#804040][b]parse linein[/b][/color] line
  [COLOR=#804040][b]say[/b][/color] line
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]exit[/b][/color]

Then I convert it into HTML in my editor Vim and save this into the file named io.rexx.htm:
Code:
[COLOR=#0000ff]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a href="[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</a>">[/URL][/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]html[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]head[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]title[/b][/color][COLOR=#008080]>[/color][COLOR=#ff00ff][b]~\Work\io.rex.html[/b][/color][COLOR=#008080]</[/color][COLOR=#804040][b]title[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]meta[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]name[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"Generator"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]content[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"Vim/7.1"[/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]meta[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]http-equiv[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"content-type"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]content[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"text/html; charset=windows-1250"[/color][COLOR=#008080]>[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]head[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]body[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]bgcolor[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#ffffff"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]text[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#000000"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]face[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"monospace"[/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#804040"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]>[/color][b]do[/b][COLOR=#008080]</[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#804040"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]>[/color][COLOR=#6a5acd]&nbsp;[/color][b]while [/b][COLOR=#008080]</[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#008080"[/color][COLOR=#008080]>[/color]lines()[COLOR=#008080]</[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#6a5acd]&nbsp;[/color][COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#804040"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]>[/color][b]\=[/b][COLOR=#008080]</[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#6a5acd]&nbsp;[/color]0[COLOR=#008080]<[/color][COLOR=#804040][b]br[/b][/color][COLOR=#008080]>[/color]
[COLOR=#6a5acd]&nbsp;&nbsp;[/color][COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#804040"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]>[/color][b]parse linein[/b][COLOR=#008080]</[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#6a5acd]&nbsp;[/color]line[COLOR=#008080]<[/color][COLOR=#804040][b]br[/b][/color][COLOR=#008080]>[/color]
[COLOR=#6a5acd]&nbsp;&nbsp;[/color][COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#804040"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]>[/color][b]say[/b][COLOR=#008080]</[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#6a5acd]&nbsp;[/color]line[COLOR=#008080]<[/color][COLOR=#804040][b]br[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#804040"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]>[/color][b]end[/b][COLOR=#008080]</[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#008080]<[/color][COLOR=#804040][b]br[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]color[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"#804040"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]>[/color][b]exit[/b][COLOR=#008080]</[/color][COLOR=#804040][b]b[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]>[/color][COLOR=#008080]<[/color][COLOR=#804040][b]br[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]font[/b][/color][COLOR=#008080]></[/color][COLOR=#804040][b]body[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]html[/b][/color][COLOR=#008080]>[/color]

Then I run the script I wrote on the last html-file redirecting the output to a text-file
Code:
tek_tips_poster.rex < io.rex.html > post.txt

Then I open the resulting txt-file post.txt copy all from it and paste it here the code-tags.

That's all. It seems a little bit complicated, but it's simple.
 
For compariton: A script with the same functionality written in Perl:
Code:
[COLOR=#0000ff]#############################################################################[/color]
[COLOR=#0000ff]# Usage example:[/color]
[COLOR=#0000ff]#   [perl] tek_tips_poster.pl < matrices.rex.html > post.txt[/color]
[COLOR=#0000ff]# ###########################################################################[/color]
[COLOR=#804040][b]use strict[/b][/color];
[COLOR=#804040][b]use warnings[/b][/color];

[COLOR=#804040][b]while[/b][/color] ([COLOR=#008080]<STDIN>[/color]){
  [COLOR=#804040][b]chomp[/b][/color];
  [COLOR=#804040][b]if[/b][/color] (([COLOR=#804040][b]m/[/b][/color][COLOR=#ff00ff]^<!DOCTYPE HTML[/color][COLOR=#6a5acd].+[/color][COLOR=#ff00ff]">[/color][COLOR=#804040][b]/[/b][/color]) ||
      ([COLOR=#804040][b]m/[/b][/color][COLOR=#ff00ff]^<[/color][COLOR=#6a5acd]\/[/color][COLOR=#6a5acd]?[/color][COLOR=#ff00ff]html>[/color][COLOR=#804040][b]/[/b][/color]) ||
      ([COLOR=#804040][b]m/[/b][/color][COLOR=#ff00ff]^<[/color][COLOR=#6a5acd]\/[/color][COLOR=#6a5acd]?[/color][COLOR=#ff00ff]head>[/color][COLOR=#804040][b]/[/b][/color]) ||
      ([COLOR=#804040][b]m/[/b][/color][COLOR=#ff00ff]<[/color][COLOR=#6a5acd]\/[/color][COLOR=#6a5acd]?[/color][COLOR=#ff00ff]title>[/color][COLOR=#804040][b]/[/b][/color]) ||
      ([COLOR=#804040][b]m/[/b][/color][COLOR=#ff00ff]^<meta[/color][COLOR=#6a5acd].+[/color][COLOR=#ff00ff]">$[/color][COLOR=#804040][b]/[/b][/color]) ||
      ([COLOR=#804040][b]m/[/b][/color][COLOR=#ff00ff]<[/color][COLOR=#6a5acd]\/[/color][COLOR=#6a5acd]?[/color][COLOR=#ff00ff]body[/color][COLOR=#6a5acd].*[/color][COLOR=#ff00ff]>[/color][COLOR=#804040][b]/[/b][/color])){
      [COLOR=#0000ff]# skip document definition, header and footer   [/color]
      [COLOR=#804040][b]next[/b][/color];
  }
  [COLOR=#0000ff]# process other lines[/color]
  [COLOR=#008080]&process_line[/color]();  
}; 

[COLOR=#804040][b]sub[/b][/color][COLOR=#008080] [/color][COLOR=#008080]process_line[/color]{
  [COLOR=#804040][b]my[/b][/color] [COLOR=#008080]$line[/color] = [COLOR=#008080]$_[/color];
  [COLOR=#0000ff]# substitutions[/color]
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]<font[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]+[/color][COLOR=#ff00ff]color[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*[/color][COLOR=#ff00ff]=[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*[/color][COLOR=#ff00ff]"[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*([/color][COLOR=#ff00ff]#[[/color][COLOR=#6a5acd]\d[/color][COLOR=#ff00ff]a-f][/color][COLOR=#6a5acd]+)[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*[/color][COLOR=#ff00ff]">[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff][COLOR=[/color][COLOR=#008080]$1[/color][COLOR=#ff00ff]][/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]<[/color][COLOR=#6a5acd]\/[/color][COLOR=#ff00ff]font>[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff][[/color][COLOR=#6a5acd]\/[/color][COLOR=#ff00ff]color][/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]<span[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]+[/color][COLOR=#ff00ff]style[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*[/color][COLOR=#ff00ff]=[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*[/color][COLOR=#ff00ff]"[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*[/color][COLOR=#ff00ff]background-color:[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]+([/color][COLOR=#ff00ff]#[[/color][COLOR=#6a5acd]\d[/color][COLOR=#ff00ff]a-f][/color][COLOR=#6a5acd]+)[/color][COLOR=#6a5acd]\s[/color][COLOR=#6a5acd]*[/color][COLOR=#ff00ff]">[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff][highlight [/color][COLOR=#008080]$1[/color][COLOR=#ff00ff]][/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]<[/color][COLOR=#6a5acd]\/[/color][COLOR=#ff00ff]span>[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff][[/color][COLOR=#6a5acd]\/[/color][COLOR=#ff00ff]highlight][/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]<[/color][COLOR=#6a5acd]([/color][COLOR=#6a5acd]\/[/color][COLOR=#6a5acd]?[/color][COLOR=#ff00ff]b[/color][COLOR=#6a5acd])[/color][COLOR=#ff00ff]>[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff][[/color][COLOR=#008080]$1[/color][COLOR=#ff00ff]][/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]&nbsp;[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff] [/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]<br>[/color][COLOR=#804040][b]/[/b][/color][COLOR=#6a5acd]\n[/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]&quot;[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]"[/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]&lt;[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]<[/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]&gt;[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]>[/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#008080]$line[/color] =~ [COLOR=#804040][b]s/[/b][/color][COLOR=#ff00ff]&amp;[/color][COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]&[/color][COLOR=#804040][b]/g[/b][/color];
  [COLOR=#804040][b]print[/b][/color] [COLOR=#ff00ff]"[/color][COLOR=#008080]$line[/color][COLOR=#ff00ff]"[/color];
}

Time I spent on writing the script in Perl was a fraction of a time I spent on writing the same functionality in REXX.
It's therefore because Perl has more powerful regular expressions. For example, Perl supports regexp substitution, so with one command
Code:
$line =~ s/[i]regexp[/i]/[i]string[/i]/g;
I can replace all patterns found in a line with a given string.
The ooREXX's regular expressions don't support such a thing, so I needed to code a do until .. loops instead.
 
There is a little issue with the generated TGML.
What the program generates will be displayed as
Code:
  [COLOR=#0000ff]/* replace strings */[/color] 
  line[COLOR=#804040][b]=[/b][/color][COLOR=#008080]changestr([/color][COLOR=#ff00ff]'</font>'[/color][COLOR=#804040][b],[/b][/color] line[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]'[/color]'[/color][COLOR=#008080])[/color]
and this hould be really
Code:
  /* replace strings */ 
  line=changestr('</font>', line, '[/color]')

It's necause the REXX-script generates for colorimg of
[tt]'[/color]'[/tt]
this
[tt]'[[&frasl;]color]'[[&frasl;]color][/tt]
and this would be in end effect interpreted by the TGML-processor as the above
[tt]''
[/tt]

At the moment I have no idea how to correct this issue, but this can happen only in a source where TGML-tags are used as string literals, i.e. in my case it occurs probably in this one source.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top