Date:2011-11-21 21:26:41 (7 years 7 months ago)
Author:Werner Almesberger
Commit:4040ad39862ced5608996c5408fbf3515d914e92
Message:neocon.c: new option -c to enable ONLCR for console output

Files: neocon/neocon.c (7 diffs)

Change Details

neocon/neocon.c
7373}
7474
7575
76static void make_raw(int fd, struct termios *old)
76static void make_raw(int fd, struct termios *old, int cr)
7777{
7878    struct termios t;
7979    long flags;
...... 
9898            exit(1);
9999        }
100100    }
101    if (cr)
102        t.c_oflag |= OPOST | ONLCR;
101103    if (tcsetattr(fd, TCSANOW, &t) < 0) {
102104        perror("tcsetattr");
103105        exit(1);
...... 
125127            break;
126128    }
127129    if (fd >= 0)
128        make_raw(fd, &tty);
130        make_raw(fd, &tty, 0);
129131        return fd;
130132}
131133
...... 
278280static void usage(const char *name)
279281{
280282    fprintf(stderr,
281"usage: %s [-b bps] [-e escape] [-l logfile [-a] [-T]] [-t delay_ms] tty ...\n\n"
283"usage: %s [-b bps] [-c] [-e escape] [-l logfile [-a] [-T]] [-t delay_ms] "
284    "tty ...\n\n"
282285" -a append to the log file if it already exists\n"
283286" -b bps set the TTY to the specified bit rate\n"
287" -c add carriage return before newline (on console)\n"
284288" -e escape set the escape character (default: ~)\n"
285289" -l logfile log all output to the specified file\n"
286290" -t delay_ms wait the specified amount of time between input characters\n"
...... 
293297int main(int argc, char *const *argv)
294298{
295299    char *end;
296    int c, bps;
300    int c, bps, cr = 0;
297301    int fd = -1;
298302    int append = 0;
299303    const char *logfile = NULL;
300304    int throttle_us = 0;
301305    int throttle = 0;
302306
303    while ((c = getopt(argc, argv, "ab:e:l:t:T")) != EOF)
307    while ((c = getopt(argc, argv, "ab:ce:l:t:T")) != EOF)
304308        switch (c) {
305309        case 'a':
306310            append = 1;
...... 
311315                    usage(*argv);
312316            speed = bps_to_speed(bps);
313317            break;
318        case 'c':
319            cr = 1;
320            break;
314321        case 'e':
315322            if (strlen(optarg) != 1)
316323                usage(*argv);
...... 
342349        setlinebuf(log);
343350    }
344351
345    make_raw(0, &console);
352    make_raw(0, &console, cr);
346353    atexit(cleanup);
347354    while (1) {
348355        struct timeval tv;

Archive Download the corresponding diff file

Branches:
master



interactive