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