]> granicus.if.org Git - apache/blobdiff - support/win32/wintty.c
More splitting as suggested by minfrin.
[apache] / support / win32 / wintty.c
index e5bdbaf0468a749d4a780a627bdfc263fff61433..684ce5b52c421356f444db147dca6e32f7e950a1 100644 (file)
@@ -1,8 +1,9 @@
-/* Copyright 2001-2004 Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -15,7 +16,7 @@
 
 /* --------------------------------------------------------------------
  *
- * wintty : a Apache/WinNT support utility for monitoring and 
+ * wintty : a Apache/WinNT support utility for monitoring and
  *          reflecting user feedback from the Apache process via
  *          stdin/stdout, even as running within the service context.
  *
@@ -29,7 +30,7 @@
  *
  * Also note the isservice detection semantics, which far exceed any
  * mechanism we have discovered thus far.
- * 
+ *
  * --------------------------------------------------------------------
  */
 
 #include <stdlib.h>
 #include <stdio.h>
 
-const char *options = 
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+#define _CRT_SECURE_NO_DEPRECATE
+#pragma warning(disable: 4996)
+#endif
+
+const char *options =
 "\nwintty: a utility for echoing the stdin stream to a new console window,\n"
 "\teven when invoked from within a service (such as the Apache server.)\n"
 "\tAlso reflects the console input back to the stdout stream, allowing\n"
@@ -55,7 +61,7 @@ const char *options =
 
 BOOL verbose = FALSE;
 
-void printerr(char *fmt, ...) 
+void printerr(char *fmt, ...)
 {
     char str[1024];
     va_list args;
@@ -123,7 +129,7 @@ int main(int argc, char** argv)
                     }
                     else {
                         timeout = 0;
-                    }  
+                    }
                     break;
                 case 'v':
                     verbose = TRUE;
@@ -135,7 +141,7 @@ int main(int argc, char** argv)
                 case '?':
                     printf(options, arg0);
                     exit(1);
-               default:
+                default:
                     printf("wintty option %s not recognized, use -? for help.\n\n", *argv);
                     exit(1);
             }
@@ -162,46 +168,46 @@ int main(int argc, char** argv)
 
     hstdin = GetStdHandle(STD_INPUT_HANDLE);
     if (!hstdin || hstdin == INVALID_HANDLE_VALUE) {
-        printerr("GetStdHandle(STD_INPUT_HANDLE) failed (%d)\n", 
+        printerr("GetStdHandle(STD_INPUT_HANDLE) failed (%d)\n",
                  GetLastError());
     }
-    else if (DuplicateHandle(hproc, hstdin, hproc, &hdup, 0, 
+    else if (DuplicateHandle(hproc, hstdin, hproc, &hdup, 0,
                              isservice, DUPLICATE_SAME_ACCESS)) {
         CloseHandle(hstdin);
         hstdin = hdup;
     }
     else {
-        printerr("DupHandle(stdin [%x]) failed (%d)\n", 
+        printerr("DupHandle(stdin [%x]) failed (%d)\n",
                  hstdin, GetLastError());
     }
 
     hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
     if (!hstdout || hstdout == INVALID_HANDLE_VALUE) {
-        printerr("GetStdHandle(STD_OUTPUT_HANDLE) failed (%d)\n", 
+        printerr("GetStdHandle(STD_OUTPUT_HANDLE) failed (%d)\n",
                  GetLastError());
     }
-    else if (DuplicateHandle(hproc, hstdout, hproc, &hdup, 0, 
+    else if (DuplicateHandle(hproc, hstdout, hproc, &hdup, 0,
                              isservice, DUPLICATE_SAME_ACCESS)) {
         CloseHandle(hstdout);
         hstdout = hdup;
     }
     else {
-        printerr("DupHandle(stdout [%x]) failed (%d)\n", 
+        printerr("DupHandle(stdout [%x]) failed (%d)\n",
                  hstdout, GetLastError());
     }
 
     hstderr = GetStdHandle(STD_ERROR_HANDLE);
     if (!hstderr || hstderr == INVALID_HANDLE_VALUE) {
-        printerr("GetStdHandle(STD_ERROR_HANDLE) failed (%d)\n", 
+        printerr("GetStdHandle(STD_ERROR_HANDLE) failed (%d)\n",
                  GetLastError());
     }
-    else if (DuplicateHandle(hproc, hstderr, hproc, &hdup, 0, 
+    else if (DuplicateHandle(hproc, hstderr, hproc, &hdup, 0,
                              isservice, DUPLICATE_SAME_ACCESS)) {
         CloseHandle(hstderr);
         hstderr = hdup;
     }
     else {
-        printerr("DupHandle(stderr [%x]) failed (%d)\n", 
+        printerr("DupHandle(stderr [%x]) failed (%d)\n",
                  hstderr, GetLastError());
     }
 
@@ -210,10 +216,10 @@ int main(int argc, char** argv)
      */
     if (!FreeConsole())
         printerr("FreeConsole() failed (%d)\n", GetLastError());
-        
+
     if (isservice) {
 #ifdef WE_EVER_FIGURE_OUT_WHY_THIS_DOESNT_WORK
-       hsavedesk = GetThreadDesktop(GetCurrentThreadId());
+        hsavedesk = GetThreadDesktop(GetCurrentThreadId());
         if (!hsavedesk || hsavedesk == INVALID_HANDLE_VALUE) {
             printerr("GetThreadDesktop(GetTID()) failed (%d)\n", GetLastError());
         }
@@ -228,7 +234,7 @@ int main(int argc, char** argv)
         hdesk = OpenDesktop("Default", 0, TRUE, MAXIMUM_ALLOWED);
         if (!hdesk || hdesk == INVALID_HANDLE_VALUE) {
             printerr("OpenDesktop(Default) failed (%d)\n", GetLastError());
-        } 
+        }
         else if (!SetThreadDesktop(hdesk)) {
             printerr("SetThreadDesktop(Default) failed (%d)\n", GetLastError());
         }
@@ -239,11 +245,11 @@ int main(int argc, char** argv)
         char appbuff[MAX_PATH];
         char *appname = NULL;
         char *cmdline = GetCommandLine();
-        
+
         if (!GetModuleFileName(NULL, appbuff, sizeof(appbuff))) {
             appname = appbuff;
         }
-        
+
         memset(&si, 0, sizeof(si));
         si.cb = sizeof(si);
         si.dwFlags     = STARTF_USESHOWWINDOW
@@ -261,7 +267,7 @@ int main(int argc, char** argv)
          * receive their EOF notification.
          */
         if (CreateProcess(appname, cmdline, NULL, NULL, TRUE,
-                          CREATE_SUSPENDED | CREATE_NEW_CONSOLE, 
+                          CREATE_SUSPENDED | CREATE_NEW_CONSOLE,
                           NULL, NULL, &si, &pi)) {
             CloseHandle(si.hStdInput);
             CloseHandle(si.hStdOutput);
@@ -285,8 +291,8 @@ int main(int argc, char** argv)
         printerr("SetConsoleTitle() failed (%d)\n", GetLastError());
     }
 
-    conout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, 
-                        FILE_SHARE_READ | FILE_SHARE_WRITE, 
+    conout = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
+                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                         FALSE, OPEN_EXISTING, 0, NULL);
     if (!conout || conout == INVALID_HANDLE_VALUE) {
         printerr("CreateFile(CONOUT$) failed (%d)\n", GetLastError());
@@ -296,12 +302,12 @@ int main(int argc, char** argv)
     }
     else if (!SetConsoleMode(conout, conmode = ((conmode | newoutmode)
                                                          & ~notoutmode))) {
-        printerr("SetConsoleMode(CONOUT, 0x%x) failed (%d)\n", 
+        printerr("SetConsoleMode(CONOUT, 0x%x) failed (%d)\n",
                  conmode, GetLastError());
     }
 
-    conin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, 
-                       FILE_SHARE_READ | FILE_SHARE_WRITE, 
+    conin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
+                       FILE_SHARE_READ | FILE_SHARE_WRITE,
                        FALSE, OPEN_EXISTING, 0, NULL);
     if (!conin || conin == INVALID_HANDLE_VALUE) {
         printerr("CreateFile(CONIN$) failed (%d)\n", GetLastError());
@@ -309,9 +315,9 @@ int main(int argc, char** argv)
     else if (!GetConsoleMode(conin, &conmode)) {
         printerr("GetConsoleMode(CONIN) failed (%d)\n", GetLastError());
     }
-    else if (!SetConsoleMode(conin, conmode = ((conmode | newinmode) 
+    else if (!SetConsoleMode(conin, conmode = ((conmode | newinmode)
                                                         & ~notinmode))) {
-        printerr("SetConsoleMode(CONIN, 0x%x) failed (%d)\n", 
+        printerr("SetConsoleMode(CONIN, 0x%x) failed (%d)\n",
                  conmode, GetLastError());
     }