| 127 | /************************************************************************/ |
| 128 | |
| 129 | PROJVALUE pj_param(PJ_CONTEXT *ctx, paralist *pl, const char *opt) { |
| 130 | |
| 131 | int type; |
| 132 | unsigned l; |
| 133 | PROJVALUE value = {0}; |
| 134 | |
| 135 | if (ctx == nullptr) |
| 136 | ctx = pj_get_default_ctx(); |
| 137 | |
| 138 | type = *opt++; |
| 139 | |
| 140 | if (nullptr == strchr("tbirds", type)) { |
| 141 | fprintf(stderr, "invalid request to pj_param, fatal\n"); |
| 142 | exit(1); |
| 143 | } |
| 144 | |
| 145 | pl = pj_param_exists(pl, opt); |
| 146 | if (type == 't') { |
| 147 | value.i = pl != nullptr; |
| 148 | return value; |
| 149 | } |
| 150 | |
| 151 | /* Not found */ |
| 152 | if (nullptr == pl) { |
| 153 | /* Return value after the switch, so that the return path is */ |
| 154 | /* taken in all cases */ |
| 155 | switch (type) { |
| 156 | case 'b': |
| 157 | case 'i': |
| 158 | value.i = 0; |
| 159 | break; |
| 160 | case 'd': |
| 161 | case 'r': |
| 162 | value.f = 0.; |
| 163 | break; |
| 164 | case 's': |
| 165 | value.s = nullptr; |
| 166 | break; |
| 167 | } |
| 168 | return value; |
| 169 | } |
| 170 | |
| 171 | /* Found parameter - now find its value */ |
| 172 | pl->used |= 1; |
| 173 | l = (int)strlen(opt); |
| 174 | opt = pl->param + l; |
| 175 | if (*opt == '=') |
| 176 | ++opt; |
| 177 | |
| 178 | switch (type) { |
| 179 | case 'i': /* integer input */ |
| 180 | value.i = atoi(opt); |
| 181 | for (const char *ptr = opt; *ptr != '\0'; ++ptr) { |
| 182 | if (!(*ptr >= '0' && *ptr <= '9')) { |
| 183 | proj_context_errno_set(ctx, |
| 184 | PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); |
| 185 | value.i = 0; |
| 186 | } |
no test coverage detected