wintty.c revision 9bc83c8de0be46245af97e1196cf12b7e70761f3
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*/
/* --------------------------------------------------------------------
*
* reflecting user feedback from the Apache process via
*
* Originally contributed by William Rowe <wrowe@covalent.net>
*
* Note: this implementation is _very_ experimental, and error handling
* is far from complete. Using it as a cgi or pipe process allows the
* programmer to discover if facilities such as reliable piped logs
* are working as expected, or answer operator prompts that would
* otherwise be discarded by the service process.
*
* Also note the isservice detection semantics, which far exceed any
* mechanism we have discovered thus far.
*
* --------------------------------------------------------------------
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
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"
"\tthe operator to respond to prompts from the context of a service.\n\n"
"Syntax: %s [opts] [-t \"Window Title\"]\n\n"
" opts: -c{haracter} or -l{ine} input\n"
"\t-q{uiet} or -e{cho} input\n"
"\t-u{nprocessed} or -p{rocessed} input\n"
"\t-n{owrap} or -w{rap} output lines\n"
"\t-f{ormatted} or -r{aw} output lines\n"
"\t-v{erbose} error reporting (for debugging)\n"
"\t-? for this message\n\n";
{
char str[1024];
return;
}
typedef struct feedback_args_t {
{
while (--argc) {
++argv;
case 'c':
notinmode |= ENABLE_LINE_INPUT; break;
case 'l':
newinmode |= ENABLE_LINE_INPUT; break;
case 'q':
notinmode |= ENABLE_ECHO_INPUT; break;
case 'e':
newinmode |= ENABLE_ECHO_INPUT; break;
case 'u':
notinmode |= ENABLE_PROCESSED_INPUT; break;
case 'p':
newinmode |= ENABLE_PROCESSED_INPUT; break;
case 'n':
notoutmode |= ENABLE_WRAP_AT_EOL_OUTPUT; break;
case 'w':
newoutmode |= ENABLE_WRAP_AT_EOL_OUTPUT; break;
case 'r':
notoutmode |= ENABLE_PROCESSED_OUTPUT; break;
case 'f':
newoutmode |= ENABLE_PROCESSED_OUTPUT; break;
case 'v':
break;
case 't':
--argc;
break;
case '?':
exit(1);
default:
exit(1);
}
}
else {
exit(1);
}
}
hproc = GetCurrentProcess();
}
}
}
}
}
}
}
}
}
else
SetLastError(0);
if (!FreeConsole())
if (isservice) {
}
else if (!SetProcessWindowStation(hwinsta)) {
}
}
}
else if (!SetThreadDesktop(hdesk)) {
}
}
if (!AllocConsole()) {
}
}
}
else if (!herrout) {
}
}
}
}
}
}
break;
}
else {
if (!SetConsoleTitle(str)) {
}
}
FreeConsole();
if (isservice) {
if (!SetProcessWindowStation(hsavewinsta)) {
len = GetLastError();
}
if (!SetThreadDesktop(hsavedesk)) {
len = GetLastError();
}
}
return 0;
}
{
char *str[1024];
break;
return 0;
}