home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / TE2_134T / te2inst.003 / ScrMenu.scr < prev    next >
Text File  |  1997-07-03  |  7KB  |  158 lines

  1. /* --------------------------------------------------------------------- */
  2. /* ScrMenu.scr - A TE/2 REXX Syntax Script                              */
  3. /*                Copyright 1994 by Oberon Software                      */
  4. /*                All rights reserved                                    */
  5. /*                                                                       */
  6. /* Notes: This sample script illustrates the use of:                     */
  7. /*          1. Using Script file arguments in REXX                       */
  8. /*          2. The TE/2 PopupMenu() function                             */
  9. /*          3. The TE/2 ErrorMsg() function                              */
  10. /*          4. Reading from a data file                                  */
  11. /*          5. Error handling in REXX Syntax TE/2 scripts                */
  12. /*                                                                       */
  13. /* Usage: ScrMenu MenuDefFile                                            */
  14. /*                                                                       */
  15. /* MenuDefFile Structure                                                 */
  16. /*   Line 1: This line will contain the Title Text for the menu          */
  17. /*   Up to ten lines follow defining the menu items, they have the       */
  18. /*     following format:                                                 */
  19. /*                       /Menu Text/ScriptToRun/Arguments                */
  20. /*     MenuText is simply the text you wish to appear on the menu        */
  21. /*     ScriptToRun is the name of the script file to execute when that   */
  22. /*       menu item is selected.                                          */
  23. /*     Arguments may take one of several forms:                          */
  24. /*       Empty: Simply end the line after the last "/" to pass no        */
  25. /*              arguments to the called script.                          */
  26. /*       HardCoded: Place the actual value of the arguments after the    */
  27. /*                  last "/".                                            */
  28. /*       Prompted: If the Argument string is exactly "[ ]" (without      */
  29. /*                 the quotes, you will be prompted for the parameters.  */
  30. /*                 If you place anything inside the square brackets, it  */
  31. /*                 must be of the form "[Prompt Text%Default Value]".    */
  32. /*                 The default value text can be empty.                  */
  33. /*                                                                       */
  34. /*   Example:                                                            */
  35. /*                                                                       */
  36. /*       Sample Menu                                                     */
  37. /*       /Play WAV Files/PlayWAVs/                                       */
  38. /*       /Change Dir    /ChDir/                                          */
  39. /*       /XonXoff Menu  /XonXoff/                                        */
  40. /*       /XonXoff ON    /XonXoff/TRUE                                    */
  41. /*       /XonXoff OFF   /XonXoff/FALSE                                   */
  42. /*       /Set Paths     /Paths/                                          */
  43. /*       /FaxWorks      /FaxWorks/[Enter ON, OFF, or nothing for menu:%] */
  44. /*                                                                       */
  45. /* --------------------------------------------------------------------- */
  46.  
  47. /* Variables used ------------------------------------------------------ */
  48. ReturnCode  = 0
  49. MnuTitle    = ''
  50. MnuTop      = 5
  51. MnuLeft     = 20
  52. MnuAttr     = 0x1f
  53. MnuHiAttr   = 0x71
  54. MnuItem.    = ''
  55. MnuItem.0   = 0
  56. MnuBuf      = ''
  57. MnuDelim    = '/'
  58.  
  59. /* Check for arguments ------------------------------------------------- */
  60. parse arg InFile
  61. if length(InFile) = 0 then
  62.   do
  63.     'ErrorMsg("ScrMenu.Scr Parameter Error", "Usage: ScrMenu MenuDefFile")'
  64.     exit 1
  65.   end
  66. if length(stream(InFile,'C','query exists')) = 0 then
  67.   do
  68.     'ErrorMsg("ScrMenu.Scr Parameter Error", "File:'InFile' does not exist.")'
  69.     exit 1
  70.   end
  71.  
  72. /* Load REXXUTIL Functions --------------------------------------------- */
  73. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  74. call SysLoadFuncs
  75.  
  76. /* Setup Error handling ------------------------------------------------ */
  77. signal on error name errproc
  78.  
  79. /* Main Program -------------------------------------------------------- */
  80. call ReadInfile
  81. if ReturnCode = 0 then
  82.   do
  83.     i = ShowMenu()
  84.     if i > 0 & i <= MnuItem.0 then
  85.       ReturnCode = RunItemScript(i)
  86.   end
  87. exit ReturnCode
  88.  
  89.  
  90. /* Subroutines --------------------------------------------------------- */
  91. ReadInfile:
  92.   call stream InFile, 'C', 'open read'
  93.   if stream(InFile, 'S') \= 'READY' then
  94.     do
  95.       ReturnCode = 1
  96.       return
  97.     end
  98.   MnuTitle = linein(InFile)
  99.   i = 1
  100.   do while i < 10
  101.     chLine = linein(InFile)
  102.     if stream(InFile, 'S') \= 'READY' then leave
  103.     if substr(chLine, 1, 1) \= '/' then leave
  104.     parse var chLine '/' MnuItem.i.Text '/' MnuItem.i.Script '/' MnuItem.i.Args
  105.     MnuItem.0 = i
  106.     i = i + 1
  107.   end
  108.   call stream InFile, 'C', 'close'
  109.   return
  110.  
  111.  
  112. ShowMenu:
  113.   MnuBuf         = ''
  114.   do i = 1 to MnuItem.0
  115.     MnuBuf = MnuBuf||MnuDelim||MnuItem.i.Text
  116.   end
  117.   MnuBuf = MnuBuf||MnuDelim
  118.   'PopupMenu("'MnuTitle'", "'MnuBuf'", 'mnuTop', 'mnuLeft', 'mnuAttr', 'mnuHiAttr', 1)'
  119.   return rc
  120.  
  121.  
  122. RunItemScript:
  123.   parse arg i
  124.   if length(MnuItem.i.Args) > 0 & substr(MnuItem.i.Args,1,1) = '[' then
  125.     do
  126.       if MnuItem.i.Args = '[ ]' then
  127.         do
  128.           chPrompt = 'Enter parameter(s) for' MnuItem.i.Script
  129.           chDefault = ''
  130.         end
  131.       else
  132.         parse var MnuItem.i.Args '[' chPrompt '%' chDefault ']'
  133.  
  134.       'sprintf("[%lu", OpenDialog(4, 4, 9, 76, DLogNormAttr))'
  135.       h = substr(rc,2)
  136.       'StrPut(5, 6, DLogNormAttr, "%s", "'chPrompt'")'
  137.       'StrGet("'chDefault'", 7, 6, 68, 255, DLogEdAttr, DLogEdHiAttr)'
  138.       MnuItem.i.Args = rc
  139.       'CloseDialog('h')'
  140.  
  141.       /* Do you want empty string entries to abort the process? */
  142.       /* if length(MnuItem.i.Args) = 0 then return 0 */
  143.     end
  144.  
  145.   'run("'MnuItem.i.Script'","'MnuItem.i.Args'")'
  146.   'itoa(rexxRC, 10)'
  147.   return rc
  148.  
  149.  
  150. /* Error handler ------------------------------------------------------- */
  151. errproc:
  152.   TE2rc = rc
  153.   say '!! Error in TE/2 call'
  154.   say 'rc          =' TE2rc
  155.   say 'line number =' sigl
  156.   say 'instruction = ['sourceline(sigl)']'
  157.   exit 1
  158.