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

Last change on this file since 2050 was 2050, checked in by sandervl, 26 years ago

Read/WriteFile return value type changes

File size: 35.2 KB
Line 
1/* $Id: conin.cpp,v 1.7 1999-12-09 19:08:25 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 <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
116BOOL 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
267BOOL 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 SetLastError(ERROR_ACCESS_DENIED);
285 return FALSE;
286}
287
288
289/*****************************************************************************
290 * Name :
291 * Purpose :
292 * Parameters:
293 * Variables :
294 * Result :
295 * Remark :
296 * Status :
297 *
298 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
299 *****************************************************************************/
300
301DWORD HMDeviceConsoleInClass::_DeviceRequest (PHMHANDLEDATA pHMHandleData,
302 ULONG ulRequestCode,
303 ULONG arg1,
304 ULONG arg2,
305 ULONG arg3,
306 ULONG arg4)
307{
308 switch (ulRequestCode)
309 {
310 case DRQ_FLUSHCONSOLEINPUTBUFFER:
311 return (HMDeviceConsoleInClass::
312 FlushConsoleInputBuffer(pHMHandleData));
313
314 case DRQ_GETCONSOLEMODE:
315 return (HMDeviceConsoleInClass
316 ::GetConsoleMode(pHMHandleData,
317 (LPDWORD)arg1));
318
319 case DRQ_GETNUMBEROFCONSOLEINPUTEVENTS:
320 return (HMDeviceConsoleInClass::
321 GetNumberOfConsoleInputEvents(pHMHandleData,
322 (LPDWORD)arg1));
323
324 case DRQ_PEEKCONSOLEINPUTA:
325 return (HMDeviceConsoleInClass::
326 PeekConsoleInputA(pHMHandleData,
327 (PINPUT_RECORD)arg1,
328 (DWORD) arg2,
329 (LPDWORD) arg3));
330
331 case DRQ_PEEKCONSOLEINPUTW:
332 return (HMDeviceConsoleInClass::
333 PeekConsoleInputW(pHMHandleData,
334 (PINPUT_RECORD)arg1,
335 (DWORD) arg2,
336 (LPDWORD) arg3));
337
338
339 case DRQ_READCONSOLEA:
340 return (HMDeviceConsoleInClass::
341 ReadConsoleA(pHMHandleData,
342 (CONST VOID*) arg1,
343 (DWORD) arg2,
344 (LPDWORD) arg3,
345 (LPVOID) arg4));
346
347 case DRQ_READCONSOLEW:
348 return (HMDeviceConsoleInClass::
349 ReadConsoleW(pHMHandleData,
350 (CONST VOID*) arg1,
351 (DWORD) arg2,
352 (LPDWORD) arg3,
353 (LPVOID) arg4));
354
355 case DRQ_READCONSOLEINPUTA:
356 return (HMDeviceConsoleInClass::
357 ReadConsoleInputA(pHMHandleData,
358 (PINPUT_RECORD)arg1,
359 (DWORD)arg2,
360 (LPDWORD)arg3));
361
362 case DRQ_READCONSOLEINPUTW:
363 return (HMDeviceConsoleInClass::
364 ReadConsoleInputW(pHMHandleData,
365 (PINPUT_RECORD)arg1,
366 (DWORD)arg2,
367 (LPDWORD)arg3));
368
369 case DRQ_SETCONSOLEMODE:
370 return (HMDeviceConsoleInClass
371 ::SetConsoleMode(pHMHandleData,
372 (DWORD)arg1));
373
374 case DRQ_WRITECONSOLEINPUTA:
375 return (HMDeviceConsoleInClass::
376 WriteConsoleInputA(pHMHandleData,
377 (PINPUT_RECORD)arg1,
378 (DWORD)arg2,
379 (LPDWORD)arg3));
380
381 case DRQ_WRITECONSOLEINPUTW:
382 return (HMDeviceConsoleInClass::
383 WriteConsoleInputW(pHMHandleData,
384 (PINPUT_RECORD)arg1,
385 (DWORD)arg2,
386 (LPDWORD)arg3));
387
388 }
389
390#ifdef DEBUG_LOCAL
391 WriteLog("KERNEL32/CONSOLE:HMDeviceConsoleInClass:_DeviceRequest %s(%08x,%08x,%08x,%08x,%08x,%08x) unknown request\n",
392 lpHMDeviceName,
393 pHMHandleData->hHMHandle,
394 ulRequestCode,
395 arg1,
396 arg2,
397 arg3,
398 arg4);
399#endif
400
401 SetLastError(ERROR_INVALID_FUNCTION); /* request not implemented */
402 return(FALSE); /* we assume this indicates API call failed */
403}
404
405
406/*****************************************************************************
407 * Name : BOOL HMDeviceConsoleInClass::FlushConsoleInputBuffer
408 * Purpose : flushes all events from the input queue
409 * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
410 * Variables :
411 * Result :
412 * Remark :
413 * Status : UNTESTED
414 *
415 * Author : Patrick Haller [Wed, 1998/02/16 11:46]
416 *****************************************************************************/
417
418BOOL HMDeviceConsoleInClass::FlushConsoleInputBuffer(PHMHANDLEDATA pHMHandleData)
419{
420 ULONG ulCounter; /* loop counter */
421
422#ifdef DEBUG_LOCAL2
423 WriteLog("KERNEL32/CONSOLE: CONIN$::FlushConsoleInputBuffer(%08x).\n",
424 pHMHandleData);
425#endif
426
427 pConsoleInput->ulIndexFree = 0;
428 pConsoleInput->ulIndexEvent = 0;
429 pConsoleInput->ulEvents = 0;
430
431 for (ulCounter = 0;
432 ulCounter < CONSOLE_INPUTQUEUESIZE;
433 ulCounter++)
434 pConsoleInput->arrInputRecord[ulCounter].EventType = 0x0000; /* free event */
435
436 return (TRUE);
437}
438
439
440/*****************************************************************************
441 * Name : DWORD HMDeviceConsoleInClass::GetConsoleMode
442 * Purpose : queries the current console mode
443 * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
444 * LPDWORD lpMode
445 * Variables :
446 * Result :
447
448 * Remark :
449 * Status : UNTESTED
450 *
451 * Author : Patrick Haller [Wed, 1998/02/16 11:46]
452 *****************************************************************************/
453
454DWORD HMDeviceConsoleInClass::GetConsoleMode(PHMHANDLEDATA pHMHandleData,
455 LPDWORD lpMode)
456{
457#ifdef DEBUG_LOCAL2
458 WriteLog("KERNEL32/CONSOLE: CONIN$::GetConsoleMode(%08x,%08x).\n",
459 pHMHandleData,
460 lpMode);
461#endif
462
463 *lpMode = pConsoleInput->dwConsoleMode; /* return current console mode */
464
465 return (TRUE);
466}
467
468
469/*****************************************************************************
470 * Name : DWORD HMDeviceConsoleInClass::GetNumberOfConsoleInputEvents
471 * Purpose : queries the current number of events in the input queue
472 * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
473 * LPDWORD lpNumberOfEvents - return number of events
474 * Variables :
475 * Result :
476 * Remark :
477 * Status : UNTESTED
478 *
479 * Author : Patrick Haller [Wed, 1998/02/16 11:46]
480 *****************************************************************************/
481
482BOOL HMDeviceConsoleInClass::GetNumberOfConsoleInputEvents(PHMHANDLEDATA pHMHandleData,
483 LPDWORD lpNumberOfEvents)
484{
485#ifdef DEBUG_LOCAL2
486 WriteLog("KERNEL32/CONSOLE: CONIN$::GetNumberOfConsoleInputEvents(%08x,%08x).\n",
487 pHMHandleData,
488 lpNumberOfEvents);
489#endif
490
491 *lpNumberOfEvents = pConsoleInput->ulEvents; /* return number of events */
492
493 return (TRUE);
494}
495
496
497/*****************************************************************************
498 * Name : DWORD HMDeviceConsoleInClass::PeekConsoleInputA
499 * Purpose : peeks events placed in the console input queue
500 * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
501 * PINPUT_RECORD pirBuffer - target buffer for events
502 * DWORD cInRecords - number of input records
503 * LPDWORD lpcRead - returns number of events stored
504 * Variables :
505 * Result : TRUE if successful, FALSE otherwise
506 * Remark : if queue is completely filled and no event is free,
507 * loop will scan over queue multiple times, until target
508 * buffer is filled. It does not check ulCounter to stop
509 * when one scan of the queue is complete.
510 * Status : UNTESTED
511 *
512 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
513 *****************************************************************************/
514
515DWORD HMDeviceConsoleInClass::PeekConsoleInputA(PHMHANDLEDATA pHMHandleData,
516 PINPUT_RECORD pirBuffer,
517 DWORD cInRecords,
518 LPDWORD lpcRead)
519{
520 ULONG ulCounter; /* loop counter */
521 ULONG ulCurrentEvent; /* index of current event in the queue */
522 PINPUT_RECORD pirEvent; /* pointer to current queue element */
523
524#ifdef DEBUG_LOCAL2
525 WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::PeekConsoleInputA(%08x,%08x,%08x,%08x).\n",
526 pHMHandleData,
527 pirBuffer,
528 cInRecords,
529 lpcRead);
530#endif
531
532 if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
533 {
534 *lpcRead = 0; /* no events read from queue */
535 return (TRUE); /* OK, we're done */
536 }
537
538
539 for (ulCounter = 0,
540 ulCurrentEvent = pConsoleInput->ulIndexEvent,
541 pirEvent = &pConsoleInput->arrInputRecord[pConsoleInput->ulIndexEvent];
542
543 ulCounter < cInRecords;
544
545 ulCounter++,
546 ulCurrentEvent++,
547 pirEvent++,
548 pirBuffer++)
549 {
550 if (ulCurrentEvent > CONSOLE_INPUTQUEUESIZE) /* reaching after end of que*/
551 {
552 ulCurrentEvent = 0; /* then start over from beginning of queue */
553 pirEvent = pConsoleInput->arrInputRecord;
554 }
555
556 if (pirEvent->EventType == 0x0000) /* no more events ? */
557 break; /* leave loop then */
558
559 memcpy(pirEvent, /* copy event data */
560 pirBuffer,
561 sizeof(INPUT_RECORD));
562 }
563
564 *lpcRead = ulCounter; /* return number of events read */
565 return (TRUE); /* OK, we're done */
566}
567
568
569/*****************************************************************************
570 * Name : DWORD HMDeviceConsoleInClass::PeekConsoleInputW
571 * Purpose : peeks events placed in the console input queue
572 * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
573 * PINPUT_RECORD pirBuffer - target buffer for events
574 * DWORD cInRecords - number of input records
575 * LPDWORD lpcRead - returns number of events stored
576 * Variables :
577 * Result : TRUE if successful, FALSE otherwise
578 * Remark : if queue is completely filled and no event is free,
579 * loop will scan over queue multiple times, until target
580 * buffer is filled. It does not check ulCounter to stop
581 * when one scan of the queue is complete.
582 * Status : UNTESTED
583 *
584 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
585 *****************************************************************************/
586
587DWORD HMDeviceConsoleInClass::PeekConsoleInputW(PHMHANDLEDATA pHMHandleData,
588 PINPUT_RECORD pirBuffer,
589 DWORD cInRecords,
590 LPDWORD lpcRead)
591{
592 ULONG ulCounter; /* loop counter */
593 ULONG ulCurrentEvent; /* index of current event in the queue */
594 PINPUT_RECORD pirEvent; /* pointer to current queue element */
595
596#ifdef DEBUG_LOCAL2
597 WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::PeekConsoleInputW(%08x,%08x,%08x,%08x).\n",
598 pHMHandleData,
599 pirBuffer,
600 cInRecords,
601 lpcRead);
602#endif
603
604 if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
605 {
606 *lpcRead = 0; /* no events read from queue */
607 return (TRUE); /* OK, we're done */
608 }
609
610
611 for (ulCounter = 0,
612 ulCurrentEvent = pConsoleInput->ulIndexEvent,
613 pirEvent = &pConsoleInput->arrInputRecord[pConsoleInput->ulIndexEvent];
614
615 ulCounter < cInRecords;
616
617 ulCounter++,
618 ulCurrentEvent++,
619 pirEvent++,
620 pirBuffer++)
621 {
622 if (ulCurrentEvent > CONSOLE_INPUTQUEUESIZE) /* reaching after end of que*/
623 {
624 ulCurrentEvent = 0; /* then start over from beginning of queue */
625 pirEvent = pConsoleInput->arrInputRecord;
626 }
627
628 if (pirEvent->EventType == 0x0000) /* no more events ? */
629 break; /* leave loop then */
630
631 memcpy(pirEvent, /* copy event data */
632 pirBuffer,
633 sizeof(INPUT_RECORD));
634 }
635
636 *lpcRead = ulCounter; /* return number of events read */
637 return (TRUE); /* OK, we're done */
638}
639
640
641/*****************************************************************************
642 * Name : DWORD HMDeviceConsoleInClass::ReadConsoleA
643 * Purpose : read a string from the console
644 * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
645 * LPWORD lpwAttribute
646 * DWORD cWriteCells
647 * COORD dwWriteCoord
648 * LPDWORD lpcWritten
649 * Variables :
650 * Result :
651 * Remark :
652 * Status : UNTESTED
653 *
654 * Author : Patrick Haller [Wed, 1998/02/16 11:46]
655 *****************************************************************************/
656
657DWORD HMDeviceConsoleInClass::ReadConsoleA(PHMHANDLEDATA pHMHandleData,
658 CONST VOID* lpvBuffer,
659 DWORD cchToRead,
660 LPDWORD lpcchRead,
661 LPVOID lpvReserved)
662{
663 PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
664
665#ifdef DEBUG_LOCAL2
666 WriteLog("KERNEL32/CONSOLE: CONIN$::ReadConsoleA(%08x,%08x,%u,%08x,%08x).\n",
667 pHMHandleData,
668 lpvBuffer,
669 cchToRead,
670 lpcchRead,
671 lpvReserved);
672#endif
673
674 /* simply forward the request to that routine */
675 return (HMDeviceConsoleInClass::ReadFile(pHMHandleData,
676 lpvBuffer,
677 cchToRead,
678 lpcchRead,
679 NULL));
680}
681
682
683/*****************************************************************************
684 * Name : DWORD HMDeviceConsoleInClass::ReadConsoleW
685 * Purpose : write a string to the console
686 * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
687 * LPWORD lpwAttribute
688 * DWORD cWriteCells
689 * COORD dwWriteCoord
690 * LPDWORD lpcWritten
691 * Variables :
692 * Result :
693 * Remark :
694 * Status : UNTESTED
695 *
696 * Author : Patrick Haller [Wed, 1998/02/16 11:46]
697 *****************************************************************************/
698
699DWORD HMDeviceConsoleInClass::ReadConsoleW(PHMHANDLEDATA pHMHandleData,
700 CONST VOID* lpvBuffer,
701 DWORD cchToRead,
702 LPDWORD lpcchRead,
703 LPVOID lpvReserved)
704{
705 PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
706 DWORD dwResult;
707 LPSTR lpstrAscii;
708
709#ifdef DEBUG_LOCAL2
710 WriteLog("KERNEL32/CONSOLE: CONIN$::ReadConsoleW(%08x,%08x,%u,%08x,%08x).\n",
711 pHMHandleData,
712 lpvBuffer,
713 cchToRead,
714 lpcchRead,
715 lpvReserved);
716#endif
717
718 // create ascii buffer
719 lpstrAscii = (LPSTR)HEAP_malloc(cchToRead);
720 if (lpstrAscii == NULL)
721 return ERROR_NOT_ENOUGH_MEMORY;
722
723 /* simply forward the request to that routine */
724 dwResult = HMDeviceConsoleInClass::ReadFile(pHMHandleData,
725 lpstrAscii,
726 cchToRead,
727 lpcchRead,
728 NULL);
729 /* Ascii -> unicode translation */
730 if (dwResult == TRUE)
731 lstrcpynAtoW((LPWSTR)lpvBuffer, lpstrAscii, *lpcchRead);
732
733 HEAP_free(lpstrAscii);
734
735 return (dwResult); /* deliver return code */
736}
737
738
739/*****************************************************************************
740 * Name : DWORD HMDeviceConsoleInClass::ReadConsoleInputA
741 * Purpose : read events placed in the console input queue
742 * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
743 * PINPUT_RECORD pirBuffer - target buffer for events
744 * DWORD cInRecords - number of input records
745 * LPDWORD lpcRead - returns number of events stored
746 * Variables :
747 * Result : TRUE if successful, FALSE otherwise
748 * Remark :
749 * Status : UNTESTED
750 *
751 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
752 *****************************************************************************/
753
754DWORD HMDeviceConsoleInClass::ReadConsoleInputA(PHMHANDLEDATA pHMHandleData,
755 PINPUT_RECORD pirBuffer,
756 DWORD cInRecords,
757 LPDWORD lpcRead)
758{
759 ULONG ulPostCounter; /* semaphore post counter - ignored */
760 APIRET rc; /* API returncode */
761
762#ifdef DEBUG_LOCAL2
763 WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::ReadConsoleInputA(%08x,%08x,%08x,%08x).\n",
764 pHMHandleData,
765 pirBuffer,
766 cInRecords,
767 lpcRead);
768#endif
769
770 if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
771 {
772 rc = DosWaitEventSem(pConsoleInput->hevInputQueue, /* wait for input */
773 SEM_INDEFINITE_WAIT);
774 DosResetEventSem(pConsoleInput->hevInputQueue, /* reset semaphore */
775 &ulPostCounter); /* post counter - ignored */
776 }
777
778
779 /* now read events into target buffer */
780 for (ulPostCounter = 0;
781 ulPostCounter < cInRecords;
782 ulPostCounter++,
783 pirBuffer++)
784 {
785 rc = iConsoleInputEventPop(pirBuffer); /* get event from queue */
786 if (rc != NO_ERROR) /* if read error occurs, break look */
787 break;
788 }
789
790 *lpcRead = ulPostCounter; /* return number of records read */
791 return (TRUE); /* OK */
792}
793
794
795/*****************************************************************************
796 * Name : DWORD HMDeviceConsoleInClass::ReadConsoleInputW
797 * Purpose : read events placed in the console input queue
798 * Parameters: PHMHANDLEDATA pHMHandleData - current handle data
799 * PINPUT_RECORD pirBuffer - target buffer for events
800 * DWORD cInRecords - number of input records
801 * LPDWORD lpcRead - returns number of events stored
802 * Variables :
803 * Result : TRUE if successful, FALSE otherwise
804 * Remark :
805 * Status : UNTESTED
806 *
807 * Author : Patrick Haller [Tue, 1998/02/10 01:55]
808 *****************************************************************************/
809
810DWORD HMDeviceConsoleInClass::ReadConsoleInputW(PHMHANDLEDATA pHMHandleData,
811 PINPUT_RECORD pirBuffer,
812 DWORD cInRecords,
813 LPDWORD lpcRead)
814{
815 ULONG ulPostCounter; /* semaphore post counter - ignored */
816 APIRET rc; /* API returncode */
817
818#ifdef DEBUG_LOCAL2
819 WriteLog("KERNEL32/CONSOLE: HMDeviceConsoleInClass::ReadConsoleInputW(%08x,%08x,%08x,%08x).\n",
820 pHMHandleData,
821 pirBuffer,
822 cInRecords,
823 lpcRead);
824#endif
825
826 if (iConsoleInputQueryEvents() == 0) /* if queue is currently empty */
827 {
828 rc = DosWaitEventSem(pConsoleInput->hevInputQueue, /* wait for input */
829 SEM_INDEFINITE_WAIT);
830 DosResetEventSem(pConsoleInput->hevInputQueue, /* reset semaphore */
831 &ulPostCounter); /* post counter - ignored */
832 }
833
834
835 /* now read events into target buffer */
836 for (ulPostCounter = 0;
837 ulPostCounter < cInRecords;
838 ulPostCounter++,
839 pirBuffer++)
840 {
841 rc = iConsoleInputEventPop(pirBuffer); /* get event from queue */
842 if (rc != NO_ERROR) /* if read error occurs, break look */
843 break;
844 }
845
846 *lpcRead = ulPostCounter; /* return number of records read */
847 return (TRUE); /* OK */
848}
849
850
851/*****************************************************************************
852 * Name : DWORD HMDeviceConsoleInClass::SetConsoleMode
853 * Purpose : sets the current console mode
854 * Parameters: PHMHANDLEDATA pHMHandleData - handle specific data
855 * DWORD dwMode - console mode
856 * Variables :
857 * Result :
858 * Remark :
859 * Status : UNTESTED
860 *
861 * Author : Patrick Haller [Wed, 1998/02/16 11:46]
862 *****************************************************************************/
863
864DWORD HMDeviceConsoleInClass::SetConsoleMode(PHMHANDLEDATA pHMHandleData,
865 DWORD dwMode)
866{
867 PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
868
869#ifdef DEBUG_LOCAL2
870 WriteLog("KERNEL32/CONSOLE: CONIN$::SetConsoleMode(%08x,%08x).\n",
871 pHMHandleData,
872 dwMode);
873#endif
874
875 pConsoleInput->dwConsoleMode = dwMode; /* set current console mode */
876
877 return (TRUE);
878}
879
880
881/*****************************************************************************
882 * Name : DWORD HMDeviceConsoleInClass::WriteConsoleInputA
883 * Purpose : this writes event records directly into the queue
884 * Parameters: PHMHANDLEDATA pHMHandleData
885 * PINPUT_RECORD pirBuffer
886 * DWORD cInRecords
887 * LPDWORD lpcWritten
888 * Variables :
889 * Result :
890 * Remark :
891 * Status : NO_ERROR - API succeeded
892 * other - what is to be set in SetLastError
893 *
894 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
895 *****************************************************************************/
896
897DWORD HMDeviceConsoleInClass::WriteConsoleInputA (PHMHANDLEDATA pHMHandleData,
898 PINPUT_RECORD pirBuffer,
899 DWORD cInRecords,
900 LPDWORD lpcWritten)
901{
902 PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
903 APIRET rc; /* API returncode */
904 ULONG ulCounter; /* loop counter */
905
906#ifdef DEBUG_LOCAL2
907 WriteLog("KERNEL32/CONSOLE: CONIN$::WriteConsoleInputA(%08x,%08x,%u,%08x).\n",
908 pHMHandleData,
909 pirBuffer,
910 cInRecords,
911 lpcWritten);
912#endif
913
914 for (ulCounter = 0;
915 ulCounter < cInRecords;
916 ulCounter++,
917 pirBuffer++)
918 {
919 rc = iConsoleInputEventPush(pirBuffer); /* push current event */
920 if (rc != NO_ERROR) /* oops ? queue full ? problem ? */
921 break;
922 }
923
924 *lpcWritten = ulCounter; /* return number of events written */
925 return (TRUE); /* OK */
926}
927
928
929/*****************************************************************************
930 * Name : DWORD HMDeviceConsoleInClass::WriteConsoleInputW
931 * Purpose : this writes event records directly into the queue
932 * Parameters: PHMHANDLEDATA pHMHandleData
933 * PINPUT_RECORD pirBuffer
934 * DWORD cInRecords
935 * LPDWORD lpcWritten
936 * Variables :
937 * Result :
938 * Remark :
939 * Status : NO_ERROR - API succeeded
940 * other - what is to be set in SetLastError
941 *
942 * Author : Patrick Haller [Wed, 1998/02/11 20:44]
943 *****************************************************************************/
944
945DWORD HMDeviceConsoleInClass::WriteConsoleInputW (PHMHANDLEDATA pHMHandleData,
946 PINPUT_RECORD pirBuffer,
947 DWORD cInRecords,
948 LPDWORD lpcWritten)
949{
950 PCONSOLEBUFFER pConsoleBuffer = (PCONSOLEBUFFER)pHMHandleData->lpHandlerData;
951 APIRET rc; /* API returncode */
952 ULONG ulCounter; /* loop counter */
953
954#ifdef DEBUG_LOCAL2
955 WriteLog("KERNEL32/CONSOLE: CONIN$::WriteConsoleInputW(%08x,%08x,%u,%08x).\n",
956 pHMHandleData,
957 pirBuffer,
958 cInRecords,
959 lpcWritten);
960#endif
961
962 for (ulCounter = 0;
963 ulCounter < cInRecords;
964 ulCounter++,
965 pirBuffer++)
966 {
967 rc = iConsoleInputEventPush(pirBuffer); /* push current event */
968 if (rc != NO_ERROR) /* oops ? queue full ? problem ? */
969 break;
970 }
971
972 *lpcWritten = ulCounter; /* return number of events written */
973 return (TRUE); /* OK */
974}
975
976
Note: See TracBrowser for help on using the repository browser.