aboutsummaryrefslogtreecommitdiff
path: root/src/cs2cs.c
diff options
context:
space:
mode:
authorAaron Puchert <aaron.puchert@sap.com>2017-11-17 17:46:34 +0100
committerAaron Puchert <aaronpuchert@alice-dsl.net>2017-12-17 23:34:40 +0100
commita07501a165e6f2521c9aa13fa63fab33cf67d876 (patch)
tree846a2df69948cb6d4927c0c8d5b953786df5cb04 /src/cs2cs.c
parent95f8e749e712218ca49e4025fe6ab59ddf991c60 (diff)
downloadPROJ-a07501a165e6f2521c9aa13fa63fab33cf67d876.tar.gz
PROJ-a07501a165e6f2521c9aa13fa63fab33cf67d876.zip
Declare non-local variables as const where possible
Having non-const variables of static lifetime or even global scope is usually a bad idea. These variables are inherently constants, and this should be enforced. This required marking some functions as not modifying input parameters and marking some pointers as pointers to const. One advantage is that the compiler usually puts const static variables in a read-only code segment, so they can't be modified physically. This can be verified with `nm` (on POSIX systems). To avoid changes to the public API, functions returning non-const pointers to data tables were left intact, but the returned data may not be modified. Internally we prefer using the proj_list_* functions over the pj_get_*_ref functions, because the former return const pointers.
Diffstat (limited to 'src/cs2cs.c')
-rw-r--r--src/cs2cs.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/cs2cs.c b/src/cs2cs.c
index 7afeea73..730d37ee 100644
--- a/src/cs2cs.c
+++ b/src/cs2cs.c
@@ -26,6 +26,7 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
+#include "proj.h"
#include "projects.h"
#include <stdio.h>
#include <stdlib.h>
@@ -206,11 +207,11 @@ int main(int argc, char **argv)
case 'l': /* list projections, ellipses or units */
if (!arg[1] || arg[1] == 'p' || arg[1] == 'P') {
/* list projections */
- struct PJ_LIST *lp;
+ const struct PJ_LIST *lp;
int do_long = arg[1] == 'P', c;
char *str;
- for (lp = pj_get_list_ref() ; lp->id ; ++lp) {
+ for (lp = proj_list_operations() ; lp->id ; ++lp) {
(void)printf("%s : ", lp->id);
if (do_long) /* possibly multiline description */
(void)puts(*lp->descr);
@@ -222,28 +223,28 @@ int main(int argc, char **argv)
}
}
} else if (arg[1] == '=') { /* list projection 'descr' */
- struct PJ_LIST *lp;
+ const struct PJ_LIST *lp;
arg += 2;
- for (lp = pj_get_list_ref() ; lp->id ; ++lp)
+ for (lp = proj_list_operations() ; lp->id ; ++lp)
if (!strcmp(lp->id, arg)) {
(void)printf("%9s : %s\n", lp->id, *lp->descr);
break;
}
} else if (arg[1] == 'e') { /* list ellipses */
- struct PJ_ELLPS *le;
+ const struct PJ_ELLPS *le;
- for (le = pj_get_ellps_ref(); le->id ; ++le)
+ for (le = proj_list_ellps(); le->id ; ++le)
(void)printf("%9s %-16s %-16s %s\n",
le->id, le->major, le->ell, le->name);
} else if (arg[1] == 'u') { /* list units */
- struct PJ_UNITS *lu;
+ const struct PJ_UNITS *lu;
- for (lu = pj_get_units_ref(); lu->id ; ++lu)
+ for (lu = proj_list_units(); lu->id ; ++lu)
(void)printf("%12s %-20s %s\n",
lu->id, lu->to_meter, lu->name);
} else if (arg[1] == 'd') { /* list datums */
- struct PJ_DATUMS *ld;
+ const struct PJ_DATUMS *ld;
printf("__datum_id__ __ellipse___ __definition/comments______________________________\n" );
for (ld = pj_get_datums_ref(); ld->id ; ++ld)
@@ -254,9 +255,9 @@ int main(int argc, char **argv)
printf( "%25s %s\n", " ", ld->comments );
}
} else if( arg[1] == 'm') { /* list prime meridians */
- struct PJ_PRIME_MERIDIANS *lpm;
+ const struct PJ_PRIME_MERIDIANS *lpm;
- for (lpm = pj_get_prime_meridians_ref(); lpm->id ; ++lpm)
+ for (lpm = proj_list_prime_meridians(); lpm->id ; ++lpm)
(void)printf("%12s %-30s\n",
lpm->id, lpm->defn);
} else