clean up formatting

This commit is contained in:
Brian Quinion
2010-12-10 16:13:07 +00:00
parent 1427753846
commit 52cdaba0f1
9 changed files with 1144 additions and 1074 deletions

View File

@@ -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);
}

View File

@@ -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;
@@ -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;
}

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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,7 +191,8 @@ int main(int argc, char *argv[])
}
}
if (long_usage_bool) {
if (long_usage_bool)
{
long_usage(argv[0]);
exit(EXIT_FAILURE);
}
@@ -174,21 +205,24 @@ int main(int argc, char *argv[])
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);
}

View File

@@ -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 */

View File

@@ -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, "'");

View File

@@ -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')