source: trunk/src/kernel32/conbuffervio.cpp@ 5016

Last change on this file since 5016 was 5016, checked in by sandervl, 25 years ago

vio, thread exit fixes

File size: 9.5 KB
Line 
1/* $Id: conbuffervio.cpp,v 1.3 2001-01-23 11:59: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
94BOOL 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;
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 if(nNumberOfBytesToWrite > 1024)
129 {
130 int tmp = 0;
131 BOOL retcode;
132
133 while(nNumberOfBytesToWrite) {
134 *lpNumberOfBytesWritten = 0;
135 retcode = WriteFile(pHMHandleData, lpBuffer,
136 min(nNumberOfBytesToWrite, 512), lpNumberOfBytesWritten,
137 lpOverlapped);
138 if(retcode != TRUE) break;
139
140 tmp += *lpNumberOfBytesWritten;
141 nNumberOfBytesToWrite -= *lpNumberOfBytesWritten;
142 lpBuffer = (LPCVOID)((char *)lpBuffer + *lpNumberOfBytesWritten);
143 }
144 *lpNumberOfBytesWritten = tmp;
145 return retcode;
146 }
147 pszBuffer = (PSZ)alloca(nNumberOfBytesToWrite);
148 if(pszBuffer == NULL) {
149 DebugInt3();
150 return FALSE;
151 }
152 memcpy(pszBuffer, lpBuffer, nNumberOfBytesToWrite);
153
154 ulCounter = 0;
155 while(ulCounter < nNumberOfBytesToWrite)
156 {
157 ucChar = pszBuffer[ulCounter]; /* map to register */
158
159 if ( (pConsoleBuffer->dwConsoleMode & ENABLE_PROCESSED_OUTPUT) &&
160 (ucChar < 32) ) /* this is faster than a large switch statement */
161 {
162 switch (ucChar)
163 {
164 case 7: /* BEL */
165 if (pConsoleGlobals->Options.fSpeakerEnabled == TRUE)
166 DosBeep(pConsoleGlobals->Options.ulSpeakerFrequency,
167 pConsoleGlobals->Options.ulSpeakerDuration);
168 break;
169#if 0
170 case 8: /* Backspace */
171 // not correct if deleting expanded tab character
172 rc = VioGetCurPos(&Row, &Column, 0);
173 if(!rc) {
174
175 }
176 if (pConsoleBuffer->coordCursorPosition.X > 0)
177 pConsoleBuffer->coordCursorPosition.X--;
178
179 //@@@PH overwrite old character
180 *(pConsoleBuffer->ppszLine[pConsoleBuffer->coordCursorPosition.Y] +
181 pConsoleBuffer->coordCursorPosition.X * 2) = 0x20;
182 break;
183
184 case 9: /* Tab */
185 {
186 rc = VioWrite
187 pConsoleBuffer->coordCursorPosition.X =
188 (pConsoleBuffer->coordCursorPosition.X
189 / pConsoleGlobals->Options.ulTabSize
190 + 1)
191 * pConsoleGlobals->Options.ulTabSize;
192
193 if (pConsoleBuffer->coordCursorPosition.X >=
194 pConsoleBuffer->coordBufferSize.X)
195 {
196 pConsoleBuffer->coordCursorPosition.X = 0;
197 pConsoleBuffer->coordCursorPosition.Y++;
198
199 if (pConsoleBuffer->coordCursorPosition.Y >=
200 pConsoleBuffer->coordBufferSize.Y)
201 {
202 if (pConsoleBuffer->dwConsoleMode & ENABLE_WRAP_AT_EOL_OUTPUT)
203 {
204 iConsoleBufferScrollUp(pConsoleBuffer, /* scroll one line up */
205 1);
206 pConsoleBuffer->coordCursorPosition.Y--;
207 }
208 }
209 }
210 break;
211#endif
212 case 13: /* CARRIAGE RETURN */
213 dprintf(("CR"));
214 pConsoleBuffer->coordCursorPosition.X = 0;
215 VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
216 break;
217
218 case 10: /* LINEFEED */
219 {
220 dprintf(("LF"));
221 pConsoleBuffer->coordCursorPosition.Y++;
222 pConsoleBuffer->coordCursorPosition.X = 0;
223 if(pConsoleBuffer->coordCursorPosition.Y >= pConsoleBuffer->coordWindowSize.Y) {
224 dprintf(("scrollup"));
225 VioScrollUp(0, 0, pConsoleBuffer->coordWindowSize.Y-1, pConsoleBuffer->coordWindowSize.X-1,
226 1, &filler[0], 0);
227 pConsoleBuffer->coordCursorPosition.Y = pConsoleBuffer->coordWindowSize.Y-1;
228 }
229 VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
230 break;
231 }
232 default:
233 break;
234 }
235 ulCounter++;
236 }
237 else
238 {
239//// dprintf(("Current cursor position (%d,%d)", pConsoleBuffer->coordCursorPosition.X, pConsoleBuffer->coordCursorPosition.Y));
240 numchar = ulCounter;
241 while(pszBuffer[numchar] >= 32 && numchar < nNumberOfBytesToWrite) {
242 numchar++;
243 }
244 numchar = numchar - ulCounter;
245
246 if(pConsoleBuffer->coordCursorPosition.X + numchar > pConsoleBuffer->coordWindowSize.X)
247 {
248 int tmp = pConsoleBuffer->coordWindowSize.X - pConsoleBuffer->coordCursorPosition.X;
249
250 VioWrtCharStr(&pszBuffer[ulCounter], tmp, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
251 ulCounter += tmp;
252 numchar -= tmp;
253
254 pConsoleBuffer->coordCursorPosition.X = 0;
255 pConsoleBuffer->coordCursorPosition.Y++;
256 if(pConsoleBuffer->coordCursorPosition.Y >= pConsoleBuffer->coordWindowSize.Y) {
257 dprintf(("scrollup"));
258 VioScrollUp(0, 0, pConsoleBuffer->coordWindowSize.Y-1, pConsoleBuffer->coordWindowSize.X-1,
259 1, &filler[0], 0);
260 pConsoleBuffer->coordCursorPosition.Y = pConsoleBuffer->coordWindowSize.Y-1;
261 }
262 VioWrtCharStr(&pszBuffer[ulCounter], numchar, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
263 pConsoleBuffer->coordCursorPosition.X += numchar;
264 VioSetCurPos(pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
265 }
266 else {
267 VioWrtCharStr(&pszBuffer[ulCounter], numchar, pConsoleBuffer->coordCursorPosition.Y, pConsoleBuffer->coordCursorPosition.X, 0);
268 pConsoleBuffer->coordCursorPosition.X += numchar;
269 }
270 ulCounter += numchar;
271 }
272 }
273
274 *lpNumberOfBytesWritten = ulCounter;
275
276 return TRUE;
277}
278
279
Note: See TracBrowser for help on using the repository browser.