Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Commit Details
Date: | 2011-11-21 21:26:41 (12 years 4 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 | ||
---|---|---|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
76 | static void make_raw(int fd, struct termios *old) | |
76 | static void make_raw(int fd, struct termios *old, int cr) | |
77 | 77 | { |
78 | 78 | struct termios t; |
79 | 79 | long flags; |
... | ... | |
98 | 98 | exit(1); |
99 | 99 | } |
100 | 100 | } |
101 | if (cr) | |
102 | t.c_oflag |= OPOST | ONLCR; | |
101 | 103 | if (tcsetattr(fd, TCSANOW, &t) < 0) { |
102 | 104 | perror("tcsetattr"); |
103 | 105 | exit(1); |
... | ... | |
125 | 127 | break; |
126 | 128 | } |
127 | 129 | if (fd >= 0) |
128 | make_raw(fd, &tty); | |
130 | make_raw(fd, &tty, 0); | |
129 | 131 | return fd; |
130 | 132 | } |
131 | 133 | |
... | ... | |
278 | 280 | static void usage(const char *name) |
279 | 281 | { |
280 | 282 | 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" | |
282 | 285 | " -a append to the log file if it already exists\n" |
283 | 286 | " -b bps set the TTY to the specified bit rate\n" |
287 | " -c add carriage return before newline (on console)\n" | |
284 | 288 | " -e escape set the escape character (default: ~)\n" |
285 | 289 | " -l logfile log all output to the specified file\n" |
286 | 290 | " -t delay_ms wait the specified amount of time between input characters\n" |
... | ... | |
293 | 297 | int main(int argc, char *const *argv) |
294 | 298 | { |
295 | 299 | char *end; |
296 | int c, bps; | |
300 | int c, bps, cr = 0; | |
297 | 301 | int fd = -1; |
298 | 302 | int append = 0; |
299 | 303 | const char *logfile = NULL; |
300 | 304 | int throttle_us = 0; |
301 | 305 | int throttle = 0; |
302 | 306 | |
303 | while ((c = getopt(argc, argv, "ab:e:l:t:T")) != EOF) | |
307 | while ((c = getopt(argc, argv, "ab:ce:l:t:T")) != EOF) | |
304 | 308 | switch (c) { |
305 | 309 | case 'a': |
306 | 310 | append = 1; |
... | ... | |
311 | 315 | usage(*argv); |
312 | 316 | speed = bps_to_speed(bps); |
313 | 317 | break; |
318 | case 'c': | |
319 | cr = 1; | |
320 | break; | |
314 | 321 | case 'e': |
315 | 322 | if (strlen(optarg) != 1) |
316 | 323 | usage(*argv); |
... | ... | |
342 | 349 | setlinebuf(log); |
343 | 350 | } |
344 | 351 | |
345 | make_raw(0, &console); | |
352 | make_raw(0, &console, cr); | |
346 | 353 | atexit(cleanup); |
347 | 354 | while (1) { |
348 | 355 | struct timeval tv; |
Branches:
master