/* Batch-Demo für AHP3.16 und Wait-Text-System */

options results

if index(show(p),"rexx_AHP")=0 then do
  say "ARexx-Port von AHP ist nicht zu finden."
  exit
end

address "rexx_AHP"

call open_libs

"discport"

port=result

if port=0 then do
  say "Kein freier Port da!"
  exit
end

say "Habe freien Port auf "||port||" gefunden."

pname="reply"||port

"port "||port

"rtp"

say result

"wait_num 1"
"wait_text 1 =>"

say "Wait-Text Nr.1 ist :"||result

call create_port(pname)

"command :c db0wob"

"reply "||pname
say "Portname ist :"||result

back=wait_text(pname)

say back

if back="1" then do
  "send u"
end

exit

open_libs: procedure    /* rexxsupport.library öffnen */

if ~show(l,'rexxsupport.library') then do
  if ~addlib('rexxsupport.library',0,-30,0) then do
    say "Konnte rexxsupport.library nicht öffnen"
    exit 10
  end
end

return

create_port: procedure   /* Antwort-Port öffnen */
parse arg port_name      /* Kleinbuchstaben sind erwünscht */

if ~openport(port_name) then do
  say "Konnte Port "||port_name||" nicht öffnen."
  say "Der Port existiert vielleicht schon."
  exit
end

return

wait_text: procedure     /* Auf die Antwort warten */
parse arg port_name      /* Kleinbuchstaben sind erwünscht */

back = "Port not found"
if index(show(p),port_name)>0 then do
  call waitpkt(port_name)
  pack = getpkt(port_name)
  back = getarg(pack)
  call reply(pack,0)
end

return back
