| 168 | } |
| 169 | |
| 170 | static int parse (struct GMT_CTRL *GMT, struct PSLEGEND_CTRL *Ctrl, struct GMT_OPTION *options) { |
| 171 | /* This parses the options provided to pslegend and sets parameters in Ctrl. |
| 172 | * Note Ctrl has already been initialized and non-zero default values set. |
| 173 | * Any GMT common options will override values set previously by other commands. |
| 174 | * It also replaces any file names specified as input or output with the data ID |
| 175 | * returned when registering these sources/destinations with the API. |
| 176 | */ |
| 177 | |
| 178 | unsigned int n_errors = 0; |
| 179 | int n; |
| 180 | char xx[GMT_LEN256] = {""}, txt_a[GMT_LEN256] = {""}, txt_b[GMT_LEN256] = {""}, txt_c[GMT_LEN256] = {""}; |
| 181 | char yy[GMT_LEN256] = {""}, txt_d[GMT_LEN256] = {""}, txt_e[GMT_LEN256] = {""}, string[GMT_LEN256] = {""}; |
| 182 | struct GMT_OPTION *opt = NULL; |
| 183 | struct GMTAPI_CTRL *API = GMT->parent; |
| 184 | |
| 185 | for (opt = options; opt; opt = opt->next) { /* Process all the options given */ |
| 186 | |
| 187 | switch (opt->option) { |
| 188 | |
| 189 | case '<': /* Input files, just check they are readable */ |
| 190 | if (GMT_Get_FilePath (API, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++; |
| 191 | Ctrl->got_file = true; |
| 192 | break; |
| 193 | |
| 194 | /* Processes program-specific parameters */ |
| 195 | |
| 196 | case 'C': /* Sets the clearance between frame and internal items */ |
| 197 | n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active); |
| 198 | if ((n = gmt_get_pair (GMT, opt->arg, GMT_PAIR_DIM_DUP, Ctrl->C.off)) < 0) n_errors++; |
| 199 | break; |
| 200 | case 'D': /* Sets position and size of legend */ |
| 201 | n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active); |
| 202 | if (strlen (opt->arg) < 5 || strchr ("jgn", opt->arg[0]) || gmt_found_modifier (GMT, opt->arg, "jlow")) { /* New syntax: */ |
| 203 | if ((Ctrl->D.refpoint = gmt_get_refpoint (GMT, opt->arg, 'D')) == NULL) { |
| 204 | n_errors++; /* Failed basic parsing */ |
| 205 | continue; |
| 206 | } |
| 207 | /* Args are +w<width>[/<height>][+j<justify>][+l<spacing>][+o<dx>[/<dy>]] */ |
| 208 | if (gmt_validate_modifiers (GMT, Ctrl->D.refpoint->args, 'D', "jlow", GMT_MSG_ERROR)) n_errors++; |
| 209 | if (gmt_get_modifier (Ctrl->D.refpoint->args, 'j', string)) |
| 210 | Ctrl->D.justify = gmt_just_decode (GMT, string, PSL_NO_DEF); |
| 211 | else /* With -Dj or -DJ, set default to reference justify point, else BL */ |
| 212 | Ctrl->D.justify = gmt_M_just_default (GMT, Ctrl->D.refpoint, PSL_BL); |
| 213 | if (gmt_get_modifier (Ctrl->D.refpoint->args, 'l', string)) { |
| 214 | Ctrl->D.spacing = atof (string); |
| 215 | } |
| 216 | if (gmt_get_modifier (Ctrl->D.refpoint->args, 'o', string)) { |
| 217 | if ((n = gmt_get_pair (GMT, string, GMT_PAIR_DIM_DUP, Ctrl->D.off)) < 0) n_errors++; |
| 218 | } |
| 219 | if (gmt_get_modifier (Ctrl->D.refpoint->args, 'w', string)) { |
| 220 | if (gmt_rectangle_dimension (GMT, &Ctrl->D.R, 0.0, 0.0, string)) |
| 221 | n_errors++; |
| 222 | } |
| 223 | } |
| 224 | else { /* Backwards handling of old syntax. Args are args are [x]<x>/<y>/<width>[/<height>][/<justify>][/<dx>/<dy>] */ |
| 225 | Ctrl->D.refpoint = gmt_M_memory (GMT, NULL, 1, struct GMT_REFPOINT); |
| 226 | Ctrl->D.refpoint->mode = GMT_REFPOINT_PLOT; |
| 227 | Ctrl->D.justify = PSL_TC; /* Backwards compatible default justification */ |
no test coverage detected