jamgram: cosmetix
[k8jam.git] / src / search.c
blob2fc0de5b9b62a37a479e7e0f06e2a80e47c819fc
1 /*
2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6 /*
7 * search.c - find a target along $(SEARCH) or $(LOCATE)
9 * 11/04/02 (seiwald) - const-ing for string literals
11 #include "jam.h"
12 #include "lists.h"
13 #include "search.h"
14 #include "timestamp.h"
15 #include "pathsys.h"
16 #include "variable.h"
17 #include "newstr.h"
18 #include "parse.h"
19 #include "compile.h"
22 static void call_bind_rule (const char *target, const char *boundname) {
23 LIST *bind_rule = var_get("BINDRULE");
24 if (bind_rule) {
25 LOL lol;
26 lol_init(&lol);
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));
30 lol_free(&lol);
35 const char *search (const char *target, time_t *time) {
36 PATHNAME f[1];
37 LIST *varlist;
38 static char buf[MAXJPATH];
39 /* parse the filename */
40 path_parse(target, f);
41 f->f_grist.ptr = 0;
42 f->f_grist.len = 0;
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);
48 timestamp(buf, time);
49 return newstr(buf);
51 if ((varlist = var_get("SEARCH"))) {
52 while (varlist) {
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);
57 timestamp(buf, time);
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? */
64 f->f_root.ptr = 0;
65 f->f_root.len = 0;
66 path_build(buf, f); /* was with binding, but it does nothing now */
67 if (DEBUG_SEARCH) printf("search %s: %s\n", target, buf);
68 timestamp(buf, time);
69 call_bind_rule(target, buf);
70 return newstr(buf);