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

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

basic support for VIO console command line apps added + FormatMessage addition

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