source: trunk/src/kernel32/conout.cpp

Last change on this file was 10210, checked in by sandervl, 22 years ago

DF: HMDeviceConsoleOutClass::CreateFile; use current window size instead of default

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