Changeset 4502 for trunk/src/kernel32/console.cpp
- Timestamp:
- Oct 20, 2000, 1:46:48 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/console.cpp
r3976 r4502 1 /* $Id: console.cpp,v 1.2 1 2000-08-10 02:19:54 phallerExp $ */1 /* $Id: console.cpp,v 1.22 2000-10-20 11:46:46 sandervl Exp $ */ 2 2 3 3 /* … … 65 65 #define INCL_DOSMODULEMGR 66 66 #define INCL_VIO 67 #define INCL_KBD 67 68 #define INCL_AVIO 68 69 #include <os2wrap.h> //Odin32 OS/2 api wrappers 69 70 70 71 #include <win32type.h> 72 #include <win32api.h> 71 73 #include <misc.h> 72 74 … … 80 82 #include "conout.h" 81 83 #include "conbuffer.h" 84 #include "conbuffervio.h" 82 85 83 86 #include "conprop.h" … … 85 88 #include "heapstring.h" 86 89 87 #define DBG_LOCALLOG 90 #define DBG_LOCALLOG DBG_console 88 91 #include "dbglocal.h" 89 92 90 91 /***********************************92 * PH: fixups for missing os2win.h *93 ***********************************/94 95 93 #include <os2sel.h> 96 97 extern "C"98 {99 void _System _O32_SetLastError(DWORD dwError);100 DWORD _System _O32_GetLastError(void);101 LPSTR _System _O32_GetCommandLine(void);102 void _System _O32_ExitProcess(UINT exitcode);103 HANDLE _System _O32_GetStdHandle(DWORD dwDevice);104 DWORD _System _O32_GetFileType(HANDLE hFile);105 106 inline void SetLastError(DWORD a)107 {108 USHORT sel = GetFS();109 110 _O32_SetLastError(a);111 SetFS(sel);112 }113 114 inline DWORD GetLastError()115 {116 DWORD yyrc;117 USHORT sel = GetFS();118 119 yyrc = _O32_GetLastError();120 SetFS(sel);121 122 return yyrc;123 }124 125 inline LPSTR GetCommandLine()126 {127 LPSTR yyrc;128 USHORT sel = GetFS();129 130 yyrc = _O32_GetCommandLine();131 SetFS(sel);132 133 return yyrc;134 }135 136 inline void ExitProcess(UINT a)137 {138 USHORT sel = GetFS();139 140 _O32_ExitProcess(a);141 SetFS(sel);142 }143 144 inline HANDLE GetStdHandle(DWORD a)145 {146 HANDLE yyrc;147 USHORT sel = GetFS();148 149 yyrc = _O32_GetStdHandle(a);150 SetFS(sel);151 152 return yyrc;153 }154 155 inline DWORD GetFileType(HANDLE a)156 {157 DWORD yyrc;158 USHORT sel = GetFS();159 160 yyrc = _O32_GetFileType(a);161 SetFS(sel);162 163 return yyrc;164 }165 166 }167 94 168 95 /***************************************************************************** … … 181 108 static ICONSOLEGLOBALS ConsoleGlobals; 182 109 static ICONSOLEINPUT ConsoleInput; 183 110 BOOL flVioConsole = FALSE; 184 111 185 112 /***************************************************************************** … … 247 174 *****************************************************************************/ 248 175 249 APIRET iConsoleInit( void)/* creation of the console subsystem */250 { 251 APIRET rc; 176 APIRET iConsoleInit(BOOL fVioConsole) /* creation of the console subsystem */ 177 { 178 APIRET rc; /* API return code */ 252 179 ULONG ulPostCount; /* semaphore post counter */ 253 180 254 181 182 flVioConsole = fVioConsole; 255 183 256 184 if (ConsoleGlobals.hevConsole != NULLHANDLE) /* we're already initialized ?*/ 257 185 return (NO_ERROR); /* then abort immediately */ 258 186 259 /* create console synchronization semaphore */ 260 rc = DosCreateEventSem (NULL, 261 &ConsoleGlobals.hevConsole, 262 0L, /* semaphore is private */ 263 FALSE); /* reset state */ 264 if (rc != NO_ERROR) /* other error ? */ 265 return (rc); /* raise error condition */ 266 267 268 /* create console input queue semaphore */ 269 rc = DosCreateEventSem (NULL, 270 &ConsoleInput.hevInputQueue, 271 0L, /* semaphore is private */ 272 FALSE); /* reset state */ 273 if (rc != NO_ERROR) /* other error ? */ 187 if(flVioConsole == TRUE) 274 188 { 275 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */ 276 return (rc); /* raise error condition */ 189 /*************************************************************************** 190 * Create pseudo-devices and initialize ConsoleGlobals * 191 ***************************************************************************/ 192 193 rc = iConsoleDevicesRegister(); /* ensure devices are there */ 194 if (rc != NO_ERROR) /* check for errors */ 195 { 196 return (rc); /* raise error condition */ 197 } 198 rc = DosCreateMutexSem(NULL, 199 &ConsoleInput.hmtxInputQueue, 200 0L, 201 FALSE); 202 if (rc != NO_ERROR) /* other error ? */ 203 { 204 return (rc); /* raise error condition */ 205 } 206 207 return NO_ERROR; 277 208 } 278 279 280 rc = DosCreateMutexSem(NULL, 281 &ConsoleInput.hmtxInputQueue, 282 0L, 283 FALSE); 284 if (rc != NO_ERROR) /* other error ? */ 285 { 286 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */ 287 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */ 288 return (rc); /* raise error condition */ 209 else { 210 /* create console synchronization semaphore */ 211 rc = DosCreateEventSem (NULL, 212 &ConsoleGlobals.hevConsole, 213 0L, /* semaphore is private */ 214 FALSE); /* reset state */ 215 if (rc != NO_ERROR) /* other error ? */ 216 return (rc); /* raise error condition */ 217 218 219 /* create console input queue semaphore */ 220 rc = DosCreateEventSem (NULL, 221 &ConsoleInput.hevInputQueue, 222 0L, /* semaphore is private */ 223 FALSE); /* reset state */ 224 if (rc != NO_ERROR) /* other error ? */ 225 { 226 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */ 227 return (rc); /* raise error condition */ 228 } 229 230 231 rc = DosCreateMutexSem(NULL, 232 &ConsoleInput.hmtxInputQueue, 233 0L, 234 FALSE); 235 if (rc != NO_ERROR) /* other error ? */ 236 { 237 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */ 238 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */ 239 return (rc); /* raise error condition */ 240 } 241 242 /*************************************************************************** 243 * Create pseudo-devices and initialize ConsoleGlobals * 244 ***************************************************************************/ 245 246 rc = iConsoleDevicesRegister(); /* ensure devices are there */ 247 if (rc != NO_ERROR) /* check for errors */ 248 { 249 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */ 250 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */ 251 return (rc); /* raise error condition */ 252 } 253 254 255 /*************************************************************************** 256 * Presentation Manager Initialization phase * 257 ***************************************************************************/ 258 259 /* OK, we're about to initialize the console subsystem for this process. */ 260 /* start message thread for console object window */ 261 ConsoleGlobals.tidConsole = _beginthread(iConsoleMsgThread, 262 NULL, 263 12288, 264 NULL); 265 /* has the thread been created properly ? */ 266 if (ConsoleGlobals.tidConsole == -1) 267 { 268 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */ 269 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close event semaphore */ 270 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */ 271 return (rc); /* raise error condition */ 272 } 273 else 274 DosSetPriority(PRTYS_THREAD, /* set priority */ 275 ConsoleGlobals.Options.ulConsoleThreadPriorityClass, 276 ConsoleGlobals.Options.ulConsoleThreadPriorityDelta, 277 ConsoleGlobals.tidConsole); 278 279 280 /* wait for the child thread to do it's initialization */ 281 /* timeout isn't really useful */ 282 rc = DosWaitEventSem(ConsoleGlobals.hevConsole, 283 SEM_INDEFINITE_WAIT); 284 if (rc != NO_ERROR) /* check for errors */ 285 { 286 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */ 287 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close event semaphore */ 288 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */ 289 return (rc); /* raise error condition */ 290 } 291 292 DosResetEventSem(ConsoleGlobals.hevConsole, /* reset event semaphore */ 293 &ulPostCount); 294 295 rc = ConsoleGlobals.rcConsole; /* pass thru console thread's return code */ 296 297 return (rc); /* OK */ 289 298 } 290 291 /***************************************************************************292 * Create pseudo-devices and initialize ConsoleGlobals *293 ***************************************************************************/294 295 rc = iConsoleDevicesRegister(); /* ensure devices are there */296 if (rc != NO_ERROR) /* check for errors */297 {298 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */299 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */300 return (rc); /* raise error condition */301 }302 303 304 /***************************************************************************305 * Presentation Manager Initialization phase *306 ***************************************************************************/307 308 /* OK, we're about to initialize the console subsystem for this process. */309 /* start message thread for console object window */310 ConsoleGlobals.tidConsole = _beginthread(iConsoleMsgThread,311 NULL,312 12288,313 NULL);314 /* has the thread been created properly ? */315 if (ConsoleGlobals.tidConsole == -1)316 {317 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */318 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close event semaphore */319 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */320 return (rc); /* raise error condition */321 }322 else323 DosSetPriority(PRTYS_THREAD, /* set priority */324 ConsoleGlobals.Options.ulConsoleThreadPriorityClass,325 ConsoleGlobals.Options.ulConsoleThreadPriorityDelta,326 ConsoleGlobals.tidConsole);327 328 329 /* wait for the child thread to do it's initialization */330 /* timeout isn't really useful */331 rc = DosWaitEventSem(ConsoleGlobals.hevConsole,332 SEM_INDEFINITE_WAIT);333 if (rc != NO_ERROR) /* check for errors */334 {335 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */336 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close event semaphore */337 ConsoleGlobals.hevConsole = NULLHANDLE; /* for ConsoleIsActive() */338 return (rc); /* raise error condition */339 }340 341 DosResetEventSem(ConsoleGlobals.hevConsole, /* reset event semaphore */342 &ulPostCount);343 344 rc = ConsoleGlobals.rcConsole; /* pass thru console thread's return code */345 346 return (rc); /* OK */347 299 } 348 300 … … 397 349 ConsoleGlobals.coordWindowPos.X = 0; 398 350 ConsoleGlobals.coordWindowPos.Y = 0; 351 if(flVioConsole == TRUE) { 352 VIOMODEINFO videoinfo; 353 354 videoinfo.cb = sizeof(VIOMODEINFO); 355 rc = VioGetMode(&videoinfo, 0); 356 if(rc == 0) { 357 dprintf(("video mode (%d,%d)", videoinfo.col, videoinfo.row)); 358 ConsoleGlobals.coordWindowSize.X = videoinfo.col; 359 ConsoleGlobals.coordWindowSize.Y = videoinfo.row; 360 } 361 } 399 362 400 363 … … 410 373 411 374 /* generate copy of title */ 412 ConsoleGlobals.pszWindowTitle = strdup(GetCommandLine ());375 ConsoleGlobals.pszWindowTitle = strdup(GetCommandLineA()); 413 376 414 377 /* obtain module handle to our resources */ … … 428 391 429 392 430 // defaults are effective, try to read and apply stored properties 431 if (ConsolePropertyLoad(&ConsoleGlobals.Options) == NO_ERROR) 432 ConsolePropertyApply(&ConsoleGlobals.Options); 393 if (flVioConsole == FALSE) 394 { 395 // defaults are effective, try to read and apply stored properties 396 if (ConsolePropertyLoad(&ConsoleGlobals.Options) == NO_ERROR) 397 ConsolePropertyApply(&ConsoleGlobals.Options); 398 } 433 399 434 400 … … 437 403 ***************************************************************************/ 438 404 439 440 441 pHMDeviceConsoleIn = new HMDeviceConsoleInClass("CONIN$",442 &ConsoleInput,443 &ConsoleGlobals); 444 445 446 405 /* create devices and register devices with handlemanager */ 406 pHMDeviceConsoleIn = new HMDeviceConsoleInClass("CONIN$", 407 &ConsoleInput, 408 &ConsoleGlobals); 409 410 rc = HMDeviceRegister ("CONIN$", 411 pHMDeviceConsoleIn); 412 if (rc != NO_ERROR) /* check for errors */ 447 413 dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONIN$ failed with %u.\n", 448 414 rc)); 449 415 450 416 451 452 453 454 455 456 417 pHMDeviceConsoleOut = new HMDeviceConsoleOutClass("CONOUT$", 418 &ConsoleInput, 419 &ConsoleGlobals); 420 rc = HMDeviceRegister ("CONOUT$", 421 pHMDeviceConsoleOut); 422 if (rc != NO_ERROR) /* check for errors */ 457 423 dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONOUT$ failed with %u.\n", 458 424 rc)); 459 425 460 461 pHMDeviceConsoleBuffer = new HMDeviceConsoleBufferClass("CONBUFFER$", 462 &ConsoleInput, 463 &ConsoleGlobals); 464 rc = HMDeviceRegister ("CONBUFFER$", 465 pHMDeviceConsoleBuffer); 466 if (rc != NO_ERROR) /* check for errors */ 426 if(flVioConsole == TRUE) 427 { 428 pHMDeviceConsoleBuffer = (HMDeviceConsoleBufferClass *)new HMDeviceConsoleVioBufferClass("CONBUFFER$", 429 &ConsoleInput, 430 &ConsoleGlobals); 431 } 432 else { 433 pHMDeviceConsoleBuffer = new HMDeviceConsoleBufferClass("CONBUFFER$", 434 &ConsoleInput, 435 &ConsoleGlobals); 436 } 437 rc = HMDeviceRegister ("CONBUFFER$", 438 pHMDeviceConsoleBuffer); 439 if (rc != NO_ERROR) /* check for errors */ 467 440 dprintf(("KERNEL32:ConsoleDevicesRegister: registering CONBUFFER$ failed with %u.\n", 468 441 rc)); 469 442 470 443 471 /*********************************************************************** 472 * initialize stdin handle * 473 ***********************************************************************/ 474 hStandardIn = GetStdHandle(STD_INPUT_HANDLE); 475 dwType = GetFileType(hStandardIn); 476 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */ 477 hStandardIn = HMCreateFile("CONIN$", 478 GENERIC_READ | GENERIC_WRITE, 479 FILE_SHARE_READ | FILE_SHARE_WRITE, 480 NULL, 481 0, 482 CONSOLE_TEXTMODE_BUFFER, 483 0); 484 485 HMSetStdHandle(STD_INPUT_HANDLE, 486 hStandardIn); 487 488 /*********************************************************************** 489 * initialize stdout handle * 490 ***********************************************************************/ 491 hStandardOut = GetStdHandle(STD_OUTPUT_HANDLE); 492 dwType = GetFileType(hStandardOut); 493 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */ 494 hStandardOut = HMCreateFile("CONOUT$", 495 GENERIC_READ | GENERIC_WRITE, 496 FILE_SHARE_READ | FILE_SHARE_WRITE, 497 NULL, 498 0, 499 CONSOLE_TEXTMODE_BUFFER, 500 0); 501 502 HMSetStdHandle(STD_OUTPUT_HANDLE, 503 hStandardOut); 504 505 506 /*********************************************************************** 507 * initialize stderr handle * 508 ***********************************************************************/ 509 hStandardError = GetStdHandle(STD_ERROR_HANDLE); 510 dwType = GetFileType(hStandardError); 511 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */ 512 hStandardError = HMCreateFile("CONOUT$", 513 GENERIC_READ | GENERIC_WRITE, 514 FILE_SHARE_READ | FILE_SHARE_WRITE, 515 NULL, 516 0, 517 CONSOLE_TEXTMODE_BUFFER, 518 0); 519 520 HMSetStdHandle(STD_ERROR_HANDLE, 521 hStandardError); 444 /*********************************************************************** 445 * initialize stdin handle * 446 ***********************************************************************/ 447 hStandardIn = GetStdHandle(STD_INPUT_HANDLE); 448 dwType = GetFileType(hStandardIn); 449 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */ 450 hStandardIn = HMCreateFile("CONIN$", 451 GENERIC_READ | GENERIC_WRITE, 452 FILE_SHARE_READ | FILE_SHARE_WRITE, 453 NULL, 454 0, 455 CONSOLE_TEXTMODE_BUFFER, 456 0); 457 458 HMSetStdHandle(STD_INPUT_HANDLE, 459 hStandardIn); 460 461 /*********************************************************************** 462 * initialize stdout handle * 463 ***********************************************************************/ 464 hStandardOut = GetStdHandle(STD_OUTPUT_HANDLE); 465 dwType = GetFileType(hStandardOut); 466 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */ 467 hStandardOut = HMCreateFile("CONOUT$", 468 GENERIC_READ | GENERIC_WRITE, 469 FILE_SHARE_READ | FILE_SHARE_WRITE, 470 NULL, 471 0, 472 CONSOLE_TEXTMODE_BUFFER, 473 0); 474 475 HMSetStdHandle(STD_OUTPUT_HANDLE, 476 hStandardOut); 477 478 /*********************************************************************** 479 * initialize stderr handle * 480 ***********************************************************************/ 481 hStandardError = GetStdHandle(STD_ERROR_HANDLE); 482 dwType = GetFileType(hStandardError); 483 if (dwType == FILE_TYPE_CHAR) /* is handle redirected ? */ 484 hStandardError = HMCreateFile("CONOUT$", 485 GENERIC_READ | GENERIC_WRITE, 486 FILE_SHARE_READ | FILE_SHARE_WRITE, 487 NULL, 488 0, 489 CONSOLE_TEXTMODE_BUFFER, 490 0); 491 492 HMSetStdHandle(STD_ERROR_HANDLE, 493 hStandardError); 522 494 523 495 return (NO_ERROR); /* OK */ … … 542 514 ULONG iConsoleTerminate(VOID) 543 515 { 544 APIRET rc; 516 APIRET rc = NO_ERROR; 517 518 if(flVioConsole == FALSE) 519 { 520 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */ 521 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */ 522 523 524 WinPostMsg (ConsoleGlobals.hwndFrame, /* force thread to terminate */ 525 WM_CLOSE, 526 (MPARAM)NULL, 527 (MPARAM)NULL); 528 529 rc = DosWaitThread(&ConsoleGlobals.tidConsole,/* wait until thd terminates */ 530 DCWW_WAIT); 531 532 } 533 DosCloseMutexSem(ConsoleInput.hmtxInputQueue); /* close semaphore */ 534 535 /* close the consolebuffer handle */ 536 HMCloseHandle(ConsoleGlobals.hConsoleBufferDefault); 537 free(ConsoleGlobals.pszWindowTitle); /* free previously allocated memory */ 538 539 return (rc); /* OK */ 540 } 541 542 543 /***************************************************************************** 544 * Name : static void ConsoleWaitClose 545 * Purpose : Wait for the user to close console window 546 * Parameters: VOID 547 * Variables : 548 * Result : 549 * Remark : 550 * Status : 551 * 552 * Author : Patrick Haller [Tue, 1998/02/10 01:55] 553 *****************************************************************************/ 554 555 void iConsoleWaitClose(void) 556 { 557 CHAR szBuffer[128]; /* buffer for the title */ 558 BOOL fResult; /* result from subsequent calls to Win32 APIs */ 559 560 /* check if there is a console window at all */ 561 if (iConsoleIsActive() == FALSE) 562 return; /* nope */ 563 564 if(flVioConsole == TRUE) //no need to wait for VIO session 565 return; 566 567 strcpy (szBuffer, /* indicate console process has terminated */ 568 "Completed: "); 569 570 fResult = GetConsoleTitleA(szBuffer + 11,/* 11 is length of Completed:_ */ 571 sizeof(szBuffer) - 11); 572 573 574 /* Set new title: Win32 Console - Terminated */ 575 fResult = SetConsoleTitleA(szBuffer); 545 576 546 577 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */ … … 549 580 550 581 551 WinPostMsg (ConsoleGlobals.hwndFrame, /* force thread to terminate */552 WM_CLOSE,553 (MPARAM)NULL,554 (MPARAM)NULL);555 556 rc = DosWaitThread(&ConsoleGlobals.tidConsole,/* wait until thd terminates */557 DCWW_WAIT);558 559 /* close the consolebuffer handle */560 HMCloseHandle(ConsoleGlobals.hConsoleBufferDefault);561 free(ConsoleGlobals.pszWindowTitle); /* free previously allocated memory */562 563 return (rc); /* OK */564 }565 566 567 /*****************************************************************************568 * Name : static void ConsoleWaitClose569 * Purpose : Wait for the user to close console window570 * Parameters: VOID571 * Variables :572 * Result :573 * Remark :574 * Status :575 *576 * Author : Patrick Haller [Tue, 1998/02/10 01:55]577 *****************************************************************************/578 579 void iConsoleWaitClose(void)580 {581 CHAR szBuffer[128]; /* buffer for the title */582 BOOL fResult; /* result from subsequent calls to Win32 APIs */583 584 /* check if there is a console window at all */585 if (iConsoleIsActive() == FALSE)586 return; /* nope */587 588 strcpy (szBuffer, /* indicate console process has terminated */589 "Completed: ");590 591 fResult = GetConsoleTitleA(szBuffer + 11,/* 11 is length of Completed:_ */592 sizeof(szBuffer) - 11);593 594 595 /* Set new title: Win32 Console - Terminated */596 fResult = SetConsoleTitleA(szBuffer);597 598 DosCloseEventSem(ConsoleGlobals.hevConsole); /* close other semaphore */599 DosCloseEventSem(ConsoleInput.hevInputQueue); /* close other semaphore */600 DosCloseMutexSem(ConsoleInput.hmtxInputQueue); /* close semaphore */601 602 603 582 /* terminate console immediately ? */ 604 583 if (ConsoleGlobals.Options.fTerminateAutomatically == FALSE) { 605 606 607 608 584 if(getenv("ODIN_AUTOEXITCONSOLE") == NULL) { 585 DosWaitThread(&ConsoleGlobals.tidConsole, /* wait until thd terminates */ 586 DCWW_WAIT); 587 } 609 588 } 610 589 } … … 625 604 BOOL iConsoleIsActive(void) 626 605 { 606 if(flVioConsole == TRUE) //actually, this isn't needed in VIO mode 607 return TRUE; 608 627 609 return (NULLHANDLE != ConsoleGlobals.hevConsole); 628 610 } … … 854 836 0, 855 837 0, 856 ConsoleGlobals.Options.coordDefault Position.X *838 ConsoleGlobals.Options.coordDefaultSize.X * 857 839 ConsoleGlobals.sCellCX + 858 840 2 * WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER), 859 ConsoleGlobals.Options.coordDefault Position.Y *841 ConsoleGlobals.Options.coordDefaultSize.Y * 860 842 ConsoleGlobals.sCellCY + 861 843 WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) + … … 1408 1390 pInputRecord, 1409 1391 sizeof (INPUT_RECORD) ); 1410 /* unblock reading threads */ 1411 rc = DosPostEventSem(ConsoleInput.hevInputQueue); 1392 1393 if(flVioConsole == FALSE) 1394 { /* unblock reading threads */ 1395 rc = DosPostEventSem(ConsoleInput.hevInputQueue); 1396 } 1397 else rc = 0; 1412 1398 return (rc); /* OK */ 1413 1399 } … … 1973 1959 *****************************************************************************/ 1974 1960 1975 ULONG iConsoleInputQueryEvents (void) 1976 { 1961 ULONG iConsoleInputQueryEvents(PICONSOLEINPUT pConsoleInput, int fWait) 1962 { 1963 ULONG ulPostCounter; /* semaphore post counter - ignored */ 1964 APIRET rc; /* API returncode */ 1965 1966 if(flVioConsole) 1967 { 1968 KBDKEYINFO keyinfo; 1969 1970 rc = KbdCharIn(&keyinfo, IO_NOWAIT, 0); //grab key if present; don't wait 1971 if((rc || !(keyinfo.fbStatus & 0x40)) && fWait == QUERY_EVENT_WAIT && ConsoleInput.ulEvents == 0) { 1972 rc = KbdCharIn(&keyinfo, IO_WAIT, 0); 1973 } 1974 while(rc == 0 && (keyinfo.fbStatus & 0x40)) 1975 { 1976 INPUT_RECORD InputRecord = {0}; 1977 1978 InputRecord.EventType = KEY_EVENT; 1979 InputRecord.Event.KeyEvent.wRepeatCount = 1; 1980 InputRecord.Event.KeyEvent.bKeyDown = 1; 1981 InputRecord.Event.KeyEvent.dwControlKeyState = 0; 1982 1983 if(keyinfo.fbStatus & 2) 1984 InputRecord.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY; 1985 1986 if(keyinfo.fsState & (KBDSTF_RIGHTSHIFT|KBDSTF_LEFTSHIFT)) 1987 InputRecord.Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED; 1988 1989 if(keyinfo.fsState & KBDSTF_LEFTALT) 1990 InputRecord.Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED; 1991 1992 if(keyinfo.fsState & KBDSTF_RIGHTALT) 1993 InputRecord.Event.KeyEvent.dwControlKeyState |= RIGHT_ALT_PRESSED; 1994 1995 if(keyinfo.fsState & KBDSTF_LEFTCONTROL) 1996 InputRecord.Event.KeyEvent.dwControlKeyState |= LEFT_CTRL_PRESSED; 1997 1998 if(keyinfo.fsState & KBDSTF_RIGHTCONTROL) 1999 InputRecord.Event.KeyEvent.dwControlKeyState |= RIGHT_CTRL_PRESSED; 2000 2001 if(keyinfo.fsState & KBDSTF_CAPSLOCK_ON) 2002 InputRecord.Event.KeyEvent.dwControlKeyState |= CAPSLOCK_ON; 2003 2004 if(keyinfo.fsState & KBDSTF_SCROLLLOCK_ON) 2005 InputRecord.Event.KeyEvent.dwControlKeyState |= SCROLLLOCK_ON; 2006 2007 if(keyinfo.fsState & KBDSTF_NUMLOCK_ON) 2008 InputRecord.Event.KeyEvent.dwControlKeyState |= NUMLOCK_ON; 2009 2010 InputRecord.Event.KeyEvent.wVirtualKeyCode = 0; 2011 InputRecord.Event.KeyEvent.wVirtualScanCode = keyinfo.chScan; 2012 InputRecord.Event.KeyEvent.uChar.AsciiChar = keyinfo.chChar; 2013 2014 rc = iConsoleInputEventPush(&InputRecord); /* add it to the queue */ 2015 if(rc) { 2016 dprintf(("WARNING: lost key!!")); 2017 break; 2018 } 2019 2020 rc = KbdCharIn(&keyinfo, IO_NOWAIT, 0); //grab key if present; don't wait 2021 } 2022 } 2023 else 2024 if(fWait == QUERY_EVENT_WAIT && ConsoleInput.ulEvents == 0) 2025 { 2026 rc = DosWaitEventSem(pConsoleInput->hevInputQueue, /* wait for input */ 2027 SEM_INDEFINITE_WAIT); 2028 DosResetEventSem(pConsoleInput->hevInputQueue, /* reset semaphore */ 2029 &ulPostCounter); /* post counter - ignored */ 2030 } 1977 2031 return (ConsoleInput.ulEvents); /* return number of events in queue */ 1978 2032 } … … 2277 2331 #endif 2278 2332 2279 rc = iConsoleInit( );/* initialize subsystem if required */2280 if (rc != NO_ERROR) 2333 rc = iConsoleInit(flVioConsole); /* initialize subsystem if required */ 2334 if (rc != NO_ERROR) /* check for errors */ 2281 2335 { 2282 2336 SetLastError(rc); /* pass thru the error code */ … … 2310 2364 2311 2365 HANDLE WIN32API CreateConsoleScreenBuffer(DWORD dwDesiredAccess, 2312 2313 2314 2315 2366 DWORD dwShareMode, 2367 LPVOID lpSecurityAttributes, 2368 DWORD dwFlags, 2369 LPVOID lpScreenBufferData) 2316 2370 { 2317 2371 HANDLE hResult; … … 2539 2593 2540 2594 BOOL WIN32API GenerateConsoleCtrlEvent(DWORD dwCtrlEvent, 2541 2595 DWORD dwProcessGroupId) 2542 2596 { 2543 2597 #ifdef DEBUG_LOCAL2 … … 2676 2730 2677 2731 BOOL WIN32API GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, 2678 2732 PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo) 2679 2733 { 2680 2734 BOOL fResult; … … 2819 2873 2820 2874 BOOL WIN32API GetNumberOfConsoleInputEvents(HANDLE hConsoleInput, 2821 2875 LPDWORD lpNumberOfEvents) 2822 2876 { 2823 2877 BOOL fResult; … … 2921 2975 2922 2976 BOOL WIN32API PeekConsoleInputA(HANDLE hConsoleInput, 2923 2924 2925 2977 PINPUT_RECORD pirBuffer, 2978 DWORD cInRecords, 2979 LPDWORD lpcRead) 2926 2980 { 2927 2981 BOOL fResult; … … 2959 3013 2960 3014 BOOL WIN32API ReadConsoleA(HANDLE hConsoleInput, 2961 2962 2963 2964 3015 LPVOID lpvBuffer, 3016 DWORD cchToRead, 3017 LPDWORD lpcchRead, 3018 LPVOID lpvReserved) 2965 3019 { 2966 3020 BOOL fResult; … … 2999 3053 3000 3054 BOOL WIN32API ReadConsoleW(HANDLE hConsoleInput, 3001 3002 3003 3004 3055 LPVOID lpvBuffer, 3056 DWORD cchToRead, 3057 LPDWORD lpcchRead, 3058 LPVOID lpvReserved) 3005 3059 { 3006 3060 BOOL fResult; … … 3039 3093 3040 3094 BOOL WIN32API ReadConsoleInputA(HANDLE hConsoleInput, 3041 3042 3043 3095 PINPUT_RECORD pirBuffer, 3096 DWORD cInRecords, 3097 LPDWORD lpcRead) 3044 3098 { 3045 3099 BOOL fResult; … … 3077 3131 3078 3132 BOOL WIN32API ReadConsoleInputW(HANDLE hConsoleInput, 3079 3080 3081 3133 PINPUT_RECORD pirBuffer, 3134 DWORD cInRecords, 3135 LPDWORD lpcRead) 3082 3136 { 3083 3137 BOOL fResult; … … 3115 3169 3116 3170 BOOL WIN32API ReadConsoleOutputA(HANDLE hConsoleOutput, 3117 3118 3119 3120 3171 PCHAR_INFO pchiDestBuffer, 3172 COORD coordDestBufferSize, 3173 COORD coordDestBufferCoord, 3174 PSMALL_RECT psrctSourceRect) 3121 3175 { 3122 3176 BOOL fResult; … … 3155 3209 3156 3210 BOOL WIN32API ReadConsoleOutputW(HANDLE hConsoleOutput, 3157 3158 3159 3160 3211 PCHAR_INFO pchiDestBuffer, 3212 COORD coordDestBufferSize, 3213 COORD coordDestBufferCoord, 3214 PSMALL_RECT psrctSourceRect) 3161 3215 { 3162 3216 BOOL fResult; … … 3195 3249 3196 3250 BOOL WIN32API ReadConsoleOutputAttribute(HANDLE hConsoleOutput, 3197 3198 3199 3200 3251 LPWORD lpwAttribute, 3252 DWORD cReadCells, 3253 COORD coordReadCoord, 3254 LPDWORD lpcNumberRead) 3201 3255 { 3202 3256 BOOL fResult; … … 3235 3289 3236 3290 BOOL WIN32API ReadConsoleOutputCharacterA(HANDLE hConsoleOutput, 3237 3238 3239 3240 3291 LPTSTR lpReadBuffer, 3292 DWORD cchRead, 3293 COORD coordReadCoord, 3294 LPDWORD lpcNumberRead) 3241 3295 { 3242 3296 BOOL fResult; … … 3275 3329 3276 3330 BOOL WIN32API ReadConsoleOutputCharacterW(HANDLE hConsoleOutput, 3277 3278 3279 3280 3331 LPTSTR lpReadBuffer, 3332 DWORD cchRead, 3333 COORD coordReadCoord, 3334 LPDWORD lpcNumberRead) 3281 3335 { 3282 3336 BOOL fResult; … … 3315 3369 3316 3370 BOOL WIN32API ScrollConsoleScreenBufferA(HANDLE hConsoleOutput, 3317 3318 3319 3320 3371 PSMALL_RECT psrctSourceRect, 3372 PSMALL_RECT psrctClipRect, 3373 COORD coordDestOrigin, 3374 PCHAR_INFO pchiFill) 3321 3375 { 3322 3376 BOOL fResult; … … 3355 3409 3356 3410 BOOL WIN32API ScrollConsoleScreenBufferW(HANDLE hConsoleOutput, 3357 3358 3359 3360 3411 PSMALL_RECT psrctSourceRect, 3412 PSMALL_RECT psrctClipRect, 3413 COORD coordDestOrigin, 3414 PCHAR_INFO pchiFill) 3361 3415 { 3362 3416 BOOL fResult; … … 3707 3761 if (lpszTitle == NULL) /* check parameters */ 3708 3762 return FALSE; 3709 3763 3710 3764 if (ConsoleGlobals.pszWindowTitle != NULL) /* previously set name */ 3711 3765 free (ConsoleGlobals.pszWindowTitle); /* then free it */ 3712 3766 3713 3767 /* create an ascii copy of the lpszTitle */ 3714 3768 int iLength = UniStrlen(lpszTitle); 3715 3769 3716 3770 ConsoleGlobals.pszWindowTitle = (PSZ)malloc(iLength+1); 3717 3771 ConsoleGlobals.pszWindowTitle[iLength] = 0; … … 3740 3794 3741 3795 BOOL WIN32API SetConsoleWindowInfo(HANDLE hConsoleOutput, 3742 3743 3796 BOOL fAbsolute, 3797 PSMALL_RECT psrctWindowRect) 3744 3798 { 3745 3799 BOOL fResult; … … 3776 3830 3777 3831 BOOL WIN32API WriteConsoleA(HANDLE hConsoleOutput, 3778 3779 3780 3781 3832 CONST VOID* lpvBuffer, 3833 DWORD cchToWrite, 3834 LPDWORD lpcchWritten, 3835 LPVOID lpvReserved) 3782 3836 { 3783 3837 BOOL fResult; … … 3816 3870 3817 3871 BOOL WIN32API WriteConsoleW(HANDLE hConsoleOutput, 3818 3819 3820 3821 3872 CONST VOID* lpvBuffer, 3873 DWORD cchToWrite, 3874 LPDWORD lpcchWritten, 3875 LPVOID lpvReserved) 3822 3876 { 3823 3877 BOOL fResult; … … 3856 3910 3857 3911 BOOL WIN32API WriteConsoleInputA(HANDLE hConsoleInput, 3858 3859 3860 3912 PINPUT_RECORD pirBuffer, 3913 DWORD cInRecords, 3914 LPDWORD lpcWritten) 3861 3915 { 3862 3916 BOOL fResult; … … 3894 3948 3895 3949 BOOL WIN32API WriteConsoleInputW(HANDLE hConsoleInput, 3896 3897 3898 3950 PINPUT_RECORD pirBuffer, 3951 DWORD cInRecords, 3952 LPDWORD lpcWritten) 3899 3953 { 3900 3954 BOOL fResult; … … 3932 3986 3933 3987 BOOL WIN32API WriteConsoleOutputA(HANDLE hConsoleOutput, 3934 3935 3936 3937 3988 PCHAR_INFO pchiSrcBuffer, 3989 COORD coordSrcBufferSize, 3990 COORD coordSrcBufferCoord, 3991 PSMALL_RECT psrctDestRect) 3938 3992 { 3939 3993 BOOL fResult; … … 3972 4026 3973 4027 BOOL WIN32API WriteConsoleOutputW(HANDLE hConsoleOutput, 3974 3975 3976 3977 4028 PCHAR_INFO pchiSrcBuffer, 4029 COORD coordSrcBufferSize, 4030 COORD coordSrcBufferCoord, 4031 PSMALL_RECT psrctDestRect) 3978 4032 { 3979 4033 BOOL fResult; … … 4011 4065 4012 4066 BOOL WIN32API WriteConsoleOutputAttribute(HANDLE hConsoleOutput, 4013 4014 4015 4016 4067 LPWORD lpwAttribute, 4068 DWORD cWriteCells, 4069 COORD coordWriteCoord, 4070 LPDWORD lpcNumberWritten) 4017 4071 { 4018 4072 BOOL fResult; … … 4051 4105 4052 4106 BOOL WIN32API WriteConsoleOutputCharacterA(HANDLE hConsoleOutput, 4053 4054 4055 4056 4107 LPTSTR lpWriteBuffer, 4108 DWORD cchWrite, 4109 COORD coordWriteCoord, 4110 LPDWORD lpcWritten) 4057 4111 { 4058 4112 BOOL fResult; … … 4091 4145 4092 4146 BOOL WIN32API WriteConsoleOutputCharacterW(HANDLE hConsoleOutput, 4093 4094 4095 4096 4147 LPTSTR lpWriteBuffer, 4148 DWORD cchWrite, 4149 COORD coordWriteCoord, 4150 LPDWORD lpcWritten) 4097 4151 { 4098 4152 BOOL fResult;
Note:
See TracChangeset
for help on using the changeset viewer.