strings.c backported from boost-jam
[k8jam.git] / search.c
blob1b0a4afd9572d7a7891056ebeaf9bd900154f9f8
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 *
22 search(
23 const char *target,
24 time_t *time )
26 PATHNAME f[1];
27 LIST *varlist;
28 char buf[ MAXJPATH ];
30 /* Parse the filename */
32 path_parse( target, f );
34 f->f_grist.ptr = 0;
35 f->f_grist.len = 0;
37 if ((varlist = var_get("LOCATE")))
39 f->f_root.ptr = varlist->string;
40 f->f_root.len = strlen( varlist->string );
42 path_build( f, buf, 1 );
44 if( DEBUG_SEARCH )
45 printf( "locate %s: %s\n", target, buf );
47 timestamp( buf, time );
49 return newstr( buf );
51 else if ((varlist = var_get("SEARCH")))
53 while( varlist )
55 f->f_root.ptr = varlist->string;
56 f->f_root.len = strlen( varlist->string );
58 path_build( f, buf, 1 );
60 if( DEBUG_SEARCH )
61 printf( "search %s: %s\n", target, buf );
63 timestamp( buf, time );
65 if( *time )
66 return newstr( buf );
68 varlist = list_next( varlist );
72 /* Look for the obvious */
73 /* This is a questionable move. Should we look in the */
74 /* obvious place if SEARCH is set? */
76 f->f_root.ptr = 0;
77 f->f_root.len = 0;
79 path_build( f, buf, 1 );
81 if( DEBUG_SEARCH )
82 printf( "search %s: %s\n", target, buf );
84 timestamp( buf, time );
86 return newstr( buf );