home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / s-ficobl.ads < prev    next >
Text File  |  2000-07-19  |  8KB  |  158 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUN-TIME COMPONENTS                         --
  4. --                                                                          --
  5. --              S Y S T E M . F I L E _ C O N T R O L _ B L O C K           --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.8 $                              --
  10. --                                                                          --
  11. --            Copyright (C) 1992-1999 Free Software Foundation, Inc.        --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. --  This package contains the declaration of the basic file control block
  37. --  shared between Text_IO, Sequential_IO, Direct_IO and Streams.Stream_IO.
  38. --  The actual control blocks are derived from this block by extension. The
  39. --  control block is itself derived from Ada.Streams.Root_Stream_Type which
  40. --  facilitates implementation of Stream_IO.Stream and Text_Streams.Stream.
  41.  
  42. with Ada.Streams;
  43. with Interfaces.C_Streams;
  44.  
  45. package System.File_Control_Block is
  46.  
  47.    -----------------------------
  48.    --  Ada File Control Block --
  49.    -----------------------------
  50.  
  51.    --  The Ada file control block is an abstract extension of the root
  52.    --  stream type. This allows a file to be treated directly as a stream
  53.    --  for the purposes of Stream_IO, or stream operations on a text file.
  54.    --  The individual I/O packages extend this type with package specific
  55.    --  fields to create the concrete types to which the routines in this
  56.    --  package can be applied.
  57.  
  58.    --  The type File_Type in the individual packages is an access to the
  59.    --  extended file control block. The value is null if the file is not
  60.    --  open, and a pointer to the control block if the file is open.
  61.  
  62.    type Pstring is access all String;
  63.    --  Used to hold name and form strings
  64.  
  65.    type File_Mode is (In_File, Inout_File, Out_File, Append_File);
  66.    --  File mode (union of file modes permitted by individual packages,
  67.    --  the types File_Mode in the individual packages are declared to
  68.    --  allow easy conversion to and from this general type.
  69.  
  70.    type Shared_Status_Type is (Yes, No, None);
  71.    --  This type is used to define the sharing status of a file. The default
  72.    --  setting of None is used if no "shared=xxx" appears in the form string
  73.    --  when a file is created or opened. For a file with Shared_Status set to
  74.    --  None, Use_Error will be raised if any other file is opened or created
  75.    --  with the same full name. Yes/No are set in response to the presence
  76.    --  of "shared=yes" or "shared=no" in the form string. In either case it
  77.    --  is permissible to have multiple files opened with the same full name.
  78.    --  All files opened simultaneously with "shared=yes" will share the same
  79.    --  stream with the semantics specified in the RM for file sharing. All
  80.    --  files opened with "shared=no" will have their own stream.
  81.  
  82.    type AFCB;
  83.    type AFCB_Ptr is access all AFCB'Class;
  84.  
  85.    type AFCB is abstract new Ada.Streams.Root_Stream_Type with record
  86.  
  87.       Stream : Interfaces.C_Streams.FILEs;
  88.       --  The file descriptor
  89.  
  90.       Name : Pstring;
  91.       --  A pointer to the file name. The file name is null for temporary
  92.       --  files, and also for standard files (stdin, stdout, stderr). The
  93.       --  name is always null-terminated if it is non-null.
  94.  
  95.       Form : Pstring;
  96.       --  A pointer to the form string. This is the string used in the
  97.       --  fopen call, and must be supplied by the caller (there are no
  98.       --  defaults at this level). The string is always null-terminated.
  99.  
  100.       Mode : File_Mode;
  101.       --  The file mode. No checks are made that the mode is consistent
  102.       --  with the form used to fopen the file.
  103.  
  104.       Is_Regular_File : Boolean;
  105.       --  A flag indicating if the file is a regular file
  106.  
  107.       Is_Temporary_File : Boolean;
  108.       --  A flag set only for temporary files (i.e. files created using the
  109.       --  Create function with a null name parameter, using tmpfile).
  110.  
  111.       Is_System_File : Boolean;
  112.       --  A flag set only for system files (stdin, stdout, stderr)
  113.  
  114.       Is_Text_File : Boolean;
  115.       --  A flag set if the file was opened in text mode
  116.  
  117.       Shared_Status : Shared_Status_Type;
  118.       --  Indicates sharing status of file, see description of type above
  119.  
  120.       Access_Method : Character;
  121.       --  Set to 'Q', 'S', 'T, 'D' for Sequential_IO, Stream_IO, Text_IO
  122.       --  Direct_IO file (used to validate file sharing request).
  123.  
  124.       Next : AFCB_Ptr;
  125.       Prev : AFCB_Ptr;
  126.       --  All open files are kept on a doubly linked chain, with these
  127.       --  pointers used to maintain the next and previous pointers.
  128.  
  129.    end record;
  130.  
  131.    ----------------------------------
  132.    -- Primitive Operations of AFCB --
  133.    ----------------------------------
  134.  
  135.    --  Note that we inherit the abstract operations Read and Write from
  136.    --  the base type. These must be overridden by the individual file
  137.    --  access methods to provide Stream Read/Write access.
  138.  
  139.    function AFCB_Allocate (Control_Block : AFCB) return AFCB_Ptr is abstract;
  140.    --  Given a control block, allocate space for a control block of the same
  141.    --  type on the heap, and return the pointer to this allocated block. Note
  142.    --  that the argument Control_Block is not used other than as the argument
  143.    --  that controls which version of AFCB_Allocate is called.
  144.  
  145.    procedure AFCB_Close (File : access AFCB) is abstract;
  146.    --  Performs any specialized close actions on a file before the file is
  147.    --  actually closed at the system level. This is called by Close, and
  148.    --  the reason we need the primitive operation is for the automatic
  149.    --  close operations done as part of finalization.
  150.  
  151.    procedure AFCB_Free (File : access AFCB) is abstract;
  152.    --  Frees the AFCB referenced by the given parameter. It is not necessary
  153.    --  to free the strings referenced by the Form and Name fields, but if the
  154.    --  extension has any other heap objects, they must be freed as well. This
  155.    --  procedure must be overridden by each individual file package.
  156.  
  157. end System.File_Control_Block;
  158.