log_error(USE_ERRNO, "Can't get pty");
/* Copy terminal attrs from stdin -> pty slave. */
- if (!term_copy(STDIN_FILENO, script_fds[SFD_SLAVE])) {
+ if (!term_copy(STDIN_FILENO, script_fds[SFD_SLAVE], 0)) {
log_error(USE_ERRNO, "Can't copy terminal attributes");
}
sync_winsize(STDIN_FILENO, script_fds[SFD_SLAVE]);
- if (!term_raw(STDIN_FILENO))
+ if (!term_raw(STDIN_FILENO, 1))
log_error(USE_ERRNO, "Can't set terminal to raw mode");
/*
void script_nextid __P((void));
void script_setup __P((void));
int term_cbreak __P((int));
-int term_copy __P((int, int));
+int term_copy __P((int, int, int));
int term_noecho __P((int));
-int term_raw __P((int));
+int term_raw __P((int, int));
int term_restore __P((int));
char *get_timestr __P((time_t, int));
YY_DECL;
#if defined(HAVE_TERMIOS_H) || defined(HAVE_TERMIO_H)
int
-term_raw(fd)
+term_raw(fd, onlcr)
int fd;
+ int onlcr;
{
struct termios term;
(void) memcpy(&term, &oterm, sizeof(term));
/* Set terminal to raw mode */
term.c_iflag &= ~(ICRNL|IGNCR|INLCR|IUCLC|IXON);
- term.c_oflag &= ~OPOST;
+ /* Retain NL to NLCR conversion if onlcr flag set. */
+ if (onlcr && ISSET(term.c_oflag, ONLCR|OPOST))
+ term.c_oflag = ONLCR|OPOST;
+ else
+ term.c_oflag &= ~OPOST;
term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
term.c_cc[VMIN] = 1;
term.c_cc[VTIME] = 0;
- if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &term) == 0) {
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH|TCSASOFT, &term) == 0) {
changed = 1;
return(1);
}
}
int
-term_copy(src, dst)
+term_copy(src, dst, onlcr)
int src;
int dst;
+ int onlcr;
{
struct termios tt;
if (tcgetattr(src, &tt) != 0)
return(0);
- if (tcsetattr(dst, TCSAFLUSH, &tt) != 0)
+ /* Do not convert line endings from NL to NLCR. */
+ if (!onlcr)
+ CLR(tt.c_oflag, ONLCR);
+ if (tcsetattr(dst, TCSAFLUSH|TCSASOFT, &tt) != 0)
return(0);
return(1);
}
#else /* SGTTY */
int
-term_raw(fd)
+term_raw(fd, onlcr)
int fd;
+ int onlcr;
{
if (!changed && ioctl(fd, TIOCGETP, &oterm) != 0)
return(0);
/* Set terminal to raw mode */
CLR(term.c_lflag, ECHO);
SET(term.sg_flags, RAW);
+ /* Retain NL to NLCR conversion if onlcr flag set. */
+ if (onlcr)
+ SET(term.sg_flags, CRMOD);
if (ioctl(fd, TIOCSETP, &term) == 0) {
changed = 1;
return(1);
}
int
-term_copy(src, dst)
+term_copy(src, dst, onlcr)
int src;
int dst;
+ int onlcr;
{
struct sgttyb b;
struct tchars tc;
ioctl(src, TIOCLGET, &lb)) {
return(0);
}
+ /* Do not convert line endings from NL to NLCR. */
+ if (!onlcr)
+ CLR(b.sg_flags, CRMOD);
if (ioctl(dst, TIOCSETP, &b) != 0 || ioctl(dst, TIOCSETC, &tc) != 0 ||
ioctl(dst, TIOCSLTC, &lc) != 0 || ioctl(dst, TIOCLSET, &lb) != 0 ||
ioctl(dst, TIOCSETD, &l) != 0) {