NEURON
mswinprt.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 #ifdef MINGW
4 
5 #include <unistd.h>
6 #include <windows.h>
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <errno.h>
12 #include "hoc.h"
13 #include "../mswin/extra/d2upath.cpp"
14 
15 #include "gui-redirect.h"
16 
17 
18 extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj);
19 extern double (*nrnpy_object_to_double_)(Object*);
20 
21 extern char* neuron_home;
22 extern char* neuron_home_dos;
23 extern void hoc_quit();
24 
25 static HCURSOR wait_cursor;
26 static HCURSOR old_cursor;
27 #if HAVE_IV
28 extern int bad_install_ok;
29 #else
30 int bad_install_ok;
31 #endif // HAVE_IV
32 extern FILE* hoc_redir_stdout;
33 void setneuronhome(const char* p) {
34  // if the program lives in .../bin/neuron.exe
35  // and .../lib exists then use ... as the
36  // NEURONHOME
37  char buf[256];
38  char* s;
39  int i, j;
40  // printf("p=|%s|\n", p);
41  bad_install_ok = 1;
42  GetModuleFileName(NULL, buf, 256);
43  for (i = strlen(buf); i >= 0 && buf[i] != '\\'; --i) {
44  ;
45  }
46  buf[i] = '\0'; // /neuron.exe gone
47  // printf("setneuronhome |%s|\n", buf);
48  for (j = strlen(buf); j >= 0 && buf[j] != '\\'; --j) {
49  ;
50  }
51  buf[j] = '\0'; // /bin gone
52  neuron_home_dos = static_cast<char*>(emalloc(strlen(buf) + 1));
53  strcpy(neuron_home_dos, buf);
55  return;
56 }
57 void HandleOutput(char* s) {
58  printf("%s", s);
59 }
60 static long exception_filter(LPEXCEPTION_POINTERS p) {
61  // hoc_execerror("unhandled exception", "");
62  // return EXCEPTION_CONTINUE_EXECUTION;
63  static int n = 0;
64  ++n;
65  if (n == 1) {
67  "\nUnhandled Exception. This usually means a bad memory \n\
68 address.",
69  "It is not possible to make a judgment as to whether it is safe\n\
70 to continue. If this happened while compiling a template, you will have to\n\
71 quit.");
72  }
73  if (n == 2) {
74  MessageBox(NULL,
75  "Second Unhandled Exception: Quitting NEURON. You will be asked to save \
76 any unsaved em buffers before exiting.",
77  "NEURON Internal ERROR",
78  MB_OK);
79  hoc_quit();
80  }
81  return EXCEPTION_EXECUTE_HANDLER;
82 }
83 
84 void hoc_set_unhandled_exception_filter() {
85  SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) exception_filter);
86 }
87 BOOL hoc_copyfile(const char* src, const char* dest) {
88  return CopyFile(src, dest, FALSE);
89 }
90 
91 static FILE* dll_stdio_[] = {(FILE*) 0x0, (FILE*) 0x20, (FILE*) 0x40};
92 
93 void nrn_mswindll_stdio(FILE* i, FILE* o, FILE* e) {
94  if (o != dll_stdio_[1]) {
95  printf("nrn_mswindll_stdio stdio in dll = %p but expected %p\n", o, dll_stdio_[1]);
96  }
97  dll_stdio_[0] = i;
98  dll_stdio_[1] = o;
99  dll_stdio_[2] = e;
100 }
101 
102 void hoc_forward2back(char* s) {
103  char* cp;
104  for (cp = s; *cp; ++cp) {
105  if (*cp == '/') {
106  *cp = '\\';
107  }
108  }
109 }
110 
111 extern "C" char* hoc_back2forward(char* s) {
112  char* cp = s;
113  while (*cp) {
114  if (*cp == '\\') {
115  *cp = '/';
116  }
117  ++cp;
118  }
119  return s;
120 }
121 
122 #if HAVE_IV
123 void ivoc_win32_cleanup();
124 #endif
125 
126 void hoc_win32_cleanup() {
127  char buf[256];
128  char* path;
129 #if HAVE_IV
130  ivoc_win32_cleanup();
131 #endif
132  path = getenv("TEMP");
133  if (path) {
134  sprintf(buf, "%s/oc%d.hl", path, getpid());
135  unlink(buf);
136  // DebugMessage("unlinked %s\n", buf);
137  }
138 }
139 
140 void hoc_win_exec(void) {
141  int i;
142  i = SW_SHOW;
143  if (ifarg(2)) {
144  i = (int) chkarg(2, -1000, 1000);
145  }
146  i = WinExec(gargstr(1), i);
147  ret();
148  pushx((double) i);
149 }
150 
151 void hoc_winio_show(int b) {}
152 
153 #if !defined(__MWERKS__)
154 int getpid() {
155  return 1;
156 }
157 #endif
158 
159 void hoc_Plt() {
161  ret();
162  pushx(0.);
163 }
164 void hoc_Setcolor() {
165  TRY_GUI_REDIRECT_DOUBLE("setcolor", NULL);
166  ret();
167  pushx(0.);
168 }
169 void hoc_Lw() {
170  ret();
171  pushx(0.);
172 }
173 
174 #endif // MINGW
char * neuron_home_dos
Definition: code2.cpp:206
void pushx(double d)
Definition: code.cpp:658
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)
double chkarg(int, double low, double high)
Definition: code2.cpp:638
#define FALSE
Definition: err.c:56
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
double(* nrnpy_object_to_double_)(Object *)
Definition: xmenu.cpp:14
char buf[512]
Definition: init.cpp:13
#define TRY_GUI_REDIRECT_DOUBLE(name, obj)
Definition: gui-redirect.h:58
void hoc_quit(void)
Definition: hoc.cpp:1162
#define gargstr
Definition: hocdec.h:14
void setneuronhome(const char *)
Definition: ivocmain.cpp:186
const char * neuron_home
Definition: hoc_init.cpp:404
int ifarg(int)
Definition: code.cpp:1581
hoc_Setcolor()
Definition: macprt.cpp:155
hoc_Lw()
Definition: macprt.cpp:160
hoc_Plt()
Definition: macprt.cpp:150
char * getenv(const char *s)
Definition: macprt.cpp:67
int hoc_copyfile(const char *src, const char *dest)
Definition: macprt.cpp:81
#define i
Definition: md1redef.h:12
char * name
Definition: init.cpp:16
char * emalloc(unsigned n)
Definition: list.cpp:166
#define printf
Definition: mwprefix.h:26
int const size_t const size_t n
Definition: nrngsl.h:11
size_t p
size_t j
char * hoc_back2forward(char *s)
char * hoc_forward2back(char *s)
#define e
Definition: passive0.cpp:22
#define ret
Definition: redef.h:123
o
Definition: seclist.cpp:175
#define NULL
Definition: sptree.h:16
Definition: hocdec.h:227