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 <cstdlib>
9 #include <cstring>
10 #include <cassert>
11 
12 char* hoc_dos2unixpath(const char* d) {
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* cp = nullptr;
17  auto* const u = static_cast<char*>(malloc(strlen(d) + 12));
18  assert(u);
19  size_t i = 0;
20  int j = 0;
21  if (d[0] && d[1] == ':') {
22  strcpy(u, "/cygdrive/");
23  i = strlen(u);
24  u[i++] = d[0];
25  j += 2;
26  u[i++] = '/';
27  if (d[j] == '/' || d[j] == '\\') {
28  j++;
29  }
30  }
31  strcpy(u + i, d + j);
32  for (cp = u + i; *cp; ++cp) {
33  if (*cp == '\\') {
34  *cp = '/';
35  }
36  }
37  return u;
38 }
#define i
Definition: md1redef.h:19
char * hoc_dos2unixpath(const char *d)
Definition: d2upath.cpp:12
#define assert(ex)
Definition: hocassrt.h:24
size_t j