/
| 212 | |
| 213 | /************************************************************************/ |
| 214 | static paralist *get_init(PJ_CONTEXT *ctx, const char *key, int allow_init_epsg) { |
| 215 | /************************************************************************* |
| 216 | Expand key from buffer or (if not in buffer) from init file |
| 217 | *************************************************************************/ |
| 218 | const char *xkey; |
| 219 | char *definition = nullptr; |
| 220 | paralist *init_items = nullptr; |
| 221 | |
| 222 | if( !ctx ) { |
| 223 | ctx = pj_get_default_ctx(); |
| 224 | } |
| 225 | |
| 226 | /* support "init=file:section", "+init=file:section", and "file:section" format */ |
| 227 | xkey = strstr (key, "init="); |
| 228 | if (nullptr==xkey) |
| 229 | xkey = key; |
| 230 | else |
| 231 | xkey += 5; |
| 232 | pj_log (ctx, PJ_LOG_TRACE, "get_init: searching cache for key: [%s]", xkey); |
| 233 | |
| 234 | /* Is file/key pair already in cache? */ |
| 235 | init_items = pj_search_initcache (xkey); |
| 236 | if (init_items) |
| 237 | return init_items; |
| 238 | |
| 239 | if( (strncmp(xkey, "epsg:", 5) == 0 || strncmp(xkey, "IGNF:", 5) == 0) ) { |
| 240 | char unused[256]; |
| 241 | char initname[5]; |
| 242 | int exists; |
| 243 | |
| 244 | strncpy(initname, xkey, 4); |
| 245 | initname[4] = 0; |
| 246 | |
| 247 | if( strncmp(xkey, "epsg:", 5) == 0 ) { |
| 248 | exists = ctx->epsg_file_exists; |
| 249 | if( exists < 0 ) { |
| 250 | exists = pj_find_file(ctx, initname, unused, sizeof(unused)); |
| 251 | ctx->epsg_file_exists = exists; |
| 252 | } |
| 253 | } else { |
| 254 | exists = pj_find_file(ctx, initname, unused, sizeof(unused)); |
| 255 | } |
| 256 | |
| 257 | if( !exists ) { |
| 258 | char szInitStr[7 + 64]; |
| 259 | PJ* src; |
| 260 | const char* proj_string; |
| 261 | |
| 262 | proj_context_errno_set( ctx, 0 ); |
| 263 | |
| 264 | if( !allow_init_epsg ) { |
| 265 | pj_log (ctx, PJ_LOG_TRACE, "%s expansion disallowed", xkey); |
| 266 | return nullptr; |
| 267 | } |
| 268 | if( strlen(xkey) > 64 ) { |
| 269 | return nullptr; |
| 270 | } |
| 271 | strcpy(szInitStr, "+init="); |
no test coverage detected