From 922411b27af99ab95996c3a0045e8a4b941dc811 Mon Sep 17 00:00:00 2001 From: Peter Date: Mon, 23 May 2011 10:31:24 +0200 Subject: [PATCH] mockup for outlining tool --- tools/.gitignore | 1 + tools/Makefile | 17 +++++++++++++ tools/osmpbf-outline.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 tools/.gitignore create mode 100644 tools/Makefile create mode 100644 tools/osmpbf-outline.cpp diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 0000000..3235067 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1 @@ +osmpbf-outline diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..771ef9c --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,17 @@ + +CXX = g++ +CXXFLAGS = -O3 +LDFLAGS = -lpthread +LIB_PROTOBUF = -lz -lprotobuf-lite -losmpbf + +all: osmpbf-outline + +osmpbf-outline: osmpbf-outline.cpp + $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) + +install: + install -m 755 -g root -o root -d $(DESTDIR)/usr/bin + install -m 644 -g root -o root osmpbf-outline $(DESTDIR)/usr/bin + +clean: + rm -f osmpbf-outline diff --git a/tools/osmpbf-outline.cpp b/tools/osmpbf-outline.cpp new file mode 100644 index 0000000..74dfff2 --- /dev/null +++ b/tools/osmpbf-outline.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +bool is_a_tty; + +void msg(const char* format, int color, va_list args) { + if(is_a_tty) fprintf(stderr, "\x1b[0;%dm", color); + + vfprintf(stderr, format, args); + + if(is_a_tty) fprintf(stderr, "\x1b[0m\n"); + else fprintf(stderr, "\n"); +} + +void err(const char* format, ...) { + va_list args; + va_start(args, format); + msg(format, 31, args); + va_end(args); + exit(1); +} + +void warn(const char* format, ...) { + va_list args; + va_start(args, format); + msg(format, 33, args); + va_end(args); +} + +void info(const char* format, ...) { + va_list args; + va_start(args, format); + msg(format, 37, args); + va_end(args); +} + +int main(int argc, char *argv[]) { + if(isatty(2)) { + is_a_tty = true; + } + + if(argc != 2) + err("usage: %s file.osm.pbf", argv[0]); + + FILE *fp = fopen(argv[1], "r"); + + + fclose(fp); + google::protobuf::ShutdownProtobufLibrary(); +}