| 1 | /* $Id: conbuffervio.cpp,v 1.1 2000-10-20 11:46:45 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 Console API Translation for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * 1998/02/10 Patrick Haller (haller@zebra.fh-weingarten.de)
|
|---|
| 7 | *
|
|---|
| 8 | * @(#) console.cpp 1.0.0 1998/02/10 PH Start from scratch
|
|---|
| 9 | *
|
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 11 | *
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | #ifdef DEBUG
|
|---|
| 16 | #define DEBUG_LOCAL
|
|---|
| 17 | #define DEBUG_LOCAL2
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | //#undef DEBUG_LOCAL
|
|---|
| 21 | //#undef DEBUG_LOCAL2
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | /*****************************************************************************
|
|---|
| 25 | * Remark *
|
|---|
| 26 | *****************************************************************************
|
|---|
| 27 |
|
|---|
| 28 | - DWORD HandlerRoutine (DWORD dwCtrlType)
|
|---|
| 29 | basically an exception handler routine. handles a few signals / excpts.
|
|---|
| 30 | should be somewhere near the exception handling code ... :)
|
|---|
| 31 |
|
|---|
| 32 | Hmm, however as PM applications don't really get a ctrl-c signal,
|
|---|
| 33 | I'll have to do this on my own ...
|
|---|
| 34 |
|
|---|
| 35 | - supply unicode<->ascii conversions for all the _A and _W function pairs.
|
|---|
| 36 |
|
|---|
| 37 | - problem: we can't prevent thread1 from blocking the message queue ?
|
|---|
| 38 | what will happen if a WinTerminate() is issued there ?
|
|---|
| 39 | will the message queue be closed and provide smooth tasking ?
|
|---|
| 40 | how will open32 react on this ?
|
|---|
| 41 |
|
|---|
| 42 | - ECHO_LINE_INPUT / ReadFile blocks till CR
|
|---|
| 43 |
|
|---|
| 44 | - scrollbars
|
|---|
| 45 | * do some flowchart to exactly determine WHEN to use WHICH setting
|
|---|
| 46 | and perform WHAT action
|
|---|
| 47 |
|
|---|
| 48 | - clipboard support
|
|---|
| 49 | */
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | /*****************************************************************************
|
|---|
| 53 | * Includes *
|
|---|
| 54 | *****************************************************************************/
|
|---|
| 55 |
|
|---|
| 56 | #define INCL_WIN
|
|---|
| 57 | #define INCL_DOSMEMMGR
|
|---|
| 58 | #define INCL_DOSSEMAPHORES
|
|---|
| 59 | #define INCL_DOSERRORS
|
|---|
| 60 | #define INCL_DOSPROCESS
|
|---|
| 61 | #define INCL_DOSMODULEMGR
|
|---|
| 62 | #define INCL_VIO
|
|---|
| 63 | #define INCL_AVIO
|
|---|
| 64 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 65 |
|
|---|
| 66 | #include <win32api.h>
|
|---|
| 67 | #include <misc.h>
|
|---|
| 68 | #include <string.h>
|
|---|
| 69 | #include <stdlib.h>
|
|---|
| 70 | #include <stdio.h>
|
|---|
| 71 |
|
|---|
| 72 | #include "conwin.h" // Windows Header for console only
|
|---|
| 73 | #include "HandleManager.h"
|
|---|
| 74 | #include "HMDevice.h"
|
|---|
| 75 | #include "ConBuffervio.H"
|
|---|
| 76 | #include "Console2.h"
|
|---|
| 77 | #include <heapstring.h>
|
|---|
| 78 |
|
|---|
| 79 | #define DBG_LOCALLOG DBG_conbuffer
|
|---|
| 80 | #include "dbglocal.h"
|
|---|
| 81 |
|
|---|
| 82 | /*****************************************************************************
|
|---|
| 83 | * Name :
|
|---|
| 84 | * Purpose :
|
|---|
| 85 | * Parameters:
|
|---|
| 86 | * Variables :
|
|---|
| 87 | * Result :
|
|---|
| 88 | * Remark :
|
|---|
| 89 | * Status :
|
|---|
| 90 | *
|
|---|
| 91 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
|---|
| 92 | *****************************************************************************/
|
|---|
| 93 |
|
|---|
| 94 | BOOL HMDeviceConsoleVioBufferClass::WriteFile(PHMHANDLEDATA pHMHandleData,
|
|---|
| 95 | LPCVOID lpBuffer,
|
|---|
| 96 | DWORD nNumberOfBytesToWrite,
|
|---|
| 97 | LPDWORD lpNumberOfBytesWritten,
|
|---|
| 98 | LPOVERLAPPED lpOverlapped)
|
|---|
| 99 | {
|
|---|
| 100 | PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
|
|---|
| 101 | ULONG ulCounter; /* counter for the byte transfer */
|
|---|
| 102 | PSZ pszBuffer = (PSZ)lpBuffer;
|
|---|
| 103 | char filler[4] = {' ', 0x07, ' ', 0x07};
|
|---|
| 104 | register UCHAR ucChar;
|
|---|
| 105 | APIRET rc;
|
|---|
| 106 | ULONG Row;
|
|---|
| 107 | USHORT Column;
|
|---|
| 108 | int numchar;
|
|---|
| 109 |
|
|---|
| 110 | #ifdef DEBUG_LOCAL2
|
|---|
| 111 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleVioBufferClass:WriteFile %s(%08x,%08x,%08x,%08x,%08x)\n",
|
|---|
| 112 | lpHMDeviceName,
|
|---|
| 113 | pHMHandleData->hHMHandle,
|
|---|
| 114 | lpBuffer,
|
|---|
| 115 | nNumberOfBytesToWrite,
|
|---|
| 116 | lpNumberOfBytesWritten,
|
|---|
| 117 | lpOverlapped);
|
|---|
| 118 | #endif
|
|---|
| 119 |
|
|---|
| 120 | /* check if we're called with non-existing line buffer */
|
|---|
| 121 | if (pConsoleBuffer->ppszLine == NULL) {
|
|---|
| 122 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 123 | return FALSE;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | dprintf(("Current cursor position (%d,%d)", pConsoleBuffer->coordCursorPosition.X, pConsoleBuffer->coordCursorPosition.Y));
|
|---|
| 127 |
|
|---|
| 128 | ulCounter = 0;
|
|---|
| 129 | while(ulCounter < nNumberOfBytesToWrite)
|
|---|
| 130 | {
|
|---|
| 131 | ucChar = pszBuffer[ulCounter]; /* map to register */
|
|---|
| 132 |
|
|---|
| 133 | if ( (pConsoleBuffer->dwConsoleMode & ENABLE_PROCESSED_OUTPUT) &&
|
|---|
| 134 | (ucChar < 32) ) /* this is faster than a large switch statement */
|
|---|
| 135 | {
|
|---|
| 136 | switch (ucChar)
|
|---|
| 137 | {
|
|---|
| 138 | case 7: /* BEL */
|
|---|
| 139 | if (pConsoleGlobals->Options.fSpeakerEnabled == TRUE)
|
|---|
| 140 | DosBeep(pConsoleGlobals->Options.ulSpeakerFrequency,
|
|---|
| 141 | pConsoleGlobals->Options.ulSpeakerDuration);
|
|---|
| 142 | break;
|
|---|
| 143 | #if 0
|
|---|
| 144 | case 8: /* Backspace */
|
|---|
| 145 | // not correct if deleting expanded tab character
|
|---|
| 146 | rc = VioGetCurPos(&Row, &Column, 0);
|
|---|
| 147 | if(!rc) {
|
|---|
| 148 |
|
|---|
| 149 | }
|
|---|
| 150 | if (pConsoleBuffer->coordCursorPosition.X > 0)
|
|---|
| 151 | pConsoleBuffer->coordCursorPosition.X--;
|
|---|
| 152 |
|
|---|
| 153 | //@@@PH overwrite old character
|
|---|
| 154 | *(pConsoleBuffer->ppszLine[pConsoleBuffer->coordCursorPosition.Y] +
|
|---|
| 155 | pConsoleBuffer->coordCursorPosition.X * 2) = 0x20;
|
|---|
| 156 | break;
|
|---|
| 157 |
|
|---|
| 158 | case 9: /* Tab */
|
|---|
| 159 | {
|
|---|
| 160 | rc = VioWrite
|
|---|
| 161 | pConsoleBuffer->coordCursorPosition.X =
|
|---|
| 162 | (pConsoleBuffer->coordCursorPosition.X
|
|---|
| 163 | / pConsoleGlobals->Options.ulTabSize
|
|---|
| 164 | + 1)
|
|---|
| 165 | * pConsoleGlobals->Options.ulTabSize;
|
|---|
| 166 |
|
|---|
| 167 | if (pConsoleBuffer->coordCursorPosition.X >=
|
|---|
| 168 | pConsoleBuffer->coordBufferSize.X)
|
|---|
| 169 | {
|
|---|
| 170 | pConsoleBuffer->coordCursorPosition.X = 0;
|
|---|
| 171 | pConsoleBuffer->coordCursorPosition.Y++;
|
|---|
| 172 |
|
|---|
| 173 | if (pConsoleBuffer->coordCursorPosition.Y >=
|
|---|
| 174 | pConsoleBuffer->coordBufferSize.Y)
|
|---|
| 175 | {
|
|---|
| 176 | if (pConsoleBuffer->dwConsoleMode & ENABLE_WRAP_AT_EOL_OUTPUT)
|
|---|
| 177 | {
|
|---|
| 178 | iConsoleBufferScrollUp(pConsoleBuffer, /* scroll one line up */
|
|---|
| 179 | 1);
|
|---|
| 180 | pConsoleBuffer->coordCursorPosition.Y--;
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 | }
|
|---|
| 184 | break;
|
|---|
| 185 | #endif
|
|---|
| 186 | case 13: /* CARRIAGE RETURN */
|
|---|
| 187 | dprintf(("CR"));
|
|---|
| 188 | pConsoleBuffer->coordCursorPosition.X = 0;
|
|---|
| 189 | VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
|---|
| 190 | break;
|
|---|
| 191 |
|
|---|
| 192 | case 10: /* LINEFEED */
|
|---|
| 193 | {
|
|---|
| 194 | dprintf(("LF"));
|
|---|
| 195 | pConsoleBuffer->coordCursorPosition.Y++;
|
|---|
| 196 | if(pConsoleBuffer->coordCursorPosition.Y >= pConsoleBuffer->coordWindowSize.Y) {
|
|---|
| 197 | dprintf(("scrollup"));
|
|---|
| 198 | VioScrollUp(0, 0, pConsoleBuffer->coordWindowSize.Y-1, pConsoleBuffer->coordWindowSize.X-1,
|
|---|
| 199 | 1, &filler[0], 0);
|
|---|
| 200 | pConsoleBuffer->coordCursorPosition.Y = pConsoleBuffer->coordWindowSize.Y-1;
|
|---|
| 201 | }
|
|---|
| 202 | VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
|---|
| 203 | break;
|
|---|
| 204 | }
|
|---|
| 205 | default:
|
|---|
| 206 | break;
|
|---|
| 207 | }
|
|---|
| 208 | ulCounter++;
|
|---|
| 209 | }
|
|---|
| 210 | else
|
|---|
| 211 | {
|
|---|
| 212 | //// dprintf(("Current cursor position (%d,%d)", pConsoleBuffer->coordCursorPosition.X, pConsoleBuffer->coordCursorPosition.Y));
|
|---|
| 213 | numchar = ulCounter;
|
|---|
| 214 | while(pszBuffer[numchar] >= 32 && numchar < nNumberOfBytesToWrite) {
|
|---|
| 215 | numchar++;
|
|---|
| 216 | }
|
|---|
| 217 | numchar = numchar - ulCounter;
|
|---|
| 218 |
|
|---|
| 219 | if(pConsoleBuffer->coordCursorPosition.X + numchar > pConsoleBuffer->coordWindowSize.X)
|
|---|
| 220 | {
|
|---|
| 221 | int tmp = pConsoleBuffer->coordWindowSize.X - pConsoleBuffer->coordCursorPosition.X;
|
|---|
| 222 |
|
|---|
| 223 | VioWrtCharStr(&pszBuffer[ulCounter], tmp, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
|---|
| 224 | ulCounter += tmp;
|
|---|
| 225 | numchar -= tmp;
|
|---|
| 226 |
|
|---|
| 227 | pConsoleBuffer->coordCursorPosition.X = 0;
|
|---|
| 228 | pConsoleBuffer->coordCursorPosition.Y++;
|
|---|
| 229 | if(pConsoleBuffer->coordCursorPosition.Y >= pConsoleBuffer->coordWindowSize.Y) {
|
|---|
| 230 | dprintf(("scrollup"));
|
|---|
| 231 | VioScrollUp(0, 0, pConsoleBuffer->coordWindowSize.Y-1, pConsoleBuffer->coordWindowSize.X-1,
|
|---|
| 232 | 1, &filler[0], 0);
|
|---|
| 233 | pConsoleBuffer->coordCursorPosition.Y = pConsoleBuffer->coordWindowSize.Y-1;
|
|---|
| 234 | }
|
|---|
| 235 | VioWrtCharStr(&pszBuffer[ulCounter], numchar, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
|---|
| 236 | pConsoleBuffer->coordCursorPosition.X += numchar;
|
|---|
| 237 | VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
|---|
| 238 | }
|
|---|
| 239 | else {
|
|---|
| 240 | VioWrtCharStr(&pszBuffer[ulCounter], numchar, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
|---|
| 241 | pConsoleBuffer->coordCursorPosition.X += numchar;
|
|---|
| 242 | }
|
|---|
| 243 | ulCounter += numchar;
|
|---|
| 244 | }
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | *lpNumberOfBytesWritten = ulCounter;
|
|---|
| 248 |
|
|---|
| 249 | return TRUE;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|