Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/osmparser.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 308 - (hide annotations) (download) (as text)
Fri Nov 27 11:03:41 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 20814 byte(s)
Add in "multilane" as a new highway property.

1 amb 2 /***************************************
2 amb 308 $Header: /home/amb/CVS/routino/src/osmparser.c,v 1.61 2009-11-27 11:03:41 amb Exp $
3 amb 2
4     OSM XML file parser (either JOSM or planet)
5 amb 151
6     Part of the Routino routing software.
7 amb 2 ******************/ /******************
8 amb 151 This file Copyright 2008,2009 Andrew M. Bishop
9 amb 2
10 amb 151 This program is free software: you can redistribute it and/or modify
11     it under the terms of the GNU Affero General Public License as published by
12     the Free Software Foundation, either version 3 of the License, or
13     (at your option) any later version.
14    
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU Affero General Public License for more details.
19    
20     You should have received a copy of the GNU Affero General Public License
21     along with this program. If not, see <http://www.gnu.org/licenses/>.
22 amb 2 ***************************************/
23    
24    
25     #include <stdio.h>
26     #include <stdlib.h>
27     #include <string.h>
28     #include <ctype.h>
29    
30 amb 199 #include "typesx.h"
31     #include "functionsx.h"
32 amb 109 #include "nodesx.h"
33     #include "segmentsx.h"
34     #include "waysx.h"
35 amb 228 #include "ways.h"
36 amb 2
37 amb 26
38 amb 228 /*+ The length of the buffer and the size increment for reading lines from the file. +*/
39 amb 244 #define BUFFSIZE 256
40 amb 2
41 amb 298 #define ISTRUE(xx) (!strcmp(xx,"true") || !strcmp(xx,"yes") || !strcmp(xx,"1"))
42 amb 297
43 amb 298 #define ISALLOWED(xx) (!strcmp(xx,"true") || !strcmp(xx,"yes") || !strcmp(xx,"1") || \
44     !strcmp(xx,"permissive") || !strcmp(xx,"designated") || !strcmp(xx,"destination"))
45    
46 amb 228 /* Local functions */
47    
48 amb 2 static char *fgets_realloc(char *buffer,FILE *file);
49    
50    
51     /*++++++++++++++++++++++++++++++++++++++
52     Parse an OSM XML file (from JOSM or planet download).
53    
54     int ParseXML Returns 0 if OK or something else in case of an error.
55    
56     FILE *file The file to read from.
57 amb 26
58 amb 97 NodesX *OSMNodes The array of nodes to fill in.
59 amb 26
60 amb 97 SegmentsX *OSMSegments The array of segments to fill in.
61 amb 26
62 amb 97 WaysX *OSMWays The arrray of ways to fill in.
63 amb 75
64 amb 228 Profile *profile A profile of the allowed transport types and included/excluded highway types.
65 amb 2 ++++++++++++++++++++++++++++++++++++++*/
66    
67 amb 97 int ParseXML(FILE *file,NodesX *OSMNodes,SegmentsX *OSMSegments,WaysX *OSMWays,Profile *profile)
68 amb 2 {
69     char *line=NULL;
70     long nlines=0;
71     long nnodes=0,nways=0,nrelations=0;
72     int isnode=0,isway=0,isrelation=0;
73 amb 203 way_t way_id=0;
74 amb 298 wayallow_t way_allow_no=0,way_allow_yes=0;
75 amb 6 int way_oneway=0,way_roundabout=0;
76 amb 308 int way_paved=0,way_multilane=0;
77 amb 51 speed_t way_maxspeed=0;
78 amb 136 weight_t way_maxweight=0;
79     height_t way_maxheight=0;
80     width_t way_maxwidth=0;
81     length_t way_maxlength=0;
82 amb 51 char *way_highway=NULL,*way_name=NULL,*way_ref=NULL;
83 amb 2 node_t *way_nodes=NULL;
84     int way_nnodes=0,way_nalloc=0;
85    
86 amb 227 printf("\rReading: Lines=0 Nodes=0 Ways=0 Relations=0");
87     fflush(stdout);
88    
89 amb 2 /* Parse the file */
90    
91     while((line=fgets_realloc(line,file)))
92     {
93     char *l=line,*m;
94    
95     nlines++;
96    
97     while(isspace(*l))
98     l++;
99    
100     if(!strncmp(l,"<node",5)) /* The start of a node */
101     {
102     node_t id;
103 amb 219 double latitude,longitude;
104 amb 2
105     nnodes++;
106    
107     isnode=1; isway=0; isrelation=0;
108    
109     m=strstr(l,"id="); m+=4; if(*m=='"' || *m=='\'') m++; id=atoll(m);
110 amb 198 m=strstr(l,"lat="); m+=5; if(*m=='"' || *m=='\'') m++; latitude=degrees_to_radians(atof(m));
111     m=strstr(l,"lon="); m+=4; if(*m=='"' || *m=='\'') m++; longitude=degrees_to_radians(atof(m));
112 amb 2
113 amb 26 AppendNode(OSMNodes,id,latitude,longitude);
114 amb 159
115     if(strstr(l,"/>")) /* The end of a node */
116     {
117     isnode=0; isway=0; isrelation=0;
118     }
119 amb 2 }
120     else if(!strncmp(l,"</node",6)) /* The end of a node */
121     {
122     isnode=0; isway=0; isrelation=0;
123     }
124     else if(!strncmp(l,"<way",4)) /* The start of a way */
125     {
126     nways++;
127    
128     isnode=0; isway=1; isrelation=0;
129    
130 amb 203 m=strstr(l,"id="); m+=4; if(*m=='"' || *m=='\'') m++; way_id=atoll(m);
131    
132 amb 298 way_allow_no=0; way_allow_yes=0;
133 amb 51 way_oneway=0; way_roundabout=0;
134 amb 308 way_paved=0; way_multilane=0;
135 amb 136 way_maxspeed=0; way_maxweight=0; way_maxheight=0; way_maxwidth=0;
136     way_maxlength=0;
137 amb 51 way_highway=NULL; way_name=NULL; way_ref=NULL;
138 amb 2 way_nnodes=0;
139     }
140     else if(!strncmp(l,"</way",5)) /* The end of a way */
141     {
142     isnode=0; isway=0; isrelation=0;
143    
144 amb 30 if(way_highway)
145 amb 2 {
146 amb 298 Way way={0};
147 amb 2
148 amb 298 way.type=HighwayType(way_highway);
149 amb 6
150 amb 298 if(profile->highway[way.type])
151 amb 2 {
152 amb 298 switch(way.type)
153 amb 73 {
154 amb 298 case Way_Motorway:
155     way.type|=Way_OneWay;
156     way.allow=Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
157 amb 308 way.props=Properties_Paved|Properties_Multilane;
158 amb 298 break;
159     case Way_Trunk:
160     way.allow=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
161     way.props=Properties_Paved;
162     break;
163     case Way_Primary:
164     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
165     way.props=Properties_Paved;
166     break;
167     case Way_Secondary:
168     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
169     way.props=Properties_Paved;
170     break;
171     case Way_Tertiary:
172     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
173     way.props=Properties_Paved;
174     break;
175     case Way_Unclassified:
176     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
177     way.props=Properties_Paved;
178     break;
179     case Way_Residential:
180     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
181     way.props=Properties_Paved;
182     break;
183     case Way_Service:
184     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_PSV|Allow_Goods|Allow_HGV;
185     way.props=Properties_Paved;
186     break;
187     case Way_Track:
188     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle;
189     way.props=0;
190     break;
191     case Way_Cycleway:
192     way.allow=Allow_Foot|Allow_Bicycle;
193     way.props=Properties_Paved;
194     break;
195     case Way_Path:
196     if(!strcmp(way_highway,"bridleway"))
197     way.allow=Allow_Foot|Allow_Horse|Allow_Bicycle; /* Special case for "bridleway". */
198     else
199     way.allow=Allow_Foot; /* Only allow bicycle and horse if so indicated. */
200     way.props=0;
201     break;
202 amb 306 case Way_Steps:
203     way.allow=Allow_Foot;
204     way.props=0;
205     break;
206 amb 298 default:
207     way.allow=0;
208     way.props=0;
209     break;
210 amb 73 }
211 amb 2
212 amb 298 if(way_allow_no) /* Remove the ones explicitly denied (e.g. private) */
213     way.allow&=~way_allow_no;
214 amb 2
215 amb 298 if(way_allow_yes) /* Add the ones explicitly allowed (e.g. footpath along private) */
216     way.allow|=way_allow_yes;
217 amb 30
218 amb 307 if(way.allow & profile->allow)
219 amb 298 {
220     char *refname;
221     int i;
222 amb 30
223 amb 298 if(way_oneway)
224     way.type|=Way_OneWay;
225 amb 30
226 amb 298 if(way_roundabout)
227     way.type|=Way_Roundabout;
228 amb 30
229 amb 307 if(profile->props_yes[Property_Paved])
230     {
231     if(way_paved>0)
232     way.props|=Properties_Paved;
233     else if(way_paved<0)
234     way.props&=~Properties_Paved;
235     }
236 amb 262
237 amb 308 if(profile->props_yes[Property_Multilane])
238     {
239     if(way_multilane>1)
240     way.props|=Properties_Multilane;
241     else if(way_paved==1)
242     way.props&=~Properties_Multilane;
243     }
244    
245 amb 298 if(way_ref && way_name)
246 amb 277 {
247 amb 298 refname=(char*)malloc(strlen(way_ref)+strlen(way_name)+4);
248     sprintf(refname,"%s (%s)",way_name,way_ref);
249 amb 277 }
250 amb 298 else if(way_ref && !way_name && way_roundabout)
251 amb 277 {
252 amb 298 refname=(char*)malloc(strlen(way_ref)+14);
253     sprintf(refname,"%s (roundabout)",way_ref);
254 amb 277 }
255 amb 298 else if(way_ref && !way_name)
256     refname=way_ref;
257     else if(!way_ref && way_name)
258     refname=way_name;
259     else if(way_roundabout)
260 amb 277 {
261 amb 298 refname=(char*)malloc(strlen(way_highway)+14);
262     sprintf(refname,"%s (roundabout)",way_highway);
263 amb 277 }
264 amb 298 else /* if(!way_ref && !way_name && !way_roundabout) */
265     refname=way_highway;
266    
267     way.speed =way_maxspeed;
268     way.weight=way_maxweight;
269     way.height=way_maxheight;
270     way.width =way_maxwidth;
271     way.length=way_maxlength;
272    
273     AppendWay(OSMWays,way_id,&way,refname);
274    
275     if(refname!=way_ref && refname!=way_name && refname!=way_highway)
276     free(refname);
277    
278     for(i=1;i<way_nnodes;i++)
279     {
280     node_t from=way_nodes[i-1];
281     node_t to =way_nodes[i];
282    
283     if(way_oneway>0)
284     {
285     AppendSegment(OSMSegments,way_id,from,to,ONEWAY_1TO2);
286     AppendSegment(OSMSegments,way_id,to,from,ONEWAY_2TO1);
287     }
288     else if(way_oneway<0)
289     {
290     AppendSegment(OSMSegments,way_id,from,to,ONEWAY_2TO1);
291     AppendSegment(OSMSegments,way_id,to,from,ONEWAY_1TO2);
292     }
293     else
294     {
295     AppendSegment(OSMSegments,way_id,from,to,0);
296     AppendSegment(OSMSegments,way_id,to,from,0);
297     }
298     }
299 amb 87 }
300 amb 73 }
301 amb 2 }
302    
303 amb 51 if(way_highway) free(way_highway);
304     if(way_name) free(way_name);
305     if(way_ref) free(way_ref);
306 amb 2 }
307     else if(!strncmp(l,"<relation",9)) /* The start of a relation */
308     {
309     nrelations++;
310    
311     isnode=0; isway=0; isrelation=1;
312     }
313     else if(!strncmp(l,"</relation",10)) /* The end of a relation */
314     {
315     isnode=0; isway=0; isrelation=0;
316     }
317     else if(isnode) /* The middle of a node */
318     {
319     }
320     else if(isway) /* The middle of a way */
321     {
322     node_t id;
323    
324     if(!strncmp(l,"<nd",3)) /* The start of a node specifier */
325     {
326     m=strstr(l,"ref="); m+=4; if(*m=='"' || *m=='\'') m++; id=atoll(m);
327    
328 amb 244 if(way_nnodes==way_nalloc)
329     way_nodes=(node_t*)realloc((void*)way_nodes,(way_nalloc+=256)*sizeof(node_t));
330 amb 2
331     way_nodes[way_nnodes++]=id;
332     }
333    
334     if(!strncmp(l,"<tag",4)) /* The start of a tag specifier */
335     {
336     char delimiter,*k="",*v="";
337    
338     m=strstr(l,"k="); m+=2; delimiter=*m; m++; k=m;
339     while(*m!=delimiter) m++; *m=0; l=m+1;
340    
341     m=strstr(l,"v="); m+=2; delimiter=*m; m++; v=m;
342     while(*m!=delimiter) m++; *m=0;
343    
344 amb 51 switch(*k)
345     {
346     case 'a':
347     if(!strcmp(k,"access"))
348 amb 136 {
349 amb 297 if(ISALLOWED(v))
350 amb 136 ;
351     else
352 amb 302 way_allow_no=Allow_ALL;
353 amb 136 }
354 amb 51 break;
355 amb 2
356 amb 51 case 'b':
357     if(!strcmp(k,"bicycle"))
358     {
359 amb 297 if(ISALLOWED(v))
360 amb 51 way_allow_yes|=Allow_Bicycle;
361     else
362 amb 297 way_allow_no |=Allow_Bicycle;
363 amb 51 }
364     break;
365 amb 2
366 amb 297 case 'd':
367     if(!strcmp(k,"designation"))
368     {
369     if(!strcmp(v,"bridleway"))
370     way_allow_yes|=Allow_Foot|Allow_Horse|Allow_Bicycle;
371     else if(!strcmp(v,"byway"))
372     way_allow_yes|=Allow_Foot|Allow_Horse|Allow_Bicycle;
373     else if(!strcmp(v,"footpath"))
374     way_allow_yes|=Allow_Foot;
375     }
376     break;
377    
378 amb 51 case 'f':
379     if(!strcmp(k,"foot"))
380     {
381 amb 297 if(ISALLOWED(v))
382 amb 51 way_allow_yes|=Allow_Foot;
383     else
384 amb 297 way_allow_no |=Allow_Foot;
385 amb 51 }
386     break;
387 amb 2
388 amb 51 case 'g':
389     if(!strcmp(k,"goods"))
390     {
391 amb 297 if(ISALLOWED(v))
392 amb 51 way_allow_yes|=Allow_Goods;
393     else
394 amb 297 way_allow_no |=Allow_Goods;
395 amb 51 }
396     break;
397 amb 2
398 amb 51 case 'h':
399     if(!strcmp(k,"highway"))
400 amb 298 way_highway=strcpy((char*)malloc(strlen(v)+1),v);
401 amb 2
402 amb 51 if(!strcmp(k,"horse"))
403     {
404 amb 297 if(ISALLOWED(v))
405 amb 51 way_allow_yes|=Allow_Horse;
406     else
407 amb 297 way_allow_no |=Allow_Horse;
408 amb 51 }
409 amb 298
410 amb 51 if(!strcmp(k,"hgv"))
411     {
412 amb 297 if(ISALLOWED(v))
413 amb 51 way_allow_yes|=Allow_HGV;
414     else
415 amb 297 way_allow_no |=Allow_HGV;
416 amb 51 }
417     break;
418 amb 8
419 amb 51 case 'j':
420     if(!strcmp(k,"junction"))
421     if(!strcmp(v,"roundabout"))
422     {way_oneway=1; way_roundabout=1;}
423     break;
424    
425 amb 308 case 'l':
426     if(!strcmp(k,"lanes"))
427     way_multilane=atoi(v);
428    
429 amb 51 case 'm':
430     if(!strcmp(k,"maxspeed"))
431     {
432     if(strstr(v,"mph"))
433 amb 183 way_maxspeed=kph_to_speed(1.609*atof(v));
434 amb 136 else
435     way_maxspeed=kph_to_speed(atof(v));
436 amb 51 }
437 amb 298
438 amb 183 if(!strcmp(k,"maxspeed:mph"))
439     way_maxspeed=kph_to_speed(1.609*atof(v));
440 amb 298
441 amb 136 if(!strcmp(k,"maxweight"))
442     {
443     if(strstr(v,"kg"))
444     way_maxweight=tonnes_to_weight(atof(v)/1000);
445     else
446     way_maxweight=tonnes_to_weight(atof(v));
447     }
448 amb 298
449 amb 136 if(!strcmp(k,"maxheight"))
450     {
451 amb 183 if(strchr(v,'\''))
452     {
453     int feet,inches;
454    
455     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
456 amb 219 way_maxheight=metres_to_height((feet+(double)inches/12.0)*0.254);
457 amb 183 else if(sscanf(v,"%d'",&feet)==1)
458 amb 219 way_maxheight=metres_to_height((feet+(double)inches/12.0)*0.254);
459 amb 183 }
460     else if(strstr(v,"ft") || strstr(v,"feet"))
461 amb 136 way_maxheight=metres_to_height(atof(v)*0.254);
462     else
463     way_maxheight=metres_to_height(atof(v));
464     }
465 amb 298
466 amb 136 if(!strcmp(k,"maxwidth"))
467     {
468 amb 183 if(strchr(v,'\''))
469     {
470     int feet,inches;
471    
472     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
473 amb 219 way_maxwidth=metres_to_height((feet+(double)inches/12.0)*0.254);
474 amb 183 else if(sscanf(v,"%d'",&feet)==1)
475 amb 219 way_maxwidth=metres_to_height((feet+(double)inches/12.0)*0.254);
476 amb 183 }
477     else if(strstr(v,"ft") || strstr(v,"feet"))
478 amb 136 way_maxwidth=metres_to_width(atof(v)*0.254);
479     else
480     way_maxwidth=metres_to_width(atof(v));
481     }
482 amb 298
483 amb 136 if(!strcmp(k,"maxlength"))
484     {
485 amb 183 if(strchr(v,'\''))
486     {
487     int feet,inches;
488    
489     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
490 amb 219 way_maxlength=metres_to_height((feet+(double)inches/12.0)*0.254);
491 amb 183 else if(sscanf(v,"%d'",&feet)==1)
492 amb 219 way_maxlength=metres_to_height((feet+(double)inches/12.0)*0.254);
493 amb 183 }
494     else if(strstr(v,"ft") || strstr(v,"feet"))
495 amb 136 way_maxlength=metres_to_length(atof(v)*0.254);
496     else
497     way_maxlength=metres_to_length(atof(v));
498     }
499 amb 298
500 amb 296 if(!strcmp(k,"moped"))
501     {
502 amb 297 if(ISALLOWED(v))
503 amb 296 way_allow_yes|=Allow_Moped;
504     else
505 amb 297 way_allow_no |=Allow_Moped;
506 amb 296 }
507 amb 298
508 amb 51 if(!strcmp(k,"motorbike"))
509     {
510 amb 297 if(ISALLOWED(v))
511 amb 51 way_allow_yes|=Allow_Motorbike;
512     else
513 amb 297 way_allow_no |=Allow_Motorbike;
514 amb 51 }
515 amb 298
516 amb 51 if(!strcmp(k,"motorcar"))
517     {
518 amb 297 if(ISALLOWED(v))
519 amb 51 way_allow_yes|=Allow_Motorcar;
520     else
521 amb 297 way_allow_no |=Allow_Motorcar;
522 amb 51 }
523 amb 298
524 amb 196 if(!strcmp(k,"motor_vehicle"))
525     {
526 amb 297 if(ISALLOWED(v))
527 amb 296 way_allow_yes|=Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
528 amb 196 else
529 amb 297 way_allow_no |=Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
530 amb 196 }
531 amb 51 break;
532    
533     case 'n':
534     if(!strcmp(k,"name"))
535     way_name=strcpy((char*)malloc(strlen(v)+1),v);
536     break;
537    
538     case 'o':
539     if(!strcmp(k,"oneway"))
540 amb 117 {
541 amb 298 if(ISTRUE(v))
542 amb 51 way_oneway=1;
543 amb 117 else if(!strcmp(v,"-1"))
544     way_oneway=-1;
545     }
546 amb 51 break;
547    
548     case 'p':
549 amb 299 if(!strcmp(k,"paved"))
550     {
551     if(ISTRUE(v))
552     way_paved=1;
553     else
554     way_paved=-1;
555     }
556    
557 amb 51 if(!strcmp(k,"psv"))
558     {
559 amb 297 if(ISALLOWED(v))
560 amb 51 way_allow_yes|=Allow_PSV;
561     else
562 amb 297 way_allow_no |=Allow_PSV;
563 amb 51 }
564     break;
565    
566     case 'r':
567     if(!strcmp(k,"ref"))
568     way_ref=strcpy((char*)malloc(strlen(v)+1),v);
569     break;
570    
571 amb 298 case 's':
572     if(!strcmp(k,"surface"))
573     {
574     if(!strcmp(v,"paved") || !strcmp(v,"asphalt") || !strcmp(v,"concrete"))
575     way_paved=1;
576     else
577     way_paved=-1;
578     }
579     break;
580    
581 amb 196 case 'v':
582     if(!strcmp(k,"vehicle"))
583     {
584 amb 297 if(ISALLOWED(v))
585 amb 296 way_allow_yes|=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
586 amb 196 else
587 amb 297 way_allow_no |=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
588 amb 196 }
589     break;
590    
591 amb 51 default:
592     ;
593 amb 2 }
594     }
595     }
596     else if(isrelation) /* The middle of a relation */
597     {
598     }
599    
600     if(!(nlines%10000))
601     {
602     printf("\rReading: Lines=%ld Nodes=%ld Ways=%ld Relations=%ld",nlines,nnodes,nways,nrelations);
603     fflush(stdout);
604     }
605     }
606    
607 amb 35 printf("\rRead: Lines=%ld Nodes=%ld Ways=%ld Relations=%ld \n",nlines,nnodes,nways,nrelations);
608 amb 2 fflush(stdout);
609    
610 amb 97 if(line)
611     free(line);
612    
613 amb 2 if(way_nalloc)
614     free(way_nodes);
615    
616     return(0);
617     }
618    
619    
620     /*++++++++++++++++++++++++++++++++++++++
621     Call fgets and realloc the buffer as needed to get a whole line.
622    
623     char *fgets_realloc Returns the modified buffer (NULL at the end of the file).
624    
625     char *buffer The current buffer.
626    
627     FILE *file The file to read from.
628     ++++++++++++++++++++++++++++++++++++++*/
629    
630     static char *fgets_realloc(char *buffer,FILE *file)
631     {
632     int n=0;
633     char *buf;
634    
635     if(!buffer)
636     buffer=(char*)malloc(BUFFSIZE+1);
637    
638     while((buf=fgets(&buffer[n],BUFFSIZE,file)))
639     {
640     int s=strlen(buf);
641     n+=s;
642    
643     if(buffer[n-1]=='\n')
644     break;
645     else
646     buffer=(char*)realloc(buffer,n+BUFFSIZE+1);
647     }
648    
649     if(!buf)
650     {free(buffer);buffer=NULL;}
651    
652     return(buffer);
653     }

Properties

Name Value
cvs:description OSM XML file parser.