mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
Simplify tty_write()
This commit is contained in:
parent
52446f4d62
commit
5b82c710f1
1 changed files with 20 additions and 20 deletions
32
src/tty.c
32
src/tty.c
|
|
@ -145,19 +145,24 @@ void tty_flush(int fd)
|
||||||
|
|
||||||
ssize_t tty_write(int fd, const void *buffer, size_t count)
|
ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t bytes_written = 0;
|
ssize_t retval = 0, bytes_written = 0;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (option.upcase)
|
||||||
|
{
|
||||||
|
// Convert lower case to upper case
|
||||||
|
for (i = 0; i<count; i++)
|
||||||
|
{
|
||||||
|
*((unsigned char*)buffer+i) = toupper(*((unsigned char*)buffer+i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (option.output_delay || option.eol_delay)
|
if (option.output_delay || option.eol_delay)
|
||||||
{
|
{
|
||||||
// Write byte by byte with output delay
|
// Write byte by byte with output delay
|
||||||
for (size_t i=0; i<count; i++)
|
for (i=0; i<count; i++)
|
||||||
{
|
{
|
||||||
// convert alpha to upper case
|
retval = write(fd, buffer, 1);
|
||||||
if ( option.upcase )
|
|
||||||
{
|
|
||||||
*(unsigned char*)buffer = toupper(*(unsigned char*)buffer);
|
|
||||||
}
|
|
||||||
ssize_t retval = write(fd, buffer, 1);
|
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
{
|
{
|
||||||
// Error
|
// Error
|
||||||
|
|
@ -165,11 +170,14 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bytes_written += retval;
|
bytes_written += retval;
|
||||||
|
|
||||||
if (option.eol_delay && *(unsigned char*)buffer == '\r')
|
if (option.eol_delay && *(unsigned char*)buffer == '\r')
|
||||||
{
|
{
|
||||||
delay(option.eol_delay);
|
delay(option.eol_delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
fsync(fd);
|
fsync(fd);
|
||||||
|
|
||||||
if (option.output_delay)
|
if (option.output_delay)
|
||||||
{
|
{
|
||||||
delay(option.output_delay);
|
delay(option.output_delay);
|
||||||
|
|
@ -184,14 +192,6 @@ ssize_t tty_write(int fd, const void *buffer, size_t count)
|
||||||
tty_flush(fd);
|
tty_flush(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert lower case to upper case, in situ
|
|
||||||
if ( option.upcase )
|
|
||||||
{
|
|
||||||
for ( size_t i = 0; i<count; i++ )
|
|
||||||
{
|
|
||||||
*((unsigned char*)buffer+i) = toupper(*((unsigned char*)buffer+i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Copy bytes to tty write buffer
|
// Copy bytes to tty write buffer
|
||||||
memcpy(tty_buffer_write_ptr, buffer, count);
|
memcpy(tty_buffer_write_ptr, buffer, count);
|
||||||
tty_buffer_write_ptr += count;
|
tty_buffer_write_ptr += count;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue