|
|
1 | /** |
|
|
2 | * ZANavi, Zoff Android Navigation system. |
|
|
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
|
|
4 | * |
|
|
5 | * This program is free software; you can redistribute it and/or |
|
|
6 | * modify it under the terms of the GNU General Public License |
|
|
7 | * version 2 as published by the Free Software Foundation. |
|
|
8 | * |
|
|
9 | * This program is distributed in the hope that it will be useful, |
|
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 | * GNU General Public License for more details. |
|
|
13 | * |
|
|
14 | * You should have received a copy of the GNU General Public License |
|
|
15 | * along with this program; if not, write to the |
|
|
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
|
17 | * Boston, MA 02110-1301, USA. |
|
|
18 | */ |
|
|
19 | |
1 | /** |
20 | /** |
2 | * Navit, a modular navigation system. |
21 | * Navit, a modular navigation system. |
3 | * Copyright (C) 2005-2008 Navit Team |
22 | * Copyright (C) 2005-2008 Navit Team |
4 | * |
23 | * |
5 | * This program is free software; you can redistribute it and/or |
24 | * This program is free software; you can redistribute it and/or |
… | |
… | |
14 | * You should have received a copy of the GNU General Public License |
33 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the |
34 | * along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
35 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
36 | * Boston, MA 02110-1301, USA. |
18 | */ |
37 | */ |
19 | |
|
|
20 | |
38 | |
21 | #define _FILE_OFFSET_BITS 64 |
39 | #define _FILE_OFFSET_BITS 64 |
22 | #define _LARGEFILE_SOURCE |
40 | #define _LARGEFILE_SOURCE |
23 | #define _LARGEFILE64_SOURCE |
41 | #define _LARGEFILE64_SOURCE |
24 | #include <stdlib.h> |
42 | #include <stdlib.h> |
… | |
… | |
41 | #include "config.h" |
59 | #include "config.h" |
42 | #include "linguistics.h" |
60 | #include "linguistics.h" |
43 | #include "plugin.h" |
61 | #include "plugin.h" |
44 | #include "maptool.h" |
62 | #include "maptool.h" |
45 | |
63 | |
46 | struct rect world_bbox = { |
64 | struct rect world_bbox = |
|
|
65 | { |
47 | { -20000000, -20000000}, |
66 | { -20000000, -20000000 }, |
48 | { 20000000, 20000000}, |
67 | { 20000000, 20000000 }, }; |
49 | }; |
|
|
50 | |
68 | |
51 | void |
|
|
52 | bbox_extend(struct coord *c, struct rect *r) |
69 | void bbox_extend(struct coord *c, struct rect *r) |
53 | { |
70 | { |
54 | if (c->x < r->l.x) |
71 | if (c->x < r->l.x) |
55 | r->l.x=c->x; |
72 | r->l.x = c->x; |
56 | if (c->y < r->l.y) |
73 | if (c->y < r->l.y) |
57 | r->l.y=c->y; |
74 | r->l.y = c->y; |
58 | if (c->x > r->h.x) |
75 | if (c->x > r->h.x) |
59 | r->h.x=c->x; |
76 | r->h.x = c->x; |
60 | if (c->y > r->h.y) |
77 | if (c->y > r->h.y) |
61 | r->h.y=c->y; |
78 | r->h.y = c->y; |
62 | } |
79 | } |
63 | |
80 | |
64 | void |
|
|
65 | bbox(struct coord *c, int count, struct rect *r) |
81 | void bbox(struct coord *c, int count, struct rect *r) |
66 | { |
82 | { |
67 | if (! count) |
83 | if (!count) |
68 | return; |
84 | return; |
69 | r->l=*c; |
85 | r->l = *c; |
70 | r->h=*c; |
86 | r->h = *c; |
71 | while (--count) { |
87 | while (--count) |
|
|
88 | { |
72 | c++; |
89 | c++; |
73 | bbox_extend(c, r); |
90 | bbox_extend(c, r); |
74 | } |
91 | } |
75 | } |
92 | } |
76 | |
93 | |
77 | int |
|
|
78 | contains_bbox(int xl, int yl, int xh, int yh, struct rect *r) |
94 | int contains_bbox(int xl, int yl, int xh, int yh, struct rect *r) |
79 | { |
95 | { |
80 | if (r->h.x < xl || r->h.x > xh) { |
96 | if (r->h.x < xl || r->h.x > xh) |
|
|
97 | { |
81 | return 0; |
98 | return 0; |
82 | } |
99 | } |
83 | if (r->l.x > xh || r->l.x < xl) { |
100 | if (r->l.x > xh || r->l.x < xl) |
|
|
101 | { |
84 | return 0; |
102 | return 0; |
85 | } |
103 | } |
86 | if (r->h.y < yl || r->h.y > yh) { |
104 | if (r->h.y < yl || r->h.y > yh) |
|
|
105 | { |
87 | return 0; |
106 | return 0; |
88 | } |
107 | } |
89 | if (r->l.y > yh || r->l.y < yl) { |
108 | if (r->l.y > yh || r->l.y < yl) |
|
|
109 | { |
90 | return 0; |
110 | return 0; |
91 | } |
111 | } |
92 | return 1; |
112 | return 1; |
93 | } |
113 | } |
94 | |
114 | |
95 | int |
|
|
96 | bbox_contains_coord(struct rect *r, struct coord *c) |
115 | int bbox_contains_coord(struct rect *r, struct coord *c) |
97 | { |
116 | { |
|
|
117 | |
|
|
118 | //fprintf(stderr,"bbox_contains_coord: rhx=%d rhy=%d rlx=%d rly=%d, cx=%d cy=%d\n", r->h.x, r->h.y, r->l.x, r->l.y,c->x, c->y); |
|
|
119 | |
98 | if (r->h.x < c->x) |
120 | if (r->h.x < c->x) |
99 | return 0; |
121 | return 0; |
100 | if (r->l.x > c->x) |
122 | if (r->l.x > c->x) |
101 | return 0; |
123 | return 0; |
102 | if (r->h.y < c->y) |
124 | if (r->h.y < c->y) |
… | |
… | |
104 | if (r->l.y > c->y) |
126 | if (r->l.y > c->y) |
105 | return 0; |
127 | return 0; |
106 | return 1; |
128 | return 1; |
107 | } |
129 | } |
108 | |
130 | |
109 | int |
|
|
110 | bbox_contains_bbox(struct rect *out, struct rect *in) |
131 | int bbox_contains_bbox(struct rect *out, struct rect *in) |
111 | { |
132 | { |
112 | if (out->h.x < in->h.x) |
133 | if (out->h.x < in->h.x) |
113 | return 0; |
134 | return 0; |
114 | if (out->l.x > in->l.x) |
135 | if (out->l.x > in->l.x) |
115 | return 0; |
136 | return 0; |
… | |
… | |
118 | if (out->l.y > in->l.y) |
139 | if (out->l.y > in->l.y) |
119 | return 0; |
140 | return 0; |
120 | return 1; |
141 | return 1; |
121 | } |
142 | } |
122 | |
143 | |
123 | long long |
|
|
124 | bbox_area(struct rect const *r) |
144 | long long bbox_area(struct rect const *r) |
125 | { |
145 | { |
126 | return ((long long)r->h.x-r->l.x)*(r->h.y-r->l.y); |
146 | return ((long long) r->h.x - r->l.x) * (r->h.y - r->l.y); |
127 | } |
147 | } |
128 | |
148 | |
129 | void |
|
|
130 | phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes) |
149 | void phase1_map(GList *maps, FILE *out_ways, FILE *out_nodes) |
131 | { |
150 | { |
132 | struct map_rect *mr; |
151 | struct map_rect *mr; |
133 | struct item *item; |
152 | struct item *item; |
134 | int count,max=16384; |
153 | int count, max = 16384; |
135 | struct coord ca[max]; |
154 | struct coord ca[max]; |
136 | struct attr attr; |
155 | struct attr attr; |
137 | struct item_bin *item_bin; |
156 | struct item_bin *item_bin; |
138 | |
157 | |
139 | while (maps) { |
158 | while (maps) |
|
|
159 | { |
140 | mr=map_rect_new(maps->data, NULL); |
160 | mr = map_rect_new(maps->data, NULL); |
141 | while ((item = map_rect_get_item(mr))) { |
161 | while ((item = map_rect_get_item(mr))) |
|
|
162 | { |
142 | count=item_coord_get(item, ca, item->type < type_line ? 1: max); |
163 | count = item_coord_get(item, ca, item->type < type_line ? 1 : max); |
143 | item_bin=init_item(item->type); |
164 | item_bin = init_item(item->type, 0); |
144 | item_bin_add_coord(item_bin, ca, count); |
165 | item_bin_add_coord(item_bin, ca, count); |
145 | while (item_attr_get(item, attr_any, &attr)) { |
166 | while (item_attr_get(item, attr_any, &attr)) |
|
|
167 | { |
146 | if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) { |
168 | if (attr.type >= attr_type_string_begin && attr.type <= attr_type_string_end) |
|
|
169 | { |
147 | attr.u.str=map_convert_string(maps->data, attr.u.str); |
170 | attr.u.str = map_convert_string(maps->data, attr.u.str); |
148 | if (attr.u.str) { |
171 | if (attr.u.str) |
|
|
172 | { |
149 | item_bin_add_attr(item_bin, &attr); |
173 | item_bin_add_attr(item_bin, &attr); |
150 | map_convert_free(attr.u.str); |
174 | map_convert_free(attr.u.str); |
151 | } |
175 | } |
|
|
176 | } |
152 | } else |
177 | else |
153 | item_bin_add_attr(item_bin, &attr); |
178 | item_bin_add_attr(item_bin, &attr); |
154 | } |
179 | } |
155 | if (item->type >= type_line) |
180 | if (item->type >= type_line) |
156 | item_bin_write(item_bin, out_ways); |
181 | item_bin_write(item_bin, out_ways); |
157 | else |
182 | else |
158 | item_bin_write(item_bin, out_nodes); |
183 | item_bin_write(item_bin, out_nodes); |
159 | } |
184 | } |
160 | map_rect_destroy(mr); |
185 | map_rect_destroy(mr); |
161 | maps=g_list_next(maps); |
186 | maps = g_list_next(maps); |
162 | } |
187 | } |
163 | } |
188 | } |
164 | |
189 | |
165 | static void |
|
|
166 | phase34_process_file(struct tile_info *info, FILE *in, FILE *reference) |
190 | static void phase34_process_file(struct tile_info *info, FILE *in, FILE *reference) |
167 | { |
191 | { |
168 | struct item_bin *ib; |
192 | struct item_bin *ib; |
169 | int max; |
193 | int max; |
170 | |
194 | |
171 | while ((ib=read_item(in))) { |
195 | while ((ib = read_item(in, 0))) |
|
|
196 | { |
|
|
197 | if (ib->type < 0x80000000) |
|
|
198 | { |
|
|
199 | processed_nodes++; |
|
|
200 | } |
|
|
201 | else |
|
|
202 | { |
|
|
203 | processed_ways++; |
|
|
204 | } |
|
|
205 | |
|
|
206 | if (border_only_map == 1) |
|
|
207 | { |
|
|
208 | // fprintf(stderr,"max=1\n"); |
|
|
209 | // max=1; --> shows all borders, all the time. but is too slow! |
|
|
210 | max = 4; |
|
|
211 | } |
|
|
212 | else |
|
|
213 | { |
|
|
214 | max = 14; |
|
|
215 | switch (ib->type) |
|
|
216 | { |
|
|
217 | case type_town_label_1e7: |
|
|
218 | case type_town_label_5e6: |
|
|
219 | case type_town_label_2e6: |
|
|
220 | case type_town_label_1e6: |
|
|
221 | case type_town_label_5e5: |
|
|
222 | case type_district_label_1e7: |
|
|
223 | case type_district_label_5e6: |
|
|
224 | case type_district_label_2e6: |
|
|
225 | case type_district_label_1e6: |
|
|
226 | case type_district_label_5e5: |
|
|
227 | max = 6; |
|
|
228 | break; |
|
|
229 | case type_town_label_2e5: |
|
|
230 | case type_town_label_1e5: |
|
|
231 | case type_district_label_2e5: |
|
|
232 | case type_district_label_1e5: |
|
|
233 | case type_street_n_lanes: |
|
|
234 | case type_highway_city: |
|
|
235 | case type_highway_land: |
|
|
236 | case type_ramp: |
|
|
237 | max = 8; |
|
|
238 | break; |
|
|
239 | case type_town_label_5e4: |
|
|
240 | case type_town_label_2e4: |
|
|
241 | case type_town_label_1e4: |
|
|
242 | case type_district_label_5e4: |
|
|
243 | case type_district_label_2e4: |
|
|
244 | case type_district_label_1e4: |
|
|
245 | max = 9; |
|
|
246 | break; |
|
|
247 | case type_street_4_land: |
|
|
248 | case type_street_4_city: |
|
|
249 | max = 10; |
|
|
250 | break; |
|
|
251 | case type_town_label_5e3: |
|
|
252 | case type_town_label_2e3: |
|
|
253 | case type_town_label_1e3: |
|
|
254 | case type_district_label_5e3: |
|
|
255 | case type_district_label_2e3: |
|
|
256 | case type_district_label_1e3: |
|
|
257 | case type_street_3_city: |
|
|
258 | case type_street_3_land: |
|
|
259 | max = 12; |
|
|
260 | break; |
|
|
261 | default: |
|
|
262 | break; |
|
|
263 | } |
|
|
264 | } |
|
|
265 | |
|
|
266 | // dont write "street unknown" items to binfile, if option "to ignore unknown types" is set |
|
|
267 | if ((ib->type == type_street_unkn) && (ignore_unkown == 1)) |
|
|
268 | { |
|
|
269 | } |
|
|
270 | else |
|
|
271 | { |
|
|
272 | tile_write_item_minmax(info, ib, reference, 0, max); |
|
|
273 | } |
|
|
274 | } |
|
|
275 | } |
|
|
276 | |
|
|
277 | static void phase34_process_file_range(struct tile_info *info, FILE *in, FILE *reference) |
|
|
278 | { |
|
|
279 | struct item_bin *ib; |
|
|
280 | int min, max; |
|
|
281 | |
|
|
282 | while ((ib = read_item_range(in, &min, &max, 0))) |
|
|
283 | { |
172 | if (ib->type < 0x80000000) |
284 | if (ib->type < 0x80000000) |
173 | processed_nodes++; |
285 | processed_nodes++; |
174 | else |
286 | else |
175 | processed_ways++; |
287 | processed_ways++; |
176 | |
288 | |
177 | if (border_only_map==1) |
289 | if ((ib->type == type_street_unkn) && (ignore_unkown == 1)) |
178 | { |
290 | { |
179 | // fprintf(stderr,"max=1\n"); |
|
|
180 | // max=1; --> shows all borders, all the time. but is too slow! |
|
|
181 | max=4; |
|
|
182 | } |
291 | } |
183 | else |
292 | else |
184 | { |
293 | { |
185 | max=14; |
294 | tile_write_item_minmax(info, ib, reference, min, max); |
186 | switch (ib->type) |
295 | } |
|
|
296 | } |
|
|
297 | } |
|
|
298 | |
|
|
299 | static int phase34(struct tile_info *info, struct zip_info *zip_info, FILE **in, FILE **reference, int in_count, int with_range) |
|
|
300 | { |
|
|
301 | int i; |
|
|
302 | |
|
|
303 | processed_nodes = processed_nodes_out = processed_ways = processed_relations = processed_tiles = 0; |
|
|
304 | |
|
|
305 | bytes_read = 0; |
|
|
306 | //sig_alrm(0); |
|
|
307 | |
|
|
308 | if (!info->write) |
|
|
309 | { |
|
|
310 | tile_hash = g_hash_table_new(g_str_hash, g_str_equal); |
|
|
311 | } |
|
|
312 | |
|
|
313 | for (i = 0; i < in_count; i++) |
|
|
314 | { |
|
|
315 | if (in[i]) |
|
|
316 | { |
|
|
317 | if (with_range) |
187 | { |
318 | { |
188 | case type_town_label_1e7: |
319 | phase34_process_file_range(info, in[i], reference ? reference[i] : NULL); |
189 | case type_town_label_5e6: |
|
|
190 | case type_town_label_2e6: |
|
|
191 | case type_town_label_1e6: |
|
|
192 | case type_town_label_5e5: |
|
|
193 | case type_district_label_1e7: |
|
|
194 | case type_district_label_5e6: |
|
|
195 | case type_district_label_2e6: |
|
|
196 | case type_district_label_1e6: |
|
|
197 | case type_district_label_5e5: |
|
|
198 | max=6; |
|
|
199 | break; |
|
|
200 | case type_town_label_2e5: |
|
|
201 | case type_town_label_1e5: |
|
|
202 | case type_district_label_2e5: |
|
|
203 | case type_district_label_1e5: |
|
|
204 | case type_street_n_lanes: |
|
|
205 | case type_highway_city: |
|
|
206 | case type_highway_land: |
|
|
207 | case type_ramp: |
|
|
208 | max=8; |
|
|
209 | break; |
|
|
210 | case type_town_label_5e4: |
|
|
211 | case type_town_label_2e4: |
|
|
212 | case type_town_label_1e4: |
|
|
213 | case type_district_label_5e4: |
|
|
214 | case type_district_label_2e4: |
|
|
215 | case type_district_label_1e4: |
|
|
216 | max=9; |
|
|
217 | break; |
|
|
218 | case type_street_4_land: |
|
|
219 | case type_street_4_city: |
|
|
220 | max=10; |
|
|
221 | break; |
|
|
222 | case type_town_label_5e3: |
|
|
223 | case type_town_label_2e3: |
|
|
224 | case type_town_label_1e3: |
|
|
225 | case type_district_label_5e3: |
|
|
226 | case type_district_label_2e3: |
|
|
227 | case type_district_label_1e3: |
|
|
228 | case type_street_3_city: |
|
|
229 | case type_street_3_land: |
|
|
230 | max=12; |
|
|
231 | break; |
|
|
232 | default: |
|
|
233 | break; |
|
|
234 | } |
320 | } |
|
|
321 | else |
|
|
322 | { |
|
|
323 | phase34_process_file(info, in[i], reference ? reference[i] : NULL); |
235 | } |
324 | } |
236 | tile_write_item_minmax(info, ib, reference, 0, max); |
|
|
237 | } |
325 | } |
238 | } |
326 | } |
239 | |
327 | |
240 | static void |
328 | if (!info->write) |
241 | phase34_process_file_range(struct tile_info *info, FILE *in, FILE *reference) |
329 | { |
|
|
330 | merge_tiles(info); |
|
|
331 | } |
|
|
332 | |
|
|
333 | //sig_alrm(0); |
|
|
334 | //sig_alrm_end(); |
|
|
335 | |
|
|
336 | write_tilesdir(info, zip_info, info->tilesdir_out); |
|
|
337 | |
|
|
338 | return 0; |
|
|
339 | |
|
|
340 | } |
|
|
341 | |
|
|
342 | void dump(FILE *in) |
242 | { |
343 | { |
243 | struct item_bin *ib; |
344 | struct item_bin *ib; |
244 | int min,max; |
|
|
245 | |
|
|
246 | while ((ib=read_item_range(in, &min, &max))) { |
|
|
247 | if (ib->type < 0x80000000) |
|
|
248 | processed_nodes++; |
|
|
249 | else |
|
|
250 | processed_ways++; |
|
|
251 | tile_write_item_minmax(info, ib, reference, min, max); |
|
|
252 | } |
|
|
253 | } |
|
|
254 | |
|
|
255 | static int |
|
|
256 | phase34(struct tile_info *info, struct zip_info *zip_info, FILE **in, FILE **reference, int in_count, int with_range) |
|
|
257 | { |
|
|
258 | int i; |
|
|
259 | |
|
|
260 | processed_nodes=processed_nodes_out=processed_ways=processed_relations=processed_tiles=0; |
|
|
261 | bytes_read=0; |
|
|
262 | sig_alrm(0); |
|
|
263 | if (! info->write) |
|
|
264 | tile_hash=g_hash_table_new(g_str_hash, g_str_equal); |
|
|
265 | for (i = 0 ; i < in_count ; i++) { |
|
|
266 | if (in[i]) { |
|
|
267 | if (with_range) |
|
|
268 | phase34_process_file_range(info, in[i], reference ? reference[i]:NULL); |
|
|
269 | else |
|
|
270 | phase34_process_file(info, in[i], reference ? reference[i]:NULL); |
|
|
271 | } |
|
|
272 | } |
|
|
273 | if (! info->write) |
|
|
274 | merge_tiles(info); |
|
|
275 | sig_alrm(0); |
|
|
276 | sig_alrm_end(); |
|
|
277 | write_tilesdir(info, zip_info, info->tilesdir_out); |
|
|
278 | |
|
|
279 | return 0; |
|
|
280 | |
|
|
281 | } |
|
|
282 | |
|
|
283 | |
|
|
284 | void |
|
|
285 | dump(FILE *in) |
|
|
286 | { |
|
|
287 | struct item_bin *ib; |
|
|
288 | while ((ib=read_item(in))) { |
345 | while ((ib = read_item(in, 0))) |
|
|
346 | { |
289 | dump_itembin(ib); |
347 | dump_itembin(ib); |
290 | } |
348 | } |
291 | } |
349 | } |
292 | |
350 | |
293 | int |
|
|
294 | phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info) |
351 | int phase4(FILE **in, int in_count, int with_range, char *suffix, FILE *tilesdir_out, struct zip_info *zip_info) |
295 | { |
352 | { |
296 | struct tile_info info; |
353 | struct tile_info info; |
297 | info.write=0; |
354 | info.write = 0; |
298 | info.maxlen=0; |
355 | info.maxlen = 0; |
299 | info.suffix=suffix; |
356 | info.suffix = suffix; |
300 | info.tiles_list=NULL; |
357 | info.tiles_list = NULL; |
301 | info.tilesdir_out=tilesdir_out; |
358 | info.tilesdir_out = tilesdir_out; |
302 | return phase34(&info, zip_info, in, NULL, in_count, with_range); |
359 | return phase34(&info, zip_info, in, NULL, in_count, with_range); |
303 | } |
360 | } |
304 | |
361 | |
305 | static int |
|
|
306 | process_slice(FILE **in, FILE **reference, int in_count, int with_range, long long size, char *suffix, struct zip_info *zip_info) |
362 | static int process_slice(FILE **in, FILE **reference, int in_count, int with_range, long long size, char *suffix, struct zip_info *zip_info) |
307 | { |
363 | { |
308 | struct tile_head *th; |
364 | struct tile_head *th; |
309 | char *slice_data,*zip_data; |
365 | char *slice_data, *zip_data; |
310 | int zipfiles=0; |
366 | int zipfiles = 0; |
311 | struct tile_info info; |
367 | struct tile_info info; |
312 | int i; |
368 | int i; |
313 | |
369 | |
314 | slice_data=malloc(size); |
370 | slice_data = malloc(size); |
315 | assert(slice_data != NULL); |
371 | assert(slice_data != NULL); |
316 | zip_data=slice_data; |
372 | zip_data = slice_data; |
317 | th=tile_head_root; |
373 | th = tile_head_root; |
318 | while (th) { |
374 | while (th) |
|
|
375 | { |
319 | if (th->process) { |
376 | if (th->process) |
|
|
377 | { |
320 | th->zip_data=zip_data; |
378 | th->zip_data = zip_data; |
321 | zip_data+=th->total_size; |
379 | zip_data += th->total_size; |
322 | } |
380 | } |
323 | th=th->next; |
381 | th = th->next; |
324 | } |
382 | } |
325 | for (i = 0 ; i < in_count ; i++) { |
383 | for (i = 0; i < in_count; i++) |
|
|
384 | { |
326 | if (in[i]) |
385 | if (in[i]) |
327 | fseek(in[i], 0, SEEK_SET); |
386 | fseek(in[i], 0, SEEK_SET); |
328 | if (reference && reference[i]) { |
387 | if (reference && reference[i]) |
|
|
388 | { |
329 | fseek(reference[i], 0, SEEK_SET); |
389 | fseek(reference[i], 0, SEEK_SET); |
330 | } |
390 | } |
331 | } |
391 | } |
332 | info.write=1; |
392 | info.write = 1; |
333 | info.maxlen=zip_get_maxnamelen(zip_info); |
393 | info.maxlen = zip_get_maxnamelen(zip_info); |
334 | info.suffix=suffix; |
394 | info.suffix = suffix; |
335 | info.tiles_list=NULL; |
395 | info.tiles_list = NULL; |
336 | info.tilesdir_out=NULL; |
396 | info.tilesdir_out = NULL; |
337 | phase34(&info, zip_info, in, reference, in_count, with_range); |
397 | phase34(&info, zip_info, in, reference, in_count, with_range); |
338 | |
398 | |
339 | th=tile_head_root; |
399 | th = tile_head_root; |
340 | while (th) { |
400 | while (th) |
|
|
401 | { |
341 | if (th->process) { |
402 | if (th->process) |
|
|
403 | { |
342 | if (th->name[0]) { |
404 | if (th->name[0]) |
|
|
405 | { |
343 | if (th->total_size != th->total_size_used) { |
406 | if (th->total_size != th->total_size_used) |
|
|
407 | { |
344 | fprintf(stderr,"Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used); |
408 | fprintf(stderr, "Size error '%s': %d vs %d\n", th->name, th->total_size, th->total_size_used); |
345 | exit(1); |
409 | exit(1); |
346 | } |
410 | } |
347 | write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size); |
411 | write_zipmember(zip_info, th->name, zip_get_maxnamelen(zip_info), th->zip_data, th->total_size); |
348 | zipfiles++; |
412 | zipfiles++; |
|
|
413 | } |
349 | } else |
414 | else |
350 | fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info)); |
415 | fwrite(th->zip_data, th->total_size, 1, zip_get_index(zip_info)); |
351 | } |
416 | } |
352 | th=th->next; |
417 | th = th->next; |
353 | } |
418 | } |
354 | free(slice_data); |
419 | free(slice_data); |
355 | |
420 | |
356 | return zipfiles; |
421 | return zipfiles; |
357 | } |
422 | } |
358 | |
423 | |
359 | int |
|
|
360 | phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info) |
424 | int phase5(FILE **in, FILE **references, int in_count, int with_range, char *suffix, struct zip_info *zip_info) |
361 | { |
425 | { |
362 | long long size; |
426 | long long size; |
363 | int slices; |
427 | int slices; |
364 | int zipnum,written_tiles; |
428 | int zipnum, written_tiles; |
365 | struct tile_head *th,*th2; |
429 | struct tile_head *th, *th2; |
|
|
430 | |
|
|
431 | time_t start_tt, end_tt; |
|
|
432 | double diff_tt; |
|
|
433 | double diff2_tt; |
|
|
434 | |
366 | create_tile_hash(); |
435 | create_tile_hash(); |
367 | |
436 | |
368 | th=tile_head_root; |
437 | th = tile_head_root; |
369 | size=0; |
438 | size = 0; |
370 | slices=0; |
439 | slices = 0; |
371 | fprintf(stderr, "Maximum slice size "LONGLONG_FMT"\n", slice_size); |
440 | fprintf(stderr, "Maximum slice size "LONGLONG_FMT"\n", slice_size); |
372 | while (th) { |
441 | while (th) |
|
|
442 | { |
373 | if (size + th->total_size > slice_size) { |
443 | if (size + th->total_size > slice_size) |
|
|
444 | { |
374 | fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size); |
445 | fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size); |
375 | size=0; |
446 | size = 0; |
376 | slices++; |
447 | slices++; |
377 | } |
448 | } |
378 | size+=th->total_size; |
449 | size += th->total_size; |
379 | th=th->next; |
450 | th = th->next; |
380 | } |
451 | } |
|
|
452 | |
381 | if (size) |
453 | if (size) |
|
|
454 | { |
382 | fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size); |
455 | fprintf(stderr,"Slice %d is of size "LONGLONG_FMT"\n", slices, size); |
|
|
456 | } |
|
|
457 | |
|
|
458 | int max_slices_ = slices; |
383 | th=tile_head_root; |
459 | th = tile_head_root; |
384 | size=0; |
460 | size = 0; |
385 | slices=0; |
461 | slices = 0; |
|
|
462 | |
386 | while (th) { |
463 | while (th) |
|
|
464 | { |
|
|
465 | time(&start_tt); |
|
|
466 | |
|
|
467 | fprintf(stderr,"Slice #%d of %d\n", (slices + 1), (max_slices_ + 1)); |
|
|
468 | |
387 | th2=tile_head_root; |
469 | th2 = tile_head_root; |
388 | while (th2) { |
470 | while (th2) |
|
|
471 | { |
389 | th2->process=0; |
472 | th2->process = 0; |
390 | th2=th2->next; |
473 | th2 = th2->next; |
391 | } |
474 | } |
|
|
475 | |
392 | size=0; |
476 | size = 0; |
393 | while (th && size+th->total_size < slice_size) { |
477 | while (th && size + th->total_size < slice_size) |
|
|
478 | { |
394 | size+=th->total_size; |
479 | size += th->total_size; |
395 | th->process=1; |
480 | th->process = 1; |
396 | th=th->next; |
481 | th = th->next; |
397 | } |
482 | } |
|
|
483 | |
398 | /* process_slice() modifies zip_info, but need to retain old info */ |
484 | /* process_slice() modifies zip_info, but need to retain old info */ |
399 | zipnum=zip_get_zipnum(zip_info); |
485 | zipnum = zip_get_zipnum(zip_info); |
400 | written_tiles=process_slice(in, references, in_count, with_range, size, suffix, zip_info); |
486 | written_tiles = process_slice(in, references, in_count, with_range, size, suffix, zip_info); |
401 | zip_set_zipnum(zip_info, zipnum+written_tiles); |
487 | zip_set_zipnum(zip_info, zipnum + written_tiles); |
|
|
488 | |
|
|
489 | time(&end_tt); |
|
|
490 | diff_tt = difftime(end_tt,start_tt); |
|
|
491 | char outstring[200]; |
|
|
492 | convert_to_human_time(diff_tt, outstring); |
|
|
493 | fprintf(stderr, "-RUNTIME-LOOP-PHASE5: %s this loop run\n", outstring); |
|
|
494 | diff2_tt = diff2_tt + diff_tt; |
|
|
495 | if ((slices + 1) > 0) |
|
|
496 | { |
|
|
497 | double eta_time = (diff2_tt / (slices + 1)) * (max_slices_ + 1 - (slices + 1)); |
|
|
498 | convert_to_human_time(eta_time, outstring); |
|
|
499 | fprintf(stderr, "-RUNTIME-LOOP-PHASE5: %s left\n", outstring); |
|
|
500 | } |
|
|
501 | |
402 | slices++; |
502 | slices++; |
403 | } |
503 | } |
|
|
504 | |
404 | return 0; |
505 | return 0; |
405 | } |
506 | } |
406 | |
507 | |
407 | void |
|
|
408 | process_binfile(FILE *in, FILE *out) |
508 | void process_binfile(FILE *in, FILE *out) |
409 | { |
509 | { |
410 | struct item_bin *ib; |
510 | struct item_bin *ib; |
411 | while ((ib=read_item(in))) { |
511 | while ((ib = read_item(in, 0))) |
|
|
512 | { |
412 | fwrite(ib, (ib->len+1)*4, 1, out); |
513 | fwrite(ib, (ib->len + 1) * 4, 1, out); |
413 | } |
514 | } |
414 | } |
515 | } |
415 | |
516 | |
416 | void |
|
|
417 | add_aux_tiles(char *name, struct zip_info *info) |
517 | void add_aux_tiles(char *name, struct zip_info *info) |
418 | { |
518 | { |
419 | char buffer[4096]; |
519 | char buffer[4096]; |
420 | char *s; |
520 | char *s; |
421 | FILE *in; |
521 | FILE *in; |
422 | FILE *tmp; |
522 | FILE *tmp; |
423 | in=fopen(name,"rb"); |
523 | in = fopen(name, "rb"); |
424 | if (!in) |
524 | if (!in) |
425 | return; |
525 | return; |
426 | while (fscanf(in,"%s",buffer) == 1) { |
526 | while (fscanf(in, "%s", buffer) == 1) |
|
|
527 | { |
427 | s=strchr(buffer,'/'); |
528 | s = strchr(buffer, '/'); |
428 | if (s) |
529 | if (s) |
429 | s++; |
530 | s++; |
430 | else |
531 | else |
431 | s=buffer; |
532 | s = buffer; |
432 | tmp=fopen(buffer,"rb"); |
533 | tmp = fopen(buffer, "rb"); |
433 | if (tmp) { |
534 | if (tmp) |
|
|
535 | { |
434 | fseek(tmp, 0, SEEK_END); |
536 | fseek(tmp, 0, SEEK_END); |
435 | add_aux_tile(info, s, buffer, ftell(tmp)); |
537 | add_aux_tile(info, s, buffer, ftell(tmp)); |
436 | fclose(tmp); |
538 | fclose(tmp); |
437 | } |
539 | } |
438 | } |
540 | } |