NEURON
mos2nrn.cpp
Go to the documentation of this file.
1 // this is a copy of neuron.exe but no space handling and calls
2 // mos2nrn.sh
3 
4 #include <windows.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <cstdio>
8 #include "d2upath.h"
9 
10 char* nrnhome;
11 char* nh;
12 
13 static void setneuronhome() {
14  int i, j;
15  char buf[256];
16  GetModuleFileName(NULL, buf, 256);
17  for (i = strlen(buf); i >= 0 && buf[i] != '\\'; --i) {
18  ;
19  }
20  buf[i] = '\0'; // /neuron.exe gone
21  for (i = strlen(buf); i >= 0 && buf[i] != '\\'; --i) {
22  ;
23  }
24  buf[i] = '\0'; // /bin gone
25  nrnhome = new char[strlen(buf) + 1];
26  strcpy(nrnhome, buf);
27 }
28 
29 static char* argstr(int argc, char** argv) {
30  // put args into single string, each with enclosing ""
31  int i, j, cnt;
32  char* s;
33  char* a;
34  char* u;
35  cnt = 100;
36  for (i = 1; i < argc; ++i) {
37  cnt += strlen(argv[i]) + 20;
38  }
39  s = new char[cnt];
40  j = 0;
41  for (i = 1; i < argc; ++i) {
42  s[j++] = '"';
43  u = hoc_dos2unixpath(argv[i]);
44  for (a = u; *a; ++a) {
45  s[j++] = *a;
46  }
47  s[j++] = '"';
48  if (i < argc - 1) {
49  s[j++] = ' ';
50  }
51  free(u);
52  }
53  s[j] = '\0';
54  return s;
55 }
56 
57 int main(int argc, char** argv) {
58  int err;
59  char* buf;
60  char* args;
61  char* msg;
62  char* temp;
63 
64  setneuronhome();
66  args = argstr(argc, argv);
67  temp = getenv("TEMP");
68  if (!temp) {
69  temp = strdup("c:/tmp");
70  }
71  temp = hoc_dos2unixpath(temp);
72  auto const bufsz = strlen(args) + 3 * strlen(nh) + 200 + strlen(temp);
73  buf = new char[bufsz];
74 
75 #ifdef MINGW
76 #if 0
77  if (nh[1] == ':') {
78  nh[1] = nh[0];
79  nh[0] = '/';
80  }
81 #endif
82 
83  std::snprintf(buf,
84  bufsz,
85  "%s\\mingw\\usr\\bin\\bash.exe %s/lib/mos2nrn3.sh %s %s %s",
86  nrnhome,
87  nh,
88  temp,
89  nh,
90  args);
91 #else
92  std::snprintf(buf, bufsz, "%s\\bin\\sh %s/lib/mos2nrn.sh %s %s", nrnhome, nh, nh, args);
93 #endif
94  auto const sz = strlen(buf) + 100;
95  msg = new char[sz];
96  err = WinExec(buf, SW_SHOW);
97  if (err < 32) {
98  std::snprintf(msg, sz, "Cannot WinExec %s\n", buf);
99  MessageBox(0, msg, "NEURON", MB_OK);
100  }
101  delete[] msg;
102  return 0;
103 }
#define cnt
Definition: tqueue.hpp:44
#define i
Definition: md1redef.h:19
char * hoc_dos2unixpath(const char *d)
Definition: d2upath.cpp:12
char buf[512]
Definition: init.cpp:13
static int argc
Definition: inithoc.cpp:45
static char ** argv
Definition: inithoc.cpp:46
char * nrnhome
Definition: mos2nrn.cpp:10
int main(int argc, char **argv)
Definition: mos2nrn.cpp:57
static char * argstr(int argc, char **argv)
Definition: mos2nrn.cpp:29
static void setneuronhome()
Definition: mos2nrn.cpp:13
char * nh
Definition: mos2nrn.cpp:11
size_t j
s
Definition: multisend.cpp:521
#define NULL
Definition: spdefs.h:105