NEURON
d2upath.cpp
Go to the documentation of this file.
1 /*
2 input dos path, output unix (or mingw) path. The output
3 string may range from the same size as the input string
4 up to 11 characters longer.
5 the output string should be freed with free() when no longer needed.
6 */
7 
8 #include <stdlib.h>
9 #include <string.h>
10 #include <assert.h>
11 
12 char* hoc_dos2cygdrivepath(const char* d, int cygdrive) {
13  /* translate x: and x:/ and x:\, to /cygdrive/x/ */
14  /* and all backslashes to forward slashes */
15  /* or, for mingw, just backslashes to forward slashes */
16  char *u;
17  char *cp;
18  int i, j;
19 #if 0
20  u = new char[strlen(d) + 12];
21 #else
22  u = static_cast<char*>(malloc(strlen(d) + 12));
23  assert(u);
24 #endif
25  i = j = 0;
26  if (cygdrive) {
27  if (d[0] && d[1] == ':') {
28  strcpy(u, "/cygdrive/");
29  i = strlen(u);
30  u[i++] = d[0]; j += 2;
31  u[i++] = '/';
32  if (d[j] == '/' || d[j] == '\\'){
33  j++;
34  }
35  }
36  }
37  strcpy(u+i, d+j);
38  for (cp = u+i; *cp; ++cp) {
39  if (*cp == '\\') {
40  *cp = '/';
41  }
42  }
43  return u;
44 }
45 
46 char* hoc_dos2unixpath(const char* d) {
47 #if defined(__MINGW32__)
48  return hoc_dos2cygdrivepath(d, 1);
49 #else
50  return hoc_dos2cygdrivepath(d, 1);
51 #endif
52 }
53 
#define assert(ex)
Definition: hocassrt.h:26
char * hoc_dos2unixpath(const char *d)
Definition: d2upath.cpp:46
char * hoc_dos2cygdrivepath(const char *d, int cygdrive)
Definition: d2upath.cpp:12
size_t j
#define i
Definition: md1redef.h:12