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

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

lstrcpynAtoW/WtoA fixes (Wine depends on 0 terminating of these functions) + console changes for methods that depended on the old behaviour

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