mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
detabbing (by tab with 4)
This commit is contained in:
150
termios2.c
150
termios2.c
@ -54,59 +54,59 @@
|
||||
int
|
||||
tc2setattr(int fd, int optional_actions, const struct termios *tios)
|
||||
{
|
||||
struct termios2 t2;
|
||||
int cmd;
|
||||
struct termios2 t2;
|
||||
int cmd;
|
||||
|
||||
switch (optional_actions) {
|
||||
case TCSANOW:
|
||||
cmd = IOCTL_SETS;
|
||||
break;
|
||||
case TCSADRAIN:
|
||||
cmd = IOCTL_SETSW;
|
||||
break;
|
||||
case TCSAFLUSH:
|
||||
cmd = IOCTL_SETSF;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
switch (optional_actions) {
|
||||
case TCSANOW:
|
||||
cmd = IOCTL_SETS;
|
||||
break;
|
||||
case TCSADRAIN:
|
||||
cmd = IOCTL_SETSW;
|
||||
break;
|
||||
case TCSAFLUSH:
|
||||
cmd = IOCTL_SETSF;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
t2.c_iflag = tios->c_iflag & ~IBAUD0;
|
||||
t2.c_oflag = tios->c_oflag;
|
||||
t2.c_cflag = tios->c_cflag;
|
||||
t2.c_lflag = tios->c_lflag;
|
||||
t2.c_line = tios->c_line;
|
||||
t2.c_ispeed = tios->c_ispeed;
|
||||
t2.c_ospeed = tios->c_ospeed;
|
||||
memcpy(&t2.c_cc[0], &tios->c_cc[0], K_NCCS * sizeof (cc_t));
|
||||
t2.c_iflag = tios->c_iflag & ~IBAUD0;
|
||||
t2.c_oflag = tios->c_oflag;
|
||||
t2.c_cflag = tios->c_cflag;
|
||||
t2.c_lflag = tios->c_lflag;
|
||||
t2.c_line = tios->c_line;
|
||||
t2.c_ispeed = tios->c_ispeed;
|
||||
t2.c_ospeed = tios->c_ospeed;
|
||||
memcpy(&t2.c_cc[0], &tios->c_cc[0], K_NCCS * sizeof (cc_t));
|
||||
|
||||
return ioctl(fd, cmd, &t2);
|
||||
return ioctl(fd, cmd, &t2);
|
||||
}
|
||||
|
||||
int
|
||||
tc2getattr(int fd, struct termios *tios)
|
||||
{
|
||||
struct termios2 t2;
|
||||
size_t i;
|
||||
int r;
|
||||
struct termios2 t2;
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
r = ioctl(fd, IOCTL_GETS, &t2);
|
||||
if (r < 0) return r;
|
||||
r = ioctl(fd, IOCTL_GETS, &t2);
|
||||
if (r < 0) return r;
|
||||
|
||||
tios->c_iflag = t2.c_iflag;
|
||||
tios->c_oflag = t2.c_oflag;
|
||||
tios->c_cflag = t2.c_cflag;
|
||||
tios->c_lflag = t2.c_lflag;
|
||||
tios->c_line = t2.c_line;
|
||||
tios->c_ispeed = t2.c_ispeed;
|
||||
tios->c_ospeed = t2.c_ospeed;
|
||||
memcpy(&tios->c_cc[0], &t2.c_cc[0], K_NCCS * sizeof (cc_t));
|
||||
tios->c_iflag = t2.c_iflag;
|
||||
tios->c_oflag = t2.c_oflag;
|
||||
tios->c_cflag = t2.c_cflag;
|
||||
tios->c_lflag = t2.c_lflag;
|
||||
tios->c_line = t2.c_line;
|
||||
tios->c_ispeed = t2.c_ispeed;
|
||||
tios->c_ospeed = t2.c_ospeed;
|
||||
memcpy(&tios->c_cc[0], &t2.c_cc[0], K_NCCS * sizeof (cc_t));
|
||||
|
||||
for (i = K_NCCS; i < NCCS; i++)
|
||||
tios->c_cc[i] = _POSIX_VDISABLE;
|
||||
for (i = K_NCCS; i < NCCS; i++)
|
||||
tios->c_cc[i] = _POSIX_VDISABLE;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The termios2 interface supports separate input and output
|
||||
@ -124,22 +124,22 @@ tc2getattr(int fd, struct termios *tios)
|
||||
int
|
||||
cf2setispeed(struct termios *tios, speed_t speed)
|
||||
{
|
||||
if ( (speed & ~CBAUD) != 0
|
||||
&& (speed < B57600 || speed > __MAX_BAUD) ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
tios->c_ispeed = speed;
|
||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||
tios->c_cflag |= (speed << IBSHIFT);
|
||||
if ( (speed & ~CBAUD) != 0
|
||||
&& (speed < B57600 || speed > __MAX_BAUD) ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
tios->c_ispeed = speed;
|
||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||
tios->c_cflag |= (speed << IBSHIFT);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
speed_t
|
||||
cf2getispeed(struct termios *tios)
|
||||
{
|
||||
return (tios->c_cflag >> IBSHIFT) & (CBAUD | CBAUDEX);
|
||||
return (tios->c_cflag >> IBSHIFT) & (CBAUD | CBAUDEX);
|
||||
}
|
||||
|
||||
/* Use these to set custom input or output speeds (i.e. speeds that do
|
||||
@ -148,37 +148,37 @@ cf2getispeed(struct termios *tios)
|
||||
int
|
||||
cf2setospeed_custom(struct termios *tios, int speed)
|
||||
{
|
||||
if ( speed <= 0 ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
tios->c_cflag &= ~(CBAUD | CBAUDEX);
|
||||
tios->c_cflag |= BOTHER;
|
||||
tios->c_ospeed = speed;
|
||||
if ( speed <= 0 ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
tios->c_cflag &= ~(CBAUD | CBAUDEX);
|
||||
tios->c_cflag |= BOTHER;
|
||||
tios->c_ospeed = speed;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
cf2setispeed_custom(struct termios *tios, int speed)
|
||||
{
|
||||
if ( speed < 0 ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if ( speed == 0 ) {
|
||||
/* Special case: ispeed == 0 means "same as ospeed". Kernel
|
||||
does this if it sees B0 in the "CIBAUD" field (i.e. in
|
||||
CBAUD << IBSHIFT) */
|
||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||
tios->c_cflag |= (B0 << IBSHIFT);
|
||||
} else {
|
||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||
tios->c_cflag |= (BOTHER << IBSHIFT);
|
||||
tios->c_ispeed = speed;
|
||||
}
|
||||
if ( speed < 0 ) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if ( speed == 0 ) {
|
||||
/* Special case: ispeed == 0 means "same as ospeed". Kernel
|
||||
does this if it sees B0 in the "CIBAUD" field (i.e. in
|
||||
CBAUD << IBSHIFT) */
|
||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||
tios->c_cflag |= (B0 << IBSHIFT);
|
||||
} else {
|
||||
tios->c_cflag &= ~((CBAUD | CBAUDEX) << IBSHIFT);
|
||||
tios->c_cflag |= (BOTHER << IBSHIFT);
|
||||
tios->c_ispeed = speed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
Reference in New Issue
Block a user