|
|
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> |
… | |
… | |
44 | |
62 | |
45 | #include "maptool.h" |
63 | #include "maptool.h" |
46 | |
64 | |
47 | GList *aux_tile_list; |
65 | GList *aux_tile_list; |
48 | struct tile_head *tile_head_root; |
66 | struct tile_head *tile_head_root; |
49 | GHashTable *strings_hash,*tile_hash,*tile_hash2; |
67 | GHashTable *strings_hash, *tile_hash, *tile_hash2; |
50 | |
68 | |
51 | static char* string_hash_lookup( const char* key ) |
69 | static char* string_hash_lookup(const char* key) |
52 | { |
70 | { |
53 | char* key_ptr = NULL; |
71 | char* key_ptr = NULL; |
54 | |
72 | |
55 | if ( strings_hash == NULL ) { |
73 | if (strings_hash == NULL) |
|
|
74 | { |
56 | strings_hash = g_hash_table_new(g_str_hash, g_str_equal); |
75 | strings_hash = g_hash_table_new(g_str_hash, g_str_equal); |
57 | } |
76 | } |
58 | |
77 | |
59 | if ( ( key_ptr = g_hash_table_lookup(strings_hash, key )) == NULL ) { |
78 | if ((key_ptr = g_hash_table_lookup(strings_hash, key)) == NULL) |
|
|
79 | { |
60 | key_ptr = g_strdup( key ); |
80 | key_ptr = g_strdup(key); |
61 | g_hash_table_insert(strings_hash, key_ptr, (gpointer)key_ptr ); |
81 | g_hash_table_insert(strings_hash, key_ptr, (gpointer) key_ptr); |
62 | |
82 | |
63 | } |
83 | } |
64 | return key_ptr; |
84 | return key_ptr; |
65 | } |
85 | } |
66 | |
86 | |
67 | static char** th_get_subtile( const struct tile_head* th, int idx ) |
87 | static char** th_get_subtile(const struct tile_head* th, int idx) |
68 | { |
88 | { |
69 | char* subtile_ptr = NULL; |
89 | char* subtile_ptr = NULL; |
70 | subtile_ptr = (char*)th + sizeof( struct tile_head ) + idx * sizeof( char *); |
90 | subtile_ptr = (char*) th + sizeof(struct tile_head) + idx * sizeof(char *); |
71 | return (char**)subtile_ptr; |
91 | return (char**) subtile_ptr; |
72 | } |
92 | } |
73 | |
93 | |
74 | int |
|
|
75 | tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr) |
94 | int tile(struct rect *r, char *suffix, char *ret, int max, int overlap, struct rect *tr) |
76 | { |
95 | { |
77 | int x0,x2,x4; |
96 | int x0, x2, x4; |
78 | int y0,y2,y4; |
97 | int y0, y2, y4; |
79 | int xo,yo; |
98 | int xo, yo; |
80 | int i; |
99 | int i; |
81 | x0=world_bbox.l.x; |
100 | x0 = world_bbox.l.x; |
82 | y0=world_bbox.l.y; |
101 | y0 = world_bbox.l.y; |
83 | x4=world_bbox.h.x; |
102 | x4 = world_bbox.h.x; |
84 | y4=world_bbox.h.y; |
103 | y4 = world_bbox.h.y; |
85 | for (i = 0 ; i < max ; i++) { |
104 | for (i = 0; i < max; i++) |
|
|
105 | { |
86 | x2=(x0+x4)/2; |
106 | x2 = (x0 + x4) / 2; |
87 | y2=(y0+y4)/2; |
107 | y2 = (y0 + y4) / 2; |
88 | xo=(x4-x0)*overlap/100; |
108 | xo = (x4 - x0) * overlap / 100; |
89 | yo=(y4-y0)*overlap/100; |
109 | yo = (y4 - y0) * overlap / 100; |
90 | if ( contains_bbox(x0,y0,x2+xo,y2+yo,r)) { |
110 | if (contains_bbox(x0, y0, x2 + xo, y2 + yo, r)) |
|
|
111 | { |
91 | strcat(ret,"d"); |
112 | strcat(ret, "d"); |
92 | x4=x2+xo; |
113 | x4 = x2 + xo; |
93 | y4=y2+yo; |
114 | y4 = y2 + yo; |
|
|
115 | } |
94 | } else if (contains_bbox(x2-xo,y0,x4,y2+yo,r)) { |
116 | else if (contains_bbox(x2 - xo, y0, x4, y2 + yo, r)) |
|
|
117 | { |
95 | strcat(ret,"c"); |
118 | strcat(ret, "c"); |
96 | x0=x2-xo; |
119 | x0 = x2 - xo; |
97 | y4=y2+yo; |
120 | y4 = y2 + yo; |
|
|
121 | } |
98 | } else if (contains_bbox(x0,y2-yo,x2+xo,y4,r)) { |
122 | else if (contains_bbox(x0, y2 - yo, x2 + xo, y4, r)) |
|
|
123 | { |
99 | strcat(ret,"b"); |
124 | strcat(ret, "b"); |
100 | x4=x2+xo; |
125 | x4 = x2 + xo; |
101 | y0=y2-yo; |
126 | y0 = y2 - yo; |
|
|
127 | } |
102 | } else if (contains_bbox(x2-xo,y2-yo,x4,y4,r)) { |
128 | else if (contains_bbox(x2 - xo, y2 - yo, x4, y4, r)) |
|
|
129 | { |
103 | strcat(ret,"a"); |
130 | strcat(ret, "a"); |
104 | x0=x2-xo; |
131 | x0 = x2 - xo; |
105 | y0=y2-yo; |
132 | y0 = y2 - yo; |
|
|
133 | } |
106 | } else |
134 | else |
107 | break; |
135 | break; |
108 | } |
136 | } |
109 | if (tr) { |
137 | if (tr) |
|
|
138 | { |
110 | tr->l.x=x0; |
139 | tr->l.x = x0; |
111 | tr->l.y=y0; |
140 | tr->l.y = y0; |
112 | tr->h.x=x4; |
141 | tr->h.x = x4; |
113 | tr->h.y=y4; |
142 | tr->h.y = y4; |
114 | } |
143 | } |
115 | if (suffix) |
144 | if (suffix) |
116 | strcat(ret,suffix); |
145 | strcat(ret, suffix); |
117 | return i; |
146 | return i; |
118 | } |
147 | } |
119 | |
148 | |
120 | void |
|
|
121 | tile_bbox(char *tile, struct rect *r, int overlap) |
149 | void tile_bbox(char *tile, struct rect *r, int overlap) |
122 | { |
150 | { |
123 | struct coord c; |
151 | struct coord c; |
124 | int xo,yo; |
152 | int xo, yo; |
125 | *r=world_bbox; |
153 | *r = world_bbox; |
126 | while (*tile) { |
154 | while (*tile) |
|
|
155 | { |
127 | c.x=(r->l.x+r->h.x)/2; |
156 | c.x = (r->l.x + r->h.x) / 2; |
128 | c.y=(r->l.y+r->h.y)/2; |
157 | c.y = (r->l.y + r->h.y) / 2; |
129 | xo=(r->h.x-r->l.x)*overlap/100; |
158 | xo = (r->h.x - r->l.x) * overlap / 100; |
130 | yo=(r->h.y-r->l.y)*overlap/100; |
159 | yo = (r->h.y - r->l.y) * overlap / 100; |
131 | switch (*tile) { |
160 | switch (*tile) |
|
|
161 | { |
132 | case 'a': |
162 | case 'a': |
133 | r->l.x=c.x-xo; |
163 | r->l.x = c.x - xo; |
134 | r->l.y=c.y-yo; |
164 | r->l.y = c.y - yo; |
135 | break; |
165 | break; |
136 | case 'b': |
166 | case 'b': |
137 | r->h.x=c.x+xo; |
167 | r->h.x = c.x + xo; |
138 | r->l.y=c.y-yo; |
168 | r->l.y = c.y - yo; |
139 | break; |
169 | break; |
140 | case 'c': |
170 | case 'c': |
141 | r->l.x=c.x-xo; |
171 | r->l.x = c.x - xo; |
142 | r->h.y=c.y+yo; |
172 | r->h.y = c.y + yo; |
143 | break; |
173 | break; |
144 | case 'd': |
174 | case 'd': |
145 | r->h.x=c.x+xo; |
175 | r->h.x = c.x + xo; |
146 | r->h.y=c.y+yo; |
176 | r->h.y = c.y + yo; |
147 | break; |
177 | break; |
148 | } |
178 | } |
149 | tile++; |
179 | tile++; |
150 | } |
180 | } |
151 | } |
181 | } |
152 | |
182 | |
153 | int |
|
|
154 | tile_len(char *tile) |
183 | int tile_len(char *tile) |
155 | { |
184 | { |
156 | int ret=0; |
185 | int ret = 0; |
157 | while (tile[0] >= 'a' && tile[0] <= 'd') { |
186 | while (tile[0] >= 'a' && tile[0] <= 'd') |
|
|
187 | { |
158 | tile++; |
188 | tile++; |
159 | ret++; |
189 | ret++; |
160 | } |
190 | } |
161 | return ret; |
191 | return ret; |
162 | } |
192 | } |
163 | |
193 | |
164 | static void |
|
|
165 | tile_extend(char *tile, struct item_bin *ib, GList **tiles_list) |
194 | static void tile_extend(char *tile, struct item_bin *ib, GList **tiles_list) |
166 | { |
195 | { |
167 | struct tile_head *th=NULL; |
196 | struct tile_head *th = NULL; |
168 | if (debug_tile(tile)) |
197 | if (debug_tile(tile)) |
|
|
198 | { |
169 | fprintf(stderr,"Tile:Writing %d bytes to '%s' (%p,%p) 0x%x "LONGLONG_FMT"\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type, item_bin_get_id(ib)); |
199 | fprintf (stderr,"Tile:Writing %d bytes to '%s' (%p,%p) 0x%x "LONGLONG_FMT"\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type, item_bin_get_id(ib)); |
|
|
200 | } |
|
|
201 | if (tile_hash2) |
|
|
202 | th=g_hash_table_lookup(tile_hash2, tile); |
|
|
203 | if (!th) |
|
|
204 | th=g_hash_table_lookup(tile_hash, tile); |
|
|
205 | if (! th) |
|
|
206 | { |
|
|
207 | th=malloc(sizeof(struct tile_head)+ sizeof( char* ) ); |
|
|
208 | assert(th != NULL); |
|
|
209 | // strcpy(th->subtiles, tile); |
|
|
210 | th->num_subtiles=1; |
|
|
211 | th->total_size=0; |
|
|
212 | th->total_size_used=0; |
|
|
213 | th->zipnum=0; |
|
|
214 | th->zip_data=NULL; |
|
|
215 | th->name=string_hash_lookup(tile); |
|
|
216 | *th_get_subtile( th, 0 ) = th->name; |
|
|
217 | |
170 | if (tile_hash2) |
218 | if (tile_hash2) |
|
|
219 | g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th); |
|
|
220 | if (tiles_list) |
|
|
221 | *tiles_list=g_list_append(*tiles_list, string_hash_lookup( th->name ) ); |
|
|
222 | processed_tiles++; |
|
|
223 | if (debug_tile(tile)) |
|
|
224 | fprintf(stderr,"new '%s'\n", tile); |
|
|
225 | } |
|
|
226 | th->total_size+=ib->len*4+4; |
|
|
227 | if (debug_tile(tile)) |
|
|
228 | { |
|
|
229 | fprintf(stderr,"New total size of %s(%p):%d\n", th->name, th, th->total_size); |
|
|
230 | } |
|
|
231 | g_hash_table_insert(tile_hash, string_hash_lookup( th->name ), th); |
|
|
232 | } |
|
|
233 | |
|
|
234 | static int tile_data_size(char *tile) |
|
|
235 | { |
|
|
236 | struct tile_head *th; |
171 | th=g_hash_table_lookup(tile_hash2, tile); |
237 | th = g_hash_table_lookup(tile_hash, tile); |
172 | if (!th) |
238 | if (!th) |
173 | th=g_hash_table_lookup(tile_hash, tile); |
239 | { |
174 | if (! th) { |
|
|
175 | th=malloc(sizeof(struct tile_head)+ sizeof( char* ) ); |
|
|
176 | assert(th != NULL); |
|
|
177 | // strcpy(th->subtiles, tile); |
|
|
178 | th->num_subtiles=1; |
|
|
179 | th->total_size=0; |
|
|
180 | th->total_size_used=0; |
|
|
181 | th->zipnum=0; |
|
|
182 | th->zip_data=NULL; |
|
|
183 | th->name=string_hash_lookup(tile); |
|
|
184 | *th_get_subtile( th, 0 ) = th->name; |
|
|
185 | |
|
|
186 | if (tile_hash2) |
|
|
187 | g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th); |
|
|
188 | if (tiles_list) |
|
|
189 | *tiles_list=g_list_append(*tiles_list, string_hash_lookup( th->name ) ); |
|
|
190 | processed_tiles++; |
|
|
191 | if (debug_tile(tile)) |
|
|
192 | fprintf(stderr,"new '%s'\n", tile); |
|
|
193 | } |
|
|
194 | th->total_size+=ib->len*4+4; |
|
|
195 | if (debug_tile(tile)) |
|
|
196 | fprintf(stderr,"New total size of %s(%p):%d\n", th->name, th, th->total_size); |
|
|
197 | g_hash_table_insert(tile_hash, string_hash_lookup( th->name ), th); |
|
|
198 | } |
|
|
199 | |
|
|
200 | static int |
|
|
201 | tile_data_size(char *tile) |
|
|
202 | { |
|
|
203 | struct tile_head *th; |
|
|
204 | th=g_hash_table_lookup(tile_hash, tile); |
|
|
205 | if (! th) |
|
|
206 | return 0; |
240 | return 0; |
|
|
241 | } |
207 | return th->total_size; |
242 | return th->total_size; |
208 | } |
243 | } |
209 | |
244 | |
210 | static int |
|
|
211 | merge_tile(char *base, char *sub) |
245 | static int merge_tile(char *base, char *sub) |
212 | { |
246 | { |
213 | struct tile_head *thb, *ths; |
247 | struct tile_head *thb, *ths; |
214 | thb=g_hash_table_lookup(tile_hash, base); |
248 | thb = g_hash_table_lookup(tile_hash, base); |
215 | ths=g_hash_table_lookup(tile_hash, sub); |
249 | ths = g_hash_table_lookup(tile_hash, sub); |
216 | if (! ths) |
250 | if (!ths) |
|
|
251 | { |
217 | return 0; |
252 | return 0; |
|
|
253 | } |
218 | if (debug_tile(base) || debug_tile(sub)) |
254 | if (debug_tile(base) || debug_tile(sub)) |
219 | fprintf(stderr,"merging '%s'(%p) (%d) with '%s'(%p) (%d)\n", base, thb, thb ? thb->total_size : 0, sub, ths, ths->total_size); |
255 | fprintf(stderr, "merging '%s'(%p) (%d) with '%s'(%p) (%d)\n", base, thb, thb ? thb->total_size : 0, sub, ths, ths->total_size); |
220 | if (! thb) { |
256 | if (!thb) |
|
|
257 | { |
221 | thb=ths; |
258 | thb = ths; |
222 | g_hash_table_remove(tile_hash, sub); |
259 | g_hash_table_remove(tile_hash, sub); |
223 | thb->name=string_hash_lookup(base); |
260 | thb->name = string_hash_lookup(base); |
224 | g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb); |
261 | g_hash_table_insert(tile_hash, string_hash_lookup(thb->name), thb); |
225 | |
262 | |
226 | } else { |
263 | } |
|
|
264 | else |
|
|
265 | { |
227 | thb=realloc(thb, sizeof(struct tile_head)+( ths->num_subtiles+thb->num_subtiles ) * sizeof( char*) ); |
266 | thb = realloc(thb, sizeof(struct tile_head) + (ths->num_subtiles + thb->num_subtiles) * sizeof(char*)); |
228 | assert(thb != NULL); |
267 | assert(thb != NULL); |
229 | memcpy( th_get_subtile( thb, thb->num_subtiles ), th_get_subtile( ths, 0 ), ths->num_subtiles * sizeof( char*) ); |
268 | memcpy(th_get_subtile(thb, thb->num_subtiles), th_get_subtile(ths, 0), ths->num_subtiles * sizeof(char*)); |
230 | thb->num_subtiles+=ths->num_subtiles; |
269 | thb->num_subtiles += ths->num_subtiles; |
231 | thb->total_size+=ths->total_size; |
270 | thb->total_size += ths->total_size; |
232 | g_hash_table_insert(tile_hash, string_hash_lookup( thb->name ), thb); |
271 | g_hash_table_insert(tile_hash, string_hash_lookup(thb->name), thb); |
233 | g_hash_table_remove(tile_hash, sub); |
272 | g_hash_table_remove(tile_hash, sub); |
234 | g_free(ths); |
273 | g_free(ths); |
235 | } |
274 | } |
236 | return 1; |
275 | return 1; |
237 | } |
276 | } |
238 | |
277 | |
239 | static gint |
|
|
240 | get_tiles_list_cmp(gconstpointer s1, gconstpointer s2) |
278 | static gint get_tiles_list_cmp(gconstpointer s1, gconstpointer s2) |
241 | { |
279 | { |
242 | return strcmp((char *)s1, (char *)s2); |
280 | return strcmp((char *) s1, (char *) s2); |
243 | } |
281 | } |
244 | |
282 | |
245 | static void |
|
|
246 | get_tiles_list_func(char *key, struct tile_head *th, GList **list) |
283 | static void get_tiles_list_func(char *key, struct tile_head *th, GList **list) |
247 | { |
284 | { |
248 | *list=g_list_prepend(*list, key); |
285 | *list = g_list_prepend(*list, key); |
249 | } |
286 | } |
250 | |
287 | |
251 | static GList * |
288 | static GList * |
252 | get_tiles_list(void) |
289 | get_tiles_list(void) |
253 | { |
290 | { |
254 | GList *ret=NULL; |
291 | GList *ret = NULL; |
255 | g_hash_table_foreach(tile_hash, (GHFunc)get_tiles_list_func, &ret); |
292 | g_hash_table_foreach(tile_hash, (GHFunc) get_tiles_list_func, &ret); |
256 | ret=g_list_sort(ret, get_tiles_list_cmp); |
293 | ret = g_list_sort(ret, get_tiles_list_cmp); |
257 | return ret; |
294 | return ret; |
258 | } |
295 | } |
259 | |
296 | |
260 | #if 0 |
297 | #if 0 |
261 | static void |
298 | static void |
… | |
… | |
268 | strcat(buffer,key); |
305 | strcat(buffer,key); |
269 | #if 0 |
306 | #if 0 |
270 | strcat(buffer,".bin"); |
307 | strcat(buffer,".bin"); |
271 | #endif |
308 | #endif |
272 | f=fopen(buffer, "wb+"); |
309 | f=fopen(buffer, "wb+"); |
273 | while (th) { |
310 | while (th) |
|
|
311 | { |
274 | fwrite(th->data, th->size, 1, f); |
312 | fwrite(th->data, th->size, 1, f); |
275 | th=th->next; |
313 | th=th->next; |
276 | } |
314 | } |
277 | fclose(f); |
315 | fclose(f); |
278 | } |
316 | } |
279 | #endif |
317 | #endif |
280 | |
318 | |
281 | static void |
|
|
282 | write_item(char *tile, struct item_bin *ib, FILE *reference) |
319 | static void write_item(char *tile, struct item_bin *ib, FILE *reference) |
283 | { |
320 | { |
284 | struct tile_head *th; |
321 | struct tile_head *th; |
285 | int size; |
322 | int size; |
286 | |
323 | |
287 | th=g_hash_table_lookup(tile_hash2, tile); |
324 | th = g_hash_table_lookup(tile_hash2, tile); |
288 | if (debug_itembin(ib)) { |
325 | if (debug_itembin(ib)) |
|
|
326 | { |
|
|
327 | fprintf(stderr, "write_item: == START == TILE: %s == File: %p\n", tile, reference); |
289 | fprintf(stderr,"tile head %p\n",th); |
328 | fprintf(stderr, "tile head %p\n", th); |
|
|
329 | |
|
|
330 | fprintf(stderr, "== TILE:item_START ==\n"); |
|
|
331 | dump_itembin(ib); |
|
|
332 | fprintf(stderr, "== TILE:item_END ==\n"); |
290 | } |
333 | } |
291 | if (! th) |
334 | if (!th) |
292 | th=g_hash_table_lookup(tile_hash, tile); |
335 | th = g_hash_table_lookup(tile_hash, tile); |
293 | if (th) { |
336 | if (th) |
|
|
337 | { |
294 | if (debug_itembin(ib)) { |
338 | if (debug_itembin(ib)) |
|
|
339 | { |
295 | fprintf(stderr,"Match %s %d %s\n",tile,th->process,th->name); |
340 | fprintf(stderr, "Match %s %d %s\n", tile, th->process, th->name); |
296 | dump_itembin(ib); |
341 | dump_itembin(ib); |
297 | } |
342 | } |
298 | if (th->process != 0 && th->process != 1) { |
343 | if (th->process != 0 && th->process != 1) |
|
|
344 | { |
299 | fprintf(stderr,"error with tile '%s' of length %d\n", tile, (int)strlen(tile)); |
345 | fprintf(stderr, "error with tile '%s' of length %d\n", tile, (int) strlen(tile)); |
300 | abort(); |
346 | abort(); |
301 | } |
347 | } |
302 | if (! th->process) { |
348 | if (!th->process) |
|
|
349 | { |
303 | if (reference) |
350 | if (reference) |
304 | fseek(reference, 8, SEEK_CUR); |
351 | fseek(reference, 8, SEEK_CUR); |
305 | return; |
352 | return; |
306 | } |
353 | } |
307 | if (debug_tile(tile)) |
354 | if (debug_tile(tile)) |
|
|
355 | { |
308 | fprintf(stderr,"Data:Writing %d bytes to '%s' (%p,%p) 0x%x\n", (ib->len+1)*4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type); |
356 | fprintf(stderr, "Data:Writing %d bytes to '%s' (%p,%p) 0x%x\n", (ib->len + 1) * 4, tile, g_hash_table_lookup(tile_hash, tile), tile_hash2 ? g_hash_table_lookup(tile_hash2, tile) : NULL, ib->type); |
|
|
357 | } |
309 | size=(ib->len+1)*4; |
358 | size = (ib->len + 1) * 4; |
310 | if (th->total_size_used+size > th->total_size) { |
359 | if (th->total_size_used + size > th->total_size) |
|
|
360 | { |
311 | fprintf(stderr,"Overflow in tile %s (used %d max %d item %d)\n", tile, th->total_size_used, th->total_size, size); |
361 | fprintf(stderr, "Overflow in tile %s (used %d max %d item %d)\n", tile, th->total_size_used, th->total_size, size); |
312 | exit(1); |
362 | exit(1); |
313 | return; |
363 | return; |
314 | } |
364 | } |
315 | if (reference) { |
365 | if (reference) |
|
|
366 | { |
316 | int offset=th->total_size_used/4; |
367 | int offset = th->total_size_used / 4; |
317 | fwrite(&th->zipnum, sizeof(th->zipnum), 1, reference); |
368 | fwrite(&th->zipnum, sizeof(th->zipnum), 1, reference); |
318 | fwrite(&offset, sizeof(th->total_size_used), 1, reference); |
369 | fwrite(&offset, sizeof(th->total_size_used), 1, reference); |
319 | } |
370 | } |
320 | if (th->zip_data) |
371 | if (th->zip_data) |
321 | memcpy(th->zip_data+th->total_size_used, ib, size); |
372 | memcpy(th->zip_data + th->total_size_used, ib, size); |
322 | th->total_size_used+=size; |
373 | th->total_size_used += size; |
323 | } else { |
374 | } |
|
|
375 | else |
|
|
376 | { |
324 | fprintf(stderr,"no tile hash found for %s\n", tile); |
377 | fprintf(stderr, "no tile hash found for %s\n", tile); |
325 | exit(1); |
378 | exit(1); |
326 | } |
379 | } |
327 | } |
380 | } |
328 | |
381 | |
329 | void |
|
|
330 | tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name) |
382 | void tile_write_item_to_tile(struct tile_info *info, struct item_bin *ib, FILE *reference, char *name) |
331 | { |
383 | { |
332 | if (info->write) |
384 | if (info->write) |
333 | write_item(name, ib, reference); |
385 | write_item(name, ib, reference); |
334 | else |
386 | else |
335 | tile_extend(name, ib, info->tiles_list); |
387 | tile_extend(name, ib, info->tiles_list); |
336 | } |
388 | } |
337 | |
389 | |
338 | void |
|
|
339 | tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max) |
390 | void tile_write_item_minmax(struct tile_info *info, struct item_bin *ib, FILE *reference, int min, int max) |
340 | { |
391 | { |
341 | struct rect r; |
392 | struct rect r; |
342 | char buffer[1024]; |
393 | char buffer[1024]; |
343 | bbox((struct coord *)(ib+1), ib->clen/2, &r); |
394 | bbox((struct coord *) (ib + 1), ib->clen / 2, &r); |
344 | buffer[0]='\0'; |
395 | buffer[0] = '\0'; |
345 | tile(&r, info->suffix, buffer, max, overlap, NULL); |
396 | tile(&r, info->suffix, buffer, max, overlap, NULL); |
346 | tile_write_item_to_tile(info, ib, reference, buffer); |
397 | tile_write_item_to_tile(info, ib, reference, buffer); |
347 | } |
398 | } |
348 | |
399 | |
349 | int |
|
|
350 | add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size) |
400 | int add_aux_tile(struct zip_info *zip_info, char *name, char *filename, int size) |
351 | { |
401 | { |
352 | struct aux_tile *at; |
402 | struct aux_tile *at; |
353 | GList *l; |
403 | GList *l; |
354 | l=aux_tile_list; |
404 | l = aux_tile_list; |
355 | while (l) { |
405 | while (l) |
|
|
406 | { |
356 | at=l->data; |
407 | at = l->data; |
357 | if (!strcmp(at->name, name)) { |
408 | if (!strcmp(at->name, name)) |
|
|
409 | { |
358 | fprintf(stderr,"exists %s vs %s\n",at->name, name); |
410 | fprintf(stderr, "exists %s vs %s\n", at->name, name); |
359 | return -1; |
411 | return -1; |
360 | } |
412 | } |
361 | l=g_list_next(l); |
413 | l = g_list_next(l); |
362 | } |
|
|
363 | at=g_new0(struct aux_tile, 1); |
414 | } at=g_new0(struct aux_tile, 1); |
364 | at->name=g_strdup(name); |
415 | at->name = g_strdup(name); |
365 | at->filename=g_strdup(filename); |
416 | at->filename = g_strdup(filename); |
366 | at->size=size; |
417 | at->size = size; |
367 | aux_tile_list=g_list_append(aux_tile_list, at); |
418 | aux_tile_list = g_list_append(aux_tile_list, at); |
368 | return zip_add_member(zip_info); |
419 | return zip_add_member(zip_info); |
369 | } |
420 | } |
370 | |
421 | |
371 | int |
|
|
372 | write_aux_tiles(struct zip_info *zip_info) |
422 | int write_aux_tiles(struct zip_info *zip_info) |
373 | { |
423 | { |
374 | GList *l=aux_tile_list; |
424 | GList *l = aux_tile_list; |
375 | struct aux_tile *at; |
425 | struct aux_tile *at; |
376 | char *buffer; |
426 | char *buffer; |
377 | FILE *f; |
427 | FILE *f; |
378 | int count=0; |
428 | int count = 0; |
379 | |
429 | |
380 | while (l) { |
430 | while (l) |
|
|
431 | { |
381 | at=l->data; |
432 | at = l->data; |
382 | buffer=malloc(at->size); |
433 | buffer = malloc(at->size); |
383 | assert(buffer != NULL); |
434 | assert(buffer != NULL); |
384 | f=fopen(at->filename,"rb"); |
435 | f = fopen(at->filename, "rb"); |
385 | assert(f != NULL); |
436 | assert(f != NULL); |
386 | fread(buffer, at->size, 1, f); |
437 | fread(buffer, at->size, 1, f); |
387 | fclose(f); |
438 | fclose(f); |
388 | write_zipmember(zip_info, at->name, zip_get_maxnamelen(zip_info), buffer, at->size); |
439 | write_zipmember(zip_info, at->name, zip_get_maxnamelen(zip_info), buffer, at->size); |
389 | free(buffer); |
440 | free(buffer); |
390 | count++; |
441 | count++; |
391 | l=g_list_next(l); |
442 | l = g_list_next(l); |
392 | zip_add_member(zip_info); |
443 | zip_add_member(zip_info); |
393 | } |
444 | } |
394 | return count; |
445 | return count; |
395 | } |
446 | } |
396 | |
447 | |
397 | static int |
|
|
398 | add_tile_hash(struct tile_head *th) |
448 | static int add_tile_hash(struct tile_head *th) |
399 | { |
449 | { |
400 | int idx,len,maxnamelen=0; |
450 | int idx, len, maxnamelen = 0; |
401 | char **data; |
451 | char **data; |
402 | |
452 | |
403 | #if 0 |
453 | #if 0 |
404 | g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th); |
454 | g_hash_table_insert(tile_hash2, string_hash_lookup( th->name ), th); |
405 | #endif |
455 | #endif |
406 | for( idx = 0; idx < th->num_subtiles; idx++ ) { |
456 | for (idx = 0; idx < th->num_subtiles; idx++) |
|
|
457 | { |
407 | |
458 | |
408 | data = th_get_subtile( th, idx ); |
459 | data = th_get_subtile(th, idx); |
409 | |
460 | |
410 | if (debug_tile(((char *)data)) || debug_tile(th->name)) { |
461 | if (debug_tile(((char *) data)) || debug_tile(th->name)) |
|
|
462 | { |
411 | fprintf(stderr,"Parent for '%s' is '%s'\n", *data, th->name); |
463 | fprintf(stderr, "Parent for '%s' is '%s'\n", *data, th->name); |
412 | } |
464 | } |
413 | |
465 | |
414 | g_hash_table_insert(tile_hash2, *data, th); |
466 | g_hash_table_insert(tile_hash2, *data, th); |
415 | |
467 | |
416 | len = strlen( *data ); |
468 | len = strlen(*data); |
417 | |
469 | |
418 | if (len > maxnamelen) { |
470 | if (len > maxnamelen) |
|
|
471 | { |
419 | maxnamelen=len; |
472 | maxnamelen = len; |
420 | } |
473 | } |
421 | } |
474 | } |
422 | return maxnamelen; |
475 | return maxnamelen; |
423 | } |
476 | } |
424 | |
477 | |
425 | |
|
|
426 | int |
|
|
427 | create_tile_hash(void) |
478 | int create_tile_hash(void) |
428 | { |
479 | { |
429 | struct tile_head *th; |
480 | struct tile_head *th; |
430 | int len,maxnamelen=0; |
481 | int len, maxnamelen = 0; |
431 | |
482 | |
432 | tile_hash2=g_hash_table_new(g_str_hash, g_str_equal); |
483 | tile_hash2 = g_hash_table_new(g_str_hash, g_str_equal); |
433 | th=tile_head_root; |
484 | th = tile_head_root; |
434 | while (th) { |
485 | while (th) |
|
|
486 | { |
435 | len=add_tile_hash(th); |
487 | len = add_tile_hash(th); |
436 | if (len > maxnamelen) |
488 | if (len > maxnamelen) |
437 | maxnamelen=len; |
489 | maxnamelen = len; |
438 | th=th->next; |
490 | th = th->next; |
439 | } |
491 | } |
440 | return maxnamelen; |
492 | return maxnamelen; |
441 | } |
493 | } |
442 | |
494 | |
443 | static void |
|
|
444 | create_tile_hash_list(GList *list) |
495 | static void create_tile_hash_list(GList *list) |
445 | { |
496 | { |
446 | GList *next; |
497 | GList *next; |
447 | struct tile_head *th; |
498 | struct tile_head *th; |
448 | |
499 | |
449 | tile_hash2=g_hash_table_new(g_str_hash, g_str_equal); |
500 | tile_hash2 = g_hash_table_new(g_str_hash, g_str_equal); |
450 | |
501 | |
451 | next=g_list_first(list); |
502 | next = g_list_first(list); |
452 | while (next) { |
503 | while (next) |
|
|
504 | { |
453 | th=g_hash_table_lookup(tile_hash, next->data); |
505 | th = g_hash_table_lookup(tile_hash, next->data); |
454 | if (!th) { |
506 | if (!th) |
|
|
507 | { |
455 | fprintf(stderr,"No tile found for '%s'\n", (char *)(next->data)); |
508 | fprintf(stderr, "No tile found for '%s'\n", (char *) (next->data)); |
456 | } |
509 | } |
457 | add_tile_hash(th); |
510 | add_tile_hash(th); |
458 | next=g_list_next(next); |
511 | next = g_list_next(next); |
459 | } |
512 | } |
460 | } |
513 | } |
461 | |
514 | |
462 | void |
|
|
463 | write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out) |
515 | void write_tilesdir(struct tile_info *info, struct zip_info *zip_info, FILE *out) |
464 | { |
516 | { |
465 | int idx,len,maxlen; |
517 | int idx, len, maxlen; |
466 | GList *next,*tiles_list; |
518 | GList *next, *tiles_list; |
467 | char **data; |
519 | char **data; |
468 | struct tile_head *th,**last=NULL; |
520 | struct tile_head *th, **last = NULL; |
469 | |
521 | |
470 | tiles_list=get_tiles_list(); |
522 | tiles_list = get_tiles_list(); |
471 | info->tiles_list=&tiles_list; |
523 | info->tiles_list = &tiles_list; |
472 | if (phase == 3) |
524 | // if (phase == 3) |
|
|
525 | if (!info->write) |
|
|
526 | { |
473 | create_tile_hash_list(tiles_list); |
527 | create_tile_hash_list(tiles_list); |
|
|
528 | } |
474 | next=g_list_first(tiles_list); |
529 | next = g_list_first(tiles_list); |
475 | last=&tile_head_root; |
530 | last = &tile_head_root; |
476 | maxlen=info->maxlen; |
531 | maxlen = info->maxlen; |
477 | if (! maxlen) { |
532 | if (!maxlen) |
|
|
533 | { |
478 | while (next) { |
534 | while (next) |
|
|
535 | { |
479 | if (strlen(next->data) > maxlen) |
536 | if (strlen(next->data) > maxlen) |
|
|
537 | { |
480 | maxlen=strlen(next->data); |
538 | maxlen = strlen(next->data); |
|
|
539 | } |
481 | next=g_list_next(next); |
540 | next = g_list_next(next); |
482 | } |
|
|
483 | } |
541 | } |
|
|
542 | } |
|
|
543 | |
484 | len=maxlen; |
544 | len = maxlen; |
485 | while (len >= 0) { |
545 | while (len >= 0) |
|
|
546 | { |
486 | #if 0 |
547 | #if 0 |
487 | fprintf(stderr,"PROGRESS: collecting tiles with len=%d\n", len); |
548 | fprintf(stderr,"PROGRESS: collecting tiles with len=%d\n", len); |
488 | #endif |
549 | #endif |
489 | next=g_list_first(tiles_list); |
550 | next = g_list_first(tiles_list); |
490 | while (next) { |
551 | while (next) |
|
|
552 | { |
491 | if (strlen(next->data) == len) { |
553 | if (strlen(next->data) == len) |
|
|
554 | { |
492 | th=g_hash_table_lookup(tile_hash, next->data); |
555 | th = g_hash_table_lookup(tile_hash, next->data); |
493 | if (phase == 3) { |
556 | // if (phase == 3) |
|
|
557 | if (!info->write) |
|
|
558 | { |
494 | *last=th; |
559 | *last = th; |
495 | last=&th->next; |
560 | last = &th->next; |
496 | th->next=NULL; |
561 | th->next = NULL; |
497 | th->zipnum=zip_get_zipnum(zip_info); |
562 | th->zipnum = zip_get_zipnum(zip_info); |
498 | fprintf(out,"%s:%d",(char *)next->data,th->total_size); |
563 | fprintf(out, "%s:%d", (char *) next->data, th->total_size); |
499 | |
564 | |
500 | for ( idx = 0; idx< th->num_subtiles; idx++ ){ |
565 | for (idx = 0; idx < th->num_subtiles; idx++) |
|
|
566 | { |
501 | data= th_get_subtile( th, idx ); |
567 | data = th_get_subtile(th, idx); |
502 | fprintf(out,":%s", *data); |
568 | fprintf(out, ":%s", *data); |
503 | } |
569 | } |
504 | |
570 | |
505 | fprintf(out,"\n"); |
571 | fprintf(out, "\n"); |
506 | } |
572 | } |
507 | if (th->name[strlen(info->suffix)]) |
573 | if (th->name[strlen(info->suffix)]) |
508 | index_submap_add(info, th); |
574 | index_submap_add(info, th); |
509 | zip_add_member(zip_info); |
575 | zip_add_member(zip_info); |
510 | processed_tiles++; |
576 | processed_tiles++; |
511 | } |
577 | } |
512 | next=g_list_next(next); |
578 | next = g_list_next(next); |
513 | } |
579 | } |
514 | len--; |
580 | len--; |
515 | } |
581 | } |
516 | if (info->suffix[0] && info->write) { |
582 | if (info->suffix[0] && info->write) |
|
|
583 | { |
517 | struct item_bin *item_bin=init_item(type_submap); |
584 | struct item_bin *item_bin = init_item(type_submap, 0); |
518 | item_bin_add_coord_rect(item_bin, &world_bbox); |
585 | item_bin_add_coord_rect(item_bin, &world_bbox); |
519 | item_bin_add_attr_range(item_bin, attr_order, 0, 255); |
586 | item_bin_add_attr_range(item_bin, attr_order, 0, 255); |
520 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_get_zipnum(zip_info)-1); |
587 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, zip_get_zipnum(zip_info) - 1); |
521 | item_bin_write(item_bin, zip_get_index(zip_info)); |
588 | item_bin_write(item_bin, zip_get_index(zip_info)); |
522 | } |
589 | } |
523 | } |
590 | } |
524 | |
591 | |
525 | void |
|
|
526 | merge_tiles(struct tile_info *info) |
592 | void merge_tiles(struct tile_info *info) |
527 | { |
593 | { |
528 | struct tile_head *th; |
594 | struct tile_head *th; |
529 | char basetile[1024]; |
595 | char basetile[1024]; |
530 | char subtile[1024]; |
596 | char subtile[1024]; |
531 | GList *tiles_list_sorted,*last; |
597 | GList *tiles_list_sorted, *last; |
532 | int i,i_min,len,size_all,size[5],size_min,work_done; |
598 | int i, i_min, len, size_all, size[5], size_min, work_done; |
533 | long long zip_size; |
599 | long long zip_size; |
534 | |
600 | |
535 | do { |
601 | do |
|
|
602 | { |
536 | tiles_list_sorted=get_tiles_list(); |
603 | tiles_list_sorted = get_tiles_list(); |
537 | fprintf(stderr,"PROGRESS: sorting %d tiles\n", g_list_length(tiles_list_sorted)); |
604 | fprintf(stderr, "PROGRESS: sorting %d tiles\n", g_list_length(tiles_list_sorted)); |
538 | tiles_list_sorted=g_list_sort(tiles_list_sorted, (GCompareFunc)strcmp); |
605 | tiles_list_sorted = g_list_sort(tiles_list_sorted, (GCompareFunc) strcmp); |
539 | fprintf(stderr,"PROGRESS: sorting %d tiles done\n", g_list_length(tiles_list_sorted)); |
606 | fprintf(stderr, "PROGRESS: sorting %d tiles done\n", g_list_length(tiles_list_sorted)); |
540 | last=g_list_last(tiles_list_sorted); |
607 | last = g_list_last(tiles_list_sorted); |
541 | zip_size=0; |
608 | zip_size = 0; |
542 | while (last) { |
609 | while (last) |
|
|
610 | { |
543 | th=g_hash_table_lookup(tile_hash, last->data); |
611 | th = g_hash_table_lookup(tile_hash, last->data); |
544 | zip_size+=th->total_size; |
612 | zip_size += th->total_size; |
545 | last=g_list_previous(last); |
613 | last = g_list_previous(last); |
546 | } |
614 | } |
|
|
615 | |
547 | last=g_list_last(tiles_list_sorted); |
616 | last = g_list_last(tiles_list_sorted); |
548 | work_done=0; |
617 | work_done = 0; |
549 | while (last) { |
618 | while (last) |
|
|
619 | { |
550 | processed_tiles++; |
620 | processed_tiles++; |
551 | len=tile_len(last->data); |
621 | len = tile_len(last->data); |
552 | if (len >= 1) { |
622 | if (len >= 1) |
|
|
623 | { |
553 | strcpy(basetile,last->data); |
624 | strcpy(basetile, last->data); |
554 | basetile[len-1]='\0'; |
625 | basetile[len - 1] = '\0'; |
555 | strcat(basetile, info->suffix); |
626 | strcat(basetile, info->suffix); |
556 | strcpy(subtile,last->data); |
627 | strcpy(subtile, last->data); |
557 | for (i = 0 ; i < 4 ; i++) { |
628 | for (i = 0; i < 4; i++) |
|
|
629 | { |
558 | subtile[len-1]='a'+i; |
630 | subtile[len - 1] = 'a' + i; |
559 | size[i]=tile_data_size(subtile); |
631 | size[i] = tile_data_size(subtile); |
560 | } |
632 | } |
561 | size[4]=tile_data_size(basetile); |
633 | size[4] = tile_data_size(basetile); |
562 | size_all=size[0]+size[1]+size[2]+size[3]+size[4]; |
634 | size_all = size[0] + size[1] + size[2] + size[3] + size[4]; |
563 | if (size_all < 65536 && size_all > 0 && size_all != size[4]) { |
635 | if (size_all < 65536 && size_all > 0 && size_all != size[4]) |
|
|
636 | { |
564 | for (i = 0 ; i < 4 ; i++) { |
637 | for (i = 0; i < 4; i++) |
|
|
638 | { |
565 | subtile[len-1]='a'+i; |
639 | subtile[len - 1] = 'a' + i; |
566 | work_done+=merge_tile(basetile, subtile); |
640 | work_done += merge_tile(basetile, subtile); |
567 | } |
641 | } |
|
|
642 | } |
568 | } else { |
643 | else |
|
|
644 | { |
569 | for (;;) { |
645 | for (;;) |
|
|
646 | { |
570 | size_min=size_all; |
647 | size_min = size_all; |
571 | i_min=-1; |
648 | i_min = -1; |
572 | for (i = 0 ; i < 4 ; i++) { |
649 | for (i = 0; i < 4; i++) |
|
|
650 | { |
573 | if (size[i] && size[i] < size_min) { |
651 | if (size[i] && size[i] < size_min) |
|
|
652 | { |
574 | size_min=size[i]; |
653 | size_min = size[i]; |
575 | i_min=i; |
654 | i_min = i; |
576 | } |
655 | } |
577 | } |
656 | } |
578 | if (i_min == -1) |
657 | if (i_min == -1) |
579 | break; |
658 | break; |
580 | if (size[4]+size_min >= 65536) |
659 | if (size[4] + size_min >= 65536) |
581 | break; |
660 | break; |
582 | subtile[len-1]='a'+i_min; |
661 | subtile[len - 1] = 'a' + i_min; |
583 | work_done+=merge_tile(basetile, subtile); |
662 | work_done += merge_tile(basetile, subtile); |
584 | size[4]+=size[i_min]; |
663 | size[4] += size[i_min]; |
585 | size[i_min]=0; |
664 | size[i_min] = 0; |
586 | } |
665 | } |
587 | } |
666 | } |
588 | } |
667 | } |
589 | last=g_list_previous(last); |
668 | last = g_list_previous(last); |
590 | } |
669 | } |
591 | g_list_free(tiles_list_sorted); |
670 | g_list_free(tiles_list_sorted); |
592 | fprintf(stderr,"PROGRESS: merged %d tiles\n", work_done); |
671 | fprintf(stderr, "PROGRESS: merged %d tiles\n", work_done); |
|
|
672 | } |
593 | } while (work_done); |
673 | while (work_done); |
594 | } |
674 | } |
595 | |
675 | |
596 | struct attr map_information_attrs[32]; |
676 | struct attr map_information_attrs[32]; |
597 | |
677 | |
598 | void |
|
|
599 | index_init(struct zip_info *info, int version) |
678 | void index_init(struct zip_info *info, int version) |
600 | { |
679 | { |
601 | struct item_bin *item_bin; |
680 | struct item_bin *item_bin; |
602 | int i; |
681 | int i; |
603 | map_information_attrs[0].type=attr_version; |
682 | map_information_attrs[0].type = attr_version; |
604 | map_information_attrs[0].u.num=version; |
683 | map_information_attrs[0].u.num = version; |
605 | item_bin=init_item(type_map_information); |
684 | item_bin = init_item(type_map_information, 0); |
606 | for (i = 0 ; i < 32 ; i++) { |
685 | for (i = 0; i < 32; i++) |
|
|
686 | { |
607 | if (!map_information_attrs[i].type) |
687 | if (!map_information_attrs[i].type) |
608 | break; |
688 | break; |
609 | item_bin_add_attr(item_bin, &map_information_attrs[i]); |
689 | item_bin_add_attr(item_bin, &map_information_attrs[i]); |
610 | } |
690 | } |
611 | item_bin_write(item_bin, zip_get_index(info)); |
691 | item_bin_write(item_bin, zip_get_index(info)); |
612 | } |
692 | } |
613 | |
693 | |
614 | void |
|
|
615 | index_submap_add(struct tile_info *info, struct tile_head *th) |
694 | void index_submap_add(struct tile_info *info, struct tile_head *th) |
616 | { |
695 | { |
617 | int tlen=tile_len(th->name); |
696 | int tlen = tile_len(th->name); |
618 | int len=tlen; |
697 | int len = tlen; |
619 | char index_tile[len+1+strlen(info->suffix)]; |
698 | char index_tile[len + 1 + strlen(info->suffix)]; |
620 | struct rect r; |
699 | struct rect r; |
621 | struct item_bin *item_bin; |
700 | struct item_bin *item_bin; |
622 | |
701 | |
623 | strcpy(index_tile, th->name); |
702 | strcpy(index_tile, th->name); |
624 | if (len > 6) |
703 | if (len > 6) |
625 | len=6; |
704 | len = 6; |
626 | else |
705 | else |
627 | len=0; |
706 | len = 0; |
628 | index_tile[len]=0; |
707 | index_tile[len] = 0; |
629 | strcat(index_tile, info->suffix); |
708 | strcat(index_tile, info->suffix); |
630 | tile_bbox(th->name, &r, overlap); |
709 | tile_bbox(th->name, &r, overlap); |
631 | |
710 | |
632 | item_bin=init_item(type_submap); |
711 | item_bin = init_item(type_submap, 0); |
633 | item_bin_add_coord_rect(item_bin, &r); |
712 | item_bin_add_coord_rect(item_bin, &r); |
634 | item_bin_add_attr_range(item_bin, attr_order, (tlen > 4)?tlen-4 : 0, 255); |
713 | item_bin_add_attr_range(item_bin, attr_order, (tlen > 4) ? tlen - 4 : 0, 255); |
635 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, th->zipnum); |
714 | item_bin_add_attr_int(item_bin, attr_zipfile_ref, th->zipnum); |
636 | tile_write_item_to_tile(info, item_bin, NULL, index_tile); |
715 | tile_write_item_to_tile(info, item_bin, NULL, index_tile); |
637 | } |
716 | } |
|
|
717 | |