added "jamgram" files, so k8jam can be built w/o yacc
[k8jam.git] / search.c
bloba348a207441e5fbb3661cae64684ce03aa9f5642
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 */
7 /*
8 * search.c - find a target along $(SEARCH) or $(LOCATE)
10 * 11/04/02 (seiwald) - const-ing for string literals
13 # include "jam.h"
14 # include "lists.h"
15 # include "search.h"
16 # include "timestamp.h"
17 # include "pathsys.h"
18 # include "variable.h"
19 # include "newstr.h"
21 const char *search (const char *target, time_t *time) {
22 PATHNAME f[1];
23 LIST *varlist;
24 char buf[MAXJPATH];
26 /* Parse the filename */
27 path_parse(target, f);
28 f->f_grist.ptr = 0;
29 f->f_grist.len = 0;
30 if ((varlist = var_get("LOCATE"))) {
31 f->f_root.ptr = varlist->string;
32 f->f_root.len = strlen(varlist->string);
33 path_build(f, buf, 1);
34 if (DEBUG_SEARCH) printf("locate %s: %s\n", target, buf);
35 timestamp(buf, time);
36 return newstr(buf);
37 } else if ((varlist = var_get("SEARCH"))) {
38 while (varlist) {
39 f->f_root.ptr = varlist->string;
40 f->f_root.len = strlen(varlist->string);
41 path_build(f, buf, 1);
42 if (DEBUG_SEARCH) printf("search %s: %s\n", target, buf);
43 timestamp(buf, time);
44 if (*time) return newstr(buf);
45 varlist = list_next(varlist);
48 /* Look for the obvious */
49 /* This is a questionable move. Should we look in the */
50 /* obvious place if SEARCH is set? */
51 f->f_root.ptr = 0;
52 f->f_root.len = 0;
53 path_build(f, buf, 1);
54 if (DEBUG_SEARCH) printf("search %s: %s\n", target, buf);
55 timestamp(buf, time);
56 return newstr(buf);