Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/jam/src/timestamp.c @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.5 KB
Line 
1/*
2 * Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc.
3 *
4 * This file is part of Jam - see jam.c for Copyright information.
5 */
6
7/*  This file is ALSO:
8 *  Copyright 2001-2004 David Abrahams.
9 *  Distributed under the Boost Software License, Version 1.0.
10 *  (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
11 */
12
13# include "jam.h"
14# include "debug.h"
15
16# include "hash.h"
17# include "filesys.h"
18# include "pathsys.h"
19# include "timestamp.h"
20# include "newstr.h"
21# include "strings.h"
22
23/*
24 * timestamp.c - get the timestamp of a file or archive member
25 *
26 * 09/22/00 (seiwald) - downshift names on OS2, too
27 */
28
29/*
30 * BINDING - all known files
31 */
32
33typedef struct _binding BINDING;
34
35struct _binding {
36        char    *name;
37        short   flags;
38
39# define BIND_SCANNED   0x01    /* if directory or arch, has been scanned */
40
41        short   progress;
42
43# define BIND_INIT      0       /* never seen */
44# define BIND_NOENTRY   1       /* timestamp requested but file never found */
45# define BIND_SPOTTED   2       /* file found but not timed yet */
46# define BIND_MISSING   3       /* file found but can't get timestamp */
47# define BIND_FOUND     4       /* file found and time stamped */
48
49        time_t  time;           /* update time - 0 if not exist */
50} ;
51
52static struct hash *bindhash = 0;
53static void time_enter( void *, char *, int , time_t  );
54
55static char *time_progress[] =
56{
57        "INIT",
58        "NOENTRY",
59        "SPOTTED",
60        "MISSING",
61        "FOUND"
62} ;
63
64
65/*
66 * timestamp() - return timestamp on a file, if present
67 */
68
69void
70timestamp( 
71        char    *target,
72        time_t  *time )
73{
74    PROFILE_ENTER(timestamp);
75   
76        PATHNAME f1, f2;
77        BINDING binding, *b = &binding;
78        string buf[1];
79    string path; 
80        char *p;
81
82# ifdef DOWNSHIFT_PATHS
83
84        string_copy( &path, target );
85        p = path.value;
86
87        do
88    {
89        *p = tolower( *p );
90#  ifdef NT
91        /* On NT, we must use backslashes or the file won't be found. */
92        if (*p == '/')
93            *p = PATH_DELIM;
94#  endif
95    }
96        while( *p++ );
97
98        target = path.value;
99# endif
100        string_new( buf );
101
102        if( !bindhash )
103            bindhash = hashinit( sizeof( BINDING ), "bindings" );
104
105        /* Quick path - is it there? */
106
107        b->name = target;
108        b->time = b->flags = 0;
109        b->progress = BIND_INIT;
110
111        if( hashenter( bindhash, (HASHDATA **)&b ) )
112            b->name = newstr( target );         /* never freed */
113
114        if( b->progress != BIND_INIT )
115            goto afterscanning;
116
117        b->progress = BIND_NOENTRY;
118
119        /* Not found - have to scan for it */
120
121        path_parse( target, &f1 );
122
123        /* Scan directory if not already done so */
124
125        {
126            BINDING binding, *b = &binding;
127
128            f2 = f1;
129            f2.f_grist.len = 0;
130            path_parent( &f2 );
131            path_build( &f2, buf, 0 );
132
133            b->name = buf->value;
134            b->time = b->flags = 0;
135            b->progress = BIND_INIT;
136
137            if( hashenter( bindhash, (HASHDATA **)&b ) )
138                b->name = newstr( buf->value ); /* never freed */
139
140            if( !( b->flags & BIND_SCANNED ) )
141            {
142                file_dirscan( buf->value, time_enter, bindhash );
143                b->flags |= BIND_SCANNED;
144            }
145        }
146
147        /* Scan archive if not already done so */
148
149        if( f1.f_member.len )
150        {
151            BINDING binding, *b = &binding;
152
153            f2 = f1;
154            f2.f_grist.len = 0;
155            f2.f_member.len = 0;
156            string_truncate( buf, 0 );
157            path_build( &f2, buf, 0 );
158
159            b->name = buf->value;
160            b->time = b->flags = 0;
161            b->progress = BIND_INIT;
162
163            if( hashenter( bindhash, (HASHDATA **)&b ) )
164                b->name = newstr( buf->value ); /* never freed */
165
166            if( !( b->flags & BIND_SCANNED ) )
167            {
168                file_archscan( buf->value, time_enter, bindhash );
169                b->flags |= BIND_SCANNED;
170            }
171        }
172
173    afterscanning:
174
175        if( b->progress == BIND_SPOTTED )
176        {
177            if( file_time( b->name, &b->time ) < 0 )
178                b->progress = BIND_MISSING;
179            else
180                b->progress = BIND_FOUND;
181        }
182
183        *time = b->progress == BIND_FOUND ? b->time : 0;
184        string_free( buf );
185# ifdef DOWNSHIFT_PATHS
186        string_free( &path );
187#endif
188   
189    PROFILE_EXIT(timestamp);
190}
191
192static void
193time_enter( 
194        void    *closure,
195        char    *target,
196        int     found,
197        time_t  time )
198{
199        BINDING binding, *b = &binding;
200        struct hash *bindhash = (struct hash *)closure;
201
202# ifdef DOWNSHIFT_PATHS
203        char path[ MAXJPATH ];
204        char *p = path;
205
206        do *p++ = tolower( *target );
207        while( *target++ );
208
209        target = path;
210# endif
211
212        b->name = target;
213        b->flags = 0;
214
215        if( hashenter( bindhash, (HASHDATA **)&b ) )
216            b->name = newstr( target );         /* never freed */
217
218        b->time = time;
219        b->progress = found ? BIND_FOUND : BIND_SPOTTED;
220
221        if( DEBUG_BINDSCAN )
222            printf( "time ( %s ) : %s\n", target, time_progress[b->progress] );
223}
224
225/*
226 * donestamps() - free timestamp tables
227 */
228
229void
230donestamps()
231{
232        hashdone( bindhash );
233}
Note: See TracBrowser for help on using the repository browser.