-/* NetHack 3.6 pcmain.c $NHDT-Date: 1449116336 2015/12/03 04:18:56 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.66 $ */
+/* NetHack 3.6 pcmain.c $NHDT-Date: 1449893255 2015/12/12 04:07:35 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.67 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
#ifdef WIN32
extern boolean getreturn_enabled; /* from sys/share/pcsys.c */
extern int redirect_stdout; /* from sys/share/pcsys.c */
+extern int GUILaunched;
+HANDLE hStdOut;
char *NDECL(exename);
char default_window_sys[] = "mswin";
+boolean NDECL(fakeconsole);
+void NDECL(freefakeconsole);
#endif
#if defined(MSWIN_GRAPHICS)
Strcpy(hackdir, dir);
}
if (argc > 1) {
+#if defined(WIN32)
+ int sfd = 0;
+ boolean tmpconsole = FALSE;
+ hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+#endif
/*
* Now we know the directory containing 'record' and
* may do a prscore().
*/
if (!strncmp(argv[1], "-s", 2)) {
#if defined(WIN32)
- int sfd = (int) _fileno(stdout);
+
+#if 0
+ if (!hStdOut) {
+ tmpconsole = fakeconsole();
+ }
+#endif
+ /*
+ * Check to see if we're redirecting to a file.
+ */
+ sfd = (int) _fileno(stdout);
redirect_stdout = (sfd >= 0) ? !isatty(sfd) : 0;
- if (!redirect_stdout) {
+ if (!redirect_stdout && !hStdOut) {
raw_printf(
"-s is not supported for the Graphical Interface\n");
nethack_exit(EXIT_SUCCESS);
initoptions();
#endif
prscore(argc, argv);
+#ifdef WIN32
+ if (tmpconsole) {
+ getreturn("to exit");
+ freefakeconsole();
+ tmpconsole = FALSE;
+ }
+#endif
nethack_exit(EXIT_SUCCESS);
}
#endif
/* Don't initialize the window system just to print usage */
if (!strncmp(argv[1], "-?", 2) || !strncmp(argv[1], "/?", 2)) {
+#if 0
+ if (!hStdOut) {
+ GUILaunched = 0;
+ tmpconsole = fakeconsole();
+ }
+#endif
nhusage();
+
+#ifdef WIN32
+ if (tmpconsole) {
+ getreturn("to exit");
+ freefakeconsole();
+ tmpconsole = FALSE;
+ }
+#endif
nethack_exit(EXIT_SUCCESS);
}
}
#ifdef WIN32
static char exenamebuf[PATHLEN];
+extern HANDLE hConIn;
+extern HANDLE hConOut;
+boolean has_fakeconsole;
char *
exename()
tmp2++;
return tmp2;
}
+
+boolean
+fakeconsole(void)
+{
+ if (!hStdOut) {
+ HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+ HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
+
+ if (!hStdOut && !hStdIn) {
+ /* Bool rval; */
+ AllocConsole();
+ AttachConsole(GetCurrentProcessId());
+ /* rval = SetStdHandle(STD_OUTPUT_HANDLE, hWrite); */
+ freopen("CON", "w", stdout);
+ freopen("CON", "r", stdin);
+ }
+ has_fakeconsole = TRUE;
+ }
+
+ /* Obtain handles for the standard Console I/O devices */
+ hConIn = GetStdHandle(STD_INPUT_HANDLE);
+ hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
+#if 0
+ if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE)) {
+ /* Unable to set control handler */
+ cmode = 0; /* just to have a statement to break on for debugger */
+ }
+#endif
+ return has_fakeconsole;
+}
+void freefakeconsole()
+{
+ if (has_fakeconsole) {
+ FreeConsole();
+ }
+}
#endif
#define EXEPATHBUFSZ 256
-/* NetHack 3.6 nttty.c $NHDT-Date: 1431737067 2015/05/16 00:44:27 $ $NHDT-Branch: master $:$NHDT-Revision: 1.63 $ */
+/* NetHack 3.6 nttty.c $NHDT-Date: 1449893262 2015/12/12 04:07:42 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.64 $ */
/* Copyright (c) NetHack PC Development Team 1993 */
/* NetHack may be freely redistributed. See license for details. */
DWORD cmode;
long mask;
+ GUILaunched = 0;
+
try :
/* The following lines of code were suggested by
* Bob Landau of Microsoft WIN32 Developer support,
* we were launched from the command prompt, or from
* the NT program manager. M. Allison
*/
- hStdOut
- = GetStdHandle(STD_OUTPUT_HANDLE);
+ hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
+
if (hStdOut) {
GetConsoleScreenBufferInfo(hStdOut, &origcsbi);
- GUILaunched = ((origcsbi.dwCursorPosition.X == 0)
- && (origcsbi.dwCursorPosition.Y == 0));
- if ((origcsbi.dwSize.X <= 0) || (origcsbi.dwSize.Y <= 0))
- GUILaunched = 0;
} else if (mode) {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);
freopen("CON", "r", stdin);
}
mode = 0;
- goto try
- ;
- } else
+ goto try;
+ } else {
return;
+ }
+
+ /* Obtain handles for the standard Console I/O devices */
+ hConIn = GetStdHandle(STD_INPUT_HANDLE);
+ hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
load_keyboard_handler();
/* Initialize the function pointer that points to
*/
nt_kbhit = nttty_kbhit;
- /* Obtain handles for the standard Console I/O devices */
- hConIn = GetStdHandle(STD_INPUT_HANDLE);
- hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
#if 0
hConIn = CreateFile("CONIN$",
GENERIC_READ |GENERIC_WRITE,