/*************************************** Fixme file dumper. Part of the Routino routing software. ******************/ /****************** This file Copyright 2013-2015, 2018 Andrew M. Bishop This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . ***************************************/ #include #include #include #include #include #include #include "version.h" #include "types.h" #include "errorlog.h" #include "files.h" #include "xmlparse.h" /* Local functions */ static void OutputErrorLog(ErrorLogs *errorlogs,double latmin,double latmax,double lonmin,double lonmax); static void print_errorlog_visualiser(ErrorLogs *errorlogs,index_t item); static char *RFC822Date(time_t t); static void print_usage(int detail,const char *argerr,const char *err); /*++++++++++++++++++++++++++++++++++++++ The main program for the fixme dumper. ++++++++++++++++++++++++++++++++++++++*/ int main(int argc,char** argv) { ErrorLogs*OSMErrorLogs; int arg; char *dirname=NULL,*prefix=NULL; char *errorlogs_filename; int option_statistics=0; int option_visualiser=0,coordcount=0; double latmin=0,latmax=0,lonmin=0,lonmax=0; char *option_data=NULL; int option_dump_visualiser=0; /* Parse the command line arguments */ for(arg=1;argfile.number); printf("Number(geographical) =%9"Pindex_t"\n",OSMErrorLogs->file.number_geo); printf("Number(non-geographical)=%9"Pindex_t"\n",OSMErrorLogs->file.number_nongeo); printf("\n"); stat(errorlogs_filename,&buf); #if !SLIM printf("Total strings=%9zu Bytes\n",(size_t)buf.st_size-(OSMErrorLogs->strings-(char*)OSMErrorLogs->data)); #else printf("Total strings=%9zu Bytes\n",(size_t)buf.st_size-(size_t)OSMErrorLogs->stringsoffset); #endif } /* Print out internal data (in HTML format for the visualiser) */ if(option_dump_visualiser) { index_t item; if(!option_data) print_usage(0,NULL,"The --dump-visualiser option must have --data.\n"); for(arg=1;argfile.number) print_errorlog_visualiser(OSMErrorLogs,item); else printf("Invalid fixme number; minimum=0, maximum=%"Pindex_t".\n",OSMErrorLogs->file.number-1); } } exit(EXIT_SUCCESS); } /*++++++++++++++++++++++++++++++++++++++ Output the data for error logs within the region. ErrorLogs *errorlogs The set of error logs to use. double latmin The minimum latitude. double latmax The maximum latitude. double lonmin The minimum longitude. double lonmax The maximum longitude. ++++++++++++++++++++++++++++++++++++++*/ static void OutputErrorLog(ErrorLogs *errorlogs,double latmin,double latmax,double lonmin,double lonmax) { ll_bin_t latminbin=latlong_to_bin(radians_to_latlong(latmin))-errorlogs->file.latzero; ll_bin_t latmaxbin=latlong_to_bin(radians_to_latlong(latmax))-errorlogs->file.latzero; ll_bin_t lonminbin=latlong_to_bin(radians_to_latlong(lonmin))-errorlogs->file.lonzero; ll_bin_t lonmaxbin=latlong_to_bin(radians_to_latlong(lonmax))-errorlogs->file.lonzero; ll_bin_t latb,lonb; index_t i,index1,index2; /* Loop through all of the error logs. */ for(latb=latminbin;latb<=latmaxbin;latb++) for(lonb=lonminbin;lonb<=lonmaxbin;lonb++) { ll_bin2_t llbin=lonb*errorlogs->file.latbins+latb; if(llbin<0 || llbin>(errorlogs->file.latbins*errorlogs->file.lonbins)) continue; index1=LookupErrorLogOffset(errorlogs,llbin); index2=LookupErrorLogOffset(errorlogs,llbin+1); if(index2>errorlogs->file.number_geo) index2=errorlogs->file.number_geo; for(i=index1;ifile.latzero+latb)+off_to_latlong(errorlogp->latoffset)); double lon=latlong_to_radians(bin_to_latlong(errorlogs->file.lonzero+lonb)+off_to_latlong(errorlogp->lonoffset)); if(lat>latmin && latlonmin && lontm_wday]); strcpy(month,months[tim->tm_mon]); /* Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 */ sprintf(value,"%3s, %02d %3s %4d %02d:%02d:%02d %s", weekday, tim->tm_mday, month, tim->tm_year+1900, tim->tm_hour, tim->tm_min, tim->tm_sec, "GMT" ); return(value); } /*++++++++++++++++++++++++++++++++++++++ Print out the usage information. int detail The level of detail to use: -1 = just version number, 0 = low detail, 1 = full details. 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,const char *argerr,const char *err) { if(detail<0) { fprintf(stderr, "Routino version " ROUTINO_VERSION " " ROUTINO_URL ".\n" ); } if(detail>=0) { fprintf(stderr, "Usage: fixme-dumper [--version]\n" " [--help]\n" " [--dir=]\n" " [--statistics]\n" " [--visualiser --latmin= --latmax=\n" " --lonmin= --lonmax=\n" " --data=]\n" " [--dump--visualiser [--data=fixme]]\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==1) fprintf(stderr, "\n" "--version Print the version of Routino.\n" "\n" "--help Prints this information.\n" "\n" "--dir= The directory containing the fixme database.\n" "\n" "--statistics Print statistics about the fixme database.\n" "\n" "--visualiser Extract selected data from the fixme database:\n" " --latmin= * the minimum latitude (degrees N).\n" " --latmax= * the maximum latitude (degrees N).\n" " --lonmin= * the minimum longitude (degrees E).\n" " --lonmax= * the maximum longitude (degrees E).\n" " --data= * the type of data to select.\n" "\n" " can be selected from:\n" " fixmes = fixme tags extracted from the data.\n" "\n" "--dump-visualiser Dump selected contents of the database in HTML.\n" " --data=fixme * the fixme with the selected index.\n"); exit(!detail); }