source: trunk/src/kernel32/conin.cpp@ 7457

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

preliminary work on overlapped serial comm IO

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