Debian Codegraph @

src/file_basic.c

raw symbols SCIP
1 /* Target file management for GNU Make.
2 Copyright (C) 1988-2014 Free Software Foundation, Inc.
3 This file is part of GNU Make.
4
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
8 version.
9
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #include "makeint.h"
18
19 #include <assert.h>
20
21 #include "filedef.h"
22 #include "file.h"
23 #include "dep.h"
24 #include "job.h"
25 #include "commands.h"
26 #include "variable.h"
27 #include "debug.h"
28 #include "hash.h"
29
30 struct hash_table files;
31
32 extern unsigned long
33 file_hash_1 (const void *key)
34 {
35 return_ISTRING_HASH_1 (((struct file const *) key)->hname);
36 }
37
38 extern unsigned long
39 file_hash_2 (const void *key)
40 {
41 return_ISTRING_HASH_2 (((struct file const *) key)->hname);
42 }
43
44 extern int
45 file_hash_cmp (const void *x, const void *y)
46 {
47 return_ISTRING_COMPARE (((struct file const *) x)->hname,
48 ((struct file const *) y)->hname);
49 }
50
51 #ifndef FILE_BUCKETS
52 #define FILE_BUCKETS 1007
53 #endif
54
55 /* Access the hash table of all file records.
56 lookup_file given a name, return the struct file * for that name,
57 or nil if there is none.
58 */
59
60 struct file *
61 lookup_file (const char *name)
62 {
63 struct file *f;
64 struct file file_key;
65 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
66 char *lname;
67 #endif
68
69 assert (*name != '\0');
70
71 /* This is also done in parse_file_seq, so this is redundant
72 for names read from makefiles. It is here for names passed
73 on the command line. */
74 #ifdef VMS
75 # ifndef WANT_CASE_SENSITIVE_TARGETS
76 if (*name != '.')
77 {
78 const char *n;
79 char *ln;
80 lname = xstrdup (name);
81 for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
82 *ln = isupper ((unsigned char)*n) ? tolower ((unsigned char)*n) : *n;
83 *ln = '\0';
84 name = lname;
85 }
86 # endif
87
88 while (name[0] == '[' && name[1] == ']' && name[2] != '\0')
89 name += 2;
90 #endif
91 while (name[0] == '.'
92 #ifdef HAVE_DOS_PATHS
93 && (name[1] == '/' || name[1] == '\\')
94 #else
95 && name[1] == '/'
96 #endif
97 && name[2] != '\0')
98 {
99 name += 2;
100 while (*name == '/'
101 #ifdef HAVE_DOS_PATHS
102 || *name == '\\'
103 #endif
104 )
105 /* Skip following slashes: ".//foo" is "foo", not "/foo". */
106 ++name;
107 }
108
109 if (*name == '\0')
110 /* It was all slashes after a dot. */
111 #if defined(VMS)
112 name = "[]";
113 #elif defined(_AMIGA)
114 name = "";
115 #else
116 name = "./";
117 #endif
118
119 file_key.hname = name;
120 f = hash_find_item (&files, &file_key);
121 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
122 if (*name != '.')
123 free (lname);
124 #endif
125
126 return f;
127 }
128
129 struct file *
130 enter_file (const char *name)
131 {
132 struct file *f;
133 struct file *new;
134 struct file **file_slot;
135 struct file file_key;
136
137 assert (*name != '\0');
138 assert (! verify_flag || strcache_iscached (name));
139
140 #if defined(VMS) && !defined(WANT_CASE_SENSITIVE_TARGETS)
141 if (*name != '.')
142 {
143 const char *n;
144 char *lname, *ln;
145 lname = xstrdup (name);
146 for (n = name, ln = lname; *n != '\0'; ++n, ++ln)
147 if (isupper ((unsigned char)*n))
148 *ln = tolower ((unsigned char)*n);
149 else
150 *ln = *n;
151
152 *ln = '\0';
153 name = strcache_add (lname);
154 free (lname);
155 }
156 #endif
157
158 file_key.hname = name;
159 file_slot = (struct file **) hash_find_slot (&files, &file_key);
160 f = *file_slot;
161 if (! HASH_VACANT (f) && !f->double_colon)
162 {
163 f->builtin = 0;
164 return f;
165 }
166
167 new = xcalloc (sizeof (struct file));
168 new->name = new->hname = name;
169 new->update_status = us_none;
170
171 if (HASH_VACANT (f))
172 {
173 new->last = new;
174 hash_insert_at (&files, new, file_slot);
175 }
176 else
177 {
178 /* There is already a double-colon entry for this file. */
179 new->double_colon = f;
180 f->last->prev = new;
181 f->last = new;
182 }
183
184 return new;
185 }
186
187 void
188 init_hash_files (void)
189 {
190 hash_init (&files, 1000, file_hash_1, file_hash_2, file_hash_cmp);
191 }