2
* -= Copyright 2005 Tim Baker (treectrl@hotmail.com) =-
4
* This file is part of depslib.
6
* License is hereby granted to use this software and distribute it
7
* freely, as long as this copyright notice is retained and modifications
10
* ALL WARRANTIES ARE HEREBY DISCLAIMED.
13
* - D support (search for "D support")
14
* - Depth level counting (needed for D support)
15
* - Simple optimization by avoiding regexec most of the time
16
* - Special cache keys for source files (needed for D support)
29
#include "depslib.h" /* for struct depsStats */
30
extern struct depsStats g_stats;
32
struct hash *headerhash = 0;
33
static regexp *hdrre = 0;
35
static regexp *dimpre = 0;
37
LIST *headers1(const char *file, int depth)
43
int fnlen=strlen(file);
48
if(file[fnlen-2] == '.' && file[fnlen-1] == 'd')
52
printf("D file detected\n");
55
/* C::B patch: Debug usage of root folder */
57
printf("header open %s\n", file);
59
if (!(f = fopen(file, "r")))
63
printf("header scan %s\n", file);
66
hdrre = my_regcomp("^[ ]*#[ ]*include[ ]*([<\"])([^\">]*)([\">]).*$");
74
"^.*import[ \t]*([[A-Za-z_ \t]+=[ \t]*)?([A-Za-z_\\.]+)(\\:.+)?;.*$");
78
while (fgets(buf, sizeof(buf), f))
85
if(strstr(buf, "public"))
97
/* Simple reduction of regex overhead */
98
if(strstr(buf, dMode ? "import" : "include"))
99
if (my_regexec(re, buf))
103
/* FIXME: don't add duplicate headers*/
104
if(!dMode && re->startp[3])
106
int l = re->endp[3] - re->startp[1];
107
memcpy(buf2, re->startp[1], l);
111
else if(re->startp[2])
115
/* private import? */
123
for(p = re->startp[2];p < re->endp[2];++p)
136
result = list_new(result, buf2, 0);
139
printf("header found: %s\n", buf2);
163
static ALLOC *hdralloc = 0;
165
HEADERS *headerentry(HEADERS *chain, HEADER *header)
171
hdralloc = alloc_init(sizeof(HEADERS), 64);
172
c = (HEADERS *) alloc_enter(hdralloc);
174
c = (HEADERS *)malloc(sizeof(HEADERS));
178
if (!chain) chain = c;
179
else chain->tail->next = c;
186
HEADER *headersDepth(const char *t, time_t time, int depth)
188
HEADER hdr, *h = &hdr;
190
const char* cachekey=t;
192
/* D support (doesn't affect C(++), because a source file is never included) */
195
cachekey=malloc(strlen(t)+sizeof("source:"));
196
strcpy((char*)cachekey,"source:");
197
strcpy((char*)cachekey+7,t);
201
headerhash = hashinit(sizeof(HEADER), "headers");
208
if (!hashenter(headerhash, (HASHDATA **)&h))
213
if (!cache_check(cachekey, time, &h->includes))
215
h->includes = headers1(t, depth);
216
cache_enter(cachekey, time, h->includes);
219
h->includes = headers1(t, depth);
222
free((char*)cachekey);
227
const char *t2 = search(t, l->string, &time);
229
h->headers = headerentry(h->headers, headersDepth(t2, time, depth+1));
236
HEADER *headers(const char *t, time_t time)
238
return headersDepth(t, time, 0);
241
void headernewest(HEADER *h)
243
HEADERS *hs = h->headers;
250
headernewest(hs->header);
251
if (hs->header->newest->time > h->newest->time)
252
h->newest = hs->header->newest;
264
hashdone(headerhash);
266
alloc_free(hdralloc);