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

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

moved registry apis into kernel32 + cleanup

File size: 10.6 KB
Line 
1/* $Id: conout.cpp,v 1.7 2000-03-03 11:15:57 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#if 0
246 HMDeviceRequest(pConsoleGlobals->hConsoleBuffer, /* hide the cursor */
247 DRQ_INTERNAL_CONSOLECURSORSHOW,
248 CONSOLECURSOR_HIDE,
249 0,
250 0,
251 0);
252#endif
253
254 dwResult = HMWriteFile(pConsoleGlobals->hConsoleBuffer,
255 lpBuffer,
256 nNumberOfBytesToWrite,
257 lpNumberOfBytesWritten,
258 lpOverlapped);
259
260#if 0
261 HMDeviceRequest(pConsoleGlobals->hConsoleBuffer, /* show the cursor */
262 DRQ_INTERNAL_CONSOLECURSORSHOW,
263 CONSOLECURSOR_SHOW,
264 0,
265 0,
266 0);
267#endif
268
269 return (dwResult); /* return result code */
270 }
271 else
272 return (FALSE); /* raise error condition */
273}
274
275
276/*****************************************************************************
277 * Name : DWORD HMDeviceConsoleOutClass::_DeviceRequest
278 * Purpose : we just forward those device requests to the console buffer
279 * currently associated with the console itself.
280 * Parameters:
281 * Variables :
282 * Result :
283 * Remark :
284 * Status : UNTESTED
285 *
286 * Author : Patrick Haller [Wed, 1998/03/35 20:44]
287 *****************************************************************************/
288
289DWORD HMDeviceConsoleOutClass::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
290 ULONG ulRequestCode,
291 ULONG arg1,
292 ULONG arg2,
293 ULONG arg3,
294 ULONG arg4)
295{
296#ifdef DEBUG_LOCAL2
297 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleOutClass:_DeviceRequest %s(%08x,%08x,%08x,%08x,%08x,%08x)\n",
298 lpHMDeviceName,
299 pHMHandleData->hHMHandle,
300 ulRequestCode,
301 arg1,
302 arg2,
303 arg3,
304 arg4);
305#endif
306 /* just prevent an endless loop, although this condition might never */
307 /* be true ! */
308 if (pHMHandleData->hHMHandle != pConsoleGlobals->hConsoleBuffer)
309 return (HMDeviceRequest(pConsoleGlobals->hConsoleBuffer,
310 ulRequestCode,
311 arg1,
312 arg2,
313 arg3,
314 arg4));
315 else
316 return (ERROR_SYS_INTERNAL); /* raise error condition */
317}
318
Note: See TracBrowser for help on using the repository browser.