1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-12-22 06:01:09 +02:00

neocon.c: new option -c to enable ONLCR for console output

This commit is contained in:
Werner Almesberger 2011-11-21 17:26:41 -03:00
parent f3e1f925c4
commit 4040ad3986

View File

@ -73,7 +73,7 @@ static speed_t bps_to_speed(int bps)
}
static void make_raw(int fd, struct termios *old)
static void make_raw(int fd, struct termios *old, int cr)
{
struct termios t;
long flags;
@ -98,6 +98,8 @@ static void make_raw(int fd, struct termios *old)
exit(1);
}
}
if (cr)
t.c_oflag |= OPOST | ONLCR;
if (tcsetattr(fd, TCSANOW, &t) < 0) {
perror("tcsetattr");
exit(1);
@ -125,7 +127,7 @@ static int open_next_tty(void)
break;
}
if (fd >= 0)
make_raw(fd, &tty);
make_raw(fd, &tty, 0);
return fd;
}
@ -278,9 +280,11 @@ static void cleanup(void)
static void usage(const char *name)
{
fprintf(stderr,
"usage: %s [-b bps] [-e escape] [-l logfile [-a] [-T]] [-t delay_ms] tty ...\n\n"
"usage: %s [-b bps] [-c] [-e escape] [-l logfile [-a] [-T]] [-t delay_ms] "
"tty ...\n\n"
" -a append to the log file if it already exists\n"
" -b bps set the TTY to the specified bit rate\n"
" -c add carriage return before newline (on console)\n"
" -e escape set the escape character (default: ~)\n"
" -l logfile log all output to the specified file\n"
" -t delay_ms wait the specified amount of time between input characters\n"
@ -293,14 +297,14 @@ static void usage(const char *name)
int main(int argc, char *const *argv)
{
char *end;
int c, bps;
int c, bps, cr = 0;
int fd = -1;
int append = 0;
const char *logfile = NULL;
int throttle_us = 0;
int throttle = 0;
while ((c = getopt(argc, argv, "ab:e:l:t:T")) != EOF)
while ((c = getopt(argc, argv, "ab:ce:l:t:T")) != EOF)
switch (c) {
case 'a':
append = 1;
@ -311,6 +315,9 @@ int main(int argc, char *const *argv)
usage(*argv);
speed = bps_to_speed(bps);
break;
case 'c':
cr = 1;
break;
case 'e':
if (strlen(optarg) != 1)
usage(*argv);
@ -342,7 +349,7 @@ int main(int argc, char *const *argv)
setlinebuf(log);
}
make_raw(0, &console);
make_raw(0, &console, cr);
atexit(cleanup);
while (1) {
struct timeval tv;