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  buf[i] = '\0'; // /neuron.exe gone
19  for (i=strlen(buf); i >= 0 && buf[i] != '\\'; --i) {;}
20  buf[i] = '\0'; // /bin gone
21  nrnhome = new char[strlen(buf)+1];
22  strcpy(nrnhome, buf);
23 }
24 
25 static char* argstr(int argc, char** argv) {
26  // put args into single string, each with enclosing ""
27  int i, j, cnt;
28  char* s;
29  char* a;
30  char* u;
31  cnt = 100;
32  for (i=1; i < argc; ++i) {
33  cnt += strlen(argv[i])+20;
34  }
35  s = new char[cnt];
36  j = 0;
37  for (i=1; i < argc; ++i) {
38  s[j++] = '"';
39  u = hoc_dos2unixpath(argv[i]);
40  for (a = u; *a; ++a) {
41  s[j++] = *a;
42  }
43  s[j++] = '"';
44  if (i < argc-1) {
45  s[j++] = ' ';
46  }
47  free(u);
48  }
49  s[j] = '\0';
50  return s;
51 }
52 
53 int main(int argc, char** argv) {
54  int err;
55  char* buf;
56  char* args;
57  char* msg;
58  char* temp;
59 
60  setneuronhome();
62  args = argstr(argc, argv);
63  temp = getenv("TEMP");
64  if (!temp) {temp = strdup("c:/tmp"); }
65  temp = hoc_dos2unixpath(temp);
66  buf = new char[strlen(args) + 3*strlen(nh) + 200 + strlen(temp)];
67 
68 #if defined(MINGW)
69 #if 0
70  if (nh[1] == ':') {
71  nh[1] = nh[0];
72  nh[0] = '/';
73  }
74 #endif
75 
76  sprintf(buf, "%s\\mingw\\usr\\bin\\bash.exe %s/lib/mos2nrn3.sh %s %s %s", nrnhome, nh, temp, nh, args);
77 #else
78  sprintf(buf, "%s\\bin\\sh %s/lib/mos2nrn.sh %s %s", nrnhome, nh, nh, args);
79 #endif
80  msg = new char[strlen(buf) + 100];
81  err = WinExec(buf, SW_SHOW);
82  if (err < 32) {
83  sprintf(msg, "Cannot WinExec %s\n", buf);
84  MessageBox(0, msg, "NEURON", MB_OK);
85  }
86  return 0;
87 }
char * nrnhome
Definition: mos2nrn.cpp:10
char * hoc_dos2unixpath(const char *d)
Definition: d2upath.cpp:46
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
static char * argstr(int argc, char **argv)
Definition: mos2nrn.cpp:25
static void setneuronhome()
Definition: mos2nrn.cpp:13
_CONST char * s
Definition: system.cpp:74
#define cnt
Definition: spt2queue.cpp:19
char * getenv(const char *s)
Definition: macprt.cpp:67
size_t j
int main(int argc, char **argv)
Definition: mos2nrn.cpp:53
#define i
Definition: md1redef.h:12
char buf[512]
Definition: init.cpp:13
static int argc
Definition: inithoc.cpp:53
char * nh
Definition: mos2nrn.cpp:11
return NULL
Definition: cabcode.cpp:461
static char ** argv
Definition: inithoc.cpp:54