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 307 - (hide annotations) (download) (as text)
Wed Nov 25 15:00:37 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 20371 byte(s)
Store the selected options when parsing (planetsplitter) and display them in the
statistics (filedumper) and check them when routing (router).

1 amb 2 /***************************************
2 amb 307 $Header: /home/amb/CVS/routino/src/osmparser.c,v 1.60 2009-11-25 15:00:37 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 298 int way_paved=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 298 way_paved=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     way.props=Properties_Paved;
158     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 298 if(way_ref && way_name)
238 amb 277 {
239 amb 298 refname=(char*)malloc(strlen(way_ref)+strlen(way_name)+4);
240     sprintf(refname,"%s (%s)",way_name,way_ref);
241 amb 277 }
242 amb 298 else if(way_ref && !way_name && way_roundabout)
243 amb 277 {
244 amb 298 refname=(char*)malloc(strlen(way_ref)+14);
245     sprintf(refname,"%s (roundabout)",way_ref);
246 amb 277 }
247 amb 298 else if(way_ref && !way_name)
248     refname=way_ref;
249     else if(!way_ref && way_name)
250     refname=way_name;
251     else if(way_roundabout)
252 amb 277 {
253 amb 298 refname=(char*)malloc(strlen(way_highway)+14);
254     sprintf(refname,"%s (roundabout)",way_highway);
255 amb 277 }
256 amb 298 else /* if(!way_ref && !way_name && !way_roundabout) */
257     refname=way_highway;
258    
259     way.speed =way_maxspeed;
260     way.weight=way_maxweight;
261     way.height=way_maxheight;
262     way.width =way_maxwidth;
263     way.length=way_maxlength;
264    
265     AppendWay(OSMWays,way_id,&way,refname);
266    
267     if(refname!=way_ref && refname!=way_name && refname!=way_highway)
268     free(refname);
269    
270     for(i=1;i<way_nnodes;i++)
271     {
272     node_t from=way_nodes[i-1];
273     node_t to =way_nodes[i];
274    
275     if(way_oneway>0)
276     {
277     AppendSegment(OSMSegments,way_id,from,to,ONEWAY_1TO2);
278     AppendSegment(OSMSegments,way_id,to,from,ONEWAY_2TO1);
279     }
280     else if(way_oneway<0)
281     {
282     AppendSegment(OSMSegments,way_id,from,to,ONEWAY_2TO1);
283     AppendSegment(OSMSegments,way_id,to,from,ONEWAY_1TO2);
284     }
285     else
286     {
287     AppendSegment(OSMSegments,way_id,from,to,0);
288     AppendSegment(OSMSegments,way_id,to,from,0);
289     }
290     }
291 amb 87 }
292 amb 73 }
293 amb 2 }
294    
295 amb 51 if(way_highway) free(way_highway);
296     if(way_name) free(way_name);
297     if(way_ref) free(way_ref);
298 amb 2 }
299     else if(!strncmp(l,"<relation",9)) /* The start of a relation */
300     {
301     nrelations++;
302    
303     isnode=0; isway=0; isrelation=1;
304     }
305     else if(!strncmp(l,"</relation",10)) /* The end of a relation */
306     {
307     isnode=0; isway=0; isrelation=0;
308     }
309     else if(isnode) /* The middle of a node */
310     {
311     }
312     else if(isway) /* The middle of a way */
313     {
314     node_t id;
315    
316     if(!strncmp(l,"<nd",3)) /* The start of a node specifier */
317     {
318     m=strstr(l,"ref="); m+=4; if(*m=='"' || *m=='\'') m++; id=atoll(m);
319    
320 amb 244 if(way_nnodes==way_nalloc)
321     way_nodes=(node_t*)realloc((void*)way_nodes,(way_nalloc+=256)*sizeof(node_t));
322 amb 2
323     way_nodes[way_nnodes++]=id;
324     }
325    
326     if(!strncmp(l,"<tag",4)) /* The start of a tag specifier */
327     {
328     char delimiter,*k="",*v="";
329    
330     m=strstr(l,"k="); m+=2; delimiter=*m; m++; k=m;
331     while(*m!=delimiter) m++; *m=0; l=m+1;
332    
333     m=strstr(l,"v="); m+=2; delimiter=*m; m++; v=m;
334     while(*m!=delimiter) m++; *m=0;
335    
336 amb 51 switch(*k)
337     {
338     case 'a':
339     if(!strcmp(k,"access"))
340 amb 136 {
341 amb 297 if(ISALLOWED(v))
342 amb 136 ;
343     else
344 amb 302 way_allow_no=Allow_ALL;
345 amb 136 }
346 amb 51 break;
347 amb 2
348 amb 51 case 'b':
349     if(!strcmp(k,"bicycle"))
350     {
351 amb 297 if(ISALLOWED(v))
352 amb 51 way_allow_yes|=Allow_Bicycle;
353     else
354 amb 297 way_allow_no |=Allow_Bicycle;
355 amb 51 }
356     break;
357 amb 2
358 amb 297 case 'd':
359     if(!strcmp(k,"designation"))
360     {
361     if(!strcmp(v,"bridleway"))
362     way_allow_yes|=Allow_Foot|Allow_Horse|Allow_Bicycle;
363     else if(!strcmp(v,"byway"))
364     way_allow_yes|=Allow_Foot|Allow_Horse|Allow_Bicycle;
365     else if(!strcmp(v,"footpath"))
366     way_allow_yes|=Allow_Foot;
367     }
368     break;
369    
370 amb 51 case 'f':
371     if(!strcmp(k,"foot"))
372     {
373 amb 297 if(ISALLOWED(v))
374 amb 51 way_allow_yes|=Allow_Foot;
375     else
376 amb 297 way_allow_no |=Allow_Foot;
377 amb 51 }
378     break;
379 amb 2
380 amb 51 case 'g':
381     if(!strcmp(k,"goods"))
382     {
383 amb 297 if(ISALLOWED(v))
384 amb 51 way_allow_yes|=Allow_Goods;
385     else
386 amb 297 way_allow_no |=Allow_Goods;
387 amb 51 }
388     break;
389 amb 2
390 amb 51 case 'h':
391     if(!strcmp(k,"highway"))
392 amb 298 way_highway=strcpy((char*)malloc(strlen(v)+1),v);
393 amb 2
394 amb 51 if(!strcmp(k,"horse"))
395     {
396 amb 297 if(ISALLOWED(v))
397 amb 51 way_allow_yes|=Allow_Horse;
398     else
399 amb 297 way_allow_no |=Allow_Horse;
400 amb 51 }
401 amb 298
402 amb 51 if(!strcmp(k,"hgv"))
403     {
404 amb 297 if(ISALLOWED(v))
405 amb 51 way_allow_yes|=Allow_HGV;
406     else
407 amb 297 way_allow_no |=Allow_HGV;
408 amb 51 }
409     break;
410 amb 8
411 amb 51 case 'j':
412     if(!strcmp(k,"junction"))
413     if(!strcmp(v,"roundabout"))
414     {way_oneway=1; way_roundabout=1;}
415     break;
416    
417     case 'm':
418     if(!strcmp(k,"maxspeed"))
419     {
420     if(strstr(v,"mph"))
421 amb 183 way_maxspeed=kph_to_speed(1.609*atof(v));
422 amb 136 else
423     way_maxspeed=kph_to_speed(atof(v));
424 amb 51 }
425 amb 298
426 amb 183 if(!strcmp(k,"maxspeed:mph"))
427     way_maxspeed=kph_to_speed(1.609*atof(v));
428 amb 298
429 amb 136 if(!strcmp(k,"maxweight"))
430     {
431     if(strstr(v,"kg"))
432     way_maxweight=tonnes_to_weight(atof(v)/1000);
433     else
434     way_maxweight=tonnes_to_weight(atof(v));
435     }
436 amb 298
437 amb 136 if(!strcmp(k,"maxheight"))
438     {
439 amb 183 if(strchr(v,'\''))
440     {
441     int feet,inches;
442    
443     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
444 amb 219 way_maxheight=metres_to_height((feet+(double)inches/12.0)*0.254);
445 amb 183 else if(sscanf(v,"%d'",&feet)==1)
446 amb 219 way_maxheight=metres_to_height((feet+(double)inches/12.0)*0.254);
447 amb 183 }
448     else if(strstr(v,"ft") || strstr(v,"feet"))
449 amb 136 way_maxheight=metres_to_height(atof(v)*0.254);
450     else
451     way_maxheight=metres_to_height(atof(v));
452     }
453 amb 298
454 amb 136 if(!strcmp(k,"maxwidth"))
455     {
456 amb 183 if(strchr(v,'\''))
457     {
458     int feet,inches;
459    
460     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
461 amb 219 way_maxwidth=metres_to_height((feet+(double)inches/12.0)*0.254);
462 amb 183 else if(sscanf(v,"%d'",&feet)==1)
463 amb 219 way_maxwidth=metres_to_height((feet+(double)inches/12.0)*0.254);
464 amb 183 }
465     else if(strstr(v,"ft") || strstr(v,"feet"))
466 amb 136 way_maxwidth=metres_to_width(atof(v)*0.254);
467     else
468     way_maxwidth=metres_to_width(atof(v));
469     }
470 amb 298
471 amb 136 if(!strcmp(k,"maxlength"))
472     {
473 amb 183 if(strchr(v,'\''))
474     {
475     int feet,inches;
476    
477     if(sscanf(v,"%d'%d\"",&feet,&inches)==2)
478 amb 219 way_maxlength=metres_to_height((feet+(double)inches/12.0)*0.254);
479 amb 183 else if(sscanf(v,"%d'",&feet)==1)
480 amb 219 way_maxlength=metres_to_height((feet+(double)inches/12.0)*0.254);
481 amb 183 }
482     else if(strstr(v,"ft") || strstr(v,"feet"))
483 amb 136 way_maxlength=metres_to_length(atof(v)*0.254);
484     else
485     way_maxlength=metres_to_length(atof(v));
486     }
487 amb 298
488 amb 296 if(!strcmp(k,"moped"))
489     {
490 amb 297 if(ISALLOWED(v))
491 amb 296 way_allow_yes|=Allow_Moped;
492     else
493 amb 297 way_allow_no |=Allow_Moped;
494 amb 296 }
495 amb 298
496 amb 51 if(!strcmp(k,"motorbike"))
497     {
498 amb 297 if(ISALLOWED(v))
499 amb 51 way_allow_yes|=Allow_Motorbike;
500     else
501 amb 297 way_allow_no |=Allow_Motorbike;
502 amb 51 }
503 amb 298
504 amb 51 if(!strcmp(k,"motorcar"))
505     {
506 amb 297 if(ISALLOWED(v))
507 amb 51 way_allow_yes|=Allow_Motorcar;
508     else
509 amb 297 way_allow_no |=Allow_Motorcar;
510 amb 51 }
511 amb 298
512 amb 196 if(!strcmp(k,"motor_vehicle"))
513     {
514 amb 297 if(ISALLOWED(v))
515 amb 296 way_allow_yes|=Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
516 amb 196 else
517 amb 297 way_allow_no |=Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
518 amb 196 }
519 amb 51 break;
520    
521     case 'n':
522     if(!strcmp(k,"name"))
523     way_name=strcpy((char*)malloc(strlen(v)+1),v);
524     break;
525    
526     case 'o':
527     if(!strcmp(k,"oneway"))
528 amb 117 {
529 amb 298 if(ISTRUE(v))
530 amb 51 way_oneway=1;
531 amb 117 else if(!strcmp(v,"-1"))
532     way_oneway=-1;
533     }
534 amb 51 break;
535    
536     case 'p':
537 amb 299 if(!strcmp(k,"paved"))
538     {
539     if(ISTRUE(v))
540     way_paved=1;
541     else
542     way_paved=-1;
543     }
544    
545 amb 51 if(!strcmp(k,"psv"))
546     {
547 amb 297 if(ISALLOWED(v))
548 amb 51 way_allow_yes|=Allow_PSV;
549     else
550 amb 297 way_allow_no |=Allow_PSV;
551 amb 51 }
552     break;
553    
554     case 'r':
555     if(!strcmp(k,"ref"))
556     way_ref=strcpy((char*)malloc(strlen(v)+1),v);
557     break;
558    
559 amb 298 case 's':
560     if(!strcmp(k,"surface"))
561     {
562     if(!strcmp(v,"paved") || !strcmp(v,"asphalt") || !strcmp(v,"concrete"))
563     way_paved=1;
564     else
565     way_paved=-1;
566     }
567     break;
568    
569 amb 196 case 'v':
570     if(!strcmp(k,"vehicle"))
571     {
572 amb 297 if(ISALLOWED(v))
573 amb 296 way_allow_yes|=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
574 amb 196 else
575 amb 297 way_allow_no |=Allow_Bicycle|Allow_Moped|Allow_Motorbike|Allow_Motorcar|Allow_Goods|Allow_HGV|Allow_PSV;
576 amb 196 }
577     break;
578    
579 amb 51 default:
580     ;
581 amb 2 }
582     }
583     }
584     else if(isrelation) /* The middle of a relation */
585     {
586     }
587    
588     if(!(nlines%10000))
589     {
590     printf("\rReading: Lines=%ld Nodes=%ld Ways=%ld Relations=%ld",nlines,nnodes,nways,nrelations);
591     fflush(stdout);
592     }
593     }
594    
595 amb 35 printf("\rRead: Lines=%ld Nodes=%ld Ways=%ld Relations=%ld \n",nlines,nnodes,nways,nrelations);
596 amb 2 fflush(stdout);
597    
598 amb 97 if(line)
599     free(line);
600    
601 amb 2 if(way_nalloc)
602     free(way_nodes);
603    
604     return(0);
605     }
606    
607    
608     /*++++++++++++++++++++++++++++++++++++++
609     Call fgets and realloc the buffer as needed to get a whole line.
610    
611     char *fgets_realloc Returns the modified buffer (NULL at the end of the file).
612    
613     char *buffer The current buffer.
614    
615     FILE *file The file to read from.
616     ++++++++++++++++++++++++++++++++++++++*/
617    
618     static char *fgets_realloc(char *buffer,FILE *file)
619     {
620     int n=0;
621     char *buf;
622    
623     if(!buffer)
624     buffer=(char*)malloc(BUFFSIZE+1);
625    
626     while((buf=fgets(&buffer[n],BUFFSIZE,file)))
627     {
628     int s=strlen(buf);
629     n+=s;
630    
631     if(buffer[n-1]=='\n')
632     break;
633     else
634     buffer=(char*)realloc(buffer,n+BUFFSIZE+1);
635     }
636    
637     if(!buf)
638     {free(buffer);buffer=NULL;}
639    
640     return(buffer);
641     }

Properties

Name Value
cvs:description OSM XML file parser.