Skip to content

Explore adding long-format GMT options #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 94 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
a0d6f1c
WIP Explore adding long-format GMT options
PaulWessel Dec 21, 2018
4f06191
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 21, 2018
10dcf50
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 22, 2018
2e6cd71
More common option long-format words
PaulWessel Dec 23, 2018
3e1a5e6
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 23, 2018
64905f0
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 23, 2018
97907f7
Update mgd77track.c
PaulWessel Dec 23, 2018
958968e
Add separator variable to GMT_KW_DICT
PaulWessel Dec 23, 2018
225359c
Let -T option be a modifer under -C
PaulWessel Dec 23, 2018
ce41093
Remove the ifdef USE_GMT_KWD
PaulWessel Dec 23, 2018
b795ed8
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 23, 2018
cdd0229
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 28, 2018
fdcf1ed
Implement parsing of sections
PaulWessel Dec 29, 2018
404438b
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 29, 2018
60e44e2
Documentation
PaulWessel Dec 29, 2018
af27567
Merge branch 'pstextsimplify' into longoptionsparsing
PaulWessel Dec 29, 2018
1f76192
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 29, 2018
b3bbc3f
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 30, 2018
9868ffe
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 1, 2019
f939ffe
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 1, 2019
1680ae7
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 2, 2019
193ad85
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 4, 2019
e0efe84
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 5, 2019
a99eb23
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 6, 2019
a07d34e
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 6, 2019
3636fb4
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 6, 2019
b2c71d4
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 8, 2019
d73c3ef
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 12, 2019
169d384
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 16, 2019
2d48a32
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 17, 2019
9d89c2c
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 21, 2019
3044e26
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 22, 2019
61e8dde
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 24, 2019
4465e53
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 24, 2019
359bae7
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 26, 2019
8c0069e
Merge branch 'master' into longoptionsparsing
PaulWessel Jan 26, 2019
4a8449c
Merge branch 'master' into longoptionsparsing
leouieda Mar 2, 2019
f84188c
Merge branch 'master' into longoptionsparsing
PaulWessel Mar 9, 2019
1b5a35f
Merge branch 'master' into longoptionsparsing
PaulWessel Mar 9, 2019
28394a1
Merge branch 'master' into longoptionsparsing
PaulWessel Mar 27, 2019
0a85e33
Merge branch 'master' into longoptionsparsing
PaulWessel Apr 6, 2019
4f02938
Merge branch 'master' into longoptionsparsing
PaulWessel Apr 14, 2019
aba2206
Merge branch 'master' into longoptionsparsing
PaulWessel Apr 29, 2019
f711500
Merge branch 'master' into longoptionsparsing
PaulWessel May 12, 2019
c23adb3
Merge branch 'master' into longoptionsparsing
PaulWessel May 12, 2019
4ab1b1f
Merge branch 'master' into longoptionsparsing
PaulWessel May 13, 2019
2c299f0
Merge branch 'master' into longoptionsparsing
PaulWessel May 16, 2019
eb866da
Fix a few issues
PaulWessel May 16, 2019
3c4a82a
Merge branch 'master' into longoptionsparsing
PaulWessel May 16, 2019
e336c6b
Merge branch 'master' into longoptionsparsing
PaulWessel May 19, 2019
ef5af6a
Merge branch 'master' into longoptionsparsing
PaulWessel May 25, 2019
1dff0fd
Merge branch 'master' into longoptionsparsing
PaulWessel May 26, 2019
eeddf1d
Merge branch 'master' into longoptionsparsing
PaulWessel May 29, 2019
d664c60
Merge branch 'master' into longoptionsparsing
PaulWessel Jun 7, 2019
52a026a
Merge branch 'master' into longoptionsparsing
PaulWessel Jun 8, 2019
d242cf1
Merge branch 'master' into longoptionsparsing
PaulWessel Jun 10, 2019
5ea7172
Merge branch 'master' into longoptionsparsing
PaulWessel Jun 13, 2019
42fc5f2
Merge branch 'master' into longoptionsparsing
PaulWessel Jun 15, 2019
70121fb
Merge branch 'master' into longoptionsparsing
PaulWessel Jul 1, 2019
0d371f6
Merge branch 'longoptionsparsing' of https://github.com/GenericMappin…
PaulWessel Jul 1, 2019
9d22bbd
Merge branch '6.0' into longoptionsparsing
PaulWessel Jul 1, 2019
4e4ae65
Merge branch 'master' into longoptionsparsing
PaulWessel Jul 4, 2019
3cf971f
Merge branch '6.0' into longoptionsparsing
PaulWessel Jul 6, 2019
22dfa7e
Merge branch 'master' into longoptionsparsing
PaulWessel Jul 14, 2019
11740a1
Seppl out structure name
PaulWessel Jul 29, 2019
e475664
Merge branch 'master' into longoptionsparsing
PaulWessel Aug 8, 2019
25e841f
Merge branch 'longoptionsparsing' of https://github.com/GenericMappin…
PaulWessel Aug 8, 2019
7d06285
Merge branch '6.0' into longoptionsparsing
PaulWessel Sep 3, 2019
b952226
Merge branch '6.0' into longoptionsparsing
PaulWessel Sep 4, 2019
f7f263c
Merge branch 'master' into longoptionsparsing
PaulWessel Sep 9, 2019
e80aff4
rename a few keywords
PaulWessel Dec 13, 2019
7dfc286
Add grdinterpolate to the mix and fix some errors
PaulWessel Dec 14, 2019
4344a01
Let keyword dictionary be ifdef under USE_LONG_OPTIONS
PaulWessel Dec 14, 2019
564f29d
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 14, 2019
1e63473
Minor text improvements
PaulWessel Dec 15, 2019
7cc0b20
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 15, 2019
0d48d5e
Fix the use of USE_LONG_OPTIONS
PaulWessel Dec 15, 2019
05e5c37
Update ConfigUserTemplate.cmake
PaulWessel Dec 15, 2019
7726b38
Add --frame
PaulWessel Dec 15, 2019
498abc7
Rename kw arrays to make it clearer that one is module-specific
PaulWessel Dec 15, 2019
4f66c03
Update src/blockmean.c
PaulWessel Dec 17, 2019
13244f5
Fix issues in block_subs.c
PaulWessel Dec 17, 2019
dffcbf0
Update src/gmt_init.c
PaulWessel Dec 17, 2019
32cdb1e
Update src/gmt_init.c
PaulWessel Dec 17, 2019
8a2ba44
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 18, 2019
eaa3b61
Adding axes as keyword
PaulWessel Dec 19, 2019
d96e725
Escape +? strings that should not be seen as modifiers
PaulWessel Dec 19, 2019
3c8e67f
Move --increment to block_subs.c, update commons, use --axis
PaulWessel Dec 19, 2019
73af06c
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 19, 2019
ea731fd
Enable CI testing for long options (#2305)
seisman Dec 20, 2019
7b15d16
Add a long-format option test to test/modern
PaulWessel Dec 20, 2019
e25bf8e
Improve coments only
PaulWessel Dec 20, 2019
90821af
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 20, 2019
8143ea1
Merge branch 'master' into longoptionsparsing
PaulWessel Dec 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/begin.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int GMT_begin (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) return (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) return (API->error); /* Save current state */
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
if ((error = parse (GMT, options)) != 0) Return (error);

Expand Down
12 changes: 11 additions & 1 deletion src/blockmean.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@

#include "block_subs.h"

GMT_LOCAL struct GMT_KW_DICT local_kw[] = {
{ 'A', "fields", "", "", "", "" },
{ 'C', "center", "", "", "", "" },
{ 'E', "extend", "", "", "P,p", "prop-error,prop-mean" },
{ 'G', "gridfile", "", "", "", "" },
{ 'S', "select", "m,n,s,w", "mean,count,sum,weight", "", "" },
{ 'W', "weights", "i,o", "in,out", "s", "sigma" },
{'\0', "", "", "", "", ""} /* End of list marked with empty code and strings */
};

enum Block_Modes {
BLK_MODE_NOTSET = 0, /* No -E+p|P (or -Ep) set */
BLK_MODE_OBSOLETE = 1, /* Old -Ep for backwards compabitibility; assumes input weights are already set to 1/s^ */
Expand Down Expand Up @@ -299,7 +309,7 @@ int GMT_blockmean (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, local_kw, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
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
2 changes: 1 addition & 1 deletion src/blockmedian.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ int GMT_blockmedian (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
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
2 changes: 1 addition & 1 deletion src/blockmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ int GMT_blockmode (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
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
2 changes: 1 addition & 1 deletion src/clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int GMT_clear (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
if ((error = parse (GMT, options)) != 0) Return (error);

Expand Down
2 changes: 1 addition & 1 deletion src/docs.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int GMT_docs (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
if ((error = parse (GMT, options)) != 0) Return (error);

Expand Down
2 changes: 1 addition & 1 deletion src/end.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int GMT_end (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
if ((error = parse (GMT, options)) != 0) Return (error);

Expand Down
2 changes: 1 addition & 1 deletion src/figure.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int GMT_figure (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
if ((error = parse (GMT, options)) != 0) Return (error);

Expand Down
2 changes: 1 addition & 1 deletion src/filter1d.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ int GMT_filter1d (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error, "Error parsing filter1d options\n");
Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */
if ((error = parse (GMT, Ctrl, options)) != 0) Return (error, "Error parsing filter1d options\n");
Expand Down
2 changes: 1 addition & 1 deletion src/fitcircle.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ int GMT_fitcircle (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
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
2 changes: 1 addition & 1 deletion src/gmt2kml.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ int GMT_gmt2kml (void *V_API, int mode, void *args) {

/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, NULL, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
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
151 changes: 105 additions & 46 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,28 +356,28 @@ static struct GMT_FONTSPEC GMT_standard_fonts[GMT_N_STANDARD_FONTS] = {
/* List of GMT common keyword/options pairs */
#ifdef USE_GMT_KWD
struct GMT_KW_DICT gmt_kw_common[] = {
{'R', "region"},
{'J', "proj"},
{'U', "timestamp"},
{'V', "verbose"},
{'X', "xoff"},
{'Y', "yoff"},
{'a', "aspatial"},
{'b', "binary"},
{'d', "nodata"},
{'e', "find"},
{'f', "coltypes"},
{'g', "gap"},
{'h', "header"},
{'i', "incol"},
{'o', "outcol"},
{'n', "interpol"},
{'p', "perspective"},
{'r', "registration"},
{'t', "transparency"},
{'x', "cores"},
{':', "order"},
{'\0', ""} /* End of list marked with empty code and string */
{'R', "region", "", "", "rect", "r"},
{'J', "proj", "", "", "", ""},
{'U', "timestamp", "", "", "", ""},
{'V', "verbose", "", "", "", ""},
{'X', "xoff", "", "", "", ""},
{'Y', "yoff", "", "", "", ""},
{'a', "aspatial", "", "", "", ""},
{'b', "binary", "", "", "", ""},
{'d', "nodata", "i,o", "in,out", "", ""},
{'e', "find", "", "", "f", "file"},
{'f', "coltypes", "i,o", "in,out", "", ""},
{'g', "gap", "", "", "", ""},
{'h', "header", "i,o", "in,out", "c,d,r,t", "columns,delete,remark,title"},
{'i', "incol", "", "", "", ""},
{'o', "outcol", "", "", "", ""},
{'n', "interpol", "", "", "", ""},
{'p', "perspective", "", "", "", ""},
{'r', "registration", "g,p", "gridline,pixel", "", ""},
{'t', "transparency", "", "", "", ""},
{'x', "cores", "", "", "", ""},
{':', "order", "", "", "", ""},
{'\0', "", "", "", "", ""} /* End of list marked with empty code and strings */
};
#endif

Expand Down Expand Up @@ -474,15 +474,49 @@ GMT_LOCAL bool gmtinit_file_unlock (struct GMT_CTRL *GMT, int fd) {
#ifdef USE_GMT_KWD

/*! . */
GMT_LOCAL int gmtinit_find_kw (struct GMTAPI_CTRL *API, struct GMT_KW_DICT *kw, char *arg) {
/* Determine if this arg is found in the keyword list */
int k;
GMT_LOCAL struct GMT_KW_DICT * gmtinit_find_kw (struct GMTAPI_CTRL *API, struct GMT_KW_DICT *kw1, struct GMT_KW_DICT *kw2, char *arg, int *k) {
/* Determine if this arg is found in one of the two keyword lists */
size_t len, lent = strlen(arg);
gmt_M_unused (API);
if (kw == NULL) return -1; /* No list to search in yet */
for (k = 0; kw[k].name[0]; k++) {
if (!strncmp (arg, kw[k].name, strlen(kw[k].name))) break; /* Match found */
if (kw1) { /* Search list 1 if not NULL */
for (*k = 0; kw1[*k].long_option[0]; (*k)++) {
len = MIN (lent, strlen (kw1[*k].long_option)); /* Only compare up to the given # of characters, but less than length of long_option */
if (!strncmp (arg, kw1[*k].long_option, len)) break; /* Match found */
}
if (kw1[*k].short_option) return kw1; /* Return if successful */
}
return (kw[k].code) ? k : -1; /* Either return index to match or -1 if not found */
if (kw2) { /* Search list 2 if not NULL */
for (*k = 0; kw2[*k].long_option[0]; (*k)++) {
len = MIN (lent, strlen(kw2[*k].long_option)); /* Only compare up to the given # of characters, but less than length of long_option */
if (!strncmp (arg, kw2[*k].long_option, len)) break; /* Match found */
}
if (kw2[*k].short_option) return kw2; /* Return if successful */
}
*k = -1; /* No go */
return NULL;
}

/*! . */
GMT_LOCAL char gmtinit_find_argument (struct GMTAPI_CTRL *API, char *longlist, char *shortlist, char *text, char sep, char *argument) {
unsigned int k = 0, pos = 0;
size_t len, lent = strlen(text);
char *c = strchr (text, sep), m = 0, item[GMT_LEN64] = {""};
gmt_M_unused (API);
if (c) c[0] = '0'; /* Chop off colon or equal for now */
while (m == 0 && (gmt_strtok (longlist, ",", &pos, item))) { /* While there are unprocessed directives */
len = MIN (lent, strlen(item)); /* Only compare up to the given # of characters, but less than length of item */
if (!strncmp (item, text, len)) /* Found the directive */
m = shortlist[k];
k += 2; /* Go to next char in comma-separated list of single characters */
}
if (m && c)
strcpy (argument, &c[1]); /* Pass out the directive argument */
else if (m)
argument[0] = '\0'; /* Nothing */
else
strcpy (argument, text); /* Not a directive, pass out the argument */
if (c) c[0] = sep; /* Restore colon */
return m;
}

/*! . */
Expand All @@ -491,30 +525,55 @@ GMT_LOCAL void gmtinit_kw_replace (struct GMTAPI_CTRL *API, struct GMT_KW_DICT *
* with the corresponding short option version -<code>[value] */
struct GMT_OPTION *opt = NULL;
struct GMT_KW_DICT *kw = NULL;
char text[GMT_LEN256] = {""}, *e = NULL;
char text[GMT_LEN256] = {""}, add[GMT_LEN64] = {""}, argument[GMT_LEN64] = {""};
char *e = NULL, *p = NULL, c = 0;
int k;

for (opt = *options; opt; opt = opt->next) {
if (opt->option != GMT_OPT_PARAMETER) continue; /* Cannot be a --keyword[=value] pair */
if (isupper (opt->arg[0])) continue; /* Skip the upper-case GMT Default parameter settings */
if (isupper (opt->arg[0])) continue; /* Skip the upper-case GMT Default parameter settings */

e = strchr (opt->arg, '='); /* Get location of equal sign, if present */
p = strchr (opt->arg, '+'); /* Get location of plus sign, if present */
if (e && p && ((e - opt->arg) > (p - opt->arg)))
e = NULL; /* The = is part of a modifier so ignore for now */
if (e) e[0] = '\0'; /* Cut off =value for now so opt->arg only has the keyword */
if ((k = gmtinit_find_kw (API, gmt_kw_common, opt->arg)) >= 0) /* Got common kw pair */
kw = gmt_kw_common;
else if ((k = gmtinit_find_kw (API, module_kw, opt->arg)) >= 0) /* Got module kw pair */
kw = module_kw;
else
continue; /* Got nothing */
else if (p) p[0] = '\0'; /* Cut off +modifier for now so opt->arg only has the keyword */
if ((kw = gmtinit_find_kw (API, gmt_kw_common, module_kw, opt->arg, &k)) == NULL) { /* Did not match anything in the list */
if (e) e[0] = '='; /* Restore */
if (p) p[0] = '+'; /* Restore */
continue; /* No matching keyword pair */
}

/* Here we found a matching long-format option name */
/* Do the long to short option substitution */
opt->option = kw[k].code; /* Update the option character first */
if (e) {

opt->option = kw[k].short_option; /* Update the option character first */
text[0] = '\0'; /* Initialize short option arguments */
if (e) { /* Got a <directive>[:<arg>] or just <arg> */
if ((c = gmtinit_find_argument (API, kw[k].long_directives, kw[k].short_directives, &e[1], ':', argument))) /* Get the directive, or 0 if it is an argument instead */
sprintf (add, "%c%s", c, argument);
else
sprintf (add, "%s", argument);
strcat (text, add); /* Add to the short-format option argument */
e[0] = '='; /* Put back the = character */
sprintf (text, "%s", &e[1]); /* Get string with the argument */
}
else
text[0] = '\0'; /* No argument to pass on */
if (p) { /* Do have one of more modifiers */
unsigned int pos = 0;
char item[GMT_LEN64] = {""};
p[0] = '+'; /* Put back the plus sign for the first modifier */
while ((gmt_strtok (p, "+", &pos, item))) { /* While there are unprocessed modifiers */
if ((c = gmtinit_find_argument (API, kw[k].long_modifiers, kw[k].short_modifiers, item, '=', argument))) /* Get the modifier, or 0 if unrecognized */
sprintf (add, "+%c%s", c, argument);
else {
GMT_Report (API, GMT_MSG_NORMAL, "Long-modifier form %s for option -%c not recognized!\n", &e[1], opt->option);
add[0] = '\0';
}
strcat (text, add); /* Add to the short-format option argument */
}
}
GMT_Report (API, GMT_MSG_NORMAL, "Converting long-format --%s to -%c%s\n", opt->arg, opt->option, text);
gmt_M_str_free (opt->arg); /* Free old par=value string argument */
GMT_Report (API, GMT_MSG_DEBUG, "Converting long-format --%s to -%c%s\n", opt->arg, opt->option, text);
opt->arg = strdup (text); /* Allocate copy of new argument */
}
}
Expand Down Expand Up @@ -11880,7 +11939,7 @@ GMT_LOCAL int gmtinit_set_last_dimensions (struct GMTAPI_CTRL *API) {
}

/*! Prepare options if missing and initialize module */
struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, const char *mod_name, const char *keys, const char *required, struct GMT_OPTION **options, struct GMT_CTRL **Ccopy) {
struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, const char *mod_name, const char *keys, const char *required, struct GMT_KW_DICT *module_kw, struct GMT_OPTION **options, struct GMT_CTRL **Ccopy) {
/* For modern runmode only - otherwise we simply call gmt_begin_module_sub.
* We must consult the required string. It may contain options that we need to set implicitly.
* Possible letters in the required string are:
Expand Down Expand Up @@ -11911,7 +11970,7 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name,
API->error = GMT_NOERROR;

#ifdef USE_GMT_KWD
gmtinit_kw_replace (API, NULL, options);
gmtinit_kw_replace (API, module_kw, options);
#endif
/* Making -R<country-codes> globally available means it must affect history, etc. The simplest fix here is to
* make sure pscoast -E, if passing old +r|R area settings via -E, is split into -R before GMT_Parse_Common is called */
Expand Down Expand Up @@ -12256,7 +12315,7 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name,
/*! Backwards compatible gmt_begin_module function for external modules built with GMT 5.3 or learlier */
struct GMT_CTRL * gmt_begin_module (struct GMTAPI_CTRL *API, const char *lib_name, const char *mod_name, struct GMT_CTRL **Ccopy) {
API->GMT->current.setting.run_mode = GMT_CLASSIC; /* Since gmt_begin_module is 5.3 or earlier */
return (gmt_init_module (API, lib_name, mod_name, "", "", NULL, Ccopy));
return (gmt_init_module (API, lib_name, mod_name, "", "", NULL, NULL, Ccopy));
}

/*! . */
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ EXTERN_MSC bool gmt_check_filearg (struct GMT_CTRL *GMT, char option, char *file
EXTERN_MSC int gmt_parse_model (struct GMT_CTRL *GMT, char option, char *in_arg, unsigned int dim, struct GMT_MODEL *M);
EXTERN_MSC struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsigned int pad);
EXTERN_MSC void gmt_end (struct GMT_CTRL *GMT);
EXTERN_MSC struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, const char *mod_name, const char *keys, const char *required, struct GMT_OPTION **options, struct GMT_CTRL **Ccopy);
EXTERN_MSC struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, const char *mod_name, const char *keys, const char *required, struct GMT_KW_DICT *module_kw, struct GMT_OPTION **options, struct GMT_CTRL **Ccopy);
EXTERN_MSC struct GMT_CTRL *gmt_begin_module (struct GMTAPI_CTRL *API, const char *lib_name, const char *mod_name, struct GMT_CTRL **Ccopy);
EXTERN_MSC void gmt_end_module (struct GMT_CTRL *GMT, struct GMT_CTRL *Ccopy);
EXTERN_MSC int gmt_init_time_system_structure (struct GMT_CTRL *GMT, struct GMT_TIME_SYSTEM *time_system);
Expand Down
8 changes: 6 additions & 2 deletions src/gmt_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ struct GMT_MATH_MACRO {
#ifdef USE_GMT_KWD
/*! Definition of GMT_KW_DICT used to expand keyword-value pairs to GMT options */
struct GMT_KW_DICT { /* Used for keyword-value lookup */
char code; /* Single character GMT option code */
char name[31]; /* Name of corresponding keyword */
char short_option; /* Single character GMT option code */
char long_option[31]; /* Name of corresponding long option */
char short_directives[32]; /* Single character directives, comma-separated */
char long_directives[256]; /* Long name directives, comma-separated */
char short_modifiers[32]; /* Single character modifiers, comma-separated */
char long_modifiers[256]; /* Long name modifiers, comma-separated */
};
#endif

Expand Down
Loading