GenericMappingTools / gmt

The Generic Mapping Tools
https://www.generic-mapping-tools.org
Other
858 stars 359 forks source link

Odd use of gmtinit_parse_dash_option to get version #4034

Closed PaulWessel closed 4 years ago

PaulWessel commented 4 years ago

As we try to avoid having any code that calls exit, I find this code in gmtinit_parse_dash_option:

/*! parse any --PARAM[=value] arguments */
GMT_LOCAL int gmtinit_parse_dash_option (struct GMT_CTRL *GMT, char *text) {
    int n;
    char *this_c = NULL, message[GMT_LEN128] = {""};
    if (!text)
        return (GMT_NOERROR);

    /* print version and exit */
    if (strcmp (text, "version") == 0) {
        snprintf (message, GMT_LEN128, "%s\n", GMT_PACKAGE_VERSION_WITH_GIT_REVISION);
        GMT->parent->print_func (stdout, message);
        /* cannot call gmt_M_free_options() from here, so we are leaking on exit.
         * struct GMTAPI_CTRL *G = GMT->parent;
         * if (GMT_Destroy_Session (G))
         *   GMT_exit (GMT, GMT_PARSE_ERROR); */
        GMT_exit (GMT, GMT_NOERROR);
    }

    /* print GMT folders and exit */
    if (strcmp (text, "show-datadir") == 0) {
        snprintf (message, GMT_LEN128, "%s\n", GMT->session.SHAREDIR);
        GMT->parent->print_func (stdout, message);
        /* leaking on exit same as above. */
        GMT_exit (GMT, GMT_NOERROR);
    }

Since the gmt driver processes --version and --show-data-dir, I assume these were placed here for use from external environments like python and Julia (please remind me if you remember, @joa-quim and @seisman ). We have other ways to get the version from the API - not sure about the datadir.

seisman commented 4 years ago

Not used in PyGMT.

joa-quim commented 4 years ago

Don't use it Julia either.

seisman commented 4 years ago

Closed by #4097