diff --git a/src/apps/cs2cs.cpp b/src/apps/cs2cs.cpp index 6c85d4aa44..affd2bec07 100644 --- a/src/apps/cs2cs.cpp +++ b/src/apps/cs2cs.cpp @@ -425,11 +425,18 @@ int main(int argc, char **argv) { (void)printf("%9s %-16s %-16s %s\n", le->id, le->major, le->ell, le->name); } else if (arg[1] == 'u') { /* list units */ - const struct PJ_UNITS *lu; - - for (lu = proj_list_units(); lu->id; ++lu) - (void)printf("%12s %-20s %s\n", lu->id, - lu->to_meter, lu->name); + auto units = proj_get_units_from_database(nullptr, nullptr, "linear", false, nullptr); + for( int i = 0; units && units[i]; i++ ) + { + if( units[i]->proj_short_name ) + { + (void)printf("%12s %-20.15g %s\n", + units[i]->proj_short_name, + units[i]->conv_factor, + units[i]->name); + } + } + proj_unit_list_destroy(units); } else if (arg[1] == 'm') { /* list prime meridians */ const struct PJ_PRIME_MERIDIANS *lpm; diff --git a/src/apps/geod.cpp b/src/apps/geod.cpp index b46188d32f..919430ca97 100644 --- a/src/apps/geod.cpp +++ b/src/apps/geod.cpp @@ -185,11 +185,18 @@ noargument: emess(1,"missing argument for -%c",*arg); (void)printf("%9s %-16s %-16s %s\n", le->id, le->major, le->ell, le->name); } else if (arg[1] == 'u') { /* list of units */ - const struct PJ_UNITS *lu; - - for (lu = proj_list_units();lu->id ; ++lu) - (void)printf("%12s %-20s %s\n", - lu->id, lu->to_meter, lu->name); + auto units = proj_get_units_from_database(nullptr, nullptr, "linear", false, nullptr); + for( int i = 0; units && units[i]; i++ ) + { + if( units[i]->proj_short_name ) + { + (void)printf("%12s %-20.15g %s\n", + units[i]->proj_short_name, + units[i]->conv_factor, + units[i]->name); + } + } + proj_unit_list_destroy(units); } else emess(1,"invalid list option: l%c",arg[1]); exit( 0 ); diff --git a/src/apps/geod_set.cpp b/src/apps/geod_set.cpp index ed7edeb972..603f0d95ba 100644 --- a/src/apps/geod_set.cpp +++ b/src/apps/geod_set.cpp @@ -14,7 +14,6 @@ geod_set(int argc, char **argv) { paralist *start = nullptr, *curr; double es; char *name; - int i; /* put arguments into internal linked list */ if (argc <= 0) @@ -22,7 +21,7 @@ geod_set(int argc, char **argv) { start = curr = pj_mkparam(argv[0]); if (!curr) emess(1, "memory allocation failed"); - for (i = 1; curr != nullptr && i < argc; ++i) { + for (int i = 1; curr != nullptr && i < argc; ++i) { curr->next = pj_mkparam(argv[i]); if (!curr->next) emess(1, "memory allocation failed"); @@ -32,13 +31,20 @@ geod_set(int argc, char **argv) { if (pj_ell_set(pj_get_default_ctx(),start, &geod_a, &es)) emess(1,"ellipse setup failure"); /* set units */ if ((name = pj_param(nullptr,start, "sunits").s) != nullptr) { - const char *s; - const struct PJ_UNITS *unit_list = proj_list_units(); - for (i = 0; (s = unit_list[i].id) && strcmp(name, s) ; ++i) ; - if (!s) - emess(1,"%s unknown unit conversion id", name); - to_meter = unit_list[i].factor; - fr_meter = 1 / to_meter; + bool unit_found = false; + auto units = proj_get_units_from_database(nullptr, nullptr, "linear", false, nullptr); + for( int i = 0; units && units[i]; i++ ) + { + if( units[i]->proj_short_name && + strcmp(units[i]->proj_short_name, name) == 0 ) { + unit_found = true; + to_meter = units[i]->conv_factor; + fr_meter = 1 / to_meter; + } + } + proj_unit_list_destroy(units); + if( !unit_found ) + emess(1,"%s unknown unit conversion id", name); } else to_meter = fr_meter = 1; geod_f = es/(1 + sqrt(1 - es)); diff --git a/src/apps/proj.cpp b/src/apps/proj.cpp index 852cea0436..0bf98b3a9f 100644 --- a/src/apps/proj.cpp +++ b/src/apps/proj.cpp @@ -380,11 +380,18 @@ int main(int argc, char **argv) { (void)printf("%9s %-16s %-16s %s\n", le->id, le->major, le->ell, le->name); } else if (arg[1] == 'u') { /* list units */ - const struct PJ_UNITS *lu; - - for (lu = proj_list_units(); lu->id ; ++lu) - (void)printf("%12s %-20s %s\n", - lu->id, lu->to_meter, lu->name); + auto units = proj_get_units_from_database(nullptr, nullptr, "linear", false, nullptr); + for( int i = 0; units && units[i]; i++ ) + { + if( units[i]->proj_short_name ) + { + (void)printf("%12s %-20.15g %s\n", + units[i]->proj_short_name, + units[i]->conv_factor, + units[i]->name); + } + } + proj_unit_list_destroy(units); } else emess(1,"invalid list option: l%c",arg[1]); exit(0); diff --git a/src/conversions/unitconvert.cpp b/src/conversions/unitconvert.cpp index f8439aeeb9..6ce55b0220 100644 --- a/src/conversions/unitconvert.cpp +++ b/src/conversions/unitconvert.cpp @@ -393,9 +393,7 @@ static double get_unit_conversion_factor(const char* name, /***********************************************************************/ int i; const char* s; - const PJ_UNITS *units; - - units = proj_list_units(); + const PJ_UNITS *units = pj_list_linear_units(); /* Try first with linear units */ for (i = 0; (s = units[i].id) ; ++i) { diff --git a/src/init.cpp b/src/init.cpp index a25d1ccda8..101fc8ad5d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -738,7 +738,7 @@ pj_init_ctx_with_allow_init_epsg(projCtx ctx, int argc, char **argv, int allow_i return pj_default_destructor (PIN, PJD_ERR_K_LESS_THAN_ZERO); /* Set units */ - units = proj_list_units(); + units = pj_list_linear_units(); s = nullptr; if ((name = pj_param(ctx, start, "sunits").s) != nullptr) { for (i = 0; (s = units[i].id) && strcmp(name, s) ; ++i) ; diff --git a/src/iso19111/common.cpp b/src/iso19111/common.cpp index f2e4de4c8a..4606905b7d 100644 --- a/src/iso19111/common.cpp +++ b/src/iso19111/common.cpp @@ -39,6 +39,7 @@ #include "proj/internal/io_internal.hpp" #include "proj.h" +#include "proj_internal.h" #include // M_PI #include @@ -312,7 +313,7 @@ bool UnitOfMeasure::operator!=(const UnitOfMeasure &other) PROJ_PURE_DEFN { //! @cond Doxygen_Suppress std::string UnitOfMeasure::exportToPROJString() const { if (type() == Type::LINEAR) { - auto proj_units = proj_list_units(); + auto proj_units = pj_list_linear_units(); for (int i = 0; proj_units[i].id != nullptr; i++) { if (::fabs(proj_units[i].factor - conversionToSI()) < 1e-10 * conversionToSI()) { diff --git a/src/proj.h b/src/proj.h index 8f48217fb1..69aae6d85c 100644 --- a/src/proj.h +++ b/src/proj.h @@ -151,6 +151,24 @@ extern "C" { #endif #endif +#ifdef PROJ_SUPPRESS_DEPRECATION_MESSAGE + #define PROJ_DEPRECATED(decl, msg) decl +#elif defined(__has_extension) + #if __has_extension(attribute_deprecated_with_message) + #define PROJ_DEPRECATED(decl, msg) decl __attribute__ ((deprecated(msg))) + #elif defined(__GNUC__) + #define PROJ_DEPRECATED(decl, msg) decl __attribute__ ((deprecated)) + #else + #define PROJ_DEPRECATED(decl, msg) decl + #endif +#elif defined(__GNUC__) + #define PROJ_DEPRECATED(decl, msg) decl __attribute__ ((deprecated)) +#elif defined(_MSVC_VER) + #define PROJ_DEPRECATED(decl, msg) __declspec(deprecated(msg)) decl +#else + #define PROJ_DEPRECATED(decl, msg) decl +#endif + /* The version numbers should be updated with every release! **/ #define PROJ_VERSION_MAJOR 7 #define PROJ_VERSION_MINOR 1 @@ -608,7 +626,7 @@ PJ_INIT_INFO PROJ_DLL proj_init_info(const char *initname); /* Get lists of operations, ellipsoids, units and prime meridians. */ const PJ_OPERATIONS PROJ_DLL *proj_list_operations(void); const PJ_ELLPS PROJ_DLL *proj_list_ellps(void); -const PJ_UNITS PROJ_DLL *proj_list_units(void); +PROJ_DEPRECATED(const PJ_UNITS PROJ_DLL *proj_list_units(void), "Deprecated by proj_get_units_from_database"); const PJ_UNITS PROJ_DLL *proj_list_angular_units(void); const PJ_PRIME_MERIDIANS PROJ_DLL *proj_list_prime_meridians(void); diff --git a/src/proj_internal.h b/src/proj_internal.h index 8f73200d6f..78aff49f60 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -873,6 +873,8 @@ std::string PROJ_DLL pj_context_get_user_writable_directory(PJ_CONTEXT *ctx, boo void PROJ_DLL pj_context_set_user_writable_directory(PJ_CONTEXT* ctx, const std::string& path); std::string PROJ_DLL pj_get_relative_share_proj(PJ_CONTEXT *ctx); +const PJ_UNITS *pj_list_linear_units(); + /* classic public API */ #include "proj_api.h" diff --git a/src/units.cpp b/src/units.cpp index 34a71db13f..36f2d4c72d 100644 --- a/src/units.cpp +++ b/src/units.cpp @@ -36,6 +36,12 @@ pj_units[] = { {nullptr, nullptr, nullptr, 0.0} }; +// For internal use +const PJ_UNITS *pj_list_linear_units() +{ + return pj_units; +} + const PJ_UNITS *proj_list_units() { return pj_units; diff --git a/test/unit/gie_self_tests.cpp b/test/unit/gie_self_tests.cpp index 720c13caab..6f1b3c3249 100644 --- a/test/unit/gie_self_tests.cpp +++ b/test/unit/gie_self_tests.cpp @@ -334,7 +334,6 @@ TEST(gie, info_functions) { const PJ_OPERATIONS *oper_list; const PJ_ELLPS *ellps_list; - const PJ_UNITS *unit_list; const PJ_PRIME_MERIDIANS *pm_list; char buf[40]; @@ -452,11 +451,6 @@ TEST(gie, info_functions) { n++; ASSERT_NE(n, 0U); - n = 0; - for (unit_list = proj_list_units(); unit_list->id; ++unit_list) - n++; - ASSERT_NE(n, 0U); - n = 0; for (pm_list = proj_list_prime_meridians(); pm_list->id; ++pm_list) n++;