///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Library script file                                      1.06 02-Nov-1991 //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

string cr[1]=$chr(13),return[1]=$chr(13),newline[2]=$chr(13)+$chr(10)
string escape[1]=$chr(27),lf[1]=$chr(10)

// Time in cs to wait for carrier/reply
integer modem_carrierwait=4000,modem_replywait=4000

$modeminput (integer maxlen,integer timeout)
  {
  integer start=time(),count=0,ch
  string abc[maxlen]

  while(((time()-start)<timeout) && count<maxlen)
    {
    if (port_rxbuffer()==0)
      {
      pause(10)
      }

    if (port_rxbuffer()!=0)
      {
      ch=port_rx()
      if (ch==13 || ch==10)
        {
        if (ch==10)
          {
          $return(abc)
          }
        }
      else
        {
        abc=abc+$chr(ch)
        count=count+1
        }
      }
    } 

  $return("")
  }

$modeminput2 (integer maxlen,integer timeout,integer echo)
  {
  integer start=time(),count=0,ch
  string abc[maxlen]

  while(((time()-start)<timeout) && count<maxlen)
    {
    if (port_rxbuffer()==0)
      {
      pause(10)
      }
    if (port_rxbuffer()!=0)
      {
      ch=port_rx()
      if (echo)
        {
        vdu(ch)
        }

      if (ch==13 || ch==10)
        {
        if (ch==10)
          {
          $return(abc)
          }
        }
      else
        {
        abc=abc+$chr(ch)
        count=count+1
        }
      }
    } 

  $return(abc)
  }

isalpha (string b[1])
  {
  integer a=asc(b)

  if ((a<'A' || a>'z') || (a>'Z' && a<'a'))
    {
    return(0)
    }
  return(1)
  }

isdigit (string b[1])
  {
  integer a=asc(b)

  if (a>='0' && a<='9')
    {
    return(1)
    }
  return(0)
  }

toupper (integer a)
  {
  if (a>='a' && a<='z')
    {
    a=a-32
    }
  return(a)
  }

tolower (integer a)
  {
  if (a>='A' && a<='Z')
    {
    a=a+32
    }
  return(a)
  }

dorequest (string message[80])
  {
  integer d=dbox_new("request")

  dbox_set(d,1,message)
  dbox_open(d)
  while(dbox_waitselect(d)!=0)
    {
    // Do nothing
    }
  dbox_close(d)
  dbox_dispose(d)
  }

// The following lines contain system variables. DO NOT ALTER THESE!
// set(x,y) commands
integer none=0,off=0,on=1,false=0,off=0
integer terminal=1,linklevel=2,wrap=3,newline=4,localecho=5,remoteecho=6
integer featurelock=7,hostprinter=8,flowcontrol=9,filter=10
integer autodownload=11

// set(terminal,x) commands
integer tty=1,vt102=2,ansi=3,vt52=4,viewdata=5,bbc=6,ttns_vt102=7
integer ttns_viewdata=8,teltel=9,minitel=9,ttns_teletel=10
integer ttns_minitel=10,hexdump=11,showcontrol=12,avatar=14

// set(linklevel,x) commands
integer mnp=1,vasscom=2

// flow control
integer hardware=1,xonxoff=2

// upload(x) and download(x)
integer zmodem=1,ymodem=2,xmodem1k=3,xmodem=4,kermit=6,sealink=8
integer cet=9,ymodemg=10,ascii=11

// file count for up and download
integer filesdone=0

// download path and path of currently running script
string  downloadpath[130],runpath[130]
