]> granicus.if.org Git - nethack/commitdiff
fix windows bugs H4030 and H4045 (123 and 138)
authornhmall <mjnh@persona.ca>
Sat, 12 Dec 2015 04:08:01 +0000 (23:08 -0500)
committernhmall <mjnh@persona.ca>
Sat, 12 Dec 2015 04:08:01 +0000 (23:08 -0500)
 Changes to be committed:
modified:   sys/share/pcmain.c
modified:   sys/winnt/nttty.c
modified:   sys/winnt/stubs.c

Bug 123 Report 4030:
Minor thing I've noticed - if I quit the game, at the "Hit <Enter> to end."
prompt, if I close the window rather than pressing Enter, I get the following:

Bug 138  - #H4045:
 "nethack -s" leads to "-s is not supported for the Graphical Interface".
 That's wrong.
 (The Graphical Interface comes with "nethackw".)

sys/share/pcmain.c
sys/winnt/nttty.c
sys/winnt/stubs.c

index 0276d61f828a4f2488016833e10834aac5795af9..b8cad7718514669cb74b125675a0941f2bc2b08c 100644 (file)
@@ -1,4 +1,4 @@
-/* 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. */
 
@@ -55,8 +55,12 @@ extern void FDECL(nethack_exit, (int));
 #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)
@@ -279,16 +283,30 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
             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);
@@ -302,6 +320,13 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
                 initoptions();
 #endif
                 prscore(argc, argv);
+#ifdef WIN32
+                if (tmpconsole) {
+                    getreturn("to exit");
+                    freefakeconsole();
+                    tmpconsole = FALSE;
+                }
+#endif
                 nethack_exit(EXIT_SUCCESS);
             }
 
@@ -313,7 +338,21 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
 #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);
             }
         }
@@ -804,6 +843,9 @@ authorize_wizard_mode()
 
 #ifdef WIN32
 static char exenamebuf[PATHLEN];
+extern HANDLE hConIn;
+extern HANDLE hConOut;
+boolean has_fakeconsole;
 
 char *
 exename()
@@ -826,6 +868,42 @@ 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
index 7c0c72cf1e84abaa32c6922fddc7d731e1a1df1a..37e810bcc55bf5a59db101a572ef9489ae31347c 100644 (file)
@@ -1,4 +1,4 @@
-/* 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. */
 
@@ -258,6 +258,8 @@ int mode;
     DWORD cmode;
     long mask;
 
+    GUILaunched = 0;
+
     try :
         /* The following lines of code were suggested by
          * Bob Landau of Microsoft WIN32 Developer support,
@@ -265,14 +267,10 @@ int mode;
          * 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);
@@ -286,10 +284,14 @@ int mode;
             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
@@ -297,9 +299,6 @@ int mode;
     */
     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,
index 924a8f9ea7cef54096ad12c6b691071ac0d4f7e2..cf88bd9a3a527006ec6349db3edc19c6a4ff4520 100644 (file)
@@ -7,6 +7,7 @@
 
 int GUILaunched;
 struct window_procs mswin_procs = { "guistubs" };
+
 void
 mswin_destroy_reg()
 {
@@ -36,6 +37,7 @@ char *argv[];
     return 0;
 }
 #endif
+
 #endif /* GUISTUB */
 
 /* =============================================== */
@@ -43,7 +45,10 @@ char *argv[];
 #ifdef TTYSTUB
 
 #include "hack.h"
+#include "win32api.h"
 
+HANDLE hConIn;
+HANDLE hConOut;
 int GUILaunched;
 struct window_procs tty_procs = { "ttystubs" };