[sosi2osm] 22/30: Fixed hard-to-find lua files and added Makefile targets
Ruben Undheim
rubund-guest at moszumanska.debian.org
Sat Oct 4 13:07:56 UTC 2014
This is an automated email from the git hooks/post-receive script.
rubund-guest pushed a commit to branch upstream
in repository sosi2osm.
commit 7d8b07b6bf51e4f3ad1835a8e7a426eb3d1f4017
Author: Ruben Undheim <ruben.undheim at gmail.com>
Date: Mon Jul 7 17:23:29 2014 +0200
Fixed hard-to-find lua files and added Makefile targets
sosi2osm now looks for .lua files in /usr/local/share/sosi2osm/lua
and /usr/share/sosi2osm/lua if it cannot find the file in
./lua. This means that it is now possible to run sosi2osm from
wherever.
New Makefile target: install - installs binary and lua files to
/usr/local/..
New Makefile target: uninstall - removes all the files and folders
installed by install.
It looks for header files for libfyba also in /usr/include/.. now.
---
Makefile | 15 ++++++++++-
sosi2osm.cpp | 2 +-
tag.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 87 insertions(+), 13 deletions(-)
diff --git a/Makefile b/Makefile
index d85e779..cccb057 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
PROGNAME=sosi2osm
OBJFILES=sosi2osm.o sosi.o tag.o node.o
-CPPFLAGS = -I /usr/local/include/fyba/ `pkg-config --cflags lua5.1-c++` -DLINUX -DUNIX -g
+CPPFLAGS = -I/usr/local/include/fyba -I/usr/include/fyba/ `pkg-config --cflags lua5.1-c++` -DLINUX -DUNIX -g
LDFLAGS = -lfyba -lfygm -lfyut -lproj `pkg-config --libs lua5.1-c++`
all: $(PROGNAME)
@@ -11,3 +11,16 @@ clean:
$(PROGNAME): $(OBJFILES)
$(CXX) $^ $(LDFLAGS) -o $@
+
+install: sosi2osm
+ install -m 0755 sosi2osm /usr/local/bin
+ mkdir -p /usr/local/share/sosi2osm/lua
+ install -m 0644 lua/*.lua /usr/local/share/sosi2osm/lua
+
+uninstall:
+ rm /usr/local/share/sosi2osm/lua/*.lua
+ rmdir /usr/local/share/sosi2osm/lua
+ rmdir /usr/local/share/sosi2osm
+ rm /usr/local/bin/sosi2osm
+
+.PHONY: install uninstall clean all
diff --git a/sosi2osm.cpp b/sosi2osm.cpp
index 0b563d1..25a2049 100644
--- a/sosi2osm.cpp
+++ b/sosi2osm.cpp
@@ -6,7 +6,7 @@
char* execname;
void usage() {
- printf("Usage: sosi2osm [sosi file] [lua file]\n");
+ fprintf(stderr,"Usage: sosi2osm [sosi file] [lua file]\n");
}
void handleHead() {
diff --git a/tag.cpp b/tag.cpp
index 9f22308..b45ce3e 100644
--- a/tag.cpp
+++ b/tag.cpp
@@ -33,23 +33,84 @@ char* toUTF8(char* in, char* outBuf, size_t outlen) {
lua_State *state;
void loadLua(char* filename) {
+ FILE *file_exist_check;
+ int r;
state = luaL_newstate();
luaL_openlibs(state);
- char library_filename[256];
- snprintf(library_filename, 256, "%s/lua/sosi2osm.lua", dirname(execname));
-
- int r = luaL_loadfile(state, library_filename);
- if (r) {
- fprintf(stderr, "Failed to load lua library file %s\n", library_filename);
- exit(1);
+ char filename_string[256];
+ snprintf(filename_string, 256, "%s/lua/sosi2osm.lua", dirname(execname));
+ if(file_exist_check = fopen(filename_string, "r")){
+ fclose(file_exist_check);
+ r = luaL_loadfile(state, filename_string);
+ if (r) {
+ fprintf(stderr, "Failed to load lua library file %s\n", filename_string);
+ exit(1);
+ }
+ }
+ else {
+ snprintf(filename_string, 256, "/usr/local/share/sosi2osm/lua/sosi2osm.lua");
+ if(file_exist_check = fopen(filename_string, "r")){
+ fclose(file_exist_check);
+ r = luaL_loadfile(state, filename_string);
+ if (r) {
+ fprintf(stderr, "Failed to load lua library file %s\n", filename_string);
+ exit(1);
+ }
+ }
+ else {
+ snprintf(filename_string, 256, "/usr/share/sosi2osm/lua/sosi2osm.lua");
+ if(file_exist_check = fopen(filename_string, "r")){
+ fclose(file_exist_check);
+ r = luaL_loadfile(state, filename_string);
+ if (r) {
+ fprintf(stderr, "Failed to load lua library file %s\n", filename_string);
+ exit(1);
+ }
+
+ }
+ else {
+ fprintf(stderr, "Could not find sosi2osm.lua. It has to be installed in /usr/share/sosi2osm/lua/ or /usr/local/share/sosi2osm/lua/\n");
+ exit(1);
+ }
+ }
}
+
lua_call(state, 0, 0);
- r = luaL_loadfile(state, filename);
- if (r) {
- fprintf(stderr, "Failed to load lua file %s\n", filename);
- exit(1);
+ if(file_exist_check = fopen(filename, "r")) {
+ fclose(file_exist_check);
+ r = luaL_loadfile(state, filename);
+ if (r) {
+ fprintf(stderr, "Failed to load lua file %s\n", filename);
+ exit(1);
+ }
+ }
+ else {
+ snprintf(filename_string, 256, "/usr/local/share/sosi2osm/lua/%s",filename);
+ if(file_exist_check = fopen(filename_string, "r")) {
+ fclose(file_exist_check);
+ r = luaL_loadfile(state, filename_string);
+ if (r) {
+ fprintf(stderr, "Failed to load lua file %s\n", filename_string);
+ exit(1);
+ }
+ }
+ else {
+ snprintf(filename_string, 256, "/usr/share/sosi2osm/lua/%s",filename);
+ if(file_exist_check = fopen(filename_string, "r")) {
+ fclose(file_exist_check);
+ r = luaL_loadfile(state, filename_string);
+ if(r) {
+ fprintf(stderr, "Failed to load lua file %s\n", filename_string);
+ exit(1);
+ }
+ }
+ else {
+ fprintf(stderr, "Could not find %s. It has to be installed in /usr/share/sosi2osm/lua/ or /usr/local/share/sosi2osm/lua/\n",filename);
+ exit(1);
+ }
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/sosi2osm.git
More information about the Pkg-grass-devel
mailing list