1
0
mirror of git://projects.qi-hardware.com/wernermisc.git synced 2024-11-24 09:08:06 +02:00

neocon/neocon.c: new option -L for local line editing (for Contiki)

This commit is contained in:
Werner Almesberger 2013-06-22 19:18:44 -03:00
parent 8b40af7770
commit 412d605f84
2 changed files with 18 additions and 8 deletions

View File

@ -22,6 +22,10 @@ with the option "-e escape".
To manually switch to the next device, enter "~n". To manually switch to the next device, enter "~n".
The option -L switches console input from character-by-character
(raw) mode to local line editing (cooked). Edited lines are sent
with \n termination.
Known issues Known issues
------------ ------------

View File

@ -74,7 +74,7 @@ static speed_t bps_to_speed(int bps)
} }
static void make_raw(int fd, struct termios *old, int cr) static void make_raw(int fd, struct termios *old, int cr, int local_edit)
{ {
struct termios t; struct termios t;
long flags; long flags;
@ -85,7 +85,8 @@ static void make_raw(int fd, struct termios *old, int cr)
} }
if (old) if (old)
*old = t; *old = t;
cfmakeraw(&t); if (local_edit)
return;
if (fd) { if (fd) {
t.c_iflag &= ~(IXON | IXOFF); t.c_iflag &= ~(IXON | IXOFF);
t.c_cflag |= CLOCAL; t.c_cflag |= CLOCAL;
@ -128,7 +129,7 @@ static int open_next_tty(void)
break; break;
} }
if (fd >= 0) if (fd >= 0)
make_raw(fd, &tty, 0); make_raw(fd, &tty, 0, 0);
return fd; return fd;
} }
@ -281,16 +282,17 @@ static void cleanup(void)
static void usage(const char *name) static void usage(const char *name)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s [-b bps] [-c] [-e escape] [-l logfile [-a] [-T]] [-t delay_ms] " "usage: %s [-b bps] [-c] [-e escape] [-l logfile [-a] [-T]] [-L]\n"
"tty ...\n\n" " %*s [-t delay_ms] tty ...\n\n"
" -a append to the log file if it already exists\n" " -a append to the log file if it already exists\n"
" -b bps set the TTY to the specified bit rate\n" " -b bps set the TTY to the specified bit rate\n"
" -c add carriage return before newline (on console)\n" " -c add carriage return before newline (on console)\n"
" -e escape set the escape character (default: ~)\n" " -e escape set the escape character (default: ~)\n"
" -l logfile log all output to the specified file\n" " -l logfile log all output to the specified file\n"
" -L enable local line editing\n"
" -t delay_ms wait the specified amount of time between input characters\n" " -t delay_ms wait the specified amount of time between input characters\n"
" -T add timestamps to the log file\n" " -T add timestamps to the log file\n"
, name); , name, (int) strlen(name), "");
exit(1); exit(1);
} }
@ -299,13 +301,14 @@ int main(int argc, char *const *argv)
{ {
char *end; char *end;
int c, bps, cr = 0; int c, bps, cr = 0;
int local_edit = 0;
int fd = -1; int fd = -1;
int append = 0; int append = 0;
const char *logfile = NULL; const char *logfile = NULL;
int throttle_us = 0; int throttle_us = 0;
int throttle = 0; int throttle = 0;
while ((c = getopt(argc, argv, "ab:ce:l:t:T")) != EOF) while ((c = getopt(argc, argv, "ab:ce:l:Lt:T")) != EOF)
switch (c) { switch (c) {
case 'a': case 'a':
append = 1; append = 1;
@ -327,6 +330,9 @@ int main(int argc, char *const *argv)
case 'l': case 'l':
logfile = optarg; logfile = optarg;
break; break;
case 'L':
local_edit = 1;
break;
case 't': case 't':
throttle_us = strtoul(optarg, &end, 0)*1000; throttle_us = strtoul(optarg, &end, 0)*1000;
if (*end) if (*end)
@ -350,7 +356,7 @@ int main(int argc, char *const *argv)
setlinebuf(log); setlinebuf(log);
} }
make_raw(0, &console, cr); make_raw(0, &console, cr, local_edit);
atexit(cleanup); atexit(cleanup);
while (1) { while (1) {
struct timeval tv; struct timeval tv;