From c08fd0407ec3f690108fa38a0d9caf292957ec9b Mon Sep 17 00:00:00 2001 From: Joaquim Date: Fri, 12 Apr 2024 18:29:16 +0100 Subject: [PATCH 1/2] Free the longotions from the #ifdefs jail --- src/gmt_init.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/gmt_init.c b/src/gmt_init.c index 2fc3e1b1ad8..1895dffc57c 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -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. * @@ -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 */ @@ -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 @@ -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 @@ -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) */ @@ -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 @@ -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); @@ -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 @@ -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. @@ -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 -[value]. Specifically, long-format is defined as * @@ -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 */ @@ -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; @@ -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 */ From 3d1d959f37a570df67879fb9bd69776399023c8f Mon Sep 17 00:00:00 2001 From: Joaquim Date: Sat, 13 Apr 2024 01:49:01 +0100 Subject: [PATCH 2/2] Remove all traces of the USE_COMMON_LONG_OPTIONS --- ci/config-gmt-unix.sh | 5 ----- ci/config-gmt-windows.sh | 5 ----- cmake/ConfigUserAdvancedTemplate.cmake | 2 -- doc/rst/source/devdocs/long_options.rst | 3 --- 4 files changed, 15 deletions(-) diff --git a/ci/config-gmt-unix.sh b/ci/config-gmt-unix.sh index b36dc21385a..b4e6500a81e 100755 --- a/ci/config-gmt-unix.sh +++ b/ci/config-gmt-unix.sh @@ -32,11 +32,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 diff --git a/ci/config-gmt-windows.sh b/ci/config-gmt-windows.sh index 10b4e10f9c0..ae6be96c046 100755 --- a/ci/config-gmt-windows.sh +++ b/ci/config-gmt-windows.sh @@ -21,11 +21,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 diff --git a/cmake/ConfigUserAdvancedTemplate.cmake b/cmake/ConfigUserAdvancedTemplate.cmake index aec7e9e6398..2ab0458dcfd 100644 --- a/cmake/ConfigUserAdvancedTemplate.cmake +++ b/cmake/ConfigUserAdvancedTemplate.cmake @@ -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: diff --git a/doc/rst/source/devdocs/long_options.rst b/doc/rst/source/devdocs/long_options.rst index 62c844911f0..daabe1eabbb 100644 --- a/doc/rst/source/devdocs/long_options.rst +++ b/doc/rst/source/devdocs/long_options.rst @@ -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: