Debian Codegraph @

extras/find-fixme/fixme-finder.c

raw symbols SCIP
1 /***************************************
2 OSM planet file fixme finder.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2015, 2023, 2025 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27
28 #include "version.h"cxx . . $ `<file>/src/version.h`/
29
30 #include "types.h"cxx . . $ `<file>/src/types.h`/
31 #include "ways.h"cxx . . $ `<file>/src/ways.h`/
32
33 #include "typesx.h"cxx . . $ `<file>/src/typesx.h`/
34 #include "nodesx.h"cxx . . $ `<file>/src/nodesx.h`/
35 #include "waysx.h"cxx . . $ `<file>/src/waysx.h`/
36 #include "relationsx.h"cxx . . $ `<file>/src/relationsx.h`/
37
38 #include "files.h"cxx . . $ `<file>/src/files.h`/
39 #include "logging.h"cxx . . $ `<file>/src/logging.h`/
40 #include "errorlogx.h"cxx . . $ `<file>/src/errorlogx.h`/
41 #include "functions.h"cxx . . $ `<file>/src/functions.h`/
42 #include "osmparser.h"cxx . . $ `<file>/src/osmparser.h`/
43 #include "tagging.h"cxx . . $ `<file>/src/tagging.h`/
44 #include "uncompress.h"cxx . . $ `<file>/src/uncompress.h`/
45
46
47 /* Global variables */
48
49 /*+ The name of the temporary directory. +*/
50 char *option_tmpdirnamecxx . . $ option_tmpdirname.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
51
52 /*+ The amount of RAM to use for filesorting. +*/
53 size_t option_filesort_ramsizecxx . . $ option_filesort_ramsize.=0;
54
55 /*+ The number of threads to use for filesorting. +*/
56 int option_filesort_threadscxx . . $ option_filesort_threads.=1;
57
58
59 /* Local functions */
60
61 static void print_usagecxx . . $ print_usage(70cbaa36f2a21d4d).(int detail,const char *argerr,const char *err);
62
63
64 /*++++++++++++++++++++++++++++++++++++++
65 The main program for the find-fixme.
66 ++++++++++++++++++++++++++++++++++++++*/
67
68 int maincxx . . $ main(afcd3168fc1188a4).(int argc,char** argv)
69 {
70 NodesXcxx . . $ NodesX# *OSMNodes;
71 WaysXcxx . . $ WaysX# *OSMWays;
72 RelationsXcxx . . $ RelationsX# *OSMRelations;
73 ErrorLogsXcxx . . $ ErrorLogsX# *OSMErrorLogs;
74 char *dirname=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,*prefix=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,*tagging=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
75 int option_keep=1;
76 int option_filenames=0;
77 int arg;
78
79 printf_program_startcxx . . $ printf_program_start(49f6e7a06ebc5aa8).();
80
81 /* Parse the command line arguments */
82
83 for(arg=1;arg<argc;arg++)
84 {
85 if(!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[arg],"--version"))
86 print_usagecxx . . $ print_usage(70cbaa36f2a21d4d).(-1,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
87 else if(!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[arg],"--help"))
88 print_usagecxx . . $ print_usage(70cbaa36f2a21d4d).(1,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
89 else if(!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(argv[arg],"--dir=",6))
90 dirname=&argv[arg][6];
91 else if(!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(argv[arg],"--sort-ram-size=",16))
92 option_filesort_ramsizecxx . . $ option_filesort_ramsize.=atoicxx . . $ atoi(5c4306d8553b3696).(&argv[arg][16]);
93 #if defined(USE_PTHREADScxx . . $ `<built-in>:416:9`!) && USE_PTHREADScxx . . $ `<built-in>:416:9`!
94 else if(!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(argv[arg],"--sort-threads=",15))
95 option_filesort_threadscxx . . $ option_filesort_threads.=atoicxx . . $ atoi(5c4306d8553b3696).(&argv[arg][15]);
96 #endif
97 else if(!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(argv[arg],"--tmpdir=",9))
98 option_tmpdirnamecxx . . $ option_tmpdirname.=&argv[arg][9];
99 else if(!strncmpcxx . . $ strncmp(fd278af2f295fa2e).(argv[arg],"--tagging=",10))
100 tagging=&argv[arg][10];
101 else if(!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[arg],"--loggable"))
102 option_loggablecxx . . $ option_loggable.=1;
103 else if(!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[arg],"--logtime"))
104 option_logtimecxx . . $ option_logtime.=1;
105 else if(!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[arg],"--logmemory"))
106 option_logmemorycxx . . $ option_logmemory.=1;
107 else if(argv[arg][0]=='-' && argv[arg][1]=='-')
108 print_usagecxx . . $ print_usage(70cbaa36f2a21d4d).(0,argv[arg],NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
109 else
110 option_filenames++;
111 }
112
113 /* Check the specified command line options */
114
115 if(!option_filesort_ramsizecxx . . $ option_filesort_ramsize.)
116 {
117 #if SLIMcxx . . $ `<built-in>:422:9`!
118 option_filesort_ramsize=256*1024*1024;
119 #else
120 option_filesort_ramsizecxx . . $ option_filesort_ramsize.=1024*1024*1024;
121 #endif
122 }
123 else
124 option_filesort_ramsizecxx . . $ option_filesort_ramsize.*=1024*1024;
125
126 #if defined(USE_PTHREADScxx . . $ `<built-in>:416:9`!) && USE_PTHREADScxx . . $ `<built-in>:416:9`!
127 if(option_filesort_threadscxx . . $ option_filesort_threads.<1 || option_filesort_threadscxx . . $ option_filesort_threads.>32)
128 print_usagecxx . . $ print_usage(70cbaa36f2a21d4d).(0,NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,"Sorting threads '--sort-threads=...' must be small positive integer.");
129 #endif
130
131 if(!option_tmpdirnamecxx . . $ option_tmpdirname.)
132 {
133 if(!dirname)
134 option_tmpdirnamecxx . . $ option_tmpdirname.=".";
135 else
136 option_tmpdirnamecxx . . $ option_tmpdirname.=dirname;
137 }
138
139 if(tagging)
140 {
141 if(!ExistsFilecxx . . $ ExistsFile(5c4306d8553b3696).(tagging))
142 {
143 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error: The '--tagging' option specifies a file that does not exist.\n");
144 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
145 }
146 }
147 else
148 {
149 tagging=FileNamecxx . . $ FileName(11d6a3b64d462fd0).(dirname,prefix,"fixme.xml");
150
151 if(!ExistsFilecxx . . $ ExistsFile(5c4306d8553b3696).(tagging))
152 {
153 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error: The '--tagging' option was not used and the default 'fixme.xml' does not exist.\n");
154 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
155 }
156 }
157
158 if(ParseXMLTaggingRulescxx . . $ ParseXMLTaggingRules(5c4306d8553b3696).(tagging))
159 {
160 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Error: Cannot read the tagging rules in the file '%s'.\n",tagging);
161 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
162 }
163
164 /* Create new node, segment, way and relation variables */
165
166 OSMNodes=NewNodeListcxx . . $ NewNodeList(126077cb9f7392a).(0,0);
167
168 OSMWays=NewWayListcxx . . $ NewWayList(5ffd705fdd89ca47).(0,0);
169
170 OSMRelations=NewRelationListcxx . . $ NewRelationList(6718a73d3247fc37).(0,0);
171
172 /* Create the error log file */
173
174 open_errorlogcxx . . $ open_errorlog(7b85637613228108).(FileNamecxx . . $ FileName(11d6a3b64d462fd0).(dirname,prefix,"fixme.log"),0,option_keep);
175
176 /* Parse the file */
177
178 for(arg=1;arg<argc;arg++)
179 {
180 int fd;
181 char *filename,*p;
182
183 if(argv[arg][0]=='-' && argv[arg][1]=='-')
184 continue;
185
186 filename=strcpycxx . . $ strcpy(b7b3a83273496486).(malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(argv[arg])+1),argv[arg]);
187
188 fd=OpenFilecxx . . $ OpenFile(5c4306d8553b3696).(filename);
189
190 if((p=strstrcxx . . $ strstr(a713fe7b9a57cf96).(filename,".bz2")) && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(p,".bz2"))
191 {
192 fd=Uncompress_Bzip2cxx . . $ Uncompress_Bzip2(7864480464b09eea).(fd);
193 *p=0;
194 }
195
196 if((p=strstrcxx . . $ strstr(a713fe7b9a57cf96).(filename,".gz")) && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(p,".gz"))
197 {
198 fd=Uncompress_Gzipcxx . . $ Uncompress_Gzip(7864480464b09eea).(fd);
199 *p=0;
200 }
201
202 if((p=strstrcxx . . $ strstr(a713fe7b9a57cf96).(filename,".xz")) && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(p,".xz"))
203 {
204 fd=Uncompress_Xzcxx . . $ Uncompress_Xz(7864480464b09eea).(fd);
205 *p=0;
206 }
207
208 printfcxx . . $ printf(581fddd72a8db8fc).("\nParse OSM Data [%s]\n==============\n\n",filename);
209 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
210
211 if((p=strstrcxx . . $ strstr(a713fe7b9a57cf96).(filename,".pbf")) && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(p,".pbf"))
212 {
213 if(ParsePBFFilecxx . . $ ParsePBFFile(d331c4058be34ba0).(fd,OSMNodes,OSMWays,OSMRelations))
214 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); /* no message because one printed in parser function */
215 }
216 else if((p=strstrcxx . . $ strstr(a713fe7b9a57cf96).(filename,".o5m")) && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(p,".o5m"))
217 {
218 if(ParseO5MFilecxx . . $ ParseO5MFile(d331c4058be34ba0).(fd,OSMNodes,OSMWays,OSMRelations))
219 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); /* no message because one printed in parser function */
220 }
221 else
222 {
223 if(ParseOSMFilecxx . . $ ParseOSMFile(d331c4058be34ba0).(fd,OSMNodes,OSMWays,OSMRelations))
224 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); /* no message because one printed in parser function */
225 }
226
227 CloseFilecxx . . $ CloseFile(d4f767463ce0a6b3).(fd);
228
229 freecxx . . $ free(5d22bdacc48458e8).(filename);
230 }
231
232 DeleteXMLTaggingRulescxx . . $ DeleteXMLTaggingRules(49f6e7a06ebc5aa8).();
233
234 FinishNodeListcxx . . $ FinishNodeList(40aa74c85d4e2b20).(OSMNodes);
235 FinishWayListcxx . . $ FinishWayList(9e9638554e83a823).(OSMWays);
236 FinishRelationListcxx . . $ FinishRelationList(a670f149fae266a4).(OSMRelations);
237
238 /* Sort the data */
239
240 printfcxx . . $ printf(581fddd72a8db8fc).("\nSort OSM Data\n=============\n\n");
241 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
242
243 /* Sort the nodes, ways and relations */
244
245 SortNodeListcxx . . $ SortNodeList(40aa74c85d4e2b20).(OSMNodes);
246
247 SortWayListcxx . . $ SortWayList(9e9638554e83a823).(OSMWays);
248
249 SortRelationListcxx . . $ SortRelationList(a670f149fae266a4).(OSMRelations);
250
251 /* Process the data */
252
253 RenameFilecxx . . $ RenameFile(5ae29d726ae57f88).(OSMNodes->filename_tmpcxx . . $ _NodesX#filename_tmp.,OSMNodes->filenamecxx . . $ _NodesX#filename.);
254 RenameFilecxx . . $ RenameFile(5ae29d726ae57f88).(OSMWays->filename_tmpcxx . . $ _WaysX#filename_tmp.,OSMWays->filenamecxx . . $ _WaysX#filename.);
255 RenameFilecxx . . $ RenameFile(5ae29d726ae57f88).(OSMRelations->rrfilename_tmpcxx . . $ _RelationsX#rrfilename_tmp.,OSMRelations->rrfilenamecxx . . $ _RelationsX#rrfilename.);
256 RenameFilecxx . . $ RenameFile(5ae29d726ae57f88).(OSMRelations->trfilename_tmpcxx . . $ _RelationsX#trfilename_tmp.,OSMRelations->trfilenamecxx . . $ _RelationsX#trfilename.);
257
258 close_errorlogcxx . . $ close_errorlog(49f6e7a06ebc5aa8).();
259
260 printfcxx . . $ printf(581fddd72a8db8fc).("\nCreate Error Log\n================\n\n");
261 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
262
263 OSMErrorLogs=NewErrorLogListcxx . . $ NewErrorLogList(fd46f25f42e3fa6c).();
264
265 ProcessErrorLogscxx . . $ ProcessErrorLogs(41c3a21b438859ed).(OSMErrorLogs,OSMNodes,OSMWays,OSMRelations);
266
267 SortErrorLogsGeographicallycxx . . $ SortErrorLogsGeographically(d6b90943ab8a36b3).(OSMErrorLogs);
268
269 SaveErrorLogscxx . . $ SaveErrorLogs(e1f0e7a0f8ca76c7).(OSMErrorLogs,FileNamecxx . . $ FileName(11d6a3b64d462fd0).(dirname,prefix,"fixme.mem"));
270
271 FreeErrorLogListcxx . . $ FreeErrorLogList(d6b90943ab8a36b3).(OSMErrorLogs);
272
273 /* Free the memory (delete the temporary files) */
274
275 FreeNodeListcxx . . $ FreeNodeList(8455fb8954f89607).(OSMNodes,0);
276 FreeWayListcxx . . $ FreeWayList(79a761c30c1a5425).(OSMWays,0);
277 FreeRelationListcxx . . $ FreeRelationList(e87319cf6d90937f).(OSMRelations,0);
278
279 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
280 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
281
282 printf_program_endcxx . . $ printf_program_end(49f6e7a06ebc5aa8).();
283
284 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!);
285 }
286
287
288 /*++++++++++++++++++++++++++++++++++++++
289 Print out the usage information.
290
291 int detail The level of detail to use: -1 = just version number, 0 = low detail, 1 = full details.
292
293 const char *argerr The argument that gave the error (if there is one).
294
295 const char *err Other error message (if there is one).
296 ++++++++++++++++++++++++++++++++++++++*/
297
298 static void print_usagecxx . . $ print_usage(70cbaa36f2a21d4d).(int detail,const char *argerr,const char *err)
299 {
300 if(detail<0)
301 {
302 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
303 "Routino version " ROUTINO_VERSIONcxx . . $ `src/version.h:26:9`! " " ROUTINO_URLcxx . . $ `src/version.h:28:9`! ".\n"
304 );
305 }
306
307 if(detail>=0)
308 {
309 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
310 "Usage: fixme-finder [--version]\n"
311 " [--help]\n"
312 " [--dir=<dirname>]\n"
313 #if defined(USE_PTHREADScxx . . $ `<built-in>:416:9`!) && USE_PTHREADScxx . . $ `<built-in>:416:9`!
314 " [--sort-ram-size=<size>] [--sort-threads=<number>]\n"
315 #else
316 " [--sort-ram-size=<size>]\n"
317 #endif
318 " [--tmpdir=<dirname>]\n"
319 " [--tagging=<filename>]\n"
320 " [--loggable] [--logtime] [--logmemory]\n"
321 " [<filename.osm> ...\n"
322 " | <filename.pbf> ...\n"
323 " | <filename.o5m> ..."
324 #if defined(USE_BZIP2cxx . . $ `<built-in>:417:9`!) && USE_BZIP2cxx . . $ `<built-in>:417:9`!
325 "\n | <filename.(osm|o5m).bz2> ..."
326 #endif
327 #if defined(USE_GZIPcxx . . $ `<built-in>:418:9`!) && USE_GZIPcxx . . $ `<built-in>:418:9`!
328 "\n | <filename.(osm|o5m).gz> ..."
329 #endif
330 #if defined(USE_XZ) && USE_XZ
331 "\n | <filename.(osm|o5m).xz> ..."
332 #endif
333 "]\n");
334
335 if(argerr)
336 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
337 "\n"
338 "Error with command line parameter: %s\n",argerr);
339
340 if(err)
341 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
342 "\n"
343 "Error: %s\n",err);
344 }
345
346 if(detail==1)
347 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,
348 "\n"
349 "--version Print the version of Routino.\n"
350 "\n"
351 "--help Prints this information.\n"
352 "\n"
353 "--dir=<dirname> The directory containing the fixme database.\n"
354 "\n"
355 "--sort-ram-size=<size> The amount of RAM (in MB) to use for data sorting\n"
356 #if SLIMcxx . . $ `<built-in>:422:9`!
357 " (defaults to 256MB otherwise.)\n"
358 #else
359 " (defaults to 1024MB otherwise.)\n"
360 #endif
361 #if defined(USE_PTHREADScxx . . $ `<built-in>:416:9`!) && USE_PTHREADScxx . . $ `<built-in>:416:9`!
362 "--sort-threads=<number> The number of threads to use for data sorting.\n"
363 #endif
364 "\n"
365 "--tmpdir=<dirname> The directory name for temporary files.\n"
366 " (defaults to the '--dir' option directory.)\n"
367 "\n"
368 "--tagging=<filename> The name of the XML file containing the tagging rules\n"
369 " (defaults to 'fixme.xml' with '--dir' option)\n"
370 "\n"
371 "--loggable Print progress messages suitable for logging to file.\n"
372 "--logtime Print the elapsed time for each processing step.\n"
373 "--logmemory Print the max allocated/mapped memory for each step.\n"
374 "\n"
375 "<filename.osm>, <filename.pbf>, <filename.o5m>\n"
376 " The name(s) of the file(s) to read and parse.\n"
377 " Filenames ending '.pbf' read as PBF, filenames ending\n"
378 " '.o5m' read as O5M, others as XML.\n"
379 #if defined(USE_BZIP2cxx . . $ `<built-in>:417:9`!) && USE_BZIP2cxx . . $ `<built-in>:417:9`!
380 " Filenames ending '.bz2' will be bzip2 uncompressed.\n"
381 #endif
382 #if defined(USE_GZIPcxx . . $ `<built-in>:418:9`!) && USE_GZIPcxx . . $ `<built-in>:418:9`!
383 " Filenames ending '.gz' will be gzip uncompressed.\n"
384 #endif
385 #if defined(USE_XZ) && USE_XZ
386 " Filenames ending '.xz' will be xz uncompressed.\n"
387 #endif
388 );
389
390 exitcxx . . $ exit(3ca292c338df9bb3).(!detail);
391 }