From ea571c54dd2f219ab0c2b8d5339c6dfc63352fcd Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 21 Nov 2007 14:27:25 -0600 Subject: [PATCH 1/3] Add open_console() command line parameter and stubs on each platform Add Config.windows.nt --- vm/Config.windows.nt | 8 ++++++++ vm/Config.windows.nt.x86.32 | 9 ++------- vm/factor.c | 6 ++++++ vm/image.h | 1 + vm/os-unix.c | 2 ++ vm/os-unix.h | 1 + vm/os-windows-ce.c | 2 ++ vm/os-windows-ce.h | 1 + vm/os-windows-nt.c | 4 ++++ vm/os-windows-nt.h | 1 + 10 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 vm/Config.windows.nt 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/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..7ea8155072 100755 --- a/vm/os-windows-nt.c +++ b/vm/os-windows-nt.c @@ -88,3 +88,7 @@ void c_to_factor_toplevel(CELL quot) c_to_factor(quot); RemoveVectoredExceptionHandler((void*)exception_handler); } + +void open_console(void) +{ +} diff --git a/vm/os-windows-nt.h b/vm/os-windows-nt.h index f7c56c129d..f74c7b1883 100755 --- a/vm/os-windows-nt.h +++ b/vm/os-windows-nt.h @@ -18,3 +18,4 @@ typedef char F_SYMBOL; void c_to_factor_toplevel(CELL quot); long exception_handler(PEXCEPTION_POINTERS pe); +void open_console(void); From 01682c1cd2dcb5f95db776e4a2d1c6441c0f52aa Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 21 Nov 2007 14:31:36 -0600 Subject: [PATCH 2/3] Open a console when calling factorbug() --- vm/debug.c | 1 + 1 file changed, 1 insertion(+) 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"); From 0da81b301833a87dde90a620daa397908a2bbbdc Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 21 Nov 2007 14:47:15 -0600 Subject: [PATCH 3/3] Reuse existing console if present, or else open a new console, when -console is supplied --- vm/os-windows-nt.c | 10 ++++++++++ vm/os-windows-nt.h | 1 + 2 files changed, 11 insertions(+) diff --git a/vm/os-windows-nt.c b/vm/os-windows-nt.c index 7ea8155072..afd1e0ed3b 100755 --- a/vm/os-windows-nt.c +++ b/vm/os-windows-nt.c @@ -91,4 +91,14 @@ void c_to_factor_toplevel(CELL quot) 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 f74c7b1883..9e451f0301 100755 --- a/vm/os-windows-nt.h +++ b/vm/os-windows-nt.h @@ -18,4 +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);