Skip to content

Commit

Permalink
Free the longoptions from the #ifdefs jail (#8441)
Browse files Browse the repository at this point in the history
* Free the longotions from the #ifdefs jail

* Remove all traces of the USE_COMMON_LONG_OPTIONS

---------

Co-authored-by: Federico Esteban <[email protected]>
  • Loading branch information
joa-quim and Esteban82 committed Apr 13, 2024
1 parent 57d1c86 commit 586f4e0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 40 deletions.
5 changes: 0 additions & 5 deletions ci/config-gmt-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ set (SUPPORT_EXEC_IN_BINARY_DIR TRUE)
# For code coverage
set (CMAKE_C_FLAGS "--coverage -O0 ${CMAKE_C_FLAGS}")
# Turn on testing of upcoming long-option syntax for common GMT options
add_definitions(-DUSE_COMMON_LONG_OPTIONS)
# Turn on testing of upcoming long-option syntax for module options
add_definitions(-DUSE_MODULE_LONG_OPTIONS)
EOF
fi

Expand Down
5 changes: 0 additions & 5 deletions ci/config-gmt-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ set (DO_TESTS TRUE)
set (DO_API_TESTS ON)
set (DO_SUPPLEMENT_TESTS ON)
set (SUPPORT_EXEC_IN_BINARY_DIR TRUE)
# Turn on testing of upcoming long-option syntax for common GMT options
add_definitions(-DUSE_COMMON_LONG_OPTIONS)
# Turn on testing of upcoming long-option syntax for module options
add_definitions(-DUSE_MODULE_LONG_OPTIONS)
EOF
fi

Expand Down
2 changes: 0 additions & 2 deletions cmake/ConfigUserAdvancedTemplate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ set (GMT_ENABLE_OPENMP TRUE)
# Uncomment these two statements if you are a developer debugging GMT:
#add_definitions(-DDEBUG)
#add_definitions(-DMEMDEBUG) # Turn on memory tracking; see gmt_memory .c on MEMDEBUG for information
#add_definitions(-DUSE_COMMON_LONG_OPTIONS) # Turn on testing of upcoming long-option syntax for common GMT options
#add_definitions(-DUSE_MODULE_LONG_OPTIONS) # Turn on testing of upcoming long-option syntax for module options
#add_definitions(-DEXPORT_GMTLIB) # Turn on to access normally un-exported or static gmtlib functions from external tools
#add_definitions(-DNO_THEMES) # Turn off implementation of GMT_THEME for debugging
# Uncomment this statement if you are a developer debugging PSL and want exact line coordinates:
Expand Down
3 changes: 0 additions & 3 deletions doc/rst/source/devdocs/long_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ argument to the equivalent short-option argument. That way, we only need to cal
function at the start of a module and do the replacement. Then, the specific
parsers we already have for common and module options will work as is. This design simplifies
the coding tremendously and only requires us to create the translation tables.
The approach has already been implemented and tested for the ~30 GMT Common Options and
developers can play with this by adding the compiler flag **-DUSE_COMMON_LONG_OPTIONS**
when building GMT.
The translations for the GMT common options are encapsulated in a single include file
(gmt_common_longoptions.h) that populates a *gmt_common_kw* structure and looks like this:

Expand Down
33 changes: 8 additions & 25 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,10 @@ static char *map_annot_oblique_item[N_MAP_ANNOT_OBLIQUE_ITEMS] = {
"lat_parallel"
};

#if defined(USE_COMMON_LONG_OPTIONS)
/* List of GMT common keyword/options pairs. This list is used in gmtinit_translate_to_short_options to convert
* the new long-format GMT options (e.g., --timestamp="My plot"+offset=5c/6c) to regular GMT short format
* options (e.g., -U"My plot"+o5c/6c) that the common and module parsers expect.
*
* For testing this there are two define statements that need to be set in ConfigUserAdvanced.cmake:
*
* -DUSE_COMMON_LONG_OPTIONS will allow us to test the gmt_common_kw array below.
* -DUSE_MODULE_LONG_OPTIONS will allow us to test any module_kw settings in the modules
*
* Without these we are blind to the keyword arrays. Note that while you can test the
* common options without the module options, you cannot do the reverse.
*
Expand All @@ -483,7 +477,6 @@ static char *map_annot_oblique_item[N_MAP_ANNOT_OBLIQUE_ITEMS] = {
static struct GMT_KEYWORD_DICTIONARY gmt_common_kw[] = {
#include "gmt_common_longoptions.h"
};
#endif

/* Local variables to gmt_init.c */

Expand Down Expand Up @@ -569,8 +562,7 @@ bool gmtlib_file_unlock (struct GMT_CTRL *GMT, int fd) {
}
#endif

#if defined(USE_COMMON_LONG_OPTIONS)
GMT_LOCAL void gmtinit_handle_escape_text (char *text, char key, int way) {
GMT_LOCAL void gmtinit_handle_escape_text(char *text, char key, int way) {
/* Deal with text that contains modifiers +? that should be seen as plain text
* because they have a leading escape ("My dumb \+p text"). If way == 1 then
* we replace \+ with two GMT_ASCII_ES (Escape) bytes and if way == -1 then we
Expand Down Expand Up @@ -600,7 +592,7 @@ GMT_LOCAL void gmtinit_handle_escape_text (char *text, char key, int way) {
}

/*! . */
GMT_LOCAL char * gmtinit_colon_digexcl (char *string) {
GMT_LOCAL char *gmtinit_colon_digexcl(char *string) {
/* Search for the first colon character that is not
* both preceded and followed by a digit. This is
* intended to ignore any colon which occurs within
Expand Down Expand Up @@ -630,7 +622,7 @@ GMT_LOCAL char * gmtinit_strchr_predexcl (char *string, char target, char predex
#endif

/*! . */
GMT_LOCAL struct GMT_KEYWORD_DICTIONARY * gmtinit_find_kw (struct GMTAPI_CTRL *API, struct GMT_KEYWORD_DICTIONARY *kw1, struct GMT_KEYWORD_DICTIONARY *kw2, char *arg, int *k) {
GMT_LOCAL struct GMT_KEYWORD_DICTIONARY *gmtinit_find_kw(struct GMTAPI_CTRL *API, struct GMT_KEYWORD_DICTIONARY *kw1, struct GMT_KEYWORD_DICTIONARY *kw2, char *arg, int *k) {
/* Determine if this long-format arg is found in one of the two keyword lists kw1 (common) and kw2 (current module).
* If we find a match we return a pointer to the corresponding keyword list and the index *k for the array entry index.
* If not found then we return NULL and set index to -1 (GMT_NOTSET) */
Expand Down Expand Up @@ -658,7 +650,7 @@ GMT_LOCAL struct GMT_KEYWORD_DICTIONARY * gmtinit_find_kw (struct GMTAPI_CTRL *A
}

/*! . */
GMT_LOCAL int gmtinit_find_longoptmatch (struct GMTAPI_CTRL *API, char *longlist, char *shortlist, char *textin, int sepcode, unsigned int multidir, char *codechars, unsigned int codecharsbufsz, char *argout) {
GMT_LOCAL int gmtinit_find_longoptmatch(struct GMTAPI_CTRL *API, char *longlist, char *shortlist, char *textin, int sepcode, unsigned int multidir, char *codechars, unsigned int codecharsbufsz, char *argout) {
/* Attempt to match the leading portion of textin with a long-option
* directive or modifier string which is an element of longlist, a
* single comma-subdivided string which concatenates a sequence of
Expand Down Expand Up @@ -926,7 +918,7 @@ GMT_LOCAL int gmtinit_find_longoptmatch (struct GMTAPI_CTRL *API, char *longlist
return ncodechars;
}

GMT_LOCAL int gmtinit_get_section (struct GMTAPI_CTRL *API, char *arg, char separator, int k, int *sx) {
GMT_LOCAL int gmtinit_get_section(struct GMTAPI_CTRL *API, char *arg, char separator, int k, int *sx) {
/* Find the k'th separator occurrence and chop off the rest, return pointer to start of k'th section */
int j = 0, kk = -1, s0 = 0, s = 0, last_s = 0;
gmt_M_unused (API);
Expand All @@ -953,7 +945,7 @@ GMT_LOCAL int gmtinit_get_section (struct GMTAPI_CTRL *API, char *arg, char sepa
}

/*! . */
GMT_LOCAL char * gmtinit_getfirstmodifier (char *string) {
GMT_LOCAL char *gmtinit_getfirstmodifier(char *string) {
/* Return a pointer to the + character that marks the start
* of the first modifier substring within string, where such
* a substring always begins with a + character followed by
Expand All @@ -970,7 +962,7 @@ GMT_LOCAL char * gmtinit_getfirstmodifier (char *string) {
}

/*! . */
GMT_LOCAL unsigned int gmtinit_copynextmodifier (char *string, unsigned int *srchstartpos, char *modstr) {
GMT_LOCAL unsigned int gmtinit_copynextmodifier(char *string, unsigned int *srchstartpos, char *modstr) {
/* This routine is very loosely based (at least in terms of its
* arguments and returns) on gmt_strtok() which was formerly used
* in this context to return the next modifier substring within a string.
Expand Down Expand Up @@ -1017,7 +1009,7 @@ GMT_LOCAL unsigned int gmtinit_copynextmodifier (char *string, unsigned int *src
}

/*! . */
GMT_LOCAL void gmtinit_translate_to_short_options (struct GMTAPI_CTRL *API, struct GMT_KEYWORD_DICTIONARY *this_module_kw, struct GMT_OPTION **options) {
GMT_LOCAL void gmtinit_translate_to_short_options(struct GMTAPI_CTRL *API, struct GMT_KEYWORD_DICTIONARY *this_module_kw, struct GMT_OPTION **options) {
/* Loop over given options and replace any recognized long-form --parameter[=value] arguments
* with the corresponding classic short-format version -<code>[value]. Specifically, long-format is defined as
*
Expand Down Expand Up @@ -1046,10 +1038,6 @@ GMT_LOCAL void gmtinit_translate_to_short_options (struct GMTAPI_CTRL *API, stru

if (options == NULL) return; /* Nothing to process */

#if !defined(USE_MODULE_LONG_OPTIONS)
this_module_kw = NULL; /* Debugging: Not testing the module long-options yet */
#endif

for (opt = *options; opt; opt = opt->next) { /* Examine all incoming options */
if (opt->option != GMT_OPT_PARAMETER) continue; /* Cannot be a --keyword[=value] long-option pair */
if (isupper (opt->arg[0])) continue; /* Skip any upper-case GMT Default parameter settings, e.g., --FONT_TITLE=12p */
Expand Down Expand Up @@ -1209,7 +1197,6 @@ GMT_LOCAL void gmtinit_translate_to_long_options (struct GMTAPI_CTRL *API, struc
}
#endif

#endif

GMT_LOCAL int gmtinit_check_markers (struct GMT_CTRL *GMT) {
int error = GMT_NOERROR;
Expand Down Expand Up @@ -15662,11 +15649,7 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name,
struct GMT_CTRL *GMT = API->GMT;
API->error = GMT_NOERROR;

#if defined(USE_COMMON_LONG_OPTIONS)
gmtinit_translate_to_short_options (API, this_module_kw, options); /* Replace --long-option syntax with equivalent -onechar options */
#else
gmt_M_unused(this_module_kw);
#endif

is_PS = gmtinit_is_PS_module (API, mod_name, keys, options); /* true if module will produce PS */
if (!is_PS) { /* Override API default since module is a data processor */
Expand Down

0 comments on commit 586f4e0

Please sign in to comment.