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

Function parse

src/gmtmath.c:790–937  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

788}
789
790static int parse (struct GMT_CTRL *GMT, struct GMTMATH_CTRL *Ctrl, struct GMT_OPTION *options) {
791 /* This parses the options provided to gmtmath and sets parameters in CTRL.
792 * Any GMT common options will override values set previously by other commands.
793 * It also replaces any file names specified as input or output with the data ID
794 * returned when registering these sources/destinations with the API.
795 */
796
797 unsigned int n_errors = 0, k = 0;
798 bool missing_equal = true;
799 char *c = NULL, *t_arg = NULL;
800 struct GMT_OPTION *opt = NULL;
801 struct GMTAPI_CTRL *API = GMT->parent;
802 int gmt_parse_o_option (struct GMT_CTRL *GMT, char *arg);
803
804 for (opt = options; opt; opt = opt->next) {
805 switch (opt->option) {
806
807 case '<': /* Input files */
808 if (opt->arg[0] == '=' && opt->arg[1] == 0) { /* No it was an = [outfile] sequence */
809 missing_equal = false;
810 opt->option = GMT_OPT_OUTFILE; /* Prevents further use later */
811 if (opt->next && (opt->next->option == GMT_OPT_INFILE || opt->next->option == GMT_OPT_OUTFILE)) {
812 opt = opt->next; /* Skip ahead */
813 n_errors += gmt_M_repeated_module_option (API, Ctrl->Out.active);
814 if (opt->arg[0]) Ctrl->Out.file = strdup (opt->arg); /* Optional output file since stdout is default */
815 opt->option = GMT_OPT_OUTFILE; /* Prevents further use later */
816 }
817 }
818 break;
819 case '>': /* Output file specified via an API; set required output file here */
820 n_errors += gmt_M_repeated_module_option (API, Ctrl->Out.active);
821 n_errors += gmt_get_required_file (GMT, opt->arg, opt->option, 0, GMT_IS_DATASET, GMT_OUT, GMT_FILE_LOCAL, &(Ctrl->Out.file));
822 missing_equal = false;
823 break;
824 case '#': /* Skip numbers */
825 break;
826
827 /* Processes program-specific parameters */
828
829 case 'A': /* y(x) table for LSQFIT/SVDFIT operations */
830 n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active);
831 if (opt->arg[0] == '-') { /* Old-style leading hyphen to the filename has been replaced by modifier +r */
832 if (gmt_M_compat_check (GMT, 5)) {
833 GMT_Report (API, GMT_MSG_COMPAT, "The leading hyphen in -A is deprecated. Append modifier +r instead.\n");
834 Ctrl->A.null = true;
835 k = 1;
836 }
837 else {
838 GMT_Report (API, GMT_MSG_ERROR, "Option -A: Unable to decode arguments\n");
839 n_errors++;
840 }
841 }
842 if ((c = strchr(opt->arg, '+')) != NULL && strchr("ersw", c[1]) != NULL) { /* Got a valid modifier */
843 unsigned int pos = 0;
844 char p[GMT_LEN256] = {""};
845 c[0] = '\0'; /* Temporarily chop off modifiers */
846 Ctrl->A.file = strdup (&opt->arg[k]);
847 c[0] = '+'; /* Restore the modifier */

Callers 1

GMT_gmtmathFunction · 0.70

Calls 12

strdupFunction · 0.85
gmt_get_required_fileFunction · 0.85
GMT_ReportFunction · 0.85
gmt_strtokFunction · 0.85
gmt_get_required_doubleFunction · 0.85
gmt_parse_o_optionFunction · 0.85
gmt_default_option_errorFunction · 0.85
gmt_get_no_argumentFunction · 0.85
gmt_get_dim_unitFunction · 0.85
gmt_parse_arrayFunction · 0.85
gmt_create_arrayFunction · 0.85
gmt_accessFunction · 0.85

Tested by

no test coverage detected