summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-10-27 12:27:21 +0000
committercharnier <charnier@FreeBSD.org>1997-10-27 12:27:21 +0000
commit979da9c94af054c2d753e048bb94b87e6dbeeec1 (patch)
treea3ec8a3c548049810985831e8a67b77e2df65074
parent5a5312b885f93b3a0d128c5cb83d95fefd341fb8 (diff)
downloadFreeBSD-src-979da9c94af054c2d753e048bb94b87e6dbeeec1.zip
FreeBSD-src-979da9c94af054c2d753e048bb94b87e6dbeeec1.tar.gz
Add usage() and err(3). Sync man page with usage string.
-rw-r--r--usr.sbin/xten/xten.141
-rw-r--r--usr.sbin/xten/xten.c56
2 files changed, 55 insertions, 42 deletions
diff --git a/usr.sbin/xten/xten.1 b/usr.sbin/xten/xten.1
index 1889636..4a00f33 100644
--- a/usr.sbin/xten/xten.1
+++ b/usr.sbin/xten/xten.1
@@ -27,17 +27,23 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $Id: xten.1,v 1.5 1997/02/22 16:14:46 peter Exp $
+.\" $Id: xten.1,v 1.6 1997/06/23 04:52:13 steve Exp $
.\"
-.Th XTEN 8 "30 Oct 1993"
.Dd October 30, 1993
.Dt XTEN 1
-.Os BSD FreeBSD
+.Os
.Sh NAME
-xten \- transmit X-10 commands
+.Nm xten
+.Nd transmit X-10 commands
.Sh SYNOPSIS
.Nm xten
-[ - ] house key[:cnt] [ [ house ] key[:cnt] .\|.\|. ]
+.Op Fl ""
+.Ar house Ar key Ns Op Ar :cnt
+.Oo
+.Op Ar house
+.Ar key Ns Op Ar :cnt
+.Ar ...
+.Oc
.Sh DESCRIPTION
.Nm Xten
is a command-line interface to the X-10 daemon.
@@ -48,20 +54,19 @@ that the packets are all transmitted correctly, though in general it is
not possible to tell whether the commands were actually received and
executed by the remote X-10 devices.
.Pp
-When invoked with the single argument \-,
-.Nm xten
+When invoked with the single argument
+.Fl "" ,
+.Nm
enters an interactive mode in which a line is repeatedly read from the
standard input, sent to the X-10 daemon, and the one-line response from
the daemon printed on the standard output.
.Sh OPTIONS
The
-.I
-house
+.Ar house
argument is a one-letter house code in the range A-P.
All the X-10 requests generated will refer to this house code.
Each
-.I
-key
+.Ar key
is either a numeric unit code in the range 1-16, or else
is a string that specifies an X-10 function. The possible
function code strings are:
@@ -85,20 +90,16 @@ function code strings are:
.El
.Pp
Each
-.I
-key
+.Ar key
may be followed by an optional numeric
-.I
-cnt,
+.Ar cnt ,
which specifies the number of packets that are to be sent with that
key code without gaps. If this argument is omitted, two packets
are transmitted. The ability to specify numbers of packets other than
two is used by the X-10
-.I
-Dim
+.Em Dim
and
-.I
-Bright
+.Em Bright
commands.
.Sh SEE ALSO
.Xr tw 4 ,
@@ -109,4 +110,4 @@ commands.
the TW523 special file
.El
.Sh AUTHOR
-Eugene W. Stark (stark@cs.sunysb.edu)
+.An Eugene W. Stark Aq stark@cs.sunysb.edu
diff --git a/usr.sbin/xten/xten.c b/usr.sbin/xten/xten.c
index 57d731f..f59e76f 100644
--- a/usr.sbin/xten/xten.c
+++ b/usr.sbin/xten/xten.c
@@ -29,11 +29,20 @@
* SUCH DAMAGE.
*/
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+
/*
* Xten - user command interface to X-10 daemon
*/
+#include <err.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -59,6 +68,10 @@ char *X10cmdnames[] = {
NULL
};
+int find __P((char *, char *[]));
+static void usage __P((void));
+
+int
main(argc, argv)
int argc;
char *argv[];
@@ -71,24 +84,16 @@ char *argv[];
int interactive = 0;
if(argc == 2 && !strcmp(argv[1], "-")) interactive++;
- else if(argc < 3) {
- fprintf(stderr, "Usage: %s house key[:cnt] [ [house] key[:cnt] ... ]\n", argv[0]);
- exit(1);
- }
- if((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "%s: Can't create socket\n", argv[0]);
- exit(1);
- }
+ else if(argc < 3)
+ usage();
+ if((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ errx(1, "can't create socket");
strcpy(sa.sun_path, sockpath);
sa.sun_family = AF_UNIX;
- if(connect(sock, (struct sockaddr *)(&sa), strlen(sa.sun_path) + 2) < 0) {
- fprintf(stderr, "%s: Can't connect to X-10 daemon\n", argv[0]);
- exit(1);
- }
- if((daemon = fdopen(sock, "w+")) == NULL) {
- fprintf(stderr, "%s: Can't attach stream to socket\n", argv[0]);
- exit(1);
- }
+ if(connect(sock, (struct sockaddr *)(&sa), strlen(sa.sun_path) + 2) < 0)
+ errx(1, "can't connect to X-10 daemon");
+ if((daemon = fdopen(sock, "w+")) == NULL)
+ errx(1, "can't attach stream to socket");
/*
* If interactive, copy standard input to daemon and report results
* on standard output.
@@ -110,10 +115,8 @@ char *argv[];
* Otherwise, interpret arguments and issue commands to daemon,
* handling retries in case of errors.
*/
- if((h = find(argv[1], X10housenames)) < 0) {
- fprintf(stderr, "Invalid house code: %s\n", argv[1]);
- exit(1);
- }
+ if((h = find(argv[1], X10housenames)) < 0)
+ errx(1, "invalid house code: %s", argv[1]);
argv++;
argv++;
while(argc >= 3) {
@@ -129,7 +132,7 @@ char *argv[];
else c = 2;
*cp = '\0';
if((k = find(argv[0], X10cmdnames)) < 0) {
- fprintf(stderr, "Invalid key/unit code: %s\n", argv[0]);
+ warnx("invalid key/unit code: %s", argv[0]);
error++;
}
error = 0;
@@ -142,7 +145,7 @@ char *argv[];
usleep(200000);
}
if(error == RETRIES) {
- fprintf(stderr, "Command failed: send %s %s %d\n",
+ warnx("command failed: send %s %s %d",
X10housenames[h], X10cmdnames[k], c);
}
argc--;
@@ -153,6 +156,15 @@ char *argv[];
exit(0);
}
+static void
+usage()
+{
+ fprintf(stderr,
+ "usage: xten house key[:cnt] [[house] key[:cnt] ...]\n");
+ exit(1);
+}
+
+int
find(s, tab)
char *s;
char *tab[];
OpenPOWER on IntegriCloud