diff --git a/vm/Config.windows.nt b/vm/Config.windows.nt new file mode 100644 index 0000000000..8c67b11c19 --- /dev/null +++ b/vm/Config.windows.nt @@ -0,0 +1,8 @@ +LIBS = -lm +EXE_SUFFIX=-nt +DLL_SUFFIX=-nt +PLAF_DLL_OBJS += vm/os-windows-nt.o +PLAF_EXE_OBJS += vm/resources.o +PLAF_EXE_OBJS += vm/main-windows-nt.o +CFLAGS += -mwindows +include vm/Config.windows diff --git a/vm/Config.windows.nt.x86.32 b/vm/Config.windows.nt.x86.32 index adc69b1e27..a8d4931b4d 100644 --- a/vm/Config.windows.nt.x86.32 +++ b/vm/Config.windows.nt.x86.32 @@ -1,7 +1,2 @@ -LIBS = -lm -EXE_SUFFIX=-nt -DLL_SUFFIX=-nt -PLAF_DLL_OBJS += vm/os-windows-nt.o -PLAF_EXE_OBJS += vm/resources.o -PLAF_EXE_OBJS += vm/main-windows-nt.o -include vm/Config.x86.32 vm/Config.windows +include vm/Config.windows.nt +include vm/Config.x86.32 diff --git a/vm/debug.c b/vm/debug.c index 55ffcadca6..2692bdf59c 100755 --- a/vm/debug.c +++ b/vm/debug.c @@ -213,6 +213,7 @@ void dump_objects(F_FIXNUM type) void factorbug(void) { reset_stdio(); + open_console(); printf("Starting low level debugger...\n"); printf(" Basic commands:\n"); diff --git a/vm/factor.c b/vm/factor.c index 690f5d490c..8719416b72 100755 --- a/vm/factor.c +++ b/vm/factor.c @@ -26,6 +26,7 @@ void default_parameters(F_PARAMETERS *p) p->secure_gc = false; p->fep = false; + p->console = false; } /* Get things started */ @@ -110,6 +111,8 @@ void init_factor_from_args(F_CHAR *image, int argc, F_CHAR **argv, bool embedded p.fep = true; else if(STRNCMP(argv[i],STR_FORMAT("-i="),3) == 0) p.image = argv[i] + 3; + else if(STRCMP(argv[i],STR_FORMAT("-console")) == 0) + p.console = true ; } init_factor(&p); @@ -135,6 +138,9 @@ void init_factor_from_args(F_CHAR *image, int argc, F_CHAR **argv, bool embedded nest_stacks(); + if(p.console) + open_console(); + if(p.fep) factorbug(); diff --git a/vm/image.h b/vm/image.h index 52b666254e..3774263031 100755 --- a/vm/image.h +++ b/vm/image.h @@ -32,6 +32,7 @@ typedef struct { CELL code_size; bool secure_gc; bool fep; + bool console; } F_PARAMETERS; void load_image(F_PARAMETERS *p); diff --git a/vm/os-unix.c b/vm/os-unix.c index 303c01491a..437a528fb8 100644 --- a/vm/os-unix.c +++ b/vm/os-unix.c @@ -256,3 +256,5 @@ void reset_stdio(void) fcntl(0,F_SETFL,0); fcntl(1,F_SETFL,0); } + +void open_console(void) { } diff --git a/vm/os-unix.h b/vm/os-unix.h index cbce7de985..85f760b5aa 100755 --- a/vm/os-unix.h +++ b/vm/os-unix.h @@ -39,3 +39,4 @@ s64 current_millis(void); void sleep_millis(CELL msec); void reset_stdio(void); +void open_console(void); diff --git a/vm/os-windows-ce.c b/vm/os-windows-ce.c index 1465e0c89f..e68a6385ae 100755 --- a/vm/os-windows-ce.c +++ b/vm/os-windows-ce.c @@ -46,3 +46,5 @@ void c_to_factor_toplevel(CELL quot) { c_to_factor(quot); } + +void open_console(void) { } diff --git a/vm/os-windows-ce.h b/vm/os-windows-ce.h index 959de89634..f1d6df6f3d 100755 --- a/vm/os-windows-ce.h +++ b/vm/os-windows-ce.h @@ -24,3 +24,4 @@ char *getenv(char *name); s64 current_millis(void); void c_to_factor_toplevel(CELL quot); +void open_console(void); diff --git a/vm/os-windows-nt.c b/vm/os-windows-nt.c index baa0a06c4b..afd1e0ed3b 100755 --- a/vm/os-windows-nt.c +++ b/vm/os-windows-nt.c @@ -88,3 +88,17 @@ void c_to_factor_toplevel(CELL quot) c_to_factor(quot); RemoveVectoredExceptionHandler((void*)exception_handler); } + +void open_console(void) +{ + if(!console_open) + { + if(!AttachConsole(ATTACH_PARENT_PROCESS)) + { + if(AllocConsole()) + console_open = true; + } + else + console_open = true; + } +} diff --git a/vm/os-windows-nt.h b/vm/os-windows-nt.h index f7c56c129d..9e451f0301 100755 --- a/vm/os-windows-nt.h +++ b/vm/os-windows-nt.h @@ -18,3 +18,5 @@ typedef char F_SYMBOL; void c_to_factor_toplevel(CELL quot); long exception_handler(PEXCEPTION_POINTERS pe); +bool console_open; +void open_console(void);