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