mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed io in runnerw(PY-1305)
added runner for mac
This commit is contained in:
@@ -8,9 +8,12 @@ void PrintUsage() {
|
||||
printf("Usage: runnerw.exe <app> <args>\n");
|
||||
printf("where <app> is console application and <args> it's arguments.\n");
|
||||
printf("\n");
|
||||
printf("Runner invokes console application as a process with inherited input and output streams.\n");
|
||||
printf("Input stream is scanned for presence of 2 char 255(IAC) and 243(BRK) sequence and generates Ctrl-Break event in that case.\n");
|
||||
printf("Also in case of all type of event(Ctrl-C, Close, Shutdown etc) Ctrl-Break event is generated.\n");
|
||||
printf(
|
||||
"Runner invokes console application as a process with inherited input and output streams.\n");
|
||||
printf(
|
||||
"Input stream is scanned for presence of 2 char 255(IAC) and 243(BRK) sequence and generates Ctrl-Break event in that case.\n");
|
||||
printf(
|
||||
"Also in case of all type of event(Ctrl-C, Close, Shutdown etc) Ctrl-Break event is generated.\n");
|
||||
|
||||
exit(0);
|
||||
}
|
||||
@@ -35,11 +38,11 @@ void CtrlBreak() {
|
||||
|
||||
BOOL is_iac = FALSE;
|
||||
|
||||
char IAC = 'a';
|
||||
char BRK = 'b';
|
||||
char IAC = 255;
|
||||
char BRK = 243;
|
||||
|
||||
BOOL Scan(char buf[], int count) {
|
||||
for (int i = 0; i<count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (is_iac) {
|
||||
if (buf[i] == BRK) {
|
||||
CtrlBreak();
|
||||
@@ -55,21 +58,19 @@ BOOL Scan(char buf[], int count) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CtrlHandler( DWORD fdwCtrlType )
|
||||
{
|
||||
switch( fdwCtrlType )
|
||||
{
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_CLOSE_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
CtrlBreak();
|
||||
return( TRUE );
|
||||
case CTRL_BREAK_EVENT:
|
||||
return FALSE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
BOOL CtrlHandler(DWORD fdwCtrlType) {
|
||||
switch (fdwCtrlType) {
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_CLOSE_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
CtrlBreak();
|
||||
return (TRUE);
|
||||
case CTRL_BREAK_EVENT:
|
||||
return FALSE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
@@ -107,7 +108,7 @@ int main(int argc, char * argv[]) {
|
||||
|
||||
GetStartupInfo(&si);
|
||||
|
||||
si.dwFlags = STARTF_USESTDHANDLES ;
|
||||
si.dwFlags = STARTF_USESTDHANDLES;
|
||||
si.wShowWindow = SW_HIDE;
|
||||
si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
|
||||
@@ -119,11 +120,11 @@ int main(int argc, char * argv[]) {
|
||||
char* c_args = new char[args.size() + 1];
|
||||
strcpy(c_args, args.c_str());
|
||||
|
||||
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
|
||||
SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
|
||||
|
||||
if (!CreateProcess(c_app, // Application name
|
||||
c_args, // Application arguments
|
||||
NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE , NULL, NULL, &si, &pi)) {
|
||||
if (!CreateProcess(c_app, // Application name
|
||||
c_args, // Application arguments
|
||||
NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi)) {
|
||||
ErrorMessage("CreateProcess");
|
||||
CloseHandle(newstdin);
|
||||
CloseHandle(write_stdin);
|
||||
@@ -135,7 +136,7 @@ int main(int argc, char * argv[]) {
|
||||
unsigned long b_write;
|
||||
unsigned long avail;
|
||||
|
||||
char buf[1];
|
||||
char buf[1];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
for (;;) {
|
||||
@@ -144,12 +145,11 @@ int main(int argc, char * argv[]) {
|
||||
if (exit != STILL_ACTIVE)
|
||||
break;
|
||||
|
||||
char c;
|
||||
std::cin >> c;
|
||||
// char c = fgetc();
|
||||
buf[0] = c;
|
||||
Scan(buf, 1);
|
||||
WriteFile(write_stdin, buf, 1, &b_write, NULL);
|
||||
char c;
|
||||
std::cin >> c;
|
||||
buf[0] = c;
|
||||
Scan(buf, 1);
|
||||
WriteFile(write_stdin, buf, 1, &b_write, NULL);
|
||||
}
|
||||
|
||||
CloseHandle(pi.hThread);
|
||||
|
||||
Reference in New Issue
Block a user