home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxlb.zip / SAMPLES / TRYRXWIN.CMD < prev    next >
OS/2 REXX Batch file  |  1993-08-26  |  10KB  |  263 lines

  1. /***************************************************************/
  2. /* Try out RXWINDOW by calling a series of RXWINDOW functions. */
  3. /***************************************************************/
  4.  
  5. outfile = 'tryrxwin.out'
  6. call dosdel outfile
  7. call lineout outfile,'work=w_open(5,5,20,70,112)   /* 20x70 black on white window */'
  8.  
  9. call INIT
  10. call INIT_FUNC
  11. call HELP
  12. call INIT_WIN
  13. call MAIN
  14. exit
  15.  
  16. INIT:
  17.    parse version . _n .
  18.    UnloadRXWINDOW = 0
  19.    if _n < 2.00 then do
  20.       say 'TRYRXWIN.REX requires REXX version 2.00 or later'
  21.       call BYE
  22.       end
  23.    call rxfuncadd 'w_register', 'rxwin30', 'rxwindow'
  24.    call w_register
  25.    return
  26.  
  27. INIT_FUNC:
  28.    func.1 = 'w_size     window'
  29.    func.2 = 'w_unhide   window'
  30.    func.3 = 'w_unfield  window  f_name'
  31.    func.4 = 'w_move     window  row  col'
  32.    func.5 = 'w_attr     window  row  col  length  attr'
  33.    func.6 = 'w_hide     window  [A|N]'
  34.    func.7 = 'w_scrput   window  row  col  string  [T|A|B]'
  35.    func.8 = 'w_scrread  window  row  col  length  [T|A|B]'
  36.    func.9 = 'w_field    window  f_name    row col length  [attr]  [pad]'
  37.    func.10= 'w_read     window  [f_name]  [activate:N|F]'
  38.    func.11= 'w_keys     window  [tab:J|N] [enter:A|L] [keyboard:F|E|O]'
  39.    func.12= 'w_scrwrite window  row  col  [string] [length]  [pad]   [attr]'
  40.    func.13= 'w_put      window  row  col  [string] [length]  [attr]  [pad]'
  41.    func.14= 'w_get      window  row  col  length   [string]  [attr]  [pad]  [activate:N|F]'
  42.    func.15= 'w_border   window  [top]  [right] [bot] [left] [attr]'
  43.    func.16= 'w_clear    window  [attr] [char]  [row] [col]  [height]  [width]'
  44.    return
  45.  
  46. HELP:
  47.    parse value scrsize() with scr_height scr_width .
  48.    back = w_open(1,1,scr_height,scr_width,7)    /* Background -- white on black window */
  49.    call w_hide back,'N'
  50.  
  51.    help.  = ''
  52.    help.1 = center('TRYRXWIN.REX',80)
  53.    help.3 = 'PURPOSE: Try out RXWINDOW functions.'
  54.    help.4 = '         All functions except W_OPEN and W_CLOSE can be tested.'
  55.    help.6 = 'TO USE:  When TRYRXWIN is ready to accept an RXWINDOW function name, you will'
  56.    help.7 = '         see the prompt:'
  57.    help.9 = '            Enter a windowing function [ENTER to quit] w_'
  58.    help.11= '         Notice that the W_ that appears in the name of each windowing function'
  59.    help.12= '         is already given. Enter the rest of the name of the windowing function'
  60.    help.13= '         you want to run. For example, to try out the W_CLEAR function you type:'
  61.    help.15= '            CLEAR'
  62.    help.17= '         and then hit ENTER.  (When you want to leave TRYRXWIN, don''t enter'
  63.    help.18= '         any text at this prompt--just hit ENTER.)'
  64.    help.19= '         You will then be prompted to enter each of the arguments for the'
  65.    help.20= '         function you''ve selected.  Optional arguments appear in brackets.'
  66.    help.21= '         When all the arguments for the function have been entered,'
  67.    help.22= '         the value of the function is displayed on the screen, the effect of the'
  68.    help.23= '         function (if any) can be seen in the TRYRXWIN window, and the function'
  69.    help.24= '         call and its result are written to the file TRYRXWIN.OUT.'
  70.    help.25= right('Hit any key to continue...',80)
  71.  
  72.    do i = 1 to 24
  73.       call w_scrwrite back,i,1,help.i,80
  74.       end
  75.    call w_scrwrite back,25,1,help.25,80
  76.    call w_unhide back
  77.    call inkey
  78.    drop help.
  79.    return
  80.  
  81. INIT_WIN:
  82.    call w_clear back
  83.    call w_hide back,'N'
  84.    do i = 6 to 23
  85.       call w_scrwrite back,i,5,'Text to see during W_HIDE or W_MOVE',70
  86.       end
  87.    call w_unhide back
  88.    work = w_open(5,5,20,70,112)  /* Workspace  -- black on white window */
  89.    return
  90.  
  91. MAIN:
  92.    signal on halt
  93.    signal on syntax
  94.    do forever
  95.       call GET_FUNC
  96.       call CALL_FUNC
  97.       end
  98.    return
  99.  
  100. GET_FUNC:
  101.    /* Select function to call */
  102.    msg = 'Enter a windowing function [ENTER to quit] w_'
  103.    call w_scrwrite back,2,2,msg,70
  104.    funcname = 'w_'w_get(back,2,length(msg)+2,8)
  105.  
  106.    /* Exit if no function name is specified */
  107.    if substr(funcname,3) = '' then call BYE
  108.    else call GET_ARGS
  109.    return
  110.  
  111. GET_ARGS:
  112.    /* Construct argument list for function */
  113.    arg_string = 'work'
  114.    found = 0
  115.    do i = 1 to 16
  116.       if word(func.i,1) = funcname then do
  117.          found = 1
  118.          do k = 3 to words(func.i)
  119.             _argtype = word(func.i,k)
  120.             prompt =  _argtype '=> '
  121.             call w_scrwrite back,2,2,prompt,70
  122.             _arg = check_arg(_argtype)
  123.             arg_string = arg_string"," || _arg
  124.             end
  125.          end
  126.       end
  127.    if \found then do
  128.       call w_clear back,,,3,2,1,70
  129.       call w_scrwrite back,2,2,'Function not found. Hit any key to continue...',70
  130.       call inkey                        /* Wait for user to hit a key */
  131.       call GET_FUNC                     /* Select function to call */
  132.       end
  133.    return
  134.  
  135. CHECK_ARG:
  136.    /* Be sure argument passed to function is valid */
  137.    arg _argtype
  138.    if pos('[',_argtype) then do
  139.       optional = 1
  140.       _argtype = strip(strip(_argtype,'T',']'),'L','[')
  141.       end
  142.    else optional = 0
  143.    do forever
  144.       _arg = w_get(back,2,length(prompt)+2,70)
  145.       select
  146.          when _arg='' then do
  147.             if \optional then do
  148.                call w_scrwrite back,2,2,'Argument must be specified. Hit any key to continue...',70
  149.                call PAUSE
  150.                end
  151.             else return _arg
  152.             end
  153.          when _argtype='TOP' | _argtype='BOT' | _argtype='LEFT' | _argtype='RIGHT' then do
  154.             if \(datatype(_arg,'W') & (_arg > -1 & _arg < 3)) then do
  155.                call w_scrwrite back,2,2,'Argument must in range 0-2. Hit any key to continue...',70
  156.                call PAUSE
  157.                end
  158.             else return _arg
  159.             end
  160.          when _argtype='ROW' | _argtype='COL' | _argtype='LENGTH' | _argtype='HEIGHT' | _argtype='WIDTH' then do
  161.             if \(datatype(_arg,'W') & _arg > 0) then do
  162.                call w_scrwrite back,2,2,'Argument must be nonzero whole number. Hit any key to continue...',70
  163.                call PAUSE
  164.                end
  165.             else return _arg
  166.             end
  167.          when _argtype='ATTR' then do
  168.             if _arg < 0 | _arg > 255 then do
  169.                call w_scrwrite back,2,2,'Argument must be in the range 0-255. Hit any key to continue...',70
  170.                call PAUSE
  171.                end
  172.             else return _arg
  173.             end
  174.          when pos('T|A|B',_argtype) then do
  175.             _string = substr(strip(strip(_arg,,'"'),,"'"),1,1)
  176.             if \(upper(_string)='T' | upper(_string)='A' | upper(_string)='B') then do
  177.                call w_scrwrite back,2,2,'Argument must be "T" or "A" or "B". Hit any key to continue...',70
  178.                call PAUSE
  179.                end
  180.             else return _arg
  181.             end
  182.          when pos('A|N',_argtype) then do
  183.             _string = substr(strip(strip(_arg,,'"'),,"'"),1,1)
  184.             if \(upper(_string)='A' | upper(_string)='N') then do
  185.                call w_scrwrite back,2,2,'Argument must be "A" or "N". Hit any key to continue...',70
  186.                call PAUSE
  187.                end
  188.             else return _arg
  189.             end
  190.          when pos('TAB:',_argtype) then do
  191.             _string = substr(strip(strip(_arg,,'"'),,"'"),1,1)
  192.             if \(upper(_string)='J' | upper(_string)='N') then do
  193.                call w_scrwrite back,2,2,'Argument must be "J" or "N". Hit any key to continue...',70
  194.                call PAUSE
  195.                end
  196.             else return _arg
  197.             end
  198.          when pos('ENTER:',_argtype) then do
  199.             _string = substr(strip(strip(_arg,,'"'),,"'"),1,1)
  200.             if \(upper(_string)='A' | upper(_string)='L') then do
  201.                call w_scrwrite back,2,2,'Argument must be "A" or "L". Hit any key to continue...',70
  202.                call PAUSE
  203.                end
  204.             else return _arg
  205.             end
  206.          when pos('KEYBOARD:',_argtype) then do
  207.             _string = substr(strip(strip(_arg,,'"'),,"'"),1,1)
  208.             if \(upper(_string)='F' | upper(_string)='E' | upper(_string)='O') then do
  209.                call w_scrwrite back,2,2,'Argument must be "F" or "E" or "O". Hit any key to continue...',70
  210.                call PAUSE
  211.                end
  212.             else return _arg
  213.             end
  214.          when pos('ACTIVATE',_argtype) then do
  215.             _string = substr(strip(strip(_arg,,'"'),,"'"),1,1)
  216.             if \(upper(_string)='N' | upper(_string)='F') then do
  217.                call w_scrwrite back,2,2,'Argument must be "N" or "F". Hit any key to continue...',70
  218.                call PAUSE
  219.                end
  220.             else return _arg
  221.             end
  222.          otherwise return _arg
  223.          end
  224.       end
  225.  
  226. CALL_FUNC:
  227.    /* Call function, removing trailing commas from constructed argument list */
  228.    interpret 'value =' funcname'('strip(arg_string,'T',',')')'
  229.  
  230.    /* Display results on screen and write results to output file */
  231.    call w_scrwrite back,3,2,'Result from' funcname 'is "'value'"',70
  232.    call lineout outfile,'call' funcname strip(arg_string,'T',',')
  233.    call lineout outfile,'   /* Returns "'value'" */'
  234.    return
  235.  
  236. PAUSE:
  237.    /* Wait for the user to hit a key, then redisplay the prompt */
  238.    call w_clear back,,,3,2,1,70
  239.    call inkey
  240.    call w_scrwrite back,2,2,prompt,70
  241.    return
  242.  
  243. SYNTAX:
  244.    call w_scrwrite back,3,2,'REXX:' errortext(rc) '(error' rc'). Hit any key to continue...',70
  245.    call inkey
  246.    call w_clear back,,,3,2,1,70
  247.    call lineout outfile,'/* call' funcname strip(arg_string,'T',',')' */'
  248.    if pos('/*',errortext(rc)) \= 0 then call lineout outfile,'   /* Unmatched quote or comment delimiter */'
  249.    else call lineout outfile,'   /*' errortext(rc) '*/'
  250.    signal main
  251.    return
  252.  
  253. HALT:
  254.    call BYE
  255.    return
  256.  
  257. BYE:
  258.    call lineout outfile,'call w_close work'
  259.    call lineout outfile              /* Close output file */
  260.    call w_close work                 /* Close Workspace window */
  261.    call w_close back                 /* Close Background window */
  262.    exit
  263.