]> granicus.if.org Git - nethack/commitdiff
fix W343-1 open win32 bug from known bugs page
authornethack.allison <nethack.allison>
Tue, 25 Apr 2006 01:16:54 +0000 (01:16 +0000)
committernethack.allison <nethack.allison>
Tue, 25 Apr 2006 01:16:54 +0000 (01:16 +0000)
W343-1 Redirecting score output through a pipe doesn't work.

sys/share/pcmain.c
sys/share/pcsys.c
sys/winnt/nttty.c
win/win32/mswproc.c

index 3172cdf5b713cb2a661ba0a8f307e4c2e343d7fe..a93e5c5b08d35399fdc71930486796df2eebbf23 100644 (file)
@@ -54,6 +54,7 @@ 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 */
 #endif
 
 #if defined(MSWIN_GRAPHICS)
@@ -227,14 +228,22 @@ char *argv[];
                 * may do a prscore().
                 */
                if (!strncmp(argv[1], "-s", 2)) {
-#if !defined(MSWIN_GRAPHICS)
-# if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
-                       chdirx(hackdir,0);
+#if defined(MSWIN_GRAPHICS) || defined(WIN32CON)
+                       int sfd = _fileno(stdout);
+                       redirect_stdout = (sfd >= 0) ? !isatty(sfd) : 0;
+
+# ifdef MSWIN_GRAPHICS
+                       if (!redirect_stdout) {
+                          raw_printf("-s is not supported for the Graphical Interface\n");
+                          nethack_exit(EXIT_SUCCESS);
+                       }
 # endif
+#endif
+
+#if defined(CHDIR) && !defined(NOCWD_ASSUMPTIONS)
+                       chdirx(hackdir,0);
+#endif
                        prscore(argc, argv);
-#else
-                       raw_printf("-s is not supported for the Graphical Interface\n");
-#endif /*MSWIN_GRAPHICS*/
                        nethack_exit(EXIT_SUCCESS);
                }
 
index 23b12e4706f467bdaa1357c7f4a21c0bb278b2cc..fed9de9c106b027f1f4eee9117db49e8d3a5cec7 100644 (file)
@@ -390,6 +390,7 @@ char *name;
 
 #ifdef WIN32
 boolean getreturn_enabled;
+int redirect_stdout;
 #endif
 
 void
index e71622dbdb443ec77273a62db1d0b0b2b7b328cb..fc4be4451e341a2ffb03abe59cdd4a0b88825a38 100644 (file)
@@ -56,6 +56,7 @@ INPUT_RECORD ir;
  * from the command line. 
  */
 int GUILaunched;
+extern int redirect_stdout;
 static BOOL FDECL(CtrlHandler, (DWORD));
 
 #ifdef PORT_DEBUG
@@ -941,8 +942,12 @@ msmsg VA_DECL(const char *, fmt)
        VA_INIT(fmt, const char *);
        Vsprintf(buf, fmt, VA_ARGS);
        VA_END();
-       xputs(buf);
-       if (ttyDisplay) curs(BASE_WINDOW, cursor.X+1, cursor.Y);
+       if (redirect_stdout)
+               fprintf(stdout,"%s",buf);
+       else {
+               xputs(buf);
+               if (ttyDisplay) curs(BASE_WINDOW, cursor.X+1, cursor.Y);
+       }
        return;
 }
 
index 5248fe0c8d14f123884acb84c2820855fccf497b..c6c6387dc6ea1d4e4e89bb7f265390cb50a91356 100644 (file)
@@ -1290,8 +1290,13 @@ void mswin_raw_print(const char *str)
 {
        TCHAR wbuf[255];
     logDebug("mswin_raw_print(%s)\n", str);
-       if( str && *str )
+       if( str && *str ) {
+           extern int redirect_stdout;
+           if (!redirect_stdout)
                NHMessageBox(GetNHApp()->hMainWnd, NH_A2W(str, wbuf, sizeof(wbuf)), MB_ICONINFORMATION | MB_OK );
+           else
+               fprintf(stdout,"%s",str);
+       }
 }
 
 /*