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