1 /*
2  *	spritdir.cc - Sprite_dir class
3  *	AYM 2000-06-01
4  */
5 
6 
7 /*
8 This file is part of Yadex.
9 
10 Yadex incorporates code from DEU 5.21 that was put in the public domain in
11 1994 by Rapha�l Quinet and Brendon Wyber.
12 
13 The rest of Yadex is Copyright � 1997-2003 Andr� Majorel and others.
14 
15 This program is free software; you can redistribute it and/or modify it under
16 the terms of the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any later
18 version.
19 
20 This program is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License along with
25 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
26 Place, Suite 330, Boston, MA 02111-1307, USA.
27 */
28 
29 
30 #include "yadex.h"
31 #include <functional>
32 #include "dependcy.h"
33 #include "lumpdir.h"
34 #include "spritdir.h"
35 #include "wadname.h"
36 #include "wadnamec.h"
37 
38 
39 /*
40  *	Sprite_dir::loc_by_root - find sprite by prefix
41  *
42  *      Return the (wad, offset, length) location of the first
43  *      lump by alphabetical order whose name begins with
44  *      <name>. If not found, set loc.wad to 0.
45  */
loc_by_root(const char * name,Lump_loc & loc)46 void Sprite_dir::loc_by_root (const char *name, Lump_loc& loc)
47 {
48   if (dependency->outdated ())
49     refresh ();
50 
51   /* Caller asked for same lump twice in a row. Save us a second
52      search. */
53   if (have_prev && ! y_strnicmp (name, name_prev, WAD_NAME))
54   {
55     loc = loc_prev;
56     return;
57   }
58 
59   Lump_map::const_iterator i = lump_map.lower_bound (name);
60   have_prev = true;
61   if (i == lump_map.end () || y_strnicmp (name, i->first.name, strlen (name)))
62     loc.wad = loc_prev.wad = 0;
63   else
64     loc = loc_prev = i->second;
65 }
66 
67