| 1 |
706 |
jeremybenn |
------------------------------------------------------------------------------
|
| 2 |
|
|
-- --
|
| 3 |
|
|
-- GNAT LIBRARY COMPONENTS --
|
| 4 |
|
|
-- --
|
| 5 |
|
|
-- G N A T . E X P E C T . T T Y --
|
| 6 |
|
|
-- --
|
| 7 |
|
|
-- S p e c --
|
| 8 |
|
|
-- --
|
| 9 |
|
|
-- Copyright (C) 2000-2011, AdaCore --
|
| 10 |
|
|
-- --
|
| 11 |
|
|
-- GNAT is free software; you can redistribute it and/or modify it under --
|
| 12 |
|
|
-- terms of the GNU General Public License as published by the Free Soft- --
|
| 13 |
|
|
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
| 14 |
|
|
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
| 15 |
|
|
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
| 16 |
|
|
-- or FITNESS FOR A PARTICULAR PURPOSE. --
|
| 17 |
|
|
-- --
|
| 18 |
|
|
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
| 19 |
|
|
-- additional permissions described in the GCC Runtime Library Exception, --
|
| 20 |
|
|
-- version 3.1, as published by the Free Software Foundation. --
|
| 21 |
|
|
-- --
|
| 22 |
|
|
-- You should have received a copy of the GNU General Public License and --
|
| 23 |
|
|
-- a copy of the GCC Runtime Library Exception along with this program; --
|
| 24 |
|
|
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
| 25 |
|
|
-- <http://www.gnu.org/licenses/>. --
|
| 26 |
|
|
-- --
|
| 27 |
|
|
-- GNAT was originally developed by the GNAT team at New York University. --
|
| 28 |
|
|
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
| 29 |
|
|
-- --
|
| 30 |
|
|
------------------------------------------------------------------------------
|
| 31 |
|
|
|
| 32 |
|
|
with GNAT.TTY;
|
| 33 |
|
|
|
| 34 |
|
|
with System;
|
| 35 |
|
|
with System.OS_Constants;
|
| 36 |
|
|
|
| 37 |
|
|
package GNAT.Expect.TTY is
|
| 38 |
|
|
|
| 39 |
|
|
pragma Linker_Options (System.OS_Constants.PTY_Library);
|
| 40 |
|
|
|
| 41 |
|
|
------------------
|
| 42 |
|
|
-- TTY_Process --
|
| 43 |
|
|
------------------
|
| 44 |
|
|
|
| 45 |
|
|
type TTY_Process_Descriptor is new Process_Descriptor with private;
|
| 46 |
|
|
-- Similar to Process_Descriptor, with the parent set up as a full terminal
|
| 47 |
|
|
-- (Unix sense, see tty(4)).
|
| 48 |
|
|
|
| 49 |
|
|
procedure Pseudo_Descriptor
|
| 50 |
|
|
(Descriptor : out TTY_Process_Descriptor'Class;
|
| 51 |
|
|
TTY : GNAT.TTY.TTY_Handle;
|
| 52 |
|
|
Buffer_Size : Natural := 4096);
|
| 53 |
|
|
-- Given a terminal descriptor (TTY), create a pseudo process descriptor
|
| 54 |
|
|
-- to be used with GNAT.Expect.
|
| 55 |
|
|
--
|
| 56 |
|
|
-- Note that it is invalid to call Close, Interrupt, Send_Signal on the
|
| 57 |
|
|
-- resulting descriptor. To deallocate memory associated with Process,
|
| 58 |
|
|
-- call Close_Pseudo_Descriptor instead.
|
| 59 |
|
|
|
| 60 |
|
|
procedure Close_Pseudo_Descriptor
|
| 61 |
|
|
(Descriptor : in out TTY_Process_Descriptor);
|
| 62 |
|
|
-- Free memory and ressources associated with Descriptor. Will *not*
|
| 63 |
|
|
-- close the associated TTY, it is the caller's responsibility to call
|
| 64 |
|
|
-- GNAT.TTY.Close_TTY.
|
| 65 |
|
|
|
| 66 |
|
|
procedure Interrupt (Pid : Integer);
|
| 67 |
|
|
-- Interrupt a process given its pid
|
| 68 |
|
|
|
| 69 |
|
|
overriding procedure Send
|
| 70 |
|
|
(Descriptor : in out TTY_Process_Descriptor;
|
| 71 |
|
|
Str : String;
|
| 72 |
|
|
Add_LF : Boolean := True;
|
| 73 |
|
|
Empty_Buffer : Boolean := False);
|
| 74 |
|
|
-- See parent
|
| 75 |
|
|
-- What does that comment mean??? what is "parent" here
|
| 76 |
|
|
|
| 77 |
|
|
procedure Set_Use_Pipes
|
| 78 |
|
|
(Descriptor : in out TTY_Process_Descriptor;
|
| 79 |
|
|
Use_Pipes : Boolean);
|
| 80 |
|
|
-- Tell Expect.TTY whether to use Pipes or Console (on windows). Needs to
|
| 81 |
|
|
-- be set before spawning the process. Default is to use Pipes.
|
| 82 |
|
|
|
| 83 |
|
|
procedure Set_Size
|
| 84 |
|
|
(Descriptor : in out TTY_Process_Descriptor'Class;
|
| 85 |
|
|
Rows : Natural;
|
| 86 |
|
|
Columns : Natural);
|
| 87 |
|
|
-- Sets up the size of the terminal as reported to the spawned process
|
| 88 |
|
|
|
| 89 |
|
|
private
|
| 90 |
|
|
|
| 91 |
|
|
-- All declarations in the private part must be fully commented ???
|
| 92 |
|
|
|
| 93 |
|
|
overriding procedure Close
|
| 94 |
|
|
(Descriptor : in out TTY_Process_Descriptor;
|
| 95 |
|
|
Status : out Integer);
|
| 96 |
|
|
|
| 97 |
|
|
overriding procedure Close
|
| 98 |
|
|
(Descriptor : in out TTY_Process_Descriptor);
|
| 99 |
|
|
|
| 100 |
|
|
overriding procedure Interrupt (Descriptor : in out TTY_Process_Descriptor);
|
| 101 |
|
|
-- When we use pseudo-terminals, we do not need to use signals to
|
| 102 |
|
|
-- interrupt the debugger, we can simply send the appropriate character.
|
| 103 |
|
|
-- This provides a better support for remote debugging for instance.
|
| 104 |
|
|
|
| 105 |
|
|
procedure Set_Up_Communications
|
| 106 |
|
|
(Pid : in out TTY_Process_Descriptor;
|
| 107 |
|
|
Err_To_Out : Boolean;
|
| 108 |
|
|
Pipe1 : access Pipe_Type;
|
| 109 |
|
|
Pipe2 : access Pipe_Type;
|
| 110 |
|
|
Pipe3 : access Pipe_Type);
|
| 111 |
|
|
|
| 112 |
|
|
procedure Set_Up_Parent_Communications
|
| 113 |
|
|
(Pid : in out TTY_Process_Descriptor;
|
| 114 |
|
|
Pipe1 : in out Pipe_Type;
|
| 115 |
|
|
Pipe2 : in out Pipe_Type;
|
| 116 |
|
|
Pipe3 : in out Pipe_Type);
|
| 117 |
|
|
|
| 118 |
|
|
procedure Set_Up_Child_Communications
|
| 119 |
|
|
(Pid : in out TTY_Process_Descriptor;
|
| 120 |
|
|
Pipe1 : in out Pipe_Type;
|
| 121 |
|
|
Pipe2 : in out Pipe_Type;
|
| 122 |
|
|
Pipe3 : in out Pipe_Type;
|
| 123 |
|
|
Cmd : String;
|
| 124 |
|
|
Args : System.Address);
|
| 125 |
|
|
|
| 126 |
|
|
type TTY_Process_Descriptor is new Process_Descriptor with record
|
| 127 |
|
|
Process : System.Address; -- Underlying structure used in C
|
| 128 |
|
|
Use_Pipes : Boolean := True;
|
| 129 |
|
|
end record;
|
| 130 |
|
|
|
| 131 |
|
|
end GNAT.Expect.TTY;
|