| 1 | /* $Id: conout.cpp,v 1.6 2000-02-16 14:25:32 sandervl Exp $ */
|
|---|
| 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 |
|
|---|
| 15 | //#undef DEBUG_LOCAL
|
|---|
| 16 | //#undef DEBUG_LOCAL2
|
|---|
| 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
|
|---|
| 59 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 60 | #include <builtin.h>
|
|---|
| 61 | #include <stdlib.h>
|
|---|
| 62 | #include <string.h>
|
|---|
| 63 |
|
|---|
| 64 | #include <win32type.h>
|
|---|
| 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 |
|
|---|
| 76 | #define DBG_LOCALLOG DBG_conout
|
|---|
| 77 | #include "dbglocal.h"
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | /***********************************
|
|---|
| 81 | * Open32 support for SetLastError *
|
|---|
| 82 | ***********************************/
|
|---|
| 83 | #include <os2sel.h>
|
|---|
| 84 |
|
|---|
| 85 | extern "C"
|
|---|
| 86 | {
|
|---|
| 87 | void _System _O32_SetLastError(DWORD dwError);
|
|---|
| 88 | int _System _O32_GetLastError(void);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | inline void SetLastError(DWORD a)
|
|---|
| 92 | {
|
|---|
| 93 | USHORT sel = GetFS();
|
|---|
| 94 |
|
|---|
| 95 | _O32_SetLastError(a);
|
|---|
| 96 | SetFS(sel);
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | inline int GetLastError(void)
|
|---|
| 100 | {
|
|---|
| 101 | USHORT sel = GetFS();
|
|---|
| 102 | int rc;
|
|---|
| 103 |
|
|---|
| 104 | rc = _O32_GetLastError();
|
|---|
| 105 | SetFS(sel);
|
|---|
| 106 | return rc;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 | /*****************************************************************************
|
|---|
| 111 | * Name : DWORD HMDeviceConsoleOutClass::CreateFile
|
|---|
| 112 | * Purpose : this is called from the handle manager if a CreateFile() is
|
|---|
| 113 | * performed on a handle
|
|---|
| 114 | * Parameters: LPCSTR lpFileName name of the file / device
|
|---|
| 115 | * PHMHANDLEDATA pHMHandleData data of the NEW handle
|
|---|
| 116 | * PVOID lpSecurityAttributes ignored
|
|---|
| 117 | * PHMHANDLEDATA pHMHandleDataTemplate data of the template handle
|
|---|
| 118 | * Variables :
|
|---|
| 119 | * Result :
|
|---|
| 120 | * Remark :
|
|---|
| 121 | * Status : NO_ERROR - API succeeded
|
|---|
| 122 | * other - what is to be set in SetLastError
|
|---|
| 123 | *
|
|---|
| 124 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 125 | *****************************************************************************/
|
|---|
| 126 |
|
|---|
| 127 | DWORD HMDeviceConsoleOutClass::CreateFile (LPCSTR lpFileName,
|
|---|
| 128 | PHMHANDLEDATA pHMHandleData,
|
|---|
| 129 | PVOID lpSecurityAttributes,
|
|---|
| 130 | PHMHANDLEDATA pHMHandleDataTemplate)
|
|---|
| 131 | {
|
|---|
| 132 | APIRET rc;
|
|---|
| 133 | BOOL fResult;
|
|---|
| 134 | HANDLE hConsole;
|
|---|
| 135 |
|
|---|
| 136 | #ifdef DEBUG_LOCAL2
|
|---|
| 137 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass %s(%s,%08x,%08x,%08x)\n",
|
|---|
| 138 | lpHMDeviceName,
|
|---|
| 139 | lpFileName,
|
|---|
| 140 | pHMHandleData->hHMHandle,
|
|---|
| 141 | lpSecurityAttributes,
|
|---|
| 142 | pHMHandleDataTemplate);
|
|---|
| 143 | #endif
|
|---|
| 144 |
|
|---|
| 145 | pHMHandleData->dwType = FILE_TYPE_CHAR; /* we're a character device */
|
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 | /* if no default buffer is available, then do default setup */
|
|---|
| 149 | if (pConsoleGlobals->hConsoleBuffer == INVALID_HANDLE_VALUE)
|
|---|
| 150 | {
|
|---|
| 151 | /* now we need a default screen buffer with the default size */
|
|---|
| 152 | hConsole = CreateConsoleScreenBuffer(0,
|
|---|
| 153 | 0,
|
|---|
| 154 | NULL,
|
|---|
| 155 | CONSOLE_TEXTMODE_BUFFER,
|
|---|
| 156 | NULL);
|
|---|
| 157 | if (hConsole == INVALID_HANDLE_VALUE)
|
|---|
| 158 | {
|
|---|
| 159 | #ifdef DEBUG_LOCAL
|
|---|
| 160 | WriteLog("KERNEL32/CONSOLE:OS2CreateConsoleScreenBuffer = %u.\n",
|
|---|
| 161 | GetLastError());
|
|---|
| 162 | #endif
|
|---|
| 163 | return INVALID_HANDLE_VALUE; /* abort further processing immediately */
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | fResult = SetConsoleTextAttribute(hConsole,
|
|---|
| 167 | pConsoleGlobals->Options.ucDefaultAttribute);
|
|---|
| 168 | #ifdef DEBUG_LOCAL
|
|---|
| 169 | if (fResult == FALSE) /* check errors */
|
|---|
| 170 | WriteLog("KERNEL32/CONSOLE:OS2SetConsoleTextAttribute=%u.\n",
|
|---|
| 171 | GetLastError());
|
|---|
| 172 | #endif
|
|---|
| 173 |
|
|---|
| 174 | fResult = SetConsoleScreenBufferSize(hConsole,
|
|---|
| 175 | pConsoleGlobals->Options.coordDefaultSize);
|
|---|
| 176 | if (fResult == FALSE)
|
|---|
| 177 | {
|
|---|
| 178 | #ifdef DEBUG_LOCAL
|
|---|
| 179 | WriteLog("KERNEL32/CONSOLE:OS2SetConsoleScreenBufferSize=%u.\n",
|
|---|
| 180 | GetLastError());
|
|---|
| 181 | #endif
|
|---|
| 182 | HMCloseHandle(hConsole); /* free handle again */
|
|---|
| 183 | return (INVALID_HANDLE_VALUE); /* abort further processing */
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | fResult = SetConsoleActiveScreenBuffer(hConsole);
|
|---|
| 187 | if (fResult == FALSE)
|
|---|
| 188 | {
|
|---|
| 189 | #ifdef DEBUG_LOCAL
|
|---|
| 190 | WriteLog("KERNEL32/CONSOLE:OS2SetConsoleActiveScreenBuffer=%u.\n",
|
|---|
| 191 | GetLastError());
|
|---|
| 192 | #endif
|
|---|
| 193 | HMCloseHandle(hConsole); /* free handle again */
|
|---|
| 194 | return (INVALID_HANDLE_VALUE); /* abort further processing */
|
|---|
| 195 | }
|
|---|
| 196 | else
|
|---|
| 197 | {
|
|---|
| 198 | pConsoleGlobals->hConsoleBufferDefault = hConsole; /* save handle */
|
|---|
| 199 | pConsoleGlobals->hConsoleBuffer = hConsole;
|
|---|
| 200 | }
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | return(NO_ERROR);
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 | /*****************************************************************************
|
|---|
| 208 | * Name :
|
|---|
| 209 | * Purpose :
|
|---|
| 210 | * Parameters:
|
|---|
| 211 | * Variables :
|
|---|
| 212 | * Result :
|
|---|
| 213 | * Remark :
|
|---|
| 214 | * Status :
|
|---|
| 215 | *
|
|---|
| 216 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 217 | *****************************************************************************/
|
|---|
| 218 |
|
|---|
| 219 | BOOL HMDeviceConsoleOutClass::ReadFile(PHMHANDLEDATA pHMHandleData,
|
|---|
| 220 | LPCVOID lpBuffer,
|
|---|
| 221 | DWORD nNumberOfBytesToRead,
|
|---|
| 222 | LPDWORD lpNumberOfBytesRead,
|
|---|
| 223 | LPOVERLAPPED lpOverlapped)
|
|---|
| 224 | {
|
|---|
| 225 |
|
|---|
| 226 | #ifdef DEBUG_LOCAL
|
|---|
| 227 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)\n",
|
|---|
| 228 | lpHMDeviceName,
|
|---|
| 229 | pHMHandleData->hHMHandle,
|
|---|
| 230 | lpBuffer,
|
|---|
| 231 | nNumberOfBytesToRead,
|
|---|
| 232 | lpNumberOfBytesRead,
|
|---|
| 233 | lpOverlapped);
|
|---|
| 234 | #endif
|
|---|
| 235 |
|
|---|
| 236 | SetLastError(ERROR_ACCESS_DENIED);
|
|---|
| 237 | return FALSE;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 | /*****************************************************************************
|
|---|
| 242 | * Name :
|
|---|
| 243 | * Purpose :
|
|---|
| 244 | * Parameters:
|
|---|
| 245 | * Variables :
|
|---|
| 246 | * Result :
|
|---|
| 247 | * Remark :
|
|---|
| 248 | * Status :
|
|---|
| 249 | *
|
|---|
| 250 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 251 | *****************************************************************************/
|
|---|
| 252 |
|
|---|
| 253 | BOOL HMDeviceConsoleOutClass::WriteFile(PHMHANDLEDATA pHMHandleData,
|
|---|
| 254 | LPCVOID lpBuffer,
|
|---|
| 255 | DWORD nNumberOfBytesToWrite,
|
|---|
| 256 | LPDWORD lpNumberOfBytesWritten,
|
|---|
| 257 | LPOVERLAPPED lpOverlapped)
|
|---|
| 258 | {
|
|---|
| 259 | BOOL dwResult; /* result from subsequent WriteFile */
|
|---|
| 260 |
|
|---|
| 261 | #ifdef DEBUG_LOCAL2
|
|---|
| 262 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:WriteFile %s(%08x,%s,%08x,%08x,%08x)\n",
|
|---|
| 263 | lpHMDeviceName,
|
|---|
| 264 | pHMHandleData->hHMHandle,
|
|---|
| 265 | lpBuffer,
|
|---|
| 266 | nNumberOfBytesToWrite,
|
|---|
| 267 | lpNumberOfBytesWritten,
|
|---|
| 268 | lpOverlapped);
|
|---|
| 269 | #endif
|
|---|
| 270 |
|
|---|
| 271 | /* just prevent an endless loop, although this condition might never */
|
|---|
| 272 | /* be true ! */
|
|---|
| 273 | if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
|
|---|
| 274 | {
|
|---|
| 275 | #if 0
|
|---|
| 276 | HMDeviceRequest(pConsoleGlobals->hConsoleBuffer, /* hide the cursor */
|
|---|
| 277 | DRQ_INTERNAL_CONSOLECURSORSHOW,
|
|---|
| 278 | CONSOLECURSOR_HIDE,
|
|---|
| 279 | 0,
|
|---|
| 280 | 0,
|
|---|
| 281 | 0);
|
|---|
| 282 | #endif
|
|---|
| 283 |
|
|---|
| 284 | dwResult = HMWriteFile(pConsoleGlobals->hConsoleBuffer,
|
|---|
| 285 | lpBuffer,
|
|---|
| 286 | nNumberOfBytesToWrite,
|
|---|
| 287 | lpNumberOfBytesWritten,
|
|---|
| 288 | lpOverlapped);
|
|---|
| 289 |
|
|---|
| 290 | #if 0
|
|---|
| 291 | HMDeviceRequest(pConsoleGlobals->hConsoleBuffer, /* show the cursor */
|
|---|
| 292 | DRQ_INTERNAL_CONSOLECURSORSHOW,
|
|---|
| 293 | CONSOLECURSOR_SHOW,
|
|---|
| 294 | 0,
|
|---|
| 295 | 0,
|
|---|
| 296 | 0);
|
|---|
| 297 | #endif
|
|---|
| 298 |
|
|---|
| 299 | return (dwResult); /* return result code */
|
|---|
| 300 | }
|
|---|
| 301 | else
|
|---|
| 302 | return (FALSE); /* raise error condition */
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 | /*****************************************************************************
|
|---|
| 307 | * Name : DWORD HMDeviceConsoleOutClass::_DeviceRequest
|
|---|
| 308 | * Purpose : we just forward those device requests to the console buffer
|
|---|
| 309 | * currently associated with the console itself.
|
|---|
| 310 | * Parameters:
|
|---|
| 311 | * Variables :
|
|---|
| 312 | * Result :
|
|---|
| 313 | * Remark :
|
|---|
| 314 | * Status : UNTESTED
|
|---|
| 315 | *
|
|---|
| 316 | * Author : Patrick Haller [Wed, 1998/03/35 20:44]
|
|---|
| 317 | *****************************************************************************/
|
|---|
| 318 |
|
|---|
| 319 | DWORD HMDeviceConsoleOutClass::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
|
|---|
| 320 | ULONG ulRequestCode,
|
|---|
| 321 | ULONG arg1,
|
|---|
| 322 | ULONG arg2,
|
|---|
| 323 | ULONG arg3,
|
|---|
| 324 | ULONG arg4)
|
|---|
| 325 | {
|
|---|
| 326 | #ifdef DEBUG_LOCAL2
|
|---|
| 327 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:_DeviceRequest %s(%08x,%08x,%08x,%08x,%08x,%08x)\n",
|
|---|
| 328 | lpHMDeviceName,
|
|---|
| 329 | pHMHandleData->hHMHandle,
|
|---|
| 330 | ulRequestCode,
|
|---|
| 331 | arg1,
|
|---|
| 332 | arg2,
|
|---|
| 333 | arg3,
|
|---|
| 334 | arg4);
|
|---|
| 335 | #endif
|
|---|
| 336 | /* just prevent an endless loop, although this condition might never */
|
|---|
| 337 | /* be true ! */
|
|---|
| 338 | if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
|
|---|
| 339 | return (HMDeviceRequest(pConsoleGlobals->hConsoleBuffer,
|
|---|
| 340 | ulRequestCode,
|
|---|
| 341 | arg1,
|
|---|
| 342 | arg2,
|
|---|
| 343 | arg3,
|
|---|
| 344 | arg4));
|
|---|
| 345 | else
|
|---|
| 346 | return (ERROR_SYS_INTERNAL); /* raise error condition */
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|