      Subroutine Setcmd(Cmd)
c
      Integer*4 Index,Lib$Do_Command
      Character*40 Cmd
      Include'($SSDEF)'
      Index = LIB$Do_Command(Cmd)
      If (.NOT. Index) Call Lib$Signal(%Val(Index))
      End
      Subroutine Chrpos(Irow,Icol)
c
      Integer*2 Irow,Ipos,Ichr,Len
      Character*5 Getpos
      Character*1 Ctemp
      Byte Ichar
      Equivalence (Ichr,Ichar),(Ichar,Ctemp)
c
      Ichar = 27
      Getpos(2:4) = '[6n'
      Getpos(1:1) = Ctemp
      Len = 4
      Call Wrtqio(Getpos,Len)
c
 10   Continue
c
      Call Ittinr(Ichr)
      If (Ichar .NE. '[') Go To 10
c
c              Get the value of the row
c 
      Call Ittinr(Ichr)
      Irow = Ichr - 48
      Call Ittinr(Ichr)
      If (Ichar .NE. ';') Then
         Irow = Irow * 10 + Ichr - 48
         Call Ittinr(Ichr)
      End If
c
c              Get the value of the column
c
      Call Ittinr(Ichr)
      Icol = Ichr - 48
      Call Ittinr(Ichr)
      If (Ichar .NE. 'R') Then
         Icol = Icol * 10 + Ichr - 48
         Call Ittinr(Ichr)
      End If
c
      Return
      End
      Subroutine Wrtqio(Answer,Len)
c
      Integer*2 Irow,Icol,Ichr,Len
      Integer*4 Status,Write_Len,Code
      Character*132 Answer
      Integer*2 Out_Chan,Input_Chan,Inctrl_Chan
c      Byte Strin
c      Equivalence (Answer(1:1),Strin) 
c
      Common/QIOchan/Input_Chan,Out_Chan,Inctrl_Chan
c
c            Status block for Qio
c
      Structure/Iostat_Block/
         Integer*2 Iostat,Byte_Count,
     $             Lines_Output
         Byte Column,Line
      End Structure
      Record /Iostat_Block/ Iosb
c
c           Routines
c
      Integer*4 SYS$Qiow
c
      Include '($IODEF)'
c
      Write_Len = Len
      Code = Io$_Writevblk .OR. Io$M_Noformat
      Status = SYS$Qiow(,%Val(Out_Chan),%Val(Code),
     $         Iosb,,,%Ref(Answer(1:Write_Len)),
     $         %Val(Write_Len),,
     $         ,,)  
      If (.NOT. Status) Call Lib$Signal(%val(Status))
      If (.NOT. Iosb.Iostat) Call Lib$Signal(%Val(Iosb.Iostat))
c
      Return
      End
      Subroutine Ittinr(Iret)
c
      Integer*4 Status
      Integer*2 Iret
c
c             Qiow Structures
c
      Integer*2 Input_Chan,Out_Chan,Inctrl_Chan
      Integer*4 Code,                  ! Type of I/O operation
     $          Input_Buff_Size,       ! Size of input buffer
     $          Prompt_Size,           ! Size of prompt
     $          Input_Size             ! Size of input line as read
      Parameter (Prompt_Size = 0,Input_Buff_Size = 1)
      Character*1 Input
c
      Common/QIOchan/Input_Chan,Out_Chan,Inctrl_Chan
c
      Include '($IODEF)'
c
c             Status block for Qiow
c
      Structure /Iostat_Block/
         Integer*2  Iostat,            ! Return status
     $              Term_Offset,       ! Location of line terminator
     $              Terminator,        ! Value of terminator
     $              Term_Size          ! Size of terminator
      End Structure
      Record /Iostat_Block/ Iosb
c
c             Subprograms
c
      Integer*4 Sys$Qiow
c
      Code = Io$_Readvblk .OR. Io$M_Noecho .OR. Io$M_Nofiltr
10    Continue
      Status = SYS$Qiow(,%Val(Input_Chan),%Val(Code),Iosb,
     $                  ,,%Ref(Input),%Val(Input_Buff_Size),,,
     $                  ,%Val(Prompt_Size))
c
c             Check Qiow status
c
      If(.NOT. Status) Call Lib$Signal(%Val(Status))
c
c             Check status of I/O operation
c
      If (.NOT. Iosb.Iostat) Call Lib$Signal(%Val(Iosb.Iostat))
c
      Iret = Ichar(Input(1:1))
      Return
      End   
      Subroutine Iostart
c
c            Subroutine Iostart - to get the input
c            and output channel numbers
c
      Integer*2 Out_Chan,Input_Chan,Inctrl_Chan,Len
      Integer*4 Status,SYS$Assign,Mask,Oldmask,Lib$_Disable_Ctrl
      Integer*4 Lib$Getdvi,Numval
      Character*20 Strin
c
      Common/QIOchan/Input_Chan,Out_Chan,Inctrl_Chan
      Include 'Cflags'
c
      Include '($IODEF)'
      Include '($Libclidef)'
      Include '($DVIDEF)'
c
c                 Turn off the Ctrl-C's and Ctrl-Y's
c
      Mask = Lib$M_Cli_Ctrly
      Status = Lib$Disable_Ctrl(Mask,Oldmask)
      If (.NOT. Status) Call Lib$Signal(%Val(Status))
c
c                 Get the output channel number
c
      Status = SYS$Assign('SYS$Output',Out_Chan,,)
      If (.NOT. Status) Call Lib$Signal(%Val(Status))
c
c                 Get the input channel number
c
      Status = Sys$Assign('Sys$Input',Input_Chan,,)
      If (.NOT. Status) Call Lib$Signal(%Val(Status))
c
c                 Get the output channel number
c
      Status = Sys$Assign('Sys$Input',Inctrl_Chan,,)
      If (.NOT. Status) Call Lib$Signal(%Val(Status))
      Call Ctrl
c
c                 See if we have Regis graphics, etc
c
      Status = Lib$Getdvi(DVI$_TT_Regis,,'TT:',Numval,
     $                    Strin,Len)
      If (.NOT. Status) Call Lib$Signal(%Val(Status))

      If (Strin .EQ. 'TRUE') Then
         Term_Type = 'VT24'
      Else
         Term_Type = 'NONE'
      End If
c      
      Return
      End
      Subroutine Ctrl
c
      Integer*2 Out_Chan,Input_Chan,Inctrl_Chan
      Integer*4 Status,Sys$Qiow,Code
c
      Structure /Iostat_Block/
         Integer*2  Iostat
         Byte       Transmit,Recieve,Crfill,Lffill,Parity,Zero
      End Structure
c
      Record /Iostat_Block/ Iosb
c
c         AST Subroutine to handle tht Ctrl C interrupt
c
      External Abt
c
      Common/QIOchan/Input_Chan,Out_Chan,Inctrl_Chan
      Include '($IODEF)'
c
      Code = Io$_Setmode  .OR. Io$m_Ctrlcast
c
      Status = Sys$Qiow(,%Val(Inctrl_Chan),%Val(Code),Iosb,,,
     $         Abt,,,,,)
      If (.NOT. Status) Call Lib$Signal(%Val(Status))
      If (.NOT. Iosb.Iostat) Call Lib$Signal(%Val(Iosb.iostat))
      Return
      End    
