source: trunk/src/kernel32/conout.cpp@ 1484

Last change on this file since 1484 was 1484, checked in by phaller, 26 years ago

Fix: console (unicode) updates

File size: 11.0 KB
Line 
1/* $Id: conout.cpp,v 1.4 1999-10-27 18:36:35 phaller 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
82extern "C"
83{
84 void _System _O32_SetLastError(DWORD dwError);
85 int _System _O32_GetLastError(void);
86}
87
88inline void SetLastError(DWORD a)
89{
90 USHORT sel = GetFS();
91
92 _O32_SetLastError(a);
93 SetFS(sel);
94}
95
96inline 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
124DWORD 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
216DWORD 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 return(ERROR_ACCESS_DENIED);
234}
235
236
237/*****************************************************************************
238 * Name :
239 * Purpose :
240 * Parameters:
241 * Variables :
242 * Result :
243 * Remark :
244 * Status :
245 *
246 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
247 *****************************************************************************/
248
249DWORD HMDeviceConsoleOutClass::WriteFile(PHMHANDLEDATA pHMHandleData,
250 LPCVOID lpBuffer,
251 DWORD nNumberOfBytesToWrite,
252 LPDWORD lpNumberOfBytesWritten,
253 LPOVERLAPPED lpOverlapped)
254{
255 DWORD dwResult; /* result from subsequent WriteFile */
256
257#ifdef DEBUG_LOCAL2
258 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:WriteFile %s(%08x,%08x,%08x,%08x,%08x)\n",
259 lpHMDeviceName,
260 pHMHandleData->hHMHandle,
261 lpBuffer,
262 nNumberOfBytesToWrite,
263 lpNumberOfBytesWritten,
264 lpOverlapped);
265#endif
266
267 /* just prevent an endless loop, although this condition might never */
268 /* be true ! */
269 if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
270 {
271#if 0
272 HMDeviceRequest(pConsoleGlobals->hConsoleBuffer, /* hide the cursor */
273 DRQ_INTERNAL_CONSOLECURSORSHOW,
274 CONSOLECURSOR_HIDE,
275 0,
276 0,
277 0);
278#endif
279
280 dwResult = HMWriteFile(pConsoleGlobals->hConsoleBuffer,
281 lpBuffer,
282 nNumberOfBytesToWrite,
283 lpNumberOfBytesWritten,
284 lpOverlapped);
285
286#if 0
287 HMDeviceRequest(pConsoleGlobals->hConsoleBuffer, /* show the cursor */
288 DRQ_INTERNAL_CONSOLECURSORSHOW,
289 CONSOLECURSOR_SHOW,
290 0,
291 0,
292 0);
293#endif
294
295 return (dwResult); /* return result code */
296 }
297 else
298 return (ERROR_SYS_INTERNAL); /* raise error condition */
299}
300
301
302/*****************************************************************************
303 * Name : DWORD HMDeviceConsoleOutClass::_DeviceRequest
304 * Purpose : we just forward those device requests to the console buffer
305 * currently associated with the console itself.
306 * Parameters:
307 * Variables :
308 * Result :
309 * Remark :
310 * Status : UNTESTED
311 *
312 * Author : Patrick Haller [Wed, 1998/03/35 20:44]
313 *****************************************************************************/
314
315DWORD HMDeviceConsoleOutClass::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
316 ULONG ulRequestCode,
317 ULONG arg1,
318 ULONG arg2,
319 ULONG arg3,
320 ULONG arg4)
321{
322#ifdef DEBUG_LOCAL2
323 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:_DeviceRequest %s(%08x,%08x,%08x,%08x,%08x,%08x)\n",
324 lpHMDeviceName,
325 pHMHandleData->hHMHandle,
326 ulRequestCode,
327 arg1,
328 arg2,
329 arg3,
330 arg4);
331#endif
332 /* just prevent an endless loop, although this condition might never */
333 /* be true ! */
334 if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
335 return (HMDeviceRequest(pConsoleGlobals->hConsoleBuffer,
336 ulRequestCode,
337 arg1,
338 arg2,
339 arg3,
340 arg4));
341 else
342 return (ERROR_SYS_INTERNAL); /* raise error condition */
343}
344
Note: See TracBrowser for help on using the repository browser.