diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2018-12-18 22:02:44 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2018-12-26 10:08:54 +0100 |
| commit | 8198bb580a5640415e09b8fd3533ffaa11317ca6 (patch) | |
| tree | 61b68db0d946e19c3b71f590320babda05886510 /src | |
| parent | 8211f48b1ac6c941f46a8f2df90bdbfdcbc85981 (diff) | |
| download | PROJ-8198bb580a5640415e09b8fd3533ffaa11317ca6.tar.gz PROJ-8198bb580a5640415e09b8fd3533ffaa11317ca6.zip | |
cpp conversion: fix remaining warnings
Diffstat (limited to 'src')
| -rw-r--r-- | src/PJ_horner.cpp | 2 | ||||
| -rw-r--r-- | src/PJ_pipeline.cpp | 4 | ||||
| -rw-r--r-- | src/PJ_unitconvert.cpp | 6 | ||||
| -rw-r--r-- | src/emess.h | 10 | ||||
| -rw-r--r-- | src/gen_cheb.cpp | 42 | ||||
| -rw-r--r-- | src/geod.cpp | 18 | ||||
| -rw-r--r-- | src/geodesic.cpp | 36 | ||||
| -rw-r--r-- | src/gie.cpp | 4 | ||||
| -rw-r--r-- | src/optargpm.h | 12 | ||||
| -rw-r--r-- | src/pj_ell_set.cpp | 14 | ||||
| -rw-r--r-- | src/pj_errno.cpp | 2 | ||||
| -rw-r--r-- | src/pj_mutex.cpp | 2 | ||||
| -rw-r--r-- | src/proj.cpp | 17 | ||||
| -rw-r--r-- | src/proj_4D_api.cpp | 4 | ||||
| -rw-r--r-- | src/projects.h | 8 |
15 files changed, 103 insertions, 78 deletions
diff --git a/src/PJ_horner.cpp b/src/PJ_horner.cpp index 3a1b7cca..73977de6 100644 --- a/src/PJ_horner.cpp +++ b/src/PJ_horner.cpp @@ -408,7 +408,7 @@ static PJ *horner_freeup (PJ *P, int errlev) { /* Destruc } -static int parse_coefs (PJ *P, double *coefs, char *param, int ncoefs) { +static int parse_coefs (PJ *P, double *coefs, const char *param, int ncoefs) { char *buf, *init, *next = nullptr; int i; diff --git a/src/PJ_pipeline.cpp b/src/PJ_pipeline.cpp index 6d409690..76fc58a5 100644 --- a/src/PJ_pipeline.cpp +++ b/src/PJ_pipeline.cpp @@ -256,7 +256,7 @@ static size_t argc_params (paralist *params) { } /* Sentinel for argument list */ -static char *argv_sentinel = "step"; +static const char *argv_sentinel = "step"; /* turn paralist into argc/argv style argument list */ static char **argv_params (paralist *params, size_t argc) { @@ -267,7 +267,7 @@ static char **argv_params (paralist *params, size_t argc) { return nullptr; for (; params != nullptr; params = params->next) argv[i++] = params->param; - argv[i++] = argv_sentinel; + argv[i++] = const_cast<char*>(argv_sentinel); return argv; } diff --git a/src/PJ_unitconvert.cpp b/src/PJ_unitconvert.cpp index f7545680..b25fd5d2 100644 --- a/src/PJ_unitconvert.cpp +++ b/src/PJ_unitconvert.cpp @@ -80,10 +80,10 @@ typedef double (*tconvert)(double); namespace { // anonymous namespace struct TIME_UNITS { - char *id; /* units keyword */ + const char *id; /* units keyword */ tconvert t_in; /* unit -> mod. julian date function pointer */ tconvert t_out; /* mod. julian date > unit function pointer */ - char *name; /* comments */ + const char *name; /* comments */ }; } // anonymous namespace @@ -436,7 +436,7 @@ static double get_unit_conversion_factor(const char* name, PJ *CONVERSION(unitconvert,0) { /***********************************************************************/ struct pj_opaque_unitconvert *Q = static_cast<struct pj_opaque_unitconvert*>(pj_calloc (1, sizeof (struct pj_opaque_unitconvert))); - char *s, *name; + const char *s, *name; int i; double f; int xy_in_is_linear = -1; /* unknown */ diff --git a/src/emess.h b/src/emess.h index cb6b38f4..d552ec90 100644 --- a/src/emess.h +++ b/src/emess.h @@ -2,10 +2,6 @@ #ifndef EMESS_H #define EMESS_H -#ifdef __cplusplus -extern "C" { -#endif - struct EMESS { char *File_name, /* input file name */ *Prog_name; /* name of program */ @@ -15,7 +11,7 @@ struct EMESS { #ifdef EMESS_ROUTINE /* use type */ /* for emess procedure */ -struct EMESS PROJ_DLL emess_dat = { (char *)0, (char *)0, 0 }; +struct EMESS PROJ_DLL emess_dat = { nullptr, nullptr, 0 }; #ifdef sun /* Archaic SunOs 4.1.1, etc. */ extern char *sys_errlist[]; @@ -30,8 +26,4 @@ extern struct EMESS PROJ_DLL emess_dat; void PROJ_DLL emess(int, const char *, ...); -#ifdef __cplusplus -} -#endif - #endif /* end EMESS_H */ diff --git a/src/gen_cheb.cpp b/src/gen_cheb.cpp index ab16b409..4ba514d4 100644 --- a/src/gen_cheb.cpp +++ b/src/gen_cheb.cpp @@ -9,12 +9,40 @@ #define COEF_LINE_MAX 50 #endif +static double strtod_type_safe(const char *s, const char ** endptr) +{ + char* l_endptr = nullptr; + double ret= strtod(s, &l_endptr); + if( endptr ) + *endptr = static_cast<const char*>(l_endptr); + return ret; +} + +static double dmstor_type_safe(const char *s, const char ** endptr) +{ + char* l_endptr = nullptr; + double ret= dmstor(s, &l_endptr); + if( endptr ) + *endptr = static_cast<const char*>(l_endptr); + return ret; +} + +static long strtol_type_safe(const char *s, const char ** endptr, int base) +{ + char* l_endptr = nullptr; + long ret = strtol(s, &l_endptr, base); + if( endptr ) + *endptr = static_cast<const char*>(l_endptr); + return ret; +} + + /* FIXME: put the declaration in a header. Also used in proj.c */ -void gen_cheb(int inverse, projUV (*proj)(projUV), char *s, PJ *P, +void gen_cheb(int inverse, projUV (*proj)(projUV), const char *s, PJ *P, int iargc, char **iargv); extern void p_series(Tseries *, FILE *, char *); -void gen_cheb(int inverse, projUV (*proj)(projUV), char *s, PJ *P, +void gen_cheb(int inverse, projUV (*proj)(projUV), const char *s, PJ *P, int iargc, char **iargv) { long NU = 15, NV = 15; int errin = 0, pwr; @@ -22,18 +50,18 @@ void gen_cheb(int inverse, projUV (*proj)(projUV), char *s, PJ *P, char *arg, fmt[32]; projUV low, upp, resid; Tseries *F; - double (*input)(const char *, char **); + double (*input)(const char *, const char **); - input = inverse ? strtod : dmstor; + input = inverse ? strtod_type_safe : dmstor_type_safe; if (*s) low.u = input(s, &s); else { low.u = 0; ++errin; } if (*s == ',') upp.u = input(s+1, &s); else { upp.u = 0; ++errin; } if (*s == ',') low.v = input(s+1, &s); else { low.v = 0; ++errin; } if (*s == ',') upp.v = input(s+1, &s); else { upp.v = 0; ++errin; } if (errin) emess(16,"null or absent -T parameters"); - if (*s == ',') if (*++s != ',') res = strtol(s, &s, 10); - if (*s == ',') if (*++s != ',') NU = strtol(s, &s, 10); - if (*s == ',') if (*++s != ',') NV = strtol(s, &s, 10); + if (*s == ',') if (*++s != ',') res = strtol_type_safe(s, &s, 10); + if (*s == ',') if (*++s != ',') NU = strtol_type_safe(s, &s, 10); + if (*s == ',') if (*++s != ',') NV = strtol_type_safe(s, &s, 10); pwr = s && *s && !strcmp(s, ",P"); (void)printf("#proj_%s\n# run-line:\n", pwr ? "Power" : "Chebyshev"); diff --git a/src/geod.cpp b/src/geod.cpp index d7741679..7b6367c6 100644 --- a/src/geod.cpp +++ b/src/geod.cpp @@ -16,12 +16,14 @@ fullout = 0, /* output full set of geodesic values */ tag = '#', /* beginning of line tag character */ pos_azi = 0, /* output azimuths as positive values */ inverse = 0; /* != 0 then inverse geodesic */ - static char -*oform = (char *)nullptr, /* output format for decimal degrees */ -*osform = "%.3f", /* output format for S */ -pline[50], /* work string */ -*usage = + +static const char *oform = nullptr; /* output format for decimal degrees */ +static const char *osform = "%.3f"; /* output format for S */ + +static char pline[50]; /* work string */ +static const char *usage = "%s\nusage: %s [ -afFIlptwW [args] ] [ +opts[=arg] ] [ files ]\n"; + static void printLL(double p, double l) { if (oform) { @@ -146,7 +148,7 @@ int main(int argc, char **argv) { if(**++argv == '-') for(arg = *argv;;) { switch(*++arg) { case '\0': /* position of "stdin" */ - if (arg[-1] == '-') eargv[eargc++] = "-"; + if (arg[-1] == '-') eargv[eargc++] = const_cast<char*>("-"); break; case 'a': /* output full set of values */ fullout = 1; @@ -217,11 +219,11 @@ noargument: emess(1,"missing argument for -%c",*arg); do_geod(); else { /* process input file list */ if (eargc == 0) /* if no specific files force sysin */ - eargv[eargc++] = "-"; + eargv[eargc++] = const_cast<char*>("-"); for ( ; eargc-- ; ++eargv) { if (**eargv == '-') { fid = stdin; - emess_dat.File_name = "<stdin>"; + emess_dat.File_name = const_cast<char*>("<stdin>"); } else { if ((fid = fopen(*eargv, "r")) == nullptr) { emess(-2, *eargv, "input file"); diff --git a/src/geodesic.cpp b/src/geodesic.cpp index badfc9fa..705056b6 100644 --- a/src/geodesic.cpp +++ b/src/geodesic.cpp @@ -507,13 +507,13 @@ real geod_genposition(const struct geod_geodesicline* l, real omg12, lam12, lon12; real ssig2, csig2, sbet2, cbet2, somg2, comg2, salp2, calp2, dn2; unsigned outmask = - (plat2 ? GEOD_LATITUDE : 0U) | - (plon2 ? GEOD_LONGITUDE : 0U) | - (pazi2 ? GEOD_AZIMUTH : 0U) | - (ps12 ? GEOD_DISTANCE : 0U) | - (pm12 ? GEOD_REDUCEDLENGTH : 0U) | - (pM12 || pM21 ? GEOD_GEODESICSCALE : 0U) | - (pS12 ? GEOD_AREA : 0U); + (plat2 ? GEOD_LATITUDE : GEOD_NONE) | + (plon2 ? GEOD_LONGITUDE : GEOD_NONE) | + (pazi2 ? GEOD_AZIMUTH : GEOD_NONE) | + (ps12 ? GEOD_DISTANCE : GEOD_NONE) | + (pm12 ? GEOD_REDUCEDLENGTH : GEOD_NONE) | + (pM12 || pM21 ? GEOD_GEODESICSCALE : GEOD_NONE) | + (pS12 ? GEOD_AREA : GEOD_NONE); outmask &= l->caps & OUT_ALL; if (!( TRUE /*Init()*/ && @@ -721,13 +721,13 @@ real geod_gendirect(const struct geod_geodesic* g, real* pS12) { struct geod_geodesicline l; unsigned outmask = - (plat2 ? GEOD_LATITUDE : 0U) | - (plon2 ? GEOD_LONGITUDE : 0U) | - (pazi2 ? GEOD_AZIMUTH : 0U) | - (ps12 ? GEOD_DISTANCE : 0U) | - (pm12 ? GEOD_REDUCEDLENGTH : 0U) | - (pM12 || pM21 ? GEOD_GEODESICSCALE : 0U) | - (pS12 ? GEOD_AREA : 0U); + (plat2 ? GEOD_LATITUDE : GEOD_NONE) | + (plon2 ? GEOD_LONGITUDE : GEOD_NONE) | + (pazi2 ? GEOD_AZIMUTH : GEOD_NONE) | + (ps12 ? GEOD_DISTANCE : GEOD_NONE) | + (pm12 ? GEOD_REDUCEDLENGTH : GEOD_NONE) | + (pM12 || pM21 ? GEOD_GEODESICSCALE : GEOD_NONE) | + (pS12 ? GEOD_AREA : GEOD_NONE); geod_lineinit(&l, g, lat1, lon1, azi1, /* Automatically supply GEOD_DISTANCE_IN if necessary */ @@ -764,10 +764,10 @@ static real geod_geninverse_int(const struct geod_geodesic* g, real omg12 = 0, somg12 = 2, comg12 = 0; unsigned outmask = - (ps12 ? GEOD_DISTANCE : 0U) | - (pm12 ? GEOD_REDUCEDLENGTH : 0U) | - (pM12 || pM21 ? GEOD_GEODESICSCALE : 0U) | - (pS12 ? GEOD_AREA : 0U); + (ps12 ? GEOD_DISTANCE : GEOD_NONE) | + (pm12 ? GEOD_REDUCEDLENGTH : GEOD_NONE) | + (pM12 || pM21 ? GEOD_GEODESICSCALE : GEOD_NONE) | + (pS12 ? GEOD_AREA : GEOD_NONE); outmask &= OUT_ALL; /* Compute longitude difference (AngDiff does this carefully). Result is diff --git a/src/gie.cpp b/src/gie.cpp index 21a3a279..3e4770a2 100644 --- a/src/gie.cpp +++ b/src/gie.cpp @@ -604,7 +604,7 @@ either a conversion or a transformation) static PJ_COORD torad_coord (PJ *P, PJ_DIRECTION dir, PJ_COORD a) { size_t i, n; - char *axis = "enut"; + const char *axis = "enut"; paralist *l = pj_param_exists (P->params, "axis"); if (l && dir==PJ_INV) axis = l->param + strlen ("axis="); @@ -618,7 +618,7 @@ static PJ_COORD torad_coord (PJ *P, PJ_DIRECTION dir, PJ_COORD a) { static PJ_COORD todeg_coord (PJ *P, PJ_DIRECTION dir, PJ_COORD a) { size_t i, n; - char *axis = "enut"; + const char *axis = "enut"; paralist *l = pj_param_exists (P->params, "axis"); if (l && dir==PJ_FWD) axis = l->param + strlen ("axis="); diff --git a/src/optargpm.h b/src/optargpm.h index edd9fbee..035c6f92 100644 --- a/src/optargpm.h +++ b/src/optargpm.h @@ -201,9 +201,9 @@ int opt_record (OPTARGS *opt); int opt_input_loop (OPTARGS *opt, int binary); static int opt_is_flag (OPTARGS *opt, int ordinal); static int opt_raise_flag (OPTARGS *opt, int ordinal); -static int opt_ordinal (OPTARGS *opt, char *option); -int opt_given (OPTARGS *opt, char *option); -char *opt_arg (OPTARGS *opt, char *option); +static int opt_ordinal (OPTARGS *opt, const char *option); +int opt_given (OPTARGS *opt, const char *option); +char *opt_arg (OPTARGS *opt, const char *option); const char *opt_strip_path (const char *full_name); OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys, const char **longflags, const char **longkeys); @@ -315,7 +315,7 @@ static int opt_raise_flag (OPTARGS *opt, int ordinal) { } /* Find the ordinal value of any (short or long) option */ -static int opt_ordinal (OPTARGS *opt, char *option) { +static int opt_ordinal (OPTARGS *opt, const char *option) { int i; if (nullptr==opt) return 0; @@ -379,7 +379,7 @@ static int opt_ordinal (OPTARGS *opt, char *option) { /* Returns 0 if option was not given on command line, non-0 otherwise */ -int opt_given (OPTARGS *opt, char *option) { +int opt_given (OPTARGS *opt, const char *option) { int ordinal = opt_ordinal (opt, option); if (0==ordinal) return 0; @@ -391,7 +391,7 @@ int opt_given (OPTARGS *opt, char *option) { /* Returns the argument to a given option */ -char *opt_arg (OPTARGS *opt, char *option) { +char *opt_arg (OPTARGS *opt, const char *option) { int ordinal = opt_ordinal (opt, option); if (0==ordinal) return nullptr; diff --git a/src/pj_ell_set.cpp b/src/pj_ell_set.cpp index 9d7fae0a..486230a5 100644 --- a/src/pj_ell_set.cpp +++ b/src/pj_ell_set.cpp @@ -15,9 +15,9 @@ static int ellps_size (PJ *P); static int ellps_shape (PJ *P); static int ellps_spherification (PJ *P); -static paralist *pj_get_param (paralist *list, char *key); +static paralist *pj_get_param (paralist *list, const char *key); static char *pj_param_value (paralist *list); -static const PJ_ELLPS *pj_find_ellps (char *name); +static const PJ_ELLPS *pj_find_ellps (const char *name); /***************************************************************************************/ @@ -75,7 +75,7 @@ int pj_ellipsoid (PJ *P) { ****************************************************************************************/ int err = proj_errno_reset (P); - char *empty = {""}; + const char *empty = {""}; P->def_size = P->def_shape = P->def_spherification = P->def_ellps = nullptr; @@ -211,7 +211,7 @@ static int ellps_size (PJ *P) { /***************************************************************************************/ static int ellps_shape (PJ *P) { /***************************************************************************************/ - char *keys[] = {"rf", "f", "es", "e", "b"}; + const char *keys[] = {"rf", "f", "es", "e", "b"}; paralist *par = nullptr; char *def = nullptr; size_t i, len; @@ -317,7 +317,7 @@ static const double RV6 = 55/1296.; /***************************************************************************************/ static int ellps_spherification (PJ *P) { /***************************************************************************************/ - char *keys[] = {"R_A", "R_V", "R_a", "R_g", "R_h", "R_lat_a", "R_lat_g"}; + const char *keys[] = {"R_A", "R_V", "R_a", "R_g", "R_h", "R_lat_a", "R_lat_g"}; size_t len, i; paralist *par = nullptr; char *def = nullptr; @@ -400,7 +400,7 @@ static int ellps_spherification (PJ *P) { /* locate parameter in list */ -static paralist *pj_get_param (paralist *list, char *key) { +static paralist *pj_get_param (paralist *list, const char *key) { size_t l = strlen(key); while (list && !(0==strncmp(list->param, key, l) && (0==list->param[l] || list->param[l] == '=') ) ) list = list->next; @@ -421,7 +421,7 @@ static char *pj_param_value (paralist *list) { } -static const PJ_ELLPS *pj_find_ellps (char *name) { +static const PJ_ELLPS *pj_find_ellps (const char *name) { int i; const char *s; const PJ_ELLPS *ellps; diff --git a/src/pj_errno.cpp b/src/pj_errno.cpp index 6e98cd73..f6ea9bfc 100644 --- a/src/pj_errno.cpp +++ b/src/pj_errno.cpp @@ -2,7 +2,7 @@ #include "projects.h" -C_NAMESPACE_VAR int pj_errno = 0; +int pj_errno = 0; /************************************************************************/ /* pj_get_errno_ref() */ diff --git a/src/pj_mutex.cpp b/src/pj_mutex.cpp index 61487cec..3752324c 100644 --- a/src/pj_mutex.cpp +++ b/src/pj_mutex.cpp @@ -34,7 +34,9 @@ #endif /* For PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #ifndef _WIN32 #include "proj_config.h" diff --git a/src/proj.cpp b/src/proj.cpp index 8bb29c31..b93fb04d 100644 --- a/src/proj.cpp +++ b/src/proj.cpp @@ -20,7 +20,7 @@ #define MAX_PARGS 100 #define PJ_INVERS(P) (P->inv ? 1 : 0) -extern void gen_cheb(int, projUV(*)(projUV), char *, PJ *, int, char **); +extern void gen_cheb(int, projUV(*)(projUV), const char *, PJ *, int, char **); static PJ *Proj; static union { @@ -42,10 +42,10 @@ static int very_verby = 0, /* very verbose mode */ postscale = 0; -static char +static const char *cheby_str, /* string controlling Chebychev evaluation */ - *oform = (char *)nullptr, /* output format for x-y or decimal degrees */ - oform_buffer[16]; /* Buffer for oform when using -d */ + *oform = nullptr; /* output format for x-y or decimal degrees */ +static char oform_buffer[16]; /* Buffer for oform when using -d */ static const char *oterr = "*\t*", /* output line for unprojectable input */ @@ -309,7 +309,8 @@ static void vprocess(FILE *fid) { } int main(int argc, char **argv) { - char *arg, **eargv = argv, *pargv[MAX_PARGS], **iargv = argv; + char *arg, *pargv[MAX_PARGS], **iargv = argv; + char **eargv = argv; FILE *fid; int pargc = 0, iargc = argc, eargc = 0, mon = 0; @@ -327,7 +328,7 @@ int main(int argc, char **argv) { if(**++argv == '-') for(arg = *argv;;) { switch(*++arg) { case '\0': /* position of "stdin" */ - if (arg[-1] == '-') eargv[eargc++] = "-"; + if (arg[-1] == '-') eargv[eargc++] = const_cast<char*>("-"); break; case 'b': /* binary I/O */ bin_in = bin_out = 1; @@ -482,7 +483,7 @@ int main(int argc, char **argv) { eargv[eargc++] = *argv; } if (eargc == 0 && !cheby_str) /* if no specific files force sysin */ - eargv[eargc++] = "-"; + eargv[eargc++] = const_cast<char*>("-"); else if (eargc > 0 && cheby_str) /* warning */ emess(4, "data files when generating Chebychev prohibited"); /* done with parameter and control input */ @@ -551,7 +552,7 @@ int main(int argc, char **argv) { for ( ; eargc-- ; ++eargv) { if (**eargv == '-') { fid = stdin; - emess_dat.File_name = "<stdin>"; + emess_dat.File_name = const_cast<char*>("<stdin>"); if (bin_in) { diff --git a/src/proj_4D_api.cpp b/src/proj_4D_api.cpp index da2ba28d..88210348 100644 --- a/src/proj_4D_api.cpp +++ b/src/proj_4D_api.cpp @@ -952,9 +952,9 @@ static char *path_append (char *buf, const char *app, size_t *buf_size) { char *p; size_t len, applen = 0, buflen = 0; #ifdef _WIN32 - char *delim = ";"; + const char *delim = ";"; #else - char *delim = ":"; + const char *delim = ":"; #endif /* Nothing to do? */ diff --git a/src/projects.h b/src/projects.h index 099684d3..b76205a5 100644 --- a/src/projects.h +++ b/src/projects.h @@ -492,10 +492,10 @@ typedef union { double f; int i; char *s; } PROJVALUE; struct PJ_DATUMS { - char *id; /* datum keyword */ - char *defn; /* ie. "to_wgs84=..." */ - char *ellipse_id; /* ie from ellipse table */ - char *comments; /* EPSG code, etc */ + const char *id; /* datum keyword */ + const char *defn; /* ie. "to_wgs84=..." */ + const char *ellipse_id; /* ie from ellipse table */ + const char *comments; /* EPSG code, etc */ }; |
