forked from hans/Nominatim
clean up formatting
This commit is contained in:
@@ -44,7 +44,8 @@ void nominatim_export(int rank_min, int rank_max, const char *conninfo, const ch
|
||||
Oid pg_prepare_params[2];
|
||||
|
||||
conn = PQconnectdb(conninfo);
|
||||
if (PQstatus(conn) != CONNECTION_OK) {
|
||||
if (PQstatus(conn) != CONNECTION_OK)
|
||||
{
|
||||
fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(conn));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -126,7 +127,7 @@ void nominatim_export(int rank_min, int rank_max, const char *conninfo, const ch
|
||||
}
|
||||
|
||||
tuples = PQntuples(resPlaces);
|
||||
for(i = 0; i < tuples; i++)
|
||||
for (i = 0; i < tuples; i++)
|
||||
{
|
||||
nominatim_exportPlace(PGint32(*((uint32_t *)PQgetvalue(resPlaces, i, 0))), conn, writer, NULL);
|
||||
rankTotalDone++;
|
||||
@@ -324,7 +325,7 @@ void nominatim_exportPlace(uint64_t place_id, PGconn * conn, xmlTextWriterPtr wr
|
||||
{
|
||||
xmlTextWriterStartElement(writer, BAD_CAST "names");
|
||||
|
||||
for(i = 0; i < PQntuples(resNames); i++)
|
||||
for (i = 0; i < PQntuples(resNames); i++)
|
||||
{
|
||||
xmlTextWriterStartElement(writer, BAD_CAST "name");
|
||||
xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST PQgetvalue(resNames, i, 0));
|
||||
@@ -359,7 +360,7 @@ void nominatim_exportPlace(uint64_t place_id, PGconn * conn, xmlTextWriterPtr wr
|
||||
if (PQntuples(resAddress) > 0)
|
||||
{
|
||||
xmlTextWriterStartElement(writer, BAD_CAST "address");
|
||||
for(i = 0; i < PQntuples(resAddress); i++)
|
||||
for (i = 0; i < PQntuples(resAddress); i++)
|
||||
{
|
||||
xmlTextWriterStartElement(writer, BAD_CAST getRankLabel(atoi(PQgetvalue(resAddress, i, 5))));
|
||||
xmlTextWriterWriteAttribute(writer, BAD_CAST "rank", BAD_CAST PQgetvalue(resAddress, i, 5));
|
||||
@@ -378,7 +379,7 @@ void nominatim_exportPlace(uint64_t place_id, PGconn * conn, xmlTextWriterPtr wr
|
||||
{
|
||||
xmlTextWriterStartElement(writer, BAD_CAST "tags");
|
||||
|
||||
for(i = 0; i < PQntuples(resExtraTags); i++)
|
||||
for (i = 0; i < PQntuples(resExtraTags); i++)
|
||||
{
|
||||
xmlTextWriterStartElement(writer, BAD_CAST "tag");
|
||||
xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST PQgetvalue(resExtraTags, i, 0));
|
||||
@@ -405,7 +406,7 @@ void nominatim_exportPlace(uint64_t place_id, PGconn * conn, xmlTextWriterPtr wr
|
||||
|
||||
const char * getRankLabel(int rank)
|
||||
{
|
||||
switch(rank)
|
||||
switch (rank)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
|
||||
@@ -22,7 +22,8 @@ typedef enum { FILEMODE_NONE, FILEMODE_ADD, FILEMODE_UPDATE, FILEMODE_DELETE } f
|
||||
#define MAX_FEATURENAMESTRING 100000
|
||||
#define MAX_FEATUREEXTRATAGSTRING 50000
|
||||
|
||||
struct feature_address {
|
||||
struct feature_address
|
||||
{
|
||||
int place_id;
|
||||
int rankAddress;
|
||||
char isAddress[2];
|
||||
@@ -33,12 +34,14 @@ struct feature_address {
|
||||
xmlChar * distance;
|
||||
};
|
||||
|
||||
struct feature_tag {
|
||||
struct feature_tag
|
||||
{
|
||||
xmlChar * type;
|
||||
xmlChar * value;
|
||||
};
|
||||
|
||||
struct feature {
|
||||
struct feature
|
||||
{
|
||||
int placeID;
|
||||
xmlChar * type;
|
||||
xmlChar * id;
|
||||
@@ -381,7 +384,7 @@ void EndElement(xmlTextReaderPtr reader, const xmlChar *name)
|
||||
namePos = 0;
|
||||
lineTypeLen = 0;
|
||||
lineValueLen = 0;
|
||||
for(i = 0; i < featureNameLines; i++)
|
||||
for (i = 0; i < featureNameLines; i++)
|
||||
{
|
||||
lineTypeLen = strlen(BAD_CAST featureName[i].type);
|
||||
lineValueLen = strlen(BAD_CAST featureName[i].value);
|
||||
@@ -409,7 +412,7 @@ void EndElement(xmlTextReaderPtr reader, const xmlChar *name)
|
||||
namePos = 0;
|
||||
lineTypeLen = 0;
|
||||
lineValueLen = 0;
|
||||
for(i = 0; i < featureExtraTagLines; i++)
|
||||
for (i = 0; i < featureExtraTagLines; i++)
|
||||
{
|
||||
lineTypeLen = strlen(BAD_CAST featureExtraTag[i].type);
|
||||
lineValueLen = strlen(BAD_CAST featureExtraTag[i].value);
|
||||
@@ -445,7 +448,7 @@ void EndElement(xmlTextReaderPtr reader, const xmlChar *name)
|
||||
}
|
||||
PQclear(res);
|
||||
|
||||
for(i = 0; i < featureAddressLines; i++)
|
||||
for (i = 0; i < featureAddressLines; i++)
|
||||
{
|
||||
// insert into place_address
|
||||
paramValues[0] = (const char *)place_id;
|
||||
@@ -504,7 +507,7 @@ void EndElement(xmlTextReaderPtr reader, const xmlChar *name)
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = 0; i < featureAddressLines; i++)
|
||||
for (i = 0; i < featureAddressLines; i++)
|
||||
{
|
||||
xmlFree(featureAddress[i].type);
|
||||
xmlFree(featureAddress[i].id);
|
||||
@@ -539,7 +542,7 @@ static void processNode(xmlTextReaderPtr reader)
|
||||
name = xmlStrdup(BAD_CAST "--");
|
||||
}
|
||||
|
||||
switch(xmlTextReaderNodeType(reader))
|
||||
switch (xmlTextReaderNodeType(reader))
|
||||
{
|
||||
case XML_READER_TYPE_ELEMENT:
|
||||
StartElement(reader, name);
|
||||
@@ -589,13 +592,13 @@ int nominatim_import(const char *conninfo, const char *partionTagsFilename, cons
|
||||
|
||||
char buffer[1024], osmkey[256], osmvalue[256];
|
||||
int fields;
|
||||
while(fgets(buffer, sizeof(buffer), partionTagsFile) != NULL)
|
||||
while (fgets(buffer, sizeof(buffer), partionTagsFile) != NULL)
|
||||
{
|
||||
fields = sscanf( buffer, "%23s %63s", osmkey, osmvalue );
|
||||
|
||||
if( fields <= 0 ) continue;
|
||||
if ( fields <= 0 ) continue;
|
||||
|
||||
if( fields != 2 )
|
||||
if ( fields != 2 )
|
||||
{
|
||||
fprintf( stderr, "Error partition file\n");
|
||||
exit_nicely();
|
||||
@@ -716,7 +719,8 @@ int nominatim_import(const char *conninfo, const char *partionTagsFilename, cons
|
||||
processNode(reader);
|
||||
ret = xmlTextReaderRead(reader);
|
||||
}
|
||||
if (ret != 0) {
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "%s : failed to parse\n", filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
||||
Oid pg_prepare_params[2];
|
||||
|
||||
conn = PQconnectdb(conninfo);
|
||||
if (PQstatus(conn) != CONNECTION_OK) {
|
||||
if (PQstatus(conn) != CONNECTION_OK)
|
||||
{
|
||||
fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(conn));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -109,7 +110,8 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
||||
for (i = 0; i < num_threads; i++)
|
||||
{
|
||||
thread_data[i].conn = PQconnectdb(conninfo);
|
||||
if (PQstatus(thread_data[i].conn) != CONNECTION_OK) {
|
||||
if (PQstatus(thread_data[i].conn) != CONNECTION_OK)
|
||||
{
|
||||
fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(thread_data[i].conn));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -258,7 +260,7 @@ void nominatim_index(int rank_min, int rank_max, int num_threads, const char *co
|
||||
|
||||
// Monitor threads to give user feedback
|
||||
sleepcount = 0;
|
||||
while(count < tuples)
|
||||
while (count < tuples)
|
||||
{
|
||||
usleep(1000);
|
||||
|
||||
@@ -312,7 +314,7 @@ void *nominatim_indexThread(void * thread_data_in)
|
||||
uint32_t place_id;
|
||||
time_t updateStartTime;
|
||||
|
||||
while(1)
|
||||
while (1)
|
||||
{
|
||||
pthread_mutex_lock( thread_data->count_mutex );
|
||||
if (*(thread_data->count) >= thread_data->tuples)
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include <libxml/encoding.h>
|
||||
#include <libxml/xmlwriter.h>
|
||||
|
||||
struct index_thread_data{
|
||||
struct index_thread_data
|
||||
{
|
||||
pthread_t thread;
|
||||
PGconn * conn;
|
||||
PGresult * res;
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
|
||||
#include "input.h"
|
||||
|
||||
struct Input {
|
||||
struct Input
|
||||
{
|
||||
char *name;
|
||||
enum { plainFile, gzipFile, bzip2File } type;
|
||||
void *fileHandle;
|
||||
@@ -33,7 +34,8 @@ struct Input {
|
||||
|
||||
// tries to re-open the bz stream at the next stream start.
|
||||
// returns 0 on success, -1 on failure.
|
||||
int bzReOpen(struct Input *ctx, int *error) {
|
||||
int bzReOpen(struct Input *ctx, int *error)
|
||||
{
|
||||
// for copying out the last unused part of the block which
|
||||
// has an EOS token in it. needed for re-initialising the
|
||||
// next stream.
|
||||
@@ -68,7 +70,8 @@ int readFile(void *context, char * buffer, int len)
|
||||
if (ctx->eof || (len == 0))
|
||||
return 0;
|
||||
|
||||
switch(ctx->type) {
|
||||
switch (ctx->type)
|
||||
{
|
||||
case plainFile:
|
||||
l = read(*(int *)f, buffer, len);
|
||||
if (l <= 0) ctx->eof = 1;
|
||||
@@ -82,9 +85,11 @@ int readFile(void *context, char * buffer, int len)
|
||||
|
||||
// error codes BZ_OK and BZ_STREAM_END are both "OK", but the stream
|
||||
// end means the reader needs to be reset from the original handle.
|
||||
if (error != BZ_OK) {
|
||||
if (error != BZ_OK)
|
||||
{
|
||||
// for stream errors, try re-opening the stream before admitting defeat.
|
||||
if (error != BZ_STREAM_END || bzReOpen(ctx, &error) != 0) {
|
||||
if (error != BZ_STREAM_END || bzReOpen(ctx, &error) != 0)
|
||||
{
|
||||
l = 0;
|
||||
ctx->eof = 1;
|
||||
}
|
||||
@@ -95,7 +100,8 @@ int readFile(void *context, char * buffer, int len)
|
||||
break;
|
||||
}
|
||||
|
||||
if (l < 0) {
|
||||
if (l < 0)
|
||||
{
|
||||
fprintf(stderr, "File reader received error %d (%d)\n", l, error);
|
||||
l = 0;
|
||||
}
|
||||
@@ -107,12 +113,14 @@ char inputGetChar(void *context)
|
||||
{
|
||||
struct Input *ctx = context;
|
||||
|
||||
if (ctx->buf_ptr == ctx->buf_fill) {
|
||||
if (ctx->buf_ptr == ctx->buf_fill)
|
||||
{
|
||||
ctx->buf_fill = readFile(context, &ctx->buf[0], sizeof(ctx->buf));
|
||||
ctx->buf_ptr = 0;
|
||||
if (ctx->buf_fill == 0)
|
||||
return 0;
|
||||
if (ctx->buf_fill < 0) {
|
||||
if (ctx->buf_fill < 0)
|
||||
{
|
||||
perror("Error while reading file");
|
||||
exit(1);
|
||||
}
|
||||
@@ -138,13 +146,17 @@ void *inputOpen(const char *name)
|
||||
|
||||
ctx->name = strdup(name);
|
||||
|
||||
if (ext && !strcmp(ext, ".gz")) {
|
||||
if (ext && !strcmp(ext, ".gz"))
|
||||
{
|
||||
ctx->fileHandle = (void *)gzopen(name, "rb");
|
||||
ctx->type = gzipFile;
|
||||
} else if (ext && !strcmp(ext, ".bz2")) {
|
||||
}
|
||||
else if (ext && !strcmp(ext, ".bz2"))
|
||||
{
|
||||
int error = 0;
|
||||
ctx->systemHandle = fopen(name, "rb");
|
||||
if (!ctx->systemHandle) {
|
||||
if (!ctx->systemHandle)
|
||||
{
|
||||
fprintf(stderr, "error while opening file %s\n", name);
|
||||
exit(10);
|
||||
}
|
||||
@@ -152,18 +164,25 @@ void *inputOpen(const char *name)
|
||||
ctx->fileHandle = (void *)BZ2_bzReadOpen(&error, ctx->systemHandle, 0, 0, NULL, 0);
|
||||
ctx->type = bzip2File;
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int *pfd = malloc(sizeof(pfd));
|
||||
if (pfd) {
|
||||
if (!strcmp(name, "-")) {
|
||||
if (pfd)
|
||||
{
|
||||
if (!strcmp(name, "-"))
|
||||
{
|
||||
*pfd = STDIN_FILENO;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int flags = O_RDONLY;
|
||||
#ifdef O_LARGEFILE
|
||||
flags |= O_LARGEFILE;
|
||||
#endif
|
||||
*pfd = open(name, flags);
|
||||
if (*pfd < 0) {
|
||||
if (*pfd < 0)
|
||||
{
|
||||
free(pfd);
|
||||
pfd = NULL;
|
||||
}
|
||||
@@ -172,7 +191,8 @@ void *inputOpen(const char *name)
|
||||
ctx->fileHandle = (void *)pfd;
|
||||
ctx->type = plainFile;
|
||||
}
|
||||
if (!ctx->fileHandle) {
|
||||
if (!ctx->fileHandle)
|
||||
{
|
||||
fprintf(stderr, "error while opening file %s\n", name);
|
||||
exit(10);
|
||||
}
|
||||
@@ -186,7 +206,8 @@ int inputClose(void *context)
|
||||
struct Input *ctx = context;
|
||||
void *f = ctx->fileHandle;
|
||||
|
||||
switch(ctx->type) {
|
||||
switch (ctx->type)
|
||||
{
|
||||
case plainFile:
|
||||
close(*(int *)f);
|
||||
free(f);
|
||||
@@ -211,7 +232,8 @@ xmlTextReaderPtr inputUTF8(const char *name)
|
||||
{
|
||||
void *ctx = inputOpen(name);
|
||||
|
||||
if (!ctx) {
|
||||
if (!ctx)
|
||||
{
|
||||
fprintf(stderr, "Input reader create failed for: %s\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ static void long_usage(char *arg0)
|
||||
fprintf(stderr, " -v|--verbose\t\tVerbose output.\n");
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
if (sizeof(int*) == 4) {
|
||||
if (sizeof(int*) == 4)
|
||||
{
|
||||
fprintf(stderr, "\n\nYou are running this on 32bit system - this will not work\n");
|
||||
}
|
||||
}
|
||||
@@ -112,9 +113,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
fprintf(stderr, "nominatim SVN version %s\n\n", VERSION);
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
int c, option_index = 0;
|
||||
static struct option long_options[] = {
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"help", 0, 0, 'h'},
|
||||
|
||||
{"verbose", 0, 0, 'v'},
|
||||
@@ -140,20 +143,47 @@ int main(int argc, char *argv[])
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'v': verbose=1; break;
|
||||
case 'd': db=optarg; break;
|
||||
case 'U': username=optarg; break;
|
||||
case 'W': pass_prompt=1; break;
|
||||
case 'H': host=optarg; break;
|
||||
case 'P': port=optarg; break;
|
||||
case 'h': long_usage_bool=1; break;
|
||||
case 'i': index=1; break;
|
||||
case 'e': export=1; break;
|
||||
case 'I': import=1; break;
|
||||
case 't': threads=atoi(optarg); break;
|
||||
case 'F': file=optarg; break;
|
||||
case 'T': tagsfile=optarg; break;
|
||||
switch (c)
|
||||
{
|
||||
case 'v':
|
||||
verbose=1;
|
||||
break;
|
||||
case 'd':
|
||||
db=optarg;
|
||||
break;
|
||||
case 'U':
|
||||
username=optarg;
|
||||
break;
|
||||
case 'W':
|
||||
pass_prompt=1;
|
||||
break;
|
||||
case 'H':
|
||||
host=optarg;
|
||||
break;
|
||||
case 'P':
|
||||
port=optarg;
|
||||
break;
|
||||
case 'h':
|
||||
long_usage_bool=1;
|
||||
break;
|
||||
case 'i':
|
||||
index=1;
|
||||
break;
|
||||
case 'e':
|
||||
export=1;
|
||||
break;
|
||||
case 'I':
|
||||
import=1;
|
||||
break;
|
||||
case 't':
|
||||
threads=atoi(optarg);
|
||||
break;
|
||||
case 'F':
|
||||
file=optarg;
|
||||
break;
|
||||
case 'T':
|
||||
tagsfile=optarg;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
short_usage(argv[0]);
|
||||
@@ -161,34 +191,38 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (long_usage_bool) {
|
||||
if (long_usage_bool)
|
||||
{
|
||||
long_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (threads < 1) threads = 1;
|
||||
|
||||
/*
|
||||
/*
|
||||
if (argc == optind) { // No non-switch arguments
|
||||
short_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
*/
|
||||
if (index && import) {
|
||||
*/
|
||||
if (index && import)
|
||||
{
|
||||
fprintf(stderr, "Error: --index and --import options can not be used on the same database!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pass_prompt)
|
||||
password = simple_prompt("Password:", 100, 0);
|
||||
else {
|
||||
else
|
||||
{
|
||||
password = getenv("PGPASS");
|
||||
}
|
||||
|
||||
// Test the database connection
|
||||
conninfo = build_conninfo(db, username, password, host, port);
|
||||
conn = PQconnectdb(conninfo);
|
||||
if (PQstatus(conn) != CONNECTION_OK) {
|
||||
if (PQstatus(conn) != CONNECTION_OK)
|
||||
{
|
||||
fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(conn));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#define MAX(x,y) (x > y?x:y)
|
||||
#define MIN(x,y) (x < y?x:y)
|
||||
|
||||
struct output_options {
|
||||
struct output_options
|
||||
{
|
||||
const char *conninfo; /* Connection info string */
|
||||
const char *prefix; /* prefix for table names */
|
||||
int scale; /* scale for converting coordinates to fixed point */
|
||||
|
||||
@@ -12,22 +12,26 @@ const char *build_conninfo(const char *db, const char *username, const char *pas
|
||||
strcat(conninfo, db);
|
||||
strcat(conninfo, "'");
|
||||
|
||||
if (username) {
|
||||
if (username)
|
||||
{
|
||||
strcat(conninfo, " user='");
|
||||
strcat(conninfo, username);
|
||||
strcat(conninfo, "'");
|
||||
}
|
||||
if (password) {
|
||||
if (password)
|
||||
{
|
||||
strcat(conninfo, " password='");
|
||||
strcat(conninfo, password);
|
||||
strcat(conninfo, "'");
|
||||
}
|
||||
if (host) {
|
||||
if (host)
|
||||
{
|
||||
strcat(conninfo, " host='");
|
||||
strcat(conninfo, host);
|
||||
strcat(conninfo, "'");
|
||||
}
|
||||
if (port) {
|
||||
if (port)
|
||||
{
|
||||
strcat(conninfo, " port='");
|
||||
strcat(conninfo, port);
|
||||
strcat(conninfo, "'");
|
||||
|
||||
@@ -107,7 +107,7 @@ simple_prompt(const char *prompt, int maxlen, int echo)
|
||||
|| (getenv("OSTYPE") && strcmp(getenv("OSTYPE"), "msys") == 0)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
{
|
||||
if (termin)
|
||||
fclose(termin);
|
||||
if (termout)
|
||||
@@ -162,7 +162,8 @@ simple_prompt(const char *prompt, int maxlen, int echo)
|
||||
if (fgets(buf, sizeof(buf), termin) == NULL)
|
||||
break;
|
||||
buflen = strlen(buf);
|
||||
} while (buflen > 0 && buf[buflen - 1] != '\n');
|
||||
}
|
||||
while (buflen > 0 && buf[buflen - 1] != '\n');
|
||||
}
|
||||
|
||||
if (length > 0 && destination[length - 1] == '\n')
|
||||
|
||||
Reference in New Issue
Block a user