MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / parse

Function parse

src/pstext.c:408–721  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408static int parse (struct GMT_CTRL *GMT, struct PSTEXT_CTRL *Ctrl, struct GMT_OPTION *options) {
409 /* This parses the options provided to pstext and sets parameters in Ctrl.
410 * Note Ctrl has already been initialized and non-zero default values set.
411 * Any GMT common options will override values set previously by other commands.
412 * It also replaces any file names specified as input or output with the data ID
413 * returned when registering these sources/destinations with the API.
414 */
415
416 int j, k;
417 unsigned int pos, n_errors = 0;
418 bool explicit_justify = false, mess = false;
419 char txt_a[GMT_LEN256] = {""}, txt_b[GMT_LEN256] = {""}, txt_c[GMT_LEN256] = {""}, p[GMT_BUFSIZ] = {""}, *c = NULL, *q = NULL;
420 struct GMT_OPTION *opt = NULL;
421 struct GMTAPI_CTRL *API = GMT->parent;
422
423 for (opt = options; opt; opt = opt->next) { /* Process all the options given */
424
425 switch (opt->option) {
426
427 case '<': /* Input files */
428 if (GMT_Get_FilePath (API, GMT_IS_DATASET, GMT_IN, GMT_FILE_REMOTE, &(opt->arg))) n_errors++;
429 break;
430
431 /* Processes program-specific parameters */
432
433 case 'A': /* Getting azimuths rather than directions, must convert via map projection */
434 n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active);
435 n_errors += gmt_get_no_argument (GMT, opt->arg, opt->option, 0);
436 break;
437 case 'C':
438 n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active);
439 c = strstr (opt->arg, "+t");
440 if ((c = strstr (opt->arg, "+t"))) {
441 if (c[2]) Ctrl->C.mode = c[2];
442 n_errors += gmt_M_check_condition (GMT, !strchr("oOcC", Ctrl->C.mode), "Option -C: Modifier +t must add o, O, c, or C\n");
443 c[0] = '\0'; /* Hide modifier */
444 }
445 if (opt->arg[0]) { /* Replace default settings with user settings */
446 Ctrl->C.percent = (strchr (opt->arg, '%')) ? true : false;
447 k = sscanf (opt->arg, "%[^/]/%s", txt_a, txt_b);
448 for (j = 0; txt_a[j]; j++) if (txt_a[j] == '%') txt_a[j] = '\0'; /* Remove % signs before processing values */
449 for (j = 0; k == 2 && txt_b[j]; j++) if (txt_b[j] == '%') txt_b[j] = '\0';
450 Ctrl->C.dx = (Ctrl->C.percent) ? atof (txt_a) : gmt_M_to_inch (GMT, txt_a);
451 Ctrl->C.dy = (k == 2) ? ((Ctrl->C.percent) ? atof (txt_b) : gmt_M_to_inch (GMT, txt_b)) : Ctrl->C.dx;
452 }
453 if (c) c[0] = '+'; /* Restore */
454 break;
455 case 'D':
456 n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active);
457 k = 0;
458 if (opt->arg[k] == 'j') { Ctrl->D.justify = 1, k++; }
459 else if (opt->arg[k] == 'J') { Ctrl->D.justify = 2, k++; }
460 for (j = k; opt->arg[j] && opt->arg[j] != 'v'; j++);
461 if (opt->arg[j] == 'v') { /* Want to draw a line from point to offset point */
462 Ctrl->D.line = true;
463 n_errors += gmt_M_check_condition (GMT, opt->arg[j+1] && gmt_getpen (GMT, &opt->arg[j+1], &Ctrl->D.pen), "Option -D: Give pen after +v\n");
464 if (opt->arg[j-1] == '+') /* New-style syntax */
465 opt->arg[j-1] = 0;

Callers 1

GMT_pstextFunction · 0.70

Calls 15

GMT_Get_FilePathFunction · 0.85
gmt_get_no_argumentFunction · 0.85
gmt_getpenFunction · 0.85
gmt_no_pstext_inputFunction · 0.85
gmt_strrepcFunction · 0.85
gmt_getmodoptFunction · 0.85
gmt_getfontFunction · 0.85
gmt_just_decodeFunction · 0.85
GMT_ReportFunction · 0.85
strdupFunction · 0.85
gmt_getfillFunction · 0.85
gmt_fill_syntaxFunction · 0.85

Tested by

no test coverage detected