1 | /* $Id: conbuffervio.cpp,v 1.5 2001-12-05 14:15:57 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 | #include <malloc.h>
|
---|
72 |
|
---|
73 | #include "conwin.h" // Windows Header for console only
|
---|
74 | #include "HandleManager.h"
|
---|
75 | #include "HMDevice.h"
|
---|
76 | #include "ConBuffervio.H"
|
---|
77 | #include "Console2.h"
|
---|
78 | #include <heapstring.h>
|
---|
79 |
|
---|
80 | #define DBG_LOCALLOG DBG_conbuffer
|
---|
81 | #include "dbglocal.h"
|
---|
82 |
|
---|
83 | /*****************************************************************************
|
---|
84 | * Name :
|
---|
85 | * Purpose :
|
---|
86 | * Parameters:
|
---|
87 | * Variables :
|
---|
88 | * Result :
|
---|
89 | * Remark :
|
---|
90 | * Status :
|
---|
91 | *
|
---|
92 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
93 | *****************************************************************************/
|
---|
94 |
|
---|
95 | BOOL HMDeviceConsoleVioBufferClass::WriteFile(PHMHANDLEDATA pHMHandleData,
|
---|
96 | LPCVOID lpBuffer,
|
---|
97 | DWORD nNumberOfBytesToWrite,
|
---|
98 | LPDWORD lpNumberOfBytesWritten,
|
---|
99 | LPOVERLAPPED lpOverlapped,
|
---|
100 | LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
|
---|
101 | {
|
---|
102 | PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
|
---|
103 | ULONG ulCounter; /* counter for the byte transfer */
|
---|
104 | PSZ pszBuffer;
|
---|
105 | char filler[4] = {' ', 0x07, ' ', 0x07};
|
---|
106 | register UCHAR ucChar;
|
---|
107 | APIRET rc;
|
---|
108 | ULONG Row;
|
---|
109 | USHORT Column;
|
---|
110 | int numchar;
|
---|
111 |
|
---|
112 | #ifdef DEBUG_LOCAL2
|
---|
113 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleVioBufferClass:WriteFile %s(%08x,%08x,%08x,%08x,%08x)\n",
|
---|
114 | lpHMDeviceName,
|
---|
115 | pHMHandleData->hHMHandle,
|
---|
116 | lpBuffer,
|
---|
117 | nNumberOfBytesToWrite,
|
---|
118 | lpNumberOfBytesWritten,
|
---|
119 | lpOverlapped);
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | /* check if we're called with non-existing line buffer */
|
---|
123 | if (pConsoleBuffer->ppszLine == NULL) {
|
---|
124 | SetLastError(ERROR_OUTOFMEMORY_W);
|
---|
125 | return FALSE;
|
---|
126 | }
|
---|
127 |
|
---|
128 | dprintf(("Current cursor position (%d,%d)", pConsoleBuffer->coordCursorPosition.X, pConsoleBuffer->coordCursorPosition.Y));
|
---|
129 |
|
---|
130 | if(nNumberOfBytesToWrite > 1024)
|
---|
131 | {
|
---|
132 | int tmp = 0;
|
---|
133 | BOOL retcode;
|
---|
134 |
|
---|
135 | while(nNumberOfBytesToWrite) {
|
---|
136 | *lpNumberOfBytesWritten = 0;
|
---|
137 | retcode = WriteFile(pHMHandleData, lpBuffer,
|
---|
138 | min(nNumberOfBytesToWrite, 512), lpNumberOfBytesWritten,
|
---|
139 | lpOverlapped, lpCompletionRoutine);
|
---|
140 | if(retcode != TRUE) break;
|
---|
141 |
|
---|
142 | tmp += *lpNumberOfBytesWritten;
|
---|
143 | nNumberOfBytesToWrite -= *lpNumberOfBytesWritten;
|
---|
144 | lpBuffer = (LPCVOID)((char *)lpBuffer + *lpNumberOfBytesWritten);
|
---|
145 | }
|
---|
146 | *lpNumberOfBytesWritten = tmp;
|
---|
147 | return retcode;
|
---|
148 | }
|
---|
149 | pszBuffer = (PSZ)alloca(nNumberOfBytesToWrite);
|
---|
150 | if(pszBuffer == NULL) {
|
---|
151 | DebugInt3();
|
---|
152 | return FALSE;
|
---|
153 | }
|
---|
154 | memcpy(pszBuffer, lpBuffer, nNumberOfBytesToWrite);
|
---|
155 |
|
---|
156 | ulCounter = 0;
|
---|
157 | while(ulCounter < nNumberOfBytesToWrite)
|
---|
158 | {
|
---|
159 | ucChar = pszBuffer[ulCounter]; /* map to register */
|
---|
160 |
|
---|
161 | if ( (pConsoleBuffer->dwConsoleMode & ENABLE_PROCESSED_OUTPUT) &&
|
---|
162 | (ucChar < 32) ) /* this is faster than a large switch statement */
|
---|
163 | {
|
---|
164 | switch (ucChar)
|
---|
165 | {
|
---|
166 | case 7: /* BEL */
|
---|
167 | if (pConsoleGlobals->Options.fSpeakerEnabled == TRUE)
|
---|
168 | DosBeep(pConsoleGlobals->Options.ulSpeakerFrequency,
|
---|
169 | pConsoleGlobals->Options.ulSpeakerDuration);
|
---|
170 | break;
|
---|
171 | #if 0
|
---|
172 | case 8: /* Backspace */
|
---|
173 | // not correct if deleting expanded tab character
|
---|
174 | rc = VioGetCurPos(&Row, &Column, 0);
|
---|
175 | if(!rc) {
|
---|
176 |
|
---|
177 | }
|
---|
178 | if (pConsoleBuffer->coordCursorPosition.X > 0)
|
---|
179 | pConsoleBuffer->coordCursorPosition.X--;
|
---|
180 |
|
---|
181 | //@@@PH overwrite old character
|
---|
182 | *(pConsoleBuffer->ppszLine[pConsoleBuffer->coordCursorPosition.Y] +
|
---|
183 | pConsoleBuffer->coordCursorPosition.X * 2) = 0x20;
|
---|
184 | break;
|
---|
185 |
|
---|
186 | case 9: /* Tab */
|
---|
187 | {
|
---|
188 | rc = VioWrite
|
---|
189 | pConsoleBuffer->coordCursorPosition.X =
|
---|
190 | (pConsoleBuffer->coordCursorPosition.X
|
---|
191 | / pConsoleGlobals->Options.ulTabSize
|
---|
192 | + 1)
|
---|
193 | * pConsoleGlobals->Options.ulTabSize;
|
---|
194 |
|
---|
195 | if (pConsoleBuffer->coordCursorPosition.X >=
|
---|
196 | pConsoleBuffer->coordBufferSize.X)
|
---|
197 | {
|
---|
198 | pConsoleBuffer->coordCursorPosition.X = 0;
|
---|
199 | pConsoleBuffer->coordCursorPosition.Y++;
|
---|
200 |
|
---|
201 | if (pConsoleBuffer->coordCursorPosition.Y >=
|
---|
202 | pConsoleBuffer->coordBufferSize.Y)
|
---|
203 | {
|
---|
204 | if (pConsoleBuffer->dwConsoleMode & ENABLE_WRAP_AT_EOL_OUTPUT)
|
---|
205 | {
|
---|
206 | iConsoleBufferScrollUp(pConsoleBuffer, /* scroll one line up */
|
---|
207 | 1);
|
---|
208 | pConsoleBuffer->coordCursorPosition.Y--;
|
---|
209 | }
|
---|
210 | }
|
---|
211 | }
|
---|
212 | break;
|
---|
213 | #endif
|
---|
214 | case 13: /* CARRIAGE RETURN */
|
---|
215 | dprintf(("CR"));
|
---|
216 | pConsoleBuffer->coordCursorPosition.X = 0;
|
---|
217 | VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
---|
218 | break;
|
---|
219 |
|
---|
220 | case 10: /* LINEFEED */
|
---|
221 | {
|
---|
222 | dprintf(("LF"));
|
---|
223 | pConsoleBuffer->coordCursorPosition.Y++;
|
---|
224 | pConsoleBuffer->coordCursorPosition.X = 0;
|
---|
225 | if(pConsoleBuffer->coordCursorPosition.Y >= pConsoleBuffer->coordWindowSize.Y) {
|
---|
226 | dprintf(("scrollup"));
|
---|
227 | VioScrollUp(0, 0, pConsoleBuffer->coordWindowSize.Y-1, pConsoleBuffer->coordWindowSize.X-1,
|
---|
228 | 1, &filler[0], 0);
|
---|
229 | pConsoleBuffer->coordCursorPosition.Y = pConsoleBuffer->coordWindowSize.Y-1;
|
---|
230 | }
|
---|
231 | VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
---|
232 | break;
|
---|
233 | }
|
---|
234 | default:
|
---|
235 | break;
|
---|
236 | }
|
---|
237 | ulCounter++;
|
---|
238 | }
|
---|
239 | else
|
---|
240 | {
|
---|
241 | //// dprintf(("Current cursor position (%d,%d)", pConsoleBuffer->coordCursorPosition.X, pConsoleBuffer->coordCursorPosition.Y));
|
---|
242 | numchar = ulCounter;
|
---|
243 | while(pszBuffer[numchar] >= 32 && numchar < nNumberOfBytesToWrite) {
|
---|
244 | numchar++;
|
---|
245 | }
|
---|
246 | numchar = numchar - ulCounter;
|
---|
247 |
|
---|
248 | if(pConsoleBuffer->coordCursorPosition.X + numchar > pConsoleBuffer->coordWindowSize.X)
|
---|
249 | {
|
---|
250 | int tmp = pConsoleBuffer->coordWindowSize.X - pConsoleBuffer->coordCursorPosition.X;
|
---|
251 |
|
---|
252 | VioWrtCharStr(&pszBuffer[ulCounter], tmp, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
---|
253 | ulCounter += tmp;
|
---|
254 | numchar -= tmp;
|
---|
255 |
|
---|
256 | pConsoleBuffer->coordCursorPosition.X = 0;
|
---|
257 | pConsoleBuffer->coordCursorPosition.Y++;
|
---|
258 | if(pConsoleBuffer->coordCursorPosition.Y >= pConsoleBuffer->coordWindowSize.Y) {
|
---|
259 | dprintf(("scrollup"));
|
---|
260 | VioScrollUp(0, 0, pConsoleBuffer->coordWindowSize.Y-1, pConsoleBuffer->coordWindowSize.X-1,
|
---|
261 | 1, &filler[0], 0);
|
---|
262 | pConsoleBuffer->coordCursorPosition.Y = pConsoleBuffer->coordWindowSize.Y-1;
|
---|
263 | }
|
---|
264 | VioWrtCharStr(&pszBuffer[ulCounter], numchar, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
---|
265 | pConsoleBuffer->coordCursorPosition.X += numchar;
|
---|
266 | VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
---|
267 | }
|
---|
268 | else {
|
---|
269 | VioWrtCharStr(&pszBuffer[ulCounter], numchar, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
|
---|
270 | pConsoleBuffer->coordCursorPosition.X += numchar;
|
---|
271 | }
|
---|
272 | ulCounter += numchar;
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | *lpNumberOfBytesWritten = ulCounter;
|
---|
277 |
|
---|
278 | return TRUE;
|
---|
279 | }
|
---|
280 |
|
---|
281 |
|
---|