| 38 | /************************************************************************/ |
| 39 | |
| 40 | int pj_datum_set(PJ_CONTEXT *ctx, paralist *pl, PJ *projdef) |
| 41 | |
| 42 | { |
| 43 | const char *name, *towgs84, *nadgrids; |
| 44 | |
| 45 | projdef->datum_type = PJD_UNKNOWN; |
| 46 | |
| 47 | /* -------------------------------------------------------------------- */ |
| 48 | /* Is there a datum definition in the parameters list? If so, */ |
| 49 | /* add the defining values to the parameter list. Note that */ |
| 50 | /* this will append the ellipse definition as well as the */ |
| 51 | /* towgs84= and related parameters. It should also be pointed */ |
| 52 | /* out that the addition is permanent rather than temporary */ |
| 53 | /* like most other keyword expansion so that the ellipse */ |
| 54 | /* definition will last into the pj_ell_set() function called */ |
| 55 | /* after this one. */ |
| 56 | /* -------------------------------------------------------------------- */ |
| 57 | if ((name = pj_param(ctx, pl, "sdatum").s) != nullptr) { |
| 58 | paralist *curr; |
| 59 | const char *s; |
| 60 | int i; |
| 61 | |
| 62 | /* find the end of the list, so we can add to it */ |
| 63 | for (curr = pl; curr && curr->next; curr = curr->next) { |
| 64 | } |
| 65 | |
| 66 | /* cannot happen in practice, but makes static analyzers happy */ |
| 67 | if (!curr) |
| 68 | return -1; |
| 69 | |
| 70 | /* find the datum definition */ |
| 71 | const struct PJ_DATUMS *pj_datums = pj_get_datums_ref(); |
| 72 | for (i = 0; (s = pj_datums[i].id) && strcmp(name, s); ++i) { |
| 73 | } |
| 74 | |
| 75 | if (!s) { |
| 76 | pj_log(ctx, PJ_LOG_ERROR, _("Unknown value for datum")); |
| 77 | proj_context_errno_set(ctx, PROJ_ERR_INVALID_OP_ILLEGAL_ARG_VALUE); |
| 78 | return 1; |
| 79 | } |
| 80 | |
| 81 | if (pj_datums[i].ellipse_id && strlen(pj_datums[i].ellipse_id) > 0) { |
| 82 | char entry[100]; |
| 83 | |
| 84 | strcpy(entry, "ellps="); |
| 85 | strncpy(entry + strlen(entry), pj_datums[i].ellipse_id, |
| 86 | sizeof(entry) - 1 - strlen(entry)); |
| 87 | entry[sizeof(entry) - 1] = '\0'; |
| 88 | |
| 89 | auto param = pj_mkparam(entry); |
| 90 | if (nullptr == param) { |
| 91 | proj_context_errno_set(ctx, PROJ_ERR_OTHER /*ENOMEM*/); |
| 92 | return 1; |
| 93 | } |
| 94 | curr->next = param; |
| 95 | curr = param; |
| 96 | } |
| 97 |
no test coverage detected