home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXMENU2.ZIP / MENUPICK.CMD < prev    next >
OS/2 REXX Batch file  |  1992-11-25  |  3KB  |  99 lines

  1. /* MenuPick - Set environment variable from a menu created from the input.
  2.  *            Expect input of type VAL:Description;VAL:Description;etc...
  3.  *            and will set environment variable to VAL.
  4.  */
  5.  
  6. if ARG(1) = "" then signal MenuPickHelp
  7.  
  8. /* Parse input into first the Environment Variable Name, uppercase
  9.  */
  10. PARSE ARG VariableName SourceArgs
  11. PARSE UPPER VAR VariableName VariableName
  12. if SourceArgs = "" then signal MenuPickHelp
  13.  
  14. /* Create MenuPickLst.0,1, etc for all the items selected
  15.  */
  16. ChoiceCount = 0
  17. do until SourceArgs = ""
  18.    PARSE VAR SourceArgs MenuPickLst.ChoiceCount ";" SourceArgs
  19.    DescCount = ChoiceCount + 1
  20.    PARSE VAR MenuPickLst.ChoiceCount MenuPickLst.ChoiceCount ':' MenuPickLst.DescCount
  21.    if MenuPickLst.DescCount = "" then
  22.       MenuPickLst.DescCount = MenuPickLst.ChoiceCount
  23.    ChoiceCount = DescCount + 1
  24. end /* do */
  25. if ChoiceCount = 0 then signal MenuPickHelp
  26.  
  27. /* Create file of the display choices
  28.  */
  29. '@if exist MenuPLst.tmp del MenuPLst.tmp > NUL'
  30. i = 0
  31. do until i = ChoiceCount
  32.    i = i + 1
  33.    '@echo' MenuPickLst.i '>> MenuPLst.tmp'
  34.    i = i + 1
  35. end /* do */
  36.  
  37. /* Create string to execute to call RexxMenum checking for TIMEOUT and PROMPT
  38.  */
  39. RexxMenuStr = "RexxMenuResult = RexxMenu('MenuPLst.tmp'"
  40. if \(value('MP_TIMEOUT',,'OS2ENVIRONMENT') = "") then do
  41.    RexxMenuStr = INSERT(RexxMenuStr,",'/Time','")
  42.    RexxMenuStr = INSERT(RexxMenuStr,value('MP_TIMEOUT',,'OS2ENVIRONMENT'))
  43.    RexxMenuStr = INSERT(RexxMenuStr,"'")
  44. end  /* Do */
  45. if \(value('MP_PROMPT',,'OS2ENVIRONMENT') = "") then do
  46.    RexxMenuStr = INSERT(RexxMenuStr,",'/Prompt','")
  47.    RexxMenuStr = INSERT(RexxMenuStr,value('MP_PROMPT',,'OS2ENVIRONMENT'))
  48.    RexxMenuStr = INSERT(RexxMenuStr,"'")
  49. end  /* Do */
  50. RexxMenuStr = INSERT(RexxMenuStr,")")
  51.  
  52. /* Call RexxMenu, end it will set RexxMenuResult
  53.  */
  54. if 1 = RxFuncQuery('RexxMenu') then
  55.    CALL RxFuncAdd 'RexxMenu', 'RexxMenu', 'RexxMenu'
  56. interpret RexxMenuStr
  57. '@del MenuPLst.tmp > NUL'
  58. if RexxMenuResult = "" then signal MenuPickHelp
  59.  
  60. /* Set environment variable based on RexxMenuResult
  61.  */
  62. i = 1
  63. do while \(RexxMenuResult = MenuPickLst.i)
  64.    i = i + 2
  65. end /* do */
  66. i = i - 1
  67. interpret INSERT(INSERT(INSERT(INSERT("'SET ",VariableName),"="),MenuPickLst.i),"'")
  68. signal AllDone
  69.  
  70.  
  71. MenuPickHelp:
  72. say
  73. say 'MenuPick - Set environment variable from a menu of options.'
  74. say
  75. say 'SYNTAX: MenuPick <ENVIRONMENT_VARIABLE> [Value[:Descr][;Value:Descr]...]'
  76. say 'Where:'
  77. say '  ENVIRONMENT_VARIABLE - This environment variable will be set to the chosen'
  78. say '          menu Value.'
  79. say '  Value - What the ENVIRONMENT_VARIABLE may be set to.'
  80. say '  Descr - Paired with val, this is the choice that appears on the menu.'
  81. say '          If no ":" delimiting description then Value will be shown.'
  82. say
  83. say 'The following environment variables are used if they have been set:'
  84. say '   MP_TIMEOUT - Number of seconds to wait before timing out on the first choice.'
  85. say '   MP_PROMPT - Text at top of screen to prompt for user selection.'
  86. say
  87. say 'Example: To set the screen lines, you may have a batch file as follows:'
  88. say '           set MP_TIMEOUT=5'
  89. say '           set MP_PROMPT=Choose screen height:'
  90. say '           MenuPick LINES 25:Few big text lines;50:Many small text lines'
  91. say '           mode 80,%LINES%'
  92. say
  93. signal AllDone
  94.  
  95.  
  96. AllDone:
  97. DROP MenuPickLst.
  98.  
  99.