1 | # include "jam.h" |
---|
2 | # include "pathsys.h" |
---|
3 | # include "strings.h" |
---|
4 | # include "newstr.h" |
---|
5 | # include "filesys.h" |
---|
6 | # include "lists.h" |
---|
7 | |
---|
8 | void |
---|
9 | file_build1( |
---|
10 | PATHNAME *f, |
---|
11 | string* file) |
---|
12 | { |
---|
13 | if( DEBUG_SEARCH ) |
---|
14 | { |
---|
15 | printf("build file: "); |
---|
16 | if( f->f_root.len ) |
---|
17 | printf( "root = '%.*s' ", f->f_root.len, f->f_root.ptr ); |
---|
18 | if( f->f_dir.len ) |
---|
19 | printf( "dir = '%.*s' ", f->f_dir.len, f->f_dir.ptr ); |
---|
20 | if( f->f_base.len ) |
---|
21 | printf( "base = '%.*s' ", f->f_base.len, f->f_base.ptr ); |
---|
22 | } |
---|
23 | |
---|
24 | /* Start with the grist. If the current grist isn't */ |
---|
25 | /* surrounded by <>'s, add them. */ |
---|
26 | |
---|
27 | if( f->f_grist.len ) |
---|
28 | { |
---|
29 | if( f->f_grist.ptr[0] != '<' ) |
---|
30 | string_push_back( file, '<' ); |
---|
31 | string_append_range( |
---|
32 | file, f->f_grist.ptr, f->f_grist.ptr + f->f_grist.len ); |
---|
33 | if( file->value[file->size - 1] != '>' ) |
---|
34 | string_push_back( file, '>' ); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | static struct hash * filecache_hash = 0; |
---|
39 | |
---|
40 | file_info_t * file_info(char * filename) |
---|
41 | { |
---|
42 | file_info_t finfo_, *finfo = &finfo_; |
---|
43 | |
---|
44 | if ( !filecache_hash ) |
---|
45 | filecache_hash = hashinit( sizeof( file_info_t ), "file_info" ); |
---|
46 | |
---|
47 | finfo->name = filename; |
---|
48 | if ( hashenter( filecache_hash, (HASHDATA**)&finfo ) ) |
---|
49 | { |
---|
50 | /* printf( "file_info: %s\n", filename ); */ |
---|
51 | finfo->name = newstr( finfo->name ); |
---|
52 | finfo->is_file = 0; |
---|
53 | finfo->is_dir = 0; |
---|
54 | finfo->size = 0; |
---|
55 | finfo->time = 0; |
---|
56 | finfo->files = 0; |
---|
57 | } |
---|
58 | |
---|
59 | return finfo; |
---|
60 | } |
---|
61 | |
---|
62 | static LIST * files_to_remove = L0; |
---|
63 | |
---|
64 | static void remove_files_atexit(void) |
---|
65 | { |
---|
66 | /* we do pop front in case this exit function is called |
---|
67 | more than once */ |
---|
68 | while ( files_to_remove ) |
---|
69 | { |
---|
70 | remove( files_to_remove->string ); |
---|
71 | files_to_remove = list_pop_front( files_to_remove ); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | void file_done() |
---|
76 | { |
---|
77 | remove_files_atexit(); |
---|
78 | hashdone( filecache_hash ); |
---|
79 | } |
---|
80 | |
---|
81 | void file_remove_atexit( const char * path ) |
---|
82 | { |
---|
83 | files_to_remove = list_new( files_to_remove, newstr((char*)path) ); |
---|
84 | } |
---|