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

Last change on this file since 6496 was 5308, checked in by sandervl, 24 years ago

removed builtin.h include + initterm update

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