| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 56 |
|
| 57 |
|
| 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 |
|
| 72 |
|
| 73 |
|
| 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 |
|
| 106 |
++name; |
| 107 |
} |
| 108 |
|
| 109 |
if (*name == '\0') |
| 110 |
|
| 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 |
|
| 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 |
} |