| 222 | } |
| 223 | |
| 224 | static int parse (struct GMT_CTRL *GMT, struct GMTCONVERT_CTRL *Ctrl, struct GMT_OPTION *options) { |
| 225 | /* This parses the options provided to gmtconvert and sets parameters in CTRL. |
| 226 | * Any GMT common options will override values set previously by other commands. |
| 227 | * It also replaces any file names specified as input or output with the data ID |
| 228 | * returned when registering these sources/destinations with the API. |
| 229 | */ |
| 230 | |
| 231 | unsigned int pos, n_errors = 0, k; |
| 232 | int n = 0; |
| 233 | int64_t value = 0; |
| 234 | char p[GMT_BUFSIZ] = {""}, *c = NULL; |
| 235 | struct GMT_OPTION *opt = NULL; |
| 236 | struct GMTAPI_CTRL *API = GMT->parent; |
| 237 | EXTERN_MSC unsigned int gmtlib_string_parser (struct GMT_CTRL *GMT, char *file); /* For debug only */ |
| 238 | |
| 239 | for (opt = options; opt; opt = opt->next) { |
| 240 | switch (opt->option) { |
| 241 | |
| 242 | case '<': /* Skip input files */ |
| 243 | if (GMT_Get_FilePath (API, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++; |
| 244 | /* Hidden test of string parsing for developers */ |
| 245 | if (Ctrl->debug.active) { |
| 246 | if (gmtlib_string_parser (API->GMT, opt->arg)) return (GMT_RUNTIME_ERROR); |
| 247 | return (NOT_REALLY_AN_ERROR); |
| 248 | } |
| 249 | break; |
| 250 | case '>': /* Got named output file */ |
| 251 | n_errors += gmt_M_repeated_module_option (API, Ctrl->Out.active); |
| 252 | n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_DATASET, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->Out.file)); |
| 253 | break; |
| 254 | |
| 255 | /* Processes program-specific parameters */ |
| 256 | |
| 257 | case 'A': /* pAste mode */ |
| 258 | n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active); |
| 259 | n_errors += gmt_get_no_argument (GMT, opt->arg, opt->option, 0); |
| 260 | break; |
| 261 | case 'C': /* record-count selection mode */ |
| 262 | n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active); |
| 263 | pos = 0; |
| 264 | while (gmt_getmodopt (GMT, 'C', opt->arg, "ilu", &pos, p, &n_errors) && n_errors == 0) { /* Looking for +i, +l, +u */ |
| 265 | switch (p[0]) { |
| 266 | case 'i': /* Invert selection */ |
| 267 | Ctrl->C.invert = true; break; |
| 268 | case 'l': /* Set fewest records required */ |
| 269 | if ((value = atol (&p[1])) < 0) |
| 270 | GMT_Report (API, GMT_MSG_ERROR, "The -C+l modifier was given negative record count!\n"); |
| 271 | else |
| 272 | Ctrl->C.min = (uint64_t)value; |
| 273 | break; |
| 274 | case 'u': /* Set max records required */ |
| 275 | if ((value = atol (&p[1])) < 0) |
| 276 | GMT_Report (API, GMT_MSG_ERROR, "The -C+u modifier was given negative record count!\n"); |
| 277 | else |
| 278 | Ctrl->C.max = (uint64_t)value; |
| 279 | break; |
| 280 | default: /* These are caught in gmt_getmodopt so break is just for Coverity */ |
| 281 | break; |
no test coverage detected