Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: add --version long argument to return PROJ version #3836

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/reference_exported_symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
Expand Down
8 changes: 1 addition & 7 deletions src/4D_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};

/*****************************************************************************/
Expand All @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/apps/bin_projinfo.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(PROJINFO_SRC projinfo.cpp)
set(PROJINFO_SRC projinfo.cpp emess.cpp)

source_group("Source Files\\Bin" FILES ${PROJINFO_SRC})

Expand Down
2 changes: 1 addition & 1 deletion src/apps/bin_projsync.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(PROJSYNC_SRC projsync.cpp)
set(PROJSYNC_SRC projsync.cpp emess.cpp)

source_group("Source Files\\Bin" FILES ${PROJSYNC_SRC})

Expand Down
5 changes: 3 additions & 2 deletions src/apps/cct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion src/apps/cs2cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/apps/geod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/apps/gie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;

Expand All @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions src/apps/proj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,15 @@ int main(int argc, char **argv) {
case 's': /* reverse output */
reverseout = 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;
Expand Down
13 changes: 12 additions & 1 deletion src/apps/projinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include "proj.h"
#include "proj_internal.h"
#include "emess.h"

#include <proj/common.hpp>
#include <proj/coordinateoperation.hpp>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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], ','));
Expand Down
16 changes: 15 additions & 1 deletion src/apps/projsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand All @@ -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") {
Expand Down
1 change: 1 addition & 0 deletions src/proj_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions src/release.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading