BSD 4_3_Tahoe release
[unix-history] / usr / src / usr.bin / tip / cu.c
CommitLineData
051b1e55
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
05862919 7#ifndef lint
ca67e7b4 8static char sccsid[] = "@(#)cu.c 5.5 (Berkeley) 10/22/87";
051b1e55 9#endif not lint
24f09632
SL
10
11#include "tip.h"
12
13int cleanup();
14int timeout();
15
16/*
17 * Botch the interface to look like cu's
18 */
19cumain(argc, argv)
20 char *argv[];
21{
22 register int i;
c731dacc 23 static char sbuf[12];
24f09632 24
24f09632 25 if (argc < 2) {
c731dacc 26 printf("usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
24f09632
SL
27 exit(8);
28 }
c731dacc 29 CU = DV = NOSTR;
b9847ed6 30 BR = DEFBR;
24f09632
SL
31 for (; argc > 1; argv++, argc--) {
32 if (argv[1][0] != '-')
33 PN = argv[1];
3f48242d 34 else switch (argv[1][1]) {
24f09632
SL
35
36 case 't':
37 HW = 1, DU = -1;
38 --argc;
39 continue;
40
41 case 'a':
42 CU = argv[2]; ++argv; --argc;
43 break;
44
45 case 's':
b9847ed6 46 if (argc < 3 || speed(atoi(argv[2])) == 0) {
c731dacc
BS
47 fprintf(stderr, "cu: unsupported speed %s\n",
48 argv[2]);
24f09632
SL
49 exit(3);
50 }
51 BR = atoi(argv[2]); ++argv; --argc;
52 break;
53
54 case 'l':
55 DV = argv[2]; ++argv; --argc;
56 break;
57
58 case '0': case '1': case '2': case '3': case '4':
59 case '5': case '6': case '7': case '8': case '9':
c731dacc
BS
60 if (CU)
61 CU[strlen(CU)-1] = argv[1][1];
62 if (DV)
63 DV[strlen(DV)-1] = argv[1][1];
24f09632
SL
64 break;
65
66 default:
67 printf("Bad flag %s", argv[1]);
68 break;
69 }
70 }
c731dacc
BS
71 signal(SIGINT, cleanup);
72 signal(SIGQUIT, cleanup);
73 signal(SIGHUP, cleanup);
74 signal(SIGTERM, cleanup);
75
24f09632
SL
76 /*
77 * The "cu" host name is used to define the
78 * attributes of the generic dialer.
79 */
9a491ec2
KB
80 (void)sprintf(sbuf, "cu%d", BR);
81 if ((i = hunt(sbuf)) == 0) {
24f09632
SL
82 printf("all ports busy\n");
83 exit(3);
84 }
85 if (i == -1) {
86 printf("link down\n");
87 delock(uucplock);
88 exit(3);
89 }
c731dacc
BS
90 setbuf(stdout, NULL);
91 loginit();
45d9e9af 92 user_uid();
c731dacc 93 vinit();
dfec50f2 94 setparity("none");
c731dacc 95 boolean(value(VERBOSE)) = 0;
24f09632
SL
96 if (HW)
97 ttysetup(speed(BR));
98 if (connect()) {
99 printf("Connect failed\n");
45d9e9af 100 daemon_uid();
24f09632
SL
101 delock(uucplock);
102 exit(1);
103 }
104 if (!HW)
105 ttysetup(speed(BR));
106}