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

Last change on this file since 1484 was 1484, checked in by phaller, 26 years ago

Fix: console (unicode) updates

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