1
-------------------------------------------------------------------------------
3
-- This file is part of AdaBrowse.
5
-- <STRONG>Copyright (c) 2002 by Thomas Wolf.</STRONG>
7
-- AdaBrowse is free software; you can redistribute it and/or modify it
8
-- under the terms of the GNU General Public License as published by the
9
-- Free Software Foundation; either version 2, or (at your option) any
10
-- later version. AdaBrowse is distributed in the hope that it will be
11
-- useful, but <EM>without any warranty</EM>; without even the implied
12
-- warranty of <EM>merchantability or fitness for a particular purpose.</EM>
13
-- See the GNU General Public License for more details. You should have
14
-- received a copy of the GNU General Public License with this distribution,
15
-- see file "<A HREF="GPL.txt">GPL.txt</A>". If not, write to the Free
16
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21
-- Author:</STRONG><DD>
23
-- <ADDRESS><A HREF="mailto:twolf@acm.org">twolf@acm.org</A></ADDRESS></DL>
26
-- Purpose:</STRONG><DD>
27
-- Keeps a list of known filename/unitname pairs.</DL>
32
-- 09-JUL-2003 TW Initial version
34
-------------------------------------------------------------------------------
38
with GAL.ADT.Hash_Tables;
39
with GAL.Support.Hashing;
40
with GAL.Storage.Standard;
42
pragma Elaborate_All (GAL.ADT.Hash_Tables);
47
package body AD.Known_Units is
49
package ASU renames Ada.Strings.Unbounded;
51
-- All right. We need several different access methods:
52
-- case sensitive first, then case insensitive. Exact match, and
53
-- basename match. We hash on the greatest common denominator: the
54
-- case insensitive base name.
56
Prefix : Boolean := False;
57
Case_Insensitive : Boolean := False;
60
(Left, Right : in String)
64
(Left, Right : in String)
68
if not Case_Insensitive then
71
return Util.Strings.Equal (Left, Right);
79
return Match (Base_Name (Left), Base_Name (Right));
81
return Match (Left, Right);
87
return GAL.Support.Hashing.Hash_Type
91
return GAL.Support.Hashing.Hash_Case_Insensitive (Base_Name (S));
96
File, Path, Unit : ASU.Unbounded_String;
100
new GAL.ADT.Hash_Tables
103
Memory => GAL.Storage.Standard,
107
Known : Units.Hash_Table;
110
(File_Name : in String;
111
Unit_Name : in String)
113
New_Entry : Unit_Desc;
114
The_Name : constant String := Util.Pathes.Name (File_Name);
116
Prefix := False; Case_Insensitive := False;
117
New_Entry.File := ASU.To_Unbounded_String (The_Name);
118
New_Entry.Path := ASU.To_Unbounded_String (Util.Pathes.Path (File_Name));
119
New_Entry.Unit := ASU.To_Unbounded_String (Unit_Name);
120
Units.Insert (Known, The_Name, New_Entry);
122
when Units.Duplicate_Key =>
127
(Given_File_Name : in String;
128
Stored_File_Name : out Ada.Strings.Unbounded.Unbounded_String;
129
Stored_Path : out Ada.Strings.Unbounded.Unbounded_String;
130
Unit_Name : out Ada.Strings.Unbounded.Unbounded_String)
138
Item := Units.Retrieve (Known, Key);
139
Stored_File_Name := Item.File;
140
Stored_Path := Item.Path;
141
Unit_Name := Item.Unit;
144
when Units.Not_Found =>
152
The_Name : constant String := Name (Given_File_Name);
155
Stored_File_Name := ASU.Null_Unbounded_String;
156
Unit_Name := ASU.Null_Unbounded_String;
157
if not Units.Is_Empty (Known) then
158
for B in Boolean loop
159
Prefix := False; Case_Insensitive := B;
160
Get (The_Name, Found);
161
if Found then return; end if;
162
Get (Replace_Extension (The_Name, "ads"), Found);
163
if Found then return; end if;
165
Get (Base_Name (The_Name), Found);
166
if Found then return; end if;
172
Units.Set_Resize (Known, 0.75);
174
Linear_Growth : GAL.Support.Hashing.Linear_Growth_Policy (50);
176
Units.Set_Growth_Policy (Known, Linear_Growth);