MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtinit_set_env

Function gmtinit_set_env

src/gmt_init.c:3719–3931  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

3717
3718/*! . */
3719GMT_LOCAL int gmtinit_set_env (struct GMT_CTRL *GMT) {
3720 char *this_c = NULL, path[PATH_MAX+1];
3721 static char *how[2] = {"detected", "created"};
3722 unsigned int u = 0, c = 0;
3723 int err;
3724 struct GMTAPI_CTRL *API = GMT->parent;
3725 struct stat S;
3726
3727#ifdef SUPPORT_EXEC_IN_BINARY_DIR
3728 /* If SUPPORT_EXEC_IN_BINARY_DIR is defined we try to set the share dir to
3729 * ${GMT_SOURCE_DIR}/share and the user dir to ${GMT_BINARY_DIR}/share in
3730 * order to simplify debugging and running in GMT_BINARY_DIR, e.g., when
3731 * debugging with Xcode or Visual Studio. This saves us from setting the
3732 * env variables GMT_SHAREDIR and GMT_USERDIR and we do not have to install
3733 * src/share in its destination dir. */
3734
3735 /* Only true, when we are running in a subdir of GMT_BINARY_DIR_SRC_DEBUG: */
3736 bool running_in_bindir_src = !strncmp (GMT->init.runtime_bindir, GMT_BINARY_DIR_SRC_DEBUG, strlen(GMT_BINARY_DIR_SRC_DEBUG));
3737#endif
3738
3739 /* Determine GMT->session.SHAREDIR (directory containing coast, cpt, etc. subdirectories) */
3740
3741 /* Note: gmtinit_set_env cannot use GMT_Report because the verbose level is not yet set */
3742
3743 if ((this_c = getenv ("GMT6_SHAREDIR")) != NULL && !access (this_c, F_OK|R_OK)) /* GMT6_SHAREDIR was set to a valid directory */
3744 GMT->session.SHAREDIR = gmt_strdup_noquote (this_c);
3745 else if ((this_c = getenv ("GMT5_SHAREDIR")) != NULL && !access (this_c, F_OK|R_OK)) /* GMT5_SHAREDIR was set to a valid directory */
3746 GMT->session.SHAREDIR = gmt_strdup_noquote (this_c);
3747 else if ((this_c = getenv ("GMT_SHAREDIR")) != NULL && !access (this_c, F_OK|R_OK)) /* GMT_SHAREDIR was set to a valid directory */
3748 GMT->session.SHAREDIR = gmt_strdup_noquote (this_c);
3749#ifdef SUPPORT_EXEC_IN_BINARY_DIR
3750 else if (running_in_bindir_src)
3751 /* Use ${GMT_SOURCE_DIR}/share to simplify debugging and running in GMT_BINARY_DIR */
3752 GMT->session.SHAREDIR = gmt_strdup_noquote (GMT_SHARE_DIR_DEBUG);
3753#endif
3754 else if (!access (GMT_SHARE_DIR, F_OK|R_OK)) /* Found in hardcoded GMT_SHARE_DIR pointing to an existent directory */
3755 GMT->session.SHAREDIR = gmt_strdup_noquote (GMT_SHARE_DIR);
3756 else {
3757 /* SHAREDIR still not found, make a smart guess based on runpath: */
3758 if (gmt_guess_sharedir (path, GMT->init.runtime_bindir))
3759 GMT->session.SHAREDIR = gmt_strdup_noquote (path);
3760 else {
3761 /* Still not found */
3762 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Could not locate share directory for GMT.\n");
3763 return GMT_RUNTIME_ERROR;
3764 }
3765 }
3766
3767 gmt_dos_path_fix (GMT->session.SHAREDIR);
3768 gmtinit_trim_off_any_slash_at_end (GMT->session.SHAREDIR);
3769 GMT_Report (API, GMT_MSG_DEBUG, "GMT->session.SHAREDIR = %s\n", GMT->session.SHAREDIR);
3770
3771 /* Determine HOMEDIR (user home directory) */
3772
3773 if ((this_c = getenv ("HOME")) != NULL) /* HOME was set */
3774 GMT->session.HOMEDIR = gmt_strdup_noquote (this_c);
3775#ifdef WIN32
3776 else if ((this_c = getenv ("USERPROFILE")) != NULL) /* USERPROFILE was set */

Callers 1

gmtinit_new_GMT_ctrlFunction · 0.85

Calls 9

gmt_strdup_noquoteFunction · 0.85
gmt_dos_path_fixFunction · 0.85
GMT_ReportFunction · 0.85
strdupFunction · 0.85
gmt_mkdirFunction · 0.85
gmt_strrepcFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected