MCPcopy Create free account
hub / github.com/OSGeo/PROJ / get_init_string

Function get_init_string

src/init.cpp:70–209  ·  view source on GitHub ↗

/

Source from the content-addressed store, hash-verified

68
69/**************************************************************************************/
70static char *get_init_string(PJ_CONTEXT *ctx, const char *name) {
71/***************************************************************************************
72 Read a section of an init file. Return its contents as a plain character
73string. It is the duty of the caller to free the memory allocated for the
74string.
75***************************************************************************************/
76#define MAX_LINE_LENGTH 1000
77 size_t current_buffer_size = 5 * (MAX_LINE_LENGTH + 1);
78 char *fname, *section;
79 const char *key;
80 char *buffer = nullptr;
81 size_t n;
82
83 fname = static_cast<char *>(malloc(MAX_PATH_FILENAME + ID_TAG_MAX + 3));
84 if (nullptr == fname) {
85 return nullptr;
86 }
87
88 /* Support "init=file:section", "+init=file:section", and "file:section"
89 * format */
90 key = strstr(name, "init=");
91 if (nullptr == key)
92 key = name;
93 else
94 key += 5;
95 if (MAX_PATH_FILENAME + ID_TAG_MAX + 2 < strlen(key)) {
96 free(fname);
97 return nullptr;
98 }
99 memmove(fname, key, strlen(key) + 1);
100
101 /* Locate the name of the section we search for */
102 section = strrchr(fname, ':');
103 if (nullptr == section) {
104 pj_log(ctx, PJ_LOG_ERROR, _("Missing colon in +init"));
105 proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
106 free(fname);
107 return nullptr;
108 }
109 *section = 0;
110 section++;
111 n = strlen(section);
112 pj_log(ctx, PJ_LOG_TRACE,
113 "get_init_string: searching for section [%s] in init file [%s]",
114 section, fname);
115
116 auto file = NS_PROJ::FileManager::open_resource_file(ctx, fname);
117 if (nullptr == file) {
118 pj_log(ctx, PJ_LOG_ERROR, _("Cannot open %s"), fname);
119 proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE);
120 free(fname);
121 return nullptr;
122 }
123
124 /* Search for section in init file */
125 std::string line;
126 for (;;) {
127

Callers 1

get_initFunction · 0.85

Calls 5

pj_logFunction · 0.85
proj_context_errno_setFunction · 0.85
pj_chompFunction · 0.85
pj_shrinkFunction · 0.85
read_lineMethod · 0.80

Tested by

no test coverage detected