Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison files.c @ 10:800f3a560a3b
move seenfiles to place.c too
author | David A. Holland |
---|---|
date | Sun, 19 Dec 2010 19:27:14 -0500 (2010-12-20) |
parents | 1fbcbd58742e |
children | 120629a5d6bf |
comparison
equal
deleted
inserted
replaced
9:1fbcbd58742e | 10:800f3a560a3b |
---|---|
12 struct incdir { | 12 struct incdir { |
13 const char *name; | 13 const char *name; |
14 bool issystem; | 14 bool issystem; |
15 }; | 15 }; |
16 | 16 |
17 struct seenfile { | |
18 struct place includedfrom; | |
19 char *name; | |
20 bool fromsystemdir; | |
21 }; | |
22 | |
23 DECLARRAY(incdir); | 17 DECLARRAY(incdir); |
24 DECLARRAY(seenfile); | |
25 DEFARRAY(incdir, ); | 18 DEFARRAY(incdir, ); |
26 DEFARRAY(seenfile, ); | |
27 | 19 |
28 static struct incdirarray quotepath, bracketpath; | 20 static struct incdirarray quotepath, bracketpath; |
29 static struct seenfilearray seenfiles; | |
30 | 21 |
31 //////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////// |
32 // management | 23 // management |
33 | 24 |
34 static | 25 static |
48 incdir_destroy(struct incdir *id) | 39 incdir_destroy(struct incdir *id) |
49 { | 40 { |
50 free(id); | 41 free(id); |
51 } | 42 } |
52 | 43 |
53 static | |
54 struct seenfile * | |
55 seenfile_create(const struct place *from, char *name, bool fromsystemdir) | |
56 { | |
57 struct seenfile *sf; | |
58 | |
59 sf = domalloc(sizeof(*sf)); | |
60 sf->includedfrom = *from; | |
61 sf->name = name; | |
62 sf->fromsystemdir = fromsystemdir; | |
63 return sf; | |
64 } | |
65 | |
66 static | |
67 void | |
68 seenfile_destroy(struct seenfile *sf) | |
69 { | |
70 free(sf->name); | |
71 free(sf); | |
72 } | |
73 | |
74 void | 44 void |
75 files_init(void) | 45 files_init(void) |
76 { | 46 { |
77 incdirarray_init("epath); | 47 incdirarray_init("epath); |
78 incdirarray_init(&bracketpath); | 48 incdirarray_init(&bracketpath); |
79 } | 49 } |
80 | 50 |
81 DESTROYALL_ARRAY(incdir, ); | 51 DESTROYALL_ARRAY(incdir, ); |
82 DESTROYALL_ARRAY(seenfile, ); | |
83 | 52 |
84 void | 53 void |
85 files_cleanup(void) | 54 files_cleanup(void) |
86 { | 55 { |
87 seenfilearray_destroyall(&seenfiles); | |
88 seenfilearray_cleanup(&seenfiles); | |
89 | |
90 incdirarray_destroyall("epath); | 56 incdirarray_destroyall("epath); |
91 incdirarray_cleanup("epath); | 57 incdirarray_cleanup("epath); |
92 incdirarray_destroyall(&bracketpath); | 58 incdirarray_destroyall(&bracketpath); |
93 incdirarray_cleanup(&bracketpath); | 59 incdirarray_cleanup(&bracketpath); |
94 } | 60 } |
110 { | 76 { |
111 struct incdir *id; | 77 struct incdir *id; |
112 | 78 |
113 id = incdir_create(dir, issystem); | 79 id = incdir_create(dir, issystem); |
114 incdirarray_add(&bracketpath, id, NULL); | 80 incdirarray_add(&bracketpath, id, NULL); |
115 } | |
116 | |
117 //////////////////////////////////////////////////////////// | |
118 // seenfile functions exposed for places.c | |
119 | |
120 const char * | |
121 seenfile_getname(const struct seenfile *file) | |
122 { | |
123 return file->name; | |
124 } | |
125 | |
126 const struct place * | |
127 seenfile_getincludeplace(const struct seenfile *file) | |
128 { | |
129 return &file->includedfrom; | |
130 } | 81 } |
131 | 82 |
132 //////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////// |
133 // parsing | 84 // parsing |
134 | 85 |
168 for (i=0; i<num; i++) { | 119 for (i=0; i<num; i++) { |
169 id = incdirarray_get(path, i); | 120 id = incdirarray_get(path, i); |
170 file = dostrdup3(id->name, "/", name); | 121 file = dostrdup3(id->name, "/", name); |
171 fd = file_tryopen(file); | 122 fd = file_tryopen(file); |
172 if (fd >= 0) { | 123 if (fd >= 0) { |
173 sf = seenfile_create(place, file, id->issystem); | 124 sf = place_seen_file(place, file, id->issystem); |
174 seenfilearray_add(&seenfiles, sf, NULL); | |
175 file_read(sf, fd); | 125 file_read(sf, fd); |
176 close(fd); | 126 close(fd); |
177 return; | 127 return; |
178 } | 128 } |
179 free(file); | 129 free(file); |
205 fd = file_tryopen(name); | 155 fd = file_tryopen(name); |
206 if (fd < 0) { | 156 if (fd < 0) { |
207 warn("%s", name); | 157 warn("%s", name); |
208 die(); | 158 die(); |
209 } | 159 } |
210 sf = seenfile_create(place, dostrdup(name), false); | 160 sf = place_seen_file(place, dostrdup(name), false); |
211 seenfilearray_add(&seenfiles, sf, NULL); | |
212 file_read(sf, fd); | 161 file_read(sf, fd); |
213 close(fd); | 162 close(fd); |
214 } | 163 } |