Allow "-" for working with STDIN

Allow printing of each option separately when keyword specified without a
number
This commit is contained in:
Andrey A. Chernov 2000-04-30 18:06:04 +00:00
parent 43175e5e19
commit 85a23112fd
2 changed files with 50 additions and 16 deletions

@ -4,22 +4,26 @@
.Os FreeBSD
.Sh NAME
.Nm comcontrol
.Nd control an sio device.
.Nd control an special tty device.
.Sh SYNOPSIS
.Nm comcontrol
.Ar sio_special_device
.Op options
.Ar special_device | -
.Op dtrwait Op number
.Op drainwait Op number
.Sh DESCRIPTION
.Nm Comcontrol
is used to examine and modify some of the special characteristics
of the specified sio device.
If no arguments other than the device are specified,
of the specified tty device.
If no arguments other than the device (or "-" for stdin)
are specified,
it prints the settings of all controllable characteristics.
This usage requires only read access on the device.
Only the superuser can change the settings.
.Pp
The following options are available:
.Bl -tag -width indent
.It Cm dtrwait
Print current DTR wait time.
.It Cm dtrwait Ar number
Set the time to wait after dropping DTR
to the given number.
@ -27,11 +31,14 @@ The units are hundredths of a second.
The default is 300 hundredths, i.e., 3 seconds.
This option needed mainly to set proper recover time after
modem reset.
.It Cm drainwait
Print current output drain timeout.
.It Cm drainwait Ar number
Set the time to wait for output drain
to the given number.
The units are seconds.
The default is 0, i.e. wait forever.
The default is 5 minutes, 0 means
waiting forever.
This option needed mainly to specify upper limit of minutes
to prevent modem hanging.
.El

@ -44,7 +44,7 @@ static void
usage()
{
fprintf(stderr,
"usage: comcontrol <filename> [dtrwait <n>] [drainwait <n>]\n");
"usage: comcontrol <filename|-> [dtrwait [<n>]] [drainwait [<n>]]\n");
exit(1);
}
@ -54,14 +54,20 @@ main(int argc, char *argv[])
int fd;
int res = 0;
int dtrwait = -1, drainwait = -1;
int temp;
int output = 0;
if (argc < 2)
usage();
fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0);
if (fd < 0) {
warn("couldn't open file %s", argv[1]);
return 1;
if (strcmp(argv[1], "-") == 0)
fd = STDIN_FILENO;
else {
fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0);
if (fd < 0) {
warn("couldn't open file %s", argv[1]);
return 1;
}
}
if (argc == 2) {
@ -73,21 +79,40 @@ main(int argc, char *argv[])
res = 1;
warn("TIOCGDRAINWAIT");
}
printf("dtrwait %d drainwait %d\n", dtrwait, drainwait);
printf("dtrwait %d drainwait %d ", dtrwait, drainwait);
output = 1;
} else {
while (argv[2] != NULL) {
if (!strcmp(argv[2],"dtrwait")) {
if (argv[3] == NULL || !isdigit(argv[3][0])) {
if (ioctl(fd, TIOCMGDTRWAIT, &temp) < 0) {
res = 1;
temp = -1;
warn("TIOCMGDTRWAIT");
}
printf("dtrwait %d ", temp);
output = 1;
argv++;
continue;
}
if (dtrwait >= 0)
usage();
if (argv[3] == NULL || !isdigit(argv[3][0]))
usage();
dtrwait = atoi(argv[3]);
argv += 2;
} else if (!strcmp(argv[2],"drainwait")) {
if (argv[3] == NULL || !isdigit(argv[3][0])) {
if (ioctl(fd, TIOCGDRAINWAIT, &temp) < 0) {
res = 1;
temp = -1;
warn("TIOCGDRAINWAIT");
}
printf("drainwait %d ", temp);
argv++;
output = 1;
continue;
}
if (drainwait >= 0)
usage();
if (argv[3] == NULL || !isdigit(argv[3][0]))
usage();
drainwait = atoi(argv[3]);
argv += 2;
} else
@ -108,5 +133,7 @@ main(int argc, char *argv[])
}
close(fd);
if (output)
printf("\n");
return res;
}