2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
7 * search.c - find a target along $(SEARCH) or $(LOCATE)
9 * 11/04/02 (seiwald) - const-ing for string literals
14 #include "timestamp.h"
22 static void call_bind_rule (const char *target
, const char *boundname
) {
23 LIST
*bind_rule
= var_get("BINDRULE");
27 lol_add(&lol
, list_new(L0
, target
, 1));
28 lol_add(&lol
, list_new(L0
, boundname
, 1));
29 if (lol_get(&lol
, 1)) list_free(evaluate_rule(bind_rule
->string
, &lol
, L0
));
35 const char *search (const char *target
, time_t *time
) {
38 static char buf
[MAXJPATH
];
39 /* parse the filename */
40 path_parse(target
, f
);
43 if ((varlist
= var_get("LOCATE"))) {
44 f
->f_root
.ptr
= varlist
->string
;
45 f
->f_root
.len
= strlen(varlist
->string
);
46 path_build(buf
, f
); /* was with binding, but it does nothing now */
47 if (DEBUG_SEARCH
) printf("locate %s: %s\n", target
, buf
);
51 if ((varlist
= var_get("SEARCH"))) {
53 f
->f_root
.ptr
= varlist
->string
;
54 f
->f_root
.len
= strlen(varlist
->string
);
55 path_build(buf
, f
); /* was with binding, but it does nothing now */
56 if (DEBUG_SEARCH
) printf("search %s: %s\n", target
, buf
);
58 if (*time
) return newstr(buf
);
59 varlist
= list_next(varlist
);
62 /* look for the obvious */
63 /* this is a questionable move: should we look in the obvious place if SEARCH is set? */
66 path_build(buf
, f
); /* was with binding, but it does nothing now */
67 if (DEBUG_SEARCH
) printf("search %s: %s\n", target
, buf
);
69 call_bind_rule(target
, buf
);