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 
8 #include "d2upath.cpp"
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  buf = new char[strlen(args) + 3 * strlen(nh) + 200 + strlen(temp)];
73 
74 #ifdef MINGW
75 #if 0
76  if (nh[1] == ':') {
77  nh[1] = nh[0];
78  nh[0] = '/';
79  }
80 #endif
81 
82  sprintf(buf,
83  "%s\\mingw\\usr\\bin\\bash.exe %s/lib/mos2nrn3.sh %s %s %s",
84  nrnhome,
85  nh,
86  temp,
87  nh,
88  args);
89 #else
90  sprintf(buf, "%s\\bin\\sh %s/lib/mos2nrn.sh %s %s", nrnhome, nh, nh, args);
91 #endif
92  msg = new char[strlen(buf) + 100];
93  err = WinExec(buf, SW_SHOW);
94  if (err < 32) {
95  sprintf(msg, "Cannot WinExec %s\n", buf);
96  MessageBox(0, msg, "NEURON", MB_OK);
97  }
98  return 0;
99 }
char * hoc_dos2unixpath(const char *d)
Definition: d2upath.cpp:47
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
char buf[512]
Definition: init.cpp:13
static int argc
Definition: inithoc.cpp:53
static char ** argv
Definition: inithoc.cpp:54
char * getenv(const char *s)
Definition: macprt.cpp:67
#define i
Definition: md1redef.h:12
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
#define cnt
Definition: spt2queue.cpp:19
#define NULL
Definition: sptree.h:16