OSDN Git Service

2004-04-19 Arnaud Charlet <charlet@act-europe.fr>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-util.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              P R J . U T I L                             --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --             Copyright (C) 2001-2004 Free Software Foundation, Inc.       --
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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  Utilities for use in processing project files
28
29 with Types; use Types;
30
31 with GNAT.OS_Lib; use GNAT.OS_Lib;
32
33 package Prj.Util is
34
35    function Executable_Of
36      (Project  : Project_Id;
37       Main     : Name_Id;
38       Ada_Main : Boolean := True) return Name_Id;
39    --  Return the value of the attribute Builder'Executable for file Main in
40    --  the project Project, if it exists. If there is no attribute Executable
41    --  for Main, remove the suffix from Main; then, if the attribute
42    --  Executable_Suffix is specified, add this suffix, otherwise add the
43    --  standard executable suffix for the platform.
44
45    function Value_Of
46      (Variable : Variable_Value;
47       Default  : String) return String;
48    --  Get the value of a single string variable. If Variable is
49    --  Nil_Variable_Value, is a string list or is defaulted, return Default.
50
51    function Value_Of
52      (Index    : Name_Id;
53       In_Array : Array_Element_Id) return Name_Id;
54    --  Get a single string array component. Returns No_Name if there is no
55    --  component Index, if In_Array is null, or if the component is a String
56    --  list. Depending on the attribute (only attributes may be associative
57    --  arrays) the index may or may not be case sensitive. If the index is not
58    --  case sensitive, it is first set to lower case before the search in the
59    --  associative array.
60
61    function Value_Of
62      (Index    : Name_Id;
63       In_Array : Array_Element_Id) return Variable_Value;
64    --  Get a string array component (single String or String list).
65    --  Returns Nil_Variable_Value if there is no component Index
66    --  or if In_Array is null.
67    --
68    --  Depending on the attribute (only attributes may be associative arrays)
69    --  the index may or may not be case sensitive. If the index is not
70    --  case sensitive, it is first set to lower case before the search
71    --  in the associative array.
72
73    function Value_Of
74      (Name                    : Name_Id;
75       Attribute_Or_Array_Name : Name_Id;
76       In_Package              : Package_Id) return Variable_Value;
77    --  In a specific package,
78    --   - if there exists an array Attribute_Or_Array_Name with an index
79    --     Name, returns the corresponding component (depending on the
80    --     attribute, the index may or may not be case sensitive, see previous
81    --     function),
82    --   - otherwise if there is a single attribute Attribute_Or_Array_Name,
83    --     returns this attribute,
84    --   - otherwise, returns Nil_Variable_Value.
85    --  If In_Package is null, returns Nil_Variable_Value.
86
87    function Value_Of
88      (Index     : Name_Id;
89       In_Array  : Name_Id;
90       In_Arrays : Array_Id) return Name_Id;
91    --  Get a string array component in an array of an array list.
92    --  Returns No_Name if there is no component Index, if In_Arrays is null, if
93    --  In_Array is not found in In_Arrays or if the component is a String list.
94
95    function Value_Of
96      (Name      : Name_Id;
97       In_Arrays : Array_Id) return Array_Element_Id;
98    --  Returns a specified array in an array list. Returns No_Array_Element
99    --  if In_Arrays is null or if Name is not the name of an array in
100    --  In_Arrays. The caller must ensure that Name is in lower case.
101
102    function Value_Of
103      (Name        : Name_Id;
104       In_Packages : Package_Id) return Package_Id;
105    --  Returns a specified package in a package list. Returns No_Package
106    --  if In_Packages is null or if Name is not the name of a package in
107    --  Package_List. The caller must ensure that Name is in lower case.
108
109    function Value_Of
110      (Variable_Name : Name_Id;
111       In_Variables  : Variable_Id) return Variable_Value;
112    --  Returns a specified variable in a variable list. Returns null if
113    --  In_Variables is null or if Variable_Name is not the name of a
114    --  variable in In_Variables. Caller must ensure that Name is lower case.
115
116    procedure Write_Str
117      (S          : String;
118       Max_Length : Positive;
119       Separator  : Character);
120    --  Output string S using Output.Write_Str. If S is too long to fit in
121    --  one line of Max_Length, cut it in several lines, using Separator as
122    --  the last character of each line, if possible.
123
124    type Text_File is limited private;
125    --  Represents a text file. Default is invalid text file.
126
127    function Is_Valid (File : Text_File) return Boolean;
128    --  Returns True if File designates an open text file that
129    --  has not yet been closed.
130
131    procedure Open (File : out Text_File; Name : String);
132    --  Open a text file. If this procedure fails, File is invalid.
133
134    function End_Of_File (File : Text_File) return Boolean;
135    --  Returns True if the end of the text file File has been
136    --  reached. Fails if File is invalid.
137
138    procedure Get_Line
139      (File : Text_File;
140       Line : out String;
141       Last : out Natural);
142    --  Reads a line from an open text file. Fails if File is invalid.
143
144    procedure Close (File : in out Text_File);
145    --  Close an open text file. File becomes invalid.
146    --  Fails if File is already invalid.
147
148 private
149
150    type Text_File_Data is record
151       FD                  : File_Descriptor := Invalid_FD;
152       Buffer              : String (1 .. 1_000);
153       Buffer_Len          : Natural;
154       Cursor              : Natural := 0;
155       End_Of_File_Reached : Boolean := False;
156    end record;
157
158    type Text_File is access Text_File_Data;
159
160 end Prj.Util;