#! ../../xsrexx

/*
 *  A sample S/REXX standalone dialog box:
 *
 * ---------------------------------------------------------------
 * |                                                             |
 * | |Quit|       From Directory: _____________________________  |
 * |                                                             |
 * |              Tape Selection:   nrst4   nrst5              |
 * |                                                             |
 * |                                                             |
 * |                         | Start TAR |                       |
 * ---------------------------------------------------------------
 *
 */
signal on novalue
option mixed setenv

call dy_start()

$quit = dy_button(1, 1,  "Quit")

call dy_label 14, 1.3, 'From Directory:'
$dir = dy_input(30, 1.3, 28)

$tape = dy_tg('Tape Selection:', 14, 5, 32, 4.5, "nrst4", 1, 40, 4.5, "nrst5", 0)


$start = dy_button(26.5, 10, "Start TAR")

$handle_dy_ex = dy_end("proc", 2, 3.5, 61, 12.5, "n")

call dy_map $handle_dy_ex
exit

proc:
  parse arg handle reason

  select
    when reason = 'F1'  | reason = 'B'$quit | reason = '^c' then
      {  call dy_unmap(handle)
         exit 0
      }

    when reason = 'B'$start | reason = 'return' then
      { if  do_it() = 0 then  exit 0
      }

    otherwise return 0
  end
return

do_it:
  dir = dy_vinput(handle, $dir)

  if ~state(dir, 'd') then
   { call dy_start()
     call dy_label 2, 5, '"'dir'" is not a valid directory.'
     call dy_button 26.5, 10, "Restart"
     $prompt = dy_end("foo", 2, 3.5, 61, 12.5, "g")
     call dy_map $prompt
     call dy_destroy $prompt
     return 1
   }

  select
    when 1 = dy_vtg(handle, $tape, 1) then tape = 'nrst4'
    when 1 = dy_vtg(handle, $tape, 2) then tape = 'nrst5'
  end

  cd dir
  say 'dy_tar could perform the following commands:'
  say
  say '   cd 'cwd()
  say '   tar -cvf /dev/'tape '.'
  say
return 0

foo:
return
