/[zanavi_public1]/navit/navit/map/binfile/binfile.c
ZANavi

Diff of /navit/navit/map/binfile/binfile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 15 Revision 31
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
40#include "types.h" 59#include "types.h"
41#include "navit.h" 60#include "navit.h"
42 61
43static int map_id; 62static int map_id;
44 63
45struct tile { 64struct tile
65{
46 int *start; 66 int *start;
47 int *end; 67 int *end;
48 int *pos; 68 int *pos;
49 int *pos_coord_start; 69 int *pos_coord_start;
50 int *pos_coord; 70 int *pos_coord;
54 struct file *fi; 74 struct file *fi;
55 int zipfile_num; 75 int zipfile_num;
56 int mode; 76 int mode;
57}; 77};
58 78
59struct map_download { 79struct map_download
80{
60 int state; 81 int state;
61 struct map_priv *m; 82 struct map_priv *m;
62 struct map_rect_priv *mr; 83 struct map_rect_priv *mr;
63 struct file *http,*file; 84 struct file *http, *file;
64 int zipfile,toffset,tlength,progress,read,dl_size; 85 int zipfile, toffset, tlength, progress, read, dl_size;
65 long long offset,start_offset,cd1offset,size; 86 long long offset, start_offset, cd1offset, size;
66 struct zip64_eoc *zip64_eoc; 87 struct zip64_eoc *zip64_eoc;
67 struct zip64_eocl *zip64_eocl; 88 struct zip64_eocl *zip64_eocl;
68 struct zip_eoc *zip_eoc; 89 struct zip_eoc *zip_eoc;
69 struct zip_cd *cd_copy,*cd; 90 struct zip_cd *cd_copy, *cd;
70}; 91};
71 92
72struct map_priv { 93struct map_priv
94{
73 int id; 95 int id;
74 char *filename; 96 char *filename;
75 char *cachedir; 97 char *cachedir;
76 struct file *fi,*http; 98 struct file *fi, *http;
77 struct file **fis; 99 struct file **fis;
78 struct zip_cd *index_cd; 100 struct zip_cd *index_cd;
79 int index_offset; 101 int index_offset;
80 int cde_size; 102 int cde_size;
81 struct zip_eoc *eoc; 103 struct zip_eoc *eoc;
98 struct map_download *download; 120 struct map_download *download;
99 int redirect; 121 int redirect;
100 long download_enabled; 122 long download_enabled;
101}; 123};
102 124
103struct map_rect_priv { 125struct map_rect_priv
126{
104 int *start; 127 int *start;
105 int *end; 128 int *end;
106 enum attr_type attr_last; 129 enum attr_type attr_last;
107 int label; 130 int label;
108 int *label_attr[5]; 131 int *label_attr[5];
109 struct map_selection *sel; 132 struct map_selection *sel;
110 struct map_priv *m; 133 struct map_priv *m;
111 struct item item; 134 struct item item;
112 int tile_depth; 135 int tile_depth;
113 struct tile tiles[8]; 136 struct tile tiles[8];
114 struct tile *t; 137 struct tile *t;
115 int country_id; 138 int country_id;
116 char *url; 139 char *url;
117 struct attr attrs[8]; 140 struct attr attrs[8];
118 int status; 141 int status;
119#ifdef DEBUG_SIZE 142#ifdef DEBUG_SIZE
120 int size; 143int size;
121#endif 144#endif
122}; 145};
123 146
124struct map_search_priv { 147struct map_search_priv
148{
125 struct map_priv *map; 149 struct map_priv *map;
126 struct map_rect_priv *mr; 150 struct map_rect_priv *mr;
127 struct map_rect_priv *mr_item; 151 struct map_rect_priv *mr_item;
128 struct item *item; 152 struct item *item;
129 struct attr *search; 153 struct attr *search;
132 int mode; 156 int mode;
133 GHashTable *search_results; 157 GHashTable *search_results;
134 char *str; 158 char *str;
135}; 159};
136 160
137
138static void push_tile(struct map_rect_priv *mr, struct tile *t, int offset, int length); 161static void push_tile(struct map_rect_priv *mr, struct tile *t, int offset, int length);
139static void setup_pos(struct map_rect_priv *mr); 162static void setup_pos(struct map_rect_priv *mr);
140static void map_binfile_close(struct map_priv *m); 163static void map_binfile_close(struct map_priv *m);
141static int map_binfile_open(struct map_priv *m); 164static int map_binfile_open(struct map_priv *m);
142static void map_binfile_destroy(struct map_priv *m); 165static void map_binfile_destroy(struct map_priv *m);
143 166
144static void lfh_to_cpu(struct zip_lfh *lfh) { 167static void lfh_to_cpu(struct zip_lfh *lfh)
168{
145 dbg_assert(lfh != NULL); 169 dbg_assert(lfh != NULL);
146 if (lfh->ziplocsig != zip_lfh_sig) { 170 if (lfh->ziplocsig != zip_lfh_sig)
171 {
172 // dbg(0,"_endian 3\n");
147 lfh->ziplocsig = le32_to_cpu(lfh->ziplocsig); 173 lfh->ziplocsig = le32_to_cpu(lfh->ziplocsig);
148 lfh->zipver = le16_to_cpu(lfh->zipver); 174 lfh->zipver = le16_to_cpu(lfh->zipver);
149 lfh->zipgenfld = le16_to_cpu(lfh->zipgenfld); 175 lfh->zipgenfld = le16_to_cpu(lfh->zipgenfld);
150 lfh->zipmthd = le16_to_cpu(lfh->zipmthd); 176 lfh->zipmthd = le16_to_cpu(lfh->zipmthd);
151 lfh->ziptime = le16_to_cpu(lfh->ziptime); 177 lfh->ziptime = le16_to_cpu(lfh->ziptime);
152 lfh->zipdate = le16_to_cpu(lfh->zipdate); 178 lfh->zipdate = le16_to_cpu(lfh->zipdate);
153 lfh->zipcrc = le32_to_cpu(lfh->zipcrc); 179 lfh->zipcrc = le32_to_cpu(lfh->zipcrc);
154 lfh->zipsize = le32_to_cpu(lfh->zipsize); 180 lfh->zipsize = le32_to_cpu(lfh->zipsize);
155 lfh->zipuncmp = le32_to_cpu(lfh->zipuncmp); 181 lfh->zipuncmp = le32_to_cpu(lfh->zipuncmp);
156 lfh->zipfnln = le16_to_cpu(lfh->zipfnln); 182 lfh->zipfnln = le16_to_cpu(lfh->zipfnln);
157 lfh->zipxtraln = le16_to_cpu(lfh->zipxtraln); 183 lfh->zipxtraln = le16_to_cpu(lfh->zipxtraln);
158 } 184 }
159} 185}
160 186
161static void cd_to_cpu(struct zip_cd *zcd) { 187static void cd_to_cpu(struct zip_cd *zcd)
188{
162 dbg_assert(zcd != NULL); 189 dbg_assert(zcd != NULL);
163 if (zcd->zipcensig != zip_cd_sig) { 190 if (zcd->zipcensig != zip_cd_sig)
191 {
192 // dbg(0,"_endian 1\n");
164 zcd->zipcensig = le32_to_cpu(zcd->zipcensig); 193 zcd->zipcensig = le32_to_cpu(zcd->zipcensig);
165 zcd->zipccrc = le32_to_cpu(zcd->zipccrc); 194 zcd->zipccrc = le32_to_cpu(zcd->zipccrc);
166 zcd->zipcsiz = le32_to_cpu(zcd->zipcsiz); 195 zcd->zipcsiz = le32_to_cpu(zcd->zipcsiz);
167 zcd->zipcunc = le32_to_cpu(zcd->zipcunc); 196 zcd->zipcunc = le32_to_cpu(zcd->zipcunc);
168 zcd->zipcfnl = le16_to_cpu(zcd->zipcfnl); 197 zcd->zipcfnl = le16_to_cpu(zcd->zipcfnl);
169 zcd->zipcxtl = le16_to_cpu(zcd->zipcxtl); 198 zcd->zipcxtl = le16_to_cpu(zcd->zipcxtl);
170 zcd->zipccml = le16_to_cpu(zcd->zipccml); 199 zcd->zipccml = le16_to_cpu(zcd->zipccml);
171 zcd->zipdsk = le16_to_cpu(zcd->zipdsk); 200 zcd->zipdsk = le16_to_cpu(zcd->zipdsk);
172 zcd->zipint = le16_to_cpu(zcd->zipint); 201 zcd->zipint = le16_to_cpu(zcd->zipint);
173 zcd->zipext = le32_to_cpu(zcd->zipext); 202 zcd->zipext = le32_to_cpu(zcd->zipext);
174 zcd->zipofst = le32_to_cpu(zcd->zipofst); 203 zcd->zipofst = le32_to_cpu(zcd->zipofst);
175 } 204 }
176} 205}
177 206
178static void eoc_to_cpu(struct zip_eoc *eoc) { 207static void eoc_to_cpu(struct zip_eoc *eoc)
208{
179 dbg_assert(eoc != NULL); 209 dbg_assert(eoc != NULL);
180 if (eoc->zipesig != zip_eoc_sig) { 210 if (eoc->zipesig != zip_eoc_sig)
211 {
212 // dbg(0,"_endian 2\n");
181 eoc->zipesig = le32_to_cpu(eoc->zipesig); 213 eoc->zipesig = le32_to_cpu(eoc->zipesig);
182 eoc->zipedsk = le16_to_cpu(eoc->zipedsk); 214 eoc->zipedsk = le16_to_cpu(eoc->zipedsk);
183 eoc->zipecen = le16_to_cpu(eoc->zipecen); 215 eoc->zipecen = le16_to_cpu(eoc->zipecen);
184 eoc->zipenum = le16_to_cpu(eoc->zipenum); 216 eoc->zipenum = le16_to_cpu(eoc->zipenum);
185 eoc->zipecenn = le16_to_cpu(eoc->zipecenn); 217 eoc->zipecenn = le16_to_cpu(eoc->zipecenn);
186 eoc->zipecsz = le32_to_cpu(eoc->zipecsz); 218 eoc->zipecsz = le32_to_cpu(eoc->zipecsz);
187 eoc->zipeofst = le32_to_cpu(eoc->zipeofst); 219 eoc->zipeofst = le32_to_cpu(eoc->zipeofst);
188 eoc->zipecoml = le16_to_cpu(eoc->zipecoml); 220 eoc->zipecoml = le16_to_cpu(eoc->zipecoml);
189 } 221 }
190} 222}
191 223
192static void binfile_check_version(struct map_priv *m); 224static void binfile_check_version(struct map_priv *m);
193 225
194static struct zip_eoc * 226static struct zip_eoc *
195binfile_read_eoc(struct file *fi) 227binfile_read_eoc(struct file *fi)
196{ 228{
197 struct zip_eoc *eoc; 229 struct zip_eoc *eoc;
198 eoc=(struct zip_eoc *)file_data_read(fi,fi->size-sizeof(struct zip_eoc), sizeof(struct zip_eoc)); 230 eoc = (struct zip_eoc *) file_data_read(fi, fi->size - sizeof(struct zip_eoc), sizeof(struct zip_eoc));
199 if (eoc) { 231 if (eoc)
232 {
200 eoc_to_cpu(eoc); 233 eoc_to_cpu(eoc);
201 dbg(1,"sig 0x%x\n", eoc->zipesig); 234 // dbg(0, "sig 0x%x\n", eoc->zipesig);
202 if (eoc->zipesig != zip_eoc_sig) { 235 if (eoc->zipesig != zip_eoc_sig)
236 {
203 file_data_free(fi,(unsigned char *)eoc); 237 file_data_free(fi, (unsigned char *) eoc);
204 eoc=NULL; 238 eoc = NULL;
205 } 239 }
206 } 240 }
207 return eoc; 241 return eoc;
208} 242}
209 243
210static struct zip64_eoc * 244static struct zip64_eoc *
211binfile_read_eoc64(struct file *fi) 245binfile_read_eoc64(struct file *fi)
212{ 246{
213 struct zip64_eocl *eocl; 247 struct zip64_eocl *eocl;
214 struct zip64_eoc *eoc; 248 struct zip64_eoc *eoc;
215 eocl=(struct zip64_eocl *)file_data_read(fi,fi->size-sizeof(struct zip_eoc)-sizeof(struct zip64_eocl), sizeof(struct zip64_eocl)); 249 eocl = (struct zip64_eocl *) file_data_read(fi, fi->size - sizeof(struct zip_eoc) - sizeof(struct zip64_eocl), sizeof(struct zip64_eocl));
216 if (!eocl) 250 if (!eocl)
251 {
217 return NULL; 252 return NULL;
253 }
218 dbg(1,"sig 0x%x\n", eocl->zip64lsig); 254 //dbg(0, "sig 0x%x\n", eocl->zip64lsig);
219 if (eocl->zip64lsig != zip64_eocl_sig) { 255 if (eocl->zip64lsig != zip64_eocl_sig)
256 {
220 file_data_free(fi,(unsigned char *)eocl); 257 file_data_free(fi, (unsigned char *) eocl);
221 dbg(1,"eocl wrong\n"); 258 //dbg(0, "eocl wrong\n");
222 return NULL; 259 return NULL;
223 } 260 }
224 eoc=(struct zip64_eoc *)file_data_read(fi,eocl->zip64lofst, sizeof(struct zip64_eoc)); 261 eoc = (struct zip64_eoc *) file_data_read(fi, eocl->zip64lofst, sizeof(struct zip64_eoc));
225 if (eoc) { 262 if (eoc)
263 {
226 if (eoc->zip64esig != zip64_eoc_sig) { 264 if (eoc->zip64esig != zip64_eoc_sig)
265 {
227 file_data_free(fi,(unsigned char *)eoc); 266 file_data_free(fi, (unsigned char *) eoc);
228 dbg(1,"eoc wrong\n"); 267 //dbg(0, "eoc wrong\n");
229 eoc=NULL; 268 eoc = NULL;
230 } 269 }
231 dbg(1,"eoc64 ok 0x%Lx 0x%Lx\n",eoc->zip64eofst,eoc->zip64ecsz); 270 //dbg(0, "eoc64 ok 0x%Lx 0x%Lx\n", eoc->zip64eofst, eoc->zip64ecsz);
232 } 271 }
233 file_data_free(fi,(unsigned char *)eocl); 272 file_data_free(fi, (unsigned char *) eocl);
234 return eoc; 273 return eoc;
235} 274}
236 275
237static int
238binfile_cd_extra(struct zip_cd *cd) 276static int binfile_cd_extra(struct zip_cd *cd)
239{ 277{
240 return cd->zipcfnl+cd->zipcxtl; 278 return cd->zipcfnl + cd->zipcxtl;
241} 279}
242 280
243static struct zip_cd * 281static struct zip_cd *
244binfile_read_cd(struct map_priv *m, int offset, int len) 282binfile_read_cd(struct map_priv *m, int offset, int len)
245{ 283{
284 //dbg(0,"_enter\n");
246 struct zip_cd *cd; 285 struct zip_cd *cd;
247 long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst; 286 long long cdoffset = m->eoc64 ? m->eoc64->zip64eofst : m->eoc->zipeofst;
287 //dbg(0,"_cdoffset="LONGLONG_FMT"\n", cdoffset);
288
248 if (len == -1) { 289 if (len == -1)
290 {
291 //dbg(0,"_len = -1\n");
249 cd=(struct zip_cd *)file_data_read(m->fi,cdoffset+offset, sizeof(*cd)); 292 cd = (struct zip_cd *) file_data_read(m->fi, cdoffset + offset, sizeof(*cd));
250 cd_to_cpu(cd); 293 cd_to_cpu(cd);
251 len=binfile_cd_extra(cd); 294 len = binfile_cd_extra(cd);
295 //dbg(0,"_len = %d\n", len);
252 file_data_free(m->fi,(unsigned char *)cd); 296 file_data_free(m->fi, (unsigned char *) cd);
253 } 297 }
298
254 cd=(struct zip_cd *)file_data_read(m->fi,cdoffset+offset, sizeof(*cd)+len); 299 cd = (struct zip_cd *) file_data_read(m->fi, cdoffset + offset, sizeof(*cd) + len);
300
255 if (cd) { 301 if (cd)
302 {
256 dbg(1,"cd at "LONGLONG_FMT" %d bytes\n",cdoffset+offset, sizeof(*cd)+len); 303 //dbg(0,"cd at "LONGLONG_FMT" %d bytes\n",cdoffset+offset, sizeof(*cd)+len);
257 cd_to_cpu(cd); 304 cd_to_cpu(cd);
258 dbg(1,"sig 0x%x\n", cd->zipcensig); 305 //dbg(0, "sig 0x%x\n", cd->zipcensig);
259 if (cd->zipcensig != zip_cd_sig) { 306 if (cd->zipcensig != zip_cd_sig)
307 {
260 file_data_free(m->fi,(unsigned char *)cd); 308 file_data_free(m->fi, (unsigned char *) cd);
309 //dbg(0,"_cd=NULL\n");
261 cd=NULL; 310 cd = NULL;
262 }
263 } 311 }
312 }
313
314 //dbg(0,"leave\n");
264 return cd; 315 return cd;
265} 316}
266 317
267static struct zip_cd_ext * 318static struct zip_cd_ext *
268binfile_cd_ext(struct zip_cd *cd) 319binfile_cd_ext(struct zip_cd *cd)
270 struct zip_cd_ext *ext; 321 struct zip_cd_ext *ext;
271 if (cd->zipofst != 0xffffffff) 322 if (cd->zipofst != 0xffffffff)
272 return NULL; 323 return NULL;
273 if (cd->zipcxtl != sizeof(*ext)) 324 if (cd->zipcxtl != sizeof(*ext))
274 return NULL; 325 return NULL;
275 ext=(struct zip_cd_ext *)((unsigned char *)cd+sizeof(*cd)+cd->zipcfnl); 326 ext = (struct zip_cd_ext *) ((unsigned char *) cd + sizeof(*cd) + cd->zipcfnl);
276 if (ext->tag != 0x0001 || ext->size != 8) 327 if (ext->tag != 0x0001 || ext->size != 8)
277 return NULL; 328 return NULL;
278 return ext; 329 return ext;
279} 330}
280 331
281static long long
282binfile_cd_offset(struct zip_cd *cd) 332static long long binfile_cd_offset(struct zip_cd *cd)
283{ 333{
284 struct zip_cd_ext *ext=binfile_cd_ext(cd); 334 struct zip_cd_ext *ext = binfile_cd_ext(cd);
285 if (ext) 335 if (ext)
286 return ext->zipofst; 336 return ext->zipofst;
287 else 337 else
288 return cd->zipofst; 338 return cd->zipofst;
289} 339}
291static struct zip_lfh * 341static struct zip_lfh *
292binfile_read_lfh(struct file *fi, long long offset) 342binfile_read_lfh(struct file *fi, long long offset)
293{ 343{
294 struct zip_lfh *lfh; 344 struct zip_lfh *lfh;
295 345
296 lfh=(struct zip_lfh *)(file_data_read(fi,offset,sizeof(struct zip_lfh))); 346 lfh = (struct zip_lfh *) (file_data_read(fi, offset, sizeof(struct zip_lfh)));
297 if (lfh) { 347 if (lfh)
348 {
298 lfh_to_cpu(lfh); 349 lfh_to_cpu(lfh);
299 if (lfh->ziplocsig != zip_lfh_sig) { 350 if (lfh->ziplocsig != zip_lfh_sig)
351 {
300 file_data_free(fi,(unsigned char *)lfh); 352 file_data_free(fi, (unsigned char *) lfh);
301 lfh=NULL; 353 lfh = NULL;
302 } 354 }
303 } 355 }
304 return lfh; 356 return lfh;
305} 357}
306 358
307static unsigned char * 359static unsigned char *
308binfile_read_content(struct map_priv *m, struct file *fi, long long offset, struct zip_lfh *lfh) 360binfile_read_content(struct map_priv *m, struct file *fi, long long offset, struct zip_lfh *lfh)
309{ 361{
310 struct zip_enc *enc; 362 struct zip_enc *enc;
311 unsigned char *ret=NULL; 363 unsigned char *ret = NULL;
312 364
313 offset+=sizeof(struct zip_lfh)+lfh->zipfnln; 365 offset += sizeof(struct zip_lfh) + lfh->zipfnln;
314 switch (lfh->zipmthd) { 366 switch (lfh->zipmthd)
315 case 0: 367 {
316 offset+=lfh->zipxtraln;
317 ret=file_data_read(fi,offset, lfh->zipuncmp);
318 break;
319 case 8:
320 offset+=lfh->zipxtraln;
321 ret=file_data_read_compressed(fi,offset, lfh->zipsize, lfh->zipuncmp);
322 break;
323 case 99:
324 if (!m->passwd)
325 break;
326 enc=(struct zip_enc *)file_data_read(fi, offset, sizeof(*enc));
327 offset+=lfh->zipxtraln;
328 switch (enc->compress_method) {
329 case 0: 368 case 0:
330 ret=file_data_read_encrypted(fi, offset, lfh->zipsize, lfh->zipuncmp, 0, m->passwd); 369 offset += lfh->zipxtraln;
370 ret = file_data_read(fi, offset, lfh->zipuncmp);
331 break; 371 break;
332 case 8: 372 case 8:
373 offset += lfh->zipxtraln;
374 ret = file_data_read_compressed(fi, offset, lfh->zipsize, lfh->zipuncmp);
375 break;
376 case 99:
377 if (!m->passwd)
378 {
379 break;
380 }
381 enc = (struct zip_enc *) file_data_read(fi, offset, sizeof(*enc));
382 offset += lfh->zipxtraln;
383 switch (enc->compress_method)
384 {
385 case 0:
386 ret = file_data_read_encrypted(fi, offset, lfh->zipsize, lfh->zipuncmp, 0, m->passwd);
387 break;
388 case 8:
333 ret=file_data_read_encrypted(fi, offset, lfh->zipsize, lfh->zipuncmp, 1, m->passwd); 389 ret = file_data_read_encrypted(fi, offset, lfh->zipsize, lfh->zipuncmp, 1, m->passwd);
390 break;
391 default:
392 // dbg(0, "Unknown encrypted compression method %d\n", enc->compress_method);
393 break;
394 }
395 file_data_free(fi, (unsigned char *) enc);
334 break; 396 break;
335 default: 397 default:
336 dbg(0,"Unknown encrypted compression method %d\n",enc->compress_method);
337 }
338 file_data_free(fi, (unsigned char *)enc);
339 break;
340 default:
341 dbg(0,"Unknown compression method %d\n", lfh->zipmthd); 398 // dbg(0, "Unknown compression method %d\n", lfh->zipmthd);
399 break;
342 } 400 }
343 return ret; 401 return ret;
344} 402}
345 403
346static int
347binfile_search_cd(struct map_priv *m, int offset, char *name, int partial, int skip) 404static int binfile_search_cd(struct map_priv *m, int offset, char *name, int partial, int skip)
348{ 405{
406 //dbg(0,"_enter\n");
407
349 int size=4096; 408 int size = 4096;
350 int end=m->eoc64?m->eoc64->zip64ecsz:m->eoc->zipecsz; 409 int end = m->eoc64 ? m->eoc64->zip64ecsz : m->eoc->zipecsz;
351 int len=strlen(name); 410 int len = strlen(name);
352 long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst; 411 long long cdoffset = m->eoc64 ? m->eoc64->zip64eofst : m->eoc->zipeofst;
353 struct zip_cd *cd; 412 struct zip_cd *cd;
354#if 0 413#if 0
355 dbg(0,"end=%d\n",end); 414 // dbg(0,"end=%d\n",end);
356#endif 415#endif
357 while (offset < end) { 416 while (offset < end)
417 {
358 cd=(struct zip_cd *)(m->search_data+offset-m->search_offset); 418 cd = (struct zip_cd *) (m->search_data + offset - m->search_offset);
359 if (! m->search_data || 419 if (!m->search_data || m->search_offset > offset || offset - m->search_offset + sizeof(*cd) > m->search_size || offset - m->search_offset + sizeof(*cd) + cd->zipcfnl + cd->zipcxtl > m->search_size)
360 m->search_offset > offset || 420 {
361 offset-m->search_offset+sizeof(*cd) > m->search_size ||
362 offset-m->search_offset+sizeof(*cd)+cd->zipcfnl+cd->zipcxtl > m->search_size
363 ) {
364#if 0 421#if 0
365 dbg(0,"reload %p %d %d\n", m->search_data, m->search_offset, offset); 422 // dbg(0,"reload %p %d %d\n", m->search_data, m->search_offset, offset);
366#endif 423#endif
367 if (m->search_data) 424 if (m->search_data)
425 {
368 file_data_free(m->fi,m->search_data); 426 file_data_free(m->fi, m->search_data);
427 }
369 m->search_offset=offset; 428 m->search_offset = offset;
370 m->search_size=end-offset; 429 m->search_size = end - offset;
371 if (m->search_size > size) 430 if (m->search_size > size)
431 {
372 m->search_size=size; 432 m->search_size = size;
433 }
373 m->search_data=file_data_read(m->fi,cdoffset+m->search_offset,m->search_size); 434 m->search_data = file_data_read(m->fi, cdoffset + m->search_offset, m->search_size);
374 cd=(struct zip_cd *)m->search_data; 435 cd = (struct zip_cd *) m->search_data;
375 } 436 }
376#if 0 437#if 0
377 dbg(0,"offset=%d search_offset=%d search_size=%d search_data=%p cd=%p\n", offset, m->search_offset, m->search_size, m->search_data, cd); 438 // dbg(0,"offset=%d search_offset=%d search_size=%d search_data=%p cd=%p\n", offset, m->search_offset, m->search_size, m->search_data, cd);
378 dbg(0,"offset=%d fn='%s'\n",offset,cd->zipcfn); 439 // dbg(0,"offset=%d fn='%s'\n",offset,cd->zipcfn);
379#endif 440#endif
380 if (!skip && 441 if (!skip && (partial || cd->zipcfnl == len) && !strncmp(cd->zipcfn, name, len))
381 (partial || cd->zipcfnl == len) && 442 {
382 !strncmp(cd->zipcfn, name, len))
383 return offset; 443 return offset;
444 }
384 skip=0; 445 skip = 0;
385 offset+=sizeof(*cd)+cd->zipcfnl+cd->zipcxtl+cd->zipccml; 446 offset += sizeof(*cd) + cd->zipcfnl + cd->zipcxtl + cd->zipccml;
386; 447 ;
387 } 448 }
388 return -1; 449 return -1;
389} 450}
390 451
391static void
392map_destroy_binfile(struct map_priv *m) 452static void map_destroy_binfile(struct map_priv *m)
393{ 453{
394 dbg(1,"map_destroy_binfile\n"); 454 // dbg(1, "map_destroy_binfile\n");
395 if (m->fi) 455 if (m->fi)
396 map_binfile_close(m); 456 map_binfile_close(m);
397 map_binfile_destroy(m); 457 map_binfile_destroy(m);
398} 458}
399 459
400static void
401binfile_coord_rewind(void *priv_data) 460static void binfile_coord_rewind(void *priv_data)
402{ 461{
403 struct map_rect_priv *mr=priv_data; 462 struct map_rect_priv *mr = priv_data;
404 struct tile *t=mr->t; 463 struct tile *t = mr->t;
405 t->pos_coord=t->pos_coord_start; 464 t->pos_coord = t->pos_coord_start;
406} 465}
407 466
408static int
409binfile_coord_get(void *priv_data, struct coord *c, int count) 467static int binfile_coord_get(void *priv_data, struct coord *c, int count)
410{ 468{
411 struct map_rect_priv *mr=priv_data; 469 struct map_rect_priv *mr = priv_data;
412 struct tile *t=mr->t; 470 struct tile *t = mr->t;
413 int max,ret=0; 471 int max, ret = 0;
414 max=(t->pos_attr_start-t->pos_coord)/2; 472 max = (t->pos_attr_start - t->pos_coord) / 2;
415 if (count > max) 473 if (count > max)
474 {
416 count=max; 475 count = max;
476 }
417#if __BYTE_ORDER == __LITTLE_ENDIAN 477#if __BYTE_ORDER == __LITTLE_ENDIAN
418 memcpy(c, t->pos_coord, count*sizeof(struct coord)); 478 memcpy(c, t->pos_coord, count * sizeof(struct coord));
419#else 479#else
420 { 480 {
421 int i=0,end=count*sizeof(struct coord)/sizeof(int); 481 int i=0,end=count*sizeof(struct coord)/sizeof(int);
422 int *src=(int *)t->pos_coord; 482 int *src=(int *)t->pos_coord;
423 int *dst=(int *)c; 483 int *dst=(int *)c;
424 while (i++ < end) { 484 while (i++ < end)
485 {
425 *dst++=le32_to_cpu(*src); 486 *dst++=le32_to_cpu(*src);
426 src++; 487 src++;
427 } 488 }
428 } 489 }
429#endif 490#endif
430 t->pos_coord+=count*2; 491 t->pos_coord += count * 2;
431 ret=count; 492 ret = count;
432 return ret; 493 return ret;
433} 494}
434 495
435static void
436binfile_attr_rewind(void *priv_data) 496static void binfile_attr_rewind(void *priv_data)
437{ 497{
438 struct map_rect_priv *mr=priv_data; 498 struct map_rect_priv *mr = priv_data;
439 struct tile *t=mr->t; 499 struct tile *t = mr->t;
440 t->pos_attr=t->pos_attr_start; 500 t->pos_attr = t->pos_attr_start;
441 mr->label=0; 501 mr->label = 0;
442 memset(mr->label_attr, 0, sizeof(mr->label_attr)); 502 memset(mr->label_attr, 0, sizeof(mr->label_attr));
443 503
444} 504}
445 505
446static char * 506static char *
447binfile_extract(struct map_priv *m, char *dir, char *filename, int partial) 507binfile_extract(struct map_priv *m, char *dir, char *filename, int partial)
448{ 508{
449 char *full,*fulld,*sep; 509 char *full, *fulld, *sep;
450 unsigned char *start; 510 unsigned char *start;
451 int len,offset=m->index_offset; 511 int len, offset = m->index_offset;
452 struct zip_cd *cd; 512 struct zip_cd *cd;
453 struct zip_lfh *lfh; 513 struct zip_lfh *lfh;
454 FILE *f; 514 FILE *f;
455 515
456 for (;;) { 516 for (;;)
517 {
457 offset=binfile_search_cd(m, offset, filename, partial, 1); 518 offset = binfile_search_cd(m, offset, filename, partial, 1);
458 if (offset == -1) 519 if (offset == -1)
459 break; 520 break;
460 cd=binfile_read_cd(m, offset, -1); 521 cd = binfile_read_cd(m, offset, -1);
461 len=strlen(dir)+1+cd->zipcfnl+1; 522 len = strlen(dir) + 1 + cd->zipcfnl + 1;
462 full=g_malloc(len); 523 full = g_malloc(len);
463 strcpy(full,dir); 524 strcpy(full, dir);
464 strcpy(full+strlen(full),"/"); 525 strcpy(full + strlen(full), "/");
465 strncpy(full+strlen(full),cd->zipcfn,cd->zipcfnl); 526 strncpy(full + strlen(full), cd->zipcfn, cd->zipcfnl);
466 full[len-1]='\0'; 527 full[len - 1] = '\0';
467 fulld=g_strdup(full); 528 fulld = g_strdup(full);
468 sep=strrchr(fulld, '/'); 529 sep = strrchr(fulld, '/');
469 if (sep) { 530 if (sep)
531 {
470 *sep='\0'; 532 *sep = '\0';
471 file_mkdir(fulld, 1); 533 file_mkdir(fulld, 1);
472 } 534 }
473 if (full[len-2] != '/') { 535 if (full[len - 2] != '/')
536 {
474 lfh=binfile_read_lfh(m->fi, binfile_cd_offset(cd)); 537 lfh = binfile_read_lfh(m->fi, binfile_cd_offset(cd));
475 start=binfile_read_content(m, m->fi, binfile_cd_offset(cd), lfh); 538 start = binfile_read_content(m, m->fi, binfile_cd_offset(cd), lfh);
476 dbg(0,"fopen '%s'\n", full); 539 // dbg(0, "fopen '%s'\n", full);
477 f=fopen(full,"w"); 540 f = fopen(full, "w");
478 fwrite(start, lfh->zipuncmp, 1, f); 541 fwrite(start, lfh->zipuncmp, 1, f);
479 fclose(f); 542 fclose(f);
480 file_data_free(m->fi, start); 543 file_data_free(m->fi, start);
481 file_data_free(m->fi, (unsigned char *)lfh); 544 file_data_free(m->fi, (unsigned char *) lfh);
482 } 545 }
483 file_data_free(m->fi, (unsigned char *)cd); 546 file_data_free(m->fi, (unsigned char *) cd);
484 g_free(fulld); 547 g_free(fulld);
485 g_free(full); 548 g_free(full);
486 if (! partial) 549 if (!partial)
550 {
487 break; 551 break;
488 } 552 }
489 553 }
554
490 return g_strdup_printf("%s/%s",dir,filename); 555 return g_strdup_printf("%s/%s", dir, filename);
491} 556}
492 557
493static int
494binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) 558static int binfile_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
495{ 559{
560#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
561 dbg(0,"+#+:enter\n");
562#endif
563
564 // try to return "0" on any problem, to avoid crash!!
565
496 struct map_rect_priv *mr=priv_data; 566 struct map_rect_priv *mr = priv_data;
497 struct tile *t=mr->t; 567 struct tile *t = mr->t;
498 enum attr_type type; 568 enum attr_type type;
499 int i,size; 569 int i, size;
500 570
501 if (attr_type != mr->attr_last) { 571 if (attr_type != mr->attr_last)
572 {
502 t->pos_attr=t->pos_attr_start; 573 t->pos_attr = t->pos_attr_start;
503 mr->attr_last=attr_type; 574 mr->attr_last = attr_type;
504 } 575 }
576
505 while (t->pos_attr < t->pos_next) { 577 while (t->pos_attr < t->pos_next)
578 {
579 //dbg(0,"batg:002 %d %d\n",t->pos_attr,(t->pos_attr+1));
506 size=le32_to_cpu(*(t->pos_attr++)); 580 size = le32_to_cpu(*(t->pos_attr++));
581 // dbg(0,"batg:002.1 %d %d\n",t->pos_attr, t->pos_attr[0]);
507 type=le32_to_cpu(t->pos_attr[0]); 582 type = le32_to_cpu(t->pos_attr[0]);
583 // dbg(0, "type=%d\n", type);
584
585#ifdef NAVIT_ATTR_SAFETY_CHECK
586 // safety check (always keep value in sync with "attr_def.h" !!) ---------------
587 if (type > 0x000effff)
588 {
589 return 0;
590 }
591 // safety check (always keep value in sync with "attr_def.h" !!) ---------------
592#endif
593
594 //dbg(0,"batg:002.2\n");
508 if (type == attr_label) 595 if (type == attr_label)
509 mr->label=1; 596 mr->label = 1;
510 if (type == attr_house_number) 597 if (type == attr_house_number)
511 mr->label_attr[0]=t->pos_attr; 598 mr->label_attr[0] = t->pos_attr;
512 if (type == attr_street_name) 599 if (type == attr_street_name)
513 mr->label_attr[1]=t->pos_attr; 600 mr->label_attr[1] = t->pos_attr;
514 if (type == attr_street_name_systematic) 601 if (type == attr_street_name_systematic)
515 mr->label_attr[2]=t->pos_attr; 602 mr->label_attr[2] = t->pos_attr;
516 if (type == attr_district_name && mr->item.type < type_line) 603 if (type == attr_district_name && mr->item.type < type_line)
517 mr->label_attr[3]=t->pos_attr; 604 mr->label_attr[3] = t->pos_attr;
518 if (type == attr_town_name && mr->item.type < type_line) 605 if (type == attr_town_name && mr->item.type < type_line)
519 mr->label_attr[4]=t->pos_attr; 606 mr->label_attr[4] = t->pos_attr;
607
520 if (type == attr_type || attr_type == attr_any) { 608 if (type == attr_type || attr_type == attr_any)
609 {
521 if (attr_type == attr_any) { 610 if (attr_type == attr_any)
611 {
522 dbg(1,"pos %p attr %s size %d\n", t->pos_attr-1, attr_to_name(type), size); 612 // dbg(1, "pos %p attr %s size %d\n", t->pos_attr - 1, attr_to_name(type), size);
523 } 613 }
524 attr->type=type; 614 attr->type = type;
525 if (ATTR_IS_GROUP(type)) { 615 if (ATTR_IS_GROUP(type))
616 {
526 int i=0; 617 int i = 0;
527 int *subpos=t->pos_attr+1; 618 int *subpos = t->pos_attr + 1;
528 int size_rem=size-1; 619 int size_rem = size - 1;
529 i=0; 620 i = 0;
530 while (size_rem > 0 && i < 7) { 621 while (size_rem > 0 && i < 7)
622 {
531 int subsize=le32_to_cpu(*subpos++); 623 int subsize = le32_to_cpu(*subpos++);
532 int subtype=le32_to_cpu(subpos[0]); 624 int subtype = le32_to_cpu(subpos[0]);
533 mr->attrs[i].type=subtype; 625 mr->attrs[i].type = subtype;
534 attr_data_set_le(&mr->attrs[i], subpos+1); 626 attr_data_set_le(&mr->attrs[i], subpos + 1);
535 subpos+=subsize; 627 subpos += subsize;
536 size_rem-=subsize+1; 628 size_rem -= subsize + 1;
537 i++; 629 i++;
538 } 630 }
631
539 mr->attrs[i].type=type_none; 632 mr->attrs[i].type = type_none;
540 mr->attrs[i].u.data=NULL; 633 mr->attrs[i].u.data = NULL;
541 attr->u.attrs=mr->attrs; 634 attr->u.attrs = mr->attrs;
635 }
542 } else { 636 else
637 {
543 attr_data_set_le(attr, t->pos_attr+1); 638 attr_data_set_le(attr, t->pos_attr + 1);
544 if (type == attr_url_local) { 639 if (type == attr_url_local)
640 {
545 g_free(mr->url); 641 g_free(mr->url);
546 mr->url=binfile_extract(mr->m, mr->m->cachedir, attr->u.str, 1); 642 mr->url = binfile_extract(mr->m, mr->m->cachedir, attr->u.str, 1);
547 attr->u.str=mr->url; 643 attr->u.str = mr->url;
548 } 644 }
645
549 if (type == attr_flags && mr->m->map_version < 1) 646 if (type == attr_flags && mr->m->map_version < 1)
647 {
550 attr->u.num |= AF_CAR; 648 attr->u.num |= AF_CAR;
649 }
551 } 650 }
552 t->pos_attr+=size; 651 t->pos_attr += size;
553 return 1; 652 return 1;
653 }
554 } else { 654 else
655 {
555 t->pos_attr+=size; 656 t->pos_attr += size;
556 }
557 } 657 }
658 }
659
558 if (!mr->label && (attr_type == attr_any || attr_type == attr_label)) { 660 if (!mr->label && (attr_type == attr_any || attr_type == attr_label))
661 {
559 for (i = 0 ; i < sizeof(mr->label_attr)/sizeof(int *) ; i++) { 662 for (i = 0; i < sizeof(mr->label_attr) / sizeof(int *); i++)
663 {
560 if (mr->label_attr[i]) { 664 if (mr->label_attr[i])
665 {
561 mr->label=1; 666 mr->label = 1;
562 attr->type=attr_label; 667 attr->type = attr_label;
563 attr_data_set_le(attr,mr->label_attr[i]+1); 668 attr_data_set_le(attr, mr->label_attr[i] + 1);
564 return 1; 669 return 1;
565 } 670 }
566 } 671 }
567 } 672 }
673
674#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
675 dbg(0,"+#+:leave\n");
676#endif
677
568 return 0; 678 return 0;
569} 679}
570 680
571struct binfile_hash_entry { 681struct binfile_hash_entry
682{
572 struct item_id id; 683 struct item_id id;
573 int flags; 684 int flags;
574 int data[0]; 685 int data[0];
575}; 686};
576 687
577static guint
578binfile_hash_entry_hash(gconstpointer key) 688static guint binfile_hash_entry_hash(gconstpointer key)
579{ 689{
580 const struct binfile_hash_entry *entry=key; 690 const struct binfile_hash_entry *entry = key;
581 return (entry->id.id_hi ^ entry->id.id_lo); 691 return (entry->id.id_hi ^ entry->id.id_lo);
582} 692}
583 693
584static gboolean
585binfile_hash_entry_equal(gconstpointer a, gconstpointer b) 694static gboolean binfile_hash_entry_equal(gconstpointer a, gconstpointer b)
586{ 695{
587 const struct binfile_hash_entry *entry1=a,*entry2=b; 696 const struct binfile_hash_entry *entry1 = a, *entry2 = b;
588 return (entry1->id.id_hi==entry2->id.id_hi && entry1->id.id_lo == entry2->id.id_lo); 697 return (entry1->id.id_hi == entry2->id.id_hi && entry1->id.id_lo == entry2->id.id_lo);
589} 698}
590 699
591static int * 700static int *
592binfile_item_dup(struct map_priv *m, struct item *item, struct tile *t, int extend) 701binfile_item_dup(struct map_priv *m, struct item *item, struct tile *t, int extend)
593{ 702{
594 int size=le32_to_cpu(t->pos[0]); 703 int size = le32_to_cpu(t->pos[0]);
595 struct binfile_hash_entry *entry=g_malloc(sizeof(struct binfile_hash_entry)+(size+1+extend)*sizeof(int)); 704 struct binfile_hash_entry *entry = g_malloc(sizeof(struct binfile_hash_entry) + (size + 1 + extend) * sizeof(int));
596 void *ret=entry->data; 705 void *ret = entry->data;
597 entry->id.id_hi=item->id_hi; 706 entry->id.id_hi = item->id_hi;
598 entry->id.id_lo=item->id_lo; 707 entry->id.id_lo = item->id_lo;
599 entry->flags=1; 708 entry->flags = 1;
600 dbg(0,"id 0x%x,0x%x\n",entry->id.id_hi,entry->id.id_lo); 709 // dbg(0, "id 0x%x,0x%x\n", entry->id.id_hi, entry->id.id_lo);
601 710
602 memcpy(ret, t->pos, (size+1)*sizeof(int)); 711 memcpy(ret, t->pos, (size + 1) * sizeof(int));
603 if (!m->changes) 712 if (!m->changes)
604 m->changes=g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL); 713 m->changes = g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free_func, NULL);
605 g_hash_table_replace(m->changes, entry, entry); 714 g_hash_table_replace(m->changes, entry, entry);
606 dbg(0,"ret %p\n",ret); 715 // dbg(0, "ret %p\n", ret);
607 return ret; 716 return ret;
608} 717}
609 718
610static int
611binfile_coord_set(void *priv_data, struct coord *c, int count, enum change_mode mode) 719static int binfile_coord_set(void *priv_data, struct coord *c, int count, enum change_mode mode)
612{ 720{
613 struct map_rect_priv *mr=priv_data; 721 struct map_rect_priv *mr = priv_data;
614 struct tile *t=mr->t,*tn,new; 722 struct tile *t = mr->t, *tn, new;
615 int i,delta,move_len; 723 int i, delta, move_len;
616 int write_offset,move_offset,aoffset,coffset,clen; 724 int write_offset, move_offset, aoffset, coffset, clen;
617 int *data; 725 int *data;
618 726
619 { 727 //{
620 int *i=t->pos,j=0; 728 //int *i = t->pos, j = 0;
621 dbg(0,"Before: pos_coord=%d\n",t->pos_coord-i); 729 // dbg(0, "Before: pos_coord=%d\n", t->pos_coord - i);
622 while (i < t->pos_next) 730 //while (i < t->pos_next)
731 //{
623 dbg(0,"%d:0x%x\n",j++,*i++); 732 // // dbg(0, "%d:0x%x\n", j++, *i++);
624 733 //}
625 } 734
735 //}
736
626 aoffset=t->pos_attr-t->pos_attr_start; 737 aoffset = t->pos_attr - t->pos_attr_start;
627 coffset=t->pos_coord-t->pos_coord_start-2; 738 coffset = t->pos_coord - t->pos_coord_start - 2;
628 clen=t->pos_attr_start-t->pos_coord+2; 739 clen = t->pos_attr_start - t->pos_coord + 2;
629 dbg(0,"coffset=%d clen=%d\n",coffset,clen); 740 // dbg(0, "coffset=%d clen=%d\n", coffset, clen);
630 switch (mode) { 741 switch (mode)
742 {
631 case change_mode_delete: 743 case change_mode_delete:
632 if (count*2 > clen) 744 if (count * 2 > clen)
633 count=clen/2; 745 count = clen / 2;
634 delta=-count*2; 746 delta = -count * 2;
635 move_offset=coffset+count*2; 747 move_offset = coffset + count * 2;
636 move_len=t->pos_next-t->pos_coord_start-move_offset; 748 move_len = t->pos_next - t->pos_coord_start - move_offset;
637 write_offset=0; 749 write_offset = 0;
638 break; 750 break;
639 case change_mode_modify: 751 case change_mode_modify:
640 write_offset=coffset; 752 write_offset = coffset;
641 if (count*2 > clen) { 753 if (count * 2 > clen)
754 {
642 delta=count*2-clen; 755 delta = count * 2 - clen;
643 move_offset=t->pos_attr_start-t->pos_coord_start; 756 move_offset = t->pos_attr_start - t->pos_coord_start;
644 move_len=t->pos_next-t->pos_coord_start-move_offset; 757 move_len = t->pos_next - t->pos_coord_start - move_offset;
645 } else { 758 }
759 else
760 {
646 move_len=0; 761 move_len = 0;
647 move_offset=0; 762 move_offset = 0;
648 delta=0; 763 delta = 0;
649 } 764 }
650 break; 765 break;
651 case change_mode_prepend: 766 case change_mode_prepend:
652 delta=count*2; 767 delta = count * 2;
653 move_offset=coffset-2; 768 move_offset = coffset - 2;
654 move_len=t->pos_next-t->pos_coord_start-move_offset; 769 move_len = t->pos_next - t->pos_coord_start - move_offset;
655 write_offset=coffset-2; 770 write_offset = coffset - 2;
656 break; 771 break;
657 case change_mode_append: 772 case change_mode_append:
658 delta=count*2; 773 delta = count * 2;
659 move_offset=coffset; 774 move_offset = coffset;
660 move_len=t->pos_next-t->pos_coord_start-move_offset; 775 move_len = t->pos_next - t->pos_coord_start - move_offset;
661 write_offset=coffset; 776 write_offset = coffset;
662 break; 777 break;
663 default: 778 default:
664 return 0; 779 return 0;
665 } 780 }
666 dbg(0,"delta %d\n",delta); 781 // dbg(0, "delta %d\n", delta);
667 data=binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta:0); 782 data = binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta : 0);
668 data[0]=cpu_to_le32(le32_to_cpu(data[0])+delta); 783 data[0] = cpu_to_le32(le32_to_cpu(data[0]) + delta);
669 data[2]=cpu_to_le32(le32_to_cpu(data[2])+delta); 784 data[2] = cpu_to_le32(le32_to_cpu(data[2]) + delta);
670 new.pos=new.start=data; 785 new.pos = new.start = data;
671 new.zipfile_num=t->zipfile_num; 786 new.zipfile_num = t->zipfile_num;
672 new.mode=2; 787 new.mode = 2;
673 push_tile(mr, &new, 0, 0); 788 push_tile(mr, &new, 0, 0);
674 setup_pos(mr); 789 setup_pos(mr);
675 tn=mr->t; 790 tn = mr->t;
676 tn->pos_coord=tn->pos_coord_start+coffset; 791 tn->pos_coord = tn->pos_coord_start + coffset;
677 tn->pos_attr=tn->pos_attr_start+aoffset; 792 tn->pos_attr = tn->pos_attr_start + aoffset;
678 dbg(0,"moving %d ints from offset %d to %d\n",move_len,tn->pos_coord_start+move_offset-data,tn->pos_coord_start+move_offset+delta-data); 793 // dbg(0, "moving %d ints from offset %d to %d\n", move_len, tn->pos_coord_start + move_offset - data, tn->pos_coord_start + move_offset + delta - data);
679 memmove(tn->pos_coord_start+move_offset+delta, tn->pos_coord_start+move_offset, move_len*4); 794 memmove(tn->pos_coord_start + move_offset + delta, tn->pos_coord_start + move_offset, move_len * 4);
680 { 795 //{
681 int *i=tn->pos,j=0; 796 //int *i = tn->pos, j = 0;
682 dbg(0,"After move: pos_coord=%d\n",tn->pos_coord-i); 797 // dbg(0, "After move: pos_coord=%d\n", tn->pos_coord - i);
683 while (i < tn->pos_next) 798 //while (i < tn->pos_next)
799 //{
684 dbg(0,"%d:0x%x\n",j++,*i++); 800 // // dbg(0, "%d:0x%x\n", j++, *i++);
685 } 801 //}
802 //}
686 if (mode != change_mode_append) 803 if (mode != change_mode_append)
804 {
687 tn->pos_coord+=move_offset; 805 tn->pos_coord += move_offset;
806 }
688 if (mode != change_mode_delete) { 807 if (mode != change_mode_delete)
808 {
689 dbg(0,"writing %d ints at offset %d\n",count*2,write_offset+tn->pos_coord_start-data); 809 // dbg(0, "writing %d ints at offset %d\n", count * 2, write_offset + tn->pos_coord_start - data);
690 for (i = 0 ; i < count ; i++) { 810 for (i = 0; i < count; i++)
811 {
691 tn->pos_coord_start[write_offset++]=c[i].x; 812 tn->pos_coord_start[write_offset++] = c[i].x;
692 tn->pos_coord_start[write_offset++]=c[i].y; 813 tn->pos_coord_start[write_offset++] = c[i].y;
693 }
694
695 } 814 }
696 { 815
816 }
817 //{
697 int *i=tn->pos,j=0; 818 //int *i = tn->pos, j = 0;
698 dbg(0,"After: pos_coord=%d\n",tn->pos_coord-i); 819 //// dbg(0, "After: pos_coord=%d\n", tn->pos_coord - i);
699 while (i < tn->pos_next) 820 //while (i < tn->pos_next)
821 //{
700 dbg(0,"%d:0x%x\n",j++,*i++); 822 // // dbg(0, "%d:0x%x\n", j++, *i++);
701 } 823 //}
824 //}
702 return 1; 825 return 1;
703} 826}
704 827
705static int
706binfile_attr_set(void *priv_data, struct attr *attr, enum change_mode mode) 828static int binfile_attr_set(void *priv_data, struct attr *attr, enum change_mode mode)
707{ 829{
708 struct map_rect_priv *mr=priv_data; 830 struct map_rect_priv *mr = priv_data;
709 struct tile *t=mr->t,*tn,new; 831 struct tile *t = mr->t, *tn, new;
710 int extend,offset,delta,move_len; 832 int extend, offset, delta, move_len;
711 int write_offset,move_offset,naoffset,coffset,oattr_len; 833 int write_offset, move_offset, naoffset, coffset, oattr_len;
712 int nattr_size,nattr_len,pad; 834 int nattr_size, nattr_len, pad;
713 int *data; 835 int *data;
714 836
715 { 837 //{
716 int *i=t->pos,j=0; 838 //int *i = t->pos, j = 0;
717 dbg(0,"Before: pos_attr=%d\n",t->pos_attr-i); 839 //// dbg(0, "Before: pos_attr=%d\n", t->pos_attr - i);
718 while (i < t->pos_next) 840 //while (i < t->pos_next)
841 //{
719 dbg(0,"%d:0x%x\n",j++,*i++); 842 // // dbg(0, "%d:0x%x\n", j++, *i++);
720 843 //}
721 } 844 //}
722 845
723 write_offset=0; 846 write_offset = 0;
724 naoffset=t->pos_attr-t->pos_attr_start; 847 naoffset = t->pos_attr - t->pos_attr_start;
725 coffset=t->pos_coord-t->pos_coord_start; 848 coffset = t->pos_coord - t->pos_coord_start;
726 offset=0; 849 offset = 0;
727 oattr_len=0; 850 oattr_len = 0;
728 if (!naoffset) { 851 if (!naoffset)
852 {
729 if (mode == change_mode_delete || mode == change_mode_modify) { 853 if (mode == change_mode_delete || mode == change_mode_modify)
854 {
730 dbg(0,"no attribute selected\n"); 855 // dbg(0, "no attribute selected\n");
731 return 0; 856 return 0;
732 } 857 }
733 if (mode == change_mode_append) 858 if (mode == change_mode_append)
859 {
734 naoffset=t->pos_next-t->pos_attr_start; 860 naoffset = t->pos_next - t->pos_attr_start;
735 } 861 }
862 }
736 while (offset < naoffset) { 863 while (offset < naoffset)
864 {
737 oattr_len=le32_to_cpu(t->pos_attr_start[offset])+1; 865 oattr_len = le32_to_cpu(t->pos_attr_start[offset]) + 1;
738 dbg(0,"len %d\n",oattr_len); 866 // dbg(0, "len %d\n", oattr_len);
739 write_offset=offset; 867 write_offset = offset;
740 offset+=oattr_len; 868 offset += oattr_len;
741 } 869 }
742 move_len=t->pos_next-t->pos_attr_start-offset; 870 move_len = t->pos_next - t->pos_attr_start - offset;
743 move_offset=offset; 871 move_offset = offset;
744 switch (mode) { 872 switch (mode)
873 {
745 case change_mode_delete: 874 case change_mode_delete:
746 nattr_size=0; 875 nattr_size = 0;
747 nattr_len=0; 876 nattr_len = 0;
748 pad=0; 877 pad = 0;
749 extend=0; 878 extend = 0;
750 break; 879 break;
751 case change_mode_modify: 880 case change_mode_modify:
752 case change_mode_prepend: 881 case change_mode_prepend:
753 case change_mode_append: 882 case change_mode_append:
754 nattr_size=attr_data_size(attr); 883 nattr_size = attr_data_size(attr);
755 pad=(4-(nattr_size%4))%4; 884 pad = (4 - (nattr_size % 4)) % 4;
756 nattr_len=(nattr_size+pad)/4+2; 885 nattr_len = (nattr_size + pad) / 4 + 2;
757 if (mode == change_mode_prepend) { 886 if (mode == change_mode_prepend)
887 {
758 move_offset=write_offset; 888 move_offset = write_offset;
759 move_len+=oattr_len; 889 move_len += oattr_len;
760 } 890 }
761 if (mode == change_mode_append) { 891 if (mode == change_mode_append)
892 {
762 write_offset=move_offset; 893 write_offset = move_offset;
763 } 894 }
764 break; 895 break;
765 default: 896 default:
766 return 0; 897 return 0;
767 } 898 }
768 if (mode == change_mode_delete || mode == change_mode_modify) 899 if (mode == change_mode_delete || mode == change_mode_modify)
900 {
769 delta=nattr_len-oattr_len; 901 delta = nattr_len - oattr_len;
902 }
770 else 903 else
904 {
771 delta=nattr_len; 905 delta = nattr_len;
906 }
772 dbg(0,"delta %d oattr_len %d nattr_len %d\n",delta,oattr_len, nattr_len); 907 // dbg(0, "delta %d oattr_len %d nattr_len %d\n", delta, oattr_len, nattr_len);
773 data=binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta:0); 908 data = binfile_item_dup(mr->m, &mr->item, t, delta > 0 ? delta : 0);
774 data[0]=cpu_to_le32(le32_to_cpu(data[0])+delta); 909 data[0] = cpu_to_le32(le32_to_cpu(data[0]) + delta);
775 new.pos=new.start=data; 910 new.pos = new.start = data;
776 new.zipfile_num=t->zipfile_num; 911 new.zipfile_num = t->zipfile_num;
777 new.mode=2; 912 new.mode = 2;
778 push_tile(mr, &new, 0, 0); 913 push_tile(mr, &new, 0, 0);
779 setup_pos(mr); 914 setup_pos(mr);
780 tn=mr->t; 915 tn = mr->t;
781 tn->pos_coord=tn->pos_coord_start+coffset; 916 tn->pos_coord = tn->pos_coord_start + coffset;
782 tn->pos_attr=tn->pos_attr_start+offset; 917 tn->pos_attr = tn->pos_attr_start + offset;
783 dbg(0,"attr start %d offset %d\n",tn->pos_attr_start-data,offset); 918 // dbg(0, "attr start %d offset %d\n", tn->pos_attr_start - data, offset);
784 dbg(0,"moving %d ints from offset %d to %d\n",move_len,tn->pos_attr_start+move_offset-data,tn->pos_attr_start+move_offset+delta-data); 919 // dbg(0, "moving %d ints from offset %d to %d\n", move_len, tn->pos_attr_start + move_offset - data, tn->pos_attr_start + move_offset + delta - data);
785 memmove(tn->pos_attr_start+move_offset+delta, tn->pos_attr_start+move_offset, move_len*4); 920 memmove(tn->pos_attr_start + move_offset + delta, tn->pos_attr_start + move_offset, move_len * 4);
786 if (mode != change_mode_append) 921 if (mode != change_mode_append)
787 tn->pos_attr+=delta; 922 tn->pos_attr += delta;
788 { 923 {
789 int *i=tn->pos,j=0; 924 int *i = tn->pos, j = 0;
790 dbg(0,"After move: pos_attr=%d\n",tn->pos_attr-i); 925 // dbg(0, "After move: pos_attr=%d\n", tn->pos_attr - i);
791 while (i < tn->pos_next) 926 while (i < tn->pos_next)
927 {
792 dbg(0,"%d:0x%x\n",j++,*i++); 928 // dbg(0, "%d:0x%x\n", j++, *i++);
793 } 929 }
930 }
931
794 if (nattr_len) { 932 if (nattr_len)
933 {
795 int *nattr=tn->pos_attr_start+write_offset; 934 int *nattr = tn->pos_attr_start + write_offset;
796 dbg(0,"writing %d ints at %d\n",nattr_len,nattr-data); 935 // dbg(0, "writing %d ints at %d\n", nattr_len, nattr - data);
797 nattr[0]=cpu_to_le32(nattr_len-1); 936 nattr[0] = cpu_to_le32(nattr_len - 1);
798 nattr[1]=cpu_to_le32(attr->type); 937 nattr[1] = cpu_to_le32(attr->type);
799 memcpy(nattr+2, attr_data_get(attr), nattr_size); 938 memcpy(nattr + 2, attr_data_get(attr), nattr_size);
800 memset((unsigned char *)(nattr+2)+nattr_size, 0, pad); 939 memset((unsigned char *) (nattr + 2) + nattr_size, 0, pad);
801 } 940 }
802 { 941
942 //{
803 int *i=tn->pos,j=0; 943 //int *i = tn->pos, j = 0;
804 dbg(0,"After: pos_attr=%d\n",tn->pos_attr-i); 944 //// dbg(0, "After: pos_attr=%d\n", tn->pos_attr - i);
805 while (i < tn->pos_next) 945 //while (i < tn->pos_next)
946 //{
806 dbg(0,"%d:0x%x\n",j++,*i++); 947 // // dbg(0, "%d:0x%x\n", j++, *i++);
807 } 948 //}
949 //}
808 return 1; 950 return 1;
809} 951}
810 952
811static struct item_methods methods_binfile = { 953static struct item_methods methods_binfile =
812 binfile_coord_rewind, 954{ binfile_coord_rewind, binfile_coord_get, binfile_attr_rewind, binfile_attr_get, NULL, binfile_attr_set, binfile_coord_set, };
813 binfile_coord_get,
814 binfile_attr_rewind,
815 binfile_attr_get,
816 NULL,
817 binfile_attr_set,
818 binfile_coord_set,
819};
820 955
821static void
822push_tile(struct map_rect_priv *mr, struct tile *t, int offset, int length) 956static void push_tile(struct map_rect_priv *mr, struct tile *t, int offset, int length)
823{ 957{
824 dbg_assert(mr->tile_depth < 8); 958 dbg_assert(mr->tile_depth < 8);
825 mr->t=&mr->tiles[mr->tile_depth++]; 959 mr->t = &mr->tiles[mr->tile_depth++];
826 *(mr->t)=*t; 960 *(mr->t) = *t;
827 mr->t->pos=mr->t->pos_next=mr->t->start+offset; 961 mr->t->pos = mr->t->pos_next = mr->t->start + offset;
828 if (length == -1) 962 if (length == -1)
829 length=le32_to_cpu(mr->t->pos[0])+1; 963 length = le32_to_cpu(mr->t->pos[0]) + 1;
830 if (length > 0) 964 if (length > 0)
831 mr->t->end=mr->t->pos+length; 965 mr->t->end = mr->t->pos + length;
832} 966}
833 967
834static int
835pop_tile(struct map_rect_priv *mr) 968static int pop_tile(struct map_rect_priv *mr)
836{ 969{
837 if (mr->tile_depth <= 1) 970 if (mr->tile_depth <= 1)
838 return 0; 971 return 0;
839 if (mr->t->mode < 2) 972 if (mr->t->mode < 2)
840 file_data_free(mr->m->fi, (unsigned char *)(mr->t->start)); 973 file_data_free(mr->m->fi, (unsigned char *) (mr->t->start));
841#ifdef DEBUG_SIZE 974#ifdef DEBUG_SIZE
842#if DEBUG_SIZE > 0 975#if DEBUG_SIZE > 0
843 dbg(0,"leave %d\n",mr->t->zipfile_num); 976 // dbg(0,"leave %d\n",mr->t->zipfile_num);
844#endif 977#endif
845#endif 978#endif
846 mr->t=&mr->tiles[--mr->tile_depth-1]; 979 mr->t = &mr->tiles[--mr->tile_depth - 1];
847 return 1; 980 return 1;
848} 981}
849 982
850
851static int
852zipfile_to_tile(struct map_priv *m, struct zip_cd *cd, struct tile *t) 983static int zipfile_to_tile(struct map_priv *m, struct zip_cd *cd, struct tile *t)
853{ 984{
854 char buffer[1024]; 985 char buffer[1024];
855 struct zip_lfh *lfh; 986 struct zip_lfh *lfh;
856 char *zipfn; 987 char *zipfn;
857 struct file *fi; 988 struct file *fi;
858 dbg(1,"enter %p %p %p\n", m, cd, t); 989 // dbg(1, "enter %p %p %p\n", m, cd, t);
859 dbg(1,"cd->zipofst=0x%Lx\n", binfile_cd_offset(cd)); 990 // dbg(1, "cd->zipofst=0x%Lx\n", binfile_cd_offset(cd));
860 t->start=NULL; 991 t->start = NULL;
861 t->mode=1; 992 t->mode = 1;
862 if (m->fis) 993 if (m->fis)
863 fi=m->fis[cd->zipdsk]; 994 fi = m->fis[cd->zipdsk];
864 else 995 else
865 fi=m->fi; 996 fi = m->fi;
866 lfh=binfile_read_lfh(fi, binfile_cd_offset(cd)); 997 lfh = binfile_read_lfh(fi, binfile_cd_offset(cd));
867 zipfn=(char *)(file_data_read(fi,binfile_cd_offset(cd)+sizeof(struct zip_lfh), lfh->zipfnln)); 998 zipfn = (char *) (file_data_read(fi, binfile_cd_offset(cd) + sizeof(struct zip_lfh), lfh->zipfnln));
868 strncpy(buffer, zipfn, lfh->zipfnln); 999 strncpy(buffer, zipfn, lfh->zipfnln);
869 buffer[lfh->zipfnln]='\0'; 1000 buffer[lfh->zipfnln] = '\0';
870 t->start=(int *)binfile_read_content(m, fi, binfile_cd_offset(cd), lfh); 1001 t->start = (int *) binfile_read_content(m, fi, binfile_cd_offset(cd), lfh);
871 t->end=t->start+lfh->zipuncmp/4; 1002 t->end = t->start + lfh->zipuncmp / 4;
872 t->fi=fi; 1003 t->fi = fi;
873 dbg(1,"0x%x '%s' %d %d,%d\n", lfh->ziplocsig, buffer, sizeof(*cd)+cd->zipcfnl, lfh->zipsize, lfh->zipuncmp); 1004 // dbg(1, "0x%x '%s' %d %d,%d\n", lfh->ziplocsig, buffer, sizeof(*cd) + cd->zipcfnl, lfh->zipsize, lfh->zipuncmp);
874 file_data_free(fi, (unsigned char *)zipfn); 1005 file_data_free(fi, (unsigned char *) zipfn);
875 file_data_free(fi, (unsigned char *)lfh); 1006 file_data_free(fi, (unsigned char *) lfh);
876 return t->start != NULL; 1007 return t->start != NULL;
877} 1008}
878 1009
879
880static int
881map_binfile_handle_redirect(struct map_priv *m) 1010static int map_binfile_handle_redirect(struct map_priv *m)
882{ 1011{
883 char *location=file_http_header(m->http, "location"); 1012 char *location = file_http_header(m->http, "location");
884 if (!location) { 1013 if (!location)
1014 {
885 m->redirect=0; 1015 m->redirect = 0;
886 return 0; 1016 return 0;
887 } 1017 }
888 if (m->redirect) 1018 if (m->redirect)
889 return 0; 1019 return 0;
890 m->redirect=1; 1020 m->redirect = 1;
891 dbg(0,"redirected from %s to %s\n",m->url,location); 1021 // dbg(0, "redirected from %s to %s\n", m->url, location);
892 g_free(m->url); 1022 g_free(m->url);
893 m->url=g_strdup(location); 1023 m->url = g_strdup(location);
894 file_destroy(m->http); 1024 file_destroy(m->http);
895 m->http=NULL; 1025 m->http = NULL;
896 1026
897 return 1; 1027 return 1;
898} 1028}
899 1029
900static int
901map_binfile_http_request(struct map_priv *m, struct attr **attrs) 1030static int map_binfile_http_request(struct map_priv *m, struct attr **attrs)
902{ 1031{
903 if (!m->http) { 1032 if (!m->http)
1033 {
904 m->http=file_create(NULL, attrs); 1034 m->http = file_create(NULL, attrs);
905 } else { 1035 }
1036 else
1037 {
906 file_request(m->http, attrs); 1038 file_request(m->http, attrs);
907 } 1039 }
908 return 1; 1040 return 1;
909} 1041}
910 1042
911
912static long long
913map_binfile_download_size(struct map_priv *m) 1043static long long map_binfile_download_size(struct map_priv *m)
914{ 1044{
915 struct attr url={attr_url}; 1045 struct attr url =
916 struct attr http_method={attr_http_method}; 1046 { attr_url };
917 struct attr persistent={attr_persistent}; 1047 struct attr http_method =
1048 { attr_http_method };
1049 struct attr persistent =
1050 { attr_persistent };
918 struct attr *attrs[4]; 1051 struct attr *attrs[4];
919 int size_ret; 1052 int size_ret;
920 long long ret; 1053 long long ret;
921 void *data; 1054 void *data;
922 1055
923 do { 1056 do
1057 {
924 attrs[0]=&url; 1058 attrs[0] = &url;
925 url.u.str=m->url; 1059 url.u.str = m->url;
926 attrs[1]=&http_method; 1060 attrs[1] = &http_method;
927 http_method.u.str="HEAD"; 1061 http_method.u.str = "HEAD";
928 persistent.u.num=1; 1062 persistent.u.num = 1;
929 attrs[2]=&persistent; 1063 attrs[2] = &persistent;
930 attrs[3]=NULL; 1064 attrs[3] = NULL;
931 1065
932 map_binfile_http_request(m, attrs); 1066 map_binfile_http_request(m, attrs);
933 data=file_data_read_special(m->http, 0, &size_ret); 1067 data = file_data_read_special(m->http, 0, &size_ret);
934 g_free(data); 1068 g_free(data);
935 if (size_ret < 0) 1069 if (size_ret < 0)
936 return 0; 1070 return 0;
1071 }
937 } while (map_binfile_handle_redirect(m)); 1072 while (map_binfile_handle_redirect(m));
938 1073
939 ret=file_size(m->http); 1074 ret = file_size(m->http);
940 dbg(1,"file size "LONGLONG_FMT"\n",ret); 1075 // dbg(1,"file size "LONGLONG_FMT"\n",ret);
941 return ret; 1076 return ret;
942} 1077}
943 1078
944
945static int
946map_binfile_http_close(struct map_priv *m) 1079static int map_binfile_http_close(struct map_priv *m)
947{ 1080{
948 if (m->http) { 1081 if (m->http)
1082 {
949 file_destroy(m->http); 1083 file_destroy(m->http);
950 m->http=NULL; 1084 m->http = NULL;
951 } 1085 }
952 return 1; 1086 return 1;
953} 1087}
954
955 1088
956static struct file * 1089static struct file *
957map_binfile_http_range(struct map_priv *m, long long offset, int size) 1090map_binfile_http_range(struct map_priv *m, long long offset, int size)
958{ 1091{
959 struct attr *attrs[4]; 1092 struct attr *attrs[4];
960 struct attr url={attr_url}; 1093 struct attr url =
961 struct attr http_header={attr_http_header}; 1094 { attr_url };
962 struct attr persistent={attr_persistent}; 1095 struct attr http_header =
1096 { attr_http_header };
1097 struct attr persistent =
1098 { attr_persistent };
963 1099
964 persistent.u.num=1; 1100 persistent.u.num = 1;
965 attrs[0]=&url; 1101 attrs[0] = &url;
966 attrs[1]=&http_header; 1102 attrs[1] = &http_header;
967 attrs[2]=&persistent; 1103 attrs[2] = &persistent;
968 attrs[3]=NULL; 1104 attrs[3] = NULL;
969 1105
970 url.u.str=m->url; 1106 url.u.str = m->url;
971 http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset, offset+size-1); 1107 http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset, offset+size-1);
972 map_binfile_http_request(m, attrs); 1108 map_binfile_http_request(m, attrs);
973 g_free(http_header.u.str); 1109 g_free(http_header.u.str);
974 return m->http; 1110 return m->http;
975} 1111}
977static unsigned char * 1113static unsigned char *
978map_binfile_download_range(struct map_priv *m, long long offset, int size) 1114map_binfile_download_range(struct map_priv *m, long long offset, int size)
979{ 1115{
980 unsigned char *ret; 1116 unsigned char *ret;
981 int size_ret; 1117 int size_ret;
982 struct file *http=map_binfile_http_range(m, offset, size); 1118 struct file *http = map_binfile_http_range(m, offset, size);
983 1119
984 ret=file_data_read_special(http, size, &size_ret); 1120 ret = file_data_read_special(http, size, &size_ret);
985 if (size_ret != size) { 1121 if (size_ret != size)
1122 {
986 dbg(0,"size %d vs %d\n",size,size_ret); 1123 // dbg(0, "size %d vs %d\n", size, size_ret);
987 g_free(ret); 1124 g_free(ret);
988 return NULL; 1125 return NULL;
989 } 1126 }
990 return ret; 1127 return ret;
991} 1128}
992 1129
993static struct zip_cd * 1130static struct zip_cd *
994download_cd(struct map_download *download) 1131download_cd(struct map_download *download)
995{ 1132{
996 struct map_priv *m=download->m; 1133 struct map_priv *m = download->m;
997 struct zip64_eoc *zip64_eoc=(struct zip64_eoc *)file_data_read(m->fi, 0, sizeof(*zip64_eoc)); 1134 struct zip64_eoc *zip64_eoc = (struct zip64_eoc *) file_data_read(m->fi, 0, sizeof(*zip64_eoc));
998 struct zip_cd *cd=(struct zip_cd *)map_binfile_download_range(m, zip64_eoc->zip64eofst+download->zipfile*m->cde_size,m->cde_size); 1135 struct zip_cd *cd = (struct zip_cd *) map_binfile_download_range(m, zip64_eoc->zip64eofst + download->zipfile * m->cde_size, m->cde_size);
999 file_data_free(m->fi, (unsigned char *)zip64_eoc); 1136 file_data_free(m->fi, (unsigned char *) zip64_eoc);
1000 dbg(0,"needed cd, result %p\n",cd); 1137 // dbg(0, "needed cd, result %p\n", cd);
1001 return cd; 1138 return cd;
1002} 1139}
1003 1140
1004static int
1005download_request(struct map_download *download) 1141static int download_request(struct map_download *download)
1006{ 1142{
1007 struct attr url={attr_url}; 1143 struct attr url =
1008 struct attr http_header={attr_http_header}; 1144 { attr_url };
1009 struct attr persistent={attr_persistent}; 1145 struct attr http_header =
1146 { attr_http_header };
1147 struct attr persistent =
1148 { attr_persistent };
1010 struct attr *attrs[4]; 1149 struct attr *attrs[4];
1011 1150
1012 if(!download->m->download_enabled) 1151 if (!download->m->download_enabled)
1013 { 1152 {
1014 dbg(0,"Tried downloading while it's not allowed\n"); 1153 // dbg(0, "Tried downloading while it's not allowed\n");
1015 return 0; 1154 return 0;
1016 } 1155 }
1017 attrs[0]=&url; 1156 attrs[0] = &url;
1018 persistent.u.num=1; 1157 persistent.u.num = 1;
1019 attrs[1]=&persistent; 1158 attrs[1] = &persistent;
1020 attrs[2]=NULL; 1159 attrs[2] = NULL;
1021 if (strchr(download->m->url,'?')) { 1160 if (strchr(download->m->url, '?'))
1161 {
1022 url.u.str=g_strdup_printf("%smemberid=%d",download->m->url,download->zipfile); 1162 url.u.str = g_strdup_printf("%smemberid=%d", download->m->url, download->zipfile);
1023 download->dl_size=-1; 1163 download->dl_size = -1;
1024 } else { 1164 }
1165 else
1166 {
1025 long long offset=binfile_cd_offset(download->cd_copy); 1167 long long offset = binfile_cd_offset(download->cd_copy);
1026 int size=download->cd_copy->zipcsiz+sizeof(struct zip_lfh)+download->cd_copy->zipcfnl; 1168 int size = download->cd_copy->zipcsiz + sizeof(struct zip_lfh) + download->cd_copy->zipcfnl;
1027 url.u.str=g_strdup(download->m->url); 1169 url.u.str = g_strdup(download->m->url);
1028 http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset,offset+size-1); 1170 http_header.u.str=g_strdup_printf("Range: bytes="LONGLONG_FMT"-"LONGLONG_FMT,offset,offset+size-1);
1029 attrs[2]=&http_header; 1171 attrs[2] = &http_header;
1030 attrs[3]=NULL; 1172 attrs[3] = NULL;
1031 download->dl_size=size; 1173 download->dl_size = size;
1032 } 1174 }
1033 dbg(0,"encountered missing tile %d %s(%s), Downloading %d bytes at "LONGLONG_FMT"\n",download->zipfile, url.u.str,(char *)(download->cd_copy+1), download->dl_size, download->offset); 1175 // dbg(0,"encountered missing tile %d %s(%s), Downloading %d bytes at "LONGLONG_FMT"\n",download->zipfile, url.u.str,(char *)(download->cd_copy+1), download->dl_size, download->offset);
1034 map_binfile_http_request(download->m, attrs); 1176 map_binfile_http_request(download->m, attrs);
1035 g_free(url.u.str); 1177 g_free(url.u.str);
1036 download->http=download->m->http; 1178 download->http = download->m->http;
1037 return 1; 1179 return 1;
1038} 1180}
1039 1181
1040
1041static int
1042download_start(struct map_download *download) 1182static int download_start(struct map_download *download)
1043{ 1183{
1044 long long offset; 1184 long long offset;
1045 struct zip_eoc *eoc; 1185 struct zip_eoc *eoc;
1046 1186
1047 if (!download->cd->zipcensig) { 1187 if (!download->cd->zipcensig)
1188 {
1048 download->cd_copy=download_cd(download); 1189 download->cd_copy = download_cd(download);
1049 } else { 1190 }
1191 else
1192 {
1050 download->cd_copy=g_malloc(download->m->cde_size); 1193 download->cd_copy = g_malloc(download->m->cde_size);
1051 memcpy(download->cd_copy, download->cd, download->m->cde_size); 1194 memcpy(download->cd_copy, download->cd, download->m->cde_size);
1052 } 1195 }
1053 file_data_remove(download->file, (unsigned char *)download->cd); 1196 file_data_remove(download->file, (unsigned char *) download->cd);
1054 download->cd=NULL; 1197 download->cd = NULL;
1055 offset=file_size(download->file); 1198 offset = file_size(download->file);
1056 offset-=sizeof(struct zip_eoc); 1199 offset -= sizeof(struct zip_eoc);
1057 eoc=(struct zip_eoc *)file_data_read(download->file, offset, sizeof(struct zip_eoc)); 1200 eoc = (struct zip_eoc *) file_data_read(download->file, offset, sizeof(struct zip_eoc));
1058 download->zip_eoc=g_malloc(sizeof(struct zip_eoc)); 1201 download->zip_eoc = g_malloc(sizeof(struct zip_eoc));
1059 memcpy(download->zip_eoc, eoc, sizeof(struct zip_eoc)); 1202 memcpy(download->zip_eoc, eoc, sizeof(struct zip_eoc));
1060 file_data_remove(download->file, (unsigned char *)eoc); 1203 file_data_remove(download->file, (unsigned char *) eoc);
1061 download->start_offset=download->offset=offset; 1204 download->start_offset = download->offset = offset;
1062 return download_request(download); 1205 return download_request(download);
1063} 1206}
1064 1207
1065static int
1066download_download(struct map_download *download) 1208static int download_download(struct map_download *download)
1067{ 1209{
1068 int size=64*1024,size_ret; 1210 int size = 64 * 1024, size_ret;
1069 unsigned char *data; 1211 unsigned char *data;
1070 if (download->dl_size != -1 && size > download->dl_size) 1212 if (download->dl_size != -1 && size > download->dl_size)
1071 size=download->dl_size; 1213 size = download->dl_size;
1072 if (!size) 1214 if (!size)
1073 return 1; 1215 return 1;
1074 data=file_data_read_special(download->http, size, &size_ret); 1216 data = file_data_read_special(download->http, size, &size_ret);
1075 if (!download->read && download->m->http && map_binfile_handle_redirect(download->m)) { 1217 if (!download->read && download->m->http && map_binfile_handle_redirect(download->m))
1218 {
1076 g_free(data); 1219 g_free(data);
1077 download_request(download); 1220 download_request(download);
1078 return 0; 1221 return 0;
1079 } 1222 }
1080 1223
1081 dbg(1,"got %d bytes writing at offset "LONGLONG_FMT"\n",size_ret,download->offset); 1224 // dbg(1,"got %d bytes writing at offset "LONGLONG_FMT"\n",size_ret,download->offset);
1082 if (size_ret <= 0) { 1225 if (size_ret <= 0)
1226 {
1083 g_free(data); 1227 g_free(data);
1084 return 1; 1228 return 1;
1085 } 1229 }
1086 file_data_write(download->file, download->offset, size_ret, data); 1230 file_data_write(download->file, download->offset, size_ret, data);
1087 download->offset+=size_ret; 1231 download->offset += size_ret;
1088 download->read+=size_ret; 1232 download->read += size_ret;
1089 download->dl_size-=size_ret; 1233 download->dl_size -= size_ret;
1090 if (download->dl_size != -1) 1234 if (download->dl_size != -1)
1091 download->progress=download->read*100/(download->read+download->dl_size); 1235 download->progress = download->read * 100 / (download->read + download->dl_size);
1092 return 0; 1236 return 0;
1093} 1237}
1094 1238
1095static int
1096download_finish(struct map_download *download) 1239static int download_finish(struct map_download *download)
1097{ 1240{
1098 struct zip_lfh *lfh; 1241 struct zip_lfh *lfh;
1099 char *lfh_filename; 1242 char *lfh_filename;
1100 struct zip_cd_ext *ext; 1243 struct zip_cd_ext *ext;
1101 long long lfh_offset; 1244 long long lfh_offset;
1102 file_data_write(download->file, download->offset, sizeof(struct zip_eoc), (void *)download->zip_eoc); 1245 file_data_write(download->file, download->offset, sizeof(struct zip_eoc), (void *) download->zip_eoc);
1103 lfh=(struct zip_lfh *)(file_data_read(download->file,download->start_offset, sizeof(struct zip_lfh))); 1246 lfh = (struct zip_lfh *) (file_data_read(download->file, download->start_offset, sizeof(struct zip_lfh)));
1104 ext=binfile_cd_ext(download->cd_copy); 1247 ext = binfile_cd_ext(download->cd_copy);
1105 if (ext) 1248 if (ext)
1106 ext->zipofst=download->start_offset; 1249 ext->zipofst = download->start_offset;
1107 else 1250 else
1108 download->cd_copy->zipofst=download->start_offset; 1251 download->cd_copy->zipofst = download->start_offset;
1109 download->cd_copy->zipcsiz=lfh->zipsize; 1252 download->cd_copy->zipcsiz = lfh->zipsize;
1110 download->cd_copy->zipcunc=lfh->zipuncmp; 1253 download->cd_copy->zipcunc = lfh->zipuncmp;
1111 download->cd_copy->zipccrc=lfh->zipcrc; 1254 download->cd_copy->zipccrc = lfh->zipcrc;
1112 lfh_offset = binfile_cd_offset(download->cd_copy)+sizeof(struct zip_lfh); 1255 lfh_offset = binfile_cd_offset(download->cd_copy) + sizeof(struct zip_lfh);
1113 lfh_filename=(char *)file_data_read(download->file,lfh_offset,lfh->zipfnln); 1256 lfh_filename = (char *) file_data_read(download->file, lfh_offset, lfh->zipfnln);
1114 memcpy(download->cd_copy+1,lfh_filename,lfh->zipfnln); 1257 memcpy(download->cd_copy + 1, lfh_filename, lfh->zipfnln);
1115 file_data_remove(download->file,(void *)lfh_filename); 1258 file_data_remove(download->file, (void *) lfh_filename);
1116 file_data_remove(download->file,(void *)lfh); 1259 file_data_remove(download->file, (void *) lfh);
1117 file_data_write(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, binfile_cd_extra(download->cd_copy)+sizeof(struct zip_cd), (void *)download->cd_copy); 1260 file_data_write(download->file, download->m->eoc->zipeofst + download->zipfile * download->m->cde_size, binfile_cd_extra(download->cd_copy) + sizeof(struct zip_cd), (void *) download->cd_copy);
1118 file_data_flush(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, sizeof(struct zip_cd)); 1261 file_data_flush(download->file, download->m->eoc->zipeofst + download->zipfile * download->m->cde_size, sizeof(struct zip_cd));
1119 1262
1120 g_free(download->cd_copy); 1263 g_free(download->cd_copy);
1121 download->cd=(struct zip_cd *)(file_data_read(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, download->m->cde_size)); 1264 download->cd = (struct zip_cd *) (file_data_read(download->file, download->m->eoc->zipeofst + download->zipfile * download->m->cde_size, download->m->cde_size));
1122 cd_to_cpu(download->cd); 1265 cd_to_cpu(download->cd);
1123 dbg(1,"Offset %d\n",download->cd->zipofst); 1266 // dbg(1, "Offset %d\n", download->cd->zipofst);
1124 return 1; 1267 return 1;
1125} 1268}
1126 1269
1127static int
1128download_planet_size(struct map_download *download) 1270static int download_planet_size(struct map_download *download)
1129{ 1271{
1130 download->size=map_binfile_download_size(download->m); 1272 download->size = map_binfile_download_size(download->m);
1131 dbg(0,"Planet size "LONGLONG_FMT"\n",download->size); 1273 // dbg(0,"Planet size "LONGLONG_FMT"\n",download->size);
1132 if (!download->size) 1274 if (!download->size)
1133 return 0; 1275 return 0;
1134 return 1; 1276 return 1;
1135} 1277}
1136 1278
1137static int
1138download_eoc(struct map_download *download) 1279static int download_eoc(struct map_download *download)
1139{ 1280{
1140 download->zip64_eoc=(struct zip64_eoc *)map_binfile_download_range(download->m, download->size-98, 98); 1281 download->zip64_eoc = (struct zip64_eoc *) map_binfile_download_range(download->m, download->size - 98, 98);
1141 if (!download->zip64_eoc) 1282 if (!download->zip64_eoc)
1142 return 0; 1283 return 0;
1143 download->zip64_eocl=(struct zip64_eocl *)(download->zip64_eoc+1); 1284 download->zip64_eocl = (struct zip64_eocl *) (download->zip64_eoc + 1);
1144 download->zip_eoc=(struct zip_eoc *)(download->zip64_eocl+1); 1285 download->zip_eoc = (struct zip_eoc *) (download->zip64_eocl + 1);
1145 if (download->zip64_eoc->zip64esig != zip64_eoc_sig || download->zip64_eocl->zip64lsig != zip64_eocl_sig || download->zip_eoc->zipesig != zip_eoc_sig) 1286 if (download->zip64_eoc->zip64esig != zip64_eoc_sig || download->zip64_eocl->zip64lsig != zip64_eocl_sig || download->zip_eoc->zipesig != zip_eoc_sig)
1146 { 1287 {
1147 dbg(0,"wrong signature on zip64_eoc downloaded from "LONGLONG_FMT"\n",download->size-98); 1288 // dbg(0,"wrong signature on zip64_eoc downloaded from "LONGLONG_FMT"\n",download->size-98);
1148 g_free(download->zip64_eoc); 1289 g_free(download->zip64_eoc);
1149 return 0; 1290 return 0;
1150 } 1291 }
1151 return 1; 1292 return 1;
1152} 1293}
1153 1294
1154static int
1155download_directory_start(struct map_download *download) 1295static int download_directory_start(struct map_download *download)
1156{ 1296{
1157 download->http=map_binfile_http_range(download->m, download->zip64_eoc->zip64eofst, download->zip64_eoc->zip64ecsz); 1297 download->http = map_binfile_http_range(download->m, download->zip64_eoc->zip64eofst, download->zip64_eoc->zip64ecsz);
1158 if (!download->http) 1298 if (!download->http)
1159 return 0; 1299 return 0;
1160 return 1; 1300 return 1;
1161} 1301}
1162 1302
1163static int
1164download_directory_do(struct map_download *download) 1303static int download_directory_do(struct map_download *download)
1165{ 1304{
1166 int count; 1305 int count;
1167 1306
1168 for (count = 0 ; count < 100 ; count++) { 1307 for (count = 0; count < 100; count++)
1308 {
1169 int cd_xlen, size_ret; 1309 int cd_xlen, size_ret;
1170 unsigned char *cd_data; 1310 unsigned char *cd_data;
1171 struct zip_cd *cd; 1311 struct zip_cd *cd;
1172 cd=(struct zip_cd *)file_data_read_special(download->http, sizeof(*cd), &size_ret); 1312 cd = (struct zip_cd *) file_data_read_special(download->http, sizeof(*cd), &size_ret);
1173 cd->zipcunc=0; 1313 cd->zipcunc = 0;
1174 dbg(1,"size_ret=%d\n",size_ret); 1314 // dbg(1, "size_ret=%d\n", size_ret);
1175 if (!size_ret) 1315 if (!size_ret)
1176 return 0; 1316 return 0;
1177 if (size_ret != sizeof(*cd) || cd->zipcensig != zip_cd_sig) { 1317 if (size_ret != sizeof(*cd) || cd->zipcensig != zip_cd_sig)
1318 {
1178 dbg(0,"error1 size=%d vs %d\n",size_ret, sizeof(*cd)); 1319 // dbg(0, "error1 size=%d vs %d\n", size_ret, sizeof(*cd));
1179 return 0; 1320 return 0;
1180 } 1321 }
1181 file_data_write(download->file, download->offset, sizeof(*cd), (unsigned char *)cd); 1322 file_data_write(download->file, download->offset, sizeof(*cd), (unsigned char *) cd);
1182 download->offset+=sizeof(*cd); 1323 download->offset += sizeof(*cd);
1183 cd_xlen=cd->zipcfnl+cd->zipcxtl; 1324 cd_xlen = cd->zipcfnl + cd->zipcxtl;
1184 cd_data=file_data_read_special(download->http, cd_xlen, &size_ret); 1325 cd_data = file_data_read_special(download->http, cd_xlen, &size_ret);
1185 if (size_ret != cd_xlen) { 1326 if (size_ret != cd_xlen)
1327 {
1186 dbg(0,"error2 size=%d vs %d\n",size_ret,cd_xlen); 1328 // dbg(0, "error2 size=%d vs %d\n", size_ret, cd_xlen);
1187 return 0; 1329 return 0;
1188 } 1330 }
1189 file_data_write(download->file, download->offset, cd_xlen, cd_data); 1331 file_data_write(download->file, download->offset, cd_xlen, cd_data);
1190 download->offset+=cd_xlen; 1332 download->offset += cd_xlen;
1191 g_free(cd); 1333 g_free(cd);
1192 g_free(cd_data); 1334 g_free(cd_data);
1193 } 1335 }
1194 return 1; 1336 return 1;
1195} 1337}
1196 1338
1197static int
1198download_directory_finish(struct map_download *download) 1339static int download_directory_finish(struct map_download *download)
1199{ 1340{
1200 download->http=NULL; 1341 download->http = NULL;
1201 return 1; 1342 return 1;
1202} 1343}
1203 1344
1204static int
1205download_initial_finish(struct map_download *download) 1345static int download_initial_finish(struct map_download *download)
1206{ 1346{
1207 download->zip64_eoc->zip64eofst=download->cd1offset; 1347 download->zip64_eoc->zip64eofst = download->cd1offset;
1208 download->zip64_eocl->zip64lofst=download->offset; 1348 download->zip64_eocl->zip64lofst = download->offset;
1209 download->zip_eoc->zipeofst=download->cd1offset; 1349 download->zip_eoc->zipeofst = download->cd1offset;
1210#if 0 1350#if 0
1211 file_data_write(download->file, download->offset, sizeof(*download->zip64_eoc), (unsigned char *)download->zip64_eoc); 1351 file_data_write(download->file, download->offset, sizeof(*download->zip64_eoc), (unsigned char *)download->zip64_eoc);
1212 download->offset+=sizeof(*download->zip64_eoc); 1352 download->offset+=sizeof(*download->zip64_eoc);
1213 file_data_write(download->file, download->offset, sizeof(*download->zip64_eocl), (unsigned char *)download->zip64_eocl); 1353 file_data_write(download->file, download->offset, sizeof(*download->zip64_eocl), (unsigned char *)download->zip64_eocl);
1214 download->offset+=sizeof(*download->zip64_eocl); 1354 download->offset+=sizeof(*download->zip64_eocl);
1215#endif 1355#endif
1216 file_data_write(download->file, download->offset, sizeof(*download->zip_eoc), (unsigned char *)download->zip_eoc); 1356 file_data_write(download->file, download->offset, sizeof(*download->zip_eoc), (unsigned char *) download->zip_eoc);
1217 download->offset+=sizeof(*download->zip_eoc); 1357 download->offset += sizeof(*download->zip_eoc);
1218 g_free(download->zip64_eoc); 1358 g_free(download->zip64_eoc);
1219 download->zip64_eoc=NULL; 1359 download->zip64_eoc = NULL;
1220 return 1; 1360 return 1;
1221} 1361}
1222 1362
1223static void
1224push_zipfile_tile_do(struct map_rect_priv *mr, struct zip_cd *cd, int zipfile, int offset, int length) 1363static void push_zipfile_tile_do(struct map_rect_priv *mr, struct zip_cd *cd, int zipfile, int offset, int length)
1225 1364
1226{ 1365{
1227 struct tile t; 1366 struct tile t;
1228 struct map_priv *m=mr->m; 1367 struct map_priv *m = mr->m;
1229 struct file *f=m->fi; 1368 struct file *f = m->fi;
1230 1369
1231 dbg(1,"enter %p %d\n", mr, zipfile); 1370 // dbg(1, "enter %p %d\n", mr, zipfile);
1232#ifdef DEBUG_SIZE 1371#ifdef DEBUG_SIZE
1233#if DEBUG_SIZE > 0 1372#if DEBUG_SIZE > 0
1234 { 1373 {
1235 char filename[cd->zipcfnl+1]; 1374 char filename[cd->zipcfnl+1];
1236 memcpy(filename, cd+1, cd->zipcfnl); 1375 memcpy(filename, cd+1, cd->zipcfnl);
1237 filename[cd->zipcfnl]='\0'; 1376 filename[cd->zipcfnl]='\0';
1238 dbg(0,"enter %d (%s) %d\n",zipfile, filename, cd->zipcunc); 1377 // dbg(0,"enter %d (%s) %d\n",zipfile, filename, cd->zipcunc);
1239 } 1378 }
1240#endif 1379#endif
1241 mr->size+=cd->zipcunc; 1380 mr->size+=cd->zipcunc;
1242#endif 1381#endif
1243 t.zipfile_num=zipfile; 1382 t.zipfile_num = zipfile;
1244 if (zipfile_to_tile(m, cd, &t)) 1383 if (zipfile_to_tile(m, cd, &t))
1245 push_tile(mr, &t, offset, length); 1384 push_tile(mr, &t, offset, length);
1246 file_data_free(f, (unsigned char *)cd); 1385 file_data_free(f, (unsigned char *) cd);
1247} 1386}
1248
1249 1387
1250static struct zip_cd * 1388static struct zip_cd *
1251download(struct map_priv *m, struct map_rect_priv *mr, struct zip_cd *cd, int zipfile, int offset, int length, int async) 1389download(struct map_priv *m, struct map_rect_priv *mr, struct zip_cd *cd, int zipfile, int offset, int length, int async)
1252{ 1390{
1253 struct map_download *download; 1391 struct map_download *download;
1254 1392
1255 if(!m->download_enabled) 1393 if (!m->download_enabled)
1256 return NULL; 1394 return NULL;
1257 1395
1258 if (async == 2) { 1396 if (async == 2)
1397 {
1259 download=m->download; 1398 download = m->download;
1260 } else { 1399 }
1400 else
1401 {
1261 download=g_new0(struct map_download, 1); 1402 download=g_new0(struct map_download, 1);
1262 if (mr) { 1403 if (mr)
1404 {
1263 download->m=m; 1405 download->m = m;
1264 download->mr=mr; 1406 download->mr = mr;
1265 download->file=m->fi; 1407 download->file = m->fi;
1266 download->cd=cd; 1408 download->cd = cd;
1267 download->zipfile=zipfile; 1409 download->zipfile = zipfile;
1268 download->toffset=offset; 1410 download->toffset = offset;
1269 download->tlength=length; 1411 download->tlength = length;
1270 download->state=1; 1412 download->state = 1;
1413 }
1271 } else { 1414 else
1272 struct attr readwrite={attr_readwrite,{(void *)1}}; 1415 {
1273 struct attr create={attr_create,{(void *)1}}; 1416 struct attr readwrite =
1417 { attr_readwrite,
1418 { (void *) 1 } };
1419 struct attr create =
1420 { attr_create,
1421 { (void *) 1 } };
1274 struct attr *attrs[3]; 1422 struct attr *attrs[3];
1275 attrs[0]=&readwrite; 1423 attrs[0] = &readwrite;
1276 attrs[1]=&create; 1424 attrs[1] = &create;
1277 attrs[2]=NULL; 1425 attrs[2] = NULL;
1278 download->file=file_create(m->filename,attrs); 1426 download->file = file_create(m->filename, attrs);
1279 download->m=m; 1427 download->m = m;
1280 download->state=4; 1428 download->state = 4;
1281 }
1282 } 1429 }
1430 }
1283 if (async == 1) { 1431 if (async == 1)
1432 {
1284 m->download=download; 1433 m->download = download;
1285 g_free(m->progress); 1434 g_free(m->progress);
1286 if (download->mr) 1435 if (download->mr)
1287 m->progress=g_strdup_printf("Download Tile %d 0%%",download->zipfile); 1436 m->progress = g_strdup_printf("Download Tile %d 0%%", download->zipfile);
1288 else 1437 else
1289 m->progress=g_strdup_printf("Download Map Information 0%%"); 1438 m->progress = g_strdup_printf("Download Map Information 0%%");
1290 callback_list_call_attr_0(m->cbl, attr_progress); 1439 callback_list_call_attr_0(m->cbl, attr_progress);
1291 return NULL; 1440 return NULL;
1292 } 1441 }
1293 for (;;) { 1442 for (;;)
1443 {
1294 dbg(0,"state=%d\n",download->state); 1444 // dbg(0, "state=%d\n", download->state);
1295 switch (download->state) { 1445 switch (download->state)
1446 {
1296 case 0: 1447 case 0:
1297 dbg(0,"error\n"); 1448 // dbg(0, "error\n");
1298 break; 1449 break;
1299 case 1: 1450 case 1:
1300 if (download_start(download)) 1451 if (download_start(download))
1301 download->state=2; 1452 download->state = 2;
1302 else 1453 else
1303 download->state=0; 1454 download->state = 0;
1304 break; 1455 break;
1305 case 2: 1456 case 2:
1306 if (download_download(download)) 1457 if (download_download(download))
1307 download->state=3; 1458 download->state = 3;
1308 else { 1459 else
1460 {
1461 g_free(m->progress);
1462 m->progress = g_strdup_printf("Download Tile %d %d%%", download->zipfile, download->progress);
1463 callback_list_call_attr_0(m->cbl, attr_progress);
1464 }
1465 break;
1466 case 3:
1467 if (download_finish(download))
1468 {
1469 struct zip_cd *ret;
1470 g_free(m->progress);
1471 m->progress = g_strdup_printf("Download Tile %d 100%%", download->zipfile);
1472 callback_list_call_attr_0(m->cbl, attr_progress);
1473 if (async)
1474 {
1475 push_zipfile_tile_do(download->mr, download->cd, download->zipfile, download->toffset, download->tlength);
1476 ret = NULL;
1477 }
1478 else
1479 ret = download->cd;
1480 g_free(m->progress);
1481 m->progress = NULL;
1482 g_free(download);
1483 if (async)
1484 m->download = NULL;
1485 return ret;
1486 }
1487 else
1488 download->state = 0;
1489 break;
1490 case 4:
1491 if (download_planet_size(download))
1492 download->state = 5;
1493 else
1494 download->state = 0;
1495 break;
1496 case 5:
1309 g_free(m->progress); 1497 g_free(m->progress);
1310 m->progress=g_strdup_printf("Download Tile %d %d%%",download->zipfile,download->progress); 1498 m->progress = g_strdup_printf("Download Map Information 50%%");
1311 callback_list_call_attr_0(m->cbl, attr_progress); 1499 callback_list_call_attr_0(m->cbl, attr_progress);
1500 if (download_eoc(download))
1501 download->state = 6;
1502 else
1503 {
1504 // dbg(0, "download of eoc failed\n");
1505 download->state = 0;
1312 } 1506 }
1313 break; 1507 break;
1314 case 3: 1508 case 6:
1315 if (download_finish(download)) {
1316 struct zip_cd *ret;
1317 g_free(m->progress); 1509 g_free(m->progress);
1318 m->progress=g_strdup_printf("Download Tile %d 100%%",download->zipfile); 1510 m->progress = g_strdup_printf("Download Map Information 100%%");
1319 callback_list_call_attr_0(m->cbl, attr_progress); 1511 callback_list_call_attr_0(m->cbl, attr_progress);
1320 if (async) { 1512 if (download_directory_start(download))
1321 push_zipfile_tile_do(download->mr, download->cd, download->zipfile, download->toffset, download->tlength); 1513 download->state = 7;
1322 ret=NULL;
1323 } else 1514 else
1324 ret=download->cd; 1515 download->state = 0;
1516 break;
1517 case 7:
1325 g_free(m->progress); 1518 g_free(m->progress);
1519 m->progress = g_strdup_printf("Download Map Directory %d%%", (int) (download->offset * 100 / download->zip64_eoc->zip64ecsz));
1520 callback_list_call_attr_0(m->cbl, attr_progress);
1521 if (!download_directory_do(download))
1522 download->state = 8;
1523 break;
1524 case 8:
1525 if (download_directory_finish(download))
1526 download->state = 9;
1527 else
1528 download->state = 0;
1529 break;
1530 case 9:
1531 download_initial_finish(download);
1532 m->fi = download->file;
1533 g_free(m->progress);
1326 m->progress=NULL; 1534 m->progress = NULL;
1327 g_free(download); 1535 g_free(download);
1328 if (async) 1536 if (async)
1329 m->download=NULL; 1537 m->download = NULL;
1330 return ret;
1331 } else
1332 download->state=0;
1333 break;
1334 case 4:
1335 if (download_planet_size(download))
1336 download->state=5;
1337 else
1338 download->state=0;
1339 break;
1340 case 5:
1341 g_free(m->progress);
1342 m->progress=g_strdup_printf("Download Map Information 50%%");
1343 callback_list_call_attr_0(m->cbl, attr_progress);
1344 if (download_eoc(download))
1345 download->state=6;
1346 else {
1347 dbg(0,"download of eoc failed\n");
1348 download->state=0;
1349 }
1350 break;
1351 case 6:
1352 g_free(m->progress);
1353 m->progress=g_strdup_printf("Download Map Information 100%%");
1354 callback_list_call_attr_0(m->cbl, attr_progress);
1355 if (download_directory_start(download))
1356 download->state=7;
1357 else
1358 download->state=0;
1359 break;
1360 case 7:
1361 g_free(m->progress);
1362 m->progress=g_strdup_printf("Download Map Directory %d%%",(int)(download->offset*100/download->zip64_eoc->zip64ecsz));
1363 callback_list_call_attr_0(m->cbl, attr_progress);
1364 if (!download_directory_do(download))
1365 download->state=8;
1366 break;
1367 case 8:
1368 if (download_directory_finish(download))
1369 download->state=9;
1370 else
1371 download->state=0;
1372 break;
1373 case 9:
1374 download_initial_finish(download);
1375 m->fi=download->file;
1376 g_free(m->progress);
1377 m->progress=NULL;
1378 g_free(download);
1379 if (async)
1380 m->download=NULL;
1381 map_binfile_open(m); 1538 map_binfile_open(m);
1382 break; 1539 break;
1383 } 1540 }
1384 if (async) 1541 if (async)
1385 return NULL; 1542 return NULL;
1386 } 1543 }
1387} 1544}
1388 1545
1389static int
1390push_zipfile_tile(struct map_rect_priv *mr, int zipfile, int offset, int length, int async) 1546static int push_zipfile_tile(struct map_rect_priv *mr, int zipfile, int offset, int length, int async)
1391{ 1547{
1392 struct map_priv *m=mr->m; 1548 struct map_priv *m = mr->m;
1393 struct file *f=m->fi; 1549 struct file *f = m->fi;
1394 long long cdoffset=m->eoc64?m->eoc64->zip64eofst:m->eoc->zipeofst; 1550 long long cdoffset = m->eoc64 ? m->eoc64->zip64eofst : m->eoc->zipeofst;
1395 struct zip_cd *cd=(struct zip_cd *)(file_data_read(f, cdoffset + zipfile*m->cde_size, m->cde_size)); 1551 struct zip_cd *cd = (struct zip_cd *) (file_data_read(f, cdoffset + zipfile * m->cde_size, m->cde_size));
1396 dbg(1,"read from "LONGLONG_FMT" %d bytes\n",cdoffset + zipfile*m->cde_size, m->cde_size); 1552 // dbg(1,"read from "LONGLONG_FMT" %d bytes\n",cdoffset + zipfile*m->cde_size, m->cde_size);
1397 cd_to_cpu(cd); 1553 cd_to_cpu(cd);
1398 if (!cd->zipcunc && m->url) { 1554 if (!cd->zipcunc && m->url)
1555 {
1399 cd=download(m, mr, cd, zipfile, offset, length, async); 1556 cd = download(m, mr, cd, zipfile, offset, length, async);
1400 if (!cd) 1557 if (!cd)
1401 return 1; 1558 return 1;
1402 } 1559 }
1403 push_zipfile_tile_do(mr, cd, zipfile, offset, length); 1560 push_zipfile_tile_do(mr, cd, zipfile, offset, length);
1404 return 0; 1561 return 0;
1408map_rect_new_binfile_int(struct map_priv *map, struct map_selection *sel) 1565map_rect_new_binfile_int(struct map_priv *map, struct map_selection *sel)
1409{ 1566{
1410 struct map_rect_priv *mr; 1567 struct map_rect_priv *mr;
1411 1568
1412 binfile_check_version(map); 1569 binfile_check_version(map);
1413 dbg(1,"map_rect_new_binfile\n"); 1570 // dbg(1, "map_rect_new_binfile\n");
1414 if (!map->fi && !map->url) 1571 if (!map->fi && !map->url)
1415 return NULL; 1572 return NULL;
1416 map_binfile_http_close(map); 1573 map_binfile_http_close(map);
1417 mr=g_new0(struct map_rect_priv, 1); 1574 mr=g_new0(struct map_rect_priv, 1);
1418 mr->m=map; 1575 mr->m = map;
1419 mr->sel=sel; 1576 mr->sel = sel;
1420 mr->item.id_hi=0; 1577 mr->item.id_hi = 0;
1421 mr->item.id_lo=0; 1578 mr->item.id_lo = 0;
1422 mr->item.meth=&methods_binfile; 1579 mr->item.meth = &methods_binfile;
1423 mr->item.priv_data=mr; 1580 mr->item.priv_data = mr;
1424 return mr; 1581 return mr;
1425} 1582}
1426 1583
1427static void
1428tile_bbox(char *tile, int len, struct coord_rect *r) 1584static void tile_bbox(char *tile, int len, struct coord_rect *r)
1429{ 1585{
1430 struct coord c; 1586 struct coord c;
1431 int overlap=1; 1587 int overlap = 1;
1432 int xo,yo; 1588 int xo, yo;
1433 struct coord_rect world_bbox = { 1589 struct coord_rect world_bbox =
1590 {
1434 { -20000000, 20000000}, /* lu */ 1591 { -20000000, 20000000 }, /* lu */
1435 { 20000000, -20000000}, /* rl */ 1592 { 20000000, -20000000 }, /* rl */
1436 }; 1593 };
1437 *r=world_bbox; 1594 *r = world_bbox;
1438 while (len) { 1595 while (len)
1439 c.x=(r->lu.x+r->rl.x)/2; 1596 {
1440 c.y=(r->lu.y+r->rl.y)/2; 1597 c.x = (r->lu.x + r->rl.x) / 2;
1441 xo=(r->rl.x-r->lu.x)*overlap/100; 1598 c.y = (r->lu.y + r->rl.y) / 2;
1442 yo=(r->lu.y-r->rl.y)*overlap/100; 1599 xo = (r->rl.x - r->lu.x) * overlap / 100;
1443 switch (*tile) { 1600 yo = (r->lu.y - r->rl.y) * overlap / 100;
1444 case 'a': 1601 switch (*tile)
1445 r->lu.x=c.x-xo; 1602 {
1446 r->rl.y=c.y-yo; 1603 case 'a':
1447 break; 1604 r->lu.x = c.x - xo;
1448 case 'b': 1605 r->rl.y = c.y - yo;
1449 r->rl.x=c.x+xo; 1606 break;
1450 r->rl.y=c.y-yo; 1607 case 'b':
1451 break; 1608 r->rl.x = c.x + xo;
1452 case 'c': 1609 r->rl.y = c.y - yo;
1453 r->lu.x=c.x-xo; 1610 break;
1454 r->lu.y=c.y+yo; 1611 case 'c':
1455 break; 1612 r->lu.x = c.x - xo;
1456 case 'd': 1613 r->lu.y = c.y + yo;
1457 r->rl.x=c.x+xo; 1614 break;
1458 r->lu.y=c.y+yo; 1615 case 'd':
1459 break; 1616 r->rl.x = c.x + xo;
1460 default: 1617 r->lu.y = c.y + yo;
1461 return; 1618 break;
1462 } 1619 default:
1463 tile++; 1620 return;
1464 len--; 1621 }
1465 } 1622 tile++;
1623 len--;
1624 }
1466} 1625}
1467 1626
1468static int
1469map_download_selection_check(struct zip_cd *cd, struct map_selection *sel) 1627static int map_download_selection_check(struct zip_cd *cd, struct map_selection *sel)
1470{ 1628{
1471 //dbg(0,"EEnter\n"); 1629 //// dbg(0,"EEnter\n");
1472 1630
1473 struct coord_rect cd_rect; 1631 struct coord_rect cd_rect;
1474 if (cd->zipcunc) 1632 if (cd->zipcunc)
1475 return 0; 1633 return 0;
1476 tile_bbox((char *)(cd+1), cd->zipcfnl, &cd_rect); 1634 tile_bbox((char *) (cd + 1), cd->zipcfnl, &cd_rect);
1477 while (sel) { 1635 while (sel)
1636 {
1478 if (coord_rect_overlap(&cd_rect, &sel->u.c_rect)) 1637 if (coord_rect_overlap(&cd_rect, &sel->u.c_rect))
1479 return 1; 1638 return 1;
1480 sel=sel->next; 1639 sel = sel->next;
1481 } 1640 }
1482 return 0; 1641 return 0;
1483} 1642}
1484 1643
1485static void
1486map_download_selection(struct map_priv *m, struct map_rect_priv *mr, struct map_selection *sel) 1644static void map_download_selection(struct map_priv *m, struct map_rect_priv *mr, struct map_selection *sel)
1487{ 1645{
1488 int i; 1646 int i;
1489 struct zip_cd *cd; 1647 struct zip_cd *cd;
1490 for (i = 0 ; i < m->zip_members ; i++) { 1648 for (i = 0; i < m->zip_members; i++)
1649 {
1491 cd=binfile_read_cd(m, m->cde_size*i, -1); 1650 cd = binfile_read_cd(m, m->cde_size * i, -1);
1492 if (map_download_selection_check(cd, sel)) 1651 if (map_download_selection_check(cd, sel))
1493 download(m, mr, cd, i, 0, 0, 0); 1652 download(m, mr, cd, i, 0, 0, 0);
1494 file_data_free(m->fi, (unsigned char *)cd); 1653 file_data_free(m->fi, (unsigned char *) cd);
1495 } 1654 }
1496} 1655}
1497 1656
1498static struct map_rect_priv * 1657static struct map_rect_priv *
1499map_rect_new_binfile(struct map_priv *map, struct map_selection *sel) 1658map_rect_new_binfile(struct map_priv *map, struct map_selection *sel)
1500{ 1659{
1501 struct map_rect_priv *mr=map_rect_new_binfile_int(map, sel); 1660 struct map_rect_priv *mr = map_rect_new_binfile_int(map, sel);
1502 struct tile t; 1661 struct tile t;
1503 dbg(1,"zip_members=%d\n", map->zip_members); 1662 // dbg(1, "zip_members=%d\n", map->zip_members);
1504 if (map->url && map->fi && sel && sel->order == 255) { 1663 if (map->url && map->fi && sel && sel->order == 255)
1664 {
1505 map_download_selection(map, mr, sel); 1665 map_download_selection(map, mr, sel);
1506 } 1666 }
1507 if (map->eoc) 1667 if (map->eoc)
1508 mr->status=1; 1668 mr->status = 1;
1509 else { 1669 else
1670 {
1510 unsigned char *d; 1671 unsigned char *d;
1511 if (map->fi) { 1672 if (map->fi)
1673 {
1512 d=file_data_read(map->fi, 0, map->fi->size); 1674 d = file_data_read(map->fi, 0, map->fi->size);
1513 t.start=(int *)d; 1675 t.start = (int *) d;
1514 t.end=(int *)(d+map->fi->size); 1676 t.end = (int *) (d + map->fi->size);
1515 t.fi=map->fi; 1677 t.fi = map->fi;
1516 t.zipfile_num=0; 1678 t.zipfile_num = 0;
1517 t.mode=0; 1679 t.mode = 0;
1518 push_tile(mr, &t, 0, 0); 1680 push_tile(mr, &t, 0, 0);
1681 }
1519 } else if (map->url && !map->download) { 1682 else if (map->url && !map->download)
1683 {
1520 download(map, NULL, NULL, 0, 0, 0, 1); 1684 download(map, NULL, NULL, 0, 0, 0, 1);
1521 mr->status=1; 1685 mr->status = 1;
1522 } 1686 }
1523 } 1687 }
1524 return mr; 1688 return mr;
1525} 1689}
1526 1690
1527static void
1528write_changes_do(gpointer key, gpointer value, gpointer user_data) 1691static void write_changes_do(gpointer key, gpointer value, gpointer user_data)
1529{ 1692{
1530 struct binfile_hash_entry *entry=key; 1693 struct binfile_hash_entry *entry = key;
1531 FILE *out=user_data; 1694 FILE *out = user_data;
1532 if (entry->flags) { 1695 if (entry->flags)
1696 {
1533 entry->flags=0; 1697 entry->flags = 0;
1534 fwrite(entry, sizeof(*entry)+(le32_to_cpu(entry->data[0])+1)*4, 1, out); 1698 fwrite(entry, sizeof(*entry) + (le32_to_cpu(entry->data[0]) + 1) * 4, 1, out);
1535 dbg(0,"yes\n"); 1699 // dbg(0, "yes\n");
1536 } 1700 }
1537} 1701}
1538 1702
1539static void
1540write_changes(struct map_priv *m) 1703static void write_changes(struct map_priv *m)
1541{ 1704{
1542 FILE *changes; 1705 FILE *changes;
1543 char *changes_file; 1706 char *changes_file;
1544 if (!m->changes) 1707 if (!m->changes)
1545 return; 1708 return;
1546 changes_file=g_strdup_printf("%s.log",m->filename); 1709 changes_file = g_strdup_printf("%s.log", m->filename);
1547 changes=fopen(changes_file,"ab"); 1710 changes = fopen(changes_file, "ab");
1548 g_hash_table_foreach(m->changes, write_changes_do, changes); 1711 g_hash_table_foreach(m->changes, write_changes_do, changes);
1549 fclose(changes); 1712 fclose(changes);
1550 g_free(changes_file); 1713 g_free(changes_file);
1551} 1714}
1552 1715
1553static void
1554load_changes(struct map_priv *m) 1716static void load_changes(struct map_priv *m)
1555{ 1717{
1556 FILE *changes; 1718 FILE *changes;
1557 char *changes_file; 1719 char *changes_file;
1558 struct binfile_hash_entry entry,*e; 1720 struct binfile_hash_entry entry, *e;
1559 int size; 1721 int size;
1560 changes_file=g_strdup_printf("%s.log",m->filename); 1722 changes_file = g_strdup_printf("%s.log", m->filename);
1561 changes=fopen(changes_file,"rb"); 1723 changes = fopen(changes_file, "rb");
1562 if (! changes) { 1724 if (!changes)
1725 {
1563 g_free(changes_file); 1726 g_free(changes_file);
1564 return; 1727 return;
1565 } 1728 }
1566 m->changes=g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free, NULL); 1729 m->changes = g_hash_table_new_full(binfile_hash_entry_hash, binfile_hash_entry_equal, g_free_func, NULL);
1567 while (fread(&entry, sizeof(entry), 1, changes) == 1) { 1730 while (fread(&entry, sizeof(entry), 1, changes) == 1)
1731 {
1568 if (fread(&size, sizeof(size), 1, changes) != 1) 1732 if (fread(&size, sizeof(size), 1, changes) != 1)
1569 break; 1733 break;
1570 e=g_malloc(sizeof(struct binfile_hash_entry)+(le32_to_cpu(size)+1)*4); 1734 e = g_malloc(sizeof(struct binfile_hash_entry) + (le32_to_cpu(size) + 1) * 4);
1571 *e=entry; 1735 *e = entry;
1572 e->data[0]=size; 1736 e->data[0] = size;
1573 if (fread(e->data+1, le32_to_cpu(size)*4, 1, changes) != 1) 1737 if (fread(e->data + 1, le32_to_cpu(size) * 4, 1, changes) != 1)
1574 break; 1738 break;
1575 g_hash_table_replace(m->changes, e, e); 1739 g_hash_table_replace(m->changes, e, e);
1576 } 1740 }
1577 fclose(changes); 1741 fclose(changes);
1578 g_free(changes_file); 1742 g_free(changes_file);
1579} 1743}
1580 1744
1581
1582static void
1583map_rect_destroy_binfile(struct map_rect_priv *mr) 1745static void map_rect_destroy_binfile(struct map_rect_priv *mr)
1584{ 1746{
1585 write_changes(mr->m); 1747 write_changes(mr->m);
1586 while (pop_tile(mr)); 1748 while (pop_tile(mr))
1749 ;
1587#ifdef DEBUG_SIZE 1750#ifdef DEBUG_SIZE
1588 dbg(0,"size=%d kb\n",mr->size/1024); 1751 // dbg(0,"size=%d kb\n",mr->size/1024);
1589#endif 1752#endif
1590 if (mr->tiles[0].fi && mr->tiles[0].start) 1753 if (mr->tiles[0].fi && mr->tiles[0].start)
1591 file_data_free(mr->tiles[0].fi, (unsigned char *)(mr->tiles[0].start)); 1754 file_data_free(mr->tiles[0].fi, (unsigned char *) (mr->tiles[0].start));
1592 g_free(mr->url); 1755 g_free(mr->url);
1593 map_binfile_http_close(mr->m); 1756 map_binfile_http_close(mr->m);
1594 g_free(mr); 1757 g_free(mr);
1595} 1758}
1596 1759
1597static void
1598setup_pos(struct map_rect_priv *mr) 1760static void setup_pos(struct map_rect_priv *mr)
1599{ 1761{
1600 int size,coord_size; 1762 int size, coord_size;
1601 struct tile *t=mr->t; 1763 struct tile *t = mr->t;
1602 size=le32_to_cpu(t->pos[0]); 1764 size = le32_to_cpu(t->pos[0]);
1603 if (size > 1024*1024 || size < 0) { 1765 if (size > 1024 * 1024 || size < 0)
1766 {
1604 dbg(0,"size=0x%x\n", size); 1767 // dbg(0, "size=0x%x\n", size);
1605#if 0 1768#if 0
1606 fprintf(stderr,"offset=%d\n", (unsigned char *)(mr->pos)-mr->m->f->begin); 1769 fprintf(stderr,"offset=%d\n", (unsigned char *)(mr->pos)-mr->m->f->begin);
1607#endif 1770#endif
1608 dbg(0,"size error"); 1771 // dbg(0, "size error");
1609 } 1772 }
1610 t->pos_next=t->pos+size+1; 1773 t->pos_next = t->pos + size + 1;
1611 mr->item.type=le32_to_cpu(t->pos[1]); 1774 mr->item.type = le32_to_cpu(t->pos[1]);
1612 coord_size=le32_to_cpu(t->pos[2]); 1775 coord_size = le32_to_cpu(t->pos[2]);
1613 t->pos_coord_start=t->pos+3; 1776 t->pos_coord_start = t->pos + 3;
1614 t->pos_attr_start=t->pos_coord_start+coord_size; 1777 t->pos_attr_start = t->pos_coord_start + coord_size;
1615} 1778}
1616 1779
1617static int
1618selection_contains(struct map_selection *sel, struct coord_rect *r, struct range *mima) 1780static int selection_contains(struct map_selection *sel, struct coord_rect *r, struct range *mima)
1619{ 1781{
1620 //dbg(0,"EEnter\n"); 1782 //// dbg(0,"EEnter\n");
1621 1783
1622 int order; 1784 int order;
1623 if (! sel) 1785 if (!sel)
1624 return 1; 1786 return 1;
1625 while (sel) { 1787 while (sel)
1788 {
1626 if (coord_rect_overlap(r, &sel->u.c_rect)) { 1789 if (coord_rect_overlap(r, &sel->u.c_rect))
1790 {
1627 order=sel->order; 1791 order = sel->order;
1628 dbg(1,"min %d max %d order %d\n", mima->min, mima->max, order); 1792 // dbg(1, "min %d max %d order %d\n", mima->min, mima->max, order);
1629 if (!mima->min && !mima->max) 1793 if (!mima->min && !mima->max)
1630 return 1; 1794 return 1;
1631 if (order >= mima->min && order <= mima->max) 1795 if (order >= mima->min && order <= mima->max)
1632 return 1; 1796 return 1;
1633 } 1797 }
1634 sel=sel->next; 1798 sel = sel->next;
1635 } 1799 }
1636 return 0; 1800 return 0;
1637} 1801}
1638 1802
1639static void
1640map_parse_country_binfile(struct map_rect_priv *mr) 1803static void map_parse_country_binfile(struct map_rect_priv *mr)
1641{ 1804{
1642 struct attr at; 1805 struct attr at;
1643 if (binfile_attr_get(mr->item.priv_data, attr_country_id, &at)) { 1806 if (binfile_attr_get(mr->item.priv_data, attr_country_id, &at))
1807 {
1644 if (at.u.num == mr->country_id) 1808 if (at.u.num == mr->country_id)
1645 { 1809 {
1646 if (binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at)) 1810 if (binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at))
1647 { 1811 {
1648 push_zipfile_tile(mr, at.u.num, 0, 0, 0); 1812 push_zipfile_tile(mr, at.u.num, 0, 0, 0);
1649 } 1813 }
1650 } 1814 }
1651 } 1815 }
1652} 1816}
1653 1817
1654static int
1655map_parse_submap(struct map_rect_priv *mr, int async) 1818static int map_parse_submap(struct map_rect_priv *mr, int async)
1656{ 1819{
1657 struct coord_rect r; 1820 struct coord_rect r;
1658 struct coord c[2]; 1821 struct coord c[2];
1659 struct attr at; 1822 struct attr at;
1660 struct range mima; 1823 struct range mima;
1661 if (binfile_coord_get(mr->item.priv_data, c, 2) != 2) 1824 if (binfile_coord_get(mr->item.priv_data, c, 2) != 2)
1662 return 0; 1825 return 0;
1663 r.lu.x=c[0].x; 1826 r.lu.x = c[0].x;
1664 r.lu.y=c[1].y; 1827 r.lu.y = c[1].y;
1665 r.rl.x=c[1].x; 1828 r.rl.x = c[1].x;
1666 r.rl.y=c[0].y; 1829 r.rl.y = c[0].y;
1667 if (!binfile_attr_get(mr->item.priv_data, attr_order, &at)) 1830 if (!binfile_attr_get(mr->item.priv_data, attr_order, &at))
1668 return 0; 1831 return 0;
1669#if __BYTE_ORDER == __BIG_ENDIAN 1832#if __BYTE_ORDER == __BIG_ENDIAN
1670 mima.min=le16_to_cpu(at.u.range.max); 1833 mima.min = le16_to_cpu(at.u.range.max);
1671 mima.max=le16_to_cpu(at.u.range.min); 1834 mima.max = le16_to_cpu(at.u.range.min);
1672#else 1835#else
1673 mima=at.u.range; 1836 mima=at.u.range;
1674#endif 1837#endif
1675 if (!mr->m->eoc || !selection_contains(mr->sel, &r, &mima)) 1838 if (!mr->m->eoc || !selection_contains(mr->sel, &r, &mima))
1676 return 0; 1839 return 0;
1677 if (!binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at)) 1840 if (!binfile_attr_get(mr->item.priv_data, attr_zipfile_ref, &at))
1678 return 0; 1841 return 0;
1679 dbg(1,"pushing zipfile %d from %d\n", at.u.num, mr->t->zipfile_num); 1842 // dbg(1, "pushing zipfile %d from %d\n", at.u.num, mr->t->zipfile_num);
1680 return push_zipfile_tile(mr, at.u.num, 0, 0, async); 1843 return push_zipfile_tile(mr, at.u.num, 0, 0, async);
1681} 1844}
1682 1845
1683static int
1684push_modified_item(struct map_rect_priv *mr) 1846static int push_modified_item(struct map_rect_priv *mr)
1685{ 1847{
1686 struct item_id id; 1848 struct item_id id;
1687 struct binfile_hash_entry *entry; 1849 struct binfile_hash_entry *entry;
1688 id.id_hi=mr->item.id_hi; 1850 id.id_hi = mr->item.id_hi;
1689 id.id_lo=mr->item.id_lo; 1851 id.id_lo = mr->item.id_lo;
1690 entry=g_hash_table_lookup(mr->m->changes, &id); 1852 entry = g_hash_table_lookup(mr->m->changes, &id);
1691 if (entry) { 1853 if (entry)
1854 {
1692 struct tile tn; 1855 struct tile tn;
1693 tn.pos_next=tn.pos=tn.start=entry->data; 1856 tn.pos_next = tn.pos = tn.start = entry->data;
1694 tn.zipfile_num=mr->item.id_hi; 1857 tn.zipfile_num = mr->item.id_hi;
1695 tn.mode=2; 1858 tn.mode = 2;
1696 tn.end=tn.start+le32_to_cpu(entry->data[0])+1; 1859 tn.end = tn.start + le32_to_cpu(entry->data[0]) + 1;
1697 push_tile(mr, &tn, 0, 0); 1860 push_tile(mr, &tn, 0, 0);
1698 return 1; 1861 return 1;
1699 } 1862 }
1700 return 0; 1863 return 0;
1701} 1864}
1702 1865
1703static struct item * 1866static struct item *
1704map_rect_get_item_binfile(struct map_rect_priv *mr) 1867map_rect_get_item_binfile(struct map_rect_priv *mr)
1705{ 1868{
1869#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1870 dbg(0,"+#+:enter\n");
1871#endif
1872
1706 struct tile *t; 1873 struct tile *t;
1707 struct map_priv *m=mr->m; 1874 struct map_priv *m = mr->m;
1875
1708 if (m->download) { 1876 if (m->download)
1877 {
1709 download(m, NULL, NULL, 0, 0, 0, 2); 1878 download(m, NULL, NULL, 0, 0, 0, 2);
1879#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1880 dbg(0,"+#+:leave9\n");
1881#endif
1710 return &busy_item; 1882 return &busy_item;
1711 } 1883 }
1884
1712 if (mr->status == 1) { 1885 if (mr->status == 1)
1886 {
1713 mr->status=0; 1887 mr->status = 0;
1714 if (push_zipfile_tile(mr, m->zip_members-1, 0, 0, 1)) 1888 if (push_zipfile_tile(mr, m->zip_members - 1, 0, 0, 1))
1889 {
1890#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1891 dbg(0,"+#+:leave8\n");
1892#endif
1715 return &busy_item; 1893 return &busy_item;
1716 } 1894 }
1895 }
1896
1717 for (;;) { 1897 for (;;)
1898 {
1718 t=mr->t; 1899 t = mr->t;
1900
1719 if (! t) 1901 if (!t)
1902 {
1903#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1904 dbg(0,"+#+:leave6\n");
1905#endif
1720 return NULL; 1906 return NULL;
1907 }
1908
1721 t->pos=t->pos_next; 1909 t->pos = t->pos_next;
1910
1722 if (t->pos >= t->end) { 1911 if (t->pos >= t->end)
1912 {
1723 if (pop_tile(mr)) 1913 if (pop_tile(mr))
1914 {
1724 continue; 1915 continue;
1916 }
1917
1918#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1919 dbg(0,"+#+:leave5\n");
1920#endif
1921
1725 return NULL; 1922 return NULL;
1726 } 1923 }
1924
1727 setup_pos(mr); 1925 setup_pos(mr);
1728 binfile_coord_rewind(mr); 1926 binfile_coord_rewind(mr);
1729 binfile_attr_rewind(mr); 1927 binfile_attr_rewind(mr);
1730 if ((mr->item.type == type_submap) && (!mr->country_id)) { 1928 if ((mr->item.type == type_submap) && (!mr->country_id))
1929 {
1731 if (map_parse_submap(mr, 1)) 1930 if (map_parse_submap(mr, 1))
1931 {
1932#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1933 dbg(0,"+#+:leave4\n");
1934#endif
1732 return &busy_item; 1935 return &busy_item;
1936 }
1733 continue; 1937 continue;
1734 } 1938 }
1735 if (t->mode != 2) { 1939 if (t->mode != 2)
1940 {
1736 mr->item.id_hi=t->zipfile_num; 1941 mr->item.id_hi = t->zipfile_num;
1737 mr->item.id_lo=t->pos-t->start; 1942 mr->item.id_lo = t->pos - t->start;
1738 if (mr->m->changes && push_modified_item(mr)) 1943 if (mr->m->changes && push_modified_item(mr))
1739 continue; 1944 continue;
1740 } 1945 }
1741 if (mr->country_id) 1946 if (mr->country_id)
1742 { 1947 {
1743 if (mr->item.type == type_countryindex) { 1948 if (mr->item.type == type_countryindex)
1949 {
1744 map_parse_country_binfile(mr); 1950 map_parse_country_binfile(mr);
1745 } 1951 }
1746 if (item_is_town(mr->item)) 1952 if (item_is_town(mr->item))
1747 { 1953 {
1954#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1955 dbg(0,"+#+:leave3\n");
1956#endif
1748 return &mr->item; 1957 return &mr->item;
1958 }
1749 } else { 1959 else
1960 {
1750 continue; 1961 continue;
1751 } 1962 }
1752 } 1963 }
1964#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1965 dbg(0,"+#+:leave 2\n");
1966#endif
1753 return &mr->item; 1967 return &mr->item;
1754 } 1968 }
1969
1970#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1971 dbg(0,"+#+:leave\n");
1972#endif
1755} 1973}
1756 1974
1757static struct item * 1975static struct item *
1758map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo) 1976map_rect_get_item_byid_binfile(struct map_rect_priv *mr, int id_hi, int id_lo)
1759{ 1977{
1760 struct tile *t; 1978 struct tile *t;
1761 if (mr->m->eoc) 1979 if (mr->m->eoc)
1762 { 1980 {
1763 while (pop_tile(mr)); 1981 while (pop_tile(mr))
1982 ;
1764 push_zipfile_tile(mr, id_hi, 0, 0, 0); 1983 push_zipfile_tile(mr, id_hi, 0, 0, 0);
1765 } 1984 }
1766 t=mr->t; 1985 t = mr->t;
1767 t->pos=t->start+id_lo; 1986 t->pos = t->start + id_lo;
1768 mr->item.id_hi=id_hi; 1987 mr->item.id_hi = id_hi;
1769 mr->item.id_lo=id_lo; 1988 mr->item.id_lo = id_lo;
1770 if (mr->m->changes) 1989 if (mr->m->changes)
1771 { 1990 {
1772 push_modified_item(mr); 1991 push_modified_item(mr);
1773 } 1992 }
1774 setup_pos(mr); 1993 setup_pos(mr);
1776 binfile_attr_rewind(mr); 1995 binfile_attr_rewind(mr);
1777 1996
1778 return &mr->item; 1997 return &mr->item;
1779} 1998}
1780 1999
1781static int
1782binmap_search_by_index(struct map_priv *map, struct item *item, struct map_rect_priv **ret) 2000static int binmap_search_by_index(struct map_priv *map, struct item *item, struct map_rect_priv **ret)
1783{ 2001{
1784 struct attr zipfile_ref; 2002 struct attr zipfile_ref;
1785 int *data; 2003 int *data;
1786 2004
1787 if (!item) { 2005 if (!item)
2006 {
1788 *ret=NULL; 2007 *ret = NULL;
1789 return 0; 2008 return 0;
1790 } 2009 }
1791 if (item_attr_get(item, attr_item_id, &zipfile_ref)) { 2010 if (item_attr_get(item, attr_item_id, &zipfile_ref))
2011 {
1792 data=zipfile_ref.u.data; 2012 data = zipfile_ref.u.data;
1793 *ret=map_rect_new_binfile_int(map, NULL); 2013 *ret = map_rect_new_binfile_int(map, NULL);
1794 push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), -1, 0); 2014 push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), -1, 0);
1795 return 3; 2015 return 3;
1796 } 2016 }
1797 if (item_attr_get(item, attr_zipfile_ref, &zipfile_ref)) { 2017 if (item_attr_get(item, attr_zipfile_ref, &zipfile_ref))
2018 {
1798 *ret=map_rect_new_binfile_int(map, NULL); 2019 *ret = map_rect_new_binfile_int(map, NULL);
1799 push_zipfile_tile(*ret, zipfile_ref.u.num, 0, 0, 0); 2020 push_zipfile_tile(*ret, zipfile_ref.u.num, 0, 0, 0);
1800 return 1; 2021 return 1;
1801 } 2022 }
1802 if (item_attr_get(item, attr_zipfile_ref_block, &zipfile_ref)) { 2023 if (item_attr_get(item, attr_zipfile_ref_block, &zipfile_ref))
2024 {
1803 data=zipfile_ref.u.data; 2025 data = zipfile_ref.u.data;
1804 *ret=map_rect_new_binfile_int(map, NULL); 2026 *ret = map_rect_new_binfile_int(map, NULL);
1805 push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), le32_to_cpu(data[2]), 0); 2027 push_zipfile_tile(*ret, le32_to_cpu(data[0]), le32_to_cpu(data[1]), le32_to_cpu(data[2]), 0);
1806 return 2; 2028 return 2;
1807 } 2029 }
1808 *ret=NULL; 2030 *ret = NULL;
1809 return 0; 2031 return 0;
1810} 2032}
1811 2033
1812static struct map_rect_priv * 2034static struct map_rect_priv *
1813binmap_search_street_by_place(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel) 2035binmap_search_street_by_place(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel)
1814{ 2036{
1815 struct attr town_name, poly_town_name; 2037 struct attr town_name, poly_town_name;
1816 struct map_rect_priv *map_rec2; 2038 struct map_rect_priv *map_rec2;
1817 struct item *place; 2039 struct item *place;
1818 int found=0; 2040 int found = 0;
1819 2041
1820 if (!item_attr_get(town, attr_label, &town_name)) 2042 if (!item_attr_get(town, attr_label, &town_name))
1821 return NULL; 2043 return NULL;
1822 sel->range = item_range_all; 2044 sel->range = item_range_all;
1823 sel->order = 18; 2045 sel->order = 18;
1824 sel->next = NULL; 2046 sel->next = NULL;
1825 sel->u.c_rect.lu=*c; 2047 sel->u.c_rect.lu = *c;
1826 sel->u.c_rect.rl=*c; 2048 sel->u.c_rect.rl = *c;
1827 map_rec2=map_rect_new_binfile(map, sel); 2049 map_rec2 = map_rect_new_binfile(map, sel);
1828 while ((place=map_rect_get_item_binfile(map_rec2))) { 2050 while ((place = map_rect_get_item_binfile(map_rec2)))
1829 if (item_is_poly_place(*place) && 2051 {
1830 item_attr_get(place, attr_label, &poly_town_name) && 2052 if (item_is_poly_place(*place) && item_attr_get(place, attr_label, &poly_town_name) && !strcmp(poly_town_name.u.str, town_name.u.str))
1831 !strcmp(poly_town_name.u.str,town_name.u.str)) { 2053 {
1832 struct coord c[128]; 2054 struct coord c[128];
1833 int i,count; 2055 int i, count;
1834 found=1; 2056 found = 1;
1835 while ((count=item_coord_get(place, c, 128))) { 2057 while ((count = item_coord_get(place, c, 128)))
2058 {
1836 for (i = 0 ; i < count ; i++) 2059 for (i = 0; i < count; i++)
2060 {
1837 coord_rect_extend(&sel->u.c_rect, &c[i]); 2061 coord_rect_extend(&sel->u.c_rect, &c[i]);
1838 } 2062 }
1839 } 2063 }
1840 } 2064 }
2065 }
2066
1841 map_rect_destroy_binfile(map_rec2); 2067 map_rect_destroy_binfile(map_rec2);
1842 if (found) 2068 if (found)
2069 {
1843 return map_rect_new_binfile(map, sel); 2070 return map_rect_new_binfile(map, sel);
2071 }
1844 return NULL; 2072 return NULL;
1845} 2073}
1846 2074
1847static struct map_rect_priv * 2075static struct map_rect_priv *
1848binmap_search_street_by_estimate(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel) 2076binmap_search_street_by_estimate(struct map_priv *map, struct item *town, struct coord *c, struct map_selection *sel)
1849{ 2077{
1850 int size = 10000; 2078 int size = 10000;
1851 switch (town->type) { 2079 switch (town->type)
2080 {
1852 case type_town_label_1e7: 2081 case type_town_label_1e7:
1853 case type_town_label_5e6: 2082 case type_town_label_5e6:
1854 case type_town_label_2e6: 2083 case type_town_label_2e6:
1855 case type_town_label_1e6: 2084 case type_town_label_1e6:
1856 case type_town_label_5e5: 2085 case type_town_label_5e5:
1881 size = 1000; 2110 size = 1000;
1882 break; 2111 break;
1883 default: 2112 default:
1884 break; 2113 break;
1885 } 2114 }
2115
2116 if (global_search_street_size_factor > 1)
2117 {
2118 size = size * global_search_street_size_factor;
2119 }
2120
1886 sel->u.c_rect.lu.x = c->x-size; 2121 sel->u.c_rect.lu.x = c->x - size;
1887 sel->u.c_rect.lu.y = c->y+size; 2122 sel->u.c_rect.lu.y = c->y + size;
1888 sel->u.c_rect.rl.x = c->x+size; 2123 sel->u.c_rect.rl.x = c->x + size;
1889 sel->u.c_rect.rl.y = c->y-size; 2124 sel->u.c_rect.rl.y = c->y - size;
1890 return map_rect_new_binfile(map, sel); 2125 return map_rect_new_binfile(map, sel);
1891} 2126}
1892 2127
1893static struct map_rect_priv * 2128static struct map_rect_priv *
1894binmap_search_housenumber_by_estimate(struct map_priv *map, struct coord *c, struct map_selection *sel) 2129binmap_search_housenumber_by_estimate(struct map_priv *map, struct coord *c, struct map_selection *sel)
1895{ 2130{
1896 int size = 20; 2131 int size = 20;
1897 sel->u.c_rect.lu.x = c->x-size; 2132 sel->u.c_rect.lu.x = c->x - size;
1898 sel->u.c_rect.lu.y = c->y+size; 2133 sel->u.c_rect.lu.y = c->y + size;
1899 sel->u.c_rect.rl.x = c->x+size; 2134 sel->u.c_rect.rl.x = c->x + size;
1900 sel->u.c_rect.rl.y = c->y-size; 2135 sel->u.c_rect.rl.y = c->y - size;
1901 2136
1902 sel->range = item_range_all; 2137 sel->range = item_range_all;
1903 sel->order = 18; 2138 sel->order = 18;
1904 //sel->next = NULL; 2139 //sel->next = NULL;
1905 2140
1910binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial) 2145binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, int partial)
1911{ 2146{
1912 struct map_rect_priv *map_rec; 2147 struct map_rect_priv *map_rec;
1913 struct map_search_priv *msp=g_new0(struct map_search_priv, 1); 2148 struct map_search_priv *msp=g_new0(struct map_search_priv, 1);
1914 struct item *town; 2149 struct item *town;
1915 int willsearch=0; 2150 int willsearch = 0;
1916 2151
1917 msp->search = search; 2152 msp->search = search;
1918 msp->partial = partial; 2153 msp->partial = partial;
1919 /* 2154 /*
1920 * NOTE: If you implement search for other attributes than attr_town_name and attr_street_name, 2155 * NOTE: If you implement search for other attributes than attr_town_name and attr_street_name,
1921 * please update this comment and the documentation for map_search_new() in map.c 2156 * please update this comment and the documentation for map_search_new() in map.c
1922 */ 2157 */
1923 switch (search->type) 2158 switch (search->type)
1924 { 2159 {
1925 case attr_country_name: 2160 case attr_country_name:
1926 break; 2161 break;
1927 case attr_town_name: 2162 case attr_town_name:
1928 case attr_town_or_district_name: 2163 case attr_town_or_district_name:
1929 map_rec = map_rect_new_binfile(map, NULL); 2164 map_rec = map_rect_new_binfile(map, NULL);
1930 if (!map_rec) 2165 if (!map_rec)
2166 {
1931 break; 2167 break;
2168 }
1932 map_rec->country_id = item->id_lo; 2169 map_rec->country_id = item->id_lo;
1933 msp->mr = map_rec; 2170 msp->mr = map_rec;
1934 willsearch=1; 2171 willsearch = 1;
1935 break; 2172 break;
1936 case attr_town_postal: 2173 case attr_town_postal:
1937 break; 2174 break;
1938 case attr_street_name: 2175 case attr_street_name:
1939 if (! item->map) 2176 if (!item->map)
1940 break; 2177 break;
1941 if (!map_priv_is(item->map, map)) 2178 if (!map_priv_is(item->map, map))
1942 break; 2179 break;
1943 map_rec = map_rect_new_binfile(map, NULL); 2180 map_rec = map_rect_new_binfile(map, NULL);
1944 town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo); 2181 town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo);
1946 { 2183 {
1947 struct coord c; 2184 struct coord c;
1948 2185
1949 if (binmap_search_by_index(map, town, &msp->mr)) 2186 if (binmap_search_by_index(map, town, &msp->mr))
1950 { 2187 {
2188 //dbg(0, "search:mode=1\n");
1951 msp->mode = 1; 2189 msp->mode = 1;
1952 } 2190 }
1953 else 2191 else
1954 { 2192 {
1955 if (item_coord_get(town, &c, 1)) 2193 if (item_coord_get(town, &c, 1))
1956 { 2194 {
1957 if ((msp->mr=binmap_search_street_by_place(map, town, &c, &msp->ms))) 2195 if ((msp->mr = binmap_search_street_by_place(map, town, &c, &msp->ms)))
1958 { 2196 {
2197 //dbg(0, "search:mode=2\n");
1959 msp->mode = 2; 2198 msp->mode = 2;
1960 } 2199 }
1961 else 2200 else
1962 { 2201 {
1963 msp->mr=binmap_search_street_by_estimate(map, town, &c, &msp->ms); 2202 msp->mr = binmap_search_street_by_estimate(map, town, &c, &msp->ms);
2203 //dbg(0, "search:mode=3\n");
1964 msp->mode = 3; 2204 msp->mode = 3;
1965 } 2205 }
1966 } 2206 }
1967 } 2207 }
1968 map_rect_destroy_binfile(map_rec); 2208 map_rect_destroy_binfile(map_rec);
1969 if (!msp->mr) 2209 if (!msp->mr)
1970 { 2210 {
1971 break; 2211 break;
1972 } 2212 }
1973 willsearch=1; 2213 willsearch = 1;
1974 break; 2214 break;
1975 } 2215 }
1976 map_rect_destroy_binfile(map_rec); 2216 map_rect_destroy_binfile(map_rec);
1977 break; 2217 break;
1978 case attr_house_number: 2218 case attr_house_number:
1979 dbg(1,"case house_number"); 2219 // dbg(1, "case house_number");
1980 if (! item->map) 2220 if (!item->map)
1981 break; 2221 break;
1982 if (!map_priv_is(item->map, map)) 2222 if (!map_priv_is(item->map, map))
1983 break; 2223 break;
1984 msp->map=map; 2224 msp->map = map;
1985 msp->mr_item = map_rect_new_binfile(map, NULL); 2225 msp->mr_item = map_rect_new_binfile(map, NULL);
1986 msp->item = map_rect_get_item_byid_binfile(msp->mr_item, item->id_hi, item->id_lo); 2226 msp->item = map_rect_get_item_byid_binfile(msp->mr_item, item->id_hi, item->id_lo);
1987 if (binmap_search_by_index(map, msp->item, &msp->mr) != 3) 2227 if (binmap_search_by_index(map, msp->item, &msp->mr) != 3)
1988 { 2228 {
1989 struct coord c; 2229 struct coord c;
1990 if (item_coord_get(msp->item, &c, 1)) 2230 if (item_coord_get(msp->item, &c, 1))
1991 { 2231 {
1992 msp->mr=binmap_search_housenumber_by_estimate(map, &c, &msp->ms); 2232 msp->mr = binmap_search_housenumber_by_estimate(map, &c, &msp->ms);
1993 msp->mode = 2; 2233 msp->mode = 2;
1994 } 2234 }
1995 map_rect_destroy_binfile(msp->mr_item); 2235 map_rect_destroy_binfile(msp->mr_item);
1996 msp->mr_item=NULL; 2236 msp->mr_item = NULL;
1997 } 2237 }
1998 if (!msp->mr) 2238 if (!msp->mr)
1999 { 2239 {
2000 break; 2240 break;
2001 } 2241 }
2002 willsearch=1; 2242 willsearch = 1;
2003 break; 2243 break;
2004 default: 2244 default:
2005 break; 2245 break;
2006 } 2246 }
2007 2247
2008 if (!willsearch) 2248 if (!willsearch)
2009 { 2249 {
2010 g_free(msp); 2250 g_free(msp);
2011 msp=NULL; 2251 msp = NULL;
2012 } 2252 }
2013 else 2253 else
2014 { 2254 {
2015 msp->str=linguistics_casefold(search->u.str); 2255 msp->str = linguistics_casefold(search->u.str);
2016 } 2256 }
2017 return msp; 2257 return msp;
2018} 2258}
2019 2259
2020static int
2021ascii_cmp(char *name, char *match, int partial) 2260static int ascii_cmp(char *name, char *match, int partial)
2022{ 2261{
2023 int ret=1; 2262 int ret = 1;
2024 2263
2025 if (name==NULL) 2264 if (name == NULL)
2026 { 2265 {
2027 return ret; 2266 return ret;
2028 } 2267 }
2029 2268
2030 if (match==NULL) 2269 if (match == NULL)
2031 { 2270 {
2032 return ret; 2271 return ret;
2033 } 2272 }
2034 2273
2035 char *s2=linguistics_casefold(match); // user entered search string 2274 char *s2 = linguistics_casefold(match); // user entered search string
2036 char *s1=linguistics_casefold(name); // string from mapfile 2275 char *s1 = linguistics_casefold(name); // string from mapfile
2037 char *s1_1=linguistics_expand_special(s1, 1); 2276 char *s1_1 = linguistics_expand_special(s1, 1);
2038 char *s2_1=linguistics_expand_special(s2, 1); 2277 char *s2_1 = linguistics_expand_special(s2, 1);
2039 2278
2040 if (s1_1) 2279 if (s1_1)
2041 { 2280 {
2042 if (s2_1) 2281 if (s2_1)
2043 { 2282 {
2044 ret=linguistics_compare(s1_1,s2_1,partial); 2283 ret = linguistics_compare(s1_1, s2_1, partial);
2045 } 2284 }
2046 else 2285 else
2047 { 2286 {
2048 ret=linguistics_compare(s1_1,s2,partial); 2287 ret = linguistics_compare(s1_1, s2, partial);
2049 } 2288 }
2050 } 2289 }
2051 else 2290 else
2052 { 2291 {
2053 if (s2_1) 2292 if (s2_1)
2054 { 2293 {
2055 ret=linguistics_compare(s1,s2_1,partial); 2294 ret = linguistics_compare(s1, s2_1, partial);
2056 } 2295 }
2057 else 2296 else
2058 { 2297 {
2059 ret=linguistics_compare(s1,s2,partial); 2298 ret = linguistics_compare(s1, s2, partial);
2060 } 2299 }
2061 } 2300 }
2062 2301
2063 if (s1_1) 2302 if (s1_1)
2064 g_free(s1_1); 2303 g_free(s1_1);
2075{ 2314{
2076 struct coord c; 2315 struct coord c;
2077 char str[0]; 2316 char str[0];
2078}; 2317};
2079 2318
2080static guint
2081duplicate_hash(gconstpointer key) 2319static guint duplicate_hash(gconstpointer key)
2082{ 2320{
2083 const struct duplicate *d=key; 2321 const struct duplicate *d = key;
2084 return d->c.x^d->c.y^g_str_hash(d->str); 2322 return d->c.x ^ d->c.y ^ g_str_hash(d->str);
2085} 2323}
2086 2324
2087static gboolean
2088duplicate_equal(gconstpointer a, gconstpointer b) 2325static gboolean duplicate_equal(gconstpointer a, gconstpointer b)
2089{ 2326{
2090 const struct duplicate *da=a; 2327 const struct duplicate *da = a;
2091 const struct duplicate *db=b; 2328 const struct duplicate *db = b;
2092 return (da->c.x == db->c.x && da->c.y == da->c.y && g_str_equal(da->str,db->str)); 2329 return (da->c.x == db->c.x && da->c.y == da->c.y && g_str_equal(da->str, db->str));
2093} 2330}
2094 2331
2095static int
2096duplicate(struct map_search_priv *msp, struct item *item, enum attr_type attr_type) 2332static int duplicate(struct map_search_priv *msp, struct item *item, enum attr_type attr_type)
2097{ 2333{
2098 struct attr attr; 2334 struct attr attr;
2099 if (!msp->search_results) 2335 if (!msp->search_results)
2100 msp->search_results = g_hash_table_new_full(duplicate_hash, duplicate_equal, g_free, NULL); 2336 msp->search_results = g_hash_table_new_full(duplicate_hash, duplicate_equal, g_free_func, NULL);
2101 binfile_attr_rewind(item->priv_data); 2337 binfile_attr_rewind(item->priv_data);
2102 if (!item_attr_get(item, attr_type, &attr)) 2338 if (!item_attr_get(item, attr_type, &attr))
2103 return 1; 2339 return 1;
2104 { 2340 {
2105 int len=sizeof(struct coord)+strlen(attr.u.str)+1; 2341 int len = sizeof(struct coord) + strlen(attr.u.str) + 1;
2106 char *buffer=g_alloca(sizeof(char)*len); 2342 char *buffer = g_alloca(sizeof(char) * len);
2107 struct duplicate *d=(struct duplicate *)buffer; 2343 struct duplicate *d = (struct duplicate *) buffer;
2108 if (!item_coord_get(item, &d->c, 1)) { 2344 if (!item_coord_get(item, &d->c, 1))
2345 {
2109 d->c.x=0; 2346 d->c.x = 0;
2110 d->c.y=0; 2347 d->c.y = 0;
2111 } 2348 }
2112 binfile_coord_rewind(item->priv_data); 2349 binfile_coord_rewind(item->priv_data);
2113 strcpy(d->str, attr.u.str); 2350 strcpy(d->str, attr.u.str);
2114 if (!g_hash_table_lookup(msp->search_results, d)) { 2351 if (!g_hash_table_lookup(msp->search_results, d))
2352 {
2115 struct duplicate *dc=g_malloc(len); 2353 struct duplicate *dc = g_malloc(len);
2116 memcpy(dc, d, len); 2354 memcpy(dc, d, len);
2117 g_hash_table_insert(msp->search_results, dc, GINT_TO_POINTER(1)); 2355 g_hash_table_insert(msp->search_results, dc, GINT_TO_POINTER(1));
2118 binfile_attr_rewind(item->priv_data); 2356 binfile_attr_rewind(item->priv_data);
2119 return 0; 2357 return 0;
2120 } 2358 }
2126binmap_search_get_item(struct map_search_priv *map_search) 2364binmap_search_get_item(struct map_search_priv *map_search)
2127{ 2365{
2128 struct item* it; 2366 struct item* it;
2129 struct attr at; 2367 struct attr at;
2130 2368
2369 // // dbg(0,"Enter\n");
2370
2131 for (;;) 2371 for (;;)
2132 { 2372 {
2133 while ((it = map_rect_get_item_binfile(map_search->mr))) 2373 while ((it = map_rect_get_item_binfile(map_search->mr)))
2134 { 2374 {
2135 switch (map_search->search->type) 2375 switch (map_search->search->type)
2136 { 2376 {
2137 case attr_town_name: 2377 case attr_town_name:
2138 case attr_district_name: 2378 case attr_district_name:
2139 case attr_town_or_district_name: 2379 case attr_town_or_district_name:
2140 2380
2141#if 0 2381#if 0
2142 if (map_search->mr->tile_depth > 1 && item_is_town(*it) && !item_is_district(*it) && map_search->search->type != attr_district_name) {
2143 if (binfile_attr_get(it->priv_data, attr_town_name_match, &at) || binfile_attr_get(it->priv_data, attr_town_name, &at)) {
2144 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name))
2145 return it;
2146 }
2147 }
2148#endif
2149
2150#if 1
2151 if (map_search->mr->tile_depth > 1 && item_is_town(*it) && !item_is_district(*it) && map_search->search->type != attr_district_name) 2382 if (map_search->mr->tile_depth > 1 && item_is_town(*it) && !item_is_district(*it) && map_search->search->type != attr_district_name)
2152 {
2153 if (binfile_attr_get(it->priv_data, attr_town_name, &at))
2154 { 2383 {
2155 //dbg(0,"22town n:%s\n",at.u.str); 2384 if (binfile_attr_get(it->priv_data, attr_town_name_match, &at) || binfile_attr_get(it->priv_data, attr_town_name, &at))
2156 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial)
2157 // && !duplicate(map_search, it, attr_town_name)
2158 )
2159 { 2385 {
2160 //dbg(0,"town n:%s\n",at.u.str); 2386 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name))
2161 return it; 2387 return it;
2162 } 2388 }
2163 } 2389 }
2390#endif
2164 2391
2165 if (binfile_attr_get(it->priv_data, attr_town_name_match, &at)) 2392#if 1
2393 if (map_search->mr->tile_depth > 1 && item_is_town(*it) && !item_is_district(*it) && map_search->search->type != attr_district_name)
2166 { 2394 {
2395 if (binfile_attr_get(it->priv_data, attr_town_name, &at))
2396 {
2167 //dbg(0,"11town M:%s\n",at.u.str); 2397 //// dbg(0,"22town n:%s\n",at.u.str);
2168 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) 2398 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial)
2169 // && !duplicate(map_search, it, attr_town_name) 2399 // && !duplicate(map_search, it, attr_town_name)
2170 ) 2400 )
2171 {
2172 //dbg(0,"town M:%s\n",at.u.str);
2173 return it;
2174 }
2175 }
2176 }
2177#endif
2178
2179 if (map_search->mr->tile_depth > 1 && item_is_district(*it) && map_search->search->type != attr_town_name) {
2180 if (binfile_attr_get(it->priv_data, attr_district_name_match, &at) || binfile_attr_get(it->priv_data, attr_district_name, &at)) {
2181 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name))
2182 return it;
2183 }
2184 }
2185 break;
2186 case attr_street_name:
2187 if (map_search->mode == 1)
2188 {
2189 //if (binfile_attr_get(it->priv_data, attr_street_name_match, &at) || binfile_attr_get(it->priv_data, attr_street_name, &at)) {
2190 // if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_street_name)) {
2191 // return it;
2192 // }
2193 //}
2194
2195 if (binfile_attr_get(it->priv_data, attr_street_name, &at))
2196 {
2197 //dbg(0,"str AA:%s\n", at.u.str);
2198
2199 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial))
2200 {
2201 if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_street_name)))
2202 { 2401 {
2402 //// dbg(0,"town n:%s\n",at.u.str);
2203 return it; 2403 return it;
2204 } 2404 }
2205 else 2405 }
2406
2407 if (binfile_attr_get(it->priv_data, attr_town_name_match, &at))
2408 {
2409 //// dbg(0,"11town M:%s\n",at.u.str);
2410 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial)
2411 // && !duplicate(map_search, it, attr_town_name)
2412 )
2206 { 2413 {
2207 //dbg(0,"dup street 1:%s\n",at.u.str); 2414 //// dbg(0,"town M:%s\n",at.u.str);
2415 return it;
2208 } 2416 }
2209 } 2417 }
2210 } 2418 }
2419#endif
2211 2420
2212 if (binfile_attr_get(it->priv_data, attr_street_name_match, &at)) 2421 if (map_search->mr->tile_depth > 1 && item_is_district(*it) && map_search->search->type != attr_town_name)
2213 { 2422 {
2214 //dbg(0,"str BB:%s\n", at.u.str); 2423 if (binfile_attr_get(it->priv_data, attr_district_name_match, &at) || binfile_attr_get(it->priv_data, attr_district_name, &at))
2215
2216 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial))
2217 { 2424 {
2218 if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_street_name))) 2425 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_town_name))
2219 {
2220 return it; 2426 return it;
2221 }
2222 else
2223 {
2224 //dbg(0,"dup street 2:%s\n",at.u.str);
2225 }
2226 } 2427 }
2227 } 2428 }
2429 break;
2228 2430
2229 continue; 2431 case attr_street_name:
2230 }
2231 2432
2232 if (item_is_street(*it)) 2433 if (map_search->mode == 1)
2233 {
2234 struct attr at;
2235 if (map_selection_contains_item_rect(map_search->mr->sel, it))
2236 { 2434 {
2435 //dbg(0,"*in here 00*\n");
2436
2437 //if (binfile_attr_get(it->priv_data, attr_street_name_match, &at) || binfile_attr_get(it->priv_data, attr_street_name, &at)) {
2438 // if (!ascii_cmp(at.u.str, map_search->str, map_search->partial) && !duplicate(map_search, it, attr_street_name)) {
2439 // return it;
2440 // }
2441 //}
2442
2237 if (binfile_attr_get(it->priv_data, attr_label, &at)) 2443 if (binfile_attr_get(it->priv_data, attr_street_name, &at))
2238 { 2444 {
2239 int match=0; 2445 //// dbg(0,"str AA:%s\n", at.u.str);
2240 char *str=g_strdup(at.u.str);
2241 2446
2242 //dbg(0,"search=%s str is:%s\n",map_search->str, at.u.str);
2243
2244 if (!ascii_cmp(str, map_search->str, map_search->partial)) 2447 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial))
2245 { 2448 {
2246 match=1; 2449 if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_street_name)))
2247 }
2248
2249#if 0
2250 char *word=str;
2251 int first=1;
2252 do
2253 {
2254 if (!ascii_cmp(word, map_search->str, map_search->partial))
2255 { 2450 {
2256 match=1; 2451 return it;
2257 break;
2258 }
2259 if (first==1)
2260 {
2261 first=0;
2262 word=linguistics_next_word(word);
2263 } 2452 }
2264 else 2453 else
2265 { 2454 {
2266 word=linguistics_next_word(NULL); 2455 //// dbg(0,"dup street 1:%s\n",at.u.str);
2267 } 2456 }
2268 } while (word); 2457 }
2458 }
2459
2460 if (binfile_attr_get(it->priv_data, attr_street_name_match, &at))
2461 {
2462 //// dbg(0,"str BB:%s\n", at.u.str);
2463
2464 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial))
2465 {
2466 if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_street_name_match)))
2467 {
2468 return it;
2469 }
2470 else
2471 {
2472 //// dbg(0,"dup street 2:%s\n",at.u.str);
2473 }
2474 }
2475 }
2476
2477 continue;
2478 }
2479
2480#if 1
2481 // ------------------------------------
2482 // map_search->mode == 2 or 3
2483 // ------------------------------------
2484 if (item_is_street(*it))
2485 {
2486 // dbg(0,"*in here 11*\n");
2487
2488 struct attr at;
2489 if (map_selection_contains_item_rect(map_search->mr->sel, it))
2490 {
2491 if (binfile_attr_get(it->priv_data, attr_label, &at))
2492 {
2493 int match = 0;
2494 char *str = g_strdup(at.u.str);
2495 // dbg(0,"search=%s str is:%s\n",map_search->str, at.u.str);
2496 if (!ascii_cmp(str, map_search->str, map_search->partial))
2497 {
2498 match = 1;
2499 }
2500 g_free(str);
2501 if (match)
2502 {
2503 if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_label)))
2504 {
2505 item_coord_rewind(it);
2506 return it;
2507 }
2508 }
2509 }
2510
2511 if (binfile_attr_get(it->priv_data, attr_street_name_match, &at))
2512 {
2513 int match = 0;
2514 char *str = g_strdup(at.u.str);
2515 // dbg(0,"search=%s mstr is:%s\n",map_search->str, at.u.str);
2516 if (!ascii_cmp(str, map_search->str, map_search->partial))
2517 {
2518 match = 1;
2519 }
2520 g_free(str);
2521 if (match)
2522 {
2523 if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_street_name_match)))
2524 {
2525 item_coord_rewind(it);
2526 return it;
2527 }
2528 }
2529 }
2530 //else
2531 //{
2532 // if (binfile_attr_get(it->priv_data, attr_street_name, &at))
2533 // {
2534 // // dbg(0,"---str X*X:%s\n", at.u.str);
2535 // }
2536 //}
2537 }
2538 }
2269#endif 2539#endif
2270 g_free(str); 2540 break;
2271 2541 case attr_house_number:
2272 if (match) 2542 //if (it->type == type_house_number)
2543 if ((it->type == type_house_number) || (type_house_number_interpolation_even) || (type_house_number_interpolation_odd) || (type_house_number_interpolation_all))
2544 {
2545 // is it a housenumber?
2546 if (binfile_attr_get(it->priv_data, attr_house_number, &at))
2547 {
2548 // match housenumber to our string
2549 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial))
2273 { 2550 {
2274 if ((offline_search_filter_duplicates != 1) || (!duplicate(map_search, it, attr_label))) 2551 //binfile_attr_get(it->priv_data, attr_street_name, &at);
2552 //// dbg(0,"hnnn B1 street_name=%s",at.u.str);
2553
2554 if (!duplicate(map_search, it, attr_house_number))
2275 { 2555 {
2276 item_coord_rewind(it); 2556 binfile_attr_rewind(it->priv_data);
2277 return it; 2557 return it;
2278 } 2558 }
2279 } 2559 }
2280 } 2560 }
2281 //else 2561 else
2282 //{
2283 // if (binfile_attr_get(it->priv_data, attr_street_name, &at))
2284 // {
2285 // dbg(0,"---str X*X:%s\n", at.u.str);
2286 // }
2287 //}
2288 }
2289 }
2290 break;
2291 case attr_house_number:
2292 //if (it->type == type_house_number)
2293 if ((it->type == type_house_number)||(type_house_number_interpolation_even)
2294 ||(type_house_number_interpolation_odd)
2295 ||(type_house_number_interpolation_all)
2296 )
2297 {
2298 // is it a housenumber?
2299 if (binfile_attr_get(it->priv_data, attr_house_number, &at))
2300 {
2301 // match housenumber to our string
2302 if (!ascii_cmp(at.u.str, map_search->str, map_search->partial))
2303 { 2562 {
2304 //binfile_attr_get(it->priv_data, attr_street_name, &at);
2305 //dbg(0,"hnnn B1 street_name=%s",at.u.str);
2306
2307 if (!duplicate(map_search, it, attr_house_number))
2308 {
2309 binfile_attr_rewind(it->priv_data);
2310 return it; 2563 return it;
2311 }
2312 } 2564 }
2313 } 2565 }
2314 else
2315 {
2316 return it;
2317 }
2318 }
2319 continue; 2566 continue;
2320 default: 2567 default:
2321 return NULL; 2568 return NULL;
2322 } 2569 }
2323 } 2570 }
2571
2324 if (!map_search->mr_item) 2572 if (!map_search->mr_item)
2573 {
2325 return NULL; 2574 return NULL;
2575 }
2326 map_rect_destroy_binfile(map_search->mr); 2576 map_rect_destroy_binfile(map_search->mr);
2327 if (!binmap_search_by_index(map_search->map, map_search->item, &map_search->mr)) 2577 if (!binmap_search_by_index(map_search->map, map_search->item, &map_search->mr))
2578 {
2328 return NULL; 2579 return NULL;
2329 } 2580 }
2330} 2581 } // endless for-loop
2331 2582
2583 return NULL; // this is never reached
2584}
2332 2585
2333static void
2334binmap_search_destroy(struct map_search_priv *ms) 2586static void binmap_search_destroy(struct map_search_priv *ms)
2335{ 2587{
2336 if (ms->search_results) 2588 if (ms->search_results)
2337 g_hash_table_destroy(ms->search_results); 2589 g_hash_table_destroy(ms->search_results);
2338 if (ms->mr_item) 2590 if (ms->mr_item)
2339 map_rect_destroy_binfile(ms->mr_item); 2591 map_rect_destroy_binfile(ms->mr_item);
2342 if (ms->str) 2594 if (ms->str)
2343 g_free(ms->str); 2595 g_free(ms->str);
2344 g_free(ms); 2596 g_free(ms);
2345} 2597}
2346 2598
2347static int
2348binmap_get_attr(struct map_priv *m, enum attr_type type, struct attr *attr) 2599static int binmap_get_attr(struct map_priv *m, enum attr_type type, struct attr *attr)
2349{ 2600{
2350 attr->type=type; 2601 attr->type = type;
2351 switch (type) { 2602 switch (type)
2603 {
2352 case attr_map_release: 2604 case attr_map_release:
2353 if (m->map_release) { 2605 if (m->map_release)
2606 {
2354 attr->u.str=m->map_release; 2607 attr->u.str = m->map_release;
2608 return 1;
2609 }
2610 break;
2611 case attr_progress:
2612 if (m->progress)
2613 {
2614 attr->u.str = m->progress;
2615 return 1;
2616 }
2617 default:
2618 break;
2619 }
2620 return 0;
2621}
2622
2623static int binmap_set_attr(struct map_priv *map, struct attr *attr)
2624{
2625 switch (attr->type)
2626 {
2627 case attr_update:
2628 map->download_enabled = attr->u.num;
2355 return 1; 2629 return 1;
2356 }
2357 break;
2358 case attr_progress:
2359 if (m->progress) {
2360 attr->u.str=m->progress;
2361 return 1;
2362 }
2363 default: 2630 default:
2364 break;
2365 }
2366 return 0;
2367}
2368
2369static int
2370binmap_set_attr(struct map_priv *map, struct attr *attr)
2371{
2372 switch (attr->type) {
2373 case attr_update:
2374 map->download_enabled = attr->u.num;
2375 return 1;
2376 default:
2377 return 0; 2631 return 0;
2378 } 2632 }
2379 2633
2380} 2634}
2381 2635
2382static struct map_methods map_methods_binfile = { 2636static struct map_methods map_methods_binfile =
2383 projection_mg, 2637{ projection_mg, "utf-8", map_destroy_binfile, map_rect_new_binfile, map_rect_destroy_binfile, map_rect_get_item_binfile, map_rect_get_item_byid_binfile, binmap_search_new, binmap_search_destroy, binmap_search_get_item, NULL, binmap_get_attr, binmap_set_attr, };
2384 "utf-8",
2385 map_destroy_binfile,
2386 map_rect_new_binfile,
2387 map_rect_destroy_binfile,
2388 map_rect_get_item_binfile,
2389 map_rect_get_item_byid_binfile,
2390 binmap_search_new,
2391 binmap_search_destroy,
2392 binmap_search_get_item,
2393 NULL,
2394 binmap_get_attr,
2395 binmap_set_attr,
2396};
2397 2638
2398static int
2399binfile_get_index(struct map_priv *m) 2639static int binfile_get_index(struct map_priv *m)
2400{ 2640{
2641 //dbg(0,"_enter\n");
2401 int len; 2642 int len;
2402 int cde_index_size; 2643 int cde_index_size;
2403 int offset; 2644 long long offset; // int or long long ?
2404 struct zip_cd *cd; 2645 struct zip_cd *cd;
2405 2646
2406 len = strlen("index"); 2647 len = strlen("index");
2407 cde_index_size = sizeof(struct zip_cd)+len; 2648 cde_index_size = sizeof(struct zip_cd) + len;
2649 //dbg(0,"_cde_index_size=%d\n", cde_index_size);
2408 if (m->eoc64) 2650 if (m->eoc64)
2651 {
2652 //dbg(0,"_m->eoc64->zip64ecsz=%d\n", m->eoc64->zip64ecsz);
2409 offset = m->eoc64->zip64ecsz-cde_index_size; 2653 offset = m->eoc64->zip64ecsz - cde_index_size;
2654 //dbg(0,"_eoc64 offset="LONGLONG_FMT"\n", offset);
2655 }
2410 else 2656 else
2657 {
2658 //dbg(0,"_m->eoc->zipecsz=%d\n", m->eoc->zipecsz);
2411 offset = m->eoc->zipecsz-cde_index_size; 2659 offset = m->eoc->zipecsz - cde_index_size;
2660 //dbg(0,"_eoc offset="LONGLONG_FMT"\n", offset);
2661 }
2412 cd = binfile_read_cd(m, offset, len); 2662 cd = binfile_read_cd(m, offset, len);
2413 2663
2414 if (!cd) { 2664 if (!cd)
2665 {
2666 //dbg(0,"_!cd\n");
2415 cde_index_size+=sizeof(struct zip_cd_ext); 2667 cde_index_size += sizeof(struct zip_cd_ext);
2668 //dbg(0,"_cde_index_size=%d\n", cde_index_size);
2416 if (m->eoc64) 2669 if (m->eoc64)
2670 {
2417 offset = m->eoc64->zip64ecsz-cde_index_size; 2671 offset = m->eoc64->zip64ecsz - cde_index_size;
2672 //dbg(0,"_eoc64 offset aa.1="LONGLONG_FMT"\n", offset);
2673 }
2418 else 2674 else
2675 {
2419 offset = m->eoc->zipecsz-cde_index_size; 2676 offset = m->eoc->zipecsz - cde_index_size;
2677 //dbg(0,"_offset 22.0="LONGLONG_FMT"\n", offset);
2678 }
2420 cd = binfile_read_cd(m, offset, len+sizeof(struct zip_cd_ext)); 2679 cd = binfile_read_cd(m, offset, len + sizeof(struct zip_cd_ext));
2421 } 2680 }
2681 //dbg(0,"_offset 22="LONGLONG_FMT"\n", offset);
2682
2422 if (cd) { 2683 if (cd)
2684 {
2685 //dbg(0,"_cd 001\n");
2423 if (cd->zipcfnl == len && !strncmp(cd->zipcfn, "index", len)) { 2686 if (cd->zipcfnl == len && !strncmp(cd->zipcfn, "index", len))
2687 {
2424 m->index_offset=offset; 2688 m->index_offset = offset;
2425 m->index_cd=cd; 2689 m->index_cd = cd;
2690 //dbg(0,"_leave:offset 33="LONGLONG_FMT"\n", offset);
2426 return 1; 2691 return 1;
2427 } 2692 }
2693 //dbg(0,"_cd 002\n");
2428 } 2694 }
2695
2429 offset=binfile_search_cd(m, 0, "index", 0, 0); 2696 offset = binfile_search_cd(m, 0, "index", 0, 0);
2697 //dbg(0,"_offset 44="LONGLONG_FMT"\n", offset);
2698
2430 if (offset == -1) 2699 if (offset == -1)
2700 {
2701 //dbg(0,"_leave:55\n");
2431 return 0; 2702 return 0;
2703 }
2704
2432 cd=binfile_read_cd(m, offset, -1); 2705 cd = binfile_read_cd(m, offset, -1);
2706
2433 if (!cd) 2707 if (!cd)
2708 {
2709 //dbg(0,"_leave:66\n");
2434 return 0; 2710 return 0;
2711 }
2712
2435 m->index_offset=offset; 2713 m->index_offset = offset;
2436 m->index_cd=cd; 2714 m->index_cd = cd;
2715
2716 //dbg(0,"_leave:normal:offset 77="LONGLONG_FMT"\n", offset);
2437 return 1; 2717 return 1;
2438} 2718}
2439 2719
2440static int
2441map_binfile_zip_setup(struct map_priv *m, char *filename, int mmap) 2720static int map_binfile_zip_setup(struct map_priv *m, char *filename, int mmap)
2442{ 2721{
2722 //dbg(0,"_enter\n");
2723
2443 struct zip_cd *first_cd; 2724 struct zip_cd *first_cd;
2444 int i; 2725 int i;
2445 if (!(m->eoc=binfile_read_eoc(m->fi))) 2726 if (!(m->eoc = binfile_read_eoc(m->fi)))
2727 {
2728 //dbg(0,"_leave:1\n");
2446 return 0; 2729 return 0;
2730 }
2447 dbg_assert(m->eoc->zipedsk == m->eoc->zipecen); 2731 dbg_assert(m->eoc->zipedsk == m->eoc->zipecen);
2448 if (m->eoc->zipedsk && strlen(filename) > 3) { 2732 if (m->eoc->zipedsk && strlen(filename) > 3)
2449 char *tmpfilename=g_strdup(filename),*ext=tmpfilename+strlen(tmpfilename)-3; 2733 {
2734 char *tmpfilename = g_strdup(filename);
2735 char *ext = tmpfilename + strlen(tmpfilename) - 3;
2736
2737 //dbg(0,"_ff-1:%s\n", tmpfilename);
2738 //dbg(0,"_ff-2:%s\n", ext);
2739
2450 m->fis=g_new(struct file *,m->eoc->zipedsk); 2740 m->fis=g_new(struct file *,m->eoc->zipedsk);
2451 for (i = 0 ; i < m->eoc->zipedsk-1 ; i++) { 2741 for (i = 0; i < m->eoc->zipedsk - 1; i++)
2742 {
2452 sprintf(ext,"b%02d",i+1); 2743 sprintf(ext, "b%02d", i + 1);
2744 //dbg(0,"_ff--3:%s\n", ext);
2453 m->fis[i]=file_create(tmpfilename, 0); 2745 m->fis[i] = file_create(tmpfilename, 0);
2454 if (mmap) 2746 if (mmap)
2747 {
2748 //dbg(0,"_want mmap 2 %s\n", m->fis[i]->name);
2455 file_mmap(m->fis[i]); 2749 file_mmap(m->fis[i]);
2456 } 2750 }
2751 }
2457 m->fis[m->eoc->zipedsk-1]=m->fi; 2752 m->fis[m->eoc->zipedsk - 1] = m->fi;
2458 g_free(tmpfilename); 2753 g_free(tmpfilename);
2459 } 2754 }
2755 else
2756 {
2757 //dbg(0,"_ff-XX\n");
2758 }
2460 dbg(0,"num_disk %d\n",m->eoc->zipedsk); 2759 //dbg(0, "_num_disk %d\n", m->eoc->zipedsk);
2461 m->eoc64=binfile_read_eoc64(m->fi); 2760 m->eoc64 = binfile_read_eoc64(m->fi);
2761
2462 if (!binfile_get_index(m)) 2762 if (!binfile_get_index(m))
2763 {
2764 //dbg(0,"_leave:2\n");
2463 return 0; 2765 return 0;
2766 }
2767
2464 if (!(first_cd=binfile_read_cd(m, 0, 0))) 2768 if (!(first_cd = binfile_read_cd(m, 0, 0)))
2769 {
2770 //dbg(0,"_leave:3\n");
2465 return 0; 2771 return 0;
2772 }
2773
2466 m->cde_size=sizeof(struct zip_cd)+first_cd->zipcfnl+first_cd->zipcxtl; 2774 m->cde_size = sizeof(struct zip_cd) + first_cd->zipcfnl + first_cd->zipcxtl;
2467 m->zip_members=m->index_offset/m->cde_size+1; 2775 m->zip_members = m->index_offset / m->cde_size + 1;
2468 dbg(1,"cde_size %d\n", m->cde_size); 2776 //dbg(0, "_cde_size %d\n", m->cde_size);
2469 dbg(1,"members %d\n",m->zip_members); 2777 //dbg(0, "_members %d\n", m->zip_members);
2470 file_data_free(m->fi, (unsigned char *)first_cd); 2778 file_data_free(m->fi, (unsigned char *) first_cd);
2471 if (mmap) 2779 if (mmap)
2780 {
2781 //dbg(0,"_want mmap 3 %s\n", m->fi->name);
2472 file_mmap(m->fi); 2782 file_mmap(m->fi);
2783 }
2473 return 1; 2784 return 1;
2474} 2785}
2475
2476 2786
2477#if 0 2787#if 0
2478static int 2788static int
2479map_binfile_download_initial(struct map_priv *m) 2789map_binfile_download_initial(struct map_priv *m)
2480{ 2790{
2481 struct attr readwrite={attr_readwrite,{(void *)1}}; 2791 struct attr readwrite=
2482 struct attr create={attr_create,{(void *)1}}; 2792 { attr_readwrite,
2793 { (void *)1}};
2794 struct attr create=
2795 { attr_create,
2796 { (void *)1}};
2483 struct attr *attrs[4]; 2797 struct attr *attrs[4];
2484 struct file *out; 2798 struct file *out;
2485 long long woffset=0,planet_size; 2799 long long woffset=0,planet_size;
2486 int size_ret; 2800 int size_ret;
2487 int cd1size,cdisize; 2801 int cd1size,cdisize;
2506 download_directory_finish(download); 2820 download_directory_finish(download);
2507 download_initial_finish(download); 2821 download_initial_finish(download);
2508 m->fi=download->file; 2822 m->fi=download->file;
2509 g_free(download); 2823 g_free(download);
2510 return 1; 2824 return 1;
2511
2512 2825
2513 cd1size=sizeof(*cd1); 2826 cd1size=sizeof(*cd1);
2514 cd1offset=zip64_eoc->zip64eofst; 2827 cd1offset=zip64_eoc->zip64eofst;
2515 cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size); 2828 cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size);
2516 if (!cd1) 2829 if (!cd1)
2517 return 0; 2830 return 0;
2518 cd1size=sizeof(*cd1)+binfile_cd_extra(cd1); 2831 cd1size=sizeof(*cd1)+binfile_cd_extra(cd1);
2832 g_free(cd1);
2833 cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size);
2834 if (!cd1)
2835 return 0;
2836 cd1->zipcunc=0;
2837 cdisize=sizeof(*cdi)+strlen("index")+cd1->zipcxtl;
2838 cdioffset=zip64_eoc->zip64eofst+zip64_eoc->zip64ecsz-cdisize;
2839 cdi=(struct zip_cd *)map_binfile_download_range(m, cdioffset, cdisize);
2840 if (!cdi)
2841 {
2519 g_free(cd1); 2842 g_free(cd1);
2520 cd1=(struct zip_cd *)map_binfile_download_range(m, cd1offset, cd1size);
2521 if (!cd1)
2522 return 0; 2843 return 0;
2523 cd1->zipcunc=0;
2524 cdisize=sizeof(*cdi)+strlen("index")+cd1->zipcxtl;
2525 cdioffset=zip64_eoc->zip64eofst+zip64_eoc->zip64ecsz-cdisize;
2526 cdi=(struct zip_cd *)map_binfile_download_range(m, cdioffset, cdisize);
2527 if (!cdi) {
2528 g_free(cd1);
2529 return 0;
2530 } 2844 }
2531 cdi->zipcunc=0; 2845 cdi->zipcunc=0;
2532 cdn=g_malloc0(cd1size*256); 2846 cdn=g_malloc0(cd1size*256);
2533 2847
2534 file_data_write(out, woffset, sizeof(*zip64_eoc), (unsigned char *)zip64_eoc); 2848 file_data_write(out, woffset, sizeof(*zip64_eoc), (unsigned char *)zip64_eoc);
2535 woffset+=sizeof(*zip64_eoc); 2849 woffset+=sizeof(*zip64_eoc);
2536 cdoffset=woffset; 2850 cdoffset=woffset;
2537 2851
2538 file_data_write(out, woffset, cd1size, (unsigned char *)cd1); 2852 file_data_write(out, woffset, cd1size, (unsigned char *)cd1);
2539 woffset+=cd1size; 2853 woffset+=cd1size;
2540 count=(cdioffset-cd1offset)/cd1size-1; 2854 count=(cdioffset-cd1offset)/cd1size-1;
2541 while (count > 0) { 2855 while (count > 0)
2856 {
2542 if (count > 256) 2857 if (count > 256)
2543 chunk=256; 2858 chunk=256;
2544 else 2859 else
2545 chunk=count; 2860 chunk=count;
2546 file_data_write(out, woffset, cd1size*chunk, (unsigned char *)cdn); 2861 file_data_write(out, woffset, cd1size*chunk, (unsigned char *)cdn);
2547 woffset+=cd1size*chunk; 2862 woffset+=cd1size*chunk;
2548 count-=chunk; 2863 count-=chunk;
2549 } 2864 }
2550 g_free(cdn); 2865 g_free(cdn);
2551 g_free(cd1); 2866 g_free(cd1);
2552 file_data_write(out, woffset, cdisize, (unsigned char *)cdi); 2867 file_data_write(out, woffset, cdisize, (unsigned char *)cdi);
2553 woffset+=cdisize; 2868 woffset+=cdisize;
2554 2869
2555} 2870}
2556#endif 2871#endif
2557 2872
2558static int
2559map_binfile_open(struct map_priv *m) 2873static int map_binfile_open(struct map_priv *m)
2560{ 2874{
2561 int *magic; 2875 int *magic;
2562 struct map_rect_priv *mr; 2876 struct map_rect_priv *mr;
2563 struct item *item; 2877 struct item *item;
2564 struct attr attr; 2878 struct attr attr;
2565 struct attr readwrite={attr_readwrite, {(void *)1}}; 2879 struct attr readwrite =
2566 struct attr *attrs[]={&readwrite, NULL}; 2880 { attr_readwrite,
2881 { (void *) 1 } };
2882 struct attr *attrs[] =
2883 { &readwrite, NULL };
2567 2884
2568 dbg(0,"file_create %s\n", m->filename); 2885 // dbg(0, "file_create %s\n", m->filename);
2569 m->fi=file_create(m->filename, m->url?attrs:NULL); 2886 m->fi = file_create(m->filename, m->url ? attrs : NULL);
2570 if (! m->fi && m->url) 2887 if (!m->fi && m->url)
2888 {
2571 return 0; 2889 return 0;
2890 }
2572 if (! m->fi) { 2891 if (!m->fi)
2892 {
2573 dbg(0,"Failed to load '%s'\n", m->filename); 2893 // dbg(0, "Failed to load '%s'\n", m->filename);
2574 return 0; 2894 return 0;
2575 } 2895 }
2576 if (m->check_version) 2896 if (m->check_version)
2897 {
2577 m->version=file_version(m->fi, m->check_version); 2898 m->version = file_version(m->fi, m->check_version);
2899 }
2900
2578 magic=(int *)file_data_read(m->fi, 0, 4); 2901 magic = (int *) file_data_read(m->fi, 0, 4);
2579 if (!magic) { 2902 if (!magic)
2903 {
2580 file_destroy(m->fi); 2904 file_destroy(m->fi);
2581 m->fi=NULL; 2905 m->fi = NULL;
2582 return 0; 2906 return 0;
2583 } 2907 }
2908
2909 //dbg(0,"_zip_lfh_sig=%d\n", zip_lfh_sig);
2910
2911 //dbg(0,"_magic1=%d\n", magic[0]);
2912 //dbg(0,"_magic1=%d\n", magic[1]);
2913 //dbg(0,"_magic1=%d\n", magic[2]);
2914 //dbg(0,"_magic1=%d\n", magic[3]);
2584 *magic = le32_to_cpu(*magic); 2915 *magic = le32_to_cpu(*magic);
2916 //dbg(0,"_magic2=%d\n", magic[0]);
2917 //dbg(0,"_magic2=%d\n", magic[1]);
2918 //dbg(0,"_magic2=%d\n", magic[2]);
2919 //dbg(0,"_magic2=%d\n", magic[3]);
2585 if (*magic == zip_lfh_sig || *magic == zip_split_sig || *magic == zip_cd_sig || *magic == zip64_eoc_sig) { 2920 if (*magic == zip_lfh_sig || *magic == zip_split_sig || *magic == zip_cd_sig || *magic == zip64_eoc_sig)
2921 {
2586 if (!map_binfile_zip_setup(m, m->filename, m->flags & 1)) { 2922 if (!map_binfile_zip_setup(m, m->filename, m->flags & 1))
2923 {
2587 dbg(0,"invalid file format for '%s'\n", m->filename); 2924 dbg(0, "invalid file format for '%s'\n", m->filename);
2588 file_destroy(m->fi); 2925 file_destroy(m->fi);
2589 m->fi=NULL; 2926 m->fi = NULL;
2590 return 0; 2927 return 0;
2591 } 2928 }
2929 }
2592 } else 2930 else
2931 {
2932 //dbg(0,"_want mmap %s\n", m->fi->name);
2593 file_mmap(m->fi); 2933 file_mmap(m->fi);
2934 }
2935
2936 //dbg(0,"_cont\n");
2937
2594 file_data_free(m->fi, (unsigned char *)magic); 2938 file_data_free(m->fi, (unsigned char *) magic);
2595 m->cachedir=g_strdup("/tmp/navit"); 2939 m->cachedir = g_strdup("/tmp/navit");
2596 m->map_version=0; 2940 m->map_version = 0;
2941
2597 mr=map_rect_new_binfile(m, NULL); 2942 mr = map_rect_new_binfile(m, NULL);
2598 if (mr) { 2943 if (mr)
2944 {
2599 while ((item=map_rect_get_item_binfile(mr)) == &busy_item); 2945 while ((item = map_rect_get_item_binfile(mr)) == &busy_item)
2946 {
2947 ;
2948 }
2949
2600 if (item && item->type == type_map_information) { 2950 if (item && item->type == type_map_information)
2951 {
2601 if (binfile_attr_get(item->priv_data, attr_version, &attr)) 2952 if (binfile_attr_get(item->priv_data, attr_version, &attr))
2953 {
2602 m->map_version=attr.u.num; 2954 m->map_version = attr.u.num;
2955 dbg(0, "map_version=%d\n", m->map_version);
2956 }
2603 if (binfile_attr_get(item->priv_data, attr_map_release, &attr)) 2957 if (binfile_attr_get(item->priv_data, attr_map_release, &attr))
2958 {
2604 m->map_release=g_strdup(attr.u.str); 2959 m->map_release = g_strdup(attr.u.str);
2960 dbg(0, "map_release=%s\n", m->map_release);
2961 }
2605 if (m->url && binfile_attr_get(item->priv_data, attr_url, &attr)) { 2962 if (m->url && binfile_attr_get(item->priv_data, attr_url, &attr))
2963 {
2606 dbg(0,"url config %s map %s\n",m->url,attr.u.str); 2964 //dbg(0, "url config %s map %s\n", m->url, attr.u.str);
2607 if (strcmp(m->url, attr.u.str)) 2965 if (strcmp(m->url, attr.u.str))
2966 {
2608 m->update_available=1; 2967 m->update_available = 1;
2968 }
2609 g_free(m->url); 2969 g_free(m->url);
2610 m->url=g_strdup(attr.u.str); 2970 m->url = g_strdup(attr.u.str);
2611 } 2971 }
2612 } 2972 }
2973
2613 map_rect_destroy_binfile(mr); 2974 map_rect_destroy_binfile(mr);
2975
2614 if (m->map_version >= 16) { 2976 if (m->map_version >= 16)
2977 {
2615 dbg(0,"Warning: This map is incompatible with your navit version. Please update navit.\n"); 2978 dbg(0, "Warning: This map is incompatible with your versionof ZANavi. Please update ZANavi.\n");
2616 return 0; 2979 return 0;
2617 } 2980 }
2618 } 2981 }
2619 return 1; 2982 return 1;
2620} 2983}
2621 2984
2622static void
2623map_binfile_close(struct map_priv *m) 2985static void map_binfile_close(struct map_priv *m)
2624{ 2986{
2625 int i; 2987 int i;
2626 file_data_free(m->fi, (unsigned char *)m->index_cd); 2988 file_data_free(m->fi, (unsigned char *) m->index_cd);
2627 file_data_free(m->fi, (unsigned char *)m->eoc); 2989 file_data_free(m->fi, (unsigned char *) m->eoc);
2628 file_data_free(m->fi, (unsigned char *)m->eoc64); 2990 file_data_free(m->fi, (unsigned char *) m->eoc64);
2629 g_free(m->cachedir); 2991 g_free(m->cachedir);
2630 g_free(m->map_release); 2992 g_free(m->map_release);
2631 if (m->fis) { 2993 if (m->fis)
2994 {
2632 for (i = 0 ; i < m->eoc->zipedsk ; i++) { 2995 for (i = 0; i < m->eoc->zipedsk; i++)
2996 {
2633 file_destroy(m->fis[i]); 2997 file_destroy(m->fis[i]);
2634 } 2998 }
2999 }
2635 } else 3000 else
2636 file_destroy(m->fi); 3001 file_destroy(m->fi);
2637} 3002}
2638 3003
2639static void
2640map_binfile_destroy(struct map_priv *m) 3004static void map_binfile_destroy(struct map_priv *m)
2641{ 3005{
2642 g_free(m->filename); 3006 g_free(m->filename);
2643 g_free(m->url); 3007 g_free(m->url);
2644 g_free(m->progress); 3008 g_free(m->progress);
2645 g_free(m); 3009 g_free(m);
2646} 3010}
2647 3011
2648
2649static void
2650binfile_check_version(struct map_priv *m) 3012static void binfile_check_version(struct map_priv *m)
2651{ 3013{
2652 int version=-1; 3014 int version = -1;
2653 if (!m->check_version) 3015 if (!m->check_version)
2654 return; 3016 return;
2655 if (m->fi) 3017 if (m->fi)
2656 version=file_version(m->fi, m->check_version); 3018 version = file_version(m->fi, m->check_version);
2657 if (version != m->version) { 3019 if (version != m->version)
3020 {
2658 if (m->fi) 3021 if (m->fi)
2659 map_binfile_close(m); 3022 map_binfile_close(m);
2660 map_binfile_open(m); 3023 map_binfile_open(m);
2661 } 3024 }
2662} 3025}
2663 3026
2664
2665static struct map_priv * 3027static struct map_priv *
2666map_new_binfile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl) 3028map_new_binfile(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl)
2667{ 3029{
2668 struct map_priv *m; 3030 struct map_priv *m;
2669 struct attr *data=attr_search(attrs, NULL, attr_data); 3031 struct attr *data = attr_search(attrs, NULL, attr_data);
2670 struct attr *check_version,*map_pass,*flags,*url,*download_enabled; 3032 struct attr *check_version, *map_pass, *flags, *url, *download_enabled;
2671 struct file_wordexp *wexp; 3033 struct file_wordexp *wexp;
2672 char **wexp_data; 3034 char **wexp_data;
2673 if (! data) 3035 if (!data)
2674 return NULL; 3036 return NULL;
2675 3037
2676 wexp=file_wordexp_new(data->u.str); 3038 // wexp = file_wordexp_new(data->u.str);
2677 wexp_data=file_wordexp_get_array(wexp); 3039 // wexp_data = file_wordexp_get_array(wexp);
2678 dbg(0,"map_new_binfile %s\n", data->u.str); 3040 // dbg(0, "map_new_binfile %s\n", data->u.str);
2679 *meth=map_methods_binfile; 3041 *meth = map_methods_binfile;
2680 3042
2681 m=g_new0(struct map_priv, 1); 3043 m=g_new0(struct map_priv, 1);
2682 m->cbl=cbl; 3044 m->cbl = cbl;
2683 m->id=++map_id; 3045 m->id = ++map_id;
2684 m->filename=g_strdup(wexp_data[0]); 3046 m->filename = g_strdup(data->u.str);
2685 file_wordexp_destroy(wexp); 3047 // file_wordexp_destroy(wexp);
2686 check_version=attr_search(attrs, NULL, attr_check_version); 3048 check_version = attr_search(attrs, NULL, attr_check_version);
2687 if (check_version) 3049 if (check_version)
2688 m->check_version=check_version->u.num; 3050 m->check_version = check_version->u.num;
2689 map_pass=attr_search(attrs, NULL, attr_map_pass); 3051 map_pass = attr_search(attrs, NULL, attr_map_pass);
2690 if (map_pass) 3052 if (map_pass)
2691 m->passwd=g_strdup(map_pass->u.str); 3053 m->passwd = g_strdup(map_pass->u.str);
2692 flags=attr_search(attrs, NULL, attr_flags); 3054 flags = attr_search(attrs, NULL, attr_flags);
2693 if (flags) 3055 if (flags)
2694 m->flags=flags->u.num; 3056 m->flags = flags->u.num;
2695 url=attr_search(attrs, NULL, attr_url); 3057 url = attr_search(attrs, NULL, attr_url);
2696 if (url) 3058 if (url)
2697 m->url=g_strdup(url->u.str); 3059 m->url = g_strdup(url->u.str);
2698 download_enabled = attr_search(attrs, NULL, attr_update); 3060 download_enabled = attr_search(attrs, NULL, attr_update);
2699 if (download_enabled) 3061 if (download_enabled)
2700 m->download_enabled=download_enabled->u.num; 3062 m->download_enabled = download_enabled->u.num;
2701 3063
2702 if (!map_binfile_open(m) && !m->check_version && !m->url) { 3064 if (!map_binfile_open(m) && !m->check_version && !m->url)
3065 {
2703 map_binfile_destroy(m); 3066 map_binfile_destroy(m);
2704 m=NULL; 3067 m = NULL;
2705 } else { 3068 }
3069 else
3070 {
2706 load_changes(m); 3071 load_changes(m);
2707 } 3072 }
2708 return m; 3073 return m;
2709} 3074}
2710 3075
2711void
2712plugin_init(void) 3076void plugin_init(void)
2713{ 3077{
2714 dbg(1,"binfile: plugin_init\n"); 3078 // dbg(1, "binfile: plugin_init\n");
2715 if (sizeof(struct zip_cd) != 46) { 3079 if (sizeof(struct zip_cd) != 46)
3080 {
2716 dbg(0,"error: sizeof(struct zip_cd)=%d\n",sizeof(struct zip_cd)); 3081 // dbg(0, "error: sizeof(struct zip_cd)=%d\n", sizeof(struct zip_cd));
2717 } 3082 }
2718 plugin_register_map_type("binfile", map_new_binfile); 3083 plugin_register_map_type("binfile", map_new_binfile);
2719} 3084}
2720 3085

Legend:
Removed from v.15  
changed lines
  Added in v.31

   
Visit the ZANavi Wiki