home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 February / PCO_0299.ISO / filesbbs / os2 / xfolder.arj / XFLD082.ZIP / bin / xhelp.cmd < prev    next >
Encoding:
Text File  |  1998-08-12  |  21.4 KB  |  641 lines

  1. /* XHELP.CMD
  2.  *
  3.  * This is CommandPak's xhelp command.
  4.  *
  5.  * (w) (c) 1997-98 Ulrich Möller. All rights reserved.
  6.  */
  7.  
  8. '@echo off'
  9.  
  10. signal on halt
  11.  
  12. nl = '0d0a'x           /* this is CR+LF (hex), helpful for defining help strings */
  13. extLevel = 0
  14.  
  15. helpList. = ''
  16. helpList.ALIAS = 'call msg getExtMsg("aliasHelp")'
  17. helpList.CD = 'call msg getExtMsg("cdHelp"), "cd"'
  18. helpList.CMDSHL = 'call msg getExtMsg("cmdshlHelp")'
  19. helpList.COPY = 'call msg getExtMsg("copyHelp"), "copy"'
  20. helpList.CP = 'call msg getExtMsg("copyHelp"), "cp"'
  21. helpList.DEF = 'call msg getExtMsg("defineHelp"), "def"'
  22. helpList.DEFINE = 'call msg getExtMsg("defineHelp"), "define"'
  23. helpList.DEL = 'call msg getExtMsg("delHelp"), "del"'
  24. helpList.DIR = 'call msg getExtMsg("dirHelp"), "dir"'
  25. helpList.EXIT = 'call msg getExtMsg("exitHelp")'
  26. helpList.HELP = 'call msg getExtMsg("helpHelp"), "help"'
  27. helpList.FL = 'call startView help.ref filelist'
  28. helpList.FOR = 'call msg getExtMsg("forHelp")'
  29. helpList.KEYS = 'call msg getExtMsg("keysHelp")'
  30. helpList.LN = 'call msg getExtMsg("lnHelp")'
  31. helpList.LS = 'call msg getExtMsg("dirHelp"), "ls"'
  32. helpList.LESS = 'call startView help.ref less'
  33. helpList.MV = 'call msg getExtMsg("renHelp"), "mv"'
  34. helpList.OPEN = 'call msg getExtMsg("openHelp")'
  35. helpList.PUSHD = 'call msg getExtMsg("pushdHelp")'
  36. helpList.POPD = 'call msg getExtMsg("pushdHelp")'
  37. helpList.QUERY = 'call msg getExtMsg("queryHelp")'
  38. helpList.QUIT = 'call msg getExtMsg("quitHelp")'
  39. helpList.REC = 'call msg getExtMsg("recurseHelp")'
  40. helpList.RECURSE = 'call msg getExtMsg("recurseHelp")'
  41. helpList.REN = 'call msg getExtMsg("renHelp"), "ren"'
  42. helpList.RULE = 'call msg getExtMsg("ruleHelp")'
  43. helpList.RX = 'call msg getExtMsg("rxHelp")'
  44. helpList.SDIR = 'call startView help.ref sdir'
  45. helpList.VER = 'call msg getExtMsg("versionMsg")'
  46. helpList.WATCHDRV = 'call msg getExtMsg("watchdrvHelp")'
  47. helpList.XCP = 'call msg getExtMsg("copyHelp"), "xcp"'
  48. helpList.XDEL = 'call msg getExtMsg("delHelp"), "xdel"'
  49. helpList.XDIR = 'call msg getExtMsg("dirHelp"), "xdir"'
  50. helpList.XHELP = 'call msg getExtMsg("helpHelp"), "xhelp"'
  51. helpList.XREN = 'call msg getExtMsg("renHelp"), "xren"'
  52. helpList._XRENEXPL = 'call msg getExtMsg("renExpl")'
  53.  
  54. escapeList.437 = 'auml=ä euml=ë iuml=ï ouml=ö uuml=ü Auml=Ä Ouml=Ö Uuml=Ü',
  55.     'aacute=á eacute=é iacute=í oacute=ó uacute=ú Eacute=É',
  56.     'agrave=à egrave=è egrave=ì ograve=ò ugrave=ù',
  57.     'acirc=â ecirc=ê icirc=î ocirc=ô ucirc=û',
  58.     'aring=å Aring=Å ntilde=ñ Ntilde=Ñ iexcl=¡ ccedil=ç Ccedil=Ç szlig=ß ',
  59.     'sect= frac14=¼ frac12=½ sup2=² sub3=ⁿ aelig=æ AElig=Æ pound=£ cent=¢ para= micro=µ lt=< gt=> amp=& quot=" nbsp= ',
  60.     'curren= plusmn=± laquo=« raquo=» uarrw= darrw= larrw= rarrw=',
  61.     /* now the codepage-specific ones */,
  62.     'Euml=E Iuml=I Aacute=A Iacute=I Oacute=O Uacute=U Agrave=A Egrave=E Igrave=I Ograve=O Ugrave=U',
  63.     'Ecirc=E Icirc=I Acirc=A Ocirc=O Ucirc=U yen=¥'
  64.  
  65. escapeList.850 = 'auml=ä euml=ë iuml=ï ouml=ö uuml=ü Auml=Ä Ouml=Ö Uuml=Ü',
  66.     'aacute=á eacute=é iacute=í oacute=ó uacute=ú Eacute=É',
  67.     'agrave=à egrave=è egrave=ì ograve=ò ugrave=ù',
  68.     'acirc=â ecirc=ê icirc=î ocirc=ô ucirc=û',
  69.     'aring=å Aring=Å ntilde=ñ Ntilde=Ñ iexcl=¡ ccedil=ç Ccedil=Ç szlig=ß ',
  70.     'sect= frac14=¼ frac12=½ sup2=² sub3=ⁿ aelig=æ AElig=Æ pound=£ cent=¢ para= micro=µ lt=< gt=> amp=& quot=" nbsp= ',
  71.     'curren= plusmn=± laquo=« raquo=» uarrw= darrw= larrw= rarrw=',
  72.     /* now the codepage-specific ones */,
  73.     'Euml=╙ Iuml=╫ Aacute=╡ Iacute=╓ Oacute=α Uacute=Θ Agrave=╖ Egrave=╘ Igrave=▐ Ograve=π Ugrave=δ',
  74.     'Ecirc=╥ Icirc=╫ Acirc=╢ Ocirc=Γ Ucirc=Ω yen=Y'
  75.  
  76. sysMsgList = 'SYS REX' /* list of prefixes to system messages */
  77.  
  78. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  79. call SysLoadFuncs
  80.  
  81. /* first detect colors out of environment vars */
  82. ansiReset = ""
  83.  
  84. /* coloring for <A HREF=""> */
  85. val = value('HELP.ANCHOR',,'OS2ENVIRONMENT')
  86. if (val \= "") then do
  87.     ansiAnchorOn = ansiValue(val)
  88.     ansiReset = '1b'x||'[0m'
  89. end
  90. else
  91.     ansiAnchorOn = ""
  92.  
  93. /* coloring for <B> */
  94. val = value('HELP.BOLD',,'OS2ENVIRONMENT')
  95. if (val \= "") then do
  96.     ansiBoldOn = ansiValue(val)
  97.     ansiReset = '1b'x||'[0m'
  98. end
  99. else
  100.     ansiBoldOn = ""
  101.  
  102. /* coloring for <I> */
  103. val = value('HELP.ITALICS',,'OS2ENVIRONMENT')
  104. if (val \= "") then do
  105.     ansiItalicsOn = ansiValue(val)
  106.     ansiReset = '1b'x||'[0m'
  107. end
  108. else
  109.     ansiItalicsOn = ""
  110.  
  111. /* default color for <I> */
  112. val = value('HELP.COLOR',,'OS2ENVIRONMENT')
  113. if (val \= "") then
  114.     ansiReset = '1b'x||'[0m'ansiValue(val)
  115.  
  116. imageString = ansiItalicsOn''
  117.  
  118. /* now process args */
  119.  
  120. parse arg args
  121.  
  122. _upper = 'helpList.'||translate(word(args, 1))
  123.  
  124. parse var args opt parameters
  125.  
  126. select
  127.   when (opt = '-c') then
  128.     call msg getExtMsg("cmdshlHelp")
  129.   when (opt = "") then
  130.     call msg getExtMsg("helpHelpFirst")
  131.   when (opt = '?') | (opt = '/?') | (opt = '-h') then
  132.     call msg getExtMsg("helpHelp"), "help"
  133.   when (opt = '-x') | (opt = '-X') then
  134.     call msg getExtMsg("helpHelpExampl"), "help"
  135.   when (opt = '-w') then
  136.     call msg getExtMsg("welcomeMsg")
  137.   when (opt = '-f') then
  138.     call msg getExtMsg(word(parameters, 1)), word(parameters, 2)
  139.   when (opt = '-F') then
  140.     call msg extractMsg(word(parameters, 1), word(parameters, 2)), word(parameters, 3)
  141.   /* output text directly */
  142.   when left(args, 1) = '"' then do
  143.     p2 = lastpos('"', args)
  144.     if p2 > 2 then
  145.         args = substr(args, 2, p2-2)
  146.         else do; call charout , SysGetMessage(1003); exit; end
  147.     call msg args
  148.   end
  149.   /* HELP LIST*/
  150.   when (translate(args) = "LIST") then do
  151.     str = getExtMsg("helpList")
  152.     /* now collect INF files on the bookshelf */
  153.     shelf = value('BOOKSHELF',, 'OS2ENVIRONMENT')
  154.     j = 0
  155.     do while (shelf \= "")
  156.         parse var shelf shelf2 ";" shelf
  157.         rc = SysFileTree(shelf2"\*.inf", found)
  158.         do i = 0 to found.0
  159.             parse var found.i fdate ftime fsize fattr fpath
  160.             if (fpath \= "") then do
  161.                 fname = lowercase(filespec('NAME', fpath))
  162.                 fname = left(fname, pos(".inf", fname)-1)
  163.                 j = j+1
  164.                 fname.j = fname
  165.             end
  166.         end
  167.     end
  168.  
  169.     /* now check all environment variables */
  170.     localqueue = rxqueue('create')
  171.     oldqueue = rxqueue('set', localqueue)
  172.     'set 2>&1 | rxqueue' localqueue
  173.     do while (queued() > 0)
  174.        parse pull line
  175.        say line
  176.     end /* do */
  177.     call rxqueue 'delete', localqueue
  178.     call rxqueue 'set', oldqueue
  179.  
  180.     /* now prepare output */
  181.     fname.0 = j
  182.     call sort
  183.     do i = 1 to j
  184.         str = str||fname.i" "
  185.     end
  186.     str = str||nl
  187.     call msg str
  188.   end /* when (LIST) */
  189.   when (left(args, 1) = "-") then
  190.     call msg strReplace(getExtMsg("invalidOptionMsg"), '%a', args), "xhelp"
  191.   /* known command, e.g. help dir */
  192.   when (symbol(_upper) = "VAR") then do
  193.     if (value(_upper) \= '') then
  194.         interpret value(_upper)
  195.     else cont = 1
  196.   end /* when */
  197.   otherwise
  198.     cont = 1
  199. end /* select */
  200.  
  201. if (cont=1) then do /* only one argument given */
  202.     /* help cmdref dir */
  203.     if (words(args) = 2) then do
  204.         book = value('HELP.'word(args, 1),,'OS2ENVIRONMENT')
  205.         if (book = "") then book = value(word(args, 1),,'OS2ENVIRONMENT')
  206.         if (pos("+", book) = 0) then book=""
  207.         if (book = "") then book = word(args, 1)
  208.         topic_ = word(args, 2)
  209.         call msg strReplace(strReplace(getExtMsg("bookshelfMsg"), '%a', book), '%b', topic_)
  210.         call startView book topic_
  211.                 /* search given book (arg 1) for given topic (arg 2) */
  212.     end
  213.     else do
  214.       sysmsg = 0
  215.       if (datatype(args) = "NUM") then
  216.           sysmsg = 1
  217.       else
  218.           do while (sysmsgList \= "")
  219.               parse var sysmsgList s_ sysmsgList
  220.               if ( (left(translate(args), length(s_)) = s_) & (datatype(substr(args, length(s_)+1))="NUM"))then /* numeric --> help for system message */
  221.                   sysmsg = 1
  222.           end
  223.       if (sysmsg) then
  224.         "call helpmsg" args    /* "helpmsg" should be in the OS/2 directory; try "helpmsg 2166" */
  225.       else do  /* non-numeric --> more checks nevessary */
  226.           if (pos('+', args) > 0) then do
  227.                                         /* there's a "+" sign --> display several INFs */
  228.             call msg strReplace(getExtMsg("callViewMsg"), '%a', args)
  229.             call startView args
  230.           end
  231.           else do
  232.             book = value('HELP.'args,,'OS2ENVIRONMENT')
  233.             if (book = "") then book = value(args,,'OS2ENVIRONMENT')
  234.             if (pos("+", book) = 0) then book=""
  235.             if (book \= "") then do
  236.                                         /* envir'variable  --> display several INFs */
  237.                 call msg strReplace(getExtMsg("callViewMsg"), '%a', book)
  238.                 call startView book
  239.             end
  240.             else if (stream(args, "c", "query exists") \= "") & (right(args, 4) \= ".inf") then
  241.                 call processExternalFile(args)
  242.             else do
  243.                 loc = SysSearchPath("BOOKSHELF", args)
  244.                 if (loc = "") then loc = SysSearchPath("BOOKSHELF", args||".inf")
  245.                 if (loc \= "") then do     /* argument is an existing INF file --> open it */
  246.                   call msg strReplace(getExtMsg("callViewMsg"), '%a', loc)
  247.                   call startView loc
  248.                 end
  249.                 else do /* otherwise search whole bookshelf for args */
  250.                   topic_ = args
  251.                   call msg strReplace(strReplace(getExtMsg("bookshelfMsg"), '%a', "BOOKSHELF"), '%b', topic_)
  252.                   call startView '/'||topic_  /* cool feature: "view /<topic>" will search bookshelf for <topic>! */
  253.                 end
  254.             end
  255.           end
  256.      end
  257.     end
  258. end /* if */
  259.  
  260. exit
  261.  
  262. halt:
  263.     say ansiReset
  264.     call msg getExtMsg("abortMsg"), "xhelp"
  265. exit
  266.  
  267. strReplace: procedure
  268.     /* syntax: result = strReplace(str, old, new) */
  269.     /* will replace a by b in oldstr */
  270.     parse arg str, old, new
  271.     p = pos(old, str)
  272.     if (p > 0) then
  273.         str = left(str, p-1)||new||substr(str,p+length(old))
  274.     drop p
  275. return str
  276.  
  277. lowercase: procedure
  278.     return translate(arg(1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  279.  
  280. startView: procedure
  281.     parse arg args
  282.     if (sysSearchPath('PATH', 'VIEW.EXE') \= "") then
  283.         'start view' args
  284.     else call msg getExtMsg("noViewMsg")
  285. return
  286.  
  287. sort:  procedure expose fname.
  288.    M = 1
  289.    do while (9 * M + 4) < fname.0
  290.       M = M * 3 + 1
  291.    end /* do while */
  292.                         /* sort fname                                  */
  293.    do while M > 0
  294.       K = fname.0 - M
  295.       do J = 1 to K
  296.          Q = J
  297.          do while Q > 0
  298.             L = Q + M
  299.             if translate(fname.Q) <<= translate(fname.L) then
  300.               leave
  301.                         /* switch elements                            */
  302.             tmp      = fname.Q
  303.             fname.Q = fname.L
  304.             fname.L = tmp
  305.             Q = Q - M
  306.          end /* do while Q > 0 */
  307.       end /* do J = 1 to K */
  308.       M = M % 3
  309.    end /* while M > 0 */
  310. return
  311.  
  312. sayBreak:
  313.     call charout , ansiReset
  314.     if (arg(1) = "") then do
  315.         call charout , '0d0a'x||copies(" ",indent.level_)
  316.         xpos = indent.level_
  317.     end
  318.     else do
  319.         call charout , '0d0a'x||copies(" ",arg(1))
  320.         xpos = arg(1)
  321.     end
  322.     call setColors
  323.     lastChar = " "
  324. return
  325.  
  326. sayChar: procedure expose lastChar xpos
  327.     call charout , arg(1)
  328.     lastChar = arg(1)
  329.     xpos = xpos+length(arg(1))
  330. return
  331.  
  332. setColors:
  333.     call charout , ansiReset
  334.     if (anchor) then
  335.         call charout , ansiAnchorOn
  336.     if (bold) then
  337.         call charout , ansiBoldOn
  338.     if (italics) then
  339.         call charout , ansiItalicsOn
  340. return
  341.  
  342. HTMLerror:
  343.     l_ = sigl
  344.     say "HTML error in line" l_":"
  345.     say sourceline(l_)
  346.     exit
  347.  
  348. oldRexxUtils:
  349.     codepage=437
  350. signal weiter
  351.  
  352. sayHTML: /* Syntax: sayHTML <htmlstr>)*/
  353.     signal on novalue name HTMLerror
  354.  
  355.     signal on syntax name oldRexxUtils
  356.     codepage = SysQueryProcessCodePage()
  357.     weiter:
  358.     signal off failure
  359.  
  360.     call charout , getExtMsg("formattingMsg")"..."
  361.     txt = arg(1)||" "||'00'x
  362.         /* a little cheat for making word break in the last line work*/
  363.     do while (pos('0d0a'x, txt) > 0)
  364.         txt = strReplace(txt, '0d0a'x, '00'x)
  365.     end
  366.     call charout , "."
  367.     do while (pos('0d'x, txt) > 0)
  368.         txt = strReplace(txt, '0d'x, '00'x)
  369.     end
  370.     call charout , "."
  371.     do while (pos('0a'x, txt) > 0)
  372.         txt = strReplace(txt, '0a'x, '00'x)
  373.     end
  374.     call charout , "."
  375. /*    do while (pos("      ", txt) > 0)
  376.         txt = strReplace(txt, "      ", ' ')
  377.     end
  378.     call charout , "."
  379.     do while (pos("  ", txt) > 0)
  380.         txt = strReplace(txt, "  ", ' ')
  381.     end*/
  382.  
  383.     parse value SysTextScreenSize() with row col
  384.     scrwidth = col-2
  385.     lastchar = ""
  386.  
  387.     anchor = 0
  388.     bold = 0
  389.     italics = 0
  390.  
  391.     xpos = 0
  392.     level_ = 1
  393.     indent.level_ = 0
  394.     indentFirst.level_ = 0
  395.  
  396.     call charout, '0d0a1b'x||'[1A'||'1b'x||'[K'
  397.     call setColors
  398.     /* now go through the whole text on a per-character basis */
  399.     do p1 = 1 to length(txt)
  400.       ch = substr(txt, p1, 1)
  401.  
  402.       select
  403.         when (ch = "<") then do
  404.             /* HTML tag found */
  405.             p2 = pos('>', txt, p1)
  406.             tag = substr(txt, p1+1, p2-p1-1)
  407.             parse upper var tag cmd args
  408.             select
  409.                 when cmd = "!--" then do /* comment: skip following */
  410.                     p1 = pos("-->", txt, p1)+2 /* p1 will be set to p2 later on */
  411.                     iterate
  412.                 end
  413.                 when cmd = "HEAD" then do /* comment: skip following */
  414.                     p1 = pos("/HEAD>", translate(txt), p1)+5 /* p1 will be set to p2 later on */
  415.                     iterate
  416.                 end
  417.                 when (cmd = "BR") | (cmd = "TR") then
  418.                     call sayBreak
  419.                 when (cmd = "HR") then do
  420.                     call sayBreak
  421.                     call sayChar " "copies("─", scrWidth-(indent.level_))
  422.                 end
  423.                 when (cmd = "IMG") then do
  424.                     call sayChar imageString
  425.                     call setColors
  426.                 end
  427.                 when cmd = "P" then do
  428.                     call sayBreak
  429.                     call sayBreak
  430.                 end
  431.                 when (cmd = "A") & (pos("HREF=", translate(args)) > 0) then do
  432.                     anchor = 1
  433.                     call setColors
  434.                 end
  435.                 when cmd = "/A" then do
  436.                     anchor = 0
  437.                     call setColors
  438.                 end
  439.                 when (cmd = "B") then do
  440.                     bold = 1
  441.                     call setColors
  442.                 end
  443.                 when cmd = "/B" then do
  444.                     bold = 0
  445.                     call setColors
  446.                 end
  447.                 when (cmd = "I") then do
  448.                     italics = 1
  449.                     call setColors
  450.                 end
  451.                 when cmd = "/I" then do
  452.                     italics = 0
  453.                     call setColors
  454.                 end
  455.                 when cmd = "UL" then do
  456.                     oldlevel_ = level_
  457.                     level_ = level_+1
  458.                     indent.level_ = (indent.oldlevel_)+3
  459.                     indentFirst.level_ = (indentFirst.oldlevel_)+3
  460.                     do while (args \= "")
  461.                         parse upper var args arg1 args
  462.                         if substr(arg1, 1, 5) = "FIRST" then
  463.                             indentFirst.level_ = substr(arg1, 7)
  464.                         if substr(arg1, 1, 4) = "NEXT" then
  465.                             indent.level_ = substr(arg1, 6)
  466.                     end
  467.                 end
  468.                 when cmd = "/UL" then do
  469.                     oldlevel_ = level_
  470.                     level_ = level_-1
  471.                     if (level_ < 1) then level_ = 1
  472.                     else if (level_=1) then call sayBreak
  473.                 end
  474.                 when cmd = "LI" then do
  475.                     call sayBreak indentFirst.level_
  476.                 end
  477.                 when cmd = "TAB" then do
  478.                     if (xpos < indent.level_) then
  479.                         call sayChar copies(" ", (indent.level_)-xpos)
  480.                     else call sayBreak
  481.                     lastChar = " "
  482.                 end
  483.                 when cmd = "DBG" then
  484.                     say xpos
  485.                 otherwise /* ignore */
  486.             end /* select */
  487.             p1 = p2 /* skip processed characters */
  488.         end
  489.         when (ch = "&") & (substr(txt, p1+1, 1) \= " ") then do
  490.             /* special chars found */
  491.             p2 = pos(';', txt, p1)
  492.             code = substr(txt, p1+1, p2-p1-1)
  493.             p3 = pos(code||"=", escapeList.codepage)
  494.             if p3 > 0 then
  495.                 call sayChar substr(escapeList.codepage, pos("=", escapeList.codepage, p3)+1, 1)
  496.             p1 = p2 /* skip the processed chars */
  497.         end
  498.         when (ch = " ") | (ch = '00'x) then do
  499.                 /* space found: now check if following word still fits in line */
  500.                 charwise = 0
  501.                 p3 = min(pos(' ', txt, p1+1), pos('00'x, txt, p1+1))
  502.                 if (p3-p1-1 > 0) then do
  503.                     wrd = substr(txt, p1+1, p3-p1-1)
  504.                     lw = length(wrd)
  505.  
  506.                     p1_ = 0
  507.                     do forever
  508.                         p1_ = pos("<", wrd, p1_+1)
  509.                         if (p1_ > 0) then do
  510.                             p2_ = pos(">", wrd, p1_+1)
  511.                             lw = lw - (p2_-p1_)-1
  512.                             charwise = 1
  513.                         end
  514.                         else leave
  515.                     end
  516.  
  517.                     p3_ = 0
  518.                     do forever
  519.                         p3_ = pos("&", wrd, p3_+1)
  520.                         if (p3_ > 0) then do
  521.                             p4_ = pos(";", wrd, p3_+1)
  522.                             lw = lw - (p4_-p3_)
  523.                             charwise = 1
  524.                         end
  525.                         else leave
  526.                     end
  527.  
  528.                     /* lw now contains the "real" length of the word w/out tags and such */
  529.  
  530.                     if (xpos+lw > scrwidth) then do
  531.                         if (pos('<UL', wrd) = 0) & (pos('</UL', wrd) = 0) & (pos('<LI>', wrd) = 0) & (pos('<BR>', wrd) = 0) & (pos('<P>', wrd) = 0) then do
  532.                             call sayBreak
  533.                         end
  534.                         charwise = 1
  535.                     end
  536.                     else if (lastChar \= " ") then
  537.                          call sayChar " "
  538.                     if \charwise then do
  539.                          call sayChar wrd
  540.                          p1 = p1+length(wrd)
  541.                     end
  542.                 end /* if */
  543.         end /* when */
  544.         otherwise
  545.                 call sayChar ch
  546.       end /* select */
  547.     end /* do while */
  548.     call charout , nl||'1b'x'[0m'
  549. return
  550.  
  551. processExternalFile:
  552.     filename = arg(1)
  553.     txt = ""
  554.  
  555.     file = stream(filename, "c", "query exists");
  556.     if (file = "") then call charout , SysGetMessage(0002)
  557.     else do
  558.         fileLength = chars( file )
  559.         call stream file, "c", "OPEN READ"
  560.         txt = CharIn( file, 1, fileLength )
  561.         call stream file, "c", "CLOSE"
  562.     end
  563.     if (txt \= "") then
  564.         call msg txt
  565. return
  566.  
  567. extractMsg: procedure /* str = extractMsg(longstr, topic) */
  568.     msgFile = arg(1)
  569.     topic2 = arg(2)
  570.     str3 = "xhelp message file" msgFile "not found."
  571.     msgfile = sysSearchPath("PATH", msgFile)
  572.     if (msgFile \= "") then do
  573.         msgFileLength = chars( msgFile )
  574.         call stream msgFile, "c", "OPEN READ"
  575.         str3 = CharIn( msgFile, 1, msgFileLength )
  576.         call stream msgFile, "c", "CLOSE"
  577.         p1 = pos('<TOPIC NAME="'topic2'"', str3)
  578.         if (p1 > 0) then do
  579.             p2 = pos('>', str3, p1)+1
  580.             p3 = pos('</TOPIC>', str3, p2)
  581.             str3 = substr(str3, p2, (p3-p2))
  582.         end
  583.         else str3 = '0d0a'x'Help topic "'topic2'" not found in 'msgFile'.'||'0d0a'x
  584.     end
  585. return str3
  586.  
  587. getExtMsg:
  588.     msgName = arg(1)
  589.     country = value('HELP.COUNTRY',,'OS2ENVIRONMENT')
  590.     if country = "" then country="001"
  591.     str = extractMsg('XHELP'country'.MSG', msgName)
  592. return str
  593.  
  594. msg:
  595.     call charout , getExtMsg("analyzeMsg")
  596.     parse arg str
  597.     if pos("<HTML>", translate(str)) = 0 then do
  598.         call charout, '0d0a1b'x||'[1A'||'1b'x||'[K'
  599.         call charout , str
  600.     end
  601.     else do
  602.         do while (pos('&version;', str) > 0)
  603.            str = strReplace(str, '&version;', getExtMsg("versionString"))
  604.         end
  605.         cmd = arg(2)
  606.         if (cmd \= "") then
  607.             do while (pos('&cmd;', str) > 0)
  608.                 str = strReplace(str, '&cmd;', cmd)
  609.             end
  610.         call charout, '0d0a1b'x||'[1A'||'1b'x||'[K'
  611.         call sayHTML str
  612.     end
  613. return
  614.  
  615. ansiValue: procedure
  616.   normal = '1b'x'[0m'
  617.  
  618.   bright = 1
  619.   underline = 4
  620.   blink = 5
  621.  
  622.   black = 30
  623.   red = 31
  624.   green = 32
  625.   yellow = 33
  626.   blue = 34
  627.   magenta = 35
  628.   cyan = 36
  629.   white = 37
  630.  
  631.   litcolor = arg(1); ansicolor = ''; on = 0
  632.   do while litcolor \= ''
  633.      parse upper var litcolor item litcolor
  634.      if item = 'ON' then on = 10
  635.      else
  636.        ansicolor = ansicolor || ';' || value(item)+on
  637.   end /* do */
  638.  
  639. return '1b'x'['strip(ansicolor,'L',';')'m'
  640.  
  641.