@@ -309,6 +309,11 @@ enum GMTAPI_enum_status {
309309 GMTAPI_GOT_SEGHEADER = -1, /* Read a segment header */
310310 GMTAPI_GOT_SEGGAP = -2}; /* Detected a gap and insertion of new segment header */
311311
312+ enum GMTAPI_enum_takes_mod {
313+ GMTAPI_MOD_NOTSET = 0, /* Not assigned */
314+ GMTAPI_MOD_SPECIAL = 1, /* Found = and possibly modifiers */
315+ GMTAPI_MOD_NORMAL = 2}; /* No arg found after stripping modifiers (if any) */
316+
312317/*==================================================================================================
313318 * PRIVATE FUNCTIONS ONLY USED BY THIS LIBRARY FILE
314319 *==================================================================================================
@@ -12958,7 +12963,7 @@ GMT_LOCAL const char *gmtapi_retrieve_module_keys (void *V_API, char *module) {
1295812963 return_null (V_API, GMT_NOT_A_VALID_MODULE);
1295912964}
1296012965
12961- GMT_LOCAL int gmtapi_extract_argument (char *optarg, char *argument, char **key, int k, bool colon, char colon_opt, int *n_pre, unsigned int *takes_mod) {
12966+ GMT_LOCAL int gmtapi_extract_argument (char *optarg, char *argument, char **key, int k, bool colon, char colon_opt, int *n_pre, enum GMTAPI_enum_takes_mod *takes_mod) {
1296212967 /* A few separate actions:
1296312968 * 1) If key ends with "=" then we pull out the option argument after stripping off +<stuff>.
1296412969 * 2) If key ends with "=q" then we see if +q is given and return pos to this modifiers argument.
@@ -12974,7 +12979,7 @@ GMT_LOCAL int gmtapi_extract_argument (char *optarg, char *argument, char **key,
1297412979 unsigned int pos = 0;
1297512980 size_t L;
1297612981 *n_pre = 0;
12977- *takes_mod = 0 ;
12982+ *takes_mod = GMTAPI_MOD_NOTSET ;
1297812983
1297912984 L = (k >= 0) ? strlen (key[k]) : 0;
1298012985 if (colon_opt) { /* Either -S (from psxy[z]) or -G (from grdcontour or pscontour) */
@@ -12989,28 +12994,28 @@ GMT_LOCAL int gmtapi_extract_argument (char *optarg, char *argument, char **key,
1298912994 }
1299012995
1299112996 if (k >= 0 && key[k][K_EQUAL] == '=') { /* Special handling */
12992- *takes_mod = 1 ; /* Flag that KEY was special */
12997+ *takes_mod = GMTAPI_MOD_SPECIAL ; /* Flag that KEY was special */
1299312998 *n_pre = (L > K_MODIFIER && key[k][K_MODIFIER] && isdigit (key[k][K_MODIFIER])) ? (int)(key[k][K_MODIFIER]-'0') : 0;
1299412999 if ((*n_pre || key[k][K_MODIFIER] == 0) && (c = strchr (inarg, '+'))) { /* Strip off trailing +<modifiers> */
1299513000 c[0] = 0;
1299613001 strcpy (argument, inarg);
1299713002 c[0] = '+';
12998- if (!argument[0]) *takes_mod = 2 ; /* Flag that option is missing the arg and needs it later */
13003+ if (!argument[0]) *takes_mod = GMTAPI_MOD_NORMAL ; /* Flag that option is missing the arg and needs it later */
1299913004 }
1300013005 else if (L > K_MODIFIER && key[k][K_MODIFIER]) { /* Look for a specific +<mod> in the option */
1300113006 char code[3] = {"+?"};
1300213007 code[1] = key[k][K_MODIFIER];
1300313008 if ((c = strstr (inarg, code))) { /* Found +<modifier> */
1300413009 strcpy (argument, inarg);
13005- if (!c[2] || c[2] == '+') *takes_mod = 2 ; /* Flag that option had no argument that KEY was looking for */
13010+ if (!c[2] || c[2] == '+') *takes_mod = GMTAPI_MOD_NORMAL ; /* Flag that option had no argument that KEY was looking for */
1300613011 pos = (unsigned int) (c - inarg + 2); /* Position of this modifier's argument. E.g., -E+f<file> will have pos = 2 as start of <file> */
1300713012 }
1300813013 else /* No modifier involved */
1300913014 strcpy (argument, inarg);
1301013015 }
1301113016 else
1301213017 strcpy (argument, inarg);
13013- if (!argument[0]) *takes_mod = 2 ; /* Flag that option is missing the arg and needs it later */
13018+ if (!argument[0]) *takes_mod = GMTAPI_MOD_NORMAL ; /* Flag that option is missing the arg and needs it later */
1301413019 }
1301513020 else
1301613021 strcpy (argument, inarg);
@@ -13184,7 +13189,8 @@ struct GMT_RESOURCE * GMT_Encode_Options (void *V_API, const char *module_name,
1318413189 */
1318513190
1318613191 unsigned int n_keys, direction = 0, kind, pos = 0, n_items = 0, ku, n_out = 0, nn[2][2];
13187- unsigned int output_pos = 0, input_pos = 0, mod_pos, takes_mod;
13192+ unsigned int output_pos = 0, input_pos = 0, mod_pos;
13193+ enum GMTAPI_enum_takes_mod takes_mod;
1318813194 int family = GMT_NOTSET; /* -1, or one of GMT_IS_DATASET, GMT_IS_GRID, GMT_IS_PALETTE, GMT_IS_IMAGE */
1318913195 int geometry = GMT_NOTSET; /* -1, or one of GMT_IS_NONE, GMT_IS_TEXT, GMT_IS_POINT, GMT_IS_LINE, GMT_IS_POLY, GMT_IS_SURFACE */
1319013196 int sdir, k = 0, n_in_added = 0, n_to_add, e, n_pre_arg, n_per_family[GMT_N_FAMILIES];
@@ -13539,7 +13545,7 @@ struct GMT_RESOURCE * GMT_Encode_Options (void *V_API, const char *module_name,
1353913545
1354013546 else if (k >= 0 && key[k][K_OPT] != GMT_OPT_INFILE && family != GMT_NOTSET && key[k][K_DIR] != '-') { /* Got some option like -G or -Lu with further args */
1354113547 bool implicit = true;
13542- if (takes_mod == 1 ) /* Got some option like -E[+f] but no +f was given so no implicit file needed */
13548+ if (takes_mod == GMTAPI_MOD_SPECIAL ) /* Got some option like -E[+f] but no +f was given so no implicit file needed */
1354313549 implicit = false;
1354413550 else if ((len = strlen (argument)) == (size_t)n_pre_arg) /* Got some option like -G or -Lu with no further args */
1354513551 GMT_Report (API, GMT_MSG_DEBUG, "GMT_Encode_Options: Option -%c needs implicit arg [offset = %d]\n", opt->option, n_pre_arg);
0 commit comments