Skip to content

Commit

Permalink
Let -J & -F have a -J without scale/size (not used anyway). (#8625)
Browse files Browse the repository at this point in the history
* Let -J & -F have a -J without scale/size (not used anyway).

Fixes #8624

* Swap the order of the loops.
  • Loading branch information
joa-quim authored Nov 19, 2024
1 parent 1154ac4 commit fa3eda0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/mapproject.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,28 @@ static int parse (struct GMT_CTRL *GMT, struct MAPPROJECT_CTRL *Ctrl, struct GMT
return (n_errors ? GMT_PARSE_ERROR : GMT_NOERROR);
}

static void add_J_scale_if_needed(struct GMT_CTRL *GMT, struct GMT_OPTION *options) {
/* Fixes #8624. That is, if -F is used the -J.../size|scale is inutil but it complained that
"No UTM zone given;". The fix requires a function like this because -J is parsed before we even
know if a -F is used. The trick is then to scan the options linked list and patch the -J option
to include a "/1:1" to make the parse_option_J happy. */
char txt_a[GMT_LEN128] = {""};
struct GMT_OPTION *optJ = NULL, *optF = NULL;
if (options == NULL) return; /* No arguments given to begin, done here */
for (optF = options; optF; optF = optF->next) { /* Loop over all options in the linked list */
if (optF->option == 'F') {
for (optJ = options; optJ; optJ = optJ->next) { /* Now search for -J */
if (optJ->option == 'J' && optJ->arg && !strchr(optJ->arg, '/')) {
strcpy(txt_a, optJ->arg); /* Save the -J argument because we need to free it first (was a strdup)*/
free(optJ->arg);
optJ->arg = strdup(strcat(txt_a, "/1:1")); /* Add /1:1 to the -J argument */
return;
}
}
}
}
}

#define bailout(code) {gmt_M_free_options (mode); return (code);}
#define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);}

Expand Down Expand Up @@ -926,6 +948,7 @@ EXTERN_MSC int GMT_mapproject (void *V_API, int mode, void *args) {
/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, module_kw, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
add_J_scale_if_needed(GMT, options);
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */
if ((error = parse (GMT, Ctrl, options)) != 0) Return (error);
Expand Down

0 comments on commit fa3eda0

Please sign in to comment.