mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
Merge pull request #194 from somewear-labs/socketInputModes
Support input mapping modes for sockets
This commit is contained in:
commit
ec2cf476bb
3 changed files with 27 additions and 2 deletions
20
src/socket.c
20
src/socket.c
|
|
@ -33,6 +33,7 @@
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
|
#include "tty.h"
|
||||||
|
|
||||||
#define MAX_SOCKET_CLIENTS 16
|
#define MAX_SOCKET_CLIENTS 16
|
||||||
#define SOCKET_PORT_DEFAULT 3333
|
#define SOCKET_PORT_DEFAULT 3333
|
||||||
|
|
@ -340,11 +341,26 @@ bool socket_handle_input(fd_set *rdfs, char *output_char)
|
||||||
clientfds[i] = -1;
|
clientfds[i] = -1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* match the behavior of a terminal in raw mode */
|
|
||||||
if (*output_char == '\n')
|
/* If INLCR is set, a received NL character shall be translated into a CR character */
|
||||||
|
if (*output_char == '\n' && map_i_nl_cr)
|
||||||
{
|
{
|
||||||
*output_char = '\r';
|
*output_char = '\r';
|
||||||
}
|
}
|
||||||
|
else if (*output_char == '\r')
|
||||||
|
{
|
||||||
|
/* If IGNCR is set, a received CR character shall be ignored (not read). */
|
||||||
|
if (map_ign_cr)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If IGNCR is not set and ICRNL is set, a received CR character shall be translated into an NL character. */
|
||||||
|
if (map_i_cr_nl)
|
||||||
|
{
|
||||||
|
*output_char = '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,9 @@ const char random_array[] =
|
||||||
};
|
};
|
||||||
|
|
||||||
bool interactive_mode = true;
|
bool interactive_mode = true;
|
||||||
|
bool map_i_nl_cr = false;
|
||||||
|
bool map_i_cr_nl = false;
|
||||||
|
bool map_ign_cr = false;
|
||||||
|
|
||||||
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
|
static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old;
|
||||||
static unsigned long rx_total = 0, tx_total = 0;
|
static unsigned long rx_total = 0, tx_total = 0;
|
||||||
|
|
@ -987,14 +990,17 @@ void tty_configure(void)
|
||||||
if (strcmp(token,"INLCR") == 0)
|
if (strcmp(token,"INLCR") == 0)
|
||||||
{
|
{
|
||||||
tio.c_iflag |= INLCR;
|
tio.c_iflag |= INLCR;
|
||||||
|
map_i_nl_cr = true;
|
||||||
}
|
}
|
||||||
else if (strcmp(token,"IGNCR") == 0)
|
else if (strcmp(token,"IGNCR") == 0)
|
||||||
{
|
{
|
||||||
tio.c_iflag |= IGNCR;
|
tio.c_iflag |= IGNCR;
|
||||||
|
map_ign_cr = true;
|
||||||
}
|
}
|
||||||
else if (strcmp(token,"ICRNL") == 0)
|
else if (strcmp(token,"ICRNL") == 0)
|
||||||
{
|
{
|
||||||
tio.c_iflag |= ICRNL;
|
tio.c_iflag |= ICRNL;
|
||||||
|
map_i_cr_nl = true;
|
||||||
}
|
}
|
||||||
else if (strcmp(token,"OCRNL") == 0)
|
else if (strcmp(token,"OCRNL") == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
extern bool interactive_mode;
|
extern bool interactive_mode;
|
||||||
|
extern bool map_i_nl_cr;
|
||||||
|
extern bool map_i_cr_nl;
|
||||||
|
extern bool map_ign_cr;
|
||||||
|
|
||||||
void stdout_configure(void);
|
void stdout_configure(void);
|
||||||
void stdin_configure(void);
|
void stdin_configure(void);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue