OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / ada / g-expect.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
5 --                          G N A T . E X P E C T                           --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                     Copyright (C) 2000-2010, 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 2,  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.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  Currently this package is implemented on all native GNAT ports except
35 --  for VMS. It is not yet implemented for any of the cross-ports (e.g. it
36 --  is not available for VxWorks or LynxOS).
37
38 --  -----------
39 --  -- Usage --
40 --  -----------
41
42 --  This package provides a set of subprograms similar to what is available
43 --  with the standard Tcl Expect tool.
44
45 --  It allows you to easily spawn and communicate with an external process.
46 --  You can send commands or inputs to the process, and compare the output
47 --  with some expected regular expression.
48
49 --  Usage example:
50
51 --      Non_Blocking_Spawn
52 --         (Fd, "ftp",
53 --           (1 => new String' ("machine@domain")));
54 --      Timeout := 10_000;  --  10 seconds
55 --      Expect (Fd, Result, Regexp_Array'(+"\(user\)", +"\(passwd\)"),
56 --              Timeout);
57 --      case Result is
58 --         when 1 => Send (Fd, "my_name");   --  matched "user"
59 --         when 2 => Send (Fd, "my_passwd"); --  matched "passwd"
60 --         when Expect_Timeout => null;      --  timeout
61 --         when others => null;
62 --      end case;
63 --      Close (Fd);
64
65 --  You can also combine multiple regular expressions together, and get the
66 --  specific string matching a parenthesis pair by doing something like this:
67 --  If you expect either "lang=optional ada" or "lang=ada" from the external
68 --  process, you can group the two together, which is more efficient, and
69 --  simply get the name of the language by doing:
70
71 --      declare
72 --         Matched : Match_Array (0 .. 2);
73 --      begin
74 --         Expect (Fd, Result, "lang=(optional)? ([a-z]+)", Matched);
75 --         Put_Line ("Seen: " &
76 --                   Expect_Out (Fd) (Matched (2).First .. Matched (2).Last));
77 --      end;
78
79 --  Alternatively, you might choose to use a lower-level interface to the
80 --  processes, where you can give your own input and output filters every
81 --  time characters are read from or written to the process.
82
83 --      procedure My_Filter
84 --        (Descriptor : Process_Descriptor'Class;
85 --         Str        : String;
86 --         User_Data  : System.Address)
87 --      is
88 --      begin
89 --         Put_Line (Str);
90 --      end;
91
92 --      Non_Blocking_Spawn
93 --        (Fd, "tail",
94 --         (new String' ("-f"), new String' ("a_file")));
95 --      Add_Filter (Fd, My_Filter'Access, Output);
96 --      Expect (Fd, Result, "", 0);  --  wait forever
97
98 --  The above example should probably be run in a separate task, since it is
99 --  blocking on the call to Expect.
100
101 --  Both examples can be combined, for instance to systematically print the
102 --  output seen by expect, even though you still want to let Expect do the
103 --  filtering. You can use the Trace_Filter subprogram for such a filter.
104
105 --  If you want to get the output of a simple command, and ignore any previous
106 --  existing output, it is recommended to do something like:
107
108 --      Expect (Fd, Result, ".*", Timeout => 0);
109 --      -- Empty the buffer, by matching everything (after checking
110 --      -- if there was any input).
111
112 --      Send (Fd, "command");
113 --      Expect (Fd, Result, ".."); -- match only on the output of command
114
115 --  -----------------
116 --  -- Task Safety --
117 --  -----------------
118
119 --  This package is not task-safe: there should not be concurrent calls to the
120 --  functions defined in this package. In other words, separate tasks must not
121 --  access the facilities of this package without synchronization that
122 --  serializes access.
123
124 with System;
125 with GNAT.OS_Lib;
126 with GNAT.Regpat;
127
128 package GNAT.Expect is
129
130    type Process_Id is new Integer;
131    Invalid_Pid : constant Process_Id := -1;
132    Null_Pid    : constant Process_Id := 0;
133
134    type Filter_Type is (Output, Input, Died);
135    --  The signals that are emitted by the Process_Descriptor upon state change
136    --  in the child. One can connect to any of these signals through the
137    --  Add_Filter subprograms.
138    --
139    --     Output => Every time new characters are read from the process
140    --               associated with Descriptor, the filter is called with
141    --               these new characters in the argument.
142    --
143    --               Note that output is generated only when the program is
144    --               blocked in a call to Expect.
145    --
146    --     Input  => Every time new characters are written to the process
147    --               associated with Descriptor, the filter is called with
148    --               these new characters in the argument.
149    --               Note that input is generated only by calls to Send.
150    --
151    --     Died   => The child process has died, or was explicitly killed
152
153    type Process_Descriptor is tagged private;
154    --  Contains all the components needed to describe a process handled
155    --  in this package, including a process identifier, file descriptors
156    --  associated with the standard input, output and error, and the buffer
157    --  needed to handle the expect calls.
158
159    type Process_Descriptor_Access is access Process_Descriptor'Class;
160
161    ------------------------
162    -- Spawning a process --
163    ------------------------
164
165    procedure Non_Blocking_Spawn
166      (Descriptor  : out Process_Descriptor'Class;
167       Command     : String;
168       Args        : GNAT.OS_Lib.Argument_List;
169       Buffer_Size : Natural := 4096;
170       Err_To_Out  : Boolean := False);
171    --  This call spawns a new process and allows sending commands to
172    --  the process and/or automatic parsing of the output.
173    --
174    --  The expect buffer associated with that process can contain at most
175    --  Buffer_Size characters. Older characters are simply discarded when this
176    --  buffer is full. Beware that if the buffer is too big, this could slow
177    --  down the Expect calls if the output not is matched, since Expect has to
178    --  match all the regexp against all the characters in the buffer. If
179    --  Buffer_Size is 0, there is no limit (i.e. all the characters are kept
180    --  till Expect matches), but this is slower.
181    --
182    --  If Err_To_Out is True, then the standard error of the spawned process is
183    --  connected to the standard output. This is the only way to get the Except
184    --  subprograms to also match on output on standard error.
185    --
186    --  Invalid_Process is raised if the process could not be spawned.
187
188    procedure Close (Descriptor : in out Process_Descriptor);
189    --  Terminate the process and close the pipes to it. It implicitly does the
190    --  'wait' command required to clean up the process table. This also frees
191    --  the buffer associated with the process id. Raise Invalid_Process if the
192    --  process id is invalid.
193
194    procedure Close
195      (Descriptor : in out Process_Descriptor;
196       Status     : out Integer);
197    --  Same as above, but also returns the exit status of the process, as set
198    --  for example by the procedure GNAT.OS_Lib.OS_Exit.
199
200    procedure Send_Signal
201      (Descriptor : Process_Descriptor;
202       Signal     : Integer);
203    --  Send a given signal to the process. Raise Invalid_Process if the process
204    --  id is invalid.
205
206    procedure Interrupt (Descriptor : in out Process_Descriptor);
207    --  Interrupt the process (the equivalent of Ctrl-C on unix and windows)
208    --  and call close if the process dies.
209
210    function Get_Input_Fd
211      (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor;
212    --  Return the input file descriptor associated with Descriptor
213
214    function Get_Output_Fd
215      (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor;
216    --  Return the output file descriptor associated with Descriptor
217
218    function Get_Error_Fd
219      (Descriptor : Process_Descriptor) return GNAT.OS_Lib.File_Descriptor;
220    --  Return the error output file descriptor associated with Descriptor
221
222    function Get_Pid
223      (Descriptor : Process_Descriptor) return Process_Id;
224    --  Return the process id associated with a given process descriptor
225
226    function Get_Command_Output
227      (Command    : String;
228       Arguments  : GNAT.OS_Lib.Argument_List;
229       Input      : String;
230       Status     : not null access Integer;
231       Err_To_Out : Boolean := False) return String;
232    --  Execute Command with the specified Arguments and Input, and return the
233    --  generated standard output data as a single string. If Err_To_Out is
234    --  True, generated standard error output is included as well. On return,
235    --  Status is set to the command's exit status.
236
237    --------------------
238    -- Adding filters --
239    --------------------
240
241    --  This is a rather low-level interface to subprocesses, since basically
242    --  the filtering is left entirely to the user. See the Expect subprograms
243    --  below for higher level functions.
244
245    type Filter_Function is access
246      procedure
247        (Descriptor : Process_Descriptor'Class;
248         Str        : String;
249         User_Data  : System.Address := System.Null_Address);
250    --  Function called every time new characters are read from or written to
251    --  the process.
252    --
253    --  Str is a string of all these characters.
254    --
255    --  User_Data, if specified, is user specific data that will be passed to
256    --  the filter. Note that no checks are done on this parameter, so it should
257    --  be used with caution.
258
259    procedure Add_Filter
260      (Descriptor : in out Process_Descriptor;
261       Filter     : Filter_Function;
262       Filter_On  : Filter_Type := Output;
263       User_Data  : System.Address := System.Null_Address;
264       After      : Boolean := False);
265    --  Add a new filter for one of the filter types. This filter will be run
266    --  before all the existing filters, unless After is set True, in which case
267    --  it will be run after existing filters. User_Data is passed as is to the
268    --  filter procedure.
269
270    procedure Remove_Filter
271      (Descriptor : in out Process_Descriptor;
272       Filter     : Filter_Function);
273    --  Remove a filter from the list of filters (whatever the type of the
274    --  filter).
275
276    procedure Trace_Filter
277      (Descriptor : Process_Descriptor'Class;
278       Str        : String;
279       User_Data  : System.Address := System.Null_Address);
280    --  Function that can be used as a filter and that simply outputs Str on
281    --  Standard_Output. This is mainly used for debugging purposes.
282    --  User_Data is ignored.
283
284    procedure Lock_Filters (Descriptor : in out Process_Descriptor);
285    --  Temporarily disables all output and input filters. They will be
286    --  reactivated only when Unlock_Filters has been called as many times as
287    --  Lock_Filters.
288
289    procedure Unlock_Filters (Descriptor : in out Process_Descriptor);
290    --  Unlocks the filters. They are reactivated only if Unlock_Filters
291    --  has been called as many times as Lock_Filters.
292
293    ------------------
294    -- Sending data --
295    ------------------
296
297    procedure Send
298      (Descriptor   : in out Process_Descriptor;
299       Str          : String;
300       Add_LF       : Boolean := True;
301       Empty_Buffer : Boolean := False);
302    --  Send a string to the file descriptor.
303    --
304    --  The string is not formatted in any way, except if Add_LF is True, in
305    --  which case an ASCII.LF is added at the end, so that Str is recognized
306    --  as a command by the external process.
307    --
308    --  If Empty_Buffer is True, any input waiting from the process (or in the
309    --  buffer) is first discarded before the command is sent. The output
310    --  filters are of course called as usual.
311
312    -----------------------------------------------------------
313    -- Working on the output (single process, simple regexp) --
314    -----------------------------------------------------------
315
316    type Expect_Match is new Integer;
317    Expect_Full_Buffer : constant Expect_Match := -1;
318    --  If the buffer was full and some characters were discarded
319
320    Expect_Timeout : constant Expect_Match := -2;
321    --  If no output matching the regexps was found before the timeout
322
323    function "+" (S : String) return GNAT.OS_Lib.String_Access;
324    --  Allocate some memory for the string. This is merely a convenience
325    --  function to help create the array of regexps in the call to Expect.
326
327    procedure Expect
328      (Descriptor  : in out Process_Descriptor;
329       Result      : out Expect_Match;
330       Regexp      : String;
331       Timeout     : Integer := 10_000;
332       Full_Buffer : Boolean := False);
333    --  Wait till a string matching Fd can be read from Fd, and return 1 if a
334    --  match was found.
335    --
336    --  It consumes all the characters read from Fd until a match found, and
337    --  then sets the return values for the subprograms Expect_Out and
338    --  Expect_Out_Match.
339    --
340    --  The empty string "" will never match, and can be used if you only want
341    --  to match after a specific timeout. Beware that if Timeout is -1 at the
342    --  time, the current task will be blocked forever.
343    --
344    --  This command times out after Timeout milliseconds (or never if Timeout
345    --  is -1). In that case, Expect_Timeout is returned. The value returned by
346    --  Expect_Out and Expect_Out_Match are meaningless in that case.
347    --
348    --  Note that using a timeout of 0ms leads to unpredictable behavior, since
349    --  the result depends on whether the process has already sent some output
350    --  the first time Expect checks, and this depends on the operating system.
351    --
352    --  The regular expression must obey the syntax described in GNAT.Regpat.
353    --
354    --  If Full_Buffer is True, then Expect will match if the buffer was too
355    --  small and some characters were about to be discarded. In that case,
356    --  Expect_Full_Buffer is returned.
357
358    procedure Expect
359      (Descriptor  : in out Process_Descriptor;
360       Result      : out Expect_Match;
361       Regexp      : GNAT.Regpat.Pattern_Matcher;
362       Timeout     : Integer := 10_000;
363       Full_Buffer : Boolean := False);
364    --  Same as the previous one, but with a precompiled regular expression.
365    --  This is more efficient however, especially if you are using this
366    --  expression multiple times, since this package won't need to recompile
367    --  the regexp every time.
368
369    procedure Expect
370      (Descriptor  : in out Process_Descriptor;
371       Result      : out Expect_Match;
372       Regexp      : String;
373       Matched     : out GNAT.Regpat.Match_Array;
374       Timeout     : Integer := 10_000;
375       Full_Buffer : Boolean := False);
376    --  Same as above, but it is now possible to get the indexes of the
377    --  substrings for the parentheses in the regexp (see the example at the
378    --  top of this package, as well as the documentation in the package
379    --  GNAT.Regpat).
380    --
381    --  Matched'First should be 0, and this index will contain the indexes for
382    --  the whole string that was matched. The index 1 will contain the indexes
383    --  for the first parentheses-pair, and so on.
384
385    ------------
386    -- Expect --
387    ------------
388
389    procedure Expect
390      (Descriptor  : in out Process_Descriptor;
391       Result      : out Expect_Match;
392       Regexp      : GNAT.Regpat.Pattern_Matcher;
393       Matched     : out GNAT.Regpat.Match_Array;
394       Timeout     : Integer := 10_000;
395       Full_Buffer : Boolean := False);
396    --  Same as above, but with a precompiled regular expression
397
398    -------------------------------------------------------------
399    -- Working on the output (single process, multiple regexp) --
400    -------------------------------------------------------------
401
402    type Regexp_Array is array (Positive range <>) of GNAT.OS_Lib.String_Access;
403
404    type Pattern_Matcher_Access is access all GNAT.Regpat.Pattern_Matcher;
405    type Compiled_Regexp_Array is
406      array (Positive range <>) of Pattern_Matcher_Access;
407
408    function "+"
409      (P : GNAT.Regpat.Pattern_Matcher) return Pattern_Matcher_Access;
410    --  Allocate some memory for the pattern matcher. This is only a convenience
411    --  function to help create the array of compiled regular expressions.
412
413    procedure Expect
414      (Descriptor  : in out Process_Descriptor;
415       Result      : out Expect_Match;
416       Regexps     : Regexp_Array;
417       Timeout     : Integer := 10_000;
418       Full_Buffer : Boolean := False);
419    --  Wait till a string matching one of the regular expressions in Regexps
420    --  is found. This function returns the index of the regexp that matched.
421    --  This command is blocking, but will timeout after Timeout milliseconds.
422    --  In that case, Timeout is returned.
423
424    procedure Expect
425      (Descriptor  : in out Process_Descriptor;
426       Result      : out Expect_Match;
427       Regexps     : Compiled_Regexp_Array;
428       Timeout     : Integer := 10_000;
429       Full_Buffer : Boolean := False);
430    --  Same as the previous one, but with precompiled regular expressions.
431    --  This can be much faster if you are using them multiple times.
432
433    procedure Expect
434      (Descriptor  : in out Process_Descriptor;
435       Result      : out Expect_Match;
436       Regexps     : Regexp_Array;
437       Matched     : out GNAT.Regpat.Match_Array;
438       Timeout     : Integer := 10_000;
439       Full_Buffer : Boolean := False);
440    --  Same as above, except that you can also access the parenthesis
441    --  groups inside the matching regular expression.
442    --
443    --  The first index in Matched must be 0, or Constraint_Error will be
444    --  raised. The index 0 contains the indexes for the whole string that was
445    --  matched, the index 1 contains the indexes for the first parentheses
446    --  pair, and so on.
447
448    procedure Expect
449      (Descriptor  : in out Process_Descriptor;
450       Result      : out Expect_Match;
451       Regexps     : Compiled_Regexp_Array;
452       Matched     : out GNAT.Regpat.Match_Array;
453       Timeout     : Integer := 10_000;
454       Full_Buffer : Boolean := False);
455    --  Same as above, but with precompiled regular expressions. The first index
456    --  in Matched must be 0, or Constraint_Error will be raised.
457
458    -------------------------------------------
459    -- Working on the output (multi-process) --
460    -------------------------------------------
461
462    type Multiprocess_Regexp is record
463       Descriptor : Process_Descriptor_Access;
464       Regexp     : Pattern_Matcher_Access;
465    end record;
466
467    type Multiprocess_Regexp_Array is
468      array (Positive range <>) of Multiprocess_Regexp;
469
470    procedure Free (Regexp : in out Multiprocess_Regexp);
471    --  Free the memory occupied by Regexp
472
473    function Has_Process (Regexp : Multiprocess_Regexp_Array) return Boolean;
474    --  Return True if at least one entry in Regexp is non-null, ie there is
475    --  still at least one process to monitor
476
477    function First_Dead_Process
478      (Regexp : Multiprocess_Regexp_Array) return Natural;
479    --  Find the first entry in Regexp that corresponds to a dead process that
480    --  wasn't Free-d yet. This function is called in general when Expect
481    --  (below) raises the exception Process_Died. This returns 0 if no process
482    --  has died yet.
483
484    procedure Expect
485      (Result      : out Expect_Match;
486       Regexps     : Multiprocess_Regexp_Array;
487       Matched     : out GNAT.Regpat.Match_Array;
488       Timeout     : Integer := 10_000;
489       Full_Buffer : Boolean := False);
490    --  Same as above, but for multi processes. Any of the entries in
491    --  Regexps can have a null Descriptor or Regexp. Such entries will
492    --  simply be ignored. Therefore when a process terminates, you can
493    --  simply reset its entry.
494    --
495    --  The expect loop would therefore look like:
496    --
497    --     Processes : Multiprocess_Regexp_Array (...) := ...;
498    --     R         : Natural;
499    --
500    --     while Has_Process (Processes) loop
501    --        begin
502    --           Expect (Result, Processes, Timeout => -1);
503    --           ... process output of process Result (output, full buffer,...)
504    --
505    --        exception
506    --           when Process_Died =>
507    --               --  Free memory
508    --               R := First_Dead_Process (Processes);
509    --               Close (Processes (R).Descriptor.all, Status);
510    --               Free (Processes (R));
511    --        end;
512    --     end loop;
513
514    procedure Expect
515      (Result      : out Expect_Match;
516       Regexps     : Multiprocess_Regexp_Array;
517       Timeout     : Integer := 10_000;
518       Full_Buffer : Boolean := False);
519    --  Same as the previous one, but for multiple processes. This procedure
520    --  finds the first regexp that match the associated process.
521
522    ------------------------
523    -- Getting the output --
524    ------------------------
525
526    procedure Flush
527      (Descriptor : in out Process_Descriptor;
528       Timeout    : Integer := 0);
529    --  Discard all output waiting from the process.
530    --
531    --  This output is simply discarded, and no filter is called. This output
532    --  will also not be visible by the next call to Expect, nor will any output
533    --  currently buffered.
534    --
535    --  Timeout is the delay for which we wait for output to be available from
536    --  the process. If 0, we only get what is immediately available.
537
538    function Expect_Out (Descriptor : Process_Descriptor) return String;
539    --  Return the string matched by the last Expect call.
540    --
541    --  The returned string is in fact the concatenation of all the strings read
542    --  from the file descriptor up to, and including, the characters that
543    --  matched the regular expression.
544    --
545    --  For instance, with an input "philosophic", and a regular expression "hi"
546    --  in the call to expect, the strings returned the first and second time
547    --  would be respectively "phi" and "losophi".
548
549    function Expect_Out_Match (Descriptor : Process_Descriptor) return String;
550    --  Return the string matched by the last Expect call.
551    --
552    --  The returned string includes only the character that matched the
553    --  specific regular expression. All the characters that came before are
554    --  simply discarded.
555    --
556    --  For instance, with an input "philosophic", and a regular expression
557    --  "hi" in the call to expect, the strings returned the first and second
558    --  time would both be "hi".
559
560    ----------------
561    -- Exceptions --
562    ----------------
563
564    Invalid_Process : exception;
565    --  Raised by most subprograms above when the parameter Descriptor is not a
566    --  valid process or is a closed process.
567
568    Process_Died : exception;
569    --  Raised by all the expect subprograms if Descriptor was originally a
570    --  valid process that died while Expect was executing. It is also raised
571    --  when Expect receives an end-of-file.
572
573 private
574    type Filter_List_Elem;
575    type Filter_List is access Filter_List_Elem;
576    type Filter_List_Elem is record
577       Filter    : Filter_Function;
578       User_Data : System.Address;
579       Filter_On : Filter_Type;
580       Next      : Filter_List;
581    end record;
582
583    type Pipe_Type is record
584       Input, Output : GNAT.OS_Lib.File_Descriptor;
585    end record;
586    --  This type represents a pipe, used to communicate between two processes
587
588    procedure Set_Up_Communications
589      (Pid        : in out Process_Descriptor;
590       Err_To_Out : Boolean;
591       Pipe1      : not null access Pipe_Type;
592       Pipe2      : not null access Pipe_Type;
593       Pipe3      : not null access Pipe_Type);
594    --  Set up all the communication pipes and file descriptors prior to
595    --  spawning the child process.
596
597    procedure Set_Up_Parent_Communications
598      (Pid   : in out Process_Descriptor;
599       Pipe1 : in out Pipe_Type;
600       Pipe2 : in out Pipe_Type;
601       Pipe3 : in out Pipe_Type);
602    --  Finish the set up of the pipes while in the parent process
603
604    procedure Set_Up_Child_Communications
605      (Pid   : in out Process_Descriptor;
606       Pipe1 : in out Pipe_Type;
607       Pipe2 : in out Pipe_Type;
608       Pipe3 : in out Pipe_Type;
609       Cmd   : String;
610       Args  : System.Address);
611    --  Finish the set up of the pipes while in the child process This also
612    --  spawns the child process (based on Cmd). On systems that support fork,
613    --  this procedure is executed inside the newly created process.
614
615    type Process_Descriptor is tagged record
616       Pid              : aliased Process_Id := Invalid_Pid;
617       Input_Fd         : GNAT.OS_Lib.File_Descriptor := GNAT.OS_Lib.Invalid_FD;
618       Output_Fd        : GNAT.OS_Lib.File_Descriptor := GNAT.OS_Lib.Invalid_FD;
619       Error_Fd         : GNAT.OS_Lib.File_Descriptor := GNAT.OS_Lib.Invalid_FD;
620       Filters_Lock     : Integer := 0;
621
622       Filters          : Filter_List := null;
623
624       Buffer           : GNAT.OS_Lib.String_Access := null;
625       Buffer_Size      : Natural := 0;
626       Buffer_Index     : Natural := 0;
627
628       Last_Match_Start : Natural := 0;
629       Last_Match_End   : Natural := 0;
630    end record;
631
632    --  The following subprogram is provided for use in the body, and also
633    --  possibly in future child units providing extensions to this package.
634
635    procedure Portable_Execvp
636      (Pid  : not null access Process_Id;
637       Cmd  : String;
638       Args : System.Address);
639    pragma Import (C, Portable_Execvp, "__gnat_expect_portable_execvp");
640    --  Executes, in a portable way, the command Cmd (full path must be
641    --  specified), with the given Args, which must be an array of string
642    --  pointers. Note that the first element in Args must be the executable
643    --  name, and the last element must be a null pointer. The returned value
644    --  in Pid is the process ID, or zero if not supported on the platform.
645
646 end GNAT.Expect;