[10210] | 1 | /* $Id: conout.cpp,v 1.16 2003-08-06 10:02:19 sandervl Exp $ */
|
---|
[111] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Win32 Console API Translation for OS/2
|
---|
| 5 | * 1998/02/10 Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
| 6 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | #ifdef DEBUG
|
---|
| 11 | #define DEBUG_LOCAL
|
---|
| 12 | #define DEBUG_LOCAL2
|
---|
| 13 | #endif
|
---|
| 14 |
|
---|
[1484] | 15 | //#undef DEBUG_LOCAL
|
---|
| 16 | //#undef DEBUG_LOCAL2
|
---|
[111] | 17 |
|
---|
| 18 |
|
---|
| 19 | /*****************************************************************************
|
---|
| 20 | * Remark *
|
---|
| 21 | *****************************************************************************
|
---|
| 22 |
|
---|
| 23 | - DWORD HandlerRoutine (DWORD dwCtrlType)
|
---|
| 24 | basically an exception handler routine. handles a few signals / excpts.
|
---|
| 25 | should be somewhere near the exception handling code ... :)
|
---|
| 26 |
|
---|
| 27 | Hmm, however as PM applications don't really get a ctrl-c signal,
|
---|
| 28 | I'll have to do this on my own ...
|
---|
| 29 |
|
---|
| 30 | - supply unicode<->ascii conversions for all the _A and _W function pairs.
|
---|
| 31 |
|
---|
| 32 | - problem: we can't prevent thread1 from blocking the message queue ?
|
---|
| 33 | what will happen if a WinTerminate() is issued there ?
|
---|
| 34 | will the message queue be closed and provide smooth tasking ?
|
---|
| 35 | how will open32 react on this ?
|
---|
| 36 |
|
---|
| 37 | - ECHO_LINE_INPUT / ReadFile blocks till CR
|
---|
| 38 |
|
---|
| 39 | - scrollbars
|
---|
| 40 | * do some flowchart to exactly determine WHEN to use WHICH setting
|
---|
| 41 | and perform WHAT action
|
---|
| 42 |
|
---|
| 43 | - clipboard support
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | /*****************************************************************************
|
---|
| 48 | * Includes *
|
---|
| 49 | *****************************************************************************/
|
---|
| 50 |
|
---|
| 51 | #define INCL_WIN
|
---|
| 52 | #define INCL_DOSMEMMGR
|
---|
| 53 | #define INCL_DOSSEMAPHORES
|
---|
| 54 | #define INCL_DOSERRORS
|
---|
| 55 | #define INCL_DOSPROCESS
|
---|
| 56 | #define INCL_DOSMODULEMGR
|
---|
| 57 | #define INCL_VIO
|
---|
| 58 | #define INCL_AVIO
|
---|
[120] | 59 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
[111] | 60 | #include <stdlib.h>
|
---|
| 61 | #include <string.h>
|
---|
| 62 |
|
---|
| 63 | #include <win32type.h>
|
---|
[2984] | 64 | #include <win32api.h>
|
---|
[111] | 65 | #include <misc.h>
|
---|
| 66 |
|
---|
| 67 | #include "conwin.h" // Windows Header for console only
|
---|
| 68 | #include "HandleManager.h"
|
---|
| 69 | #include "HMDevice.h"
|
---|
| 70 | #include "ConOut.H"
|
---|
| 71 |
|
---|
| 72 | #include "console2.h"
|
---|
| 73 | #include "conprop.h"
|
---|
| 74 | #include "unicode.h"
|
---|
| 75 |
|
---|
[2802] | 76 | #define DBG_LOCALLOG DBG_conout
|
---|
| 77 | #include "dbglocal.h"
|
---|
[111] | 78 |
|
---|
| 79 | /*****************************************************************************
|
---|
| 80 | * Name : DWORD HMDeviceConsoleOutClass::CreateFile
|
---|
| 81 | * Purpose : this is called from the handle manager if a CreateFile() is
|
---|
| 82 | * performed on a handle
|
---|
| 83 | * Parameters: LPCSTR lpFileName name of the file / device
|
---|
| 84 | * PHMHANDLEDATA pHMHandleData data of the NEW handle
|
---|
| 85 | * PVOID lpSecurityAttributes ignored
|
---|
| 86 | * PHMHANDLEDATA pHMHandleDataTemplate data of the template handle
|
---|
| 87 | * Variables :
|
---|
| 88 | * Result :
|
---|
| 89 | * Remark :
|
---|
| 90 | * Status : NO_ERROR - API succeeded
|
---|
| 91 | * other - what is to be set in SetLastError
|
---|
| 92 | *
|
---|
| 93 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
| 94 | *****************************************************************************/
|
---|
| 95 |
|
---|
[7549] | 96 | DWORD HMDeviceConsoleOutClass::CreateFile (LPCSTR lpFileName,
|
---|
[111] | 97 | PHMHANDLEDATA pHMHandleData,
|
---|
| 98 | PVOID lpSecurityAttributes,
|
---|
| 99 | PHMHANDLEDATA pHMHandleDataTemplate)
|
---|
| 100 | {
|
---|
| 101 | BOOL fResult;
|
---|
| 102 | HANDLE hConsole;
|
---|
| 103 |
|
---|
[7549] | 104 | dprintf(("KERNEL32/CONSOLE:HMDeviceConsoleOutClass %s(%s,%08x,%08x,%08x)\n",
|
---|
[111] | 105 | lpHMDeviceName,
|
---|
| 106 | lpFileName,
|
---|
[149] | 107 | pHMHandleData->hHMHandle,
|
---|
[111] | 108 | lpSecurityAttributes,
|
---|
[7549] | 109 | pHMHandleDataTemplate));
|
---|
[111] | 110 |
|
---|
| 111 |
|
---|
[7549] | 112 | /* if no default buffer is available, then do default setup */
|
---|
[111] | 113 | if (pConsoleGlobals->hConsoleBuffer == INVALID_HANDLE_VALUE)
|
---|
| 114 | {
|
---|
| 115 | /* now we need a default screen buffer with the default size */
|
---|
| 116 | hConsole = CreateConsoleScreenBuffer(0,
|
---|
| 117 | 0,
|
---|
| 118 | NULL,
|
---|
| 119 | CONSOLE_TEXTMODE_BUFFER,
|
---|
| 120 | NULL);
|
---|
| 121 | if (hConsole == INVALID_HANDLE_VALUE)
|
---|
| 122 | {
|
---|
[7549] | 123 | dprintf(("KERNEL32/CONSOLE:OS2CreateConsoleScreenBuffer = %u.\n",
|
---|
| 124 | GetLastError()));
|
---|
[111] | 125 | return INVALID_HANDLE_VALUE; /* abort further processing immediately */
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | fResult = SetConsoleTextAttribute(hConsole,
|
---|
| 129 | pConsoleGlobals->Options.ucDefaultAttribute);
|
---|
| 130 | #ifdef DEBUG_LOCAL
|
---|
| 131 | if (fResult == FALSE) /* check errors */
|
---|
| 132 | WriteLog("KERNEL32/CONSOLE:OS2SetConsoleTextAttribute=%u.\n",
|
---|
| 133 | GetLastError());
|
---|
| 134 | #endif
|
---|
| 135 |
|
---|
| 136 | fResult = SetConsoleScreenBufferSize(hConsole,
|
---|
[10210] | 137 | pConsoleGlobals->coordWindowSize);
|
---|
[111] | 138 | if (fResult == FALSE)
|
---|
| 139 | {
|
---|
[7549] | 140 | dprintf(("KERNEL32/CONSOLE:OS2SetConsoleScreenBufferSize=%u.\n",
|
---|
| 141 | GetLastError()));
|
---|
[111] | 142 | HMCloseHandle(hConsole); /* free handle again */
|
---|
| 143 | return (INVALID_HANDLE_VALUE); /* abort further processing */
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | fResult = SetConsoleActiveScreenBuffer(hConsole);
|
---|
| 147 | if (fResult == FALSE)
|
---|
| 148 | {
|
---|
[7549] | 149 | dprintf(("KERNEL32/CONSOLE:OS2SetConsoleActiveScreenBuffer=%u.\n",
|
---|
| 150 | GetLastError()));
|
---|
[111] | 151 | HMCloseHandle(hConsole); /* free handle again */
|
---|
| 152 | return (INVALID_HANDLE_VALUE); /* abort further processing */
|
---|
| 153 | }
|
---|
| 154 | else
|
---|
| 155 | {
|
---|
| 156 | pConsoleGlobals->hConsoleBufferDefault = hConsole; /* save handle */
|
---|
| 157 | pConsoleGlobals->hConsoleBuffer = hConsole;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | return(NO_ERROR);
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[7549] | 164 | /*****************************************************************************
|
---|
| 165 | * Name : DWORD HMDeviceConsoleOutClass::GetFileType
|
---|
| 166 | * Purpose : determine the handle type
|
---|
| 167 | * Parameters: PHMHANDLEDATA pHMHandleData
|
---|
| 168 | * Variables :
|
---|
| 169 | * Result : API returncode
|
---|
| 170 | * Remark :
|
---|
| 171 | * Status :
|
---|
| 172 | *
|
---|
| 173 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
| 174 | *****************************************************************************/
|
---|
[111] | 175 |
|
---|
[7549] | 176 | DWORD HMDeviceConsoleOutClass::GetFileType(PHMHANDLEDATA pHMHandleData)
|
---|
| 177 | {
|
---|
| 178 | dprintf(("KERNEL32: HMDeviceConsoleOutClass::GetFileType %s(%08x)\n",
|
---|
| 179 | lpHMDeviceName,
|
---|
| 180 | pHMHandleData));
|
---|
| 181 |
|
---|
| 182 | return FILE_TYPE_CHAR;
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[111] | 185 | /*****************************************************************************
|
---|
| 186 | * Name :
|
---|
| 187 | * Purpose :
|
---|
| 188 | * Parameters:
|
---|
| 189 | * Variables :
|
---|
| 190 | * Result :
|
---|
| 191 | * Remark :
|
---|
| 192 | * Status :
|
---|
| 193 | *
|
---|
| 194 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
| 195 | *****************************************************************************/
|
---|
| 196 |
|
---|
[2050] | 197 | BOOL HMDeviceConsoleOutClass::ReadFile(PHMHANDLEDATA pHMHandleData,
|
---|
| 198 | LPCVOID lpBuffer,
|
---|
| 199 | DWORD nNumberOfBytesToRead,
|
---|
| 200 | LPDWORD lpNumberOfBytesRead,
|
---|
[7549] | 201 | LPOVERLAPPED lpOverlapped,
|
---|
| 202 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
---|
[111] | 203 | {
|
---|
| 204 |
|
---|
| 205 | #ifdef DEBUG_LOCAL
|
---|
| 206 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)\n",
|
---|
| 207 | lpHMDeviceName,
|
---|
[149] | 208 | pHMHandleData->hHMHandle,
|
---|
[111] | 209 | lpBuffer,
|
---|
| 210 | nNumberOfBytesToRead,
|
---|
| 211 | lpNumberOfBytesRead,
|
---|
| 212 | lpOverlapped);
|
---|
| 213 | #endif
|
---|
| 214 |
|
---|
[2984] | 215 | SetLastError(ERROR_ACCESS_DENIED_W);
|
---|
[2050] | 216 | return FALSE;
|
---|
[111] | 217 | }
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | /*****************************************************************************
|
---|
| 221 | * Name :
|
---|
| 222 | * Purpose :
|
---|
| 223 | * Parameters:
|
---|
| 224 | * Variables :
|
---|
| 225 | * Result :
|
---|
| 226 | * Remark :
|
---|
| 227 | * Status :
|
---|
| 228 | *
|
---|
| 229 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
| 230 | *****************************************************************************/
|
---|
| 231 |
|
---|
[2050] | 232 | BOOL HMDeviceConsoleOutClass::WriteFile(PHMHANDLEDATA pHMHandleData,
|
---|
[111] | 233 | LPCVOID lpBuffer,
|
---|
| 234 | DWORD nNumberOfBytesToWrite,
|
---|
| 235 | LPDWORD lpNumberOfBytesWritten,
|
---|
[7549] | 236 | LPOVERLAPPED lpOverlapped,
|
---|
| 237 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
---|
[111] | 238 | {
|
---|
[2050] | 239 | BOOL dwResult; /* result from subsequent WriteFile */
|
---|
[111] | 240 |
|
---|
| 241 | #ifdef DEBUG_LOCAL2
|
---|
[2050] | 242 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:WriteFile %s(%08x,%s,%08x,%08x,%08x)\n",
|
---|
[111] | 243 | lpHMDeviceName,
|
---|
[149] | 244 | pHMHandleData->hHMHandle,
|
---|
[111] | 245 | lpBuffer,
|
---|
| 246 | nNumberOfBytesToWrite,
|
---|
| 247 | lpNumberOfBytesWritten,
|
---|
| 248 | lpOverlapped);
|
---|
| 249 | #endif
|
---|
| 250 |
|
---|
[7550] | 251 | if(lpCompletionRoutine) {
|
---|
| 252 | dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | /* just prevent an endless loop, although this condition might never */
|
---|
| 256 | /* be true ! */
|
---|
[149] | 257 | if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
|
---|
[111] | 258 | {
|
---|
| 259 | dwResult = HMWriteFile(pConsoleGlobals->hConsoleBuffer,
|
---|
| 260 | lpBuffer,
|
---|
| 261 | nNumberOfBytesToWrite,
|
---|
| 262 | lpNumberOfBytesWritten,
|
---|
[7549] | 263 | lpOverlapped, lpCompletionRoutine);
|
---|
[111] | 264 |
|
---|
| 265 | return (dwResult); /* return result code */
|
---|
| 266 | }
|
---|
[5019] | 267 | else {
|
---|
[2050] | 268 | return (FALSE); /* raise error condition */
|
---|
[5019] | 269 | }
|
---|
[111] | 270 | }
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 | /*****************************************************************************
|
---|
| 274 | * Name : DWORD HMDeviceConsoleOutClass::_DeviceRequest
|
---|
| 275 | * Purpose : we just forward those device requests to the console buffer
|
---|
| 276 | * currently associated with the console itself.
|
---|
| 277 | * Parameters:
|
---|
| 278 | * Variables :
|
---|
| 279 | * Result :
|
---|
| 280 | * Remark :
|
---|
| 281 | * Status : UNTESTED
|
---|
| 282 | *
|
---|
| 283 | * Author : Patrick Haller [Wed, 1998/03/35 20:44]
|
---|
| 284 | *****************************************************************************/
|
---|
| 285 |
|
---|
| 286 | DWORD HMDeviceConsoleOutClass::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
|
---|
| 287 | ULONG ulRequestCode,
|
---|
| 288 | ULONG arg1,
|
---|
| 289 | ULONG arg2,
|
---|
| 290 | ULONG arg3,
|
---|
| 291 | ULONG arg4)
|
---|
| 292 | {
|
---|
| 293 | #ifdef DEBUG_LOCAL2
|
---|
| 294 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:_DeviceRequest %s(%08x,%08x,%08x,%08x,%08x,%08x)\n",
|
---|
| 295 | lpHMDeviceName,
|
---|
[149] | 296 | pHMHandleData->hHMHandle,
|
---|
[111] | 297 | ulRequestCode,
|
---|
| 298 | arg1,
|
---|
| 299 | arg2,
|
---|
| 300 | arg3,
|
---|
| 301 | arg4);
|
---|
| 302 | #endif
|
---|
| 303 | /* just prevent an endless loop, although this condition might never */
|
---|
| 304 | /* be true ! */
|
---|
[149] | 305 | if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
|
---|
[111] | 306 | return (HMDeviceRequest(pConsoleGlobals->hConsoleBuffer,
|
---|
| 307 | ulRequestCode,
|
---|
| 308 | arg1,
|
---|
| 309 | arg2,
|
---|
| 310 | arg3,
|
---|
| 311 | arg4));
|
---|
| 312 | else
|
---|
| 313 | return (ERROR_SYS_INTERNAL); /* raise error condition */
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[4407] | 316 |
|
---|