11 * Reset the terminal state and exit with error.
16 /* tcsetattr(STDIN_FILENO, TCSANOW, &termio_old); */
17 fprintf(stderr
, "%s\n", s
);
23 * Set terminal to send one char at a time for interactive mode, and return the
24 * last terminal state.
27 set_terminal(int tty_fd
)
29 struct termios termio_old
;
30 struct termios termio_new
;
32 /* set the terminal to send one key at a time. */
34 /* get the terminal's state */
35 if (tcgetattr(tty_fd
, &termio_old
) < 0)
36 die("Can not get terminal attributes with tcgetattr().");
38 /* create a new modified state by switching the binary flags */
39 termio_new
= termio_old
;
40 termio_new
.c_lflag
&= ~(ICANON
| ECHO
| IGNBRK
);
42 /* apply this state to current terminal now (TCSANOW) */
43 tcsetattr(tty_fd
, TCSANOW
, &termio_new
);
50 * Replace tab as a multiple of 8 spaces in a line.
55 expand_tabs(char *line
)
58 char *converted
= malloc(sizeof(char) * (strlen(line
) * 8 + 1));
60 for (i
= 0, n
= 0; i
< strlen(line
); i
++, n
++) {
61 if (line
[i
] == '\t') {
62 for (; n
== 0 || n
% 8 != 0; n
++)
66 converted
[n
] = line
[i
];