diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2001-09-09 19:30:50 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2001-09-09 19:30:50 +0000 |
commit | 46a99c6b2f097d7d6131d664e76d028d872c9041 (patch) | |
tree | 262aa90baf0ba6a32965882e76434f6ef85131b7 /usr.bin/tip | |
parent | dd1465da7dc1d30e7bfb903d66105c707307c1ec (diff) |
implement some more command line options for cu and use getopt(3)
Diffstat (limited to 'usr.bin/tip')
-rw-r--r-- | usr.bin/tip/cu.c | 89 | ||||
-rw-r--r-- | usr.bin/tip/log.c | 6 | ||||
-rw-r--r-- | usr.bin/tip/remote.c | 14 | ||||
-rw-r--r-- | usr.bin/tip/tip.1 | 8 | ||||
-rw-r--r-- | usr.bin/tip/tip.c | 35 | ||||
-rw-r--r-- | usr.bin/tip/tip.h | 8 |
6 files changed, 88 insertions, 72 deletions
diff --git a/usr.bin/tip/cu.c b/usr.bin/tip/cu.c index 6e2f07b0ec5..07f80f43600 100644 --- a/usr.bin/tip/cu.c +++ b/usr.bin/tip/cu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cu.c,v 1.5 2001/09/09 17:58:41 millert Exp $ */ +/* $OpenBSD: cu.c,v 1.6 2001/09/09 19:30:49 millert Exp $ */ /* $NetBSD: cu.c,v 1.5 1997/02/11 09:24:05 mrg Exp $ */ /* @@ -38,12 +38,14 @@ #if 0 static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: cu.c,v 1.5 2001/09/09 17:58:41 millert Exp $"; +static char rcsid[] = "$OpenBSD: cu.c,v 1.6 2001/09/09 19:30:49 millert Exp $"; #endif /* not lint */ #include "tip.h" +#include <getopt.h> void cleanup(); +void cuusage(); /* * Botch the interface to look like cu's @@ -53,55 +55,72 @@ cumain(argc, argv) int argc; char *argv[]; { - register int i; + int ch, i; + long l; + char *cp; static char sbuf[12]; - if (argc < 2) { - printf("usage: cu [phone-number] [-t] [-s speed] [-a acu] [-l line] [-#]\n"); - exit(8); - } + if (argc < 2) + cuusage(); CU = DV = NOSTR; BR = DEFBR; - for (; argc > 1; argv++, argc--) { - if (argv[1][0] != '-') - PN = argv[1]; - else switch (argv[1][1]) { - - case 't': - HW = 1, DU = -1; - --argc; - continue; - + while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) { + switch(ch) { case 'a': - CU = argv[2]; ++argv; --argc; + CU = optarg; + break; + case 'l': + DV = optarg; break; - case 's': - if (argc < 3 || speed(atoi(argv[2])) == 0) { - fprintf(stderr, "cu: unsupported speed %s\n", - argv[2]); + l = strtol(optarg, &cp, 10); + if (*cp != '\0' || l < 0 || l >= INT_MAX || + speed((int)l) == 0) { + fprintf(stderr, "%s: unsupported speed %s\n", + __progname, optarg); exit(3); } - BR = atoi(argv[2]); ++argv; --argc; + BR = (int)l; break; - - case 'l': - DV = argv[2]; ++argv; --argc; + case 'h': + value(LECHO) = (char *)TRUE; + HD = TRUE; + break; + case 't': + HW = 1, DU = -1; + break; + case 'o': + setparity("odd"); + break; + case 'e': + setparity("even"); break; - case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (CU) - CU[strlen(CU)-1] = argv[1][1]; + CU[strlen(CU)-1] = ch; if (DV) - DV[strlen(DV)-1] = argv[1][1]; + DV[strlen(DV)-1] = ch; break; - default: - printf("Bad flag %s", argv[1]); + cuusage; break; } } + argc -= optind; + argv += optind; + + switch (argc) { + case 1: + PN = argv[0]; + break; + case 0: + break; + default: + cuusage(); + break; + } + signal(SIGINT, cleanup); signal(SIGQUIT, cleanup); signal(SIGHUP, cleanup); @@ -138,3 +157,11 @@ cumain(argc, argv) if (!HW) ttysetup(speed(BR)); } + +void +cuusage() +{ + fprintf(stderr, "usage: cu [-ehot] [-a acu] [-l line] [-s speed] [-#] " + "[phone-number]\n"); + exit(8); +} diff --git a/usr.bin/tip/log.c b/usr.bin/tip/log.c index 791cf3bafb6..1a715c0d5f5 100644 --- a/usr.bin/tip/log.c +++ b/usr.bin/tip/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.4 2001/07/12 05:17:24 deraadt Exp $ */ +/* $OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $ */ /* $NetBSD: log.c,v 1.4 1994/12/24 17:56:28 cgd Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: log.c,v 1.4 2001/07/12 05:17:24 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: log.c,v 1.5 2001/09/09 19:30:49 millert Exp $"; #endif /* not lint */ #include "tip.h" @@ -60,7 +60,7 @@ logent(group, num, acu, message) if (flog == NULL) return; if (flock(fileno(flog), LOCK_EX) < 0) { - perror("tip: flock"); + perror("flock"); return; } if ((user = getlogin()) == NOSTR) { diff --git a/usr.bin/tip/remote.c b/usr.bin/tip/remote.c index a7d0b2d9749..036b3d7e14f 100644 --- a/usr.bin/tip/remote.c +++ b/usr.bin/tip/remote.c @@ -1,4 +1,4 @@ -/* $OpenBSD: remote.c,v 1.8 2001/07/12 05:17:24 deraadt Exp $ */ +/* $OpenBSD: remote.c,v 1.9 2001/09/09 19:30:49 millert Exp $ */ /* $NetBSD: remote.c,v 1.5 1997/04/20 00:02:45 mellon Exp $ */ /* @@ -45,7 +45,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)remote.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: remote.c,v 1.8 2001/07/12 05:17:24 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: remote.c,v 1.9 2001/09/09 19:30:49 millert Exp $"; #endif /* not lint */ #include <stdio.h> @@ -106,15 +106,17 @@ getremcap(host) } switch(stat) { case -1: - fprintf(stderr, "tip: unknown host %s\n", host); + fprintf(stderr, "%s: unknown host %s\n", __progname, + host); break; case -2: fprintf(stderr, - "tip: can't open host description file\n"); + "%s: can't open host description file\n", + __progname); break; case -3: fprintf(stderr, - "tip: possible reference loop in host description file\n"); + "%s: possible reference loop in host description file\n", __progname); break; } exit(3); @@ -214,7 +216,7 @@ getremote(host) if (!lookedup) { if (host == NOSTR && (host = getenv("HOST")) == NOSTR) { - fprintf(stderr, "tip: no host specified\n"); + fprintf(stderr, "%s: no host specified\n", __progname); exit(3); } getremcap(host); diff --git a/usr.bin/tip/tip.1 b/usr.bin/tip/tip.1 index bc890a40790..071ab3e92f0 100644 --- a/usr.bin/tip/tip.1 +++ b/usr.bin/tip/tip.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tip.1,v 1.16 2001/09/09 17:58:41 millert Exp $ +.\" $OpenBSD: tip.1,v 1.17 2001/09/09 19:30:49 millert Exp $ .\" $NetBSD: tip.1,v 1.7 1994/12/08 09:31:05 jtc Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 @@ -47,12 +47,12 @@ .Op Fl Ar speed .Op Ar system\-name .Nm cu -.Op Ar phone\-number -.Op Fl t -.Op Fl s Ar speed +.Op Fl ehot .Op Fl a Ar acu .Op Fl l Ar line +.Op Fl s Ar speed .Op Fl # +.Op Ar phone\-number .Sh DESCRIPTION .Nm and diff --git a/usr.bin/tip/tip.c b/usr.bin/tip/tip.c index 91505e0f1d7..bfa760ad2f7 100644 --- a/usr.bin/tip/tip.c +++ b/usr.bin/tip/tip.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tip.c,v 1.12 2001/04/12 19:21:43 millert Exp $ */ +/* $OpenBSD: tip.c,v 1.13 2001/09/09 19:30:49 millert Exp $ */ /* $NetBSD: tip.c,v 1.13 1997/04/20 00:03:05 mellon Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: tip.c,v 1.12 2001/04/12 19:21:43 millert Exp $"; +static char rcsid[] = "$OpenBSD: tip.c,v 1.13 2001/09/09 19:30:49 millert Exp $"; #endif /* not lint */ /* @@ -68,7 +68,6 @@ int disc = TTYDISC; /* tip normally runs this way */ void intprompt(); void timeout(); void cleanup(); -char *sname(); char PNbuf[256]; /* This limits the size of a number */ int @@ -85,7 +84,7 @@ main(argc, argv) egid = getegid(); uid = getuid(); euid = geteuid(); - if (equal(sname(argv[0]), "cu")) { + if (equal(__progname, "cu")) { cumode = 1; cumain(argc, argv); goto cucommon; @@ -96,7 +95,7 @@ main(argc, argv) exit(1); } if (!isatty(0)) { - fprintf(stderr, "tip: must be interactive\n"); + fprintf(stderr, "%s: must be interactive\n", __progname); exit(1); } @@ -119,7 +118,8 @@ main(argc, argv) break; default: - fprintf(stderr, "tip: %s, unknown option\n", argv[1]); + fprintf(stderr, "%s: %s, unknown option\n", __progname, + argv[1]); break; } } @@ -134,8 +134,8 @@ main(argc, argv) * is private, we don't want 'ps' or 'w' to find it). */ if (strlen(system) > sizeof PNbuf - 1) { - fprintf(stderr, "tip: phone number too long (max = %d bytes)\n", - sizeof PNbuf - 1); + fprintf(stderr, "%s: phone number too long (max = %d bytes)\n", + __progname, sizeof(PNbuf) - 1); exit(1); } strncpy( PNbuf, system, sizeof PNbuf - 1 ); @@ -181,7 +181,8 @@ notnumber: vinit(); /* init variables */ setparity("none"); /* set the parity table */ if ((i = speed(number(value(BAUDRATE)))) == 0) { - printf("tip: bad baud rate %ld\n", number(value(BAUDRATE))); + printf("%s: bad baud rate %ld\n", __progname, + number(value(BAUDRATE))); daemon_uid(); (void)uu_unlock(uucplock); exit(3); @@ -561,22 +562,6 @@ ttysetup(speed) tcsetattr(FD, TCSAFLUSH, &cntrl); } -/* - * Return "simple" name from a file name, - * strip leading directories. - */ -char * -sname(s) - register char *s; -{ - register char *p = s; - - while (*s) - if (*s++ == '/') - p = s; - return (p); -} - static char partab[0200]; /* diff --git a/usr.bin/tip/tip.h b/usr.bin/tip/tip.h index 12dabf80d68..4c5ab2064ee 100644 --- a/usr.bin/tip/tip.h +++ b/usr.bin/tip/tip.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tip.h,v 1.10 2000/04/20 06:19:33 deraadt Exp $ */ +/* $OpenBSD: tip.h,v 1.11 2001/09/09 19:30:49 millert Exp $ */ /* $NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $ */ /* @@ -265,8 +265,10 @@ char ccc; /* synchronization character */ char ch; /* for tipout */ char *uucplock; /* name of lock file for uucp's */ -int odisc; /* initial tty line discipline */ -extern int disc; /* current tty discpline */ +int odisc; /* initial tty line discipline */ +extern int disc; /* current tty discpline */ + +extern char *__progname; /* program name */ extern char *ctrl(); extern char *vinterp(); |