From b26a2b1002beecae7901c7842613d9db43cd53da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Thu, 20 Jul 2023 10:34:46 +0200 Subject: [PATCH 1/5] CLI: add --version long argument to return PROJ version --- src/apps/proj.cpp | 5 +++++ src/proj_internal.h | 1 + src/release.cpp | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index d5afaa4909..8e9037b5d8 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -496,6 +496,11 @@ int main(int argc, char **argv) { case 's': /* reverse output */ reverseout = 1; continue; + case '-': /* long option */ + if (strcmp(*argv, "--version") == 0) { + (void)printf("%s\n", pj_get_version()); + exit(0); + } default: emess(1, "invalid option: -%c", *arg); break; diff --git a/src/proj_internal.h b/src/proj_internal.h index 55abb8c115..f303a75f9a 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -1004,6 +1004,7 @@ int pj_has_inverse(PJ *); char *pj_strdup(const char *str); const char PROJ_DLL *pj_get_release(void); +const char PROJ_DLL *pj_get_version(void); void pj_acquire_lock(void); void pj_release_lock(void); diff --git a/src/release.cpp b/src/release.cpp index 5742f3b6a3..db28ecfbe9 100644 --- a/src/release.cpp +++ b/src/release.cpp @@ -6,6 +6,11 @@ #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) +char const pj_version[] = STR(PROJ_VERSION_MAJOR) "." STR( + PROJ_VERSION_MINOR) "." STR(PROJ_VERSION_PATCH); + +const char *pj_get_version() { return pj_version; } + char const pj_release[] = "Rel. " STR(PROJ_VERSION_MAJOR) "." STR( PROJ_VERSION_MINOR) "." STR(PROJ_VERSION_PATCH) ", " "September 1st, 2023"; From c6980a903a8d96b4ba960ed6a21e6e4635c89a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Thu, 20 Jul 2023 10:43:27 +0200 Subject: [PATCH 2/5] fix error message for 'long argument' --- src/apps/proj.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index 8e9037b5d8..c8a6372cfd 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -501,6 +501,10 @@ int main(int argc, char **argv) { (void)printf("%s\n", pj_get_version()); exit(0); } + else { + emess(1, "invalid option: %s", *argv); + break; + } default: emess(1, "invalid option: -%c", *arg); break; From 6320f57dd459c7c55c6d19d71c812ecceb489a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Mon, 24 Jul 2023 16:12:45 +0200 Subject: [PATCH 3/5] add version argument and harmonize apps --- src/apps/bin_projinfo.cmake | 2 +- src/apps/bin_projsync.cmake | 2 +- src/apps/cct.cpp | 5 +++-- src/apps/cs2cs.cpp | 5 ++++- src/apps/geod.cpp | 9 +++++++++ src/apps/gie.cpp | 7 ++++--- src/apps/proj.cpp | 2 +- src/apps/projinfo.cpp | 13 ++++++++++++- src/apps/projsync.cpp | 16 +++++++++++++++- 9 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/apps/bin_projinfo.cmake b/src/apps/bin_projinfo.cmake index 6bd6355ad4..e2ac2ec7b1 100644 --- a/src/apps/bin_projinfo.cmake +++ b/src/apps/bin_projinfo.cmake @@ -1,4 +1,4 @@ -set(PROJINFO_SRC projinfo.cpp) +set(PROJINFO_SRC projinfo.cpp emess.cpp) source_group("Source Files\\Bin" FILES ${PROJINFO_SRC}) diff --git a/src/apps/bin_projsync.cmake b/src/apps/bin_projsync.cmake index 3f24fb398b..43d1c2bc2a 100644 --- a/src/apps/bin_projsync.cmake +++ b/src/apps/bin_projsync.cmake @@ -1,4 +1,4 @@ -set(PROJSYNC_SRC projsync.cpp) +set(PROJSYNC_SRC projsync.cpp emess.cpp) source_group("Source Files\\Bin" FILES ${PROJSYNC_SRC}) diff --git a/src/apps/cct.cpp b/src/apps/cct.cpp index 0d9c6a6d7b..9818c8a305 100644 --- a/src/apps/cct.cpp +++ b/src/apps/cct.cpp @@ -133,7 +133,7 @@ static const char usage[] = { " --inverse Alias for -I\n" " --skip-lines Alias for -s\n" " --help Alias for -h\n" - " --version Print version number\n" + " --version Print version\n" "--------------------------------------------------------------------------" "------\n" "Operator Specs:\n" @@ -255,7 +255,8 @@ int main(int argc, char **argv) { proj_log_func(PJ_DEFAULT_CTX, (void *)fout, logger); if (opt_given(o, "version")) { - print(PJ_LOG_NONE, "%s: %s", o->progname, pj_get_release()); + fprintf(stdout, "%s: %s\n", o->progname, pj_get_version()); + free(o); return 0; } diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp index d4485fbe5b..100b4d3fa8 100644 --- a/src/apps/cs2cs.cpp +++ b/src/apps/cs2cs.cpp @@ -428,7 +428,10 @@ int main(int argc, char **argv) { /* process run line arguments */ while (--argc > 0) { /* collect run line arguments */ ++argv; - if (strcmp(*argv, "--area") == 0) { + if (strcmp(*argv, "--version") == 0) { + (void)fprintf(stdout, "%s: %s\n", emess_dat.Prog_name, pj_get_version()); + exit(0); + } else if (strcmp(*argv, "--area") == 0) { ++argv; --argc; if (argc == 0) { diff --git a/src/apps/geod.cpp b/src/apps/geod.cpp index f5fd960f0a..431c2ef314 100644 --- a/src/apps/geod.cpp +++ b/src/apps/geod.cpp @@ -235,6 +235,15 @@ int main(int argc, char **argv) { case 'p': /* output azimuths as positive */ pos_azi = 1; continue; + case '-': /* long option */ + if (strcmp(*argv, "--version") == 0) { + (void)fprintf(stdout, "%s: %s\n", emess_dat.Prog_name, pj_get_version()); + exit(0); + } + else { + emess(1, "invalid option: %s", *argv); + break; + } default: emess(1, "invalid option: -%c", *arg); break; diff --git a/src/apps/gie.cpp b/src/apps/gie.cpp index 42b70f179b..fee56509b5 100644 --- a/src/apps/gie.cpp +++ b/src/apps/gie.cpp @@ -249,7 +249,7 @@ static const char usage[] = { " --verbose Alias for -v\n" " --help Alias for -h\n" " --list Alias for -l\n" - " --version Print version number\n" + " --version Print version\n" "--------------------------------------------------------------------------" "------\n" "Examples:\n" @@ -267,7 +267,8 @@ static const char usage[] = { int main(int argc, char **argv) { int i; const char *longflags[] = {"v=verbose", "q=quiet", "h=help", - "l=list", "version", nullptr}; + "l=list", "version", + nullptr}; const char *longkeys[] = {"o=output", nullptr}; OPTARGS *o; @@ -290,7 +291,7 @@ int main(int argc, char **argv) { } if (opt_given(o, "version")) { - fprintf(stdout, "%s: %s\n", o->progname, pj_get_release()); + fprintf(stdout, "%s: %s\n", o->progname, pj_get_version()); free(o); return 0; } diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index c8a6372cfd..df26d94121 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -498,7 +498,7 @@ int main(int argc, char **argv) { continue; case '-': /* long option */ if (strcmp(*argv, "--version") == 0) { - (void)printf("%s\n", pj_get_version()); + (void)fprintf(stdout, "%s: %s\n", emess_dat.Prog_name, pj_get_version()); exit(0); } else { diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index d076237518..3fdf6575cc 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -38,6 +38,7 @@ #include "proj.h" #include "proj_internal.h" +#include "emess.h" #include #include @@ -1016,6 +1017,11 @@ int main(int argc, char **argv) { std::cerr << pj_get_release() << std::endl; usage(); } + + if ((emess_dat.Prog_name = strrchr(*argv, '/')) != nullptr) + ++emess_dat.Prog_name; + else + emess_dat.Prog_name = *argv; std::string user_string; bool user_string_specified = false; @@ -1058,7 +1064,12 @@ int main(int argc, char **argv) { for (int i = 1; i < argc; i++) { std::string arg(argv[i]); - if (arg == "-o" && i + 1 < argc) { + if (arg == "--version") + { + std::cout << emess_dat.Prog_name << ": " << pj_get_version() << std::endl; + std::exit(0); + } + else if (arg == "-o" && i + 1 < argc) { outputSwitchSpecified = true; i++; const auto formats(split(argv[i], ',')); diff --git a/src/apps/projsync.cpp b/src/apps/projsync.cpp index deb07039a5..83535d368b 100644 --- a/src/apps/projsync.cpp +++ b/src/apps/projsync.cpp @@ -38,6 +38,7 @@ #include "filemanager.hpp" #include "proj.h" #include "proj_internal.h" +#include "emess.h" #include "proj/internal/include_nlohmann_json.hpp" #include "proj/internal/internal.hpp" @@ -75,6 +76,9 @@ class ParsingException : public std::exception { std::cerr << " [--quiet | --verbose] [--dry-run] [--list-files]" << std::endl; std::cerr << " [--no-version-filtering]" << std::endl; + std::cerr << " [--version]" << std::endl; + std::cerr << " [--release]" << std::endl; + std::cerr << " [--short-version]" << std::endl; std::exit(1); } @@ -115,6 +119,11 @@ int main(int argc, char *argv[]) { auto ctx = pj_get_default_ctx(); + if ((emess_dat.Prog_name = strrchr(*argv, '/')) != nullptr) + ++emess_dat.Prog_name; + else + emess_dat.Prog_name = *argv; + std::string targetDir; std::string endpoint(proj_context_get_url_endpoint(ctx)); const std::string geojsonFile("files.geojson"); @@ -138,7 +147,12 @@ int main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { std::string arg(argv[i]); - if (arg == "--endpoint" && i + 1 < argc) { + if (arg == "--version") + { + std::cout << emess_dat.Prog_name << ": " << pj_get_version() << std::endl; + std::exit(0); + } + else if (arg == "--endpoint" && i + 1 < argc) { i++; endpoint = argv[i]; } else if (arg == "--user-writable-directory") { From aff325074861f235ea7725e4fd117d33e427cba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Mon, 24 Jul 2023 16:21:23 +0200 Subject: [PATCH 4/5] 4D_api: Use pg_get_version() --- src/4D_api.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/4D_api.cpp b/src/4D_api.cpp index ece2ef5bf5..3b73f97793 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -2546,7 +2546,6 @@ static char *path_append(char *buf, const char *app, size_t *buf_size) { } static const char *empty = {""}; -static char version[64] = {""}; static PJ_INFO info = {0, 0, 0, nullptr, nullptr, nullptr, nullptr, 0}; /*****************************************************************************/ @@ -2565,12 +2564,7 @@ PJ_INFO proj_info(void) { info.minor = PROJ_VERSION_MINOR; info.patch = PROJ_VERSION_PATCH; - /* A normal version string is xx.yy.zz which is 8 characters - long and there is room for 64 bytes in the version string. */ - snprintf(version, sizeof(version), "%d.%d.%d", info.major, info.minor, - info.patch); - - info.version = version; + info.version = pj_get_version(); info.release = pj_get_release(); /* build search path string */ From 7e142050f2b2746e2c1c44ea29ac2c2d963b93a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bartoletti?= Date: Mon, 24 Jul 2023 16:33:24 +0200 Subject: [PATCH 5/5] scripts/reference_exported_symbols.txt: add pj_get_version() --- scripts/reference_exported_symbols.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index f9e94e1c58..3445a35e23 100644 --- a/scripts/reference_exported_symbols.txt +++ b/scripts/reference_exported_symbols.txt @@ -813,6 +813,7 @@ pj_get_default_ctx() pj_get_default_searchpaths(pj_ctx*) pj_get_relative_share_proj(pj_ctx*) pj_get_release() +pj_get_version() pj_inv(PJ_XY, PJconsts*) pj_mkparam(char const*) pj_param_exists(ARG_list*, char const*)