2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
3 * This file is part of Jam - see jam.c for Copyright information.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * search.c - find a target along $(SEARCH) or $(LOCATE)
24 #include "timestamp.h"
32 static void call_bind_rule (const char *target
, const char *boundname
) {
33 LIST
*bind_rule
= var_get("BINDRULE");
37 lol_add(&lol
, list_new(L0
, target
, 1));
38 lol_add(&lol
, list_new(L0
, boundname
, 1));
39 if (lol_get(&lol
, 1)) list_free(evaluate_rule(bind_rule
->string
, &lol
, L0
));
45 const char *search (const char *target
, time_t *time
) {
48 static char buf
[MAXJPATH
];
49 /* parse the filename */
50 path_parse(target
, f
);
53 if ((varlist
= var_get("LOCATE"))) {
54 f
->f_root
.ptr
= varlist
->string
;
55 f
->f_root
.len
= strlen(varlist
->string
);
56 path_build(buf
, f
); /* was with binding, but it does nothing now */
57 if (DEBUG_SEARCH
) printf("locate %s: %s\n", target
, buf
);
61 if ((varlist
= var_get("SEARCH"))) {
63 f
->f_root
.ptr
= varlist
->string
;
64 f
->f_root
.len
= strlen(varlist
->string
);
65 path_build(buf
, f
); /* was with binding, but it does nothing now */
66 if (DEBUG_SEARCH
) printf("search %s: %s\n", target
, buf
);
68 if (*time
) return newstr(buf
);
69 varlist
= list_next(varlist
);
72 /* look for the obvious */
73 /* this is a questionable move: should we look in the obvious place if SEARCH is set? */
76 path_build(buf
, f
); /* was with binding, but it does nothing now */
77 if (DEBUG_SEARCH
) printf("search %s: %s\n", target
, buf
);
79 call_bind_rule(target
, buf
);