/* Test of creating and destroying startup shadows */

call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
call SysLoadFuncs

parse upper arg p1 p2 p3
if p2 = '' | p3 \= '' then do
  say 'objtest.cmd needs exactly 2 arguments' p1 p2 p3
  exit
end
pp.1 = p1
pp.2 = p2
obj = ''
func = ''
do i = 1 to 2
  select
  when abbrev('KEYBOARD', pp.i, 1) then obj = "<ICEBEARSOFT_KEYBOARD_DRIVER>"
  when abbrev('SETTINGS', pp.i, 1) then obj = "<ICEBEARSOFT_KEYBOARD_SETTINGS>"
  when abbrev('CREATE', pp.i, 1) then func = "C"
  when abbrev('DESTROY', pp.i, 1) then func = "D"
  otherwise say 'Unknown parameter' pp.i
  end
end
if func = '' | obj = '' then do
  say 'Function or object not specified'
  exit
end

if func == "C" then do
  if obj = "<ICEBEARSOFT_KEYBOARD_DRIVER>" then exe = 'icekeybd.exe'
  else exe = 'icekbset.exe'
  exe = SysSearchPath('PATH', exe)
  if exe = '' then do
    say 'The program was not found along PATH'
    exit
  end
  rc = SysCreateObject('WPShadow', 'Shadow', '<WP_START>', 'OBJECTID=' || obj || ,
       ';SHADOWID=' || exe || ';', 'replace')
  if rc then say 'Object created'
  else say 'Creation failed'
end

if func == "D" then do
  rc = SysDestroyObject(obj)
  if rc then say 'Object destroyed'
  else say "Couldn't destroy the object"
end
