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

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

handle manager class for standard handles added

File size: 10.2 KB
Line 
1/* $Id: conout.cpp,v 1.9 2001-01-23 18:31:25 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 <win32api.h>
66#include <misc.h>
67
68#include "conwin.h" // Windows Header for console only
69#include "HandleManager.h"
70#include "HMDevice.h"
71#include "ConOut.H"
72
73#include "console2.h"
74#include "conprop.h"
75#include "unicode.h"
76
77#define DBG_LOCALLOG DBG_conout
78#include "dbglocal.h"
79
80/*****************************************************************************
81 * Name : DWORD HMDeviceConsoleOutClass::CreateFile
82 * Purpose : this is called from the handle manager if a CreateFile() is
83 * performed on a handle
84 * Parameters: LPCSTR lpFileName name of the file / device
85 * PHMHANDLEDATA pHMHandleData data of the NEW handle
86 * PVOID lpSecurityAttributes ignored
87 * PHMHANDLEDATA pHMHandleDataTemplate data of the template handle
88 * Variables :
89 * Result :
90 * Remark :
91 * Status : NO_ERROR - API succeeded
92 * other - what is to be set in SetLastError
93 *
94 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
95 *****************************************************************************/
96
97DWORD HMDeviceConsoleOutClass::CreateFile (LPCSTR lpFileName,
98 PHMHANDLEDATA pHMHandleData,
99 PVOID lpSecurityAttributes,
100 PHMHANDLEDATA pHMHandleDataTemplate)
101{
102 APIRET rc;
103 BOOL fResult;
104 HANDLE hConsole;
105
106#ifdef DEBUG_LOCAL2
107 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass %s(%s,%08x,%08x,%08x)\n",
108 lpHMDeviceName,
109 lpFileName,
110 pHMHandleData->hHMHandle,
111 lpSecurityAttributes,
112 pHMHandleDataTemplate);
113#endif
114
115 pHMHandleData->dwType = FILE_TYPE_CHAR; /* we're a character device */
116
117
118 /* if no default buffer is available, then do default setup */
119 if (pConsoleGlobals->hConsoleBuffer == INVALID_HANDLE_VALUE)
120 {
121 /* now we need a default screen buffer with the default size */
122 hConsole = CreateConsoleScreenBuffer(0,
123 0,
124 NULL,
125 CONSOLE_TEXTMODE_BUFFER,
126 NULL);
127 if (hConsole == INVALID_HANDLE_VALUE)
128 {
129#ifdef DEBUG_LOCAL
130 WriteLog("KERNEL32/CONSOLE:OS2CreateConsoleScreenBuffer = %u.\n",
131 GetLastError());
132#endif
133 return INVALID_HANDLE_VALUE; /* abort further processing immediately */
134 }
135
136 fResult = SetConsoleTextAttribute(hConsole,
137 pConsoleGlobals->Options.ucDefaultAttribute);
138#ifdef DEBUG_LOCAL
139 if (fResult == FALSE) /* check errors */
140 WriteLog("KERNEL32/CONSOLE:OS2SetConsoleTextAttribute=%u.\n",
141 GetLastError());
142#endif
143
144 fResult = SetConsoleScreenBufferSize(hConsole,
145 pConsoleGlobals->Options.coordDefaultSize);
146 if (fResult == FALSE)
147 {
148#ifdef DEBUG_LOCAL
149 WriteLog("KERNEL32/CONSOLE:OS2SetConsoleScreenBufferSize=%u.\n",
150 GetLastError());
151#endif
152 HMCloseHandle(hConsole); /* free handle again */
153 return (INVALID_HANDLE_VALUE); /* abort further processing */
154 }
155
156 fResult = SetConsoleActiveScreenBuffer(hConsole);
157 if (fResult == FALSE)
158 {
159#ifdef DEBUG_LOCAL
160 WriteLog("KERNEL32/CONSOLE:OS2SetConsoleActiveScreenBuffer=%u.\n",
161 GetLastError());
162#endif
163 HMCloseHandle(hConsole); /* free handle again */
164 return (INVALID_HANDLE_VALUE); /* abort further processing */
165 }
166 else
167 {
168 pConsoleGlobals->hConsoleBufferDefault = hConsole; /* save handle */
169 pConsoleGlobals->hConsoleBuffer = hConsole;
170 }
171 }
172
173 return(NO_ERROR);
174}
175
176
177/*****************************************************************************
178 * Name :
179 * Purpose :
180 * Parameters:
181 * Variables :
182 * Result :
183 * Remark :
184 * Status :
185 *
186 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
187 *****************************************************************************/
188
189BOOL HMDeviceConsoleOutClass::ReadFile(PHMHANDLEDATA pHMHandleData,
190 LPCVOID lpBuffer,
191 DWORD nNumberOfBytesToRead,
192 LPDWORD lpNumberOfBytesRead,
193 LPOVERLAPPED lpOverlapped)
194{
195
196#ifdef DEBUG_LOCAL
197 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)\n",
198 lpHMDeviceName,
199 pHMHandleData->hHMHandle,
200 lpBuffer,
201 nNumberOfBytesToRead,
202 lpNumberOfBytesRead,
203 lpOverlapped);
204#endif
205
206 SetLastError(ERROR_ACCESS_DENIED_W);
207 return FALSE;
208}
209
210
211/*****************************************************************************
212 * Name :
213 * Purpose :
214 * Parameters:
215 * Variables :
216 * Result :
217 * Remark :
218 * Status :
219 *
220 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
221 *****************************************************************************/
222
223BOOL HMDeviceConsoleOutClass::WriteFile(PHMHANDLEDATA pHMHandleData,
224 LPCVOID lpBuffer,
225 DWORD nNumberOfBytesToWrite,
226 LPDWORD lpNumberOfBytesWritten,
227 LPOVERLAPPED lpOverlapped)
228{
229 BOOL dwResult; /* result from subsequent WriteFile */
230
231#ifdef DEBUG_LOCAL2
232 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:WriteFile %s(%08x,%s,%08x,%08x,%08x)\n",
233 lpHMDeviceName,
234 pHMHandleData->hHMHandle,
235 lpBuffer,
236 nNumberOfBytesToWrite,
237 lpNumberOfBytesWritten,
238 lpOverlapped);
239#endif
240
241 /* just prevent an endless loop, although this condition might never */
242 /* be true ! */
243 if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
244 {
245 dwResult = HMWriteFile(pConsoleGlobals->hConsoleBuffer,
246 lpBuffer,
247 nNumberOfBytesToWrite,
248 lpNumberOfBytesWritten,
249 lpOverlapped);
250
251 return (dwResult); /* return result code */
252 }
253 else {
254 return (FALSE); /* raise error condition */
255 }
256}
257
258
259/*****************************************************************************
260 * Name : DWORD HMDeviceConsoleOutClass::_DeviceRequest
261 * Purpose : we just forward those device requests to the console buffer
262 * currently associated with the console itself.
263 * Parameters:
264 * Variables :
265 * Result :
266 * Remark :
267 * Status : UNTESTED
268 *
269 * Author : Patrick Haller [Wed, 1998/03/35 20:44]
270 *****************************************************************************/
271
272DWORD HMDeviceConsoleOutClass::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
273 ULONG ulRequestCode,
274 ULONG arg1,
275 ULONG arg2,
276 ULONG arg3,
277 ULONG arg4)
278{
279#ifdef DEBUG_LOCAL2
280 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:_DeviceRequest %s(%08x,%08x,%08x,%08x,%08x,%08x)\n",
281 lpHMDeviceName,
282 pHMHandleData->hHMHandle,
283 ulRequestCode,
284 arg1,
285 arg2,
286 arg3,
287 arg4);
288#endif
289 /* just prevent an endless loop, although this condition might never */
290 /* be true ! */
291 if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
292 return (HMDeviceRequest(pConsoleGlobals->hConsoleBuffer,
293 ulRequestCode,
294 arg1,
295 arg2,
296 arg3,
297 arg4));
298 else
299 return (ERROR_SYS_INTERNAL); /* raise error condition */
300}
301
302
303DWORD HMDeviceConsoleOutClass::GetFileType (PHMHANDLEDATA pHMHandleData)
304{
305 return FILE_TYPE_CHAR;
306}
Note: See TracBrowser for help on using the repository browser.