diff --git a/src/gmt_init.c b/src/gmt_init.c index 2bb5b0f62bf..eae6ebac907 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -13561,6 +13561,19 @@ void gmtinit_complete_RJ (struct GMT_CTRL *GMT, char *codes, struct GMT_OPTION * } } +GMT_LOCAL bool gmtinit_might_be_remotefile (char *file) { + bool quote = false; /* We are outside any quoted text */ + size_t k; + if (strchr (file, '@') == NULL) return false; /* No @ anywhere */ + if (file[0] == '@') return true; /* Definitively a remote file */ + /* Get here when a @ is not in the first position. Return true unless @ is inside quotes */ + for (k = 0; k < strlen (file); k++) { + if (file[k] == '\"' || file[k] == '\'') quote = !quote; + if (file[k] == '@' && !quote) return true; /* Found an unquoted at-symbol */ + } + return false; /* Nothing */ +} + /*! 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 *in_required, struct GMT_KEYWORD_DICTIONARY *this_module_kw, struct GMT_OPTION **options, struct GMT_CTRL **Ccopy) { /* For modern runmode only - otherwise we simply call gmtinit_begin_module_sub. @@ -13586,7 +13599,7 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, * Modules like psxy has "d" so we can make a quick map without specifying -R. */ - bool is_PS, is_psrose = false, is_D_module = false; + bool is_PS, is_psrose = false, is_D_module = false, remote_first = true; char *required = (char *)in_required; unsigned int k; static char *D_module[4] = {"gmtlogo", "psimage", "pslegend", "psscale"}; /* These all may take -Dx etc */ @@ -13603,9 +13616,13 @@ struct GMT_CTRL *gmt_init_module (struct GMTAPI_CTRL *API, const char *lib_name, /* First handle any half-hearted naming of remote datasets where _g or _p should be appended */ if (options) { - for (opt = *options; opt; opt = opt->next) { /* Loop over all options */ - if (opt->arg[0] != '@') continue; /* No remote file argument given */ - gmt_set_unspecified_remote_registration (API, &(opt->arg)); /* If argument is a remote file name then tis handles any missing registration _p|_g */ + for (opt = *options; opt; opt = opt->next) { /* Loop over all options */ + if (remote_first && gmtinit_might_be_remotefile (opt->arg)) { + gmt_refresh_server (GMT); /* Refresh hash and info tables as needed */ + remote_first = false; + } + if (opt->arg[0] != '@') continue; /* No remote file argument given */ + gmt_set_unspecified_remote_registration (API, &(opt->arg)); /* If argument is a remote file name then this handles any missing registration _p|_g */ } } @@ -16491,8 +16508,6 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign gmtinit_set_today (GMT); /* Determine today's rata die value */ - gmtlib_refresh_server (GMT); /* Refresh hash and info tables if needed */ - return (GMT); } diff --git a/src/gmt_internals.h b/src/gmt_internals.h index 91f105ca03a..f63e2d91ab5 100644 --- a/src/gmt_internals.h +++ b/src/gmt_internals.h @@ -55,7 +55,6 @@ EXTERN_MSC char *dlerror (void); EXTERN_MSC int gmtlib_file_is_jpeg2000_tile (struct GMTAPI_CTRL *API, char *file); EXTERN_MSC int gmtlib_download_remote_file (struct GMT_CTRL *GMT, const char* file_name, char *path, int k_data, unsigned int mode); EXTERN_MSC int gmtlib_get_serverfile_index (struct GMTAPI_CTRL *API, const char *file); -EXTERN_MSC void gmtlib_refresh_server (struct GMT_CTRL *GMT); EXTERN_MSC bool gmtlib_module_may_get_R_from_RP (struct GMT_CTRL *GMT, const char *mod_name); EXTERN_MSC double gmtlib_distance_type (struct GMT_CTRL *GMT, double lonS, double latS, double lonE, double latE, unsigned int id); EXTERN_MSC bool gmtlib_genper_reset (struct GMT_CTRL *GMT, bool reset); diff --git a/src/gmt_prototypes.h b/src/gmt_prototypes.h index be10864ef12..82674a4552f 100644 --- a/src/gmt_prototypes.h +++ b/src/gmt_prototypes.h @@ -170,6 +170,7 @@ EXTERN_MSC double gmt_fft_any_wave (uint64_t k, unsigned int mode, struct GMT_FF /* gmt_remote.c: */ +EXTERN_MSC void gmt_refresh_server (struct GMT_CTRL *GMT); EXTERN_MSC int gmt_download_file (struct GMT_CTRL *GMT, const char *name, char *url, char *localfile, bool mode); EXTERN_MSC int gmt_set_remote_and_local_filenames (struct GMT_CTRL *GMT, const char* file, char *local_path, char *remote_path, unsigned int mode); EXTERN_MSC int gmt_remote_dataset_id (struct GMTAPI_CTRL *API, const char *file); diff --git a/src/gmt_remote.c b/src/gmt_remote.c index 051031504e0..1ae4cddad04 100644 --- a/src/gmt_remote.c +++ b/src/gmt_remote.c @@ -665,7 +665,7 @@ GMT_LOCAL int gmtremote_refresh (struct GMT_CTRL *GMT, unsigned int index) { return GMT_NOERROR; } -void gmtlib_refresh_server (struct GMT_CTRL *GMT) { +void gmt_refresh_server (struct GMT_CTRL *GMT) { /* Called once in gmt_begin from GMT_Create_Session, The following actions take place: * * The data info table is refreshed if missing or older than 24 hours. diff --git a/src/gmtget.c b/src/gmtget.c index 47235f1d491..efccb6c7128 100644 --- a/src/gmtget.c +++ b/src/gmtget.c @@ -212,6 +212,8 @@ EXTERN_MSC int GMT_gmtget (void *V_API, int mode, void *args) { double world[4] = {-180.0, +180.0, -90.0, +90.0}; struct GMT_RECORD *Out = NULL; + gmt_refresh_server (GMT); /* Refresh hash and info tables as needed since we need to know what is there */ + if (Ctrl->Q.active) { /* Must activate data output machinery for a DATASET with no numerical columns */ Out = gmt_new_record (GMT, NULL, message); if ((error = GMT_Set_Columns (API, GMT_OUT, 0, GMT_COL_FIX)) != GMT_NOERROR) Return (API->error);