]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Uefi/InteractiveIO/IIOecho.c
2 Echo characters to an Interactive I/O Output device.
4 The functions assume that isatty() is TRUE at the time they are called.
5 Since the UEFI console is a WIDE character device, these functions do all
6 processing using wide characters.
8 It is the responsibility of the caller, or higher level function, to perform
9 any necessary translation between wide and narrow characters.
11 Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
12 This program and the accompanying materials are licensed and made available
13 under the terms and conditions of the BSD License which accompanies this
14 distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php.
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <LibConfig.h>
26 #include <sys/termios.h>
27 #include <Device/IIO.h>
28 #include "IIOutilities.h"
29 #include "IIOechoCtrl.h"
31 /** Echo one character to an IIO file.
33 If character InCh is a special "echo control" character, process it and output
34 the resultant character(s), if any. Otherwise pass the character on to the
35 IIO_WriteOne() function which performs generic output processing, if needed.
37 @param[in] filp Pointer to an open IIO file's file descriptor structure.
38 @param[in] InCh The wide character to be echoed.
39 @param[in] EchoIsOK A flag indicating whether echoing is appropriate for this
42 @retval -1 The filp argument does not refer to an IIO device.
43 Global value errno is set to EINVAL.
44 @retval >=0 The number of characters actually output.
50 struct __filedes
*filp
,
68 LFlags
= This
->Termio
.c_lflag
;
69 OutBuf
= This
->OutBuf
;
71 AttrBuf
= This
->AttrBuf
;
72 AttrDex
= InBuf
->GetWDex(InBuf
);
75 case IIO_ECHO_DISCARD
:
76 // Do not buffer or otherwise process
81 // Delete last character from InBuf
82 if(!InBuf
->IsEmpty(InBuf
)) {
83 (void)InBuf
->Truncate(InBuf
);
85 // Erase screen character(s) based on Attrib value
87 AttrDex
= (UINT32
)ModuloDecrement(AttrDex
, InBuf
->NumElements
);
88 NumEcho
= AttrBuf
[AttrDex
];
89 for(i
= 0; i
< NumEcho
; ++i
) {
90 (void)IIO_WriteOne(filp
, OutBuf
, CHAR_BACKSPACE
);
93 for(i
= 0; i
< NumEcho
; ++i
) {
94 (void)IIO_WriteOne(filp
, OutBuf
, L
' ');
96 for(i
= 0; i
< NumEcho
; ++i
) {
97 (void)IIO_WriteOne(filp
, OutBuf
, CHAR_BACKSPACE
);
108 // Flush contents of InBuf and OutBuf
109 InBuf
->Flush(InBuf
, (size_t)-1);
110 OutBuf
->Flush(OutBuf
, (size_t)-1);
112 // Erase characters from screen.
114 NumEcho
= IIO_CursorDelta(This
, &This
->InitialXY
, &This
->CurrentXY
);
115 for(i
= 0; i
< NumEcho
; ++i
) {
116 (void)IIO_WriteOne(filp
, OutBuf
, L
' ');
122 // Add character to input buffer
123 (void)InBuf
->Write(InBuf
, &InCh
, 1);
125 NumEcho
= 0; // In case echoing is not enabled or OK
126 // If echoing is OK and enabled, "echo" character using IIO_WriteOne
129 ((LFlags
& ECHONL
) && (InCh
== CHAR_LINEFEED
))))
131 NumEcho
= IIO_WriteOne(filp
, OutBuf
, InCh
);
133 AttrBuf
[AttrDex
] = (UINT8
)NumEcho
;