OSDN Git Service

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