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

Function parse

src/inset.c:113–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113static int parse (struct GMT_CTRL *GMT, struct INSET_CTRL *Ctrl, struct GMT_OPTION *options) {
114
115 /* This parses the options provided to inset and sets parameters in CTRL.
116 * Any GMT common options will override values set previously by other commands.
117 * It also replaces any file names specified as input or output with the data ID
118 * returned when registering these sources/destinations with the API.
119 */
120
121 unsigned int n_errors = 0, k, side;
122 struct GMT_OPTION *opt = NULL;
123 struct GMTAPI_CTRL *API = GMT->parent;
124
125 opt = options; /* The first argument is the inset command */
126 if (opt->option != GMT_OPT_INFILE) {
127 GMT_Report (API, GMT_MSG_ERROR, "No inset command given\n");
128 return GMT_PARSE_ERROR;
129 }
130 if (!strncmp (opt->arg, "begin", 5U)) { /* Initiate new inset */
131 Ctrl->In.mode = INSET_BEGIN;
132 }
133 else if (!strncmp (opt->arg, "end", 3U))
134 Ctrl->In.mode = INSET_END;
135 else {
136 GMT_Report (API, GMT_MSG_ERROR, "Not an inset command: %s\n", opt->arg);
137 return GMT_PARSE_ERROR;
138 }
139 opt = opt->next; /* Position to the next argument */
140
141 while (opt) { /* Process all the options given */
142
143 switch (opt->option) {
144
145 case 'D': /* Draw map inset */
146 n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active);
147 n_errors += gmt_getinset (GMT, 'D', opt->arg, &Ctrl->D.inset);
148 break;
149
150 case 'F':
151 n_errors += gmt_M_repeated_module_option (API, Ctrl->F.active);
152 if (gmt_getpanel (GMT, opt->option, opt->arg, &(Ctrl->D.inset.panel))) {
153 gmt_mappanel_syntax (GMT, 'F', "Specify a rectangular panel for the map inset", 3);
154 n_errors++;
155 }
156 break;
157
158 case 'M': /* inset margins */
159 GMT_Report (API, GMT_MSG_COMPAT, "-M option is deprecated; use -C instead.\n");
160 /* Fall through on purpose */
161 case 'C': /* Clearance/inside margins (repeatable) */
162 Ctrl->C.active = true;
163 if (opt->arg[0] == 0) { /* Gave nothing */
164 GMT_Report (API, GMT_MSG_ERROR, "Option -C: No clearance specified.\n");
165 n_errors++;
166 }
167 else if (strchr ("wesnxy", opt->arg[0])) { /* Gave a specific side directive */
168 switch (opt->arg[0]) {
169 case 'w': side = XLO; Ctrl->C.gap[XLO] = gmt_M_to_inch (GMT, &opt->arg[1]); break;
170 case 'e': side = XHI; Ctrl->C.gap[XHI] = gmt_M_to_inch (GMT, &opt->arg[1]); break;

Callers 1

GMT_insetFunction · 0.70

Calls 7

GMT_ReportFunction · 0.85
gmt_getinsetFunction · 0.85
gmt_getpanelFunction · 0.85
gmt_mappanel_syntaxFunction · 0.85
GMT_Get_ValuesFunction · 0.85
gmt_get_no_argumentFunction · 0.85
gmt_default_option_errorFunction · 0.85

Tested by

no test coverage detected