OSDN Git Service

Nathanael Nerode <neroden@gcc.gnu.org>
[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 --                                                                          --
10 --             Copyright (C) 2001 Free Software Foundation, Inc.            --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27 --
28 --  Utilities when using project files.
29
30 with GNAT.OS_Lib; use GNAT.OS_Lib;
31 with Types;       use Types;
32
33 package Prj.Util is
34
35    function Value_Of
36      (Variable : Variable_Value;
37       Default  : String)
38       return     String;
39    --  Get the value of a single string variable. If Variable is
40    --  Nil_Variable_Value, is a string list or is defaulted, return Default.
41
42    function Value_Of
43      (Index    : Name_Id;
44       In_Array : Array_Element_Id)
45       return     Name_Id;
46    --  Get a single string array component.
47    --  Returns No_Name if there is no component Index (case sensitive),
48    --  if In_Array is null, or if the component is a String list.
49
50    function Value_Of
51      (Index    : Name_Id;
52       In_Array : Array_Element_Id)
53       return     Variable_Value;
54    --  Get a string array component (single String or String list).
55    --  Returns Nil_Variable_Value if there is no component Index
56    --  (case sensitive), or if In_Array is null.
57
58    function Value_Of
59      (Name                    : Name_Id;
60       Attribute_Or_Array_Name : Name_Id;
61       In_Package              : Package_Id)
62       return                    Variable_Value;
63    --  In a specific package,
64    --   - if there exists an array Variable_Or_Array_Name with an index
65    --     Name, returns the corresponding component,
66    --   - otherwise if there is a attribute Attribute_Or_Array_Name,
67    --     returns this attribute,
68    --   - otherwise, returns Nil_Variable_Value.
69    --  If In_Package is null, returns Nil_Variable_Value.
70
71    function Value_Of
72      (Index     : Name_Id;
73       In_Array  : Name_Id;
74       In_Arrays : Array_Id)
75       return      Name_Id;
76    --  Get a string array component in an array of an array list.
77    --  Returns No_Name if there is no component Index (case sensitive),
78    --  if In_Arrays is null, if In_Array is not found in In_Arrays,
79    --  or if the component is a String list.
80
81    function Value_Of
82      (Name      : Name_Id;
83       In_Arrays : Array_Id)
84       return      Array_Element_Id;
85    --  Returns a specified array in an array list. Returns No_Array_Element
86    --  if In_Arrays is null or if Name is not the name of an array in
87    --  In_Arrays. The caller must ensure that Name is in lower case.
88
89    function Value_Of
90      (Name        : Name_Id;
91       In_Packages : Package_Id)
92       return        Package_Id;
93    --  Returns a specified package in a package list. Returns No_Package
94    --  if In_Packages is null or if Name is not the name of a package in
95    --  Package_List. The caller must ensure that Name is in lower case.
96
97    function Value_Of
98      (Variable_Name : Name_Id;
99       In_Variables  : Variable_Id)
100       return          Variable_Value;
101    --  Returns a specified variable in a variable list. Returns null if
102    --  In_Variables is null or if Variable_Name is not the name of a
103    --  variable in In_Variables. Caller must ensure that Name is lower case.
104
105    procedure Write_Str
106      (S          : String;
107       Max_Length : Positive;
108       Separator  : Character);
109    --  Output string S using Output.Write_Str. If S is too long to fit in
110    --  one line of Max_Length, cut it in several lines, using Separator as
111    --  the last character of each line, if possible.
112
113    type Text_File is limited private;
114    --  Represents a text file. Default is invalid text file.
115
116    function Is_Valid (File : Text_File) return Boolean;
117    --  Returns True if File designates an open text file that
118    --  has not yet been closed.
119
120    procedure Open (File : out Text_File; Name : String);
121    --  Open a text file. If this procedure fails, File is invalid.
122
123    function End_Of_File (File : Text_File) return Boolean;
124    --  Returns True if the end of the text file File has been
125    --  reached. Fails if File is invalid.
126
127    procedure Get_Line
128      (File : Text_File;
129       Line : out String;
130       Last : out Natural);
131    --  Reads a line from an open text file. Fails if File is invalid.
132
133    procedure Close (File : in out Text_File);
134    --  Close an open text file. File becomes invalid.
135    --  Fails if File is already invalid.
136
137 private
138
139    type Text_File_Data is record
140       FD                  : File_Descriptor := Invalid_FD;
141       Buffer              : String (1 .. 1_000);
142       Buffer_Len          : Natural;
143       Cursor              : Natural := 0;
144       End_Of_File_Reached : Boolean := False;
145    end record;
146
147    type Text_File is access Text_File_Data;
148
149 end Prj.Util;