Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See if using ; under Windows work better for dirs #1124

Merged
merged 6 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/rst/source/GMT_Docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4286,7 +4286,7 @@ Variable $GMT_DATADIR and parameter DIR_DATA
the current directory. This allows maintainers to consolidate large
data files and to simplify scripting that use these files since the
absolute path need not be specified. Separate multiple directories
with colons (:) – under Windows use semi-colons (;). Any directory
with commas. Any directory
name that ends in a trailing slash (/) will be searched recursively
(not under Windows).

Expand Down
2 changes: 1 addition & 1 deletion doc/rst/source/GMT_Docs_classic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4335,7 +4335,7 @@ Variable $GMT_DATADIR and parameter DIR_DATA
the current directory. This allows maintainers to consolidate large
data files and to simplify scripting that use these files since the
absolute path need not be specified. Separate multiple directories
with colons (:) – under Windows use semi-colons (;). Any directory
with commas. Any directory
name that ends in a trailing slash (/) will be searched recursively
(not under Windows).

Expand Down
6 changes: 4 additions & 2 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2819,17 +2819,19 @@ GMT_LOCAL int gmtinit_set_env (struct GMT_CTRL *GMT) {
/* Determine GMT_DATADIR (data directories) */

if ((this_c = getenv ("GMT_DATADIR")) != NULL) { /* GMT_DATADIR was set */
if (strchr (this_c, PATH_SEPARATOR) || access (this_c, R_OK) == 0) {
if (strchr (this_c, ',') || strchr (this_c, PATH_SEPARATOR) || access (this_c, R_OK) == 0) {
/* A list of directories or a single directory that is accessible */
GMT->session.DATADIR = strdup (this_c);
gmt_dos_path_fix (GMT->session.DATADIR);
}
#ifdef WIN32
else if (strchr(this_c, ':')) { /* May happen to have ':' as a path separator when running a MSYS bash shell*/
GMT->session.DATADIR = strdup(this_c);
gmt_dos_path_fix(GMT->session.DATADIR);
gmt_dos_path_fix (GMT->session.DATADIR);
}
#endif
gmt_replace_backslash_in_path (GMT->session.DATADIR);
gmt_strrepc (GMT->session.DATADIR, PATH_SEPARATOR, ','); /* Use comma for OS-independent separator */
}

/* Determine GMT_TMPDIR (for isolation mode). Needs to exist use it. */
Expand Down
10 changes: 9 additions & 1 deletion src/gmt_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4831,7 +4831,7 @@ char *gmt_getdatapath (struct GMT_CTRL *GMT, const char *stem, char *path, int m
size_t L;
bool found;
char *udir[6] = {GMT->session.USERDIR, GMT->session.DATADIR, GMT->session.CACHEDIR, NULL, NULL, NULL}, dir[PATH_MAX];
char path_separator[2] = {PATH_SEPARATOR, '\0'}, serverdir[PATH_MAX] = {""}, srtm1dir[PATH_MAX] = {""}, srtm3dir[PATH_MAX] = {""};
char path_separator[2] = {',', '\0'}, serverdir[PATH_MAX] = {""}, srtm1dir[PATH_MAX] = {""}, srtm3dir[PATH_MAX] = {""};
#ifdef HAVE_DIRENT_H_
size_t N;
#endif /* HAVE_DIRENT_H_ */
Expand Down Expand Up @@ -8564,6 +8564,14 @@ int gmt_rename_file (struct GMT_CTRL *GMT, const char *oldfile, const char *newf
return errno;
}

void gmt_replace_backslash_in_path (char *dir) {
size_t k = 0;
while (dir[k]) {
if (dir[k] == '\\') dir[k] = '/';
k++;
}
}

/*! . */
void gmt_set_column (struct GMT_CTRL *GMT, unsigned int direction, unsigned int col, enum gmt_col_enum type) {
/* Sets the column type for this input or output column or both (dir == GMT_IO) */
Expand Down
1 change: 1 addition & 0 deletions src/gmt_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ EXTERN_MSC int gmt_set_psfilename (struct GMT_CTRL *GMT);

/* gmt_io.c: */

EXTERN_MSC void gmt_replace_backslash_in_path (char *dir);
EXTERN_MSC void gmt_disable_bhi_opts (struct GMT_CTRL *GMT);
EXTERN_MSC void gmt_reenable_bhi_opts (struct GMT_CTRL *GMT);
EXTERN_MSC void gmt_insert_tableheader (struct GMT_CTRL *GMT, struct GMT_DATATABLE *T, char *txt);
Expand Down
40 changes: 10 additions & 30 deletions src/movie.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,16 +874,12 @@ int GMT_movie (void *V_API, int mode, void *args) {
char *extension[3] = {"sh", "csh", "bat"}, *load[3] = {"source", "source", "call"}, *rmfile[3] = {"rm -f", "rm -f", "del"};
char *rmdir[3] = {"rm -rf", "rm -rf", "rd /s /q"}, *export[3] = {"export ", "export ", ""};
char *mvfile[3] = {"mv -f", "mv -rf", "move"}, *sc_call[3] = {"bash ", "csh ", "start /B"};
char var_token[4] = "$$%", path_sep[4] = "::;";
char var_token[4] = "$$%";
char init_file[PATH_MAX] = {""}, state_tag[GMT_LEN16] = {""}, state_prefix[GMT_LEN64] = {""}, param_file[PATH_MAX] = {""}, cwd[PATH_MAX] = {""};
char pre_file[PATH_MAX] = {""}, post_file[PATH_MAX] = {""}, main_file[PATH_MAX] = {""}, line[PATH_MAX] = {""}, version[GMT_LEN32] = {""};
char string[GMT_LEN128] = {""}, extra[GMT_LEN256] = {""}, cmd[GMT_LEN256] = {""}, cleanup_file[PATH_MAX] = {""}, L_txt[GMT_LEN128] = {""};
char png_file[PATH_MAX] = {""}, topdir[PATH_MAX] = {""}, datadir[PATH_MAX] = {""}, frame_products[GMT_LEN32] = {MOVIE_RASTER_FORMAT};
#ifdef _WIN32
char dir_sep = '\\';
#else
char dir_sep = '/';
#endif
double percent = 0.0, L_col = 0;

FILE *fp = NULL;
Expand Down Expand Up @@ -1038,10 +1034,11 @@ int GMT_movie (void *V_API, int mode, void *args) {
}

/* We use DATADIR to include the top and working directory so any files we supply or create can be found while inside frame directory */

if (GMT->session.DATADIR) /* Prepend initial and subdir as new datadirs to the existing search list */
sprintf (datadir, "%s%c%s%c%s", topdir, path_sep[Ctrl->In.mode], cwd, path_sep[Ctrl->In.mode], GMT->session.DATADIR);
sprintf (datadir, "%s,%s,%s", topdir, cwd, GMT->session.DATADIR); /* Start with topdir */
else /* Set the initial and prefix subdirectory as data dirs */
sprintf (datadir, "%s%c%s", topdir, path_sep[Ctrl->In.mode], cwd);
sprintf (datadir, "%s,%s", topdir, cwd);
if (Ctrl->W.active && strlen (Ctrl->W.dir) > 2) { /* Also append a specific work directory with data files that we should search */
char work_dir[PATH_MAX] = {""};
#ifdef WIN32
Expand All @@ -1050,12 +1047,13 @@ int GMT_movie (void *V_API, int mode, void *args) {
if (Ctrl->W.dir[0] != '/') /* Not hard path */
#endif
/* Prepend cwd to the given relative path and update Ctrl->D.dir */
sprintf (work_dir, "%c%s%c%s", path_sep[Ctrl->In.mode], topdir, dir_sep, Ctrl->W.dir);
sprintf (work_dir, ",%s,%s", topdir, Ctrl->W.dir);
else
sprintf (work_dir, "%c%s", path_sep[Ctrl->In.mode], Ctrl->W.dir);
sprintf (work_dir, ",%s", Ctrl->W.dir);
strcat (datadir, work_dir);
}

gmt_replace_backslash_in_path (datadir); /* Since we will be fprintf the path we must use // for a slash */

/* Create the initialization file with settings common to all frames */

sprintf (init_file, "movie_init.%s", extension[Ctrl->In.mode]);
Expand Down Expand Up @@ -1406,20 +1404,10 @@ int GMT_movie (void *V_API, int mode, void *args) {
sprintf (extra, "A+g%s+n", Ctrl->G.fill);
else
sprintf (extra, "A+n"); /* No cropping, image size is fixed */
if (!access ("movie_background.ps", R_OK)) { /* Need to place a background layer first (which is in parent dir when loop script is run) */
#ifdef WIN32
strcat (extra, ",Mb..\\movie_background.ps");
#else
if (!access ("movie_background.ps", R_OK)) /* Need to place a background layer first (which is in parent dir when loop script is run) */
strcat (extra, ",Mb../movie_background.ps");
#endif
}
if (!access ("movie_foreground.ps", R_OK)) { /* Need to append foreground layer at end (which is in parent dir when script is run) */
#ifdef WIN32
strcat (extra, ",Mf..\\movie_foreground.ps");
#else
if (!access ("movie_foreground.ps", R_OK)) /* Need to append foreground layer at end (which is in parent dir when script is run) */
strcat (extra, ",Mf../movie_foreground.ps");
#endif
}
if (Ctrl->H.active) { /* Must pass the DownScaleFactor option to psconvert */
sprintf (line, ",H%d", Ctrl->H.factor);
strncat (extra, line, GMT_LEN128);
Expand Down Expand Up @@ -1519,19 +1507,11 @@ int GMT_movie (void *V_API, int mode, void *args) {
else
sprintf (extra, "A+n"); /* No cropping, image size is fixed */
if (!access ("movie_background.ps", R_OK)) { /* Need to place a background layer first (which will be in parent dir when loop script is run) */
#ifdef WIN32
strcat (extra, ",Mb..\\movie_background.ps");
#else
strcat (extra, ",Mb../movie_background.ps");
#endif
layers = true;
}
if (!access ("movie_foreground.ps", R_OK)) { /* Need to append foreground layer at end (which will be in parent dir when script is run) */
#ifdef WIN32
strcat (extra, ",Mf..\\movie_foreground.ps");
#else
strcat (extra, ",Mf../movie_foreground.ps");
#endif
layers = true;
}
if (Ctrl->H.active) { /* Must pass the DownScaleFactor option to psconvert */
Expand Down