6
* include style search support
14
typedef struct Dir_s /* directory list element */
16
struct Dir_s* next; /* next in list */
17
char dir[1]; /* directory path */
20
static struct /* directory list state */
22
Dir_t* head; /* directory list head */
23
Dir_t* tail; /* directory list tail */
27
* append dir to pathfind() include list
31
pathinclude(const char* dir)
35
if (dir && *dir && !streq(dir, "."))
37
if (!(dp = oldof(0, Dir_t, 1, strlen(dir))))
41
state.tail = state.tail->next = dp;
43
state.head = state.tail = dp;
49
* return path to name using pathinclude() list
50
* path placed in <buf,size>
51
* if lib!=0 then pathpath() attempted after include search
52
* if type!=0 and name has no '.' then file.type also attempted
53
* any *: prefix in lib is ignored (discipline library dictionary support)
57
pathfind(const char* name, const char* lib, const char* type, char* buf, size_t size)
63
if (access(name, R_OK) >= 0)
64
return strncpy(buf, name, size);
67
sfsprintf(buf, size, "%s.%s", name, type);
68
if (access(buf, R_OK) >= 0)
73
if (strchr(name, '.'))
75
for (dp = state.head; dp; dp = dp->next)
77
sfsprintf(tmp, sizeof(tmp), "%s/%s", dp->dir, name);
78
if (pathpath(buf, tmp, "", PATH_REGULAR))
82
sfsprintf(tmp, sizeof(tmp), "%s/%s.%s", dp->dir, name, type);
83
if (pathpath(buf, tmp, "", PATH_REGULAR))
89
if (s = strrchr((char*)lib, ':'))
90
lib = (const char*)s + 1;
91
sfsprintf(tmp, sizeof(tmp), "lib/%s/%s", lib, name);
92
if (pathpath(buf, tmp, "", PATH_REGULAR))
96
sfsprintf(tmp, sizeof(tmp), "lib/%s/%s.%s", lib, name, type);
97
if (pathpath(buf, tmp, "", PATH_REGULAR))