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

Function gmt_getsharepath

src/gmt_io.c:5602–5665  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

5600
5601/*! . */
5602char *gmt_getsharepath (struct GMT_CTRL *GMT, const char *subdir, const char *stem, const char *suffix, char *path, int mode) {
5603 /* stem is the prefix of the file, e.g., mysymbol for mysymbol.def
5604 * subdir is an optional subdirectory name in the $GMT_SHAREDIR directory.
5605 * suffix is an optional suffix to append to name
5606 * path is the full path to the file in question
5607 * Returns full pathname if a workable path was found
5608 * Looks for file stem in current directory, $GMT_USERDIR (default ~/.gmt), $GMT_SHAREDIR/subdir and $GMT_SHAREDIR.
5609 */
5610
5611 /* First look in the current working directory, but must be nonzero size */
5612
5613 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "GMT: 0. Will try to find subdir=%s stem = %s suffix=%s\n", subdir, stem, suffix);
5614 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "GMT: 1. gmt_getsharepath trying current dir\n");
5615 sprintf (path, "%s%s", stem, suffix);
5616
5617 if (!access (path, mode)) { /* Yes, found it in current directory */
5618 /* But is it nonzero size? */
5619 struct stat S;
5620 if (stat (path, &S) == 0 && S.st_size == 0) { /* Got empty file to skip */
5621 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "gmt_getsharepath: Skip empty file %s in current directory\n", path);
5622 goto try_other_paths;
5623 }
5624 return (path); /* Success! Found a nonzero sized file */
5625 }
5626
5627try_other_paths:
5628
5629 /* Do not continue when full pathname is given */
5630
5631 if (stem[0] == '/') return (NULL);
5632#ifdef WIN32
5633 if (stem[0] && stem[1] == ':') return (NULL);
5634#endif
5635
5636 /* Not found, see if there is a file in the user's GMT_USERDIR (~/.gmt) directory */
5637
5638 if (GMT->session.USERDIR) {
5639 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "GMT: 2. gmt_getsharepath trying USERDIR %s\n", GMT->session.USERDIR);
5640 /* Try to get file from $GMT_USERDIR */
5641 sprintf (path, "%s/%s%s", GMT->session.USERDIR, stem, suffix);
5642 if (!access (path, mode)) return (path);
5643 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "GMT: 3. gmt_getsharepath trying USERDIR subdir %s/%s\n", GMT->session.USERDIR, subdir);
5644 /* Try to get file from $GMT_USERDIR/subdir */
5645 sprintf (path, "%s/%s/%s%s", GMT->session.USERDIR, subdir, stem, suffix);
5646 if (!access (path, mode)) return (path);
5647 }
5648
5649 /* Try to get file from $GMT_SHAREDIR/subdir */
5650
5651 if (subdir) {
5652 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "GMT: 4. gmt_getsharepath trying SHAREDIR subdir %s/%s\n", GMT->session.SHAREDIR, subdir);
5653 sprintf (path, "%s/%s/%s%s", GMT->session.SHAREDIR, subdir, stem, suffix);
5654 if (!access (path, R_OK)) return (path);
5655 }
5656
5657 /* Lastly try to get file from $GMT_SHAREDIR */
5658
5659 GMT_Report (GMT->parent, GMT_MSG_DEBUG, "GMT: 5. gmt_getsharepath trying SHAREDIR %s\n", GMT->session.SHAREDIR);

Callers 15

gmt_importproj4Function · 0.85
gmt_locate_custom_symbolFunction · 0.85
gmt_list_custom_symbolsFunction · 0.85
GMT_Read_DataFunction · 0.85
gmtdcw_get_pathFunction · 0.85
gmtinit_setshorthandFunction · 0.85
gmtinit_get_languageFunction · 0.85
gmtinit_init_fontsFunction · 0.85
gmtinit_load_user_mediaFunction · 0.85
gmtinit_update_themeFunction · 0.85
gmt_get_ellipsoidFunction · 0.85
gmtshore_getpathnameFunction · 0.85

Calls 2

GMT_ReportFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected