NEURON
neuron.cpp
Go to the documentation of this file.
1 // this is the wrapper that allows one to create shortcuts and
2 // associate hoc files with neuron.exe without having to consider
3 // the issues regarding shells and the rxvt console. The latter
4 // can be given extra arguments in the lib/neuron.sh file which
5 // finally executes nrniv.exe. Nrniv.exe can be run by itself if
6 // it does not need a console or system("command")
7 
8 #include <windows.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 
12 #include "d2upath.cpp"
13 
14 char* nrnhome;
15 char* nh;
16 
17 static void setneuronhome() {
18  int i, j;
19  char buf[256];
20  GetModuleFileName(NULL, buf, 256);
21  for (i=strlen(buf); i >= 0 && buf[i] != '\\'; --i) {;}
22  buf[i] = '\0'; // /neuron.exe gone
23  for (i=strlen(buf); i >= 0 && buf[i] != '\\'; --i) {;}
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, escaping spaces in args.
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  // convert dos to unix path and space to @@
43  // the latter will be converted back to space in src/oc/hoc.c
44  // cygwin 7 need to convert x: and x:/ and x:\ to
45  // /cygdrive/x/
46  u = hoc_dos2unixpath(argv[i]);
47  for (a = u; *a; ++a) {
48  if (*a == ' ') {
49  s[j++] = '@';
50  s[j++] = '@';
51  }else{
52  s[j++] = *a;
53  }
54  }
55  if (i < argc-1) {
56  s[j++] = ' ';
57  }
58  free(u);
59  }
60  s[j] = '\0';
61  return s;
62 }
63 
64 int main(int argc, char** argv) {
65  int err;
66  char* buf;
67  char* args;
68  char* msg;
69 
70 #if !defined(MINGW)
71  ShowWindow(GetConsoleWindow(), SW_HIDE);
72 #endif
73  setneuronhome();
75  args = argstr(argc, argv);
76  buf = new char[strlen(args) + 6*strlen(nh) + 200];
77 #if defined(MINGW)
78  //sprintf(buf, "%s\\mingw\\bin\\bash.exe -rcfile %s/lib/nrnstart.bsh -i %s/lib/neuron2.sh nrngui %s", nrnhome, nh, nh, args);
79 #if 0
80  if (nh[1] == ':') {
81  nh[1] = nh[0];
82  nh[0] = '/';
83  }
84 #endif
85  sprintf(buf, "%s\\mingw\\usr\\bin\\bash.exe -i %s/lib/neuron3.sh %s nrngui %s", nrnhome, nh, nh, args);
86 //MessageBox(0, buf, "NEURON", MB_OK);
87 #else
88  sprintf(buf, "%s\\bin\\mintty -c %s/lib/minttyrc %s/bin/bash --rcfile %s/lib/nrnstart.bsh %s/lib/neuron.sh %s %s", nrnhome, nh, nh, nh, nh, nh, args);
89 #endif
90  msg = new char[strlen(buf) + 100];
91  err = WinExec(buf, SW_SHOW);
92  if (err < 32) {
93  sprintf(msg, "Cannot WinExec %s\n", buf);
94  MessageBox(0, msg, "NEURON", MB_OK);
95  }
96  return 0;
97 }
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)
int main(int argc, char **argv)
Definition: neuron.cpp:64
_CONST char * s
Definition: system.cpp:74
char * nh
Definition: neuron.cpp:15
#define cnt
Definition: spt2queue.cpp:19
size_t j
static void setneuronhome()
Definition: neuron.cpp:17
char * nrnhome
Definition: neuron.cpp:14
static char * argstr(int argc, char **argv)
Definition: neuron.cpp:29
#define i
Definition: md1redef.h:12
char buf[512]
Definition: init.cpp:13
static int argc
Definition: inithoc.cpp:53
return NULL
Definition: cabcode.cpp:461
static char ** argv
Definition: inithoc.cpp:54