Add ability to manipulate with drain wait time

This commit is contained in:
Andrey A. Chernov 2000-04-27 21:31:23 +00:00
parent fc5361f9d8
commit d0834e7f9d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=59714
6 changed files with 42 additions and 15 deletions

View File

@ -38,12 +38,12 @@ int c_cchars __P((const void *, const void *));
int c_modes __P((const void *, const void *));
int csearch __P((char ***, struct info *));
void checkredirect __P((void));
void gprint __P((struct termios *, struct winsize *, int));
void gread __P((struct termios *, char *));
void gprint __P((struct termios *, struct winsize *, int, int));
void gread __P((struct termios *, int *, char *));
int ksearch __P((char ***, struct info *));
int msearch __P((char ***, struct info *));
void optlist __P((void));
void print __P((struct termios *, struct winsize *, int, enum FMT));
void print __P((struct termios *, struct winsize *, int, int, enum FMT));
void usage __P((void));
extern struct cchar cchars1[], cchars2[];

View File

@ -59,10 +59,11 @@ gerr(s)
}
void
gprint(tp, wp, ldisc)
gprint(tp, wp, ldisc, timeout)
struct termios *tp;
struct winsize *wp;
int ldisc;
int timeout;
{
struct cchar *cp;
@ -71,13 +72,14 @@ gprint(tp, wp, ldisc)
(u_long)tp->c_oflag);
for (cp = cchars1; cp->name; ++cp)
(void)printf("%s=%x:", cp->name, tp->c_cc[cp->sub]);
(void)printf("ispeed=%lu:ospeed=%lu\n",
(u_long)cfgetispeed(tp), (u_long)cfgetospeed(tp));
(void)printf("ispeed=%lu:ospeed=%lu:drainwait=%d\n",
(u_long)cfgetispeed(tp), (u_long)cfgetospeed(tp), timeout);
}
void
gread(tp, s)
gread(tp, top, s)
struct termios *tp;
int *top;
char *s;
{
struct cchar *cp;
@ -122,6 +124,11 @@ gread(tp, s)
tp->c_ospeed = tmp;
continue;
}
if (CHK("drainwait")) {
(void)sscanf(ep, "%ld", &tmp);
*top = tmp;
continue;
}
for (cp = cchars1; cp->name != NULL; ++cp)
if (CHK(cp->name)) {
if (cp->sub == VMIN || cp->sub == VTIME)

View File

@ -56,6 +56,7 @@ void f_all __P((struct info *));
void f_cbreak __P((struct info *));
void f_columns __P((struct info *));
void f_dec __P((struct info *));
void f_drainwait __P((struct info *));
void f_everything __P((struct info *));
void f_extproc __P((struct info *));
void f_ispeed __P((struct info *));
@ -82,6 +83,7 @@ static struct key {
{ "columns", f_columns, F_NEEDARG },
{ "cooked", f_sane, 0 },
{ "dec", f_dec, 0 },
{ "drainwait", f_drainwait, F_NEEDARG },
{ "everything", f_everything, 0 },
{ "extproc", f_extproc, F_OFFOK },
{ "ispeed", f_ispeed, F_NEEDARG },
@ -140,7 +142,7 @@ void
f_all(ip)
struct info *ip;
{
print(&ip->t, &ip->win, ip->ldisc, BSD);
print(&ip->t, &ip->win, ip->ldisc, ip->timeout, BSD);
}
void
@ -182,12 +184,21 @@ f_dec(ip)
ip->set = 1;
}
void
f_drainwait(ip)
struct info *ip;
{
ip->timeout = atoi(ip->arg);
ip->tset = 1;
}
void
f_everything(ip)
struct info *ip;
{
print(&ip->t, &ip->win, ip->ldisc, BSD);
print(&ip->t, &ip->win, ip->ldisc, ip->timeout, BSD);
}
void

View File

@ -55,10 +55,11 @@ static void bput __P((char *));
static char *ccval __P((struct cchar *, int));
void
print(tp, wp, ldisc, fmt)
print(tp, wp, ldisc, timeout, fmt)
struct termios *tp;
struct winsize *wp;
int ldisc;
int timeout;
enum FMT fmt;
{
struct cchar *p;
@ -96,7 +97,8 @@ print(tp, wp, ldisc, fmt)
else
cnt += printf("speed %d baud;", ispeed);
if (fmt >= BSD)
cnt += printf(" %d rows; %d columns;", wp->ws_row, wp->ws_col);
cnt += printf(" %d rows; %d columns; drainwait %d seconds;",
wp->ws_row, wp->ws_col, timeout);
if (cnt)
(void)printf("\n");

View File

@ -103,6 +103,8 @@ args: argc -= optind;
err(1, "TIOCGETD");
if (ioctl(i.fd, TIOCGWINSZ, &i.win) < 0)
warn("TIOCGWINSZ: %s\n", strerror(errno));
if (ioctl(i.fd, TIOCGDRAINWAIT, &i.timeout) < 0)
warn("TIOCGDRAINWAIT: %s\n", strerror(errno));
checkredirect(); /* conversion aid */
@ -113,14 +115,14 @@ args: argc -= optind;
/* FALLTHROUGH */
case BSD:
case POSIX:
print(&i.t, &i.win, i.ldisc, fmt);
print(&i.t, &i.win, i.ldisc, i.timeout, fmt);
break;
case GFLAG:
gprint(&i.t, &i.win, i.ldisc);
gprint(&i.t, &i.win, i.ldisc, i.timeout);
break;
}
for (i.set = i.wset = 0; *argv; ++argv) {
for (i.set = i.wset = i.tset = 0; *argv; ++argv) {
if (ksearch(&argv, &i))
continue;
@ -141,8 +143,9 @@ args: argc -= optind;
}
if (!strncmp(*argv, "gfmt1", sizeof("gfmt1") - 1)) {
gread(&i.t, *argv + sizeof("gfmt1") - 1);
gread(&i.t, &i.timeout, *argv + sizeof("gfmt1") - 1);
i.set = 1;
i.tset = 1;
continue;
}
@ -154,6 +157,8 @@ args: argc -= optind;
err(1, "tcsetattr");
if (i.wset && ioctl(i.fd, TIOCSWINSZ, &i.win) < 0)
warn("TIOCSWINSZ");
if (i.tset && ioctl(i.fd, TIOCSDRAINWAIT, &i.timeout) < 0)
warn("TIOCSDRAINWAIT");
exit(0);
}

View File

@ -43,9 +43,11 @@ struct info {
int off; /* turn off */
int set; /* need set */
int wset; /* need window set */
int tset; /* need timeout set */
char *arg; /* argument */
struct termios t; /* terminal info */
struct winsize win; /* window info */
int timeout; /* drain wait time */
};
struct cchar {