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