OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj-ext.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              P R J . E X T                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                                                                          --
10 --             Copyright (C) 2000 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 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 with GNAT.HTable;
29 with GNAT.OS_Lib; use GNAT.OS_Lib;
30 with Namet;       use Namet;
31 with Prj.Com;     use Prj.Com;
32 with Stringt;     use Stringt;
33 with Types;       use Types;
34
35 package body Prj.Ext is
36
37    package Htable is new GNAT.HTable.Simple_HTable
38      (Header_Num => Header_Num,
39       Element    => String_Id,
40       No_Element => No_String,
41       Key        => Name_Id,
42       Hash       => Hash,
43       Equal      => "=");
44
45    ---------
46    -- Add --
47    ---------
48
49    procedure Add
50      (External_Name : String;
51       Value         : String)
52    is
53       The_Key   : Name_Id;
54       The_Value : String_Id;
55
56    begin
57       Start_String;
58       Store_String_Chars (Value);
59       The_Value := End_String;
60       Name_Len := External_Name'Length;
61       Name_Buffer (1 .. Name_Len) := External_Name;
62       The_Key := Name_Find;
63       Htable.Set (The_Key, The_Value);
64    end Add;
65
66    -----------
67    -- Check --
68    -----------
69
70    function Check (Declaration : String) return Boolean is
71    begin
72       for Equal_Pos in Declaration'Range loop
73
74          if Declaration (Equal_Pos) = '=' then
75             exit when Equal_Pos = Declaration'First;
76             exit when Equal_Pos = Declaration'Last;
77             Add
78               (External_Name =>
79                  Declaration (Declaration'First .. Equal_Pos - 1),
80                Value =>
81                  Declaration (Equal_Pos + 1 .. Declaration'Last));
82             return True;
83          end if;
84
85       end loop;
86
87       return False;
88    end Check;
89
90    --------------
91    -- Value_Of --
92    --------------
93
94    function Value_Of
95      (External_Name : Name_Id;
96       With_Default  : String_Id := No_String)
97       return          String_Id
98    is
99       The_Value : String_Id;
100
101    begin
102       The_Value := Htable.Get (External_Name);
103
104       if The_Value /= No_String then
105          return The_Value;
106       end if;
107
108       --  Find if it is an environment.
109       --  If it is, put the value in the hash table.
110
111       declare
112          Env_Value : constant String_Access :=
113            Getenv (Get_Name_String (External_Name));
114
115       begin
116          if Env_Value /= null and then Env_Value'Length > 0 then
117             Start_String;
118             Store_String_Chars (Env_Value.all);
119             The_Value := End_String;
120             Htable.Set (External_Name, The_Value);
121             return The_Value;
122
123          else
124             return With_Default;
125          end if;
126       end;
127    end Value_Of;
128
129 end Prj.Ext;