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];
31  j += 2;
32  u[i++] = '/';
33  if (d[j] == '/' || d[j] == '\\') {
34  j++;
35  }
36  }
37  }
38  strcpy(u + i, d + j);
39  for (cp = u + i; *cp; ++cp) {
40  if (*cp == '\\') {
41  *cp = '/';
42  }
43  }
44  return u;
45 }
46 
47 char* hoc_dos2unixpath(const char* d) {
48 #if defined(__MINGW32__)
49  return hoc_dos2cygdrivepath(d, 1);
50 #else
51  return hoc_dos2cygdrivepath(d, 1);
52 #endif
53 }
char * hoc_dos2cygdrivepath(const char *d, int cygdrive)
Definition: d2upath.cpp:12
char * hoc_dos2unixpath(const char *d)
Definition: d2upath.cpp:47
#define assert(ex)
Definition: hocassrt.h:32
#define i
Definition: md1redef.h:12
size_t j