Imported Upstream version 1.5
[routino] / src / planetsplitter.c
index 5380455..d660154 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************
- $Header: /home/amb/routino/src/RCS/planetsplitter.c,v 1.73 2010/05/22 18:40:47 amb Exp $
+ $Header: /home/amb/routino/src/RCS/planetsplitter.c,v 1.81 2010/09/17 18:38:39 amb Exp $
 
  OSM planet file splitter.
 
 #include <string.h>
 #include <errno.h>
 
-#include "typesx.h"
 #include "types.h"
-#include "functionsx.h"
-#include "functions.h"
+#include "ways.h"
+
+#include "typesx.h"
 #include "nodesx.h"
 #include "segmentsx.h"
 #include "waysx.h"
+#include "relationsx.h"
 #include "superx.h"
-#include "ways.h"
+
+#include "files.h"
+#include "functions.h"
+#include "functionsx.h"
 #include "tagging.h"
 
 
 /* Global variables */
 
-/*+ The option to use a slim mode with file-backed read-only intermediate storage. +*/
-int option_slim=0;
-
 /*+ The name of the temporary directory. +*/
 char *option_tmpdirname=NULL;
 
@@ -53,7 +54,7 @@ size_t option_filesort_ramsize=0;
 
 /* Local functions */
 
-static void print_usage(int detail);
+static void print_usage(int detail,const char *argerr,const char *err);
 
 
 /*++++++++++++++++++++++++++++++++++++++
@@ -62,24 +63,23 @@ static void print_usage(int detail);
 
 int main(int argc,char** argv)
 {
- NodesX    *Nodes;
- SegmentsX *Segments,*SuperSegments=NULL,*MergedSegments=NULL;
- WaysX     *Ways;
- int        iteration=0,quit=0;
- int        max_iterations=10;
- char      *dirname=NULL,*prefix=NULL,*tagging=NULL;
- int        option_parse_only=0,option_process_only=0;
- int        option_filenames=0;
- int        arg;
+ NodesX     *Nodes;
+ SegmentsX  *Segments,*SuperSegments=NULL,*MergedSegments=NULL;
+ WaysX      *Ways;
+ RelationsX *Relations;
+ int         iteration=0,quit=0;
+ int         max_iterations=10;
+ char       *dirname=NULL,*prefix=NULL,*tagging=NULL;
+ int         option_parse_only=0,option_process_only=0;
+ int         option_filenames=0;
+ int         arg;
 
  /* Parse the command line arguments */
 
  for(arg=1;arg<argc;arg++)
    {
     if(!strcmp(argv[arg],"--help"))
-       print_usage(1);
-    else if(!strcmp(argv[arg],"--slim"))
-       option_slim=1;
+       print_usage(1,NULL,NULL);
     else if(!strncmp(argv[arg],"--sort-ram-size=",16))
        option_filesort_ramsize=atoi(&argv[arg][16]);
     else if(!strncmp(argv[arg],"--dir=",6))
@@ -97,7 +97,7 @@ int main(int argc,char** argv)
     else if(!strncmp(argv[arg],"--tagging=",10))
        tagging=&argv[arg][10];
     else if(argv[arg][0]=='-' && argv[arg][1]=='-')
-       print_usage(0);
+       print_usage(0,argv[arg],NULL);
     else
        option_filenames++;
    }
@@ -105,17 +105,18 @@ int main(int argc,char** argv)
  /* Check the specified command line options */
 
  if(option_parse_only && option_process_only)
-    print_usage(0);
+    print_usage(0,NULL,"Cannot use '--parse-only' and '--process-only' at the same time.");
 
  if(option_filenames && option_process_only)
-    print_usage(0);
+    print_usage(0,NULL,"Cannot use '--process-only' and filenames at the same time.");
 
  if(!option_filesort_ramsize)
    {
-    if(option_slim)
+#if SLIM
        option_filesort_ramsize=64*1024*1024;
-    else
+#else
        option_filesort_ramsize=256*1024*1024;
+#endif
    }
  else
     option_filesort_ramsize*=1024*1024;
@@ -128,24 +129,34 @@ int main(int argc,char** argv)
        option_tmpdirname=dirname;
    }
 
- if(tagging && ExistsFile(tagging))
-    ;
- else if(!tagging && ExistsFile(FileName(dirname,prefix,"tagging.xml")))
-    tagging=FileName(dirname,prefix,"tagging.xml");
-
- if(tagging && ParseXMLTaggingRules(tagging))
+ if(tagging)
    {
-    fprintf(stderr,"Error: Cannot read the tagging rules in the file '%s'.\n",tagging);
-    return(1);
+    if(!ExistsFile(tagging))
+      {
+       fprintf(stderr,"Error: The '--tagging' option specifies a file that does not exist.\n");
+       return(1);
+      }
+   }
+ else
+   {
+    if(ExistsFile(FileName(dirname,prefix,"tagging.xml")))
+       tagging=FileName(dirname,prefix,"tagging.xml");
+    else if(ExistsFile(FileName(DATADIR,NULL,"tagging.xml")))
+       tagging=FileName(DATADIR,NULL,"tagging.xml");
+    else
+      {
+       fprintf(stderr,"Error: The '--tagging' option was not used and the default 'tagging.xml' does not exist.\n");
+       return(1);
+      }
    }
 
- if(!tagging)
+ if(ParseXMLTaggingRules(tagging))
    {
-    fprintf(stderr,"Error: Cannot run without reading some tagging rules.\n");
+    fprintf(stderr,"Error: Cannot read the tagging rules in the file '%s'.\n",tagging);
     return(1);
    }
 
- /* Create new node, segment and way variables */
+ /* Create new node, segment, way and relation variables */
 
  Nodes=NewNodeList(option_parse_only||option_process_only);
 
@@ -153,6 +164,8 @@ int main(int argc,char** argv)
 
  Ways=NewWayList(option_parse_only||option_process_only);
 
+ Relations=NewRelationList(option_parse_only||option_process_only);
+
  /* Parse the file */
 
  if(option_filenames)
@@ -175,7 +188,7 @@ int main(int argc,char** argv)
        printf("\nParse OSM Data [%s]\n==============\n\n",argv[arg]);
        fflush(stdout);
 
-       if(ParseOSM(file,Nodes,Segments,Ways))
+       if(ParseOSM(file,Nodes,Segments,Ways,Relations))
           exit(EXIT_FAILURE);
 
        fclose(file);
@@ -186,7 +199,7 @@ int main(int argc,char** argv)
     printf("\nParse OSM Data\n==============\n\n");
     fflush(stdout);
 
-    if(ParseOSM(stdin,Nodes,Segments,Ways))
+    if(ParseOSM(stdin,Nodes,Segments,Ways,Relations))
        exit(EXIT_FAILURE);
    }
 
@@ -195,6 +208,7 @@ int main(int argc,char** argv)
     FreeNodeList(Nodes,1);
     FreeSegmentList(Segments,1);
     FreeWayList(Ways,1);
+    FreeRelationList(Relations,1);
 
     return(0);
    }
@@ -204,7 +218,7 @@ int main(int argc,char** argv)
  printf("\nProcess OSM Data\n================\n\n");
  fflush(stdout);
 
- /* Sort the nodes, segments and ways */
+ /* Sort the nodes, segments, ways and relations */
 
  SortNodeList(Nodes);
 
@@ -212,6 +226,18 @@ int main(int argc,char** argv)
 
  SortWayList(Ways);
 
+ SortRelationList(Relations);
+
+ /* Process the route relations (must be before compacting the ways) */
+
+ ProcessRouteRelations(Relations,Ways);
+
+ FreeRelationList(Relations,0);
+
+ /* Compact the ways (must be before measuring the segments) */
+
+ CompactWayList(Ways);
+
  /* Remove bad segments (must be after sorting the nodes and segments) */
 
  RemoveBadSegments(Nodes,Segments);
@@ -356,20 +382,34 @@ int main(int argc,char** argv)
   Print out the usage information.
 
   int detail The level of detail to use - 0 = low, 1 = high.
+
+  const char *argerr The argument that gave the error (if there is one).
+
+  const char *err Other error message (if there is one).
   ++++++++++++++++++++++++++++++++++++++*/
 
-static void print_usage(int detail)
+static void print_usage(int detail,const char *argerr,const char *err)
 {
  fprintf(stderr,
          "Usage: planetsplitter [--help]\n"
          "                      [--dir=<dirname>] [--prefix=<name>]\n"
-         "                      [--slim] [--sort-ram-size=<size>]\n"
+         "                      [--sort-ram-size=<size>]\n"
          "                      [--tmpdir=<dirname>]\n"
          "                      [--parse-only | --process-only]\n"
          "                      [--max-iterations=<number>]\n"
          "                      [--tagging=<filename>]\n"
          "                      [<filename.osm> ...]\n");
 
+ if(argerr)
+    fprintf(stderr,
+            "\n"
+            "Error with command line parameter: %s\n",argerr);
+
+ if(err)
+    fprintf(stderr,
+            "\n"
+            "Error: %s\n",err);
+
  if(detail)
     fprintf(stderr,
             "\n"
@@ -378,9 +418,12 @@ static void print_usage(int detail)
             "--dir=<dirname>           The directory containing the routing database.\n"
             "--prefix=<name>           The filename prefix for the routing database.\n"
             "\n"
-            "--slim                    Use less RAM and more temporary files.\n"
             "--sort-ram-size=<size>    The amount of RAM (in MB) to use for data sorting\n"
-            "                          (defaults to 64MB with '--slim' or 256MB otherwise.)\n"
+#if SLIM
+            "                          (defaults to 64MB otherwise.)\n"
+#else
+            "                          (defaults to 256MB otherwise.)\n"
+#endif
             "--tmpdir=<dirname>        The directory name for temporary files.\n"
             "                          (defaults to the '--dir' option directory.)\n"
             "\n"
@@ -390,8 +433,9 @@ static void print_usage(int detail)
             "--max-iterations=<number> The number of iterations for finding super-nodes.\n"
             "\n"
             "--tagging=<filename>      The name of the XML file containing the tagging rules\n"
-            "                          (defaults to 'tagging.xml' with '--dirname' and\n"
-            "                           '--prefix' options).\n"
+            "                          (defaults to 'tagging.xml' with '--dir' and\n"
+            "                           '--prefix' options or the file installed in\n"
+            "                           '" DATADIR "').\n"
             "\n"
             "<filename.osm> ...        The name(s) of the file(s) to process (by default\n"
             "                          data is read from standard input).\n"