1 | /* $Id: conin.cpp,v 1.4 1999-07-12 17:20:03 phaller 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 | #endif
|
---|
13 |
|
---|
14 |
|
---|
15 | /*****************************************************************************
|
---|
16 | * Remark *
|
---|
17 | *****************************************************************************
|
---|
18 | */
|
---|
19 |
|
---|
20 |
|
---|
21 | /*****************************************************************************
|
---|
22 | * Includes *
|
---|
23 | *****************************************************************************/
|
---|
24 |
|
---|
25 | #define INCL_WIN
|
---|
26 | #define INCL_DOSMEMMGR
|
---|
27 | #define INCL_DOSSEMAPHORES
|
---|
28 | #define INCL_DOSERRORS
|
---|
29 | #define INCL_DOSPROCESS
|
---|
30 | #define INCL_DOSMODULEMGR
|
---|
31 | #define INCL_VIO
|
---|
32 | #define INCL_AVIO
|
---|
33 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
34 |
|
---|
35 | #include <misc.h>
|
---|
36 | #include <string.h>
|
---|
37 |
|
---|
38 | #include "conwin.h" // Windows Header for console only
|
---|
39 | #include "HandleManager.h"
|
---|
40 | #include "HMDevice.h"
|
---|
41 | #include "Conin.H"
|
---|
42 | #include "Console2.h"
|
---|
43 |
|
---|
44 |
|
---|
45 | /***********************************
|
---|
46 | * Open32 support for SetLastError *
|
---|
47 | ***********************************/
|
---|
48 | #include <os2sel.h>
|
---|
49 |
|
---|
50 | extern "C"
|
---|
51 | {
|
---|
52 | void _System _O32_SetLastError(DWORD dwError);
|
---|
53 | }
|
---|
54 |
|
---|
55 | inline void SetLastError(DWORD a)
|
---|
56 | {
|
---|
57 | USHORT sel = GetFS();
|
---|
58 |
|
---|
59 | _O32_SetLastError(a);
|
---|
60 | SetFS(sel);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /*****************************************************************************
|
---|
65 | * Name : DWORD HMDeviceConsoleInClass::CreateFile
|
---|
66 | * Purpose : this is called from the handle manager if a CreateFile() is
|
---|
67 | * performed on a handle
|
---|
68 | * Parameters: LPCSTR lpFileName name of the file / device
|
---|
69 | * PHMHANDLEDATA pHMHandleData data of the NEW handle
|
---|
70 | * PVOID lpSecurityAttributes ignored
|
---|
71 | * PHMHANDLEDATA pHMHandleDataTemplate data of the template handle
|
---|
72 | * Variables :
|
---|
73 | * Result :
|
---|
74 | * Remark : @@@PH CONIN$ handles should be exclusive
|
---|
75 | * reject other requests to this device
|
---|
76 | * Status : NO_ERROR - API succeeded
|
---|
77 | * other - what is to be set in SetLastError
|
---|
78 | *
|
---|
79 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
80 | *****************************************************************************/
|
---|
81 |
|
---|
82 | DWORD HMDeviceConsoleInClass::CreateFile (LPCSTR lpFileName,
|
---|
83 | PHMHANDLEDATA pHMHandleData,
|
---|
84 | PVOID lpSecurityAttributes,
|
---|
85 | PHMHANDLEDATA pHMHandleDataTemplate)
|
---|
86 | {
|
---|
87 | #ifdef DEBUG_LOCAL
|
---|
88 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleInClass::CreateFile %s(%s,%08x,%08x,%08x)\n",
|
---|
89 | lpHMDeviceName,
|
---|
90 | lpFileName,
|
---|
91 | pHMHandleData->hHMHandle,
|
---|
92 | lpSecurityAttributes,
|
---|
93 | pHMHandleDataTemplate);
|
---|
94 | #endif
|
---|
95 |
|
---|
96 | pHMHandleData->dwType = FILE_TYPE_CHAR; /* we're a character device */
|
---|
97 |
|
---|
98 | return(NO_ERROR);
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | /*****************************************************************************
|
---|
103 | * Name :
|
---|
104 | * Purpose :
|
---|
105 | * Parameters:
|
---|
106 | * Variables :
|
---|
107 | * Result :
|
---|
108 | * Remark :
|
---|
109 | * Status :
|
---|
110 | *
|
---|
111 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
112 | *****************************************************************************/
|
---|
113 |
|
---|
114 | DWORD HMDeviceConsoleInClass::ReadFile(PHMHANDLEDATA pHMHandleData,
|
---|
115 | LPCVOID lpBuffer,
|
---|
116 | DWORD nNumberOfBytesToRead,
|
---|
117 | LPDWORD lpNumberOfBytesRead,
|
---|
118 | LPOVERLAPPED lpOverlapped)
|
---|
119 | {
|
---|
120 | ULONG ulCounter; /* character counter for the queue loop */
|
---|
121 | PSZ pszTarget; /* pointer to target buffer */
|
---|
122 | APIRET rc; /* API returncode */
|
---|
123 | INPUT_RECORD InputRecord; /* buffer for the event to be read */
|
---|
124 | ULONG ulPostCounter; /* semaphore post counter */
|
---|
125 |
|
---|
126 | #ifdef DEBUG_LOCAL
|
---|
127 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleInClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)\n",
|
---|
128 | lpHMDeviceName,
|
---|
129 | pHMHandleData->hHMHandle,
|
---|
130 | lpBuffer,
|
---|
131 | nNumberOfBytesToRead,
|
---|
132 | lpNumberOfBytesRead,
|
---|
133 | lpOverlapped);
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | ulCounter = 0; /* read ascii chars from queue */
|
---|
137 | pszTarget = (PSZ)lpBuffer;
|
---|
138 |
|
---|
139 | /* @@@PH: ConsoleMode: ENABLE_LINE_INPUT - blocks until CR is read */
|
---|
140 |
|
---|
141 | /* block if no key events are in the queue */
|
---|
142 | for (;ulCounter==0;) /* until we got some characters */
|
---|
143 | {
|
---|
144 | if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
|
---|
145 | {
|
---|
146 | rc = DosWaitEventSem(pConsoleInput->hevInputQueue, /* wait for input */
|
---|
147 | SEM_INDEFINITE_WAIT);
|
---|
148 | DosResetEventSem(pConsoleInput->hevInputQueue, /* reset semaphore */
|
---|
149 | &ulPostCounter); /* post counter - ignored */
|
---|
150 | }
|
---|
151 |
|
---|
152 | do
|
---|
153 | {
|
---|
154 | rc = iConsoleInputEventPop(&InputRecord); /* get event from queue */
|
---|
155 | if (rc == NO_ERROR) /* if we've got a valid event in the queue */
|
---|
156 | {
|
---|
157 | if (InputRecord.EventType == KEY_EVENT) /* check event type */
|
---|
158 | {
|
---|
159 | *pszTarget = InputRecord.Event.KeyEvent.uChar.AsciiChar;
|
---|
160 | pszTarget++;
|
---|
161 | ulCounter++;
|
---|
162 |
|
---|
163 | /* local echo enabled ? */
|
---|
164 | if (pConsoleInput->dwConsoleMode & ENABLE_ECHO_INPUT)
|
---|
165 | HMWriteFile(pConsoleGlobals->hConsoleBuffer,
|
---|
166 | &InputRecord.Event.KeyEvent.uChar.AsciiChar,
|
---|
167 | 1,
|
---|
168 | &ulPostCounter, /* dummy result */
|
---|
169 | NULL);
|
---|
170 |
|
---|
171 | if (ulCounter >= nNumberOfBytesToRead) /* at buffer's end ? */
|
---|
172 | goto __readfile_exit;
|
---|
173 | }
|
---|
174 | /* Note: other events are discarded */
|
---|
175 | }
|
---|
176 | }
|
---|
177 | while (rc == NO_ERROR);
|
---|
178 | }
|
---|
179 |
|
---|
180 | __readfile_exit:
|
---|
181 |
|
---|
182 | *lpNumberOfBytesRead = ulCounter; /* write result */
|
---|
183 |
|
---|
184 | return(TRUE); /* OK */
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | /*****************************************************************************
|
---|
189 | * Name :
|
---|
190 | * Purpose :
|
---|
191 | * Parameters:
|
---|
192 | * Variables :
|
---|
193 | * Result :
|
---|
194 | * Remark :
|
---|
195 | * Status :
|
---|
196 | *
|
---|
197 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
198 | *****************************************************************************/
|
---|
199 |
|
---|
200 | DWORD HMDeviceConsoleInClass::WriteFile(PHMHANDLEDATA pHMHandleData,
|
---|
201 | LPCVOID lpBuffer,
|
---|
202 | DWORD nNumberOfBytesToWrite,
|
---|
203 | LPDWORD lpNumberOfBytesWritten,
|
---|
204 | LPOVERLAPPED lpOverlapped)
|
---|
205 | {
|
---|
206 |
|
---|
207 | #ifdef DEBUG_LOCAL
|
---|
208 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleInClass:WriteFile %s(%08x,%08x,%08x,%08x,%08x)\n",
|
---|
209 | lpHMDeviceName,
|
---|
210 | pHMHandleData->hHMHandle,
|
---|
211 | lpBuffer,
|
---|
212 | nNumberOfBytesToWrite,
|
---|
213 | lpNumberOfBytesWritten,
|
---|
214 | lpOverlapped);
|
---|
215 | #endif
|
---|
216 |
|
---|
217 | return(ERROR_ACCESS_DENIED);
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | /*****************************************************************************
|
---|
222 | * Name :
|
---|
223 | * Purpose :
|
---|
224 | * Parameters:
|
---|
225 | * Variables :
|
---|
226 | * Result :
|
---|
227 | * Remark :
|
---|
228 | * Status :
|
---|
229 | *
|
---|
230 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
231 | *****************************************************************************/
|
---|
232 |
|
---|
233 | DWORD HMDeviceConsoleInClass::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
|
---|
234 | ULONG ulRequestCode,
|
---|
235 | ULONG arg1,
|
---|
236 | ULONG arg2,
|
---|
237 | ULONG arg3,
|
---|
238 | ULONG arg4)
|
---|
239 | {
|
---|
240 | switch (ulRequestCode)
|
---|
241 | {
|
---|
242 | case DRQ_FLUSHCONSOLEINPUTBUFFER:
|
---|
243 | return (HMDeviceConsoleInClass::
|
---|
244 | FlushConsoleInputBuffer(pHMHandleData));
|
---|
245 |
|
---|
246 | case DRQ_GETCONSOLEMODE:
|
---|
247 | return (HMDeviceConsoleInClass
|
---|
248 | ::GetConsoleMode(pHMHandleData,
|
---|
249 | (LPDWORD)arg1));
|
---|
250 |
|
---|
251 | case DRQ_GETNUMBEROFCONSOLEINPUTEVENTS:
|
---|
252 | return (HMDeviceConsoleInClass::
|
---|
253 | GetNumberOfConsoleInputEvents(pHMHandleData,
|
---|
254 | (LPDWORD)arg1));
|
---|
255 |
|
---|
256 | case DRQ_PEEKCONSOLEINPUTA:
|
---|
257 | return (HMDeviceConsoleInClass::
|
---|
258 | PeekConsoleInputA(pHMHandleData,
|
---|
259 | (PINPUT_RECORD)arg1,
|
---|
260 | (DWORD) arg2,
|
---|
261 | (LPDWORD) arg3));
|
---|
262 |
|
---|
263 | case DRQ_PEEKCONSOLEINPUTW:
|
---|
264 | return (HMDeviceConsoleInClass::
|
---|
265 | PeekConsoleInputW(pHMHandleData,
|
---|
266 | (PINPUT_RECORD)arg1,
|
---|
267 | (DWORD) arg2,
|
---|
268 | (LPDWORD) arg3));
|
---|
269 |
|
---|
270 |
|
---|
271 | case DRQ_READCONSOLEA:
|
---|
272 | return (HMDeviceConsoleInClass::
|
---|
273 | ReadConsoleA(pHMHandleData,
|
---|
274 | (CONST VOID*) arg1,
|
---|
275 | (DWORD) arg2,
|
---|
276 | (LPDWORD) arg3,
|
---|
277 | (LPVOID) arg4));
|
---|
278 |
|
---|
279 | case DRQ_READCONSOLEW:
|
---|
280 | return (HMDeviceConsoleInClass::
|
---|
281 | ReadConsoleW(pHMHandleData,
|
---|
282 | (CONST VOID*) arg1,
|
---|
283 | (DWORD) arg2,
|
---|
284 | (LPDWORD) arg3,
|
---|
285 | (LPVOID) arg4));
|
---|
286 |
|
---|
287 | case DRQ_READCONSOLEINPUTA:
|
---|
288 | return (HMDeviceConsoleInClass::
|
---|
289 | ReadConsoleInputA(pHMHandleData,
|
---|
290 | (PINPUT_RECORD)arg1,
|
---|
291 | (DWORD)arg2,
|
---|
292 | (LPDWORD)arg3));
|
---|
293 |
|
---|
294 | case DRQ_READCONSOLEINPUTW:
|
---|
295 | return (HMDeviceConsoleInClass::
|
---|
296 | ReadConsoleInputW(pHMHandleData,
|
---|
297 | (PINPUT_RECORD)arg1,
|
---|
298 | (DWORD)arg2,
|
---|
299 | (LPDWORD)arg3));
|
---|
300 |
|
---|
301 | case DRQ_SETCONSOLEMODE:
|
---|
302 | return (HMDeviceConsoleInClass
|
---|
303 | ::SetConsoleMode(pHMHandleData,
|
---|
304 | (DWORD)arg1));
|
---|
305 |
|
---|
306 | case DRQ_WRITECONSOLEINPUTA:
|
---|
307 | return (HMDeviceConsoleInClass::
|
---|
308 | WriteConsoleInputA(pHMHandleData,
|
---|
309 | (PINPUT_RECORD)arg1,
|
---|
310 | (DWORD)arg2,
|
---|
311 | (LPDWORD)arg3));
|
---|
312 |
|
---|
313 | case DRQ_WRITECONSOLEINPUTW:
|
---|
314 | return (HMDeviceConsoleInClass::
|
---|
315 | WriteConsoleInputW(pHMHandleData,
|
---|
316 | (PINPUT_RECORD)arg1,
|
---|
317 | (DWORD)arg2,
|
---|
318 | (LPDWORD)arg3));
|
---|
319 |
|
---|
320 | }
|
---|
321 |
|
---|
322 | #ifdef DEBUG_LOCAL
|
---|
323 | WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleInClass:_DeviceRequest %s(%08x,%08x,%08x,%08x,%08x,%08x) unknown request\n",
|
---|
324 | lpHMDeviceName,
|
---|
325 | pHMHandleData->hHMHandle,
|
---|
326 | ulRequestCode,
|
---|
327 | arg1,
|
---|
328 | arg2,
|
---|
329 | arg3,
|
---|
330 | arg4);
|
---|
331 | #endif
|
---|
332 |
|
---|
333 | SetLastError(ERROR_INVALID_FUNCTION); /* request not implemented */
|
---|
334 | return(FALSE); /* we assume this indicates API call failed */
|
---|
335 | }
|
---|
336 |
|
---|
337 |
|
---|
338 | /*****************************************************************************
|
---|
339 | * Name : BOOL HMDeviceConsoleInClass::FlushConsoleInputBuffer
|
---|
340 | * Purpose : flushes all events from the input queue
|
---|
341 | * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
|
---|
342 | * Variables :
|
---|
343 | * Result :
|
---|
344 | * Remark :
|
---|
345 | * Status : UNTESTED
|
---|
346 | *
|
---|
347 | * Author : Patrick Haller [Wed, 1998/02/16 11:46]
|
---|
348 | *****************************************************************************/
|
---|
349 |
|
---|
350 | BOOL HMDeviceConsoleInClass::FlushConsoleInputBuffer(PHMHANDLEDATA pHMHandleData)
|
---|
351 | {
|
---|
352 | ULONG ulCounter; /* loop counter */
|
---|
353 |
|
---|
354 | #ifdef DEBUG_LOCAL2
|
---|
355 | WriteLog("KERNEL32/CONSOLE: CONIN$::FlushConsoleInputBuffer(%08x).\n",
|
---|
356 | pHMHandleData);
|
---|
357 | #endif
|
---|
358 |
|
---|
359 | pConsoleInput->ulIndexFree = 0;
|
---|
360 | pConsoleInput->ulIndexEvent = 0;
|
---|
361 | pConsoleInput->ulEvents = 0;
|
---|
362 |
|
---|
363 | for (ulCounter = 0;
|
---|
364 | ulCounter < CONSOLE_INPUTQUEUESIZE;
|
---|
365 | ulCounter++)
|
---|
366 | pConsoleInput->arrInputRecord[ulCounter].EventType = 0x0000; /* free event */
|
---|
367 |
|
---|
368 | return (TRUE);
|
---|
369 | }
|
---|
370 |
|
---|
371 |
|
---|
372 | /*****************************************************************************
|
---|
373 | * Name : DWORD HMDeviceConsoleInClass::GetConsoleMode
|
---|
374 | * Purpose : queries the current console mode
|
---|
375 | * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
|
---|
376 | * LPDWORD lpMode
|
---|
377 | * Variables :
|
---|
378 | * Result :
|
---|
379 |
|
---|
380 | * Remark :
|
---|
381 | * Status : UNTESTED
|
---|
382 | *
|
---|
383 | * Author : Patrick Haller [Wed, 1998/02/16 11:46]
|
---|
384 | *****************************************************************************/
|
---|
385 |
|
---|
386 | DWORD HMDeviceConsoleInClass::GetConsoleMode(PHMHANDLEDATA pHMHandleData,
|
---|
387 | LPDWORD lpMode)
|
---|
388 | {
|
---|
389 | #ifdef DEBUG_LOCAL2
|
---|
390 | WriteLog("KERNEL32/CONSOLE: CONIN$::GetConsoleMode(%08x,%08x).\n",
|
---|
391 | pHMHandleData,
|
---|
392 | lpMode);
|
---|
393 | #endif
|
---|
394 |
|
---|
395 | *lpMode = pConsoleInput->dwConsoleMode; /* return current console mode */
|
---|
396 |
|
---|
397 | return (TRUE);
|
---|
398 | }
|
---|
399 |
|
---|
400 |
|
---|
401 | /*****************************************************************************
|
---|
402 | * Name : DWORD HMDeviceConsoleInClass::GetNumberOfConsoleInputEvents
|
---|
403 | * Purpose : queries the current number of events in the input queue
|
---|
404 | * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
|
---|
405 | * LPDWORD lpNumberOfEvents - return number of events
|
---|
406 | * Variables :
|
---|
407 | * Result :
|
---|
408 | * Remark :
|
---|
409 | * Status : UNTESTED
|
---|
410 | *
|
---|
411 | * Author : Patrick Haller [Wed, 1998/02/16 11:46]
|
---|
412 | *****************************************************************************/
|
---|
413 |
|
---|
414 | BOOL HMDeviceConsoleInClass::GetNumberOfConsoleInputEvents(PHMHANDLEDATA pHMHandleData,
|
---|
415 | LPDWORD lpNumberOfEvents)
|
---|
416 | {
|
---|
417 | #ifdef DEBUG_LOCAL2
|
---|
418 | WriteLog("KERNEL32/CONSOLE: CONIN$::GetNumberOfConsoleInputEvents(%08x,%08x).\n",
|
---|
419 | pHMHandleData,
|
---|
420 | lpNumberOfEvents);
|
---|
421 | #endif
|
---|
422 |
|
---|
423 | *lpNumberOfEvents = pConsoleInput->ulEvents; /* return number of events */
|
---|
424 |
|
---|
425 | return (TRUE);
|
---|
426 | }
|
---|
427 |
|
---|
428 |
|
---|
429 | /*****************************************************************************
|
---|
430 | * Name : DWORD HMDeviceConsoleInClass::PeekConsoleInputA
|
---|
431 | * Purpose : peeks events placed in the console input queue
|
---|
432 | * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
|
---|
433 | * PINPUT_RECORD pirBuffer - target buffer for events
|
---|
434 | * DWORD cInRecords - number of input records
|
---|
435 | * LPDWORD lpcRead - returns number of events stored
|
---|
436 | * Variables :
|
---|
437 | * Result : TRUE if successful, FALSE otherwise
|
---|
438 | * Remark : if queue is completely filled and no event is free,
|
---|
439 | * loop will scan over queue multiple times, until target
|
---|
440 | * buffer is filled. It does not check ulCounter to stop
|
---|
441 | * when one scan of the queue is complete.
|
---|
442 | * Status : UNTESTED
|
---|
443 | *
|
---|
444 | * Author : Patrick Haller [Tue, 1998/02/10 01:55]
|
---|
445 | *****************************************************************************/
|
---|
446 |
|
---|
447 | DWORD HMDeviceConsoleInClass::PeekConsoleInputA(PHMHANDLEDATA pHMHandleData,
|
---|
448 | PINPUT_RECORD pirBuffer,
|
---|
449 | DWORD cInRecords,
|
---|
450 | LPDWORD lpcRead)
|
---|
451 | {
|
---|
452 | ULONG ulCounter; /* loop counter */
|
---|
453 | ULONG ulCurrentEvent; /* index of current event in the queue */
|
---|
454 | PINPUT_RECORD pirEvent; /* pointer to current queue element */
|
---|
455 |
|
---|
456 | #ifdef DEBUG_LOCAL2
|
---|
457 | WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::PeekConsoleInputA(%08x,%08x,%08x,%08x).\n",
|
---|
458 | pHMHandleData,
|
---|
459 | pirBuffer,
|
---|
460 | cInRecords,
|
---|
461 | lpcRead);
|
---|
462 | #endif
|
---|
463 |
|
---|
464 | if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
|
---|
465 | {
|
---|
466 | *lpcRead = 0; /* no events read from queue */
|
---|
467 | return (TRUE); /* OK, we're done */
|
---|
468 | }
|
---|
469 |
|
---|
470 |
|
---|
471 | for (ulCounter = 0,
|
---|
472 | ulCurrentEvent = pConsoleInput->ulIndexEvent,
|
---|
473 | pirEvent = &pConsoleInput->arrInputRecord[pConsoleInput->ulIndexEvent];
|
---|
474 |
|
---|
475 | ulCounter < cInRecords;
|
---|
476 |
|
---|
477 | ulCounter++,
|
---|
478 | ulCurrentEvent++,
|
---|
479 | pirEvent++,
|
---|
480 | pirBuffer++)
|
---|
481 | {
|
---|
482 | if (ulCurrentEvent > CONSOLE_INPUTQUEUESIZE) /* reaching after end of que*/
|
---|
483 | {
|
---|
484 | ulCurrentEvent = 0; /* then start over from beginning of queue */
|
---|
485 | pirEvent = pConsoleInput->arrInputRecord;
|
---|
486 | }
|
---|
487 |
|
---|
488 | if (pirEvent->EventType == 0x0000) /* no more events ? */
|
---|
489 | break; /* leave loop then */
|
---|
490 |
|
---|
491 | memcpy(pirEvent, /* copy event data */
|
---|
492 | pirBuffer,
|
---|
493 | sizeof(INPUT_RECORD));
|
---|
494 | }
|
---|
495 |
|
---|
496 | *lpcRead = ulCounter; /* return number of events read */
|
---|
497 | return (TRUE); /* OK, we're done */
|
---|
498 | }
|
---|
499 |
|
---|
500 |
|
---|
501 | /*****************************************************************************
|
---|
502 | * Name : DWORD HMDeviceConsoleInClass::PeekConsoleInputW
|
---|
503 | * Purpose : peeks events placed in the console input queue
|
---|
504 | * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
|
---|
505 | * PINPUT_RECORD pirBuffer - target buffer for events
|
---|
506 | * DWORD cInRecords - number of input records
|
---|
507 | * LPDWORD lpcRead - returns number of events stored
|
---|
508 | * Variables :
|
---|
509 | * Result : TRUE if successful, FALSE otherwise
|
---|
510 | * Remark : if queue is completely filled and no event is free,
|
---|
511 | * loop will scan over queue multiple times, until target
|
---|
512 | * buffer is filled. It does not check ulCounter to stop
|
---|
513 | * when one scan of the queue is complete.
|
---|
514 | * Status : UNTESTED
|
---|
515 | *
|
---|
516 | * Author : Patrick Haller [Tue, 1998/02/10 01:55]
|
---|
517 | *****************************************************************************/
|
---|
518 |
|
---|
519 | DWORD HMDeviceConsoleInClass::PeekConsoleInputW(PHMHANDLEDATA pHMHandleData,
|
---|
520 | PINPUT_RECORD pirBuffer,
|
---|
521 | DWORD cInRecords,
|
---|
522 | LPDWORD lpcRead)
|
---|
523 | {
|
---|
524 | ULONG ulCounter; /* loop counter */
|
---|
525 | ULONG ulCurrentEvent; /* index of current event in the queue */
|
---|
526 | PINPUT_RECORD pirEvent; /* pointer to current queue element */
|
---|
527 |
|
---|
528 | #ifdef DEBUG_LOCAL2
|
---|
529 | WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::PeekConsoleInputW(%08x,%08x,%08x,%08x).\n",
|
---|
530 | pHMHandleData,
|
---|
531 | pirBuffer,
|
---|
532 | cInRecords,
|
---|
533 | lpcRead);
|
---|
534 | #endif
|
---|
535 |
|
---|
536 | if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
|
---|
537 | {
|
---|
538 | *lpcRead = 0; /* no events read from queue */
|
---|
539 | return (TRUE); /* OK, we're done */
|
---|
540 | }
|
---|
541 |
|
---|
542 |
|
---|
543 | for (ulCounter = 0,
|
---|
544 | ulCurrentEvent = pConsoleInput->ulIndexEvent,
|
---|
545 | pirEvent = &pConsoleInput->arrInputRecord[pConsoleInput->ulIndexEvent];
|
---|
546 |
|
---|
547 | ulCounter < cInRecords;
|
---|
548 |
|
---|
549 | ulCounter++,
|
---|
550 | ulCurrentEvent++,
|
---|
551 | pirEvent++,
|
---|
552 | pirBuffer++)
|
---|
553 | {
|
---|
554 | if (ulCurrentEvent > CONSOLE_INPUTQUEUESIZE) /* reaching after end of que*/
|
---|
555 | {
|
---|
556 | ulCurrentEvent = 0; /* then start over from beginning of queue */
|
---|
557 | pirEvent = pConsoleInput->arrInputRecord;
|
---|
558 | }
|
---|
559 |
|
---|
560 | if (pirEvent->EventType == 0x0000) /* no more events ? */
|
---|
561 | break; /* leave loop then */
|
---|
562 |
|
---|
563 | memcpy(pirEvent, /* copy event data */
|
---|
564 | pirBuffer,
|
---|
565 | sizeof(INPUT_RECORD));
|
---|
566 | }
|
---|
567 |
|
---|
568 | *lpcRead = ulCounter; /* return number of events read */
|
---|
569 | return (TRUE); /* OK, we're done */
|
---|
570 | }
|
---|
571 |
|
---|
572 |
|
---|
573 | /*****************************************************************************
|
---|
574 | * Name : DWORD HMDeviceConsoleInClass::ReadConsoleA
|
---|
575 | * Purpose : read a string from the console
|
---|
576 | * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
|
---|
577 | * LPWORD lpwAttribute
|
---|
578 | * DWORD cWriteCells
|
---|
579 | * COORD dwWriteCoord
|
---|
580 | * LPDWORD lpcWritten
|
---|
581 | * Variables :
|
---|
582 | * Result :
|
---|
583 | * Remark :
|
---|
584 | * Status : UNTESTED
|
---|
585 | *
|
---|
586 | * Author : Patrick Haller [Wed, 1998/02/16 11:46]
|
---|
587 | *****************************************************************************/
|
---|
588 |
|
---|
589 | DWORD HMDeviceConsoleInClass::ReadConsoleA(PHMHANDLEDATA pHMHandleData,
|
---|
590 | CONST VOID* lpvBuffer,
|
---|
591 | DWORD cchToRead,
|
---|
592 | LPDWORD lpcchRead,
|
---|
593 | LPVOID lpvReserved)
|
---|
594 | {
|
---|
595 | PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
|
---|
596 |
|
---|
597 | #ifdef DEBUG_LOCAL2
|
---|
598 | WriteLog("KERNEL32/CONSOLE: CONIN$::ReadConsoleA(%08x,%08x,%u,%08x,%08x).\n",
|
---|
599 | pHMHandleData,
|
---|
600 | lpvBuffer,
|
---|
601 | cchToRead,
|
---|
602 | lpcchRead,
|
---|
603 | lpvReserved);
|
---|
604 | #endif
|
---|
605 |
|
---|
606 | /* simply forward the request to that routine */
|
---|
607 | return (HMDeviceConsoleInClass::ReadFile(pHMHandleData,
|
---|
608 | lpvBuffer,
|
---|
609 | cchToRead,
|
---|
610 | lpcchRead,
|
---|
611 | NULL));
|
---|
612 | }
|
---|
613 |
|
---|
614 |
|
---|
615 | /*****************************************************************************
|
---|
616 | * Name : DWORD HMDeviceConsoleInClass::ReadConsoleW
|
---|
617 | * Purpose : write a string to the console
|
---|
618 | * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
|
---|
619 | * LPWORD lpwAttribute
|
---|
620 | * DWORD cWriteCells
|
---|
621 | * COORD dwWriteCoord
|
---|
622 | * LPDWORD lpcWritten
|
---|
623 | * Variables :
|
---|
624 | * Result :
|
---|
625 | * Remark :
|
---|
626 | * Status : UNTESTED
|
---|
627 | *
|
---|
628 | * Author : Patrick Haller [Wed, 1998/02/16 11:46]
|
---|
629 | *****************************************************************************/
|
---|
630 |
|
---|
631 | DWORD HMDeviceConsoleInClass::ReadConsoleW(PHMHANDLEDATA pHMHandleData,
|
---|
632 | CONST VOID* lpvBuffer,
|
---|
633 | DWORD cchToRead,
|
---|
634 | LPDWORD lpcchRead,
|
---|
635 | LPVOID lpvReserved)
|
---|
636 | {
|
---|
637 | PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
|
---|
638 | DWORD dwResult;
|
---|
639 |
|
---|
640 | #ifdef DEBUG_LOCAL2
|
---|
641 | WriteLog("KERNEL32/CONSOLE: CONIN$::ReadConsoleW(%08x,%08x,%u,%08x,%08x).\n",
|
---|
642 | pHMHandleData,
|
---|
643 | lpvBuffer,
|
---|
644 | cchToRead,
|
---|
645 | lpcchRead,
|
---|
646 | lpvReserved);
|
---|
647 | #endif
|
---|
648 |
|
---|
649 | /* simply forward the request to that routine */
|
---|
650 | dwResult = HMDeviceConsoleInClass::ReadFile(pHMHandleData,
|
---|
651 | lpvBuffer,
|
---|
652 | cchToRead,
|
---|
653 | lpcchRead,
|
---|
654 | NULL);
|
---|
655 | /* @@@PH AScii -> unicode translation */
|
---|
656 |
|
---|
657 | return (dwResult); /* deliver return code */
|
---|
658 | }
|
---|
659 |
|
---|
660 |
|
---|
661 | /*****************************************************************************
|
---|
662 | * Name : DWORD HMDeviceConsoleInClass::ReadConsoleInputA
|
---|
663 | * Purpose : read events placed in the console input queue
|
---|
664 | * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
|
---|
665 | * PINPUT_RECORD pirBuffer - target buffer for events
|
---|
666 | * DWORD cInRecords - number of input records
|
---|
667 | * LPDWORD lpcRead - returns number of events stored
|
---|
668 | * Variables :
|
---|
669 | * Result : TRUE if successful, FALSE otherwise
|
---|
670 | * Remark :
|
---|
671 | * Status : UNTESTED
|
---|
672 | *
|
---|
673 | * Author : Patrick Haller [Tue, 1998/02/10 01:55]
|
---|
674 | *****************************************************************************/
|
---|
675 |
|
---|
676 | DWORD HMDeviceConsoleInClass::ReadConsoleInputA(PHMHANDLEDATA pHMHandleData,
|
---|
677 | PINPUT_RECORD pirBuffer,
|
---|
678 | DWORD cInRecords,
|
---|
679 | LPDWORD lpcRead)
|
---|
680 | {
|
---|
681 | ULONG ulPostCounter; /* semaphore post counter - ignored */
|
---|
682 | APIRET rc; /* API returncode */
|
---|
683 |
|
---|
684 | #ifdef DEBUG_LOCAL2
|
---|
685 | WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::ReadConsoleInputA(%08x,%08x,%08x,%08x).\n",
|
---|
686 | pHMHandleData,
|
---|
687 | pirBuffer,
|
---|
688 | cInRecords,
|
---|
689 | lpcRead);
|
---|
690 | #endif
|
---|
691 |
|
---|
692 | if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
|
---|
693 | {
|
---|
694 | rc = DosWaitEventSem(pConsoleInput->hevInputQueue, /* wait for input */
|
---|
695 | SEM_INDEFINITE_WAIT);
|
---|
696 | DosResetEventSem(pConsoleInput->hevInputQueue, /* reset semaphore */
|
---|
697 | &ulPostCounter); /* post counter - ignored */
|
---|
698 | }
|
---|
699 |
|
---|
700 |
|
---|
701 | /* now read events into target buffer */
|
---|
702 | for (ulPostCounter = 0;
|
---|
703 | ulPostCounter < cInRecords;
|
---|
704 | ulPostCounter++,
|
---|
705 | pirBuffer++)
|
---|
706 | {
|
---|
707 | rc = iConsoleInputEventPop(pirBuffer); /* get event from queue */
|
---|
708 | if (rc != NO_ERROR) /* if read error occurs, break look */
|
---|
709 | break;
|
---|
710 | }
|
---|
711 |
|
---|
712 | *lpcRead = ulPostCounter; /* return number of records read */
|
---|
713 | return (TRUE); /* OK */
|
---|
714 | }
|
---|
715 |
|
---|
716 |
|
---|
717 | /*****************************************************************************
|
---|
718 | * Name : DWORD HMDeviceConsoleInClass::ReadConsoleInputW
|
---|
719 | * Purpose : read events placed in the console input queue
|
---|
720 | * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
|
---|
721 | * PINPUT_RECORD pirBuffer - target buffer for events
|
---|
722 | * DWORD cInRecords - number of input records
|
---|
723 | * LPDWORD lpcRead - returns number of events stored
|
---|
724 | * Variables :
|
---|
725 | * Result : TRUE if successful, FALSE otherwise
|
---|
726 | * Remark :
|
---|
727 | * Status : UNTESTED
|
---|
728 | *
|
---|
729 | * Author : Patrick Haller [Tue, 1998/02/10 01:55]
|
---|
730 | *****************************************************************************/
|
---|
731 |
|
---|
732 | DWORD HMDeviceConsoleInClass::ReadConsoleInputW(PHMHANDLEDATA pHMHandleData,
|
---|
733 | PINPUT_RECORD pirBuffer,
|
---|
734 | DWORD cInRecords,
|
---|
735 | LPDWORD lpcRead)
|
---|
736 | {
|
---|
737 | ULONG ulPostCounter; /* semaphore post counter - ignored */
|
---|
738 | APIRET rc; /* API returncode */
|
---|
739 |
|
---|
740 | #ifdef DEBUG_LOCAL2
|
---|
741 | WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::ReadConsoleInputW(%08x,%08x,%08x,%08x).\n",
|
---|
742 | pHMHandleData,
|
---|
743 | pirBuffer,
|
---|
744 | cInRecords,
|
---|
745 | lpcRead);
|
---|
746 | #endif
|
---|
747 |
|
---|
748 | if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
|
---|
749 | {
|
---|
750 | rc = DosWaitEventSem(pConsoleInput->hevInputQueue, /* wait for input */
|
---|
751 | SEM_INDEFINITE_WAIT);
|
---|
752 | DosResetEventSem(pConsoleInput->hevInputQueue, /* reset semaphore */
|
---|
753 | &ulPostCounter); /* post counter - ignored */
|
---|
754 | }
|
---|
755 |
|
---|
756 |
|
---|
757 | /* now read events into target buffer */
|
---|
758 | for (ulPostCounter = 0;
|
---|
759 | ulPostCounter < cInRecords;
|
---|
760 | ulPostCounter++,
|
---|
761 | pirBuffer++)
|
---|
762 | {
|
---|
763 | rc = iConsoleInputEventPop(pirBuffer); /* get event from queue */
|
---|
764 | if (rc != NO_ERROR) /* if read error occurs, break look */
|
---|
765 | break;
|
---|
766 | }
|
---|
767 |
|
---|
768 | *lpcRead = ulPostCounter; /* return number of records read */
|
---|
769 | return (TRUE); /* OK */
|
---|
770 | }
|
---|
771 |
|
---|
772 |
|
---|
773 | /*****************************************************************************
|
---|
774 | * Name : DWORD HMDeviceConsoleInClass::SetConsoleMode
|
---|
775 | * Purpose : sets the current console mode
|
---|
776 | * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
|
---|
777 | * DWORD dwMode - console mode
|
---|
778 | * Variables :
|
---|
779 | * Result :
|
---|
780 | * Remark :
|
---|
781 | * Status : UNTESTED
|
---|
782 | *
|
---|
783 | * Author : Patrick Haller [Wed, 1998/02/16 11:46]
|
---|
784 | *****************************************************************************/
|
---|
785 |
|
---|
786 | DWORD HMDeviceConsoleInClass::SetConsoleMode(PHMHANDLEDATA pHMHandleData,
|
---|
787 | DWORD dwMode)
|
---|
788 | {
|
---|
789 | PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
|
---|
790 |
|
---|
791 | #ifdef DEBUG_LOCAL2
|
---|
792 | WriteLog("KERNEL32/CONSOLE: CONIN$::SetConsoleMode(%08x,%08x).\n",
|
---|
793 | pHMHandleData,
|
---|
794 | dwMode);
|
---|
795 | #endif
|
---|
796 |
|
---|
797 | pConsoleInput->dwConsoleMode = dwMode; /* set current console mode */
|
---|
798 |
|
---|
799 | return (TRUE);
|
---|
800 | }
|
---|
801 |
|
---|
802 |
|
---|
803 | /*****************************************************************************
|
---|
804 | * Name : DWORD HMDeviceConsoleInClass::WriteConsoleInputA
|
---|
805 | * Purpose : this writes event records directly into the queue
|
---|
806 | * Parameters: PHMHANDLEDATA pHMHandleData
|
---|
807 | * PINPUT_RECORD pirBuffer
|
---|
808 | * DWORD cInRecords
|
---|
809 | * LPDWORD lpcWritten
|
---|
810 | * Variables :
|
---|
811 | * Result :
|
---|
812 | * Remark :
|
---|
813 | * Status : NO_ERROR - API succeeded
|
---|
814 | * other - what is to be set in SetLastError
|
---|
815 | *
|
---|
816 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
817 | *****************************************************************************/
|
---|
818 |
|
---|
819 | DWORD HMDeviceConsoleInClass::WriteConsoleInputA (PHMHANDLEDATA pHMHandleData,
|
---|
820 | PINPUT_RECORD pirBuffer,
|
---|
821 | DWORD cInRecords,
|
---|
822 | LPDWORD lpcWritten)
|
---|
823 | {
|
---|
824 | PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
|
---|
825 | APIRET rc; /* API returncode */
|
---|
826 | ULONG ulCounter; /* loop counter */
|
---|
827 |
|
---|
828 | #ifdef DEBUG_LOCAL2
|
---|
829 | WriteLog("KERNEL32/CONSOLE: CONIN$::WriteConsoleInputA(%08x,%08x,%u,%08x).\n",
|
---|
830 | pHMHandleData,
|
---|
831 | pirBuffer,
|
---|
832 | cInRecords,
|
---|
833 | lpcWritten);
|
---|
834 | #endif
|
---|
835 |
|
---|
836 | for (ulCounter = 0;
|
---|
837 | ulCounter < cInRecords;
|
---|
838 | ulCounter++,
|
---|
839 | pirBuffer++)
|
---|
840 | {
|
---|
841 | rc = iConsoleInputEventPush(pirBuffer); /* push current event */
|
---|
842 | if (rc != NO_ERROR) /* oops ? queue full ? problem ? */
|
---|
843 | break;
|
---|
844 | }
|
---|
845 |
|
---|
846 | *lpcWritten = ulCounter; /* return number of events written */
|
---|
847 | return (TRUE); /* OK */
|
---|
848 | }
|
---|
849 |
|
---|
850 |
|
---|
851 | /*****************************************************************************
|
---|
852 | * Name : DWORD HMDeviceConsoleInClass::WriteConsoleInputW
|
---|
853 | * Purpose : this writes event records directly into the queue
|
---|
854 | * Parameters: PHMHANDLEDATA pHMHandleData
|
---|
855 | * PINPUT_RECORD pirBuffer
|
---|
856 | * DWORD cInRecords
|
---|
857 | * LPDWORD lpcWritten
|
---|
858 | * Variables :
|
---|
859 | * Result :
|
---|
860 | * Remark :
|
---|
861 | * Status : NO_ERROR - API succeeded
|
---|
862 | * other - what is to be set in SetLastError
|
---|
863 | *
|
---|
864 | * Author : Patrick Haller [Wed, 1998/02/11 20:44]
|
---|
865 | *****************************************************************************/
|
---|
866 |
|
---|
867 | DWORD HMDeviceConsoleInClass::WriteConsoleInputW (PHMHANDLEDATA pHMHandleData,
|
---|
868 | PINPUT_RECORD pirBuffer,
|
---|
869 | DWORD cInRecords,
|
---|
870 | LPDWORD lpcWritten)
|
---|
871 | {
|
---|
872 | PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
|
---|
873 | APIRET rc; /* API returncode */
|
---|
874 | ULONG ulCounter; /* loop counter */
|
---|
875 |
|
---|
876 | #ifdef DEBUG_LOCAL2
|
---|
877 | WriteLog("KERNEL32/CONSOLE: CONIN$::WriteConsoleInputW(%08x,%08x,%u,%08x).\n",
|
---|
878 | pHMHandleData,
|
---|
879 | pirBuffer,
|
---|
880 | cInRecords,
|
---|
881 | lpcWritten);
|
---|
882 | #endif
|
---|
883 |
|
---|
884 | for (ulCounter = 0;
|
---|
885 | ulCounter < cInRecords;
|
---|
886 | ulCounter++,
|
---|
887 | pirBuffer++)
|
---|
888 | {
|
---|
889 | rc = iConsoleInputEventPush(pirBuffer); /* push current event */
|
---|
890 | if (rc != NO_ERROR) /* oops ? queue full ? problem ? */
|
---|
891 | break;
|
---|
892 | }
|
---|
893 |
|
---|
894 | *lpcWritten = ulCounter; /* return number of events written */
|
---|
895 | return (TRUE); /* OK */
|
---|
896 | }
|
---|
897 |
|
---|
898 |
|
---|