This is an automated email from the git hooks/post-receive script. rubund-guest pushed a commit to branch upstream in repository sosi2osm.
commit b8107c908ca3d72c9fdccfd1891fa125f25a71f0 Author: Knut Karevoll <gnonth...@gmail.com> Date: Thu Oct 2 11:21:52 2014 +0200 Add optional output file --- node.cpp | 8 ++++---- sosi2osm.cpp | 47 ++++++++++++++++++++++++++++++----------------- sosi2osm.h | 4 ++-- tag.cpp | 4 ++-- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/node.cpp b/node.cpp index 21155fa..0b2df95 100644 --- a/node.cpp +++ b/node.cpp @@ -83,15 +83,15 @@ long int createNodes(long int** ids) { return size; } -void outputNode() { +void outputNode(FILE* output) { long int size; double *lat, *lon; getCoords(&size, &lat, &lon); for (int i = 0; i < size; i++) { - printf("<node id=\"%ld\" lat=\"%.7f\" lon=\"%.7f\" version=\"1\" visible=\"true\">\n", nodeId--, lat[i], lon[i]); - outputTags(); - printf("</node>\n"); + fprintf(output, "<node id=\"%ld\" lat=\"%.7f\" lon=\"%.7f\" version=\"1\" visible=\"true\">\n", nodeId--, lat[i], lon[i]); + outputTags(output); + fprintf(output, "</node>\n"); } free(lat); diff --git a/sosi2osm.cpp b/sosi2osm.cpp index 10ae604..e6d7bda 100644 --- a/sosi2osm.cpp +++ b/sosi2osm.cpp @@ -6,7 +6,7 @@ char* execname; void usage() { - fprintf(stderr,"Usage: sosi2osm [sosi file] [lua file]\n"); + fprintf(stderr,"Usage: sosi2osm <sosi file> <lua file> [output file]\n"); } void handleHead() { @@ -21,25 +21,25 @@ void handleHead() { } } -void outputWay() { +void outputWay(FILE* output) { long int* nd; long int size = createNodes(&nd); - printf("<way id=\"%ld\" version=\"1\" visible=\"true\">", -getSOSIId()); - outputTags(); + fprintf(output, "<way id=\"%ld\" version=\"1\" visible=\"true\">", -getSOSIId()); + outputTags(output); for (int i = 0; i < size; i++) { - printf("<nd ref=\"%ld\" />", nd[i]); + fprintf(output, "<nd ref=\"%ld\" />", nd[i]); } - printf("</way>\n"); + fprintf(output, "</way>\n"); free(nd); } -void outputRelation() { - printf("<relation id=\"%ld\" version=\"1\" visible=\"true\">", -getSOSIId()); - outputTags(); +void outputRelation(FILE* output) { + fprintf(output, "<relation id=\"%ld\" version=\"1\" visible=\"true\">", -getSOSIId()); + outputTags(output); bool outer = true; long refsLen = getSOSIRefsSize(); @@ -50,22 +50,34 @@ void outputRelation() { else if (refs[i] == SLUTT_OY) outer = true; else - printf("<member ref=\"%d\" role=\"%s\" type=\"way\"/>", -abs(refs[i]), outer?"outer":"inner"); + fprintf(output, "<member ref=\"%d\" role=\"%s\" type=\"way\"/>", -abs(refs[i]), outer?"outer":"inner"); } free(refs); - printf("</relation>\n"); + fprintf(output, "</relation>\n"); } int main(int argc, char** args) { - if (argc != 3) { + if (argc < 3 || argc > 4) { usage(); return 1; } execname = args[0]; char* input_filename = args[1]; + char* output_filename = "-"; + if (argc > 3) output_filename = args[3]; + + FILE* output; + if (strcmp(output_filename, "-") == 0) + output = stdout; + else + output = fopen(output_filename, "w"); + if (output == NULL) { + fprintf(stderr, "Could not open file for output '%s'\n", output_filename); + return 1; + } loadLua(args[2]); @@ -74,7 +86,7 @@ int main(int argc, char** args) { return 1; } - printf("<?xml version=\"1.0\"?>\n" + fprintf(output, "<?xml version=\"1.0\"?>\n" "<osm version=\"0.6\" upload=\"false\" generator=\"sosi2osm\">\n"); while (nextSOSIObject()) { @@ -84,24 +96,25 @@ int main(int argc, char** args) { handleHead(); break; case L_FLATE: - outputRelation(); + outputRelation(output); break; case L_PUNKT: case L_SYMBOL: case L_TEKST: - outputNode(); + outputNode(output); break; case L_KURVE: case L_LINJE: case L_BUEP: - outputWay(); + outputWay(output); break; } } - printf("</osm>\n"); + fprintf(output, "</osm>\n"); closeSOSI(); + fclose(output); return 0; } diff --git a/sosi2osm.h b/sosi2osm.h index a23bbcf..82f6aab 100644 --- a/sosi2osm.h +++ b/sosi2osm.h @@ -20,11 +20,11 @@ long getSOSIRefsSize(); extern char* execname; void setEncoding(char* encoding); void loadLua(char* filename); -void outputTags(); +void outputTags(FILE* output); // Node void setProjection(const char* proj); long int createNodes(long int** ids); -void outputNode(); +void outputNode(FILE* output); diff --git a/tag.cpp b/tag.cpp index b45ce3e..6fddc1d 100644 --- a/tag.cpp +++ b/tag.cpp @@ -117,7 +117,7 @@ void loadLua(char* filename) { lua_setglobal(state, "getTagsFromInfoTable"); } -void outputTags() { +void outputTags(FILE* output) { lua_getglobal(state, "getTagsFromInfoTable"); lua_newtable(state); int size = 0; @@ -144,7 +144,7 @@ void outputTags() { } const char* key = lua_tostring(state, -2); const char* value = lua_tostring(state, -1); - printf("<tag k=\"%s\" v=\"%s\"/>", key, value); + fprintf(output, "<tag k=\"%s\" v=\"%s\"/>", key, value); lua_pop(state, 1); } -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/sosi2osm.git _______________________________________________ Pkg-grass-devel mailing list Pkg-grass-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel