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

Function gmt_dos_path_fix

src/gmt_common_string.c:303–349  ·  view source on GitHub ↗

Turn '/c/dir/...' paths into 'c:/dir/...' * Must do it in a loop since dir may be several ';'-separated dirs */

Source from the content-addressed store, hash-verified

301/* Turn '/c/dir/...' paths into 'c:/dir/...'
302 * Must do it in a loop since dir may be several ';'-separated dirs */
303void gmt_dos_path_fix (char *dir) {
304 size_t n, k;
305
306 if (!dir || (n = strlen (dir)) < 2U)
307 /* Given NULL or too short dir to work */
308 return;
309
310 if (!strncmp (dir, "/cygdrive/", 10U))
311 /* May happen for example when Cygwin sets GMT_SHAREDIR */
312 gmt_strlshift (dir, 9); /* Chop '/cygdrive' */
313
314 /* Replace dumb backslashes with slashes */
315 gmt_strrepc (dir, '\\', '/');
316
317 /* If dir begins with '/' and is 2 long, as in '/c', replace with 'c:' */
318 if (n == 2U && dir[0] == '/') {
319 dir[0] = dir[1];
320 dir[1] = ':';
321 return;
322 }
323
324 /* If dir is longer than 2 and, e.g., '/c/', replace with 'c:/' */
325 if (n > 2U && dir[0] == '/' && dir[2] == '/' && isalpha ((int)dir[1])) {
326 dir[0] = dir[1];
327 dir[1] = ':';
328 }
329
330 /* Do the same with dirs separated by ';' but do not replace '/c/j/...' with 'c:j:/...' */
331 for (k = 4; k < n-2; k++) {
332 if ( (dir[k-1] == ';' && dir[k] == '/' && dir[k+2] == '/' && isalpha ((int)dir[k+1])) ) {
333 dir[k] = dir[k+1];
334 dir[k+1] = ':';
335 }
336 }
337
338 /* Replace ...:C:/... by ...;C:/... as that was a multi-path set by an e.g. bash shell (msys or cygwin) */
339 for (k = 4; k < n-2; k++) {
340 if ((dir[k-1] == ':' && dir[k+1] == ':' && dir[k+2] == '/' && isalpha ((int)dir[k])) )
341 dir[k-1] = ';';
342 else if ((dir[k-1] == ':' && dir[k] == '/' && dir[k+2] == '/' && isalpha ((int)dir[k+1])) ) {
343 /* The form ...:/C/... will become ...;C:/... */
344 dir[k-1] = ';';
345 dir[k] = dir[k+1];
346 dir[k+1] = ':';
347 }
348 }
349}
350#endif
351
352#if !defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)

Callers 7

gmt_DCW_operationFunction · 0.85
gmtinit_set_envFunction · 0.85
ifFunction · 0.85
mgd77_set_homeFunction · 0.85
spotter_initFunction · 0.85
x2sys_set_homeFunction · 0.85
x2sys_path_initFunction · 0.85

Calls 2

gmt_strlshiftFunction · 0.85
gmt_strrepcFunction · 0.85

Tested by

no test coverage detected