!***********************************************************************
!*
!*          Test program for screen control package
!*
!***********************************************************************
!
!
!***********************************************************************
!*
!*          Constants
!*
!***********************************************************************
!
constantinteger  no = 0, yes = 1
constantinteger  number mode = 0, character mode = 1
constantstring (3)array  ascode(0:32) = c 
"NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL", "BS", "HT", "LF", "VT",
 "FF", "CR", "SO", "SI","DLE","DC1","DC2","DC3","DC4","NAK","SYN","ETB",
"CAN", "EM","SUB","ESC", "FS", "GS", "RS", "US", "SP"
!
!
!***********************************************************************
!*
!*          Subsystem references
!*
!***********************************************************************
!
systemstringfunctionspec  htos(integer  value,places)
systemstringfunctionspec  itos(integer  n)
externalroutinespec  prompt(string (255) s)
externalintegerfunctionspec  vdub(integer  n)
externalstringfunctionspec  vduc(integer  x,y)
externalintegerfunctionspec  vdui(integer  n)
externalstringfunctionspec  vdus(integer  n)
!
!
!***********************************************************************
!*
!*          Service routines
!*
!***********************************************************************
!
stringfunction  character(integer  ch,mode)
! Yields a string describing 'ch', in a form which depends on 'mode'.
string (4) res
!
if  mode = character mode then  start 
      if  0 <= ch <= 32 then  result  = ascode(ch) else  c 
      if  ch = x'7f' then  result  = "DEL" else  start 
         res = "'".tostring(ch)."'"
         res = res."'" if  ch = ''''
         result  = res
      finish 
else 
   result  = htos(ch,2)
finish 
end ;   ! of character
!
!-----------------------------------------------------------------------
!
stringfunction  chs string(string (255) value,integer  mode)
! Yields a printable version of the item described by 'value'.
integer  last,i,count,flag,ch
string (255) res
!
res = ""
result  = "" if  length(value) = 0
last = -1
count = 0
flag = no
for  i = 1,1,length(value) cycle 
   ch = charno(value,i)
   if  ch = last then  count = count + 1 else  start 
      if  last # -1 then  start 
         res = res."," if  flag = yes
         flag = yes
         res = res.character(last,mode)
         if  count # 1 then  res = res."(".itos(count).")"
      finish 
      last = ch
      count = 1
   finish 
repeat 
res = res."," if  flag = yes
res = res.character(last,mode)
if  count # 1 then  res = res."(".itos(count).")"
result  = res
end ;   ! of chs string
!
!
!***********************************************************************
!*
!*          S T E S T
!*
!***********************************************************************
!
externalroutine  stest(string (255) parms)
integer  flag,x,y
string (255) s,s1
!
prompt("X value: ")
read(x)
prompt("Y value: ")
read(y)
!
s = vduc(x,y)
!
if  s = "" then  start 
   printstring("Terminal cannot position cursor")
else 
   printstring(chs string(s,character mode))
finish 
newline
end ;   ! of stest
endoffile